tcce.c

来自「nucleus 2006 source code」· C语言 代码 · 共 942 行 · 第 1/4 页

C
942
字号
    
        /* Task pointer is invalid.  */
        status =  NU_INVALID_TASK;
    else
    
        /* Call actual function to terminate the task.  */
        status =  TCC_Terminate_Task(task_ptr);

    /* Return completion status.  */
    return(status);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TCCE_Resume_Service                                              */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function performs error checking on the parameters supplied */
/*      to the resume task function.                                     */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      TCCE_Validate_Resume                Function that checks the     */
/*                                            current task status for a  */
/*                                            valid resume request       */
/*      TCC_Resume_Service                  Actual task resume service   */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      task_ptr                            Task control block pointer   */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                          If successful completion     */
/*      NU_INVALID_TASK                     Task pointer is invalid      */
/*      NU_INVALID_RESUME                   Not previously suspended     */
/*                                                                       */
/*************************************************************************/
STATUS  TCCE_Resume_Service(NU_TASK *task_ptr)
{

TC_TCB         *task;                       /* Task control block ptr    */
STATUS          status;                     /* Completion status         */



    /* Move task control block pointer into internal pointer.  */
    task =  (TC_TCB *) task_ptr;

    /* Determine if the task pointer is valid.  */
    if ((task == NU_NULL) || (task -> tc_id != TC_TASK_ID))
    
        /* Task pointer is invalid.  */
        status =  NU_INVALID_TASK;
        
    /* Make sure that the task is suspended in an identical manner.  */
    else if (TCCE_Validate_Resume(NU_PURE_SUSPEND, task_ptr))
    
        /* Task is not unconditionally suspended, return error status.  */
        status =  NU_INVALID_RESUME;
    
    else
    
        /* Call the actual resume service.  */
        status =  TCC_Resume_Service(task_ptr);
        
    /* Return the completion status.  */
    return(status);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TCCE_Suspend_Service                                             */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function performs error checking on the suspend service.    */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      TCC_Suspend_Service                 Actual suspend service       */
/*                                              function                 */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      task_ptr                            Task control block pointer   */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                          If successful completion     */
/*      NU_INVALID_TASK                     Task pointer is invalid      */
/*                                                                       */
/*************************************************************************/
STATUS  TCCE_Suspend_Service(NU_TASK *task_ptr)
{

TC_TCB         *task;                       /* Task control block ptr    */
STATUS          status;                     /* Completion status         */



    /* Move task control block pointer into internal pointer.  */
    task =  (TC_TCB *) task_ptr;

    /* Determine if the task pointer is valid.  */
    if ((task == NU_NULL) || (task -> tc_id != TC_TASK_ID))
    
        /* Task pointer is invalid.  */
        status =  NU_INVALID_TASK;
        
    else

       if ((task->tc_status == NU_FINISHED) ||  (task->tc_status == NU_TERMINATED))

             /* Can't suspend a task in a finished or terminated state */
             status =  NU_INVALID_SUSPEND;


    else
     
        /* Call the actual service routine.  */
        status =  TCC_Suspend_Service(task_ptr);    
    
    /* Return completion status.  */                             
    return(status);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TCCE_Relinquish                                                  */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function performs error checking for the relinquish         */
/*      function.  If the current thread is not a task, this request     */
/*      is ignored.                                                      */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      TCC_Relinquish                      Actual relinquish function   */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/*************************************************************************/
VOID  TCCE_Relinquish(VOID)
{

TC_TCB         *task;                       /* Pointer to task           */

    /* Pickup the current thread and place it in the task pointer.  */
    task =  (TC_TCB *) TCD_Current_Thread;
     
    /* Determine if the current thread is a task.  If so, call the actual
       relinquish routine.  Otherwise, ignore the request.  */
    if ((task) && (task -> tc_id == TC_TASK_ID))
    
        /* Valid request, call the relinquish function.  */
        TCC_Relinquish();
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TCCE_Task_Sleep                                                  */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function performs error checking for the task sleep         */
/*      function.  If the current thread is not a task, this request     */
/*      is ignored.                                                      */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      TCC_Task_Sleep                      Actual task sleep function   */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      ticks                               Number of ticks to sleep for */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/*************************************************************************/
VOID  TCCE_Task_Sleep(UNSIGNED ticks)
{

TC_TCB         *task;                       /* Pointer to task           */

    /* If parameter is zero, return */
    if (ticks == 0)
        return;

    /* Pickup the current thread and place it in the task pointer.  */
    task =  (TC_TCB *) TCD_Current_Thread;
     
    /* Determine if the current thread is a task.  If so, call the actual
       task sleep routine.  Otherwise, ignore the request.  */
    if ((task) && (task -> tc_id == TC_TASK_ID))
    
        /* Valid request, call the sleep function.  */
        TCC_Task_Sleep(ticks);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?