This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
problem with ethernet synchronization
- From: "Michele Paselli" <triguelon at gmail dot com>
- To: ecos-discuss at ecos dot sourceware dot org
- Date: Mon, 22 Oct 2007 12:07:59 +0200
- Subject: [ECOS] problem with ethernet synchronization
Hi,
I'm building a very simple eth stack for raw ethernet on top of the
low level ethernet driver but I'm getting into problems when I leave
the system running for some time. I guess that my system runs into a
deadlock somewhere but I cannot understand where and why. Of course I
analyzed the lwip and the freebsd stacks before starting to write the
code but what I don't understand is how the synchronization between
send and receive works. I can imagine that the hardware should not be
accessed at the same time from two different threads (for instance for
reading a packet and writing a packet) so what I did was creating a
mutex that is locked right before calling the low level driver and
released right after, so, for instance:
// Lock the low level eth driver for tx (so we cannot use it at the
same time for rx)
cyg_mutex_lock(ð_owner);
// Send the buffer to the hw
(sc->funs->send)(sc, sg_list, sg_len, total_len, (CYG_ADDRWORD)&packet_sent);
cyg_mutex_unlock(ð_owner); // unlock the low level eth driver
for transmission, and
// Lock the low level eth driver for rx (so we cannot use it at the
same time for tx)
cyg_mutex_lock(ð_owner);
// Ask hardware to unload buffers
(sc->funs->recv)(sc, sg_list, sg_len);
cyg_mutex_unlock(ð_owner); // unlock the low level eth driver
for reception. The first thing that I don't understand is where in
lwip or freebsd the same thing is done, because I don't see any
synchronization in the eth_drv.c file. The problem that I also have is
that when my system hangs I cannot debug it because gdb is also
blocked, so I guess there is something more than a deadlock. Might it
be that I'm trying to access the hardware from 2 different threads? I
also thought that in the case of transmission I should release the
eth_owner mutex in the tx_done function, but again I don't see
anything similar in the lwip or freebsd implementation. Can somebody
help me?
Thanks.
Michele
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss