📄 net_os.c
字号:
NetOS_InitSignalPtr = OSSemCreate((INT16U)0); /* Create network initialization signal (see Note #1a). */
if (NetOS_InitSignalPtr == (OS_EVENT *)0) {
*perr = NET_OS_ERR_INIT_SIGNAL;
return;
}
#if (OS_EVENT_NAME_SIZE >= NET_OBJ_NAME_SIZE_MAX)
OSEventNameSet((OS_EVENT *) NetOS_InitSignalPtr,
(INT8U *) NET_INIT_NAME,
(INT8U *)&os_err);
if (os_err != OS_ERR_NONE) {
*perr = NET_OS_ERR_INIT_SIGNAL_NAME;
return;
}
#endif
NetOS_LockPtr = OSSemCreate((INT16U)1); /* Create network lock (see Note #1b). */
if (NetOS_LockPtr == (OS_EVENT *)0) {
*perr = NET_OS_ERR_INIT_LOCK;
return;
}
#if (OS_EVENT_NAME_SIZE >= NET_OBJ_NAME_SIZE_MAX)
OSEventNameSet((OS_EVENT *) NetOS_LockPtr,
(INT8U *) NET_LOCK_NAME,
(INT8U *)&os_err);
if (os_err != OS_ERR_NONE) {
*perr = NET_OS_ERR_INIT_LOCK_NAME;
return;
}
#endif
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
NetOS_TxSuspendSignalPtr = OSSemCreate((INT16U)0); /* Create network transmit suspend signal (see Note #1c). */
if (NetOS_TxSuspendSignalPtr == (OS_EVENT *)0) {
*perr = NET_OS_ERR_INIT_TX_SUSPEND;
return;
}
/* Initialize net transmit suspend signal timeout value. */
NetOS_TxSuspendTimeoutSet(NET_CFG_TX_SUSPEND_TIMEOUT_MS, &net_err);
if (net_err != NET_ERR_NONE) {
*perr = NET_OS_ERR_INIT_TX_SUSPEND_TIMEOUT;
return;
}
#if (OS_EVENT_NAME_SIZE >= NET_OBJ_NAME_SIZE_MAX)
OSEventNameSet((OS_EVENT *) NetOS_TxSuspendSignalPtr,
(INT8U *) NET_TX_SUSPEND_NAME,
(INT8U *)&os_err);
if (os_err != OS_ERR_NONE) {
*perr = NET_OS_ERR_INIT_TX_SUSPEND_NAME;
return;
}
#endif
#endif
*perr = NET_OS_ERR_NONE;
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_InitWait()
*
* Description : Wait on signal indicating network initialization is complete.
*
* Argument(s) : perr Pointer to variable that will receive the return error code from this function :
*
* NET_OS_ERR_NONE Initialization signal received.
* NET_OS_ERR_INIT Initialization signal NOT received.
*
* Return(s) : none.
*
* Caller(s) : NetIF_RxTaskHandler(),
* NetTmr_TaskHandler().
*
* This function is an INTERNAL network protocol suite function & MUST NOT be called by
* application function(s).
*
* Note(s) : (1) Network initialization signal MUST be acquired--i.e. MUST wait for access; do NOT timeout.
*
* Failure to acquire signal will prevent network task(s) from running.
*********************************************************************************************************
*/
void NetOS_InitWait (NET_ERR *perr)
{
INT8U os_err;
OSSemPend((OS_EVENT *) NetOS_InitSignalPtr, /* Wait until network initialization completes ... */
(INT16U ) 0, /* ... without timeout (see Note #1). */
(INT8U *)&os_err);
switch (os_err) {
case OS_ERR_NONE:
*perr = NET_OS_ERR_NONE;
break;
case OS_ERR_PEVENT_NULL:
case OS_ERR_EVENT_TYPE:
case OS_ERR_PEND_ISR:
case OS_ERR_PEND_ABORT:
case OS_ERR_TIMEOUT:
default:
*perr = NET_OS_ERR_INIT;
break;
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_InitSignal()
*
* Description : Signal that network initialization is complete.
*
* Argument(s) : perr Pointer to variable that will receive the return error code from this function :
*
* NET_OS_ERR_NONE Network initialization successfully signaled.
* NET_OS_ERR_INIT_SIGNALD Network initialization NOT successfully signaled.
*
* Return(s) : none.
*
* Caller(s) : Net_Init().
*
* This function is an INTERNAL network protocol suite function & MUST NOT be called by
* application function(s).
*
* Note(s) : (1) Network initialization MUST be signaled--i.e. MUST signal without failure.
*
* Failure to signal will prevent network task(s) from running.
*********************************************************************************************************
*/
void NetOS_InitSignal (NET_ERR *perr)
{
INT8U os_err;
os_err = OSSemPost(NetOS_InitSignalPtr); /* Signal network initialization complete. */
if (os_err != OS_ERR_NONE) {
*perr = NET_OS_ERR_INIT_SIGNALD;
}
*perr = NET_OS_ERR_NONE;
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_Lock()
*
* Description : Acquire mutually exclusive access to network protocol suite.
*
* Argument(s) : perr Pointer to variable that will receive the return error code from this function :
*
* NET_OS_ERR_NONE Network access acquired.
* NET_OS_ERR_LOCK Network access NOT acquired.
*
* Return(s) : none.
*
* Caller(s) : various.
*
* This function is an INTERNAL network protocol suite function & SHOULD NOT be called by
* application function(s).
*
* Note(s) : (1) Network access MUST be acquired--i.e. MUST wait for access; do NOT timeout.
*
* Failure to acquire network access will prevent network task(s)/operation(s)
* from functioning.
*********************************************************************************************************
*/
void NetOS_Lock (NET_ERR *perr)
{
INT8U os_err;
OSSemPend((OS_EVENT *) NetOS_LockPtr, /* Acquire network access ... */
(INT16U ) 0, /* ... without timeout (see Note #1). */
(INT8U *)&os_err);
switch (os_err) {
case OS_ERR_NONE:
*perr = NET_OS_ERR_NONE;
break;
case OS_ERR_PEVENT_NULL:
case OS_ERR_EVENT_TYPE:
case OS_ERR_PEND_ISR:
case OS_ERR_PEND_ABORT:
case OS_ERR_TIMEOUT:
default:
*perr = NET_OS_ERR_LOCK;
break;
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_Unlock()
*
* Description : Release mutually exclusive access to network protocol suite.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : various.
*
* This function is an INTERNAL network protocol suite function & SHOULD NOT be called by
* application function(s).
*
* Note(s) : (1) Network access MUST be released--i.e. MUST unlock access without failure.
*
* Failure to release network access will prevent network task(s)/operation(s)
* from functioning.
*********************************************************************************************************
*/
void NetOS_Unlock (void)
{
(void)OSSemPost(NetOS_LockPtr); /* Release network access. */
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_TxSuspendWait()
*
* Description : Wait on network transmit suspend signal.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Net_TxSuspend().
*
* This function is an INTERNAL network protocol suite function & MUST NOT be called by
* application function(s).
*
* Note(s) : (1) Network transmit suspend waits until :
*
* (a) Signaled
* (b) Timed out
* (c) Any OS fault occurs
*
* (2) Implement timeout with OS-dependent functionality.
*********************************************************************************************************
*/
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
void NetOS_TxSuspendWait (void)
{
INT8U os_err;
/* Wait on network transmit suspend signal. */
OSSemPend(NetOS_TxSuspendSignalPtr, NetOS_TxSuspendTimeout_tick, &os_err);
(void)&os_err; /* See Note #1c. */
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_TxSuspendSignal()
*
* Description : Signal network transmit suspend.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Net_TxSuspendSignal().
*
* This function is an INTERNAL network protocol suite function & MUST NOT be called by
* application function(s).
*
* Note(s) : (1) Failure to signal network transmit suspend signal will cause network transmit suspends
* to timeout.
*
* See also 'NetOS_TxSuspendWait() Note #1b'.
*********************************************************************************************************
*/
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
void NetOS_TxSuspendSignal (void)
{
(void)OSSemPost(NetOS_TxSuspendSignalPtr); /* Signal network transmit suspend. */
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* NetOS_TxSuspendTimeoutSet()
*
* Description : Set network transmit suspend timeout value.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -