📄 net_os.c
字号:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2007; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/TCP-IP is provided in source form for FREE evaluation, for educational
* use or peaceful research. If you plan on using uC/TCP-IP in a commercial
* product you need to contact Micrium to properly license its use in your
* product. We provide ALL the source code for your convenience and to help
* you experience uC/TCP-IP. The fact that the source code is provided does
* NOT mean that you can use it without paying a licensing fee.
*
* Knowledge of the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK OPERATING SYSTEM LAYER
*
* Micrium uC/OS-II
*
* Filename : net_os.c
* Version : V1.89
* Programmer(s) : ITJ
*********************************************************************************************************
* Note(s) : (1) Assumes uC/OS-II V2.84 is included in the product build.
*
* (2) REQUIREs the following uC/OS-II features to be ENABLED :
*
* ------- FEATURE -------- ---------- MINIMUM CONFIGURATION FOR NET/OS PORT ----------
*
* (a) OS Events OS_MAX_EVENTS >= NET_OS_NBR_EVENTS (see this 'net_os.h
* OS OBJECT DEFINES')
*
* (b) Semaphores NET_OS_NBR_SEM (see Note #2a)
* (1) OS_SEM_EN Enabled
* (2) OS_SEM_SET_EN Enabled
* (3) OS_SEM_PEND_ABORT_EN Enabled
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define NET_OS_MODULE
#include <net.h>
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
#if ((NET_CFG_LOAD_BAL_EN == DEF_ENABLED) || \
(defined(NET_TCP_MODULE_PRESENT )) || \
(defined(NET_SOCK_MODULE_PRESENT)))
#define NET_OS_TIMEOUT_PRESENT
#endif
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*
* Note(s) : (1) (a) Signals & locks are implemented using binary semaphores.
*
* (b) Queues are implemented using counting semaphores.
*********************************************************************************************************
*/
/* -------------------- TASK STKs --------------------- */
static OS_STK NetOS_Tmr_TaskStk[NET_OS_CFG_TMR_TASK_STK_SIZE];
static OS_STK NetOS_IF_RxTaskStk[NET_OS_CFG_IF_RX_TASK_STK_SIZE];
/* --------------------- SIGNALS ---------------------- */
static OS_EVENT *NetOS_InitSignalPtr;
static OS_EVENT *NetOS_NIC_TxRdySignalPtr;
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
static OS_EVENT *NetOS_TxSuspendSignalPtr;
#endif
#ifdef NET_SOCK_MODULE_PRESENT
#if (NET_SOCK_CFG_TYPE_STREAM_EN == DEF_ENABLED)
static OS_EVENT *NetOS_Sock_ConnReqSignalPtr[NET_SOCK_CFG_NBR_SOCK];
static OS_EVENT *NetOS_Sock_ConnAcceptQ_SignalPtr[NET_SOCK_CFG_NBR_SOCK];
static OS_EVENT *NetOS_Sock_ConnCloseSignalPtr[NET_SOCK_CFG_NBR_SOCK];
#endif
#endif
/* ---------------------- LOCKS ----------------------- */
static OS_EVENT *NetOS_LockPtr;
/* --------------------- QUEUES ----------------------- */
static OS_EVENT *NetOS_IF_RxQ_SignalPtr;
/* ---------------------- SEMS ------------------------ */
#ifdef NET_TCP_MODULE_PRESENT
static OS_EVENT *NetOS_TCP_RxQ_SignalPtr[NET_TCP_CFG_NBR_CONN];
static OS_EVENT *NetOS_TCP_TxQ_SignalPtr[NET_TCP_CFG_NBR_CONN];
#endif
#ifdef NET_SOCK_MODULE_PRESENT
static OS_EVENT *NetOS_Sock_RxQ_SignalPtr[NET_SOCK_CFG_NBR_SOCK];
#endif
/* ---------------------- TMRS ------------------------ */
#ifdef NET_OS_TIMEOUT_PRESENT
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
static INT16U NetOS_TxSuspendTimeout_tick;
#endif
#ifdef NET_TCP_MODULE_PRESENT
static INT16U NetOS_TCP_RxQ_TimeoutTbl_tick[NET_TCP_CFG_NBR_CONN];
static INT16U NetOS_TCP_TxQ_TimeoutTbl_tick[NET_TCP_CFG_NBR_CONN];
#endif
#ifdef NET_SOCK_MODULE_PRESENT
static INT16U NetOS_Sock_RxQ_TimeoutTbl_tick[NET_SOCK_CFG_NBR_SOCK];
#if (NET_SOCK_CFG_TYPE_STREAM_EN == DEF_ENABLED)
static INT16U NetOS_Sock_ConnReqTimeoutTbl_tick[NET_SOCK_CFG_NBR_SOCK];
static INT16U NetOS_Sock_ConnAcceptQ_TimeoutTbl_tick[NET_SOCK_CFG_NBR_SOCK];
static INT16U NetOS_Sock_ConnCloseTimeoutTbl_tick[NET_SOCK_CFG_NBR_SOCK];
#endif
#endif
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/* ---- NETWORK TIMER MANAGEMENT FUNCTIONS ---- */
static void NetOS_Tmr_Task (void *p_data);
/* ---- NETWORK INTERFACE LAYER FUNCTIONS ----- */
static void NetOS_IF_RxTask (void *p_data);
/* - NETWORK/OS TIMEOUT CALCULATION FUNCTIONS - */
#ifdef NET_OS_TIMEOUT_PRESENT
static INT16U NetOS_TimeoutCalc_OS_tick(CPU_INT32U timeout_ms,
NET_ERR *perr);
static CPU_INT32U NetOS_TimeoutCalc_ms (INT16U os_tick);
#endif
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef NET_OS_CFG_IF_RX_TASK_PRIO
#error "NET_OS_CFG_IF_RX_TASK_PRIO not #define'd in 'app_cfg.h'"
#error " [MUST be >= 0] "
#elif (NET_OS_CFG_IF_RX_TASK_PRIO < 0)
#error "NET_OS_CFG_IF_RX_TASK_PRIO illegally #define'd in 'app_cfg.h'"
#error " [MUST be >= 0] "
#endif
#ifndef NET_OS_CFG_TMR_TASK_PRIO
#error "NET_OS_CFG_TMR_TASK_PRIO not #define'd in 'app_cfg.h'"
#error " [MUST be >= 0] "
#elif (NET_OS_CFG_TMR_TASK_PRIO < 0)
#error "NET_OS_CFG_TMR_TASK_PRIO illegally #define'd in 'app_cfg.h'"
#error " [MUST be >= 0] "
#endif
#ifndef NET_OS_CFG_TMR_TASK_STK_SIZE
#error "NET_OS_CFG_TMR_TASK_STK_SIZE not #define'd in 'app_cfg.h'"
#error " [MUST be > 0] "
#elif (NET_OS_CFG_TMR_TASK_STK_SIZE < 1)
#error "NET_OS_CFG_TMR_TASK_STK_SIZE illegally #define'd in 'app_cfg.h'"
#error " [MUST be > 0] "
#endif
#ifndef NET_OS_CFG_IF_RX_TASK_STK_SIZE
#error "NET_OS_CFG_IF_RX_TASK_STK_SIZE not #define'd in 'app_cfg.h'"
#error " [MUST be > 0] "
#elif (NET_OS_CFG_IF_RX_TASK_STK_SIZE < 1)
#error "NET_OS_CFG_IF_RX_TASK_STK_SIZE illegally #define'd in 'app_cfg.h'"
#error " [MUST be > 0] "
#endif
/*$PAGE*/
/*
*********************************************************************************************************
*********************************************************************************************************
* NETWORK FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NetOS_Init()
*
* Description : (1) Perform network/OS initialization :
*
* (a) Implement network initialization signal by creating a counting semaphore.
*
* Initialize network initialization signal with no signal by setting the semaphore
* count to 0 to block the initialization signal semaphore.
*
* (b) Implement global network lock by creating a binary semaphore.
*
* Initialize network lock as released by setting the semaphore count to 1.
*
* (c) Implement network transmit suspend signal by creating a counting semaphore.
*
* Initialize network transmit suspend signal with no signal by setting the semaphore
* count to 0 to block the transmit suspend signal semaphore.
*
*
* Argument(s) : perr Pointer to variable that will receive the return error code from this function :
*
* NET_OS_ERR_NONE Network/OS initialization successful.
*
* NET_OS_ERR_INIT_SIGNAL Network initialization signal
* NOT successfully initialized.
* NET_OS_ERR_INIT_SIGNAL_NAME Network initialization signal name
* NOT successfully configured.
*
* NET_OS_ERR_INIT_LOCK Network lock signal
* NOT successfully initialized.
* NET_OS_ERR_INIT_LOCK_NAME Network lock signal name
* NOT successfully configured.
*
* NET_OS_ERR_INIT_TX_SUSPEND Network transmit suspend signal
* NOT successfully initialized.
* NET_OS_ERR_INIT_TX_SUSPEND_NAME Network transmit suspend signal name
* NOT successfully configured.
* NET_OS_ERR_INIT_TX_SUSPEND_TIMEOUT Network transmit suspend signal timeout
* NOT successfully configured.
*
* 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) : none.
*********************************************************************************************************
*/
/*$PAGE*/
void NetOS_Init (NET_ERR *perr)
{
#if (OS_EVENT_NAME_SIZE >= NET_OBJ_NAME_SIZE_MAX)
INT8U os_err;
#endif
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
NET_ERR net_err;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -