📄 net.h
字号:
#include <net_conn.h> /* Network Connection Management */
/*$PAGE*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
#define NET_TASK_NBR 2
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
NET_EXT CPU_BOOLEAN Net_InitDone; /* Indicates when network initialization is complete. */
/* ------------------------- NET CTRS ------------------------- */
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
NET_EXT NET_CTR Net_RxPktCtr; /* Indicates number of queued received packets NOT yet handled. */
NET_EXT NET_CTR Net_TxSuspendCtr; /* Indicates number of network transmits currently suspended. */
#endif
#if (NET_CTR_CFG_ERR_EN == DEF_ENABLED) /* ------------------------- NET ERRS ------------------------- */
NET_EXT NET_CTR Net_ErrInvalidProtocolCtr; /* Indicates number of invalid protocol handled. */
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NETWORK RECEIVE PACKET MACRO'S
*
* Description : Monitor number of network receive packet(s) queued &/or available.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : NetIF_Pkt_RxHandlerLoadBal(),
* NetOS_IF_RxTaskSignal().
*
* These macro's are network protocol suite to network interface (IF) macro's & SHOULD be
* called only by appropriate network interface function(s).
*
* 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 'net.c Net_RxPktIsAvail() Note #1',
* 'net.c Net_TxSuspend() Note #1',
* 'net.c Net_TxSuspendSignal() Note #1',
* & 'net_tcp.c NetTCP_TxConnTxQ() Note #10'.
*
* (2) Network receive packet functionality implemented with inline macro's to :
*
* (a) Reduce network receive packet handling overhead
* (b) Reduce network receive packet code size when disabled
*
* (3) ALL functions which call network receive packet macro's MUST declare local variable
* 'cpu_sr' if critical section method is configured as CPU_CRITICAL_METHOD_STATUS_LOCAL :
*
* #if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
* CPU_SR cpu_sr;
* #endif
*
* (a) #### Macro's require critical section for exclusive access?
*********************************************************************************************************
*/
/*$PAGE*/
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
#define NET_RX_PKT_INC() { CPU_CRITICAL_ENTER(); \
if (Net_RxPktCtr < NET_CTR_MAX) { \
Net_RxPktCtr++; \
} \
CPU_CRITICAL_EXIT(); }
#define NET_RX_PKT_DEC() { CPU_CRITICAL_ENTER(); \
if (Net_RxPktCtr > 0) { \
Net_RxPktCtr--; \
} \
CPU_CRITICAL_EXIT(); }
#else
#define NET_RX_PKT_INC()
#define NET_RX_PKT_DEC()
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
NET_ERR Net_Init (void); /* Network startup function. */
void Net_InitDflt (void); /* Initialize default values for configurable parameters. */
CPU_INT16U Net_VersionGet (void); /* Get network protocol suite software version. */
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
/* Check if any network receive packet(s) are available. */
CPU_BOOLEAN Net_RxPktIsAvail (NET_CTR rx_chk_nbr);
void Net_TxSuspend (void); /* Suspend network transmit. */
void Net_TxSuspendSignal (void); /* Signal network transmit suspend. */
#endif
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
* DEFINED IN OS'S net_os.c
*********************************************************************************************************
*/
void NetOS_Init (NET_ERR *perr); /* Create network objects. */
void NetOS_InitWait (NET_ERR *perr); /* Wait until network initialization is complete. */
void NetOS_InitSignal (NET_ERR *perr); /* Signal that network initialization is complete. */
void NetOS_Lock (NET_ERR *perr); /* Acquire access to network protocol suite. */
void NetOS_Unlock (void); /* Release access to network protocol suite. */
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
void NetOS_TxSuspendWait (void); /* Wait until network transmit suspend is signaled. */
void NetOS_TxSuspendSignal (void); /* Signal network transmit suspend. */
void NetOS_TxSuspendTimeoutSet (CPU_INT32U timeout_ms, /* Set network transmit suspend timeout. */
NET_ERR *perr);
CPU_INT32U NetOS_TxSuspendTimeoutGet_ms(NET_ERR *perr); /* Get network transmit suspend timeout. */
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef NET_CFG_INIT_CFG_VALS
#error "NET_CFG_INIT_CFG_VALS not #define'd in 'net_cfg.h' "
#error " [MUST be NET_INIT_CFG_VALS_DFLT ]"
#error " [ || NET_INIT_CFG_VALS_APP_INIT]"
#elif ((NET_CFG_INIT_CFG_VALS != NET_INIT_CFG_VALS_DFLT ) && \
(NET_CFG_INIT_CFG_VALS != NET_INIT_CFG_VALS_APP_INIT))
#error "NET_CFG_INIT_CFG_VALS illegally #define'd in 'net_cfg.h' "
#error " [MUST be NET_INIT_CFG_VALS_DFLT ]"
#error " [ || NET_INIT_CFG_VALS_APP_INIT]"
#endif
#ifndef NET_CFG_OPTIMIZE
#error "NET_CFG_OPTIMIZE not #define'd in 'net_cfg.h'"
#error " [MUST be NET_OPTIMIZE_SPD ] "
#error " [ || NET_OPTIMIZE_SIZE] "
#elif ((NET_CFG_OPTIMIZE != NET_OPTIMIZE_SPD ) && \
(NET_CFG_OPTIMIZE != NET_OPTIMIZE_SIZE))
#error "NET_CFG_OPTIMIZE illegally #define'd in 'net_cfg.h'"
#error " [MUST be NET_OPTIMIZE_SPD ] "
#error " [ || NET_OPTIMIZE_SIZE] "
#endif
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
#ifndef NET_CFG_TX_SUSPEND_TIMEOUT_MS
#error "NET_CFG_TX_SUSPEND_TIMEOUT_MS not #define'd in 'net_cfg.h' "
#error " [MUST be >= NET_TX_SUSPEND_TIMEOUT_MIN_MS]"
#error " [ && <= NET_TX_SUSPEND_TIMEOUT_MAX_MS]"
#elif ((NET_CFG_TX_SUSPEND_TIMEOUT_MS < NET_TX_SUSPEND_TIMEOUT_MIN_MS) || \
(NET_CFG_TX_SUSPEND_TIMEOUT_MS > NET_TX_SUSPEND_TIMEOUT_MAX_MS))
#error "NET_CFG_TX_SUSPEND_TIMEOUT_MS illegally #define'd in 'net_cfg.h' "
#error " [MUST be >= NET_TX_SUSPEND_TIMEOUT_MIN_MS]"
#error " [ && <= NET_TX_SUSPEND_TIMEOUT_MAX_MS]"
#endif
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif /* End of net module include. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -