📄 net.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 SOURCE FILE
*
* Filename : net.c
* Version : V1.89
* Programmer(s) : ITJ
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define NET_MODULE
#include <net.h>
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* Net_Init()
*
* Description : (1) Initialize & startup network protocol suite :
*
* (a) Initialize network protocol suite default values
* (b) Initialize network counters
* (c) Initialize network protocol suite global OS objects
* (d) Initialize network protocol suite modules
* (e) Signal ALL network protocol suite modules & tasks
* that network initialization is complete
* (f) Enable NIC interrupts
*
*
* Argument(s) : none.
*
* Return(s) : NET_ERR_NONE, if NO errors.
*
* Specific initialization error code (see Note #5), otherwise.
*
* Caller(s) : Your Product's Application.
*
* This function is a network protocol suite initialization function & MAY be called by
* application/initialization function(s).
*
* Note(s) : (2) NetInit() MUST be called ...
*
* (a) AFTER product's OS has been initialized
* (b) BEFORE product's application calls any network protocol suite function(s)
*
* (3) NetInit() MUST ONLY be called ONCE from product's application.
*
* (4) The following initialization functions MUST be sequenced as follows :
*
* (a) Net_InitDflt() MUST precede ALL other network initialization functions
* (b) NetDbg_Init() MUST follow NetTmr_Init()
* (c) NetNIC_Init() MUST precede NetIF_Init()
* (d) NetNIC_IntEn() MUST follow ALL other network initialization
*
* (5) (a) If any network initialization error occurs, any remaining network initialization
* is immediately aborted & the specific initialization error code is returned.
*
* (b) Network error codes are listed in 'net_err.h', organized by network modules &/or
* layers. A search of the specific error code number(s) provides the corresponding
* error code label(s). A search of the error code label(s) provides the source code
* location of the network initialization error(s).
*********************************************************************************************************
*/
NET_ERR Net_Init (void)
{
NET_ERR err;
CPU_INT08U i;
Net_InitDone = DEF_NO; /* Block net fncts/tasks until init complete. */
/* ---------------- INIT NET DFLT VALS ---------------- */
#if (NET_CFG_INIT_CFG_VALS == NET_INIT_CFG_VALS_DFLT)
Net_InitDflt(); /* Init cfg vals to dflt vals. */
#endif
/* ------------------ INIT NET CTRS ------------------- */
#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
Net_RxPktCtr = 0;
Net_TxSuspendCtr = 0;
#endif
/* ---------------- INIT NET ERR CTRS ----------------- */
#if (NET_CTR_CFG_ERR_EN == DEF_ENABLED)
Net_ErrInvalidProtocolCtr = 0;
#endif
/*$PAGE*/
/* --------------- PERFORM NET/OS INIT ---------------- */
NetOS_Init(&err);
if (err != NET_OS_ERR_NONE) {
return (err);
}
/* ----------------- INIT NET MODULES ----------------- */
NetStat_Init();
NetTmr_Init(&err);
if (err != NET_TMR_ERR_NONE) {
return (err);
}
NetBuf_Init();
#ifdef NET_CONN_MODULE_PRESENT
NetConn_Init();
#endif
NetDbg_Init();
NetNIC_Init(&err);
if (err != NET_NIC_ERR_NONE) {
return (err);
}
NetIF_Init(&err);
if (err != NET_IF_ERR_NONE) {
return (err);
}
NetIP_Init();
NetICMP_Init();
NetUDP_Init();
#ifdef NET_TCP_MODULE_PRESENT
NetTCP_Init(&err);
if (err != NET_TCP_ERR_NONE) {
return (err);
}
#endif
#ifdef NET_SOCK_MODULE_PRESENT
NetSock_Init(&err);
if (err != NET_SOCK_ERR_NONE) {
return (err);
}
#endif
/* ------------- SIGNAL NET INIT COMPLETE ------------- */
Net_InitDone = DEF_YES; /* Signal net fncts/tasks that init complete. */
for (i = 0; i < NET_TASK_NBR; i++) { /* Signal ALL net tasks that init complete. */
NetOS_InitSignal(&err);
if (err != NET_OS_ERR_NONE) {
Net_InitDone = DEF_NO;
return (err);
}
}
/* ------------------- EN NIC INTS -------------------- */
NetNIC_IntEn(&err);
if (err != NET_NIC_ERR_NONE) {
Net_InitDone = DEF_NO;
return (err);
}
return (NET_ERR_NONE);
}
/*$PAGE*/
/*
*********************************************************************************************************
* Net_InitDflt()
*
* Description : Initialize default values for network protocol suite configurable parameters.
*
* (1) Network protocol suite configurable parameters MUST be initialized PRIOR to all other
* network initialization.
*
* (2) (a) When NET_CFG_INIT_CFG_VALS is configured as NET_INIT_CFG_VALS_DFLT, the network
* protocol suite's configurable parameters are configured with default values.
*
* The application need only call Net_Init() to initialize both the network protocol
* suite & its configurable parameters.
*
* (b) When NET_CFG_INIT_CFG_VALS is configured as NET_INIT_CFG_VALS_APP_INIT, the
* application MUST ...
*
* (1) Initialize ALL network protocol suite configurable parameters from values
* recalled from non-volatile memory &/or hard-coded application values :
*
* (A) Call each of the configuration functions in Net_InitDflt() passing the
* application-recalled &/or hard-coded values
* OR
* (B) Call Net_InitDflt() to initialize ALL network protocol suite configurable
* parameters to their default values & then call any of the configuration
* functions in Net_InitDflt() passing the recalled &/or hard-coded values
* to initialize some of the network protocol suite configurable parameters
*
* (2) Call Net_Init()
*
* See also 'net_cfg.h NETWORK CONFIGURATION Note #1'
* & 'net_def.h PARAMETER CONFIGURATION INITIALIZATION Note #1'.
*
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Net_Init().
*
* This function is an INTERNAL network protocol suite function but MAY be called by
* application/initialization functions (see Note #2b1B).
*
* Note(s) : (3) Ignores configuration functions' return value indicating configuration success/failure.
*********************************************************************************************************
*/
/*$PAGE*/
void Net_InitDflt (void)
{
/* -------------- CFG DBG INIT DFLT VALS -------------- */
#if (NET_DBG_CFG_STATUS_RSRC_LO_EN == DEF_ENABLED)
#if (NET_BUF_CFG_NBR_SMALL > 0)
(void)NetDbg_CfgRsrcBufSmallThLo (NET_DBG_RSRC_TH_LO_DFLT,
NET_DBG_RSRC_TH_LO_HYST_DFLT);
#endif
#if (NET_BUF_CFG_NBR_LARGE > 0)
(void)NetDbg_CfgRsrcBufLargeThLo (NET_DBG_RSRC_TH_LO_DFLT,
NET_DBG_RSRC_TH_LO_HYST_DFLT);
#endif
(void)NetDbg_CfgRsrcTmrThLo (NET_DBG_RSRC_TH_LO_DFLT,
NET_DBG_RSRC_TH_LO_HYST_DFLT);
#ifdef NET_CONN_MODULE_PRESENT
(void)NetDbg_CfgRsrcConnThLo (NET_DBG_RSRC_TH_LO_DFLT,
NET_DBG_RSRC_TH_LO_HYST_DFLT);
#endif
#ifdef NET_ARP_MODULE_PRESENT
(void)NetDbg_CfgRsrcARP_CacheThLo(NET_DBG_RSRC_TH_LO_DFLT,
NET_DBG_RSRC_TH_LO_HYST_DFLT);
#endif
#ifdef NET_TCP_MODULE_PRESENT
(void)NetDbg_CfgRsrcTCP_ConnThLo (NET_DBG_RSRC_TH_LO_DFLT,
NET_DBG_RSRC_TH_LO_HYST_DFLT);
#endif
#ifdef NET_SOCK_MODULE_PRESENT
(void)NetDbg_CfgRsrcSockThLo (NET_DBG_RSRC_TH_LO_DFLT,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -