/* Start the first task. */ __asm volatile ( " ldr r0, =0xE000ED08 \n"/* Use the NVIC offset register to locate the stack. */ " ldr r0, [r0] \n" " ldr r0, [r0] \n" " msr msp, r0 \n"/* Set the msp back to the start of the stack. */ " cpsie i \n"/* Globally enable interrupts. */ " cpsie f \n" " dsb \n" " isb \n" " svc 0 \n"/* System call to start first task. */ " nop \n" " .ltorg \n" ); }
//the table is defined for signal mechanism uint32_t BlockedBitTable = 0;
/*The RTOS delay will switch the task.It is used to liberate low-priority task*/ void TaskDelay( uint16_t ticks ) { uint32_t WakeTime = TicksBase + ticks; TCB_t *self = pxCurrentTCB; if( WakeTime < TicksBase) { OverWakeTicksTable[self->uxPriority] = WakeTime; } else { WakeTicksTable[self->uxPriority] = WakeTime; } /* This is a useless operation(for DelayBitTable), it can be discarded. * But it is retained for the sake of normativity.For example, view the status of all current tasks.*/ DelayBitTable |= (1 << (self->uxPriority) ); ReadyBitTable &= ~(1 << (self->uxPriority) ); switchTask(); }
void CheckTicks( void ) { TicksBase += 1; if( TicksBase == 0){ TicksTableSwitch( ); } for(int i=0 ; i < configMaxPriori;i++) { if( WakeTicksTable[i] > 0) { if ( TicksBase >= WakeTicksTable[i] ) { WakeTicksTable[i] = 0; DelayBitTable &= ~(1 << i );//it is retained for the sake of normativity. ReadyBitTable |= (1 << i); } } } switchTask(); }
//Task Area!The user must create task handle manually because of debugging and specification TaskHandle_t tcbTask1 = NULL; TaskHandle_t tcbTask2 = NULL;