📄 skp.c
字号:
/* */
/* OUTPUTS */
/* */
/* return(SKP_Current_Task_ID) Current task identity */
/* */
/************************************************************************/
/* This routine is optimized in assembly language, see SKD.S */
/* signed int SKP_Get_Task_ID() */
/* { */
/* Just return the current task ID. */
/* return(SKP_Current_Task_ID); */
/* } */ /* end of SKP_Get_Task_ID */
/************************************************************************/
/* */
/* FUNCTION "SKP_Set_Preemption" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function modifies the no preemption count. When this */
/* count is greater than 0, no non-intended suspension of the */
/* associated task will take place. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* NU_* Nucleus user interface */
/* routines */
/* */
/* ROUTINES CALLED */
/* */
/* CLD_Start_System_Timer Start the system timer */
/* CLD_Stop_System_Timer Stop the system timer */
/* SKD_Leave_Task Leave task to context switch*/
/* */
/* INPUTS */
/* */
/* task_id Task to lift suspension on */
/* preempt_request Request to enable or disable*/
/* */
/* OUTPUTS */
/* */
/* return(status) Status of request */
/* */
/************************************************************************/
signed int SKP_Set_Preemption(signed int task_id,
unsigned char preempt_request)
{
struct SK_TASK_CONTROL_BLOCK_STRUCT
*curr_tcb_ptr; /* Current tcb pointer */
signed int status; /* Status of request */
/* Point to the current TCB and its neighbors. */
curr_tcb_ptr = &SKP_TCB_List[task_id];
/* Process according to the preempt_request input. */
if (preempt_request == NU_NO_PREEMPT)
{
/* Determine if there is a time slice active for this task. */
if ((curr_tcb_ptr -> sk_time_slice > 0) &&
(curr_tcb_ptr -> sk_no_preempt == NU_FALSE))
{
/* Delete the time slice. */
CLD_Stop_System_Timer();
}
/* Increment the no preemption count. This will handle nested calls
to this routine. */
curr_tcb_ptr -> sk_no_preempt++;
status = NU_SUCCESS;
}
else if (preempt_request == NU_PREEMPT)
{
/* Decrement the no preemption count. This will handle nested calls
to this routine. */
curr_tcb_ptr -> sk_no_preempt--;
/* Check for a preempt condition that cropped up while preemption
was disabled. */
if ((curr_tcb_ptr -> sk_task_id == SKP_Current_Task_ID) &&
(curr_tcb_ptr -> sk_no_preempt == 0) &&
(curr_tcb_ptr -> sk_ready_prev != NU_NULL))
{
/* Leave the task. */
SKD_Leave_Task();
}
/* Determine if there is a time slice to activate for this task. */
else if ((curr_tcb_ptr -> sk_time_slice > 0) &&
(curr_tcb_ptr -> sk_no_preempt == NU_FALSE))
{
/* Start the time slice. */
CLD_Start_System_Timer(curr_tcb_ptr -> sk_time_slice);
}
/* Check for a bad condition. */
if (curr_tcb_ptr -> sk_no_preempt < 0)
curr_tcb_ptr -> sk_no_preempt = 0;
status = NU_SUCCESS;
}
else
/* return a bad status. */
status = NU_INVALID_SELECTION;
/* Return the status to the caller. */
return(status);
} /* end SKP_Set_Preemption */
/************************************************************************/
/* */
/* FUNCTION "SKP_Set_Time_Slice" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function modifies the maximum time slice allocated for */
/* the specified task id. A request less than or equal to 0 */
/* disables the time slice. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* NU_* Nucleus user interface */
/* routines */
/* */
/* ROUTINES CALLED */
/* */
/* SKP_Get_Task_ID Get the current task ID */
/* CLD_Start_System_Timer Start system timer */
/* CLD_Stop_System_Timer Stop the system timer */
/* */
/* INPUTS */
/* */
/* task_id Task to lift suspension on */
/* time_slice New time slice value */
/* */
/* OUTPUTS */
/* */
/* return(status) Status of request */
/* */
/************************************************************************/
signed int SKP_Set_Time_Slice(signed int task_id, signed int time_slice)
{
struct SK_TASK_CONTROL_BLOCK_STRUCT
*curr_tcb_ptr; /* Current tcb pointer */
/* Point to the current TCB and its neighbors. */
curr_tcb_ptr = &SKP_TCB_List[task_id];
/* Load the new time slice value. */
curr_tcb_ptr -> sk_time_slice = time_slice;
/* Determine if the currently running task is affected. */
if (SKP_Current_Task_ID == curr_tcb_ptr -> sk_task_id)
{
if (time_slice <= 0)
{
/* Delete the time slice timer. */
CLD_Stop_System_Timer();
}
else
{
/* Restart the time slice timer. */
CLD_Start_System_Timer(time_slice);
}
}
/* Return the status to the caller. */
return(NU_SUCCESS);
} /* end SKP_Set_Time_Slice */
/************************************************************************/
/* */
/* FUNCTION "SKP_Time_Slice" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is used handle the situation where a task has */
/* used up all of its allocated time. The result of this is that */
/* the task is placed at the end of the ready list of processes. */
/* It is assumed that the task's saved stack value has already */
/* been setup and that interrupts are disabled upon entry. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* CLP_Process_Timer Process the timer request */
/* */
/* ROUTINES CALLED */
/* */
/* SKP_Move_To_End Move the current tcb to the */
/* end of tcbs of same priority*/
/* CLD_Start_System_Timer Start the system timer */
/* */
/* INPUTS */
/* */
/* None */
/* */
/* OUTPUTS */
/* */
/* Ready task list */
/* */
/************************************************************************/
void SKP_Time_Slice()
{
/* If the preempt flag is not set and the time slice field still has
a positive value, re-schedule the time slice. */
if (!SKP_Move_To_End())
{
/* Restart the time slice timer. */
CLD_Start_System_Timer(SKP_Current_TCB_Ptr -> sk_time_slice);
}
} /* end of SKP_Time_Slice */
/************************************************************************/
/* */
/* FUNCTION "SKP_Retrieve_Status" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function returns status information about the selected */
/* task. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* Nucleus routines that use need task status. */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* task_id Task of interest */
/* Pointer to output */
/* */
/* OUTPUTS */
/* */
/* scheduled_count */
/* return(suspension_status) */
/* */
/************************************************************************/
signed int SKP_Retrieve_Status(signed int task_id,
unsigned int *scheduled_count)
{
/* Get the scheduled count. */
*scheduled_count = SKP_TCB_List[task_id].sk_scheduled;
/* Return the suspension status. */
return(SKP_TCB_List[task_id].sk_suspend);
} /* end of SKP_Retrieve_Status */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -