void raw_sched(void) { RAW_SR_ALLOC(); /*if it is in interrupt or system is locked, just return*/ if (raw_int_nesting || raw_sched_lock) { return; } USER_CPU_INT_DISABLE(); get_ready_task(&raw_ready_queue); /*if highest task is currently task, then no need to do switch and just return*/ if (high_ready_obj == raw_task_active) { USER_CPU_INT_ENABLE(); return; } TRACE_TASK_SWITCH(raw_task_active, high_ready_obj); CONTEXT_SWITCH(); USER_CPU_INT_ENABLE(); }
/* ************************************************************************************************************************ * Finish interrupt * * Description: This function is called to when exit interrupt. * * Arguments :NONE * * * * * * Returns * * Note(s) * ************************************************************************************************************************ */ void raw_finish_int(void) { RAW_SR_ALLOC(); #if (CONFIG_RAW_ISR_STACK_CHECK > 0) /*if you have no idea how to implement this function just write a blank port function*/ port_isr_stack_check(); #endif /*It should not be zero here*/ RAW_ASSERT(raw_int_nesting != 0); USER_CPU_INT_DISABLE(); raw_int_nesting--; /*if still interrupt nested just return */ if (raw_int_nesting) { USER_CPU_INT_ENABLE(); return; } /*if system is locked then just return*/ if (raw_sched_lock) { USER_CPU_INT_ENABLE(); return; } /*get the highest task*/ get_ready_task(&raw_ready_queue); /*if the current task is still the highest task then we do not need to have interrupt switch*/ if (high_ready_obj == raw_task_active) { USER_CPU_INT_ENABLE(); return; } TRACE_INT_TASK_SWITCH(raw_task_active, high_ready_obj); /*switch to the highest task, this function is cpu related, thus need to be ported*/ raw_int_switch(); USER_CPU_INT_ENABLE(); }
RAW_VOID raw_idle_task (void *p_arg) { RAW_SR_ALLOC(); p_arg = p_arg; /* Make compiler happy ^_^ */ while (1) { USER_CPU_INT_DISABLE(); raw_idle_count++; USER_CPU_INT_ENABLE(); #if (CONFIG_RAW_USER_HOOK > 0) raw_idle_coroutine_hook(); #endif } }
void hybrid_int_process(void) { TASK_0_EVENT_TYPE hybrid_ev; RAW_U8 *hybrid_data_temp; EVENT_HANLDER *hybrid_receiver; LIST *hybrid_node; RAW_U8 hybrid_highest_pri; RAW_SR_ALLOC(); register RAW_U8 hybrid_task_may_switch = 0u; while (1) { USER_CPU_INT_DISABLE(); if (task_0_events) { /*current running task can never be task 0*/ if (raw_int_nesting) { raw_sched_lock = 0; USER_CPU_INT_ENABLE(); return; } else { --task_0_events; /* There are events that we should deliver. */ hybrid_ev = task_0_events_queue[task_0_event_end].ev; hybrid_data_temp = task_0_events_queue[task_0_event_end].event_data; hybrid_receiver = task_0_events_queue[task_0_event_end].p; task_0_event_end++; if (task_0_event_end == MAX_TASK_EVENT) { task_0_event_end = 0; } USER_CPU_INT_ENABLE(); /*exceute the event handler*/ hybrid_receiver->handle_event(hybrid_ev, hybrid_data_temp); hybrid_task_may_switch = 1; } } else { raw_sched_lock = 0; if (hybrid_task_may_switch) { hybrid_highest_pri = raw_ready_queue.highest_priority; /*Highest priority task must be the first element on the list*/ hybrid_node = raw_ready_queue.task_ready_list[hybrid_highest_pri].next; /*Get the highest priority task object*/ high_ready_obj = raw_list_entry(hybrid_node, RAW_TASK_OBJ, task_list); /*if highest task is currently task, then no need to do switch and just return*/ if (high_ready_obj == raw_task_active) { USER_CPU_INT_ENABLE(); return; } CONTEXT_SWITCH(); } USER_CPU_INT_ENABLE(); return; } } }
static void task_0_process(void *pa) { TASK_0_EVENT_TYPE ev; RAW_U8 *data_temp; EVENT_HANLDER *receiver; RAW_SR_ALLOC(); pa = pa; /*to prevent interrupt happen here to cause system crash at task 0 start*/ USER_CPU_INT_DISABLE(); remove_ready_list(&raw_ready_queue, &raw_task_0_obj); USER_CPU_INT_ENABLE(); while (1) { /*Get the message info and update it*/ USER_CPU_INT_DISABLE(); if (task_0_events) { --task_0_events; /* There are events that we should deliver. */ ev = task_0_events_queue[task_0_event_end].ev; data_temp = task_0_events_queue[task_0_event_end].event_data; receiver = task_0_events_queue[task_0_event_end].p; task_0_event_end++; if (task_0_event_end == MAX_TASK_EVENT) { task_0_event_end = 0u; } /*lock the scheduler, so event handler can not be switched out*/ raw_sched_lock = 1u; USER_CPU_INT_ENABLE(); /*exceute the event handler*/ receiver->handle_event(ev, data_temp); } else { /*unlock the scheduler, so scheduler can work*/ raw_sched_lock = 0u; get_ready_task(&raw_ready_queue); CONTEXT_SWITCH(); USER_CPU_INT_ENABLE(); } } }