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

📄 tmc.c

📁 nucleus 2006 source code
💻 C
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************/
/*                                                                       */
/*               Copyright Mentor Graphics Corporation 2004              */
/*                         All Rights Reserved.                          */
/*                                                                       */
/* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS  */
/* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS   */
/* SUBJECT TO LICENSE TERMS.                                             */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME                                               VERSION       */
/*                                                                       */
/*      tmc.c                                          Nucleus PLUS 1.15 */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      TM - Timer Management                                            */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the core routines for the timer management    */
/*      component.                                                       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      TMC_Init_Task_Timer                 Initialize task timer        */
/*      TMC_Start_Task_Timer                Start task timer             */
/*      TMC_Stop_Task_Timer                 Stop task timer              */
/*      TMC_Start_Timer                     Actually start a timer       */
/*      TMC_Stop_Timer                      Actually stop a timer        */
/*      TMC_Timer_HISR                      Timer High-Level Interrupt   */
/*                                            Service Routine (HISR)     */
/*      TMC_Timer_Expiration                Timer expiration function    */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      cs_extr.h                           Common Service functions     */
/*      tc_extr.h                           Thread Control functions     */
/*      tm_extr.h                           Timer functions              */
/*      hi_extr.h                           History functions            */
/*                                                                       */
/*************************************************************************/
#define         NU_SOURCE_FILE


#include        "plus/inc/cs_extr.h"        /* Common service functions  */
#include        "plus/inc/tc_extr.h"        /* Thread control functions  */
#include        "plus/inc/tm_extr.h"        /* Timer functions           */
#include        "plus/inc/hi_extr.h"        /* History functions         */


/* Define external inner-component global data references.  */

extern TM_TCB         *TMD_Active_Timers_List;
extern INT             TMD_Active_List_Busy;
extern UNSIGNED        TMD_System_Clock;
extern UNSIGNED        TMD_Timer_Start;
extern UNSIGNED        TMD_Timer;
extern INT             TMD_Timer_State;
extern UNSIGNED        TMD_Time_Slice;
extern TC_TCB         *TMD_Time_Slice_Task;
extern INT             TMD_Time_Slice_State;


/* Define internal function prototypes.  */

VOID            TMC_Start_Timer(TM_TCB *timer, UNSIGNED time);
VOID            TMC_Stop_Timer(TM_TCB *timer);
VOID            TMC_Timer_Expiration(VOID);
UNSIGNED        TMT_Read_Timer(VOID);
VOID            TMT_Enable_Timer(UNSIGNED time);
VOID            TMT_Disable_Timer(VOID);



/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TMC_Init_Task_Timer                                              */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function is responsible for initializing the supplied task  */
/*      timer.  This routine must be called from Supervisor mode in a    */
/*      Supervisor/User mode switching kernel.                           */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      TCC_Create_Task                     Task create function         */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      timer                               Timer control block pointer  */
/*      information                         Information pointer - always */
/*                                            the task pointer           */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/*************************************************************************/
VOID  TMC_Init_Task_Timer(TM_TCB *timer, VOID *information)
{

    /* Initialize the task timer.  */
    timer -> tm_timer_type =      TM_TASK_TIMER;
    timer -> tm_information =     information;
    timer -> tm_next_timer =      NU_NULL;
    timer -> tm_previous_timer =  NU_NULL;
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TMC_Start_Task_Timer                                             */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function is responsible for starting 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_Suspend_Task                    Suspend task with a timeout  */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      TMC_Start_Timer                     Start the timer              */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      timer                               Timer control block pointer  */
/*      time                                Time associated with timer   */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/*************************************************************************/
VOID  TMC_Start_Task_Timer(TM_TCB *timer, UNSIGNED time)
{

    /* 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                                                             */
/*                                                                       */
/*************************************************************************/
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                                                             */
/*                                                                       */
/*************************************************************************/
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.  */

⌨️ 快捷键说明

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