Idle Task
In uC/OS, the Idle task is just busy waiting:
It will wait until there are some tasks getting ready. But it will keep the MCU in full speed mode.
In embassy, when there is no task to poll, the executor will sleep and the MCU will be turned into low power mode. So in the func of idle , we can follow the pattern of embassy, just make our MCU sleep in the func of idle.
We can
wfe
our MCU when the ready queue of the executor is empty in blinky is mainly because there is only one thread. If there are many threads in the system and we just wfe
our MCU in embassy, other thread may be affected. So we can only wfe
our MCU when there is no thread is ready. Because if there is no thread ready, the idle will be scheduled, so we can wfe
our MCU in the func of idle.Maybe we have no need to the idle?
SysTick
In uC/OS, the systick ISR looks like:
It just update the delay value of the thread, but because we use embassy to realize the delay of thread(if all tasks in a thread is delayed, the thread will be delayed). So maybe there is no need to the systick ISR? We decided to retain the SysTick, but change the scheduling algorithm. The scheduling algorithm will be coded in os_sched, so there is no need to the Systick ISR. We just use the
os_sched
(or os_sched_new
) in os_int_exit
to implement the scheduling algorithm.the SYST is in file
~external/39ef3fd2-74df-47b2-b551-a7d1ba65b336/mod.rs
, which is used to define Core peripherals(such as NVIC, SYST and so on). And in file syst.rs, there are some useful func to set the systick timer directly. For the code is so long that I won’t paste it here.After find the task should be scheduled, we should update the stride of the task, regardless of whether the scheduled task is the current task or not.
there are there point the stride should be updated: 1.before
OSStartHighRdy
; 2.in os_sched
;3.in os_int_exit
.