/** * @ingroup SystemInit * This function will startup scheduler. It will select one thread * with the highest priority level, then switch to it. */ void rt_system_scheduler_start(void) { register struct rt_thread *to_thread; register rt_ubase_t highest_ready_priority; #if RT_THREAD_PRIORITY_MAX > 32 register rt_ubase_t number; number = __rt_ffs(rt_thread_ready_priority_group) - 1; highest_ready_priority = (number << 3) + __rt_ffs(rt_thread_ready_table[number]) - 1; #else highest_ready_priority = __rt_ffs(rt_thread_ready_priority_group) - 1; #endif /* get switch to thread */ to_thread = rt_list_entry(rt_thread_priority_table[highest_ready_priority].next, struct rt_thread, tlist); rt_current_thread = to_thread; /* switch to new thread */ rt_hw_context_switch_to((rt_uint32_t)&to_thread->sp); /* never come back */ }
static void _signal_entry(void* parameter) { rt_thread_t tid = rt_thread_self(); dbg_enter; /* handle signal */ rt_thread_handle_sig(RT_FALSE); /* never come back... */ rt_hw_interrupt_disable(); /* return to thread */ tid->sp = tid->sig_ret; tid->sig_ret = RT_NULL; dbg_log(DBG_LOG, "switch back to: 0x%08x\n", tid->sp); tid->stat &= ~RT_THREAD_STAT_SIGNAL; rt_hw_context_switch_to((rt_uint32_t)&(tid->sp)); }