📄 net_os.c
字号:
* Argument(s) : perr Pointer to variable that will receive the return error code from this function :
*
* NET_OS_ERR_NONE Network interface/OS initialization
* successful.
* 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) : NetIF_Pkt_Init(),
* NetIF_Char_Init().
*
* Note(s) : none.
*********************************************************************************************************
*/
/*$PAGE*/
void NetOS_IF_Init (NET_ERR *perr)
{
INT8U os_err;
/* Create receive queue (see Note #1a). */
NetOS_IF_RxQPtr = OSSemCreate((INT16U)0);
if (NetOS_IF_RxQPtr == (OS_EVENT *)0) {
*perr = NET_OS_ERR_INIT_IF_RX_Q;
return;
}
#if (OS_EVENT_NAME_SIZE >= NET_OBJ_NAME_SIZE_MAX)
OSEventNameSet((OS_EVENT *) NetOS_IF_RxQPtr,
(INT8U *) NET_IF_RX_Q_NAME,
(INT8U *)&os_err);
if (os_err != OS_NO_ERR) {
*perr = NET_OS_ERR_INIT_IF_RX_Q_NAME;
return;
}
#endif
/* Create NetOS_IF_RxTask() [see Note #1b]. */
#if (OS_TASK_CREATE_EXT_EN == 1)
#if (OS_STK_GROWTH == 1)
os_err = OSTaskCreateExt((void (*)(void *)) NetOS_IF_RxTask,
(void * ) 0,
(OS_STK * )&NetOS_IF_RxTaskStk[NET_OS_CFG_IF_RX_TASK_STK_SIZE - 1],
(INT8U ) NET_OS_CFG_IF_RX_TASK_PRIO,
(INT16U ) NET_OS_CFG_IF_RX_TASK_PRIO, /* Set task id same as task prio. */
(OS_STK * )&NetOS_IF_RxTaskStk[0],
(INT32U ) NET_OS_CFG_IF_RX_TASK_STK_SIZE,
(void * ) 0,
(INT16U )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));
#else
os_err = OSTaskCreateExt((void (*)(void *)) NetOS_IF_RxTask,
(void * ) 0,
(OS_STK * )&NetOS_IF_RxTaskStk[0],
(INT8U ) NET_OS_CFG_IF_RX_TASK_PRIO,
(INT16U ) NET_OS_CFG_IF_RX_TASK_PRIO, /* Set task id same as task prio. */
(OS_STK * )&NetOS_IF_RxTaskStk[NET_OS_CFG_IF_RX_TASK_STK_SIZE - 1],
(INT32U ) NET_OS_CFG_IF_RX_TASK_STK_SIZE,
(void * ) 0,
(INT16U )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));
#endif
#else
#if (OS_STK_GROWTH == 1)
os_err = OSTaskCreate((void (*)(void *)) NetOS_IF_RxTask,
(void * ) 0,
(OS_STK * )&NetOS_IF_RxTaskStk[NET_OS_CFG_IF_RX_TASK_STK_SIZE - 1],
(INT8U ) NET_OS_CFG_IF_RX_TASK_PRIO);
#else
os_err = OSTaskCreate((void (*)(void *)) NetOS_IF_RxTask,
(void * ) 0,
(OS_STK * )&NetOS_IF_RxTaskStk[0],
(INT8U ) NET_OS_CFG_IF_RX_TASK_PRIO);
#endif
#endif
if (os_err != OS_NO_ERR) {
*perr = NET_OS_ERR_INIT_IF_RX_TASK;
return;
}
#if (OS_TASK_NAME_SIZE >= NET_TASK_NAME_SIZE_MAX)
OSTaskNameSet((INT8U ) NET_OS_CFG_IF_RX_TASK_PRIO,
(INT8U *) NET_IF_RX_TASK_NAME,
(INT8U *)&os_err);
if (os_err != OS_NO_ERR) {
*perr = NET_OS_ERR_INIT_IF_RX_TASK_NAME;
return;
}
#endif
*perr = NET_OS_ERR_NONE;
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_IF_RxTask()
*
* Description : OS-dependent shell task to schedule & run Network Interface Receive Task Handler.
*
* (1) Shell task's primary purpose is to schedule & run NetIF_RxTaskHandler() forever;
* (i.e. shell task should NEVER exit).
*
*
* Argument(s) : p_data Pointer to task initialization data (required by uC/OS-II).
*
* Return(s) : none.
*
* Created by : NetOS_IF_Init().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void NetOS_IF_RxTask (void *p_data)
{
(void)&p_data; /* Prevent compiler warning. */
NetIF_RxTaskHandlerInit();
while (DEF_ON) {
NetIF_RxTaskHandler();
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_IF_RxTaskWait()
*
* Description : Wait on network interface receive queue for NIC receive signal.
*
* Argument(s) : perr Pointer to variable that will receive the return error code from this function :
*
* NET_IF_ERR_NONE Signal received from NIC receive ISR.
* NET_IF_ERR_RX_Q_EMPTY Network interface receive queue empty.
*
* Return(s) : none.
*
* Caller(s) : NetIF_RxTaskHandler().
*
* Note(s) : (1) If timeouts NOT desired, wait on network interface receive queue until signaled
* (i.e. do NOT exit).
*
* (2) If timeout desired, return NET_IF_ERR_RX_Q_EMPTY error on receive queue timeout.
* Implement timeout with OS-dependent function.
*********************************************************************************************************
*/
void NetOS_IF_RxTaskWait (NET_ERR *perr)
{
INT8U os_err;
OSSemPend(NetOS_IF_RxQPtr, (INT16U)0, &os_err); /* Wait on network interface receive queue. */
switch (os_err) {
case OS_NO_ERR:
*perr = NET_IF_ERR_NONE;
break;
case OS_TIMEOUT:
case OS_ERR_EVENT_TYPE:
case OS_ERR_PEVENT_NULL:
case OS_ERR_PEND_ISR:
default:
*perr = NET_IF_ERR_RX_Q_EMPTY;
break;
}
}
/*$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 Network interface receive queue signal failed.
*
* Return(s) : none.
*
* Caller(s) : NetNIC_RxISR_Handler(), For packet -based NICs.
* NetNIC_RxPktHandler(). For character-based NICs.
*
* 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_RxQPtr); /* Signal network interface receive queue. */
switch (os_err) {
case OS_NO_ERR:
/* 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_EVENT_TYPE:
case OS_ERR_PEVENT_NULL:
default:
*perr = NET_IF_ERR_RX_Q_SIGNAL;
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 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.
*
* 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.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -