?? net_ctr.c
字號:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may not be used to write a similar
* product. This file may only be used in accordance with a license
* and should not be redistributed in any way.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK COUNTER MANAGEMENT
*
* Filename : net_ctr.c
* Version : V1.86
* Programmer(s) : ITJ
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define NET_CTR_MODULE
#include <net.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* NetCtr_CalcPctLarge()
*
* Description : Calculate percentage equation for large, double-length counters.
*
* (1) Counter percentage determined by the following equation :
*
* Numerator * 100%
* Percentage (%) = ----------------
* Denominator
*
* (a) To avoid complicated integer arithmetic on large, double-length counters, percentage
* calculation performed by shifting the numerator & denominator until all significant
* digits are located in the numerator's & denominator's low-order counters :
*
* (Numerator * 100%) / N
* Percentage (%) = ----------------------
* Denominator / N
*
* This does not affect the result of the percentage calculation, only the resolution.
*
*
* Argument(s) : pct_numer_hi High-order portion of numerator.
*
* pct_numer_lo Low -order portion of numerator.
*
* pct_denom_hi High-order portion of denominator.
*
* pct_denom_lo Low -order portion of denominator.
*
* Return(s) : Percentage calculation of numerator divided by denominator (see Note #1).
*
* Caller(s) : various.
*
* Note(s) : (2) This percentage calculation is a potentially expensive operation. Recommended only
* from low-priority, background tasks.
*
* (3) Although counters' native data type is unsigned integer & arithmetic right-shifts of
* unsigned integers SHOULD NOT produce a sign-extended '1' bit in the counters' most
* significant bit, clearing the most significant bit AFTER the right-shift ensures that
* no unexpected sign-extension occurs.
*********************************************************************************************************
*/
CPU_INT08U NetCtr_CalcPctLarge (NET_CTR pct_numer_hi,
NET_CTR pct_numer_lo,
NET_CTR pct_denom_hi,
NET_CTR pct_denom_lo)
{
CPU_INT08U pct;
while ((pct_denom_hi > 0) || /* While denom hi ctr > 0 OR ... */
(pct_numer_lo >= NET_CTR_PCT_NUMER_MAX_TH)) { /* ... numer lo ctr > lo-ctr pct th (see Note #1a), */
/* ... right-shift-rotate hi ctrs into lo ctrs. */
pct_denom_lo >>= 1; /* Right-shift denom lo ctr. */
if (pct_denom_hi & NET_CTR_BIT_LO) { /* If denom hi ctr LSb set, ... */
pct_denom_lo |= NET_CTR_BIT_HI; /* ... set denom lo ctr MSb. */
} else {
pct_denom_lo &= ~NET_CTR_BIT_HI; /* Else clr denom lo ctr MSb (see Note #3). */
}
pct_denom_hi >>= 1; /* Right-shift denom hi ctr ... */
pct_denom_hi &= ~NET_CTR_BIT_HI; /* ... & clr MSb (see Note #3). */
pct_numer_lo >>= 1; /* Right-shift numer lo ctr. */
if (pct_numer_hi & NET_CTR_BIT_LO) { /* If numer hi ctr LSb set, ... */
pct_numer_lo |= NET_CTR_BIT_HI; /* ... set numer lo ctr MSb. */
} else {
pct_numer_lo &= ~NET_CTR_BIT_HI; /* Else clr numer lo ctr MSb (see Note #3). */
}
pct_numer_hi >>= 1; /* Right-shift numer hi ctr ... */
pct_numer_hi &= ~NET_CTR_BIT_HI; /* ... & clr MSb (see Note #3). */
}
pct = (CPU_INT08U)((pct_numer_lo * 100) / pct_denom_lo); /* Calc pct (see Note #1). */
return (pct);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -