OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
task.hpp
1#ifndef QOS_CPP_TASK
2#define QOS_CPP_TASK
3
4#include "include/types.hpp"
5#include "include/timer.hpp"
6#include "include/list.hpp"
7#include "include/queue.hpp"
8
9namespace qOS {
10
82
86 enum class globalState : uint8_t {
87 UNDEFINED,
88 READY,
89 WAITING,
90 SUSPENDED,
91 RUNNING
92 };
93
95 class task;
99 #ifdef DOXYGEN
105 class event_t {
106 protected:
108 trigger Trigger{ trigger::None };
109 bool FirstCall{ false };
110 bool FirstIteration{ false };
111 bool LastIteration{ false };
112 clock_t StartDelay{ 0u };
113 task* currentTask{ nullptr };
114 _Event() = default;
116 public:
121 void *TaskData{ nullptr };
128 void *EventData{ nullptr };
133 inline bool firstCall( void ) const noexcept
134 {
135 return FirstCall;
136 }
144 inline bool firstIteration( void ) const noexcept
145 {
146 return FirstIteration;
147 }
156 inline bool lastIteration( void ) const noexcept
157 {
158 return LastIteration;
159 }
164 inline trigger getTrigger( void ) const noexcept
165 {
166 return Trigger;
167 }
177 inline clock_t startDelay( void ) const noexcept
178 {
179 return StartDelay;
180 }
184 inline task& thisTask( void ) noexcept
185 {
186 return *currentTask;
187 }
188 };
189 #endif
190
192 class taskEvent {
193 protected:
194 trigger Trigger{ trigger::None };
195 bool FirstCall{ false };
196 bool FirstIteration{ false };
197 bool LastIteration{ false };
198 clock_t StartDelay{ 0U };
199 task* currentTask{ nullptr };
200 taskEvent() = default;
201 public:
203 virtual ~taskEvent(){}
205 void *TaskData{ nullptr };
206 void *EventData{ nullptr };
207 inline bool firstCall( void ) const noexcept
208 {
209 return FirstCall;
210 }
211 inline bool firstIteration( void ) const noexcept
212 {
213 return FirstIteration;
214 }
215 inline bool lastIteration( void ) const noexcept
216 {
217 return LastIteration;
218 }
219 inline trigger getTrigger( void ) const noexcept
220 {
221 return Trigger;
222 }
223 inline clock_t startDelay( void ) const noexcept
224 {
225 return StartDelay;
226 }
227 inline task& self( void ) noexcept
228 {
229 return *currentTask;
230 }
231 inline task& thisTask( void ) noexcept
232 {
233 return *currentTask;
234 }
235 };
236 using event_t = taskEvent&;
247 enum class taskState {
252 DISABLED_STATE = 0,
257 ENABLED_STATE = 1,
264 AWAKE_STATE = 2,
272 ASLEEP_STATE = 3,
273 };
274
279 enum class queueLinkMode : uint32_t {
280 QUEUE_RECEIVER = 4U,
281 QUEUE_FULL = 8U,
282 QUEUE_COUNT = 16U,
283 QUEUE_EMPTY = 32U,
284 };
285
289 using taskFcn_t = void (*)( event_t );
291 using notifier_t = uint32_t;
292
299 using taskFlag_t = uint32_t;
300
348 class task : protected node {
349 friend class core;
350 private:
351 void *taskData{ nullptr };
352 void *asyncData{ nullptr };
353 taskFcn_t callback{ nullptr };
354 void *aObj{ nullptr };
355 queue *aQueue{ nullptr };
356 size_t aQueueCount{ 0UL };
357 char name[ 11 ] = ""; // skipcq: CXX-W2066, CXX-W2066
358 timer time;
359 cycles_t cycles{ 0UL };
360 size_t entry{ SIZE_MAX };
361 iteration_t iterations{ 0 };
362 volatile notifier_t notifications{ 0UL };
363 volatile taskFlag_t flags{ 0UL };
364 priority_t priority{ 0U };
365 trigger Trigger{ trigger::None };
366 void setFlags( const uint32_t xFlags, const bool value ) noexcept;
367 bool getFlag( const uint32_t flag ) const noexcept;
368 bool deadLineReached( void ) const noexcept;
369 trigger queueCheckEvents( void ) noexcept;
370 static const uint32_t BIT_INIT;
371 static const uint32_t BIT_ENABLED;
372 static const uint32_t BIT_QUEUE_RECEIVER;
373 static const uint32_t BIT_QUEUE_FULL;
374 static const uint32_t BIT_QUEUE_COUNT;
375 static const uint32_t BIT_QUEUE_EMPTY;
376 static const uint32_t BIT_SHUTDOWN;
377 static const uint32_t BIT_REMOVE_REQUEST;
378 static const uint32_t EVENT_FLAGS_MASK;
379 static const uint32_t QUEUE_FLAGS_MASK;
380 task( task const& ) = delete;
381 void operator=( task const& ) = delete;
382 protected:
383 virtual void activities( event_t e );
384 public:
385 task() = default;
386 virtual ~task(){}
391 priority_t getPriority( void ) const noexcept;
397 bool setPriority( const priority_t pValue ) noexcept;
403 cycles_t getCycles( void ) const noexcept;
410 taskState getState( void ) const noexcept;
429 bool setState( const taskState s ) noexcept;
435 inline bool suspend( void ) noexcept
436 {
438 }
444 inline bool disable( void ) noexcept
445 {
447 }
453 inline bool resume( void ) noexcept
454 {
456 }
462 inline bool enable( void ) noexcept
463 {
465 }
474 inline bool asleep( void ) noexcept
475 {
477 }
484 inline bool awake( void ) noexcept
485 {
487 }
493 inline bool isEnabled( void ) const noexcept
494 {
495 return ( taskState::ENABLED_STATE == getState() );
496 }
506 void setIterations( const iteration_t iValue ) noexcept;
513 bool setTime( const qOS::duration_t tValue ) noexcept;
521 bool setCallback( const taskFcn_t tCallback ) noexcept;
527 bool setData( void *arg ) noexcept;
537 bool setName( const char *tName ) noexcept;
543 const char* getName( void ) const noexcept;
548 size_t getID( void ) const noexcept;
577 bool attachQueue( queue &q, const queueLinkMode mode, const size_t arg = 1U ) noexcept;
583 void * const & getBindedObject( void ) const noexcept;
588 queue* getQueue( void ) noexcept;
592 static const iteration_t PERIODIC;
601 };
602
604}
605
606
607#endif /*QOS_CPP_TASK*/
The class to interface the OS.
Definition kernel.hpp:83
The task argument with all the regarding information of the task execution.
Definition task.hpp:105
bool firstIteration(void) const noexcept
Checks whether the current pass is the first iteration of the task. The value returned by this method...
Definition task.hpp:144
clock_t startDelay(void) const noexcept
return the number of epochs between current system time and point in time when the task was marked as...
Definition task.hpp:177
void * TaskData
Task arguments defined at the time of its creation. (Storage-Pointer)
Definition task.hpp:121
trigger getTrigger(void) const noexcept
Get the event source that triggers the task execution. Possible values are described in the qOS::trig...
Definition task.hpp:164
void * EventData
Associated data of the event. Specific data will reside here according to the event source....
Definition task.hpp:128
bool firstCall(void) const noexcept
Checks whether the task is running for the first time. Can be used for data initialization purposes.
Definition task.hpp:133
bool lastIteration(void) const noexcept
Checks whether the current pass is the last iteration of the task. The value returned by this method ...
Definition task.hpp:156
task & thisTask(void) noexcept
return the current task node being evaluated
Definition task.hpp:184
A list-node object (Used internally)
Definition list.hpp:62
A Queue object.
Definition queue.hpp:44
A task node object.
Definition task.hpp:348
bool awake(void) noexcept
Put the task into a normal operation state. Here the task will be able to catch any kind of events.
Definition task.hpp:484
size_t getID(void) const noexcept
Retrieves the Task ID number.
bool setPriority(const priority_t pValue) noexcept
Set/Change the task priority value.
priority_t getPriority(void) const noexcept
Retrieve the current task priority.
task()=default
bool setData(void *arg) noexcept
Set the task data.
bool enable(void) noexcept
Put the task into a enabled state.
Definition task.hpp:462
bool disable(void) noexcept
Put the task into a disabled state.
Definition task.hpp:444
bool setTime(const qOS::duration_t tValue) noexcept
Set/Change the Task execution interval.
static const iteration_t PERIODIC
A constant to indicate that the task will run every time its timeout has expired.
Definition task.hpp:592
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
void *const & getBindedObject(void) const noexcept
Retrieves a pointer to the object binded to the task, could be either a state-machine or a command-li...
queue * getQueue(void) noexcept
Retrieves a pointer to the queue attached to the task.
static const iteration_t INDEFINITE
Same as PERIODIC. A constant to indicate that the task will run every time its timeout has expired.
Definition task.hpp:596
const char * getName(void) const noexcept
Retrieves the task name.
bool suspend(void) noexcept
Put the task into a disabled state.
Definition task.hpp:435
virtual ~task()
Definition task.hpp:386
taskState getState(void) const noexcept
Retrieve the task operational state.
bool setState(const taskState s) noexcept
Set the task operational state.
bool asleep(void) noexcept
Put the task into a sleep state. The task can't be triggered by the lower precedence events.
Definition task.hpp:474
void setIterations(const iteration_t iValue) noexcept
Set/Change the number of task iterations.
virtual void activities(event_t e)
bool setName(const char *tName) noexcept
Set the task name.
cycles_t getCycles(void) const noexcept
Retrieve the number of task activations.
bool attachQueue(queue &q, const queueLinkMode mode, const size_t arg=1U) noexcept
Attach a queue to the Task.
bool isEnabled(void) const noexcept
Retrieve the enabled/disabled state.
Definition task.hpp:493
bool setCallback(const taskFcn_t tCallback) noexcept
Set/Change the task callback function.
bool resume(void) noexcept
Put the task into a enabled state.
Definition task.hpp:453
timeCount_t duration_t
The typedef that specified an time quantity, usually expressed in milliseconds.
Definition clock.hpp:18
timeCount_t clock_t
A unsigned integer to hold ticks count. Epochs counter.
Definition clock.hpp:15
uint32_t taskFlag_t
A 32-bit unsigned integer type to hold the task flags.
Definition task.hpp:299
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
queueLinkMode
An enum that defines the modes in which a queue can be linked to a task.
Definition task.hpp:279
trigger
An enum with all the possible values for the event_t::getTrigger() method.
Definition task.hpp:23
uint32_t notifier_t
A 32-bit unsigned integer type to hold a notification value.
Definition task.hpp:291
taskState
An enum that defines the possible task operational states.
Definition task.hpp:247
@ bySchedulingRelease
When the scheduler is released.
@ byQueueReceiver
When there are elements available in the attached queue, the scheduler make a data dequeue (auto-rece...
@ byNoReadyTasks
Only available when the Idle Task is triggered.
@ byQueueFull
When the attached queue is full. A pointer to the queue will be available in the event_t::EventData f...
@ None
To indicate the absence of trigger. Reserved for internal use.
@ byQueueEmpty
When the attached queue is empty. A pointer to the queue will be available in the event_t::EventData ...
@ byNotificationSimple
When the execution chain does, according to a requirement of asynchronous notification event prompted...
@ byTimeElapsed
When the time specified for the task elapsed.
@ byNotificationQueued
When there is a queued notification in the FIFO priority queue. For this trigger, the dispatcher perf...
@ byQueueCount
When the element-count of the attached queue reaches the specified value. A pointer to the queue will...
@ byEventFlags
When any event-flag is set.
@ DISABLED_STATE
In this state, the time events will be discarded. This operational state is available when the ENABLE...
@ ASLEEP_STATE
Task operability is put into a deep doze mode, so the task can not be triggered by the lower preceden...
@ AWAKE_STATE
In this state, the task is conceptually in an alert mode, handling most of the available events....
@ ENABLED_STATE
The task can catch all the events. This operational state is available when the ENABLE bit is set.
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_UINT32_T cycles_t
A type to instantiate a variable that hold the number of task cycles.
Definition types.hpp:99
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