tcf.c

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

C
586
字号
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_Protect                         Protect HISR created list    */
/*      TCT_Unprotect                       Release protection of list   */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      pointer_list                        Pointer to the list area     */
/*      maximum_pointers                    Maximum number of pointers   */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*                                          Number of HISRs placed in    */
/*                                            list                       */
/*************************************************************************/
UNSIGNED  TCF_HISR_Pointers(NU_HISR **pointer_list, UNSIGNED maximum_pointers)
{

CS_NODE         *node_ptr;                  /* Pointer to each TCB       */
UNSIGNED         pointers;                  /* Number of pointers in list*/
NU_SUPERV_USER_VARIABLES

    /* Switch to supervisor mode */
    NU_SUPERVISOR_MODE();

#ifdef  NU_ENABLE_STACK_CHECK

    /* Call stack checking function to check for an overflow condition.  */
    TCT_Check_Stack();

#endif

    /* Initialize the number of pointers returned.  */
    pointers =  0;

    /* Protect the HISR created list.  */
    TCT_Protect(&TCD_HISR_Protect);

    /* Loop until all HISR pointers are in the list or until the maximum
       list size is reached.  */
    node_ptr =  TCD_Created_HISRs_List;
    while ((node_ptr) && (pointers < maximum_pointers))
    {

        /* Place the node into the destination list.  */
        *pointer_list++ =  (NU_HISR *) node_ptr;

        /* Increment the pointers variable.  */
        pointers++;

        /* Position the node pointer to the next node.  */
        node_ptr =  node_ptr -> cs_next;

        /* Determine if the pointer is at the head of the list.  */
        if (node_ptr == TCD_Created_HISRs_List)

            /* The list search is complete.  */
            node_ptr =  NU_NULL;
    }

    /* Release protection.  */
    TCT_Unprotect();

    /* Return to user mode */
    NU_USER_MODE();

    /* Return the number of pointers in the list.  */
    return(pointers);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TCF_Task_Information                                             */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function returns information about the specified task.      */
/*      However, if the supplied task pointer is invalid, the function   */
/*      simply returns an error status.                                  */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_System_Protect                  Protect scheduling info      */
/*      TCT_Unprotect                       Release protection           */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      task_ptr                            Pointer to the task          */
/*      name                                Destination for the name     */
/*      status                              Destination for task status  */
/*      scheduled_count                     Destination for scheduled    */
/*                                            count of the task          */
/*      priority                            Destination for task priority*/
/*      preempt                             Destination for preempt flag */
/*      time_slice                          Destination for time slice   */
/*      stack_base                          Destination for pointer to   */
/*                                            base of task's stack       */
/*      stack_size                          Destination for stack size   */
/*      minimum_stack                       Destination for the minimum  */
/*                                            running size of the stack  */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                          If a valid task pointer is   */
/*                                            supplied                   */
/*      NU_INVALID_TASK                     If task pointer is invalid   */
/*                                                                       */
/*************************************************************************/
STATUS  TCF_Task_Information(NU_TASK *task_ptr, CHAR *name,
            DATA_ELEMENT *status, UNSIGNED *scheduled_count,
            DATA_ELEMENT *priority, OPTION *preempt, UNSIGNED *time_slice,
            VOID **stack_base, UNSIGNED *stack_size, UNSIGNED *minimum_stack)
{

R1 TC_TCB      *task;                       /* Task control block ptr    */
INT             i;                          /* Working index             */
STATUS          completion;                 /* Completion status         */
NU_SUPERV_USER_VARIABLES

    /* Switch to supervisor mode */
    NU_SUPERVISOR_MODE();

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


#ifdef  NU_ENABLE_STACK_CHECK

    /* Call stack checking function to check for an overflow condition.  */
    TCT_Check_Stack();

#endif

    /* Determine if this task is valid.  */
    if ((task != NU_NULL) && (task -> tc_id == TC_TASK_ID))
    {

        /* Protect against scheduling changes.  */
        TCT_System_Protect();

        /* The task pointer is successful.  Reflect this in the completion
           status and fill in the actual information.  */
        completion =  NU_SUCCESS;

        /* Copy the task's name.  */
        for (i = 0; i < NU_MAX_NAME; i++)
            *name++ =  task -> tc_name[i];

        /* Determine the preemption posture.  */
        if (task -> tc_preemption)
            *preempt =          NU_PREEMPT;
        else
            *preempt =          NU_NO_PREEMPT;

        /* Setup the remaining fields.  */
        *status =           task -> tc_status;
        *scheduled_count =  task -> tc_scheduled;
        *priority =         task -> tc_priority;
        *time_slice =       task -> tc_time_slice;
        *stack_base =       task -> tc_stack_start;
        *stack_size =       task -> tc_stack_size;
        *minimum_stack =    task -> tc_stack_minimum;

        /* Release protection.  */
        TCT_Unprotect();
    }
    else

        /* Indicate that the task pointer is invalid.   */
        completion =  NU_INVALID_TASK;

    /* Return to user mode */
    NU_USER_MODE();

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


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TCF_HISR_Information                                             */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function returns information about the specified HISR.      */
/*      However, if the supplied HISR pointer is invalid, the function   */
/*      simply returns an error status.                                  */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_System_Protect                  Protect scheduling info      */
/*      TCT_Unprotect                       Release protection           */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      hisr_ptr                            Pointer to the hisr          */
/*      name                                Destination for the name     */
/*      scheduled_count                     Destination for scheduled    */
/*                                            count of the HISR          */
/*      priority                            Destination for HISR priority*/
/*      stack_base                          Destination for pointer to   */
/*                                            base of HISR's stack       */
/*      stack_size                          Destination for stack size   */
/*      minimum_stack                       Destination for the minimum  */
/*                                            running size of the stack  */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                          If a valid HISR pointer is   */
/*                                            supplied                   */
/*      NU_INVALID_HISR                     If HISR pointer is invalid   */
/*                                                                       */
/*************************************************************************/
STATUS  TCF_HISR_Information(NU_HISR *hisr_ptr, CHAR *name,
           UNSIGNED *scheduled_count, DATA_ELEMENT *priority,
           VOID **stack_base, UNSIGNED *stack_size, UNSIGNED *minimum_stack)
{

R1 TC_HCB      *hisr;                       /* HISR control block ptr    */
INT             i;                          /* Working index             */
STATUS          completion;                 /* Completion status         */
NU_SUPERV_USER_VARIABLES

    /* Switch to supervisor mode */
    NU_SUPERVISOR_MODE();

    /* Move input HISR control block pointer into internal pointer.  */
    hisr =  (TC_HCB *) hisr_ptr;


#ifdef  NU_ENABLE_STACK_CHECK

    /* Call stack checking function to check for an overflow condition.  */
    TCT_Check_Stack();

#endif

    /* Determine if this HISR is valid.  */
    if ((hisr != NU_NULL) && (hisr -> tc_id == TC_HISR_ID))
    {

        /* Protect against scheduling changes.  */
        TCT_System_Protect();

        /* The HISR pointer is successful.  Reflect this in the completion
           status and fill in the actual information.  */
        completion =  NU_SUCCESS;

        /* Copy the hisr's name.  */
        for (i = 0; i < NU_MAX_NAME; i++)
            *name++ =  hisr -> tc_name[i];

        /* Setup the remaining fields.  */
        *scheduled_count =  hisr -> tc_scheduled;
        *priority =         hisr -> tc_priority;
        *stack_base =       hisr -> tc_stack_start;
        *stack_size =       hisr -> tc_stack_size;
        *minimum_stack =    hisr -> tc_stack_minimum;

        /* Release protection.  */
        TCT_Unprotect();
    }
    else

        /* Indicate that the HISR pointer is invalid.   */
        completion =  NU_INVALID_HISR;

    /* Return to user mode */
    NU_USER_MODE();

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




⌨️ 快捷键说明

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