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

📄 tmc.c

📁 nucleus plus ARM9 source code
💻 C
📖 第 1 页 / 共 4 页
字号:

    /* Start the specified timer.  */
    TMC_Start_Timer(timer, time);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TMC_Stop_Task_Timer                                              */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function is responsible for stopping a task timer.  Note    */
/*      that there are some special protection considerations since      */
/*      this function is called from the task control component.  This   */
/*      routine must be called from Supervisor mode in a Supervisor/User */
/*      mode switching kernel.                                           */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      TCC_Resume_Task                     Resume task function         */
/*      TCC_Terminate_Task                  Terminate task function      */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      TMC_Stop_Timer                      Stop the 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                             */
/*      03-01-1994      Removed protection logic since                   */
/*                      system protect is in force at                    */
/*                      the time this function is                        */
/*                      called, resulting in                             */
/*                      version 1.1                                      */
/*                                                                       */
/*      03-18-1994      Verified version 1.1                             */
/*                                                                       */
/*************************************************************************/
VOID  TMC_Stop_Task_Timer(TM_TCB *timer)
{

    /* Stop the specified timer - if it is still active.  */
    if (timer -> tm_next_timer)

        TMC_Stop_Timer(timer);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TMC_Start_Timer                                                  */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function is responsible for starting 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_Start_Task_Timer                Start task timer             */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      TMT_Read_Timer                      Read current timer counter   */
/*      TMT_Adjust_Timer                    Adjust the count-down timer  */
/*      TMT_Enable_Timer                    Enable count-down timer      */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      timer                               Timer control block pointer  */
/*      time                                Time associated with timer   */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         DATE                    REMARKS                               */
/*                                                                       */
/*      03-01-1993      Created initial version 1.0                      */
/*      04-19-1993      Verified version 1.0                             */
/*      08-09-1993      Added logic to check for timer                   */
/*                        expiration before or during                    */
/*                        another LISR's access,                         */
/*                        resulting in version 1.0a                      */
/*      08-09-1993      Verified version 1.0a                            */
/*      03-01-1994      Removed disable timer logic to                   */
/*                        insure there is no timer loss,                 */
/*                        added register logic,                          */
/*                        resulting in version 1.1                       */
/*                                                                       */
/*      03-18-1994      Verified version 1.1                             */
/*                                                                       */
/*************************************************************************/
VOID  TMC_Start_Timer(TM_TCB *timer, UNSIGNED time)
{

R1 TM_TCB      *list_ptr;                   /* Working pointer timer ptr */
UNSIGNED        elapsed;                    /* Elapsed time variable     */
INT             done;                       /* Search finished flag      */


    /* Note that protection over the active timer list is in force when this
       function is called.  */

    /* Determine if the active list is empty.  */
    if (TMD_Active_Timers_List == NU_NULL)
    {

        /* Place the timer on an empty list.  */
        timer -> tm_next_timer =      timer;
        timer -> tm_previous_timer =  timer;

        /* Link the timer to the list head.  */
        TMD_Active_Timers_List =  timer;

        /* Setup the actual count-down timer structures.  */
        TMD_Timer_Start =  time;
        timer -> tm_remaining_time =  time;


        /* BUG FIX FOR NU_RESET WITH INITIAL TIME OF 0 */
        /* Determine if there is any time remaining on the timer.
           If so, enable the timer. Otherwise, the Timer HISR is
           already pending, so skip starting the timer again.  */

        if (time != 0)
           /* Start the actual count-down timer.  */
           TMT_Enable_Timer(TMD_Timer_Start);
        else
           TMD_Timer_State =  TM_EXPIRED;

    }
    else
    {

        /* Place the new timer into the list.  */

        /* Pickup the head of the list.  */
        list_ptr =  TMD_Active_Timers_List;

        /* Determine if the timer is being added while the timer
           expiration task is running.  If so, don't attempt to adjust
           the expiration list.  If not, adjust the list.  */
        if (!TMD_Active_List_Busy)
        {

            /* Calculate the elapsed amount of time from the last timer
               request.  */
            elapsed =  TMD_Timer_Start -  TMT_Read_Timer();

            /* Adjust the first entry in the timer list and the timer
               start value accordingly.  */
            TMD_Timer_Start =  TMD_Timer_Start - elapsed;

            /* Make sure the remaining time is never below zero.  */
            if (list_ptr -> tm_remaining_time > elapsed)
            {
                list_ptr -> tm_remaining_time = list_ptr -> tm_remaining_time
                    - elapsed;
            }
            else
            {
                list_ptr -> tm_remaining_time = 0;
            }


        }

        /* At this point the timer list is accurate again.  Find the
           appropriate place on the timer list for the new timer.  */

        /* Determine where to place the timer in the list.  */
        done =  NU_FALSE;
        do
        {

            /* Determine if the timer belongs before the current timer
               pointed to by list_ptr.  */
            if (time < list_ptr -> tm_remaining_time)
            {

                /* Update the time of the next timer.  */
                list_ptr -> tm_remaining_time =
                                list_ptr -> tm_remaining_time - time;

                /* Determine if an insertion at the head of the list is
                   present.  */
                if (list_ptr == TMD_Active_Timers_List)

                    /* Move the list head to the new timer.  */
                    TMD_Active_Timers_List =  timer;

                /* Set the done flag to end the search.  */
                done =  NU_TRUE;
            }
            else
            {

                /* Decrement the time by the remaining value of each timer in
                   the list.  In this way, the list never has to be searched
                   again.  */
                time =  time - list_ptr -> tm_remaining_time;

                /* Move the list pointer to the next timer in the list.  */
                list_ptr =  list_ptr -> tm_next_timer;

                /* Check to see if the list has wrapped around.  */
                if (list_ptr == TMD_Active_Timers_List)

                    /* Searching is done.  */
                    done =  NU_TRUE;
            }
        } while (!done);

        /* Link the new timer into the list.  */
        timer -> tm_next_timer =      list_ptr;
        timer -> tm_previous_timer =  list_ptr -> tm_previous_timer;

⌨️ 快捷键说明

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