Reception using DMA
Initialization
When µC/TCP-IP is initialized, the Network Device Driver allocates a memory block for all Receive descriptors; this is performed via calls to µC/LIB.
...
The DMA controller is initialized and the hardware is informed of the address of descriptor list.
Figure 7-9 Allocation of buffers
F7-9(1) The result of Mem_Init()
and the first step in the intialization of the Network Device Driver is the allocation of buffers.
Figure 7-10 Descriptor allocation{
F7-10(1) µC/TCP-IP allocates a list of descriptors based on the network device driver configuration and sets each address field to point to the start address of a receive buffer.
Figure 7-11 Reception descriptor pointers initialization
...
F7-11(3) Finally, the DMA controller is initialized and hardware is informed of the descriptor list starting address.
Reception
Figure 7-12 Receiving an Ethernet frame with DMA
...
NetDev_Rx()
is called by core once a NetOS_IF_RxTaskSignal()
call has been made to recover the received packet. If data received is valid, this function must replace the buffer of the current descriptor with a free buffer. Also, the current descriptor must be restarted (owned by the DMA) to be able to receive again. RxBufDescPtrCur
must be moved to point on the next descriptor. The sub-function NetDev_RxDescPtrCurInc()
is called to restart the current descriptor and to move the pointer to the next descriptor. If an error has occurred, you have to set data and length pointers to 0 and return an error. If there is no free Rx buffer available, the packet must be discarded by leaving the current data buffer assigned to the DMA, increment the current descriptor and return an error to the µC/TCP-IP module. Here is a pseudo code of NetDev_Rx()
:
Listing 7-8 Packet Reception
...
NetDev_Stop()
is called to shutdown a network interface hardware by disabling the receiver and transmitter, disabling receive and transmit interrupts, free all receive descriptors and deallocate all transmit buffers. When the interface is stopped, you must deallocate the DMA descriptor ring. To do that, a sub-function is called NetDev_RxDescFreeAll()
where each descriptor’s buffer is freed and the DMA controller control is disabled:
Listing 7-10 Deallocation of Descriptor Ring
...