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

📄 net_tmr.c

📁 ucos的tcpip协议占
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
*********************************************************************************************************
*                                              uC/TCP-IP
*                                      The Embedded TCP/IP Suite
*
*                          (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*
*               uC/TCP-IP is provided in source form for FREE evaluation, for educational
*               use or peaceful research.  If you plan on using uC/TCP-IP in a commercial
*               product you need to contact Micrium to properly license its use in your
*               product.  We provide ALL the source code for your convenience and to help
*               you experience uC/TCP-IP.  The fact that the source code is provided does
*               NOT mean that you can use it without paying a licensing fee.
*
*               Knowledge of the source code may NOT be used to develop a similar product.
*
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                       NETWORK TIMER MANAGEMENT
*
* Filename      : net_tmr.c
* Version       : V1.87
* Programmer(s) : ITJ
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            INCLUDE FILES
*********************************************************************************************************
*/

#define    NET_TMR_MODULE
#include  <net.h>


/*$PAGE*/
/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                           LOCAL CONSTANTS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                          LOCAL DATA TYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                            LOCAL TABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/


/*$PAGE*/
/*
*********************************************************************************************************
*                                      LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

#if (NET_DBG_CFG_MEM_CLR_EN == DEF_ENABLED)
static  void  NetTmr_Clr           (NET_TMR  *ptmr);
#endif

#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static  void  NetTmr_Discard       (NET_TMR  *ptmr);

static  void  NetTmr_DiscardTaskTmr(void);
#endif


/*
*********************************************************************************************************
*                                     LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/


/*$PAGE*/
/*
*********************************************************************************************************
*                                            NetTmr_Init()
*
* Description : (1) Initialize Network Timer Management Module :
*
*                   (a) Perform Timer Module/OS initialization
*                   (b) Initialize timer pool
*                   (c) Initialize timer table
*                   (d) Initialize timer task list pointer
*                   (e) Initialize timer error counters
*
*
* Argument(s) : perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_TMR_ERR_NONE                Network timer module successfully initialized.
*
*                                                               ------- RETURNED BY NetOS_Tmr_Init() : -------
*                               NET_OS_ERR_INIT_TMR_TASK        Network timer task      NOT successfully
*                                                                   initialized.
*                               NET_OS_ERR_INIT_TMR_TASK_NAME   Network timer task name NOT successfully
*                                                                   configured.
*
* Return(s)   : none.
*
* Caller(s)   : Net_Init().
*
*               This function is an INTERNAL network protocol suite function & MUST NOT be called by 
*               application function(s).
*
* Note(s)     : (2) Timer pool MUST be initialized PRIOR to initializing the pool with pointers to timers.
*********************************************************************************************************
*/
/*$PAGE*/
void  NetTmr_Init (NET_ERR  *perr)
{
    NET_TMR      *ptmr;
    NET_TMR_QTY   i;
    NET_ERR       err;


                                                                /* --------------- PERFORM TMR/OS INIT ---------------- */
    NetOS_Tmr_Init(perr);                                       /* Create Tmr Task.                                     */
    if (*perr != NET_OS_ERR_NONE) {
         return;
    }


                                                                /* ------------------ INIT TMR POOL ------------------- */
    NetTmr_PoolPtr = (NET_TMR *)0;                              /* See Note #2.                                         */

    NetStat_PoolInit((NET_STAT_POOL   *)&NetTmr_PoolStat,
                     (NET_STAT_POOL_QTY) NET_TMR_CFG_NBR_TMR,
                     (NET_ERR         *)&err);


                                                                /* ------------------ INIT TMR TBL -------------------- */
    ptmr = &NetTmr_Tbl[0];
    for (i = 0; i < NET_TMR_CFG_NBR_TMR; i++) {
        ptmr->Type  =  NET_TMR_TYPE_TMR;                        /* Init each tmr type/id--NEVER modify.                 */
        ptmr->ID    = (NET_BUF_QTY)i;

        ptmr->Flags =  NET_TMR_FLAG_NONE;                       /* Init each tmr as NOT used.                           */

#if (NET_DBG_CFG_MEM_CLR_EN == DEF_ENABLED)
        NetTmr_Clr(ptmr);
#endif

        ptmr->NextPtr  = (void *)NetTmr_PoolPtr;                /* Free each tmr to tmr pool (see Note #2).             */
        NetTmr_PoolPtr =  ptmr;

        ptmr++;
    }


                                                                /* -------------- INIT TMR TASK LIST PTR -------------- */
    NetTmr_TaskListHead         = (NET_TMR *)0;
    NetTmr_TaskListPtr          = (NET_TMR *)0;


                                                                /* ---------------- INIT TMR ERR CTRS ----------------- */
#if (NET_CTR_CFG_ERR_EN         == DEF_ENABLED)
    NetTmr_ErrNoneAvailCtr      =  0;

#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
    NetTmr_ErrNullPtrCtr        =  0;
    NetTmr_ErrNullObjCtr        =  0;
    NetTmr_ErrNullFnctCtr       =  0;
    NetTmr_ErrNotUsedCtr        =  0;

    NetTmr_ErrInvalidTypeCtr    =  0;
#endif
#endif


   *perr = NET_TMR_ERR_NONE;
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                         NetTmr_TaskHandler()
*
* Description : Decrement every timer in Timer Task List & execute timer's expiration function for any
*               timer that expires.
*
*               (1) (a) Timers are managed in a doubly-linked Timer List.
*
*                       (1) 'NetTmr_TaskListHead' points to the head of the Timer List.
*
*                       (2) Timers' 'PrevPtr' & 'NextPtr' doubly-link each timer to form the Timer List.
*
*                   (b) New timers are added at the head of the Timer List.
*
*                   (c) As timers are added into the list, older timers migrate to the tail of the Timer
*                       List.  Once a timer expires or is discarded, it is removed from the Timer List.
*
*
*                                        |                                               |
*                                        |<-------------- List of Timers --------------->|
*                                        |                (see Note #1a)                 |
*
*                                      New Timers
*                                   inserted at head                         Oldest Timer in List
*                                    (see Note #1b)                            (see Note #1c)
*
*                                           |                 NextPtr                 |
*                                           |             (see Note #1a2)             |
*                                           v                    |                    v
*                                                                |
*                        Head of         -------       -------   v   -------       -------
*                       Timer List  ---->|     |------>|     |------>|     |------>|     |
*                                        |     |<------|     |<------|     |<------|     |
*                    (see Note #1a1)     -------       -------   ^   -------       -------
*                                                                |
*                                                                |
*                                                             PrevPtr
*                                                         (see Note #1a2)
*
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : NetOS_Tmr_Task() [see 'net_os.c'].
*
*               This function is a network protocol suite to operating system (OS) function & SHOULD be

⌨️ 快捷键说明

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