Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor11289591128959 NetDev_Rx() Anchor11289601128960The 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.anchor11098051109805

Files

...

Every device driver’s net_dev.c Anchor11098131109813

Prototype

...

rowspan2

...

Code Block
          static void NetDev_Rx (NET_IF      *pif,
                                 CPU_INT08U **p_data,
                                 CPU_INT16U  *size,
                                 NET_ERR     *perr);

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’. Anchor11098151109815static’.

Arguments

Anchor11103661110366 p_if Anchor11516741151674pif

Pointer to the interface to receive data from a network device.

...

p_dataanchor11516821151682

Pointer to return the address of the received data.

...

11289351128935 p_size Anchor11516901151690

Pointer to return the size of the received data.

Anchor11289361128936 p_err Anchor11516981151698perr

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

...

Returned Value

...

None. Anchor11103991110399

Required Configuration

...

None. Anchor11104011110401

Notes / Warnings

...

The receive function should perform the following actions:

...

Anchor11345631134563 a. Acquire the SPI lock by calling p_dev_bsp->SPI_Lock(). Anchor11345641134564 b. Enable the chip select by calling p_dev_bsp->SPI_ChipSelEn(). Anchor11345651134565 c. Configure the SPI controller for the wireless device by calling p_dev_bsp->SPI_SetCfg().

  1. Anchor11345581134558Check 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. Anchor10911771091177
  2. For wireless For Ethernet devices, get the size of the received frame and subtract 4 bytes for the CRC. It is it 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.
  3. Anchor11337781133778Get 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. Anchor11338931133893. For DMA devices, the current receive descriptor should be marked as available or owned by hardware. The device driver should then return from the receive function.
  4. If an error does not occur while getting a new data area, the function DMA devices should perform the following operations:

...

  1. a. Set

...

  1. *p_data equal to the address of the data area within the descriptor being serviced.

    b. Set the data area pointer within the receive descriptor to the address of the data

...

  1. area obtained by calling NetBuf_GetDataPtr().

    c. Update any descriptor ring pointers if applicable.

  2. Non DMA devices should Mem_Copy() the data stored within the device to the address of the buffer obtained by calling NetBuf_GetDataPtr() and set *p_data equal to the address of the obtained data area.
  3. Anchor11337461133746 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(). Anchor11345801134580 Set p_err Set perr to NET_DEV_ERR_NONE and return from the receive function. Otherwise, set p_err perr to an appropriate network device error code.