Microchip® Advanced Software Framework

lwip/lwip-1.4.1/src/include/lwip/sys.h File Reference
#include "lwip/opt.h"
#include "lwip/err.h"
#include "arch/sys_arch.h"

Macros

#define SYS_ARCH_DEC(var, val)
 
#define SYS_ARCH_DECL_PROTECT(lev)
 SYS_LIGHTWEIGHT_PROT define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection for certain critical regions during buffer allocation, deallocation and memory allocation and deallocation. More...
 
#define SYS_ARCH_GET(var, ret)
 
#define SYS_ARCH_INC(var, val)
 
#define SYS_ARCH_PROTECT(lev)
 
#define SYS_ARCH_SET(var, val)
 
#define SYS_ARCH_TIMEOUT   0xffffffffUL
 Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait. More...
 
#define SYS_ARCH_UNPROTECT(lev)
 
#define SYS_MBOX_EMPTY   SYS_ARCH_TIMEOUT
 sys_mbox_tryfetch() returns SYS_MBOX_EMPTY if appropriate. More...
 
#define sys_mbox_fetch(mbox, msg)   sys_arch_mbox_fetch(mbox, msg, 0)
 
#define sys_mbox_tryfetch(mbox, msg)   sys_arch_mbox_tryfetch(mbox, msg)
 For now, we map straight to sys_arch implementation. More...
 
#define sys_sem_wait(sem)   sys_arch_sem_wait(sem, 0)
 Wait for a semaphore - forever/no timeout. More...
 

Typedefs

typedef void(* lwip_thread_fn )(void *arg)
 Function prototype for thread functions. More...
 

Functions

u32_t sys_arch_mbox_fetch (sys_mbox_t *mbox, void **msg, u32_t timeout)
 Wait for a new message to arrive in the mbox. More...
 
u32_t sys_arch_mbox_tryfetch (sys_mbox_t *mbox, void **msg)
 Wait for a new message to arrive in the mbox. More...
 
u32_t sys_arch_sem_wait (sys_sem_t *sem, u32_t timeout)
 Wait for a semaphore for the specified timeout. More...
 
void sys_init (void)
 Initialize the sys_arch layer. More...
 
u32_t sys_jiffies (void)
 Ticks/jiffies since power up. More...
 
void sys_mbox_free (sys_mbox_t *mbox)
 Delete an mbox. More...
 
err_t sys_mbox_new (sys_mbox_t *mbox, int size)
 Create a new mbox of specified size. More...
 
void sys_mbox_post (sys_mbox_t *mbox, void *msg)
 Post a message to an mbox - may not fail -> blocks if full, only used from tasks not from ISR. More...
 
void sys_mbox_set_invalid (sys_mbox_t *mbox)
 Set an mbox invalid so that sys_mbox_valid returns 0. More...
 
err_t sys_mbox_trypost (sys_mbox_t *mbox, void *msg)
 Try to post a message to an mbox - may fail if full or ISR. More...
 
int sys_mbox_valid (sys_mbox_t *mbox)
 Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid. More...
 
void sys_msleep (u32_t ms)
 Sleep for some ms. More...
 
void sys_mutex_free (sys_mutex_t *mutex)
 Delete a semaphore. More...
 
void sys_mutex_lock (sys_mutex_t *mutex)
 Lock a mutex. More...
 
err_t sys_mutex_new (sys_mutex_t *mutex)
 Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores should be used instead. More...
 
void sys_mutex_set_invalid (sys_mutex_t *mutex)
 Set a mutex invalid so that sys_mutex_valid returns 0. More...
 
void sys_mutex_unlock (sys_mutex_t *mutex)
 Unlock a mutex. More...
 
int sys_mutex_valid (sys_mutex_t *mutex)
 Check if a mutex is valid/allocated: return 1 for valid, 0 for invalid. More...
 
u32_t sys_now (void)
 Returns the current time in milliseconds, may be the same as sys_jiffies or at least based on it. More...
 
void sys_sem_free (sys_sem_t *sem)
 Delete a semaphore. More...
 
err_t sys_sem_new (sys_sem_t *sem, u8_t count)
 Create a new semaphore. More...
 
void sys_sem_set_invalid (sys_sem_t *sem)
 Set a semaphore invalid so that sys_sem_valid returns 0. More...
 
void sys_sem_signal (sys_sem_t *sem)
 Signals a semaphore. More...
 
int sys_sem_valid (sys_sem_t *sem)
 Check if a sempahore is valid/allocated: return 1 for valid, 0 for invalid. More...
 
sys_thread_t sys_thread_new (const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
 The only thread function: Creates a new thread. More...
 

#define SYS_ARCH_DEC (   var,
  val 
)
Value:
do { \
SYS_ARCH_PROTECT(old_level); \
var -= val; \
SYS_ARCH_UNPROTECT(old_level); \
} while(0)
#define SYS_ARCH_DECL_PROTECT(lev)
SYS_LIGHTWEIGHT_PROT define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection for ...
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:284
#define SYS_ARCH_PROTECT(lev)
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:285
float32_t var
Definition: arm_class_marks_example_f32.c:150
#define SYS_ARCH_UNPROTECT(lev)
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:286
#define SYS_ARCH_DECL_PROTECT (   lev)

SYS_LIGHTWEIGHT_PROT define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection for certain critical regions during buffer allocation, deallocation and memory allocation and deallocation.

Referenced by mem_free(), mem_trim(), memp_free(), pbuf_free(), pbuf_ref(), and sys_thread_new().

#define SYS_ARCH_GET (   var,
  ret 
)
Value:
do { \
SYS_ARCH_PROTECT(old_level); \
ret = var; \
SYS_ARCH_UNPROTECT(old_level); \
} while(0)
#define SYS_ARCH_DECL_PROTECT(lev)
SYS_LIGHTWEIGHT_PROT define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection for ...
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:284
#define SYS_ARCH_PROTECT(lev)
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:285
float32_t var
Definition: arm_class_marks_example_f32.c:150
#define SYS_ARCH_UNPROTECT(lev)
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:286
#define SYS_ARCH_INC (   var,
  val 
)
Value:
do { \
SYS_ARCH_PROTECT(old_level); \
var += val; \
SYS_ARCH_UNPROTECT(old_level); \
} while(0)
#define SYS_ARCH_DECL_PROTECT(lev)
SYS_LIGHTWEIGHT_PROT define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection for ...
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:284
#define SYS_ARCH_PROTECT(lev)
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:285
float32_t var
Definition: arm_class_marks_example_f32.c:150
#define SYS_ARCH_UNPROTECT(lev)
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:286
#define SYS_ARCH_PROTECT (   lev)
#define SYS_ARCH_SET (   var,
  val 
)
Value:
do { \
SYS_ARCH_PROTECT(old_level); \
var = val; \
SYS_ARCH_UNPROTECT(old_level); \
} while(0)
#define SYS_ARCH_DECL_PROTECT(lev)
SYS_LIGHTWEIGHT_PROT define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection for ...
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:284
#define SYS_ARCH_PROTECT(lev)
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:285
float32_t var
Definition: arm_class_marks_example_f32.c:150
#define SYS_ARCH_UNPROTECT(lev)
Definition: lwip/lwip-1.4.1/src/include/lwip/sys.h:286
#define SYS_ARCH_TIMEOUT   0xffffffffUL

Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait.

Referenced by sys_arch_mbox_fetch(), and sys_arch_sem_wait().

#define SYS_ARCH_UNPROTECT (   lev)
#define SYS_MBOX_EMPTY   SYS_ARCH_TIMEOUT

sys_mbox_tryfetch() returns SYS_MBOX_EMPTY if appropriate.

For now we use the same magic value, but we allow this to change in future.

Referenced by sys_arch_mbox_tryfetch().

#define sys_mbox_fetch (   mbox,
  msg 
)    sys_arch_mbox_fetch(mbox, msg, 0)
#define sys_mbox_tryfetch (   mbox,
  msg 
)    sys_arch_mbox_tryfetch(mbox, msg)

For now, we map straight to sys_arch implementation.

#define sys_sem_wait (   sem)    sys_arch_sem_wait(sem, 0)

Wait for a semaphore - forever/no timeout.

typedef void(* lwip_thread_fn)(void *arg)

Function prototype for thread functions.

u32_t sys_arch_mbox_fetch ( sys_mbox_t mbox,
void **  msg,
u32_t  timeout 
)

Wait for a new message to arrive in the mbox.

Parameters
mboxmbox to get a message from
msgpointer where the message is stored
timeoutmaximum time (in milliseconds) to wait for a message
Returns
time (in milliseconds) waited for a message, may be 0 if not waited or SYS_ARCH_TIMEOUT on timeout The returned time has to be accurate to prevent timer jitter!

Wait for a new message to arrive in the mbox.

Parameters
mboxPointer to the mailbox.
msgA result parameter that is set by the function (i.e., by doing "*msg = ptr"). The "msg" parameter maybe NULL to indicate that the message should be dropped. 0 indicates the thread should be blocked until a message arrives.
Returns
Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a timeout.

Wait for a new message to arrive in the mbox.

Parameters
mboxPointer to the mailbox.
msgA result parameter that is set by the function (i.e., by doing "*msg = ptr"). The "msg" parameter maybe NULL to indicate that the message should be dropped. 0 indicates the thread should be blocked until a message arrives.
Returns
Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a timeout. Or ERR_MEM if invalid pointer to message box.
u32_t sys_arch_mbox_tryfetch ( sys_mbox_t mbox,
void **  msg 
)

Wait for a new message to arrive in the mbox.

Parameters
mboxmbox to get a message from
msgpointer where the message is stored
timeoutmaximum time (in milliseconds) to wait for a message
Returns
0 (milliseconds) if a message has been received or SYS_MBOX_EMPTY if the mailbox is empty

Wait for a new message to arrive in the mbox.

On success 0 is returned.

Parameters
mboxPointer to the mailbox.
msgA result parameter that is set by the function (i.e., by doing "*msg = ptr"). The "msg" parameter maybe NULL to indicate that the message should be dropped.
Returns
Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a timeout. Or ERR_MEM if invalid pointer to message box.
u32_t sys_arch_sem_wait ( sys_sem_t sem,
u32_t  timeout 
)

Wait for a semaphore for the specified timeout.

Parameters
semthe semaphore to wait for
timeouttimeout in milliseconds to wait (0 = wait forever)
Returns
time (in milliseconds) waited for the semaphore or SYS_ARCH_TIMEOUT on timeout

Wait for a semaphore for the specified timeout.

Note that there is another function sys_sem_wait in sys.c, but it is a wrapper for the sys_arch_sem_wait function. Please note that it is important for the semaphores to return an accurate count of elapsed milliseconds, since they are used to schedule timers in lwIP.

Parameters
semPointer to the semaphore.
timeoutThe timeout parameter specifies how many milliseconds the function should block before returning; if the function times out, it should return SYS_ARCH_TIMEOUT. If timeout=0, then the function should block indefinitely. If the function acquires the semaphore, it should return how many milliseconds expired while waiting for the semaphore.
Returns
SYS_ARCH_TIMEOUT if times out otherwise return the milliseconds expired while waiting for the semaphore.

Wait for a semaphore for the specified timeout.

Note that there is another function sys_sem_wait in sys.c, but it is a wrapper for the sys_arch_sem_wait function. Please note that it is important for the semaphores to return an accurate count of elapsed milliseconds, since they are used to schedule timers in lwIP.

Parameters
semPointer to the semaphore.
timeoutThe timeout parameter specifies how many milliseconds the function should block before returning; if the function times out, it should return SYS_ARCH_TIMEOUT. If timeout=0, then the function should block indefinitely. If the function acquires the semaphore, it should return how many milliseconds expired while waiting for the semaphore.
Returns
SYS_ARCH_TIMEOUT if times out, ERR_MEM for semaphore erro otherwise return the milliseconds expired while waiting for the semaphore.
void sys_init ( void  )

Initialize the sys_arch layer.

u32_t sys_jiffies ( void  )

Ticks/jiffies since power up.

void sys_mbox_free ( sys_mbox_t mbox)

Delete an mbox.

Parameters
mboxmbox to delete

Delete an mbox.

If there are messages still present in the mailbox when the mailbox is deallocated, it is an indication of a programming error in lwIP and the developer should be notified.

Parameters
mboxPointer to the new mailbox.
err_t sys_mbox_new ( sys_mbox_t mBoxNew,
int  size 
)

Create a new mbox of specified size.

Parameters
mboxpointer to the mbox to create
size(miminum) number of messages in this mbox
Returns
ERR_OK if successful, another err_t otherwise

Create a new mbox of specified size.

Elements stored in mailboxes are pointers.

Parameters
mBoxNewPointer to the new mailbox.
sizeMaximum "size" elements.
Returns
ERR_OK if successfull or ERR_MEM on error.
void sys_mbox_post ( sys_mbox_t mbox,
void *  msg 
)

Post a message to an mbox - may not fail -> blocks if full, only used from tasks not from ISR.

Parameters
mboxmbox to posts the message
msgmessage to post (ATTENTION: can be NULL)

Post a message to an mbox - may not fail -> blocks if full, only used from tasks not from ISR.

This function have to block until the "msg" is really posted.

Parameters
mboxPointer to the mailbox.
msgPointer to the message to be post.
void sys_mbox_set_invalid ( sys_mbox_t mbox)

Set an mbox invalid so that sys_mbox_valid returns 0.

Set an mbox invalid so that sys_mbox_valid returns 0.

Parameters
mboxPointer to the mailbox.
err_t sys_mbox_trypost ( sys_mbox_t mbox,
void *  msg 
)

Try to post a message to an mbox - may fail if full or ISR.

Parameters
mboxmbox to posts the message
msgmessage to post (ATTENTION: can be NULL)

Try to post a message to an mbox - may fail if full or ISR.

Parameters
mboxPointer to the mailbox.
msgPointer to the message to be post.
Returns
ERR_MEM if the mailbox is full otherwise ERR_OK if the "msg" is posted.
int sys_mbox_valid ( sys_mbox_t mbox)

Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid.

Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid.

Parameters
mboxPointer to the mailbox.
Returns
Mailbox for valid, 0 for invalid.
void sys_msleep ( u32_t  ms)

Sleep for some ms.

Timeouts are NOT processed while sleeping.

Parameters
msnumber of milliseconds to sleep
void sys_mutex_free ( sys_mutex_t mutex)

Delete a semaphore.

Parameters
mutexthe mutex to delete
mutexthe mutex to delete.
void sys_mutex_lock ( sys_mutex_t mutex)

Lock a mutex.

Parameters
mutexthe mutex to lock
mutexthe mutex to lock.
err_t sys_mutex_new ( sys_mutex_t mutex)

Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores should be used instead.

Create a new mutex

Parameters
mutexpointer to the mutex to create
Returns
a new mutex

Create a new mutex.

Parameters
mutexPointer to the mutex to create.
Returns
A new mutex.
void sys_mutex_set_invalid ( sys_mutex_t mutex)

Set a mutex invalid so that sys_mutex_valid returns 0.

Parameters
mutexPointer to the mutex.
void sys_mutex_unlock ( sys_mutex_t mutex)

Unlock a mutex.

Parameters
mutexthe mutex to unlock
mutexthe mutex to unlock.
int sys_mutex_valid ( sys_mutex_t mutex)

Check if a mutex is valid/allocated: return 1 for valid, 0 for invalid.

Check if a mutex is valid/allocated: return 1 for valid, 0 for invalid.

Parameters
mutexPointer to the mutex.
Returns
Valid mutex number or 0 for invalid.
u32_t sys_now ( void  )

Returns the current time in milliseconds, may be the same as sys_jiffies or at least based on it.

Returns the current time in milliseconds, may be the same as sys_jiffies or at least based on it.

void sys_sem_free ( sys_sem_t sem)

Delete a semaphore.

Parameters
semsemaphore to delete

Delete a semaphore.

Parameters
semPointer to the semaphore.
err_t sys_sem_new ( sys_sem_t sem,
u8_t  count 
)

Create a new semaphore.

Parameters
sempointer to the semaphore to create
countinitial count of the semaphore
Returns
ERR_OK if successful, another err_t otherwise

Create a new semaphore.

Parameters
semPointer to the semaphore.
countInitial state of the semaphore.
Returns
ERR_OK for OK, other value indicates error.
void sys_sem_set_invalid ( sys_sem_t sem)

Set a semaphore invalid so that sys_sem_valid returns 0.

Set a semaphore invalid so that sys_sem_valid returns 0.

Parameters
semPointer to the semaphore.
void sys_sem_signal ( sys_sem_t sem)

Signals a semaphore.

Parameters
semthe semaphore to signal

Signals a semaphore.

Parameters
semPointer to the semaphore.
int sys_sem_valid ( sys_sem_t sem)

Check if a sempahore is valid/allocated: return 1 for valid, 0 for invalid.

Check if a sempahore is valid/allocated: return 1 for valid, 0 for invalid.

Parameters
semPointer to the semaphore.
Returns
Semaphore number on valid, 0 for invalid.
sys_thread_t sys_thread_new ( const char *  name,
lwip_thread_fn  thread,
void *  arg,
int  stacksize,
int  prio 
)

The only thread function: Creates a new thread.

Parameters
namehuman-readable name for the thread (used for debugging purposes)
threadthread-function
argparameter passed to 'thread'
stacksizestack size in bytes for the new thread (may be ignored by ports)
priopriority of the new thread (may be ignored by ports)

The only thread function: Creates a new thread.

Both the id and the priority are system dependent.

Parameters
namePointer to the thread name.
threadThread function.
argArgument will be passed into the thread().
stacksizeStack size of the thread.
prioThread priority.
Returns
The id of the new thread.