Microchip® Advanced Software Framework

sam/sys_arch.c File Reference
#include "lwip/debug.h"
#include "lwip/sys.h"
#include "lwip/opt.h"
#include "lwip/stats.h"

Macros

#define SYS_ARCH_BLOCKING_TICKTIMEOUT   ((portTickType)10000)
 

Functions

u32_t sys_arch_mbox_fetch (sys_mbox_t *mbox, void **msg, u32_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). More...
 
u32_t sys_arch_mbox_tryfetch (sys_mbox_t *mbox, void **msg)
 This is similar to sys_arch_mbox_fetch, however if a message is not present in the mailbox, it immediately returns with the code SYS_MBOX_EMPTY. More...
 
sys_prot_t sys_arch_protect (void)
 Protect the system. More...
 
u32_t sys_arch_sem_wait (sys_sem_t *sem, u32_t timeout)
 Blocks the thread while waiting for the semaphore to be signaled. More...
 
void sys_arch_unprotect (sys_prot_t pval)
 Unprotect the system. More...
 
void sys_init (void)
 Initialize the sys_arch layer. More...
 
void sys_mbox_free (sys_mbox_t *mbox)
 Deallocates a mailbox. More...
 
err_t sys_mbox_new (sys_mbox_t *mBoxNew, int size)
 Creates an empty mailbox for maximum "size" elements. More...
 
void sys_mbox_post (sys_mbox_t *mbox, void *msg)
 Posts the "msg" to the mailbox. More...
 
void sys_mbox_set_invalid (sys_mbox_t *mbox)
 Set an mbox invalid. More...
 
err_t sys_mbox_trypost (sys_mbox_t *mbox, void *msg)
 Try to posts the "msg" to the mailbox. More...
 
int sys_mbox_valid (sys_mbox_t *mbox)
 Check if an mbox is valid/allocated. More...
 
void sys_mutex_free (sys_mutex_t *pxMutex)
 Delete a semaphore. More...
 
void sys_mutex_lock (sys_mutex_t *pxMutex)
 Lock a mutex. More...
 
err_t sys_mutex_new (sys_mutex_t *pxMutex)
 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 *pxMutex)
 Unlock a mutex. More...
 
int sys_mutex_valid (sys_mutex_t *mutex)
 Check if a mutex is valid/allocated. More...
 
void sys_sem_free (sys_sem_t *sem)
 Frees a semaphore created by sys_sem_new. More...
 
err_t sys_sem_new (sys_sem_t *sem, u8_t count)
 Creates and returns a new semaphore. More...
 
void sys_sem_set_invalid (sys_sem_t *sem)
 Set a semaphore invalid. More...
 
void sys_sem_signal (sys_sem_t *sem)
 Signals (or releases) a semaphore. More...
 
int sys_sem_valid (sys_sem_t *sem)
 Check if a sempahore is valid/allocated. More...
 
sys_thread_t sys_thread_new (const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
 Instantiate a thread for lwIP. More...
 

Variables

volatile unsigned portLONG ulCriticalNesting
 

#define SYS_ARCH_BLOCKING_TICKTIMEOUT   ((portTickType)10000)

u32_t sys_arch_mbox_fetch ( sys_mbox_t mbox,
void **  msg,
u32_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).

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.
u32_t sys_arch_mbox_tryfetch ( sys_mbox_t mbox,
void **  msg 
)

This is similar to sys_arch_mbox_fetch, however if a message is not present in the mailbox, it immediately returns with the code SYS_MBOX_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.
sys_prot_t sys_arch_protect ( void  )

Protect the system.

Returns
1 on success.
u32_t sys_arch_sem_wait ( sys_sem_t sem,
u32_t  timeout 
)

Blocks the thread while waiting for the semaphore to be signaled.

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.

Referenced by cgi_chipInfo(), cgi_status(), ksz8851snl_task(), and sys_msleep().

void sys_arch_unprotect ( sys_prot_t  pval)

Unprotect the system.

Parameters
pvalProtect value.
void sys_init ( void  )

Initialize the sys_arch layer.

Referenced by lwip_init().

void sys_mbox_free ( sys_mbox_t mbox)

Deallocates a mailbox.

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 
)

Creates an empty mailbox for maximum "size" elements.

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.

Referenced by tcpip_init().

void sys_mbox_post ( sys_mbox_t mbox,
void *  msg 
)

Posts the "msg" to the mailbox.

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.

Referenced by tcpip_callback_with_block().

void sys_mbox_set_invalid ( sys_mbox_t mbox)

Set an mbox invalid.

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 posts the "msg" to the mailbox.

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.

Referenced by tcpip_callback_with_block(), tcpip_input(), and tcpip_trycallback().

int sys_mbox_valid ( sys_mbox_t mbox)

Check if an mbox is valid/allocated.

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.

Referenced by tcpip_callback_with_block(), tcpip_input(), and tcpip_trycallback().

void sys_mutex_free ( sys_mutex_t pxMutex)

Delete a semaphore.

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

Lock a mutex.

Parameters
mutexthe mutex to lock.

Referenced by mem_malloc().

err_t sys_mutex_new ( sys_mutex_t pxMutex)

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.

Referenced by mem_init(), and tcpip_init().

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 pxMutex)

Unlock a mutex.

Parameters
mutexthe mutex to unlock.

Referenced by mem_malloc().

int sys_mutex_valid ( sys_mutex_t mutex)

Check if a mutex is valid/allocated.

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.
void sys_sem_free ( sys_sem_t sem)

Frees a semaphore created by sys_sem_new.

Delete a semaphore.

Parameters
semPointer to the semaphore.

Referenced by sys_msleep().

err_t sys_sem_new ( sys_sem_t sem,
u8_t  count 
)

Creates and returns a new semaphore.

Create a new semaphore.

Parameters
semPointer to the semaphore.
countInitial state of the semaphore.
Returns
ERR_OK for OK, other value indicates error.

Referenced by cgi_search(), ethernetif_init(), and sys_msleep().

void sys_sem_set_invalid ( sys_sem_t sem)

Set a semaphore invalid.

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 (or releases) a semaphore.

Signals a semaphore.

Parameters
semPointer to the semaphore.

Referenced by cgi_chipInfo(), and cgi_status().

int sys_sem_valid ( sys_sem_t sem)

Check if a sempahore is valid/allocated.

Check if a semaphore 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.

Referenced by cgi_search().

sys_thread_t sys_thread_new ( const char *  name,
lwip_thread_fn  thread,
void *  arg,
int  stacksize,
int  prio 
)

Instantiate a thread for lwIP.

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.

Referenced by ethernetif_init(), http_task(), and tcpip_init().

volatile unsigned portLONG ulCriticalNesting