lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] [lwip] RFC - new sys_arch for lwIP 0.5


From: Adam Dunkels
Subject: [lwip-users] [lwip] RFC - new sys_arch for lwIP 0.5
Date: Wed, 08 Jan 2003 22:15:32 -0000

Hi all!

I went ahead this weekend and implemented the planned changes for the 
sys_arch interface in the upcoming lwIP 0.5. This sys_arch should be easier 
to port than the sys_arch in 0.4.2 and earlier versions and since it uses the 
same interface to the upper layers, it is completely replaceable with the 
sys_arch from lwIP versions < 0.5. The preliminary code is in the CVS and can 
be downloaded from the homepage.

I also wrote a small note on how the sys_arch is supposed to work and would 
like to hear your comments on it. There has been a horrible lack of 
documentation for the sys_arch in the past - this is intended to remedy that!

---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ----

New sys_arch interface for lwIP 0.5 (Request For Comments)

The operating system emulation layer provides a common interface
between the lwIP code and the underlying operating system kernel. The
general idea is that porting lwIP to new architectures requires only
small changes to a few header files and a new sys_arch
implementation. It is also possible to do a sys_arch implementation
that does not rely on any underlying operating system.

The sys_arch provides semaphores and mailboxes to lwIP. For the full
lwIP functionality, multiple threads support can be implemented in the
sys_arch, but this is not required for the basic lwIP
functionality. Previous versions of lwIP required the sys_arch to
implement timer scheduling as well but as of lwIP 0.5 this is
implemented in a higher layer.

Semaphores can be either counting or binary - lwIP works with both
kinds. Mailboxes are used for message passing and can be implemented
either as a queue which allows multiple messages to be posted to a
mailbox, or as a rendez-vous point where only one message can be
posted at a time. lwIP works with both kinds, but the former type will
be more efficient. A message in a mailbox is just a pointer, nothing
more. 

Semaphores are represented by the type "sys_sem_t" which is typedef'd
in the sys_arch.h file. Mailboxes are equivalently represented by the
type "sys_mbox_t". lwIP does not place any restrictions on how
sys_sem_t or sys_mbox_t are represented internally.

The following functions must be implemented by the sys_arch:

- void sys_init(void)

  Is called to initialize the sys_arch layer.

- sys_sem_t sys_sem_new(u8_t count)

  Creates and returns a new semaphore. The "count" argument specifies
  the initial state of the semaphore.

- void sys_sem_free(sys_sem_t sem)

  Deallocates a semaphore. 

- void sys_sem_signal(sys_sem_t sem)

  Signals a semaphore.

- u16_t sys_arch_sem_wait(sys_sem_t sem, u16_t timeout)

  Blocks the thread while waiting for the semaphore to be
  signaled. If the "timeout" argument is non-zero, the thread should
  only be blocked for the specified time (measured in
  milliseconds).

  If the timeout argument is non-zero, the return value is the amount
  of time spent waiting for the semaphore to be signaled. If the
  semaphore wasn't signaled within the specified time, the return
  value is zero. If the thread didn't have to wait for the semaphore
  (i.e., it was already signaled), the return value should be 1.

  Notice that lwIP implements a function with a similar name,
  sys_sem_wait(), that uses the sys_arch_sem_wait() function.

- sys_mbox_t sys_mbox_new(void)

  Creates an empty mailbox.

- void sys_mbox_free(sys_mbox_t mbox)

  Deallocates a mailbox. Any messages that are still present in the
  mailbox are dropped.

- void sys_mbox_post(sys_mbox_t mbox, void *msg)

  Posts the "msg" to the mailbox.

- u16_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u16_t timeout)

  Blocks the thread until a message arrives in the mailbox, but does
  not block the thread longer than "timeout" milliseconds (similar to
  the sys_arch_sem_wait() function).

If threads are supported by the underlying operating system and if
such functionality is needed in lwIP, the following function will have
to be implemented as well:

- void sys_thread_new(void (* thread)(void *arg), void *arg)

  Starts a new thread that will begin its execution in the function
  "thread()". The "arg" argument will be passed as an argument to the
  thread() function.

---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ----

/adam
-- 
Adam Dunkels <address@hidden>
http://www.sics.se/~adam
[This message was sent through the lwip discussion list.]




reply via email to

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