📄 net_os.c
字号:
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_IF_RxTaskSignal()
*
* Description : Signal network interface receive task of NIC receive ISR.
*
* Argument(s) : psignal Pointer to signal value to post to network interface receive queue.
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_IF_ERR_NONE Network interface receive queue successfully
* signaled.
* NET_IF_ERR_RX_Q_FULL Network interface receive queue full.
* NET_IF_ERR_RX_Q_SIGNAL_FAULT Network interface receive queue signal fault.
*
* Return(s) : none.
*
* Caller(s) : NetNIC_RxISR_Handler(), for packet -based NICs.
* NetNIC_RxPktHandler(), for character-based NICs.
*
* This function is a network protocol suite to network interface controller (NIC) function
* & SHOULD be called only by appropriate network interface controller 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.
*
* (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.
*
* See also 'NETWORK RECEIVE PACKET MACRO'S Note #1'.
*********************************************************************************************************
*/
void NetOS_IF_RxTaskSignal (NET_ERR *perr)
{
#if ((NET_CFG_LOAD_BAL_EN == DEF_ENABLED) && \
(CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
CPU_SR cpu_sr;
#endif
INT8U os_err;
os_err = OSSemPost(NetOS_IF_RxQ_SignalPtr); /* Signal network interface receive queue. */
switch (os_err) {
case OS_ERR_NONE:
/* Increment number of queued receive packets ... */
NET_RX_PKT_INC(); /* ... available (see Note #1b1A). */
*perr = NET_IF_ERR_NONE;
break;
case OS_SEM_OVF:
*perr = NET_IF_ERR_RX_Q_FULL;
break;
case OS_ERR_PEVENT_NULL:
case OS_ERR_EVENT_TYPE:
default:
*perr = NET_IF_ERR_RX_Q_SIGNAL_FAULT;
break;
}
}
/*$PAGE*/
/*
*********************************************************************************************************
*********************************************************************************************************
* INTERNET CONTROL MESSAGE PROTOCOL LAYER FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NetOS_ICMP_TxMsgReq()
*
* Description : Transmit ICMP Request Message.
*
* (1) NetOS_ICMP_TxMsgReq() is the correct API function for network & end-user applications to
* transmit ICMP Request Messages (see also 'net_icmp.c NetICMP_TxMsgReq() Note #3').
*
* (2) See 'net_icmp.h ICMP MESSAGE TYPES & CODES Notes #2 & #3' for supported ICMP message
* types & codes.
*
*
* Argument(s) : type ICMP Request Message type (see Note #2) :
*
* NET_ICMP_MSG_TYPE_ECHO_REQ
* NET_ICMP_MSG_TYPE_TS_REQ
* NET_ICMP_MSG_TYPE_ADDR_MASK_REQ
*
* code ICMP Request Message code (see Note #2).
*
* TOS Specific TOS to transmit IP packet
* (see 'net_ip.h IP HEADER TYPE OF SERVICE (TOS) DEFINES').
*
* TTL Specific TTL to transmit IP packet (see 'net_ip.h IP HEADER DEFINES').
*
* addr_dest Destination IP address.
*
* flags Flags to select transmit options; bit-field flags logically OR'd :
*
* NET_IP_FLAG_NONE No IP transmit flags selected.
* NET_IP_FLAG_TX_DONT_FRAG Set IP 'Don't Frag' flag.
*
* popts Pointer to one or more IP options configuration data structures :
*
* NULL NO IP transmit options configuration.
* NET_IP_OPT_CFG_ROUTE_TS Route &/or Internet Timestamp options configuration.
* NET_IP_OPT_CFG_SECURITY Security options configuration
* (see 'net_ip.h Note #1f').
*
* perr Pointer to variable that will receive the return error code from this function :
*
* ------ RETURNED BY NetICMP_TxMsgReq() : ------
* NET_ICMP_ERR_NONE ICMP Request Message successfully transmitted.
* NET_ERR_INIT_INCOMPLETE Network initialization NOT complete.
* NET_ERR_TX Transmit error; packet discarded.
*
* Return(s) : ICMP Request Message's Identification (ID) & Sequence Numbers, if NO errors.
*
* NULL Identification (ID) & Sequence Numbers, otherwise.
*
* Caller(s) : Application.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s).
*
* Note(s) : (3) (a) RFC #792 states that the Identifier field is an "aid in matching [requests] and
* replies, may be zero ... For example, the identifier might be used like a port
* in TCP or UDP to identify a session" (Sections 'Echo or Echo Reply Message :
* Identifier, Description' & 'Timestamp or Timestamp Reply Message : Identifier,
* Description').
*
* (b) Use uC/OS-II task priority number as ICMP Request Message Identification field.
*
* (4) #### ICMP Receive Error/Reply Messages NOT yet implemented.
*
* See also 'net_icmp.c NetICMP_Rx() Note #4'.
*********************************************************************************************************
*/
/*$PAGE*/
NET_ICMP_REQ_ID_SEQ NetOS_ICMP_TxMsgReq (CPU_INT08U type,
CPU_INT08U code,
NET_IP_TOS TOS,
NET_IP_TTL TTL,
NET_IP_ADDR addr_dest,
CPU_INT16U flags,
void *popts,
void *p_data,
CPU_INT16U data_len,
NET_ERR *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
CPU_INT16U id;
NET_ICMP_REQ_ID_SEQ id_seq;
CPU_CRITICAL_ENTER();
id = (CPU_INT16U)OSTCBCur->OSTCBPrio; /* Set task prio as ICMP Req Msg id (see Note #3b). */
CPU_CRITICAL_EXIT();
id_seq = NetICMP_TxMsgReq(type, code, id, TOS, TTL, addr_dest, flags, popts, p_data, data_len, perr);
return (id_seq);
}
/*$PAGE*/
/*
*********************************************************************************************************
*********************************************************************************************************
* TRANSMISSION CONTROL PROTOCOL LAYER FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NetOS_TCP_Init()
*
* Description : (1) Perform TCP/OS initialization :
*
* (a) Create TCP connection receive queue binary semaphores :
*
* (1) Initialize TCP connection receive queue binary semaphores with no received
* packets by setting the semaphore count to 0.
* (2) Initialize TCP connection receive queue timeout values.
*
* (b) Create TCP connection transmit queue binary semaphores :
*
* (1) Initialize TCP connection transmit queue binary semaphores with no transmit
* permissions by setting the semaphore count to 0.
* (2) Initialize TCP connection transmit queue timeout values.
*
*
* Argument(s) : perr Pointer to variable that will receive the return error code from this function :
*
* NET_OS_ERR_NONE TCP/OS initialization successful.
* NET_OS_ERR_INIT_TCP_RX_Q TCP receive queue(s) NOT
* successfully initialized.
* NET_OS_ERR_INIT_TCP_RX_Q_TIMEOUT TCP receive queue timeout(s) NOT
* successfully configured.
* NET_OS_ERR_INIT_TCP_TX_Q TCP transmit queue(s) NOT
* successfully initialized.
* NET_OS_ERR_INIT_TCP_TX_Q_TIMEOUT TCP transmit queue timeout(s) NOT
* successfully configured.
*
* Return(s) : none.
*
* Caller(s) : NetTCP_Init().
*
* This function is an INTERNAL network protocol suite function & MUST NOT be called by
* application function(s).
*
* Note(s) : none.
*********************************************************************************************************
*/
/*$PAGE*/
#ifdef NET_TCP_MODULE_PRESENT
void NetOS_TCP_Init (NET_ERR *perr)
{
OS_EVENT **psignal;
NET_TCP_CONN_QTY i;
NET_ERR net_err;
/* Initialize TCP connection queues (see Note #1). */
psignal = &NetOS_TCP_RxQ_SignalPtr[0];
for (i = 0; i < NET_TCP_CFG_NBR_CONN; i++) {
*psignal = OSSemCreate((INT16U)0); /* Create TCP connection receive queue semaphores. */
if (*psignal == (OS_EVENT *)0) {
*perr = NET_OS_ERR_INIT_TCP_RX_Q;
return;
}
psignal++;
/* Initialize TCP connection receive queue timeout values. */
NetOS_TCP_RxQ_TimeoutDflt(i, &net_err);
if (net_err != NET_TCP_ERR_NONE) {
*perr = NET_OS_ERR_INIT_TCP_RX_Q_TIMEOUT;
return;
}
}
psignal = &NetOS_TCP_TxQ_SignalPtr[0];
for (i = 0; i < NET_TCP_CFG_NBR_CONN; i++) {
*psignal = OSSemCreate((INT16U)0); /* Create TCP connection transmit queue semaphores. */
if (*psignal == (OS_EVENT *)0) {
*perr = NET_OS_ERR_INIT_TCP_TX_Q;
return;
}
psignal++;
/* Initialize TCP connection transmit queue timeout values. */
NetOS_TCP_TxQ_TimeoutDflt(i, &net_err);
if (net_err != NET_TCP_ERR_NONE) {
*perr = NET_OS_ERR_INIT_TCP_TX_Q_TIMEOUT;
return;
}
}
*perr = NET_OS_ERR_NONE;
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_TCP_RxQ_Clr()
*
* Description : Clear TCP connection receive queue signal.
*
* Argument(s) : conn_id_tcp Handle identifier of TCP connection to clear receive queue signal.
* ----------- Argument validated in NetTCP_RxAppData(),
* NetTCP_RxPktConnHandlerRxQ_AppData(),
* NetTCP_ConnFreeHandler().
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_TCP_ERR_NONE TCP connection receive queue signal
* successfully cleared.
* NET_TCP_ERR_RX_Q_SIGNAL_CLR TCP connection receive queue signal
* NOT cleared.
*
* Return(s) : none.
*
* Caller(s) : NetTCP_RxAppData(),
* NetTCP_RxPktConnHandlerRxQ_AppData(),
* NetTCP_ConnFreeHandler().
*
* This function is an INTERNAL network protocol suite function & MUST NOT be called by
* application function(s).
*
* Note(s) : none.
********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -