#include #include #include #include #include"scheduler.h" #include"error.h" #include"settings.h" #include"heap.h" /* TCBs */ static osTCB_t tasks[MAX_NUMBER_OF_TASKS]; static uint8_t task_cnt = 0; /* Scheduler */ static uint8_t scheduler_initialized = 0; static osSchedulerState_t state = S_INIT; static osHeapNode_t current = NULL; /* Timing */ static uint32_t sys_clk = 0; /* Queues */ static osHeapNode_t ready_q[HEAP_SIZE]; static inline osTCB_t* osSchedulerGetRunningT(void) { for(int i=0; ifnc_ptr = NULL; } void osTaskDelay(uint8_t idelay) { osTCB_t* task_running = osSchedulerGetRunningT(); task_running->state = BLOCKED; task_running->wake_up = sys_clk + idelay; } void osTaskDelayUntil(uint32_t iwakeup_time, uint8_t idelay) { osTCB_t* task_running = osSchedulerGetRunningT(); task_running->state = BLOCKED; task_running->wake_up = iwakeup_time + idelay; } uint8_t osRunScheduler(void) { printf("System clock: %d\n", ++sys_clk); /* Are any tasks becomming ready? */ for(int i=0; istate = RUNNING; state = S_EXECUTING_TASK; (*(current->fnc_ptr))(current->arguments); state = S_EXECUTING_NO_TASK; break; case S_IDELING: printf("S_IDELING\n"); if(!osHeapIsEmpty(ready_q)) state = S_EXECUTING_NO_TASK; break; } } void osPrintTask(uint8_t index) { printf("Function Pointer:\t%p\n", tasks[index].fnc_ptr); printf("Name:\t\t\t%s\n", tasks[index].name); printf("Arguments Pointer:\t%p\n", tasks[index].fnc_ptr); printf("Priority:\t\t%d\n", tasks[index].priority); printf("State:\t\t\t%d\n", tasks[index].state); printf("Wake up:\t\t%d\n", tasks[index].wake_up); } void osPrintAllTasks(void) { for(int i=0; i