NetDev_Init() (Wireless)
The first function within the wireless API is the device driver initialization/Init()
function. This function is called by NetIF_Add()
exactly once for each specific network device added by the application. If multiple instances of the same network device are present on the development board, then this function is called for each instance of the device. However, applications should not try to add the same specific device more than once. If a network device fails to initialize, we recommend debugging to find and correct the cause of failure.
Note: This function relies heavily on the implementation of several network device board support package (BSP) functions. See Network Board Support Package and Ethernet Device BSP Functions for more information on network device BSP functions.
Files
Every device driver’s net_dev.c
Prototype
static void NetDev_Init (NET_IF *p_if, NET_ERR *p_err);
Note that since every device driver’s Init()
function is accessed only by function pointer via the device driver’s API structure, it doesn’t need to be globally available and should therefore be declared as ‘static
’.
Arguments
p_if
Pointer to the interface to initialize a network device.
p_err
Pointer to variable that will receive the return error code from this function.
Returned Value
None.
Required Configuration
None.
Notes / Warnings
The Init()
function generally performs the following operations, however, depending on the device being initialized, functionality may need to be added or removed:
- Validate all wireless configuration values.
- Configure all necessary I/O pins for the wireless device such as power enable or reset pin. This is generally performed via the network device’s BSP function pointer,
CfgGPIO()
, implemented innet_bsp.c
(see NetDev_CfgGPIO). - Initialize SPI controller for writing and reading from the wireless module.
- Configure the host interrupt controller for receive and transmit complete interrupts. Additional interrupt services may be initialized depending on the device and driver requirements. This is generally performed via the network device’s BSP function pointer,
CfgIntCtrl()
, implemented innet_bsp.c
(see NetDev_WiFi_CfgIntCtrl). - Allocate memory for all necessary driver buffers that will be reuse only by the driver such as a read buffer to validate the command sent. This is performed via calls to µC/LIB’s memory module.
- Disable the transmitted and receiver (should already be disabled).
- Set
p_err
toNET_DEV_ERR_NONE
if initialization proceeded as expected. Otherwise, setp_err
to an appropriate network device error code.