⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmc.c

📁 nucleus plus ARM9 source code
💻 C
📖 第 1 页 / 共 4 页
字号:
        (list_ptr -> tm_previous_timer) -> tm_next_timer =  timer;
        list_ptr -> tm_previous_timer =  timer;

        /* Update the remaining time parameter.  */
        timer -> tm_remaining_time =  time;

        /* Determine if a new timer should be started.  */
        if (!TMD_Active_List_Busy)
        {

            /* Calculate the new timer expiration.  */
            time =  TMD_Active_Timers_List -> tm_remaining_time;

            /* Determine if the new expiration is less than the current
               time, if any.  If not, let already started time expire.  */
            if (time <= TMD_Timer_Start)
            {

                /* Setup for a smaller timer expiration.  */
                TMD_Timer_Start =  time;

                /* Determine if there is any time remaining on the timer in
                   the front of the list.  If so, adjust the timer.
                   Otherwise, the Timer HISR is already pending, so skip
                   starting the timer again.  */
                if (TMD_Timer_Start)

                    /* Still some remaining time, adjust the timer.  */
                    TMT_Adjust_Timer(TMD_Timer_Start);
                else

                    /* Indicate that the task and application timer has
                       expired. */
                    TMD_Timer_State =  TM_EXPIRED;
            }
        }
    }
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TMC_Stop_Timer                                                   */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function is responsible for stopping both application and   */
/*      task timers.  This routine must be called from Supervisor mode   */
/*      in a Supervisor/User mode switching kernel.                      */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      TMC_Control_Timer                   Control application timer    */
/*      TMC_Stop_Task_Timer                 Start task timer             */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      TMT_Disable_Timer                   Disable the count-down timer */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      timer                               Timer control block pointer  */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*        DATE                    REMARKS                                */
/*                                                                       */
/*      03-01-1993      Created initial version 1.0                      */
/*      04-19-1993      Verified version 1.0                             */
/*      08-09-1993      Corrected a problem associated                   */
/*                      with stopping the last timer                     */
/*                      on the active list, resulting                    */
/*                      in version 1.0a                                  */
/*      08-09-1993      Verified version 1.0a                            */
/*                                                                       */
/*************************************************************************/
VOID  TMC_Stop_Timer(TM_TCB *timer)
{

    /* Note that the active timer list is already under protection.  */

    /* If the next neighbor of the timer that needs to be stopped is not the
       head of the timer list, add the remaining time field to the remaining
       time of the next neighbor.  */
    if ((timer -> tm_next_timer) != TMD_Active_Timers_List)

        /* Adjust the next neighbor's remaining time field.  */
        (timer -> tm_next_timer) -> tm_remaining_time =
                   (timer -> tm_next_timer) -> tm_remaining_time +
                                                timer -> tm_remaining_time;

    /* Unlink the timer from the active list.  */
    if (timer -> tm_next_timer == timer)
    {
        /* Only timer on the list.  */
        TMD_Active_Timers_List =  NU_NULL;

        /* Disable the timer.  */
        TMT_Disable_Timer();
    }
    else
    {

        /* More than one timer on the list.  */
        (timer -> tm_previous_timer) -> tm_next_timer = timer -> tm_next_timer;
        (timer -> tm_next_timer) -> tm_previous_timer =
                                                timer -> tm_previous_timer;

        /* Determine if the timer is at the head of the list.  */
        if (TMD_Active_Timers_List == timer)

            /* Yes, move the head pointer to the next timer.  */
            TMD_Active_Timers_List =  timer -> tm_next_timer;
    }

    /* Clear the timer's next and previous pointers.  */
    timer -> tm_next_timer =      NU_NULL;
    timer -> tm_previous_timer =  NU_NULL;
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TMC_Timer_HISR                                                   */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function is responsible for High-Level interrupt processing */
/*      of a timer expiration.  If an application timer has expired,     */
/*      the timer expiration function is called.  Otherwise, if the      */
/*      time-slice timer has expired, time-slice processing is invoked.  */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      TCC_Time_Slice                      Task time-slice processing   */
/*      TMC_Timer_Expiration                Timer expiration processing  */
/*      TMT_Retrieve_TS_Task                Retrieve time-sliced task ptr*/
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         DATE                    REMARKS                               */
/*                                                                       */
/*      03-01-1993      Created initial version 1.0                      */
/*      04-19-1993      Verified version 1.0                             */
/*      08-09-1993      Added sleep, timeout, and                        */
/*                      application timer expiration                     */
/*                      processing to the timer HISR,                    */
/*                      using time slice task pointer                    */
/*                      instead of state flag,                           */
/*                      resulting in version 1.0a                        */
/*      08-09-1993      Verified version 1.0a                            */
/*      03-01-1994      Modified function interface to                   */
/*                      TCC_Time_Slice, added logic to                   */
/*                      insure valid pointer for some                    */
/*                      ports, resulting in version 1.1                  */
/*                                                                       */
/*      03-18-1994      Verified version 1.1                             */
/*                                                                       */
/*************************************************************************/
VOID  TMC_Timer_HISR(VOID)
{

NU_TASK     *task;                          /* Time slice task.  */


    /* Determine if the task timer has expired.  */
    if (TMD_Timer_State == TM_EXPIRED)

        /* Resume the timer task.  */
        TMC_Timer_Expiration();

    /* Determine if the time-slice timer has expired.  */
    task =  TMT_Retrieve_TS_Task();
    if (task)
    {
        NU_SUPERV_USER_VARIABLES

        /* Switch to supervisor mode

           Note that this HISR function can make the switch to supervisor mode
           this is only possible because the code lives within the kernel */
        NU_SUPERVISOR_MODE();

        /* Reset the time-slice state.  */
        TMD_Time_Slice_State =  TM_NOT_ACTIVE;

        /* Process the time-slice.  */
        TCC_Time_Slice(task);

        /* Clear the time slice task pointer.  */
        TMD_Time_Slice_Task =  NU_NULL;

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


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TMC_Timer_Expiration                                             */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function is responsible for processing all task timer       */
/*      expirations.  This includes application timers and basic task    */
/*      timers that are used for task sleeping and timeouts.             */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      expiration_function                 Application specified timer  */

⌨️ 快捷键说明

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