Beispiel #1
0
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();  

}
Beispiel #2
0
/*
************************************************************************************************************************
*                                    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();  

}
Beispiel #3
0
/*
************************************************************************************************************************
*                                       Start raw os first task
*
* Description: This function is called to start raw os first task.
*
* Arguments  :None
*                 -----
*                 
*
*				         
* Returns		RAW_U16:	RAW_SYSTEM_ERROR.
*						
* Note(s)    This function shoud not returned!	
*
*             
************************************************************************************************************************
*/
RAW_U16 raw_os_start(void)
{

	if (raw_os_active == RAW_OS_STOPPED) {
		
		get_ready_task(&raw_ready_queue);
		
		/*done it here, so doesn't need do it in raw_start_first_task*/
		raw_task_active = high_ready_obj;
		raw_os_active = RAW_OS_RUNNING;
		
		raw_start_first_task(); 
	} 

	else {

		return RAW_OS_RUNNING;

	}

	return RAW_SYSTEM_ERROR;
	
}
Beispiel #4
0
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();

		}
			
	}
		
}