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

📄 tmc.c

📁 test file nucleus source
💻 C
📖 第 1 页 / 共 4 页
字号:
/*                                            expiration function        *//*      TCC_Task_Timeout                    Task timeout function        *//*      TCT_System_Protect                  Protect active timer list    *//*      TCT_Unprotect                       Release protection of list   *//*      TMC_Stop_Timer                      Stop timer                   *//*      TMC_Start_Timer                     Start timer                  *//*      TMT_Disable_Timer                   Disable timer                *//*      TMT_Enable_Timer                    Enable timer                 *//*                                                                       *//* 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      Changed from TMC_Timer_Task to                   *//*                      TMC_Timer_Expiration,                            *//*                      resulting in version 1.0a                        *//*      08-09-1993      Verified version 1.0a                            *//*      03-01-1994      Modified function interface to                   *//*                      TCC_Task_Timeout, changed                        *//*                      protection logic to use system                   *//*                      protetion, added register                        *//*                      logic, resulting in version 1.1                  *//*                                                                       *//*      03-18-1994      Verified version 1.1                             *//*      08-25-95        Made the following changes                       *//*                                                                       *//*    +INT             type = 0;                Type of expiration       *//*    +VOID           *pointer = NU_NULL;       Pointer type             *//*    +UNSIGNED        id = 0;                  Application timer ID     *//*    -INT             type;                    Type of expiration       *//*    -VOID           *pointer;                 Pointer type             *//*    -UNSIGNED        id;                      Application timer ID     *//*                                              Expiration routine ptr   *//*    +VOID            (*expiration_routine)(UNSIGNED)= NU_NULL;         *//*    -VOID            (*expiration_routine)(UNSIGNED);                  *//*                                                                       *//*************************************************************************/VOID  TMC_Timer_Expiration(VOID){R1 TM_TCB      *timer;                      /* Pointer to timer         */R2 TM_APP_TCB  *app_timer;                  /* Pointer to app timer     */INT             done;                       /* Expiration completion    */INT             type = 0;                   /* Type of expiration       */VOID           *pointer = NU_NULL;          /* Pointer type             */UNSIGNED        id = 0;                     /* Application timer ID     */                                            /* Expiration routine ptr   */VOID            (*expiration_routine)(UNSIGNED)= NU_NULL;NU_SUPERV_USER_VARIABLES    /* Switch to supervisor mode */    NU_SUPERVISOR_MODE();    /* Use system protect to protect the active timer list.  */    TCT_System_Protect();    /* Reset the timer state flag.  */    TMT_Disable_Timer();    /* Set the busy flag to indicate that the list is being processed.  */    TMD_Active_List_Busy =  NU_TRUE;    /* Update the head of the list with the timer expiration       value.  */    timer =  TMD_Active_Timers_List;    if (timer)    {        /* Adjust the active timer's remaining time value.  Note that           TMD_Timer_Start is never greater than the value in the first           timer location.  */        if (timer -> tm_remaining_time > TMD_Timer_Start)            /* Timer has not expired.  Simply subtract the last timer               value. */            timer -> tm_remaining_time = timer -> tm_remaining_time -                                                    TMD_Timer_Start;        else            /* Clear the remaining time field of the timer.  */            timer -> tm_remaining_time =  0;    }    /* Release protection, but keep the busy flag set to prevent       activating new timers.  */    TCT_Unprotect();    /* Find expired timers.  Note that the expired timers have values of       0 in the remaining time field.  */    done =  NU_FALSE;    do    {        /* Protect against list access.  */        TCT_System_Protect();        /* Pickup the head of the active list.  */        timer =  TMD_Active_Timers_List;        /* Determine if the timer now at the head of the list has           expired.  Processing continues until the list is empty or           until a non-expired timer is at the front of the list. */        if ((timer) && (timer -> tm_remaining_time == 0))        {            /* Timer has expired.  Determine which type of timer has               expired.  */            if (timer -> tm_timer_type == TM_APPL_TIMER)            {                /* Application timer has expired.  */                type =  TM_APPL_TIMER;                /* Pickup the pointer to the application timer control                   block.  */                app_timer =  (TM_APP_TCB *) timer -> tm_information;                /* Increment the number of expirations.  */                app_timer -> tm_expirations++;#ifdef INCLUDE_PROVIEW    _RTProf_DumpTimer(RT_PROF_APP_TIMER_EXPIRED,app_timer,RT_PROF_OK);#endif                /* Move the expiration information into local variables                   in case they get corrupted before this expiration can                   be processed.  Expirations are processed without the                   list protection in force.  */                id =                  app_timer -> tm_expiration_id;                expiration_routine =  app_timer -> tm_expiration_routine;                /* Clear the enabled flag and remove the timer from the                   list.  */                app_timer -> tm_enabled =  NU_FALSE;                TMC_Stop_Timer(timer);                /* Determine if this timer should be started again.  */                if (app_timer -> tm_reschedule_time)                {                    /* Timer needs to be rescheduled.  */                    /* Setup the enable flag to show that the timer is                       enabled.  */                    app_timer -> tm_enabled =  NU_TRUE;                    /* Call the start timer function to actually enable                       the timer.  This also puts it in the proper place                       on the list.  */                    TMC_Start_Timer(timer,app_timer -> tm_reschedule_time);                }            }            else            {                /* Task timer has expired (sleeps and timeouts).  */                type =  TM_TASK_TIMER;                /* Remove the timer from the list.  */                TMC_Stop_Timer(timer);                /* Save-off the task control block pointer.  */                pointer =  timer -> tm_information;            }        }        else            /* Processing is now complete- no more expired timers on the               list.  */            done =  NU_TRUE;        /* Release protection of active list.  */        TCT_Unprotect();        /* Determine if a timer expiration needs to be finished.  Note           that the actual expiration processing is done with protection           disabled.  This prevents deadlock situations from arising.  */        if (!done)        {            /* Determine which type of timer has expired.  */            if (type == TM_APPL_TIMER)                /* Call application timer's expiration function.  */                (*(expiration_routine)) (id);            else                /* Call the task timeout function in the thread control                   function.  */                TCC_Task_Timeout((NU_TASK *) pointer);        }    } while (!done);    /* Protect the active list again.  */    TCT_System_Protect();    /* Clear the busy flag to indicate that list processing is complete. */    TMD_Active_List_Busy =  NU_FALSE;    /* Determine if a new timer should be enabled.  */    if (TMD_Active_Timers_List)    {        /* Yes, a new timer should be activated.  */        /* Pickup the new timer expiration value.  */        TMD_Timer_Start =  TMD_Active_Timers_List -> tm_remaining_time;        /* Start the new timer.  */        TMT_Enable_Timer(TMD_Timer_Start);    }    /* Release protection of the active timer list.  */    TCT_Unprotect();    /* Return to user mode */    NU_USER_MODE();}

⌨️ 快捷键说明

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