Microchip® Advanced Software Framework

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)
 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...
 
sys_prot_t sys_arch_protect (void)
 
u32_t sys_arch_sem_wait (sys_sem_t *sem, u32_t timeout)
 Wait for a semaphore for the specified timeout. More...
 
void sys_arch_unprotect (sys_prot_t pval)
 
void sys_init (void)
 
void sys_mbox_free (sys_mbox_t *mbox)
 Delete an mbox. More...
 
err_t sys_mbox_new (sys_mbox_t *mBoxNew, 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_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...
 

Variables

static u16_t NbActiveThreads = 0
 
static struct TimeoutlistPerThread Threads_TimeoutsList [SYS_THREAD_MAX]
 
volatile unsigned portLONG ulCriticalNesting
 Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores should be used instead. More...
 

#define SYS_ARCH_BLOCKING_TICKTIMEOUT   ((portTickType)10000)

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!

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

Referenced by netconn_accept(), and netconn_recv_data().

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

References NULL, pdFALSE, SYS_MBOX_EMPTY, and xQueueReceive.

sys_prot_t sys_arch_protect ( void  )
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

References ERR_MEM, NULL, pdFALSE, SYS_ARCH_BLOCKING_TICKTIMEOUT, SYS_ARCH_TIMEOUT, xSemaphoreTake, and xTaskGetTickCount().

Referenced by do_write(), lwip_getsockopt(), lwip_select(), lwip_setsockopt(), sys_msleep(), and tcpip_apimsg().

void sys_arch_unprotect ( sys_prot_t  pval)
void sys_mbox_free ( sys_mbox_t mbox)
err_t sys_mbox_new ( sys_mbox_t mbox,
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

References ERR_MEM, ERR_OK, lwip_stats, stats_syselem::max, stats_sys::mbox, NULL, stats_::sys, SYS_MBOX_NULL, stats_syselem::used, and xQueueCreate().

Referenced by do_listen(), netconn_alloc(), and tcpip_init().

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)

References NULL, pdTRUE, SYS_ARCH_BLOCKING_TICKTIMEOUT, and xQueueSend.

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

void sys_mbox_set_invalid ( sys_mbox_t mbox)

Set an mbox invalid so that sys_mbox_valid returns 0.

References NULL.

Referenced by accept_function(), do_listen(), netconn_alloc(), and netconn_drain().

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)

References ERR_MEM, ERR_OK, errQUEUE_FULL, NULL, and xQueueSend.

Referenced by accept_function(), err_tcp(), recv_tcp(), tcpip_callback_with_block(), and tcpip_input().

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

References ERR_MEM, ERR_OK, lwip_stats, stats_syselem::max, NULL, stats_sys::sem, stats_::sys, SYS_SEM_NULL, stats_syselem::used, vSemaphoreCreateBinary, and xSemaphoreTake.

Referenced by lwip_select(), netconn_alloc(), prvlwIPInit(), and sys_msleep().

void sys_sem_set_invalid ( sys_sem_t sem)

Set a semaphore invalid so that sys_sem_valid returns 0.

References NULL.

Referenced by netconn_free().

void sys_sem_signal ( sys_sem_t sem)
int sys_sem_valid ( sys_sem_t sem)

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

Referenced by do_delconn(), and netconn_new_with_proto_and_callback().

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)

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

Referenced by low_level_init(), portTASK_FUNCTION(), and tcpip_init().

u16_t NbActiveThreads = 0
static

Referenced by sys_init(), and sys_thread_new().

struct TimeoutlistPerThread Threads_TimeoutsList[SYS_THREAD_MAX]
static

Referenced by sys_init(), and sys_thread_new().

volatile unsigned portLONG ulCriticalNesting

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