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

📄 net_stat.c

📁 ucos的tcpip协议占
💻 C
📖 第 1 页 / 共 2 页
字号:
        NET_CTR_ERR_INC(NetStat_ErrInvalidTypeCtr);
       *perr = NET_STAT_ERR_POOL_INVALID_TYPE;
        return;
    }
#endif


    CPU_CRITICAL_ENTER();
    pstat_pool->EntriesAvail          = pstat_pool->EntriesTot;
    pstat_pool->EntriesUsed           = 0;
    pstat_pool->EntriesUsedMax        = 0;
    pstat_pool->EntriesLostCur        = 0;
    pstat_pool->EntriesAllocatedCtr   = 0;
    pstat_pool->EntriesDeallocatedCtr = 0;
    CPU_CRITICAL_EXIT();

   *perr                              = NET_STAT_ERR_NONE;
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                     NetStat_PoolResetUsedMax()
*
* Description : Reset a statistics pool's maximum number of entries used.
*
*               (1) Resets maximum number of entries used to the current number of entries used.
*
*
* Argument(s) : pstat_pool  Pointer to a statistics pool.
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_STAT_ERR_NONE                   Statistics pool's maximum number of entries
*                                                                       used successfully reset.
*                               NET_STAT_ERR_NULL_PTR               Argument 'pstat_pool' passed a NULL pointer.
*                               NET_STAT_ERR_POOL_INVALID_TYPE      Argument 'pstat_pool's TYPE is invalid
*                                                                       or unknown.
*
* Return(s)   : none.
*
* Caller(s)   : various.
*
*               This function is an INTERNAL network protocol suite function & SHOULD NOT be called by 
*               application function(s).
*
* Note(s)     : (2) #### 'perr' may NOT be necessary (remove if unnecessary).
*********************************************************************************************************
*/

void  NetStat_PoolResetUsedMax (NET_STAT_POOL  *pstat_pool,
                                NET_ERR        *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
                                                                /* ------------------- VALIDATE PTR ------------------- */
    if (pstat_pool == (NET_STAT_POOL *)0) {
        NET_CTR_ERR_INC(NetStat_ErrNullPtrCtr);
       *perr = NET_STAT_ERR_NULL_PTR;
        return;
    }
                                                                /* ------------------- VALIDATE TYPE ------------------ */
    if (pstat_pool->Type != NET_STAT_TYPE_POOL) {
        NET_CTR_ERR_INC(NetStat_ErrInvalidTypeCtr);
       *perr = NET_STAT_ERR_POOL_INVALID_TYPE;
        return;
    }
#endif


    CPU_CRITICAL_ENTER();
    pstat_pool->EntriesUsedMax = pstat_pool->EntriesUsed;       /* Reset nbr max used (see Note #1).                    */
    CPU_CRITICAL_EXIT();

   *perr                       = NET_STAT_ERR_NONE;
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                     NetStat_PoolEntryUsedInc()
*
* Description : Increment a statistics pool's number of 'Used' entries.
*
* Argument(s) : pstat_pool  Pointer to a statistics pool.
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_STAT_ERR_NONE                   Statistics pool's number used 
*                                                                       successfully incremented.
*                               NET_STAT_ERR_NULL_PTR               Argument 'pstat_pool' passed a NULL pointer.
*                               NET_STAT_ERR_POOL_INVALID_TYPE      Argument 'pstat_pool's TYPE is invalid
*                                                                       or unknown.
*                               NET_STAT_ERR_POOL_NONE_AVAIL        NO available statistics pool entries; i.e. 
*                                                                       number of available entries already zero.
*
* Return(s)   : none.
*
* Caller(s)   : various.
*
*               This function is an INTERNAL network protocol suite function & SHOULD NOT be called by 
*               application function(s).
*
* Note(s)     : (1) #### 'perr' may NOT be necessary (remove if unnecessary).
*********************************************************************************************************
*/

void  NetStat_PoolEntryUsedInc (NET_STAT_POOL  *pstat_pool,
                                NET_ERR        *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
                                                                /* ------------------- VALIDATE PTR ------------------- */
    if (pstat_pool == (NET_STAT_POOL *)0) {
        NET_CTR_ERR_INC(NetStat_ErrNullPtrCtr);
       *perr = NET_STAT_ERR_NULL_PTR;
        return;
    }
                                                                /* ------------------- VALIDATE TYPE ------------------ */
    if (pstat_pool->Type != NET_STAT_TYPE_POOL) {
        NET_CTR_ERR_INC(NetStat_ErrInvalidTypeCtr);
       *perr = NET_STAT_ERR_POOL_INVALID_TYPE;
        return;
    }
#endif


    CPU_CRITICAL_ENTER();
    if (pstat_pool->EntriesAvail > 0) {                                 /* If any stat pool entry avail,            ..  */
        pstat_pool->EntriesAvail--;                                     /* .. adj nbr of avail/used entries in pool ..  */
        pstat_pool->EntriesUsed++;
        pstat_pool->EntriesAllocatedCtr++;                              /* .. & inc total nbr of allocated entries.     */
        if (pstat_pool->EntriesUsed    > pstat_pool->EntriesUsedMax) {  /* If nbr used > max used, set new max used.    */
            pstat_pool->EntriesUsedMax = pstat_pool->EntriesUsed;
        }

       *perr = NET_STAT_ERR_NONE;

    } else {
       *perr = NET_STAT_ERR_POOL_NONE_AVAIL;
    }
    CPU_CRITICAL_EXIT();
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                     NetStat_PoolEntryUsedDec()
*
* Description : Decrement a statistics pool's number of 'Used' entries.
*
* Argument(s) : pstat_pool  Pointer to a statistics pool.
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_STAT_ERR_NONE                   Statistics pool's number used 
*                                                                       successfully decremented.
*                               NET_STAT_ERR_NULL_PTR               Argument 'pstat_pool' passed a NULL pointer.
*                               NET_STAT_ERR_POOL_INVALID_TYPE      Argument 'pstat_pool's TYPE is invalid
*                                                                       or unknown.
*                               NET_STAT_ERR_POOL_NONE_USED         NO used statistics pool entries; i.e. 
*                                                                       number of used entries already zero.
*
* Return(s)   : none.
*
* Caller(s)   : various.
*
*               This function is an INTERNAL network protocol suite function & SHOULD NOT be called by 
*               application function(s).
*
* Note(s)     : (1) #### 'perr' may NOT be necessary (remove if unnecessary).
*********************************************************************************************************
*/

void  NetStat_PoolEntryUsedDec (NET_STAT_POOL  *pstat_pool,
                                NET_ERR        *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
                                                                /* ------------------- VALIDATE PTR ------------------- */
    if (pstat_pool == (NET_STAT_POOL *)0) {
        NET_CTR_ERR_INC(NetStat_ErrNullPtrCtr);
       *perr = NET_STAT_ERR_NULL_PTR;
        return;
    }
                                                                /* ------------------- VALIDATE TYPE ------------------ */
    if (pstat_pool->Type != NET_STAT_TYPE_POOL) {
        NET_CTR_ERR_INC(NetStat_ErrInvalidTypeCtr);
       *perr = NET_STAT_ERR_POOL_INVALID_TYPE;
        return;
    }
#endif


    CPU_CRITICAL_ENTER();
    if (pstat_pool->EntriesUsed > 0) {                          /* If any stat pool entry used,              ...        */
        pstat_pool->EntriesAvail++;                             /* ... adj nbr of avail/used entries in pool ...        */
        pstat_pool->EntriesUsed--;
        pstat_pool->EntriesDeallocatedCtr++;                    /* ... & inc total nbr of deallocated entries.          */

       *perr = NET_STAT_ERR_NONE;

    } else {
       *perr = NET_STAT_ERR_POOL_NONE_USED;
    }
    CPU_CRITICAL_EXIT();
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                     NetStat_PoolEntryLostInc()
*
* Description : Increment a statistics pool's number of 'Lost' entries.
*
* Argument(s) : pstat_pool  Pointer to a statistics pool.
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_STAT_ERR_NONE                   Statistics pool's number lost 
*                                                                       successfully incremented.
*                               NET_STAT_ERR_NULL_PTR               Argument 'pstat_pool' passed a NULL pointer.
*                               NET_STAT_ERR_POOL_INVALID_TYPE      Argument 'pstat_pool's TYPE is invalid
*                                                                       or unknown.
*                               NET_STAT_ERR_POOL_NONE_REM          NO statistics pool entries remain; i.e. 
*                                                                       total number of entries already zero.
*                               NET_STAT_ERR_POOL_NONE_USED         NO used statistics pool entries; i.e. 
*                                                                       number of used entries is zero.
*
* Return(s)   : none.
*
* Caller(s)   : various.
*
*               This function is an INTERNAL network protocol suite function & SHOULD NOT be called by 
*               application function(s).
*
* Note(s)     : (1) #### 'perr' may NOT be necessary (remove if unnecessary).
*********************************************************************************************************
*/

void  NetStat_PoolEntryLostInc (NET_STAT_POOL  *pstat_pool,
                                NET_ERR        *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
                                                                /* ------------------- VALIDATE PTR ------------------- */
    if (pstat_pool == (NET_STAT_POOL *)0) {
        NET_CTR_ERR_INC(NetStat_ErrNullPtrCtr);
       *perr = NET_STAT_ERR_NULL_PTR;
        return;
    }
                                                                /* ------------------- VALIDATE TYPE ------------------ */
    if (pstat_pool->Type != NET_STAT_TYPE_POOL) {
        NET_CTR_ERR_INC(NetStat_ErrInvalidTypeCtr);
       *perr = NET_STAT_ERR_POOL_INVALID_TYPE;
        return;
    }
#endif


    CPU_CRITICAL_ENTER();
    if (pstat_pool->EntriesTot > 0) {                           /* If   tot stat pool entries > 0, ...                  */
        if (pstat_pool->EntriesUsed > 0) {                      /* .. & any stat pool entry used,  ...                  */
            pstat_pool->EntriesUsed--;                          /* .. adj nbr used/total/lost entries in pool.          */
            pstat_pool->EntriesTot--;                         
            pstat_pool->EntriesLostCur++;
            pstat_pool->EntriesLostTot++;

           *perr = NET_STAT_ERR_NONE;
        } else {
           *perr = NET_STAT_ERR_POOL_NONE_USED;
        }

    } else {
       *perr = NET_STAT_ERR_POOL_NONE_REM;
    }
    CPU_CRITICAL_EXIT();
}
	 	 			 		    	 				 	    	 	 	 		    	     	 	 	 		 	  	  	  	     	 	      	   		 	 	 	   		   			 	     			  			 		   	 			       	  	 		  	 	  	 		 		   		  	  			 	  	 		 	 	 			 	 		 		 	 		 	   		 	 	 	   		     			  			 		  	 		 	  			 	 	 	 	  		  	   		   	   	 				 		 			 			  			 		   		 		 				 		 	    		   	  		 

⌨️ 快捷键说明

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