14 #include "config/apps.h" 15 #include "config/os.h" 16 #include "config/mcal.h" 18 #include "rtos_typedef.h" 19 #include "boot/rtos_timer.h" 30 #define OSTMR_TIMEOUT 30000 // Timeout protection for OS-Timer interrupt flag bit 39 enum TASK_QUEUE_TYPE_e {
47 typedef enum TASK_QUEUE_TYPE_e TASK_QUEUE_TYPE_t;
56 enum TASK_QUEUE_EXECUTE_OPTION_e {
63 typedef enum TASK_QUEUE_EXECUTE_OPTION_e TASK_QUEUE_EXECUTE_OPTION_t;
65 typedef uint16_t (*FUNCPTR_t)(void);
69 #define NO_OF_TASK_QUEUES 4 76 extern volatile uint16_t Queue_InitializeSequence_Size;
79 extern volatile uint16_t Queue_StartSequence_Size;
82 extern volatile uint16_t Queue_ExecuteSequence_Size;
85 extern volatile uint16_t Queue_StopSequence_Size;
97 static volatile uint16_t* exec_queues_sizes[] = {
98 &Queue_InitializeSequence_Size,
99 &Queue_StartSequence_Size,
100 &Queue_ExecuteSequence_Size,
101 &Queue_StopSequence_Size
105 static volatile uint16_t exec_queues_size = (
sizeof(exec_queues)/
sizeof(exec_queues[0]));
110 struct OS_TASK_QUEUE_s {
112 volatile enum TASK_QUEUE_TYPE_e queueType;
113 volatile uint16_t size;
114 volatile uint32_t exec_time;
115 volatile uint16_t id;
117 typedef struct OS_TASK_QUEUE_s OS_TASK_QUEUE_t;
122 struct OS_TASK_QUEUES_s {
123 volatile uint16_t size;
124 volatile struct OS_TASK_QUEUE_s queues[NO_OF_TASK_QUEUES];
126 typedef struct OS_TASK_QUEUES_s OS_TASK_QUEUES_t;
130 static volatile struct OS_TASK_QUEUES_s os_queues;
133 static volatile bool LowPriorityWait =
true;
137 volatile uint16_t ptrTaskProfileArray;
138 volatile uint16_t arrTaskProfile[2][TASK_PROFILE_ARR_SIZE];
142 static volatile uint16_t rtos_Initialize(
void);
143 static volatile uint16_t rtos_Start(
void);
144 static volatile uint16_t rtos_Queue_Execute(TASK_QUEUE_TYPE_t type, TASK_QUEUE_EXECUTE_OPTION_t priority);
145 static volatile uint16_t rtos_Task_Execute(
volatile FUNCPTR_t fptr,
volatile int32_t* exec_loops,
volatile int32_t* exec_time);
147 static volatile uint16_t __attribute__((always_inline))rtos_TaskExecCounter_Update(
void);
159 volatile uint16_t rtos_Stop(
void)
161 volatile uint16_t retval=1;
164 retval &= rtos_Queue_Execute(QUEUE_STOP, QUEUE_EXEC_ALL);
183 volatile uint16_t rtos_End(
void)
185 volatile uint16_t retval=1;
188 retval &= rtos_Queue_Execute(QUEUE_STOP, QUEUE_EXEC_ALL);
218 volatile uint16_t rtos_Execute(
void)
220 volatile uint16_t retval = 1;
221 volatile uint16_t timeout = 0;
224 retval &= rtos_Initialize();
227 retval &= rtos_Start();
233 while ((LowPriorityWait) && (timeout++ < OSTMR_TIMEOUT));
238 retval &= rtos_Queue_Execute(QUEUE_EXECUTE, QUEUE_EXEC_LP);
244 LowPriorityWait =
true;
266 void __attribute__((__interrupt__, context, no_auto_psv))
_OsTimerInterrupt(
void)
268 volatile uint16_t retval=1;
276 rtos_TaskExecCounter_Update();
279 retval &= rtos_Queue_Execute(QUEUE_EXECUTE, QUEUE_EXEC_HP);
282 LowPriorityWait =
false;
298 static volatile uint16_t rtos_Initialize(
void)
300 volatile uint16_t retval=1;
301 volatile uint16_t _i=0;
302 volatile uint16_t _j=0;
308 os_queues.size = exec_queues_size;
311 for (_i=0; _i<exec_queues_size; _i++)
313 os_queues.queues[_i].ptrQueue = (
volatile struct APPLICATION_TASK_s**)exec_queues[_i];
314 os_queues.queues[_i].size = *exec_queues_sizes[_i];
315 os_queues.queues[_i].queueType = _i;
316 os_queues.queues[_i].id = 100 * (os_queues.queues[_i].queueType + 1);
317 os_queues.queues[_i].exec_time = 0;
320 for (_j=0; _j<os_queues.queues[_i].size; _j++)
322 os_queues.queues[_i].ptrQueue[_j]->TaskID =
323 ((100 * os_queues.queues[_i].ptrQueue[_j]->Settings.execClass) + _j);
325 os_queues.queues[_i].ptrQueue[_j]->Status.busy =
false;
326 os_queues.queues[_i].ptrQueue[_j]->Status.retval =
false;
333 retval &= osTimer_Initialize();
348 static volatile uint16_t rtos_Start(
void)
350 volatile uint16_t retval=1;
353 retval &= osTimer_Enable(
false, 0);
356 retval &= rtos_Queue_Execute(QUEUE_INITIALIZE, QUEUE_EXEC_ALL);
359 retval &= rtos_Queue_Execute(QUEUE_START, QUEUE_EXEC_ALL);
387 static volatile uint16_t rtos_Queue_Execute(TASK_QUEUE_TYPE_t type, TASK_QUEUE_EXECUTE_OPTION_t priority)
389 volatile uint16_t retval=1;
390 volatile int32_t _tretval=0;
391 volatile int32_t* _tloops=0;
394 volatile uint16_t _i=0;
395 volatile uint16_t _size=0;
396 volatile uint16_t _ptr_offset=0;
397 volatile uint16_t* _ptr;
400 volatile bool _exec=
false;
401 volatile int32_t _tdiff=0;
410 _size = os_queues.queues[type].size;
411 _ptr_offset =
sizeof(exec_queues[type]);
414 if (priority == QUEUE_EXEC_HP) task_manager.
Status.bits.
hp_active =
true;
415 if (priority == QUEUE_EXEC_LP) task_manager.
Status.bits.
lp_active =
true;
418 for (_i=0; _i<_size; _i++) {
421 if (priority == QUEUE_EXEC_ALL)
424 if (os_queues.queues[type].ptrQueue[_i]->Status.enabled)
426 if ((
int)os_queues.queues[type].ptrQueue[_i]->Settings.execClass == (int)priority)
428 _tdiff = (os_queues.queues[type].ptrQueue[_i]->Settings.Period +
429 os_queues.queues[type].ptrQueue[_i]->Settings.Offset);
430 _exec = (bool)(os_queues.queues[type].ptrQueue[_i]->Settings.Counter >= _tdiff);
439 _ptr = (uint16_t *)&os_queues.queues[type].ptrQueue[_i]->Functions.Initialize;
441 _tloops = &os_queues.queues[type].ptrQueue[_i]->Settings.Counter;
443 os_queues.queues[type].ptrQueue[_i]->Status.busy =
true;
445 retval = rtos_Task_Execute((FUNCPTR_t)(*_ptr), _tloops, &_tretval);
447 os_queues.queues[type].ptrQueue[_i]->Status.retval = retval;
448 os_queues.queues[type].ptrQueue[_i]->Status.busy =
false;
453 rtos_TaskExecCounter_Update();
457 _tdiff = os_queues.queues[type].ptrQueue[_i]->Settings.Counter;
458 _tdiff -= os_queues.queues[type].ptrQueue[_i]->Settings.Offset;
459 _tdiff -= os_queues.queues[type].ptrQueue[_i]->Settings.Period;
460 _tdiff += os_queues.queues[type].ptrQueue[_i]->Settings.Offset;
461 os_queues.queues[type].ptrQueue[_i]->Settings.Counter = _tdiff;
485 static volatile uint16_t rtos_Task_Execute(
volatile FUNCPTR_t fptr,
volatile int32_t* exec_loops,
volatile int32_t* exec_time)
487 volatile uint16_t retval=1;
490 volatile uint16_t _start=0, _stop=0;
491 volatile uint32_t _pre_loop_cnt=0, _loops=0;
492 volatile uint32_t _texec=0;
501 _pre_loop_cnt = *exec_loops;
513 _loops = (*exec_loops - _pre_loop_cnt);
519 _texec = (uint32_t)(_stop - _start);
524 _texec += (uint32_t)_stop;
530 _texec += (uint32_t)_stop;
552 static volatile uint16_t rtos_TaskExecCounter_Update(
void)
554 volatile uint16_t retval=1;
555 volatile uint16_t _i=0;
556 volatile uint16_t _toff=0;
562 for (_i=0; _i<Queue_ExecuteSequence_Size; _i++) {
volatile struct APPTASK_EXECUTION_s Settings
Execution time settings of the task object.
unsigned disable
When set, causes the execution of main() to be terminated resulting in a CPU reset.
unsigned hp_active
Bit 1: Flag indicating that low-priority task queue is executed frequently.
volatile struct OS_TASKMGR_TIMEBASE_s Timebase
Task manager time base monitor.
#define _OSTIMER_TMRCAP
Timer period counter register.
volatile int32_t Counter
Operating system task execution tick counter.
unsigned lp_active
Bit 0: Flag indicating that high-priority task queue is executed frequently.
#define _OSTIMER_IF
interrupt flag bit
volatile struct OS_TASKMGR_STATUS_s Status
Task manager status word.
#define _OSTIMER_PRIORITY
interrupt priority (1 ... 7, default = 2)
volatile int32_t Counter
Execution period counter (read only)
#define _OsTimerInterrupt
Global state-machine peripheral assignments.
volatile uint16_t value
Status word value.
#define MAIN_EXEC_PER
Global state-machine user-settings conversion macros.