/*Begin Function:_Sys_Init***************************************************** Description : Initiate The Application Memory Page Allocation. Input : Void. Output : Void. ******************************************************************************/ void _Sys_Init(void) //The Paramount Process;Its PID is 0,forever. { u16 Count; while(1) { DISABLE_ALL_INTS(); #if(ENABLE_SIGNAL==TRUE) for(Count=1;Count<MAX_NUMBER_OF_TASKS+1;Count++) //Process The Signals Here. _Sys_Signal_Handler(Count); #endif //The Code Below Sets The Task Sequence. PCB_TASK_SEQ_PTR=0; //Reset The Process PTR. for(Count=1;Count<MAX_NUMBER_OF_TASKS+2;Count++) { //From 1,For "Init" Do Not Count Here. if(((PCB_PID_STATUS[Count]&OCCUPY)!=0)&&((PCB_PID_STATUS[Count]&SLEEP)==0)&&((PCB_PID_STATUS[Count]&ZOMBIE)==0)) { PCB_REMAINING_TIME[Count]=PCB_TIM[Count]; PCB_TASK_SEQ[PCB_TASK_SEQ_PTR++]=Count; //Find Out The PIDs Occupied&Not Sleeping&Not Zombie And Create The Next Schedule Table. } } PCB_TASK_SEQ[PCB_TASK_SEQ_PTR]=0; //The Last Must Be The Init process,Or The System Will Crash.Remember To Decrease The value By One,Or The System To Crash. PCB_TASK_SEQ_PTR=0; //Reset The Process PTR. ENABLE_ALL_INTS(); Sys_Switch_Now(); } }
/* Begin Function:_Sys_Arch **************************************************** Description : The system service daemon. Now it is usually used as a shell process. It is a system process(just like the init process), but it runs in the user field. Input : None. Output : None. Return : None. ******************************************************************************/ void _Sys_Arch(void) { Sys_Arch_Initial(); while(1) { _Sys_Timer_Reload(); Sys_Arch_Always(); Sys_Switch_Now(); } }
/* Begin Function:_Sys_Init *************************************************** Description : Initiate the system services. Now it is empty. Its PID is 0. Input : None. Output : None. Return : None. ******************************************************************************/ void _Sys_Init(void) { if(System_Status.Kernel.Boot_Done==FALSE) { Sys_Start_On_Boot(); } Sys_Init_Initial(); while(1) { Sys_Init_Always(); Sys_Switch_Now(); } }
void Sys_Proc_Delay_Tick(time_t Time) { struct Tick_Time Stop_Time; struct List_Head* Traverse_List_Ptr; /* If time is zero, then we don't wait at all */ if(Time==0) return; /* If the timer flag is still existent(If we don't cancel the delay) */ if(PCB_Proc_Delay[Current_PID].Delay_Status==1) return; Stop_Time.High_Bits=0; Stop_Time.Low_Bits=Time; /* According to the "OS_Total_Ticks" variable, calculate when we should stop waiting */ Sys_Tick_Time_Add(&Stop_Time, (struct Tick_Time*)&System_Status.Time.OS_Total_Ticks, &Stop_Time); PCB_Proc_Delay[Current_PID].Delay_Status=1; PCB_Proc_Delay[Current_PID].End_Total_Ticks.High_Bits=Stop_Time.High_Bits; PCB_Proc_Delay[Current_PID].End_Total_Ticks.Low_Bits=Stop_Time.Low_Bits; /* We need to find a proper time for insertion */ Traverse_List_Ptr=Proc_Delay_List_Head.Next; while((ptr_int_t)Traverse_List_Ptr!=(ptr_int_t)(&Proc_Delay_List_Head)) { /* Find a place */ if(Sys_Tick_Time_Comp(&PCB_Proc_Delay[Current_PID].End_Total_Ticks, &((struct PCB_Timer*)Traverse_List_Ptr)->End_Total_Ticks)!=1) break; Traverse_List_Ptr=Traverse_List_Ptr->Next; } /* Now put it into the wait list */ Sys_List_Insert_Node(&(PCB_Proc_Delay[Current_PID].Head),Traverse_List_Ptr->Prev,Traverse_List_Ptr); /* At last, remove the process from the running queue, and require a direct reschedule */ _Sys_Clr_Ready(Current_PID); Sys_Switch_Now(); }