void rt_systick (void) { /* Check for system clock update, suspend running task. */ P_TCB next; os_tsk.run->state = READY; rt_put_rdy_first (os_tsk.run); /* Check Round Robin timeout. */ rt_chk_robin (); /* Update delays. */ os_time++; rt_dec_dly (); /* Check the user timers. */ #ifdef __CMSIS_RTOS sysTimerTick(); #else rt_tmr_tick (); #endif /* Switch back to highest ready task */ next = rt_get_first (&os_rdy); rt_switch_req (next); }
void rt_pop_req (void) { /* Process an ISR post service requests. */ struct OS_XCB *p_CB; P_TCB next; U32 idx; os_tsk.run->state = READY; rt_put_rdy_first (os_tsk.run); idx = os_psq->last; while (os_psq->count) { p_CB = os_psq->q[idx].id; if (p_CB->cb_type == TCB) { /* Is of TCB type */ rt_evt_psh ((P_TCB)p_CB, (U16)os_psq->q[idx].arg); } else if (p_CB->cb_type == MCB) { /* Is of MCB type */ rt_mbx_psh ((P_MCB)p_CB, (void *)os_psq->q[idx].arg); } else { /* Must be of SCB type */ rt_sem_psh ((P_SCB)p_CB); } if (++idx == os_psq->size) { idx = 0U; } rt_dec (&os_psq->count); } os_psq->last = (U8)idx; next = rt_get_first (&os_rdy); rt_switch_req (next); }
void rt_systick (void) { if(NVIC_Pending(SYS_TICK_IRQn)){ rt_pop_req(); NVIC_UnpendIRQ(SYS_TICK_IRQn); SYS_TICK_TIMER->IR = 0xF; // clear timer interrupt return; } /* Check for system clock update, suspend running task. */ P_TCB next; os_tsk.run->state = READY; rt_put_rdy_first (os_tsk.run); /* Check Round Robin timeout. */ rt_chk_robin (); /* Update delays. */ os_time++; rt_dec_dly (); /* Check the user timers. */ #ifdef __CMSIS_RTOS sysTimerTick(); #else rt_tmr_tick (); #endif /* Switch back to highest ready task */ next = rt_get_first (&os_rdy); rt_switch_req (next); SYS_TICK_TIMER->IR = 0xF; // clear timer interrupt }
void rt_resume (U32 sleep_time) { /* Resume OS scheduler after suspend */ P_TCB next; U32 delta; os_tsk.run->state = READY; rt_put_rdy_first (os_tsk.run); os_robin.task = NULL; /* Update delays. */ if (os_dly.p_dlnk) { delta = sleep_time; if (delta >= os_dly.delta_time) { delta -= os_dly.delta_time; os_time += os_dly.delta_time; os_dly.delta_time = 1; while (os_dly.p_dlnk) { rt_dec_dly(); if (delta == 0) break; delta--; os_time++; } } else { os_time += delta; os_dly.delta_time -= delta; } } else { os_time += sleep_time; } /* Check the user timers. */ #ifdef __CMSIS_RTOS sysUserTimerUpdate(sleep_time); #else if (os_tmr.next) { delta = sleep_time; if (delta >= os_tmr.tcnt) { delta -= os_tmr.tcnt; os_tmr.tcnt = 1; while (os_tmr.next) { rt_tmr_tick(); if (delta == 0) break; delta--; } } else { os_tmr.tcnt -= delta; } } #endif /* Switch back to highest ready task */ next = rt_get_first (&os_rdy); rt_switch_req (next); scheduler_suspended = 0; rt_tsk_unlock(); }
void rt_dispatch (P_TCB next_TCB) { /* Dispatch next task if any identified or dispatch highest ready task */ /* "next_TCB" identifies a task to run or has value NULL (=no next task) */ if (next_TCB == NULL) { /* Running task was blocked: continue with highest ready task */ next_TCB = rt_get_first (&os_rdy); rt_switch_req (next_TCB); } else { /* Check which task continues */ if (next_TCB->prio > os_tsk.run->prio) { /* preempt running task */ rt_put_rdy_first (os_tsk.run); os_tsk.run->state = READY; rt_switch_req (next_TCB); } else { /* put next task into ready list, no task switch takes place */ next_TCB->state = READY; rt_put_prio (&os_rdy, next_TCB); } } }