OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
kernel.hpp
1#ifndef QOS_CPP_KERNEL
2#define QOS_CPP_KERNEL
3
4#include "config/config.h"
5#include "include/list.hpp"
6#include "include/clock.hpp"
7#include "include/types.hpp"
8#include "include/task.hpp"
9#include "include/prioqueue.hpp"
10#include "include/input.hpp"
11
12#if ( Q_FSM == 1 )
13 #include "include/fsm.hpp"
14#endif
15#if ( Q_CLI == 1 )
16 #include "include/cli.hpp"
17#endif
18
22namespace qOS {
23
33 using coreFlags_t = uint32_t ;
45 enum class notifyMode : uint8_t {
46 SIMPLE = 0U,
47 QUEUED = 1U,
49 NOTIFY_NONE = 3U,
51 };
52
54 struct notificationSpreader_t {
55 notifyMode mode;
56 void *eventData;
57 };
73 {
74 return ( ( i >= 1U ) && ( i <= 20U ) ) ? 0x00001000UL << ( i - 1U ) : 0x00001000UL;
75 }
76
83 class core final : protected taskEvent {
84 private:
85 task idle;
86 taskFcn_t releaseSchedCallback{ nullptr };
87 task *yieldTask{ nullptr };
88 pq::queueStack_t pq_stack[ Q_PRIO_QUEUE_SIZE ]; // skipcq: CXX-W2066
89 prioQueue priorityQueue{ pq_stack, sizeof(pq_stack)/sizeof(pq::queueStack_t) }; // skipcq: CXX-C1000
90 volatile coreFlags_t flag{ 0UL };
91 notificationSpreader_t nSpreader{ notifyMode::NOTIFY_NONE, nullptr };
92 size_t taskEntries{ 0UL };
93 list coreLists[ Q_PRIORITY_LEVELS + 2 ]; // skipcq: CXX-W2066
94 list& waitingList; // skipcq: CXX-W2012, CXX-W2010
95 list& suspendedList; // skipcq: CXX-W2012, CXX-W2010
96 list inputWatchers;
97 static const priority_t MAX_PRIORITY_VALUE;
98 static const uint32_t BIT_INIT;
99 static const uint32_t BIT_FCALL_IDLE;
100 static const uint32_t BIT_RELEASE_SCHED;
101 static const uint32_t BIT_FCALL_RELEASED;
102 void triggerReleaseSchedEvent( void ) noexcept;
103 bool checkIfReady( void ) noexcept;
104 void dispatchTaskFillEventInfo( task *Task ) noexcept;
105 void dispatch( list * const xList ) noexcept;
106 void dispatchIdle( void ) noexcept;
107 void handleInputWatchers( void ) noexcept;
108 core() : waitingList( coreLists[ Q_PRIORITY_LEVELS ] ), suspendedList( coreLists[ Q_PRIORITY_LEVELS + 1 ] ) {}
109 core( core &other ) = delete;
110 void operator=( const core & ) = delete;
111 public:
122 static core& getInstance( void ) noexcept;
168 bool init( const getTickFcn_t tFcn = nullptr, taskFcn_t callbackIdle = nullptr ) noexcept;
197 bool add( task &Task, taskFcn_t callback, const priority_t p, const duration_t t, const iteration_t n, const taskState s = taskState::ENABLED_STATE, void *arg = nullptr ) noexcept;
212 inline bool add( task &Task, taskFcn_t callback, const priority_t p, void *arg = nullptr ) noexcept
213 {
214 return add( Task, callback, p, clock::IMMEDIATE, task::SINGLE_SHOT, taskState::DISABLED_STATE, arg );
215 }
216 #if ( Q_FSM == 1 )
241 bool add( task &Task, stateMachine &m, const priority_t p, const duration_t t, const taskState s = taskState::ENABLED_STATE, void *arg = nullptr ) noexcept;
243 #endif
244 #if ( Q_CLI == 1 )
262 bool add( task &Task, commandLineInterface &cli, const priority_t p, void *arg = nullptr ) noexcept;
264 #endif
271 bool setIdleTask( taskFcn_t callback ) noexcept;
278 bool setNameIdleTask( const char *tName ) noexcept;
283 bool schedulerRelease( void ) noexcept;
290 bool setSchedulerReleaseCallback( taskFcn_t callback ) noexcept;
296 bool remove( task &Task ) noexcept;
304 bool run( void ) noexcept;
305
337 bool notify( notifyMode mode, task &Task, void* eventData = nullptr ) noexcept;
348 bool notify( notifyMode mode, void* eventData = nullptr ) noexcept;
355 bool hasPendingNotifications( const task &Task ) const noexcept;
356
373 bool eventFlagsModify( task &Task, const taskFlag_t tFlags, const bool action ) noexcept;
379 taskFlag_t eventFlagsRead( task &Task ) const noexcept;
404 bool eventFlagsCheck( task &Task, taskFlag_t flagsToCheck, const bool clearOnExit = true, const bool checkForAll = false ) noexcept;
413 task* getTaskByName( const char *name ) noexcept;
420 task* getTaskByID( size_t id ) noexcept;
430 bool yieldToTask( task &Task ) noexcept;
439 globalState getGlobalState( task &Task ) const noexcept;
447 bool add( input::watcher &w ) noexcept;
454 bool remove( input::watcher &w ) noexcept;
455 };
457 extern core& os; // skipcq: CXX-W2011, CXX-W2009
458
460}
461
462
463#endif /*QOS_CPP_KERNEL*/
static const qOS::duration_t IMMEDIATE
To specify a non-wait time value.
Definition clock.hpp:124
An AT Command Line Interface (CLI) object.
Definition cli.hpp:333
The class to interface the OS.
Definition kernel.hpp:83
bool remove(task &Task) noexcept
Remove the task from the scheduling scheme.
bool yieldToTask(task &Task) noexcept
Yield the control of the current running task to another task.
bool run(void) noexcept
Executes the scheduling scheme. It must be called once after the task pool has been defined.
task * getTaskByID(size_t id) noexcept
Tries to find the task that matches the ID provided.
bool setIdleTask(taskFcn_t callback) noexcept
Set/Change the callback for the Idle-task.
bool setSchedulerReleaseCallback(taskFcn_t callback) noexcept
Set/Change the scheduler release callback function.
task * getTaskByName(const char *name) noexcept
Tries to find the task that matches the name provided.
bool add(task &Task, taskFcn_t callback, const priority_t p, const duration_t t, const iteration_t n, const taskState s=taskState::ENABLED_STATE, void *arg=nullptr) noexcept
Add a task to the scheduling scheme. The task is scheduled to run every t time units,...
bool init(const getTickFcn_t tFcn=nullptr, taskFcn_t callbackIdle=nullptr) noexcept
Task Scheduler initialization. This core method is required and must be called once in the applicatio...
static const priority_t HIGHEST_PRIORITY
A constant that holds the value of the highest priority.
Definition kernel.hpp:117
bool setNameIdleTask(const char *tName) noexcept
Set the name for the idle task.
globalState getGlobalState(task &Task) const noexcept
Retrieve the task global-state.
static const priority_t LOWEST_PRIORITY
A constant that holds the value of the lowest priority.
Definition kernel.hpp:113
bool schedulerRelease(void) noexcept
Disables the kernel scheduling. The main thread will continue after the core::run() call.
static const priority_t MEDIUM_PRIORITY
A constant that holds the value of the medium priority.
Definition kernel.hpp:115
static core & getInstance(void) noexcept
Returns a reference to the OS control instance.
A list object (Generic double-linked)
Definition list.hpp:119
A FSM(Finite State Machine) object.
Definition fsm.hpp:822
A task node object.
Definition task.hpp:348
static const iteration_t SINGLE_SHOT
A constant to indicate that the task will be executed only once after its time has expired.
Definition task.hpp:600
bool add(task &Task, commandLineInterface &cli, const priority_t p, void *arg=nullptr) noexcept
Add a task to the scheduling scheme running an AT Command Line Interface. Task will be scheduled as e...
timeCount_t duration_t
The typedef that specified an time quantity, usually expressed in milliseconds.
Definition clock.hpp:18
clock_t(*)(void) getTickFcn_t
Pointer to a function that gets the current hardware tick value.
Definition clock.hpp:74
#define Q_PRIORITY_LEVELS
Number of priority levels.
Definition config.h:24
#define Q_PRIO_QUEUE_SIZE
The size of the priority queue.
Definition config.h:30
bool eventFlagsCheck(task &Task, taskFlag_t flagsToCheck, const bool clearOnExit=true, const bool checkForAll=false) noexcept
Check for flags set to true inside the task Event-Flags.
bool eventFlagsModify(task &Task, const taskFlag_t tFlags, const bool action) noexcept
Modify the EventFlags for the provided task.
constexpr taskFlag_t EVENT_FLAG(index_t i)
Event flag selector function.
Definition kernel.hpp:72
taskFlag_t eventFlagsRead(task &Task) const noexcept
Returns the current value of the task's EventFlags.
uint32_t taskFlag_t
A 32-bit unsigned integer type to hold the task flags.
Definition task.hpp:299
bool add(task &Task, stateMachine &m, const priority_t p, const duration_t t, const taskState s=taskState::ENABLED_STATE, void *arg=nullptr) noexcept
Add a task to the scheduling scheme running a dedicated state-machine. The task is scheduled to run e...
notifyMode
An enum that defines the modes in which a notification can be delivered.
Definition kernel.hpp:45
bool hasPendingNotifications(const task &Task) const noexcept
Check if the supplied task has pending notifications.
bool notify(notifyMode mode, task &Task, void *eventData=nullptr) noexcept
Sends a notification generating an asynchronous event. If mode = notifyMode::SIMPLE,...
core & os
The predefined instance of the OS kernel interface.
void(*)(event_t) taskFcn_t
Pointer to a task callback.
Definition task.hpp:289
globalState
An enum to describe the task global states.
Definition task.hpp:86
taskState
An enum that defines the possible task operational states.
Definition task.hpp:247
@ DISABLED_STATE
In this state, the time events will be discarded. This operational state is available when the ENABLE...
@ ENABLED_STATE
The task can catch all the events. This operational state is available when the ENABLE bit is set.
STD_TYPE_SIZE_T index_t
A type to instantiate an OS index variable. Can store the maximum size of a theoretically possible ob...
Definition types.hpp:94
STD_TYPE_INT32_T iteration_t
A type to instantiate a variable that hold the number of task iterations.
Definition types.hpp:104
STD_TYPE_UINT8_T priority_t
A type to instantiate a variable to hold the priority value of a task.
Definition types.hpp:109
OS/Kernel interfaces.
Definition bytebuffer.hpp:7