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

📄 net_if_pkt.c

📁 uCOS-II V2.84 LM3S6965 TCPIP Demo
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
*********************************************************************************************************
*                                              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.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                 PACKET-BASED NETWORK INTERFACE LAYER
*
* Filename      : net_if_pkt.c
* Version       : V1.86
* Programmer(s) : ITJ
*********************************************************************************************************
* Note(s)       : (1) Supports packet-based Network Interface Cards/Layers.
*
*                 (2) Packet-based Network Interface Layer also referred to as 'Packet Interface' & also
*                     abbreviated as network interface.
*********************************************************************************************************
*/

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

#define    NET_IF_PKT_MODULE
#include  <net.h>


/*
*********************************************************************************************************
*                                               MODULE
*
* Note(s) : (1) See 'net_if_pkt.h  MODULE'.
*********************************************************************************************************
*/

#ifdef  NET_IF_PKT_MODULE_PRESENT


/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/


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


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


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


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


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

                                                                    /* ------------------- RX FNCTS ------------------- */
static  void  NetIF_Pkt_Rx              (void);

#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
static  void  NetIF_Pkt_RxHandlerLoadBal(void);
#endif

static  void  NetIF_Pkt_RxPktDiscard    (NET_BUF      *pbuf);


                                                                    /* ------------------- TX FNCTS ------------------- */

#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static  void  NetIF_Pkt_TxPktValidate   (NET_BUF      *pbuf,
                                         NET_BUF_HDR  *pbuf_hdr,
                                         NET_ERR      *perr);
#endif

static  void  NetIF_Pkt_TxPktFree       (NET_BUF      *pbuf);

static  void  NetIF_Pkt_TxPktDiscard    (NET_BUF      *pbuf,
                                         NET_ERR      *perr);


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


/*$PAGE*/
/*
*********************************************************************************************************
*                                          NetIF_Pkt_Init()
*
* Description : (1) Initialize Packet-based Network Interface Layer :
*
*                   (a) Perform    Packet Interface/OS initialization
*                   (b) Initialize Packet Interface statistics & error counters
*
*
* Argument(s) : perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_IF_ERR_NONE                     Network interface layer successfully
*                                                                       initialized.
*
*                                                                   --- RETURNED BY NetOS_IF_Init() : ----
*                               NET_OS_ERR_INIT_IF_RX_Q             Network interface receive queue signal
*                                                                       NOT successfully initialized.
*                               NET_OS_ERR_INIT_IF_RX_Q_NAME        Network interface receive queue name
*                                                                       NOT successfully configured.
*                               NET_OS_ERR_INIT_IF_RX_TASK          Network interface receive task
*                                                                       NOT successfully initialized.
*                               NET_OS_ERR_INIT_IF_RX_TASK_NAME     Network interface receive task  name 
*                                                                       NOT successfully configured.
*
* Return(s)   : none.
*
* Caller(s)   : Net_Init().
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  NetIF_Pkt_Init (NET_ERR  *perr)
{
                                                                /* -------------- PERFORM PKT IF/OS INIT -------------- */
    NetOS_IF_Init(perr);                                        /* Create pkt IF obj(s)/task(s).                        */
    if (*perr != NET_OS_ERR_NONE) {
         return;
    }

                                                                /* ----------- INIT PKT IF STAT & ERR CTRS ------------ */
#if (NET_CTR_CFG_STAT_EN            == DEF_ENABLED)
    NetIF_Pkt_StatRxPktCtr          =  0;
    NetIF_Pkt_StatRxPktProcessedCtr =  0;

    NetIF_Pkt_StatTxPktCtr          =  0;
#endif

#if (NET_CTR_CFG_ERR_EN             == DEF_ENABLED)
    NetIF_Pkt_ErrRxPktDiscardedCtr  =  0;

    NetIF_Pkt_ErrTxPktDiscardedCtr  =  0;

#if (NET_ERR_CFG_ARG_CHK_DBG_EN     == DEF_ENABLED)
    NetIF_Pkt_ErrTxProtocolCtr      =  0;
    NetIF_Pkt_ErrTxInvalidBufIxCtr  =  0;
#endif
#endif


   *perr = NET_IF_ERR_NONE;
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                      NetIF_RxTaskHandlerInit()
*
* Description : Initialize Packet-based Network Interface Receive Task Handler.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : NetOS_IF_RxTask() [see 'net_os.c'].
*
* Note(s)     : (1) Network Interface Receive Task Handler functions named 'NetIF_' ONLY to allow NIC & OS port
*                   interfaces to be generic for either packet-based or character-based network interface.
*********************************************************************************************************
*/

void  NetIF_RxTaskHandlerInit (void)
{
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                        NetIF_RxTaskHandler()
*
* Description : (1) Handle received data packets from network interface card :
*
*                   (a) Wait for Receive ISR signal from Network Interface Card (NIC)
*                   (b) Handle   received packet
*                   (c) Handle network load balancing
*
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : NetOS_IF_RxTask() [see 'net_os.c'].
*
* Note(s)     : (2) Network Interface Receive Task Handler functions named 'NetIF_' ONLY to allow NIC & OS port
*                   interfaces to be generic for either packet-based or character-based network interface.
*
*               (3) NetIF_RxTaskHandler() blocked until network initialization completes.
*
*               (4) NetIF_RxTaskHandler() blocks ALL other network protocol tasks by pending on & acquiring
*                   the global network lock (see 'net.h  Note #2').
*********************************************************************************************************
*/

void  NetIF_RxTaskHandler (void)
{
    NET_ERR  err_rx;


    if (Net_InitDone != DEF_YES) {                              /* If init NOT complete, ...                            */
        NetOS_InitWait(&err_rx);                                /* ... wait on net init (see Note #3).                  */
        if (err_rx != NET_OS_ERR_NONE) {
            return;
        }
    }


    while (DEF_ON) {
                                                                /* -------------- WAIT FOR NIC RX SIGNAL -------------- */
        do {
            NetOS_IF_RxTaskWait(&err_rx);
        } while (err_rx != NET_IF_ERR_NONE);


        NetOS_Lock(&err_rx);                                    /* Acquire net lock (see Note #4).                      */
        if (err_rx != NET_OS_ERR_NONE) {
            return;
        }

                                                                /* ------------------ HANDLE PKT RX ------------------- */
        NetIF_Pkt_Rx();

⌨️ 快捷键说明

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