#include "lwip/opt.h"
#include "lwip/err.h"
#include "arch/sys_arch.h"
Data Structures | |
struct | sys_timeo |
struct | sys_timeouts |
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 |
#define | sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg) |
Typedefs | |
typedef void(* | sys_timeout_handler )(void *arg) |
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... | |
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_timeouts * | sys_arch_timeouts (void) |
Get a pointer to the per-thread sys_timeouts structure. More... | |
void | sys_init (void) |
Initialize the sys_arch layer. More... | |
u32_t | sys_jiffies (void) |
void | sys_mbox_fetch (sys_mbox_t mbox, void **msg) |
Wait (forever) for a message to arrive in an mbox. 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_msleep (u32_t ms) |
Sleep for some ms. More... | |
u32_t | sys_now (void) |
Returns the current time in milliseconds. 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... | |
void | sys_sem_wait (sys_sem_t sem) |
Wait (forever) for a semaphore to become available. More... | |
int | sys_sem_wait_timeout (sys_sem_t sem, u32_t timeout) |
Wait for a semaphore with timeout (specified in ms) 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... | |
void | sys_timeout (u32_t msecs, sys_timeout_handler h, void *arg) |
Create a one-shot timer (aka timeout). More... | |
void | sys_untimeout (sys_timeout_handler h, void *arg) |
Go through timeout list (for this task only) and remove the first matching entry, even though the timeout has not triggered yet. More... | |
#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.
#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.
#define SYS_ARCH_UNPROTECT | ( | lev | ) |
#define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT |
#define sys_mbox_tryfetch | ( | mbox, | |
msg | |||
) | sys_arch_mbox_tryfetch(mbox, msg) |
typedef void(* sys_timeout_handler)(void *arg) |
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).
mbox | Mailbox used. |
msg | A 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. |
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.
mbox | Mailbox used. |
msg | A 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. |
References NULL, pdFALSE, SYS_MBOX_EMPTY, and xQueueReceive.
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.
sem | Semphore number. |
timeout | The 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. |
References pdFALSE, portTICK_RATE_MS, portTickType, SYS_ARCH_BLOCKING_TICKTIMEOUT, SYS_ARCH_TIMEOUT, xSemaphoreTake, and xTaskGetTickCount().
Referenced by 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.
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_init | ( | void | ) |
Initialize the sys_arch layer.
References NbActiveThreads, sys_timeouts::next, NULL, TimeoutlistPerThread::pid, Threads_TimeoutsList, and TimeoutlistPerThread::timeouts.
Referenced by lwip_init().
u32_t sys_jiffies | ( | void | ) |
void sys_mbox_fetch | ( | sys_mbox_t | mbox, |
void ** | msg | ||
) |
Wait (forever) for a message to arrive in an mbox.
While waiting, timeouts (for this thread) are processed.
mbox | the mbox to fetch the message from |
msg | the place to store the message |
References sys_timeo::arg, sys_timeo::h, LOCK_TCPIP_CORE, LWIP_DEBUGF, memp_free(), sys_timeo::next, sys_timeouts::next, NULL, sys_arch_mbox_fetch(), SYS_ARCH_TIMEOUT, sys_arch_timeouts(), SYS_DEBUG, sys_timeo::time, and UNLOCK_TCPIP_CORE.
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.
mbox | Mailbox 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.
size | Maximum "size" elements. |
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.
mbox | Mailbox used. |
msg | Pointer 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.
mbox | Mailbox used. |
msg | Pointer to the message to be post. |
References ERR_MEM, ERR_OK, errQUEUE_FULL, and xQueueSend.
Referenced by tcpip_callback_with_block(), tcpip_input(), and tcpip_trycallback().
void sys_msleep | ( | u32_t | ms | ) |
Sleep for some ms.
Timeouts are NOT processed while sleeping.
ms | number of milliseconds to sleep |
Timeouts are processed while sleeping.
ms | number of milliseconds to sleep |
References ERR_OK, sys_arch_sem_wait(), sys_sem_free(), sys_sem_new(), and sys_sem_wait_timeout().
u32_t sys_now | ( | void | ) |
Returns the current time in milliseconds.
Returns the current time in milliseconds.
Returns the current time in milliseconds.
Returns the current time in milliseconds, may be the same as sys_jiffies or at least based on it.
References sys_get_ms(), and xTaskGetTickCount().
void sys_sem_free | ( | sys_sem_t | sem | ) |
Frees a semaphore created by sys_sem_new.
sem | Semaphore number. |
References SYS_SEM_NULL, and vQueueDelete().
Referenced by prvlwIPInit(), and sys_msleep().
Creates and returns a new semaphore.
count | Initial state of the semaphore. |
References SYS_SEM_NULL, vSemaphoreCreateBinary, and xSemaphoreTake.
Referenced by mem_init(), prvlwIPInit(), sys_msleep(), and tcpip_init().
void sys_sem_signal | ( | sys_sem_t | sem | ) |
Signals (or releases) a semaphore.
sem | Semphore number. |
References xSemaphoreGive.
Referenced by mem_malloc(), sswt_handler(), and tcpip_init_done().
void sys_sem_wait | ( | sys_sem_t | sem | ) |
Wait (forever) for a semaphore to become available.
While waiting, timeouts (for this thread) are processed.
sem | semaphore to wait for |
References sys_timeo::arg, sys_timeo::h, LWIP_DEBUGF, memp_free(), sys_timeo::next, sys_timeouts::next, NULL, sys_arch_sem_wait(), SYS_ARCH_TIMEOUT, sys_arch_timeouts(), SYS_DEBUG, and sys_timeo::time.
Wait for a semaphore with timeout (specified in ms)
sem | semaphore to wait |
timeout | timeout in ms (0: wait forever) |
References sswt_cb::psem, sswt_handler(), sys_sem_wait, sys_timeout(), sys_untimeout(), and sswt_cb::timeflag.
Referenced by sys_msleep().
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.
name | Pointer to the thread name. |
thread | Pointer to the thread function. |
arg | Argument will be passed into the thread(). |
stacksize | Stack size of the thread. |
prio | Thread priority. |
References NbActiveThreads, NULL, pdPASS, TimeoutlistPerThread::pid, result, SYS_ARCH_DECL_PROTECT, SYS_ARCH_PROTECT, SYS_ARCH_UNPROTECT, Threads_TimeoutsList, and xTaskCreate.
Referenced by low_level_init(), portTASK_FUNCTION(), and tcpip_init().
void sys_timeout | ( | u32_t | msecs, |
sys_timeout_handler | h, | ||
void * | arg | ||
) |
Create a one-shot timer (aka timeout).
Timeouts are processed in the following cases:
msecs | time in milliseconds after that the timer should expire |
h | callback function to call when msecs have elapsed |
arg | argument to pass to the callback function |
References sys_timeo::arg, sys_timeo::h, LWIP_ASSERT, LWIP_DEBUGF, memp_malloc(), sys_timeo::next, sys_timeouts::next, NULL, sys_arch_timeouts(), SYS_DEBUG, sys_timeo::time, and U32_F.
void sys_untimeout | ( | sys_timeout_handler | h, |
void * | arg | ||
) |
Go through timeout list (for this task only) and remove the first matching entry, even though the timeout has not triggered yet.
h | callback function that would be called by the timeout |
arg | callback argument that would be passed to h |
References sys_timeo::arg, sys_timeo::h, LWIP_ASSERT, memp_free(), sys_timeo::next, sys_timeouts::next, NULL, sys_arch_timeouts(), and sys_timeo::time.