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

📄 swrate.c

📁 VIA VT6524 8口网管交换机源码
💻 C
字号:
/*
 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
 * All rights reserved.
 *
 * This software is copyrighted by and is the sole property of
 * VIA Networking Technologies, Inc. This software may only be used
 * in accordance with the corresponding license agreement. Any unauthorized
 * use, duplication, transmission, distribution, or disclosure of this
 * software is expressly forbidden.
 *
 * This software is provided by VIA Networking Technologies, Inc. "as is"
 * and any express or implied warranties, including, but not limited to, the
 * implied warranties of merchantability and fitness for a particular purpose
 * are disclaimed. In no event shall VIA Networking Technologies, Inc.
 * be liable for any direct, indirect, incidental, special, exemplary, or
 * consequential damages.
 *
 *
 * File:    swrate.c
 *
 * Purpose:
 *
 * Author:  Jenda Jao
 *
 * Date:    02 20, 2003
 *
 * Functions:
 *
 * Revision History:
 *
 */


#if !defined(__SWITCH_H__)
#include "switch.h"
#endif
#if !defined(__SWREG_H__)
#include "swreg.h"
#endif




/*---------------------  Static Definitions  ------------------------*/
#define PTN_BW_CTRL_BUDGET_FACTOR   15421.81      // wRate * 1000000 / 64.0 * (1518.0/1538.0)
#define PTN_BW_CTRL_BUDGET          0x3FFF
#define PTN_BW_CTRL_10MS            0xC000
#define PTN_BW_CTRL_100MS           0x8000

/*---------------------  Static Types  ------------------------------*/

/*---------------------  Static Macros  -----------------------------*/

/*---------------------  Static Classes  ----------------------------*/

/*---------------------  Static Variables  --------------------------*/

/*---------------------  Static Functions  --------------------------*/

/*---------------------  Export Variables  --------------------------*/




/*
 *  Calculation of egress/ingress rate:
 *      Budget unit:            64   bits
 *      Rate unit:              1M   bps
 *      Max packet size:        1518 Byte
 *      IFG + Preamble size:    20   Byte
 */
static UINT16 s_wCalRateRegVal(UINT32 dwBudget) DIRECT_FUNTYPE_REENT
{
    if (dwBudget == 0)
        return 0;

    // Set budget & time unit
    //dwBudget = dwBudget * 1000000 / 64.0 * (1518.0/1538.0);
    dwBudget *= PTN_BW_CTRL_BUDGET_FACTOR;

    if (dwBudget > PTN_BW_CTRL_BUDGET)  // 10ms
        return ((UINT16)(dwBudget / 100) | PTN_BW_CTRL_10MS);
    else                                // 100ms
        return ((UINT16)(dwBudget / 10) | PTN_BW_CTRL_100MS);
}


void SWRATE_vSetRateCtrl(BYTE byPortId, BYTE byIngress, BYTE byEgress) DIRECT_FUNTYPE_REENT
{
    SWREG_vWriteW((UINT16)(QUE_INGRESS_RATE_BASE + byPortId * 2), s_wCalRateRegVal(byIngress));
    SWREG_vWriteW((UINT16)(QUE_EGRESS_RATE_BASE + byPortId * 2), s_wCalRateRegVal(byEgress));
}

⌨️ 快捷键说明

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