📄 skp.c
字号:
/* Setup pointers to the current TCB pointer and the next one. */
curr_tcb_ptr = SKP_Current_TCB_Ptr;
next_tcb_ptr = curr_tcb_ptr -> sk_ready_next;
prev_tcb_ptr = NU_NULL;
/* Look for the place in the ready list to place the current tcb. */
while ((next_tcb_ptr != NU_NULL) &&
(next_tcb_ptr -> sk_priority == curr_tcb_ptr -> sk_priority))
{
/* Keep going through the tcbs of the same priority. */
prev_tcb_ptr = next_tcb_ptr;
next_tcb_ptr = next_tcb_ptr -> sk_ready_next;
}
/* Check to see if this one even needs to be moved. */
if (prev_tcb_ptr != NU_NULL)
{
/* First, unlink the current tcb. */
if (curr_tcb_ptr -> sk_ready_prev == NU_NULL)
{
/* Remove from the front of the list. */
SKP_Ready_List_Ptr = curr_tcb_ptr -> sk_ready_next;
(curr_tcb_ptr -> sk_ready_next) -> sk_ready_prev = NU_NULL;
}
else
{
/* Link up the surrounding tcbs. */
(curr_tcb_ptr -> sk_ready_next) -> sk_ready_prev =
curr_tcb_ptr -> sk_ready_prev;
(curr_tcb_ptr -> sk_ready_prev) -> sk_ready_next =
curr_tcb_ptr -> sk_ready_next;
}
/* Move the tcb after the prev tcb pointer. */
curr_tcb_ptr -> sk_ready_next = prev_tcb_ptr -> sk_ready_next;
if (curr_tcb_ptr -> sk_ready_next != NU_NULL)
{
/* Update the new downstream tcb's previous pointer. */
(curr_tcb_ptr -> sk_ready_next) -> sk_ready_prev = curr_tcb_ptr;
}
/* Setup the links to the last tcb of the same priority. */
prev_tcb_ptr -> sk_ready_next = curr_tcb_ptr;
curr_tcb_ptr -> sk_ready_prev = prev_tcb_ptr;
}
/* Determine whether or not to set the preemption flag. */
if (SKP_Ready_List_Ptr != curr_tcb_ptr)
{
/* Something is in front of the task. */
preempt = NU_TRUE;
}
/* Return the preempt condition flag. */
return(preempt);
} /* end of SKP_Move_To_End */
/************************************************************************/
/* */
/* FUNCTION "SKP_Reset_Task" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function resets the task information to the original */
/* system startup values. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* Any nucleus routine that needs to reset a task */
/* */
/* ROUTINES CALLED */
/* */
/* SKD_Init_Stack Initialize the task stack */
/* */
/* INPUTS */
/* */
/* task_id Task to lift suspension on */
/* */
/* OUTPUTS */
/* */
/* Task's TCB */
/* return(status) Status of request */
/* */
/************************************************************************/
signed int SKP_Reset_Task(signed int task_id)
{
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];
/* Determine if this task is suspended unconditionally. This is the only
condition where a reset is allowed. */
if (curr_tcb_ptr -> sk_suspend == NU_PURE_SUSPEND)
{
/* Re-initialize the TCB entry. */
curr_tcb_ptr -> sk_ready_prev = NU_NULL;
curr_tcb_ptr -> sk_ready_next = NU_NULL;
/* Call "SKD_Init_Stack" to initialize the stack for this task. */
SKD_Init_Stack(curr_tcb_ptr);
/* The task has been successfully reset, status as such. */
status = NU_SUCCESS;
}
else
/* The task is not in a pure suspension condition. Hence, a reset
is invalid. */
status = NU_NOT_SUSPENDED;
/* Return the status. */
return(status);
} /* end of SKP_Reset_Task */
/************************************************************************/
/* */
/* FUNCTION "SKP_Maximum_Tasks" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This returns the maximum number of tasks in the system. This */
/* number also happens to be one greater than the maximum valid */
/* task id. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* NU_* Nucleus user interface */
/* routines */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* None */
/* */
/* OUTPUTS */
/* */
/* return(SKP_Total_Tasks) Total number of tasks */
/* */
/************************************************************************/
signed int SKP_Maximum_Tasks()
{
/* Just return the total tasks value. */
return(SKP_Total_Tasks);
} /* end of SKP_Maximum_Tasks */
/************************************************************************/
/* */
/* FUNCTION "SKP_Set_Task_Priority" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function modifies the selected task's priority and returns */
/* the previous value as output. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* NU_* Nucleus user interface */
/* routines */
/* */
/* ROUTINES CALLED */
/* */
/* SKP_Suspend_Task Suspend task */
/* SKP_Ready_Task Place task on the ready lst */
/* SKD_Leave_Task Leave task if preemption */
/* */
/* INPUTS */
/* */
/* task_id Task to lift suspension on */
/* */
/* OUTPUTS */
/* */
/* return(old_priority) Previous priority */
/* */
/************************************************************************/
signed int SKP_Set_Task_Priority(signed int task_id, signed int new_priority)
{
struct SK_TASK_CONTROL_BLOCK_STRUCT
*tcb_ptr; /* TCB pointer */
signed int old_priority; /* Previous task priority */
signed int saved_task_id; /* Saved task ID */
/* Point to the selected TCB. */
tcb_ptr = &SKP_TCB_List[task_id];
/* Save off the old priority. */
old_priority = tcb_ptr -> sk_priority;
/* Determine if the selected task is on the ready task list. */
if (tcb_ptr -> sk_suspend == NU_FALSE)
{
/* Task is on the ready list. Save the task ID just in case it is
the current. */
saved_task_id = SKP_Current_Task_ID;
SKP_Current_Task_ID = NU_SYSTEM;
/* Remove the task by temporarily suspending it. */
SKP_Suspend_Task(task_id, NU_PURE_SUSPEND);
/* Put in the new priority. */
tcb_ptr -> sk_priority = new_priority;
/* Place the task back on the ready list in the proper position. */
SKP_Ready_Task(task_id);
/* Restore the current task ID. */
SKP_Current_Task_ID = saved_task_id;
/* Determine if task preemption is necessary. */
if ((tcb_ptr -> sk_task_id == SKP_Current_Task_ID) &&
(SKP_Ready_List_Ptr != tcb_ptr) &&
(tcb_ptr -> sk_no_preempt == NU_FALSE))
{
/* Preempt the current task. */
SKD_Leave_Task();
}
}
else
{
/* Put in the new priority into a task that was not ready. Hence,
no need to worry about where it is linked. */
tcb_ptr -> sk_priority = new_priority;
}
/* Return the old priority to the caller. */
return(old_priority);
} /* end SKP_Set_Task_Priority */
/************************************************************************/
/* */
/* FUNCTION "SKP_Get_Task_ID" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This returns the currently executing task identification. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* NU_* Nucleus user interface */
/* routines */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* None */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -