lwIP system architecture layer for SAM.
Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
#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 *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. More... | |
u32_t | sys_now (void) |
Return systick value. 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) |
Referenced by sys_arch_mbox_fetch(), sys_arch_sem_wait(), and sys_mbox_post().
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.
mbox | Pointer to the mailbox. |
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 ERR_MEM, NULL, pdFALSE, portTICK_RATE_MS, portTickType, SYS_ARCH_BLOCKING_TICKTIMEOUT, SYS_ARCH_TIMEOUT, xQueueReceive, and xTaskGetTickCount().
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.
mbox | Pointer to the mailbox. |
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.
sys_prot_t sys_arch_protect | ( | void | ) |
Protect the system.
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.
sem | Pointer to the semaphore. |
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 ERR_MEM, NULL, pdFALSE, portTICK_RATE_MS, portTickType, SYS_ARCH_BLOCKING_TICKTIMEOUT, SYS_ARCH_TIMEOUT, xSemaphoreTake, and xTaskGetTickCount().
Referenced by ksz8851snl_task(), and sys_msleep().
void sys_arch_unprotect | ( | sys_prot_t | pval | ) |
Unprotect the system.
pval | Protect 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.
mbox | Pointer to the new mailbox. |
References NULL, SYS_MBOX_NULL, and vQueueDelete().
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.
mBoxNew | Pointer to the new mailbox. |
size | Maximum "size" elements. |
References ERR_MEM, ERR_OK, NULL, 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.
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.
mbox | Pointer to the mailbox. |
msg | Pointer to the message to be post. |
References NULL, pdTRUE, SYS_ARCH_BLOCKING_TICKTIMEOUT, and xQueueSend.
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.
mbox | Pointer to the mailbox. |
References NULL.
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.
mbox | Pointer to the mailbox. |
msg | Pointer to the message to be post. |
References ERR_MEM, ERR_OK, errQUEUE_FULL, NULL, xQueueSend, and xQueueSendFromISR.
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.
mbox | Pointer to the mailbox. |
Referenced by tcpip_callback_with_block(), tcpip_input(), and tcpip_trycallback().
void sys_mutex_free | ( | sys_mutex_t * | mutex | ) |
Delete a semaphore.
mutex | the mutex to delete. |
void sys_mutex_lock | ( | sys_mutex_t * | mutex | ) |
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.
mutex | Pointer to the mutex to create. |
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.
mutex | Pointer to the mutex. |
References NULL.
void sys_mutex_unlock | ( | sys_mutex_t * | mutex | ) |
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.
mutex | Pointer to the mutex. |
u32_t sys_now | ( | void | ) |
Return systick value.
Returns the current time in milliseconds, may be the same as sys_jiffies or at least based on it.
References xTaskGetTickCount().
void sys_sem_free | ( | sys_sem_t * | sem | ) |
Frees a semaphore created by sys_sem_new.
Delete a semaphore.
sem | Pointer to the semaphore. |
References NULL, SYS_SEM_NULL, and vQueueDelete().
Referenced by sys_msleep().
Creates and returns a new semaphore.
Create a new semaphore.
sem | Pointer to the semaphore. |
count | Initial state of the semaphore. |
References ERR_MEM, ERR_OK, NULL, SYS_SEM_NULL, vSemaphoreCreateBinary, and xSemaphoreTake.
Referenced by 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.
sem | Pointer to the semaphore. |
References NULL.
void sys_sem_signal | ( | sys_sem_t * | sem | ) |
Signals (or releases) a semaphore.
Signals a semaphore.
sem | Pointer to the semaphore. |
References NULL, and xSemaphoreGive.
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.
sem | Pointer to the semaphore. |
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.
name | Pointer to the thread name. |
thread | Thread function. |
arg | Argument will be passed into the thread(). |
stacksize | Stack size of the thread. |
prio | Thread priority. |
References NULL, pdPASS, SYS_ARCH_DECL_PROTECT, SYS_ARCH_PROTECT, SYS_ARCH_UNPROTECT, and xTaskCreate.
Referenced by ethernetif_init(), and tcpip_init().
volatile unsigned portLONG ulCriticalNesting |