NetDev_Rx() (Wireless)

The receive/Rx() function is called by µC/TCP-IP’s Receive task after the Interrupt Service Routine handler has signaled to the Receive task that a receive event has occurred. The Receive function requires that the device driver return a pointer to the data area containing the received data and return the size of the received frame via pointer.

Files

Every device driver’s net_dev.c

Prototype

          static void NetDev_Rx (NET_IF      *p_if,
                                 CPU_INT08U **p_data,
                                 CPU_INT16U  *p_size,
                                 NET_ERR     *p_err);

Note that since every device driver’s Rx() 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 receive data from a network device.

p_data

Pointer to return the address of the received data.

p_size

Pointer to return the size of the received data.

p_err

Pointer to variable that will receive the return error code from this function.

Returned Value

None.

Required Configuration

None.

Notes / Warnings

The receive function should perform the following actions:

  1. For SPI wireless device, get the access to the SPI bus by performing the following operation:
    1. Acquire the SPI lock by calling p_dev_bsp->SPI_Lock().
    2. Enable the chip select by calling p_dev_bsp->SPI_ChipSelEn().
    3. Configure the SPI controller for the wireless device by calling p_dev_bsp->SPI_SetCfg().
  2. Check for receive errors if applicable. If an error should occur during reception, the driver should set *size to 0 and *p_data to (CPU_INT08U *)0 and return. Additional steps may be necessary depending on the device being serviced.
  3. For wireless devices, get the size of the received frame and subtract 4 bytes for the CRC. It is always recommended that the frame size is checked to ensure that it is greater than 4 bytes before performing the subtraction to ensure that an underflow does not occur. Set *size equal to the adjusted frame size.
  4. Get a new data buffer area by calling NetBuf_GetDataPtr(). If memory is not available, an error will be returned and the device driver should set *size to 0 and *p_data to (CPU_INT08U *)0.
  5. If an error does not occur while getting a new data area, the function should perform the following operations:
    1. Set the frame type of the data received (NET_IF_WIFI_MGMT_FRAME or NET_IF_WIFI_DATA_PKT) at the beginning of the network buffer.
    2. The data stored within the device should be transferred to the address of the data section (after the frame type) of the network buffer by calling p_dev_bsp->SPI_WrRd()and by using a global buffer to write data and set *p_data equal to the address of the obtained data area.
  6. Sidable the device chip select by calling p_dev_bsp->SPI_ChipSelDis() and unlock the SPI bus access by calling p_dev_bsp->SPI_Unlock().
  7. Set p_err to NET_DEV_ERR_NONE and return from the receive function. Otherwise, set p_err to an appropriate network device error code.