lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Re: [lwip-devel] Rx DMA and an application specific questio


From: Jeff Barber
Subject: [lwip-users] Re: [lwip-devel] Rx DMA and an application specific question
Date: Thu, 5 Aug 2010 19:17:29 -0400

On Thu, Aug 5, 2010 at 9:22 AM, Friedrich Schick
<address@hidden> wrote:
> I am writing a driver for lwip 1.4RC1. The fec (freescale fec) is able to
> use dma in tx and rx direction. The tx side is easy to implement but now it
> comes to the rx side. How do I implement dma on the rx side? My target
> platform is using multiple threads but only one thread, which interacts with
> lwip and the fec. Thus makes is possible to use a very simple interface. I
> want the lwip thread to be blocking so this thread will wait for any fec
> interrupts and a timer.

While I use lwIP in the NO_SYS=1 mode, my single thread operates
pretty much exactly as your pseudo-code specifies.  That is, my netif
interrupt handler is simply used to awaken the thread (which, like
yours, can also be interrupted by a timer tick).  Then, I call my
netif input function as you show below to actually process packets.

So, how do I use dma on the rx side?  Simple: prior to entering the
main loop, the netif is initialized.  In the initialization function,
I pre-allocate a number of max-size packet buffers (1518 bytes in my
case) with pbuf_alloc.  I fill in a descriptor for my network device
for each of those buffers and enqueue them to the device.  Later, when
packets arrive, the device DMAs packet data into the buffer and
provides an interrupt.  Shortly thereafter, when executing my
netif_input function, I allocate new buffers to replace the used ones
and enqueue them to the device.  The newly received ones are of course
passed up the stack for processing by lwIP.

Some devices allow more efficient use of buffers (i.e. do not require
allocating the max-size buffer for each descriptor).  In fact, my
device supports that.  However, I had plenty of memory to throw at it,
so had no need to do anything more clever.  (Some devices -- or so I
understand -- DMA only into certain special and/or dedicated memory
areas; I can't help you with that.)

By the way, lwip-devel is intended for discussions about development
of the core lwip software itself. Discussions of this type (how to use
lwIP) belong on the lwip-users list so I've removed lwip-devel from
the distribution.

Hope this helps,
Jeff

> // some pseudo code
> while(true)
> {
>     wait_for_rx_tx_event(); // frame rx, successful tx, or timer
>
>     check_timer(); // process lwip timers
>     ethernetif_input(); // process lwip reception, see below
> }
>
> // tx
> thread context : low_level_output -> Any free dma channel, if not wait for
> tx interrupt (or watchdog) else proceed with setting up dma channel
>
> // rx
> interrupt context : wake up the thread -> thread context : ethernetif_input
> -> low_level_input -> pbuf_alloced_custom to get a pbuf (dma has written
> frame into custom buffers) which are linked to this custom pbuf ->
> netif->input (process user events) -> pbuf_alloced_custom_free free a dma
> buffer and tells the fec
>
> Do I miss something?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]