Microchip® Advanced Software Framework

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

Data Structures

struct  TimeoutlistPerThread
 

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...
 
struct sys_timeoutssys_arch_timeouts (void)
 Get a pointer to the per-thread sys_timeouts structure. 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...
 
sys_mbox_t sys_mbox_new (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...
 
err_t sys_mbox_trypost (sys_mbox_t mbox, void *msg)
 Try to posts the "msg" to the mailbox. More...
 
void sys_sem_free (sys_sem_t sem)
 Frees a semaphore created by sys_sem_new. More...
 
sys_sem_t sys_sem_new (u8_t count)
 Creates and returns a new semaphore. More...
 
void sys_sem_signal (sys_sem_t sem)
 Signals (or releases) a semaphore. More...
 
sys_thread_t sys_thread_new (char *name, void(*thread)(void *arg), void *arg, int stacksize, int prio)
 Instantiate a thread for lwIP. More...
 

Variables

static u16_t NbActiveThreads = 0
 
static struct TimeoutlistPerThread Threads_TimeoutsList [SYS_THREAD_MAX]
 
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).

Parameters
mboxMailbox used.
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.

References NULL, pdFALSE, portTICK_RATE_MS, portTickType, SYS_ARCH_BLOCKING_TICKTIMEOUT, SYS_ARCH_TIMEOUT, xQueueReceive, and xTaskGetTickCount().

Referenced by sys_mbox_fetch().

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.

On success 0 is returned.

Parameters
mboxMailbox used.
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.

References NULL, pdFALSE, SYS_MBOX_EMPTY, and xQueueReceive.

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.

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
semSemphore number.
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.

References pdFALSE, portTICK_RATE_MS, portTickType, SYS_ARCH_BLOCKING_TICKTIMEOUT, SYS_ARCH_TIMEOUT, xSemaphoreTake, and xTaskGetTickCount().

Referenced by cgi_chipInfo(), cgi_status(), gmac_task(), ksz8851snl_task(), mem_malloc(), sys_msleep(), and sys_sem_wait().

struct sys_timeouts* sys_arch_timeouts ( void  )

Get a pointer to the per-thread sys_timeouts structure.

In lwIP, each thread has a list of timeouts which is repressented as a linked list of sys_timeout structures. The sys_timeouts structure holds a pointer to a linked list of timeouts. This function is called by the lwIP timeout scheduler and must not return a NULL value.

Returns
Pointer to the per-thread sys_timeouts structure.

References NbActiveThreads, TimeoutlistPerThread::pid, Threads_TimeoutsList, TimeoutlistPerThread::timeouts, and xTaskGetCurrentTaskHandle().

Referenced by sys_mbox_fetch(), sys_sem_wait(), sys_timeout(), and sys_untimeout().

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.

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
mboxMailbox to be used.

References SYS_MBOX_NULL, and vQueueDelete().

sys_mbox_t sys_mbox_new ( int  size)

Creates an empty mailbox for maximum "size" elements.

Elements stored in mailboxes are pointers.

Parameters
sizeMaximum "size" elements.
Returns
Mailbox created.

References SYS_MBOX_NULL, and xQueueCreate.

Referenced by tcpip_init().

void sys_mbox_post ( sys_mbox_t  mbox,
void *  msg 
)

Posts the "msg" to the mailbox.

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

Parameters
mboxMailbox used.
msgPointer to the message to be post.

References pdTRUE, SYS_ARCH_BLOCKING_TICKTIMEOUT, and xQueueSend.

Referenced by tcpip_callback_with_block(), tcpip_timeout(), and tcpip_untimeout().

err_t sys_mbox_trypost ( sys_mbox_t  mbox,
void *  msg 
)

Try to posts the "msg" to the mailbox.

Parameters
mboxMailbox used.
msgPointer to the message to be post.
Returns
ERR_MEM if the mailbox is full otherwise ERR_OK if the "msg" is posted.

References ERR_MEM, ERR_OK, errQUEUE_FULL, and xQueueSend.

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

void sys_sem_free ( sys_sem_t  sem)

Frees a semaphore created by sys_sem_new.

Parameters
semSemaphore number.

References SYS_SEM_NULL, and vQueueDelete().

Referenced by sys_msleep().

sys_sem_t sys_sem_new ( u8_t  count)

Creates and returns a new semaphore.

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

References SYS_SEM_NULL, vSemaphoreCreateBinary, and xSemaphoreTake.

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

void sys_sem_signal ( sys_sem_t  sem)

Signals (or releases) a semaphore.

Parameters
semSemphore number.

References xSemaphoreGive.

Referenced by cgi_chipInfo(), cgi_status(), mem_malloc(), and sswt_handler().

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

Instantiate a thread for lwIP.

Both the id and the priority are system dependent.

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

References NbActiveThreads, NULL, pdPASS, TimeoutlistPerThread::pid, SYS_ARCH_DECL_PROTECT, SYS_ARCH_PROTECT, SYS_ARCH_UNPROTECT, Threads_TimeoutsList, and xTaskCreate.

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

u16_t NbActiveThreads = 0
static
struct TimeoutlistPerThread Threads_TimeoutsList[SYS_THREAD_MAX]
static
volatile unsigned portLONG ulCriticalNesting