📄 net_if_pkt.c
字号:
return; /* Prevent 'break NOT reachable' compiler warning. */
}
/* ----------------- UPDATE RX STATS ------------------ */
switch (err_rx) { /* Chk err from NetIF_Rx(). */
case NET_IF_ERR_NONE:
NET_CTR_STAT_INC(NetIF_Pkt_StatRxPktProcessedCtr);
break;
case NET_ERR_INIT_INCOMPLETE:
case NET_ERR_RX:
NET_CTR_ERR_INC(NetIF_Pkt_ErrRxPktDiscardedCtr); /* See Note #3. */
break;
default:
NetIF_Pkt_RxPktDiscard(pbuf);
return; /* Prevent 'break NOT reachable' compiler warning. */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetIF_Pkt_RxHandlerLoadBal()
*
* Description : Handle network receive versus transmit load balancing.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : NetIF_RxTaskHandler().
*
* Note(s) : (1) To balance network receive versus transmit packet loads for certain network connection
* types (e.g. stream-type connections), network receive & transmit packets SHOULD be
* handled in an APPROXIMATELY balanced ratio.
*
* (a) Network task priorities & lock mechanisms partially maintain a balanced ratio
* between network receive versus transmit packet handling.
*
* However, the handling of network receive & transmit packets :
*
* (1) SHOULD be interleaved so that for every few packet(s) received & handled,
* several packet(s) should be transmitted; & vice versa.
*
* (2) SHOULD NOT exclusively handle receive nor transmit packets, even for a
* short period of time.
*
* (b) To implement network receive versus transmit load balancing :
*
* (1) The availability of network receive packets MUST be managed at the network
* interface layer :
*
* (A) Increment the number of available network receive packets queued for
* each network packet received.
*
* (B) Decrement the number of available network receive packets queued for
* each received packet handled.
*
* (2) Certain network connections MUST periodically suspend network transmit(s)
* to handle network receive packet(s) :
*
* (A) Suspend network transmit(s) if network receive packets are available.
*
* (B) Signal or timeout network transmit suspend(s) to restart transmit(s).
*
* See also 'NETWORK RECEIVE PACKET MACRO'S Note #1'.
*********************************************************************************************************
*/
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
static void NetIF_Pkt_RxHandlerLoadBal (void)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
NET_RX_PKT_DEC(); /* Dec nbr q'd rx pkts avail (see Note #1b1B). */
Net_TxSuspendSignal(); /* Signal net tx suspend (see Note #1b2B). */
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* NetIF_Pkt_RxPktDiscard()
*
* Description : On any Packet-based Network Interface Receive errors, discard packet & buffer.
*
* Argument(s) : pbuf Pointer to network buffer.
*
* Return(s) : none.
*
* Caller(s) : NetIF_Pkt_Rx().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void NetIF_Pkt_RxPktDiscard (NET_BUF *pbuf)
{
NET_CTR *pctr;
#if (NET_CTR_CFG_ERR_EN == DEF_ENABLED)
pctr = (NET_CTR *)&NetIF_Pkt_ErrRxPktDiscardedCtr;
#else
pctr = (NET_CTR *) 0;
#endif
NetBuf_FreeBuf((NET_BUF *)pbuf,
(NET_CTR *)pctr);
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetIF_Pkt_TxPktValidate()
*
* Description : (1) Validate network interface transmit packet parameters :
*
* (a) Packets with the following invalid parameters will be "silently discarded" :
*
* (1) Protocols other than supported protocols :
* (A) Frame
*
* (2) Total Length
*
*
* Argument(s) : pbuf Pointer to network buffer to transmit network interface packet.
* ---- Argument checked in NetIF_Pkt_Tx().
*
* pbuf_hdr Pointer to network buffer header.
* -------- Argument validated in NetIF_Pkt_Tx().
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_IF_ERR_NONE Transmit packet validated.
* NET_ERR_INVALID_PROTOCOL Invalid/unknown protocol type.
* NET_BUF_ERR_INVALID_IX Invalid or insufficient buffer index.
*
* Return(s) : none.
*
* Caller(s) : NetIF_Pkt_Tx().
*
* Note(s) : none.
*********************************************************************************************************
*/
#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)
{
#if ((NET_CTR_CFG_ERR_EN == DEF_ENABLED) && \
(CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
CPU_SR cpu_sr;
#endif
CPU_INT16U ix;
/* ----------------- VALIDATE PROTOCOL ---------------- */
switch (pbuf_hdr->ProtocolHdrType) {
case NET_PROTOCOL_TYPE_FRAME:
ix = pbuf_hdr->IF_HdrIx;
break;
case NET_PROTOCOL_TYPE_NONE:
default:
NET_CTR_ERR_INC(NetIF_Pkt_ErrTxProtocolCtr);
*perr = NET_ERR_INVALID_PROTOCOL;
return; /* Prevent 'break NOT reachable' compiler warning. */
}
if (ix == NET_BUF_IX_NONE) {
NET_CTR_ERR_INC(NetIF_Pkt_ErrTxInvalidBufIxCtr);
*perr = NET_BUF_ERR_INVALID_IX;
return;
}
*perr = NET_IF_ERR_NONE;
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* NetIF_Pkt_TxPktFree()
*
* Description : Free network buffer.
*
* Argument(s) : pbuf Pointer to network buffer.
*
* Return(s) : none.
*
* Caller(s) : NetIF_Pkt_Tx().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void NetIF_Pkt_TxPktFree (NET_BUF *pbuf)
{
NetBuf_FreeBuf((NET_BUF *)pbuf,
(NET_CTR *)0);
}
/*
*********************************************************************************************************
* NetIF_Pkt_TxPktDiscard()
*
* Description : On any Transmit errors, discard packet & buffer.
*
* Argument(s) : pbuf Pointer to network buffer.
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_ERR_TX Transmit error; packet discarded.
*
* Return(s) : none.
*
* Caller(s) : NetIF_Pkt_Tx().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void NetIF_Pkt_TxPktDiscard (NET_BUF *pbuf,
NET_ERR *perr)
{
NET_CTR *pctr;
#if (NET_CTR_CFG_ERR_EN == DEF_ENABLED)
pctr = (NET_CTR *)&NetIF_Pkt_ErrTxPktDiscardedCtr;
#else
pctr = (NET_CTR *) 0;
#endif
NetBuf_FreeBuf((NET_BUF *)pbuf,
(NET_CTR *)pctr);
*perr = NET_ERR_TX;
}
/*$PAGE*/
/*
*********************************************************************************************************
* MODULE END
*
* Note(s) : (1) See 'MODULE Note #1' & 'net_if_pkt.h MODULE Note #1'.
*********************************************************************************************************
*/
#endif /* End of pkt-based net IF module include (see Note #1).*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -