Initializing a Network Device
NetDev_Init()
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 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 the failure.
NetDev_Init()
performs the following operations. However, depending on the device being initialized, functionality may need to be added or removed:
- Configure clock gating to the MAC device, if applicable. This is performed via the network device’s BSP function pointer,
NetDev_CfgClk()
, implemented innet_bsp.c
(see Device Driver BSP Functions). - Configure all necessary I/O pins for both an internal or external MAC and PHY, if present. This is performed via the network device’s BSP function pointer,
NetDev_CfgGPIO()
, implemented innet_bsp.c
.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 performed via the network device’s BSP function pointer,
NetDev_CfgIntCtrl()
, implemented innet_bsp.c
. - For DMA devices: Allocate memory for all necessary descriptors. This is performed via calls to μC/LIB’s memory module.
- For DMA devices: Initialize all descriptors to their ready states. This may be performed via calls to locally-declared, static functions.
- Initialize the (R)MII bus interface, if applicable. This entails configuring the (R)MII bus frequency which is dependent on the system clock. Static values for clock frequencies should never be used when determining clock dividers. Instead, the driver should reference the associated clock function(s) for getting the system clock or peripheral bus frequencies, and use these values to compute the correct (R)MII bus clock divider(s). This is performed via the network device’s BSP function pointer,
NetDev_ClkFreqGet()
, implemented innet_bsp.c
. - Disable the transmitter and receiver (should already be disabled).
- Disable and clear pending interrupts (should already be cleared).
- Set
perr
toNET_DEV_ERR_NONE
if initialization proceeded as expected. Otherwise, setperr
to an appropriate network device error code.