Improve system abstraction layer doxygen docs by moving documentation from sys_arch.txt to the corresponding functions

This commit is contained in:
Dirk Ziegelmeier 2017-10-17 22:30:51 +02:00
parent 33f29af0b6
commit 26b2628f01
2 changed files with 108 additions and 227 deletions

View File

@ -38,214 +38,6 @@ allows both using pointers or actual OS structures to be used. This way, memory
required for such types can be either allocated in place (globally or on the
stack) or on the heap (allocated internally in the "*_new()" functions).
The following functions must be implemented by the sys_arch:
- void sys_init(void)
Is called to initialize the sys_arch layer.
- err_t sys_sem_new(sys_sem_t *sem, u8_t count)
Creates a new semaphore. The semaphore is allocated to the memory that 'sem'
points to (which can be both a pointer or the actual OS structure).
The "count" argument specifies the initial state of the semaphore (which is
either 0 or 1).
If the semaphore has been created, ERR_OK should be returned. Returning any
other error will provide a hint what went wrong, but except for assertions,
no real error handling is implemented.
- void sys_sem_free(sys_sem_t *sem)
Deallocates a semaphore.
- void sys_sem_signal(sys_sem_t *sem)
Signals a semaphore.
- u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
Blocks the thread while waiting for the semaphore to be signaled. If the
"timeout" argument is non-zero, the thread should only be blocked for the
specified time (measured in milliseconds). If the "timeout" argument is zero,
the thread should be blocked until the semaphore is signalled.
The return value is SYS_ARCH_TIMEOUT if the semaphore wasn't signaled within
the specified time or any other value if it was signaled (with or without
waiting).
Notice that lwIP implements a function with a similar name,
sys_sem_wait(), that uses the sys_arch_sem_wait() function.
- int sys_sem_valid(sys_sem_t *sem)
Returns 1 if the semaphore is valid, 0 if it is not valid.
When using pointers, a simple way is to check the pointer for != NULL.
When directly using OS structures, implementing this may be more complex.
This may also be a define, in which case the function is not prototyped.
- void sys_sem_set_invalid(sys_sem_t *sem)
Invalidate a semaphore so that sys_sem_valid() returns 0.
ATTENTION: This does NOT mean that the semaphore shall be deallocated:
sys_sem_free() is always called before calling this function!
This may also be a define, in which case the function is not prototyped.
- void sys_mutex_new(sys_mutex_t *mutex)
Creates a new mutex. The mutex is allocated to the memory that 'mutex'
points to (which can be both a pointer or the actual OS structure).
If the mutex has been created, ERR_OK should be returned. Returning any
other error will provide a hint what went wrong, but except for assertions,
no real error handling is implemented.
- void sys_mutex_free(sys_mutex_t *mutex)
Deallocates a mutex.
- void sys_mutex_lock(sys_mutex_t *mutex)
Blocks the thread until the mutex can be grabbed.
- void sys_mutex_unlock(sys_mutex_t *mutex)
Releases the mutex previously locked through 'sys_mutex_lock()'.
- void sys_mutex_valid(sys_mutex_t *mutex)
Returns 1 if the mutes is valid, 0 if it is not valid.
When using pointers, a simple way is to check the pointer for != NULL.
When directly using OS structures, implementing this may be more complex.
This may also be a define, in which case the function is not prototyped.
- void sys_mutex_set_invalid(sys_mutex_t *mutex)
Invalidate a mutex so that sys_mutex_valid() returns 0.
ATTENTION: This does NOT mean that the mutex shall be deallocated:
sys_mutex_free() is always called before calling this function!
This may also be a define, in which case the function is not prototyped.
- err_t sys_mbox_new(sys_mbox_t *mbox, int size)
Creates an empty mailbox for maximum "size" elements. Elements stored
in mailboxes are pointers. You have to define macros "_MBOX_SIZE"
in your lwipopts.h, or ignore this parameter in your implementation
and use a default size.
If the mailbox has been created, ERR_OK should be returned. Returning any
other error will provide a hint what went wrong, but except for assertions,
no real error handling is implemented.
- 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.
- 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.
- err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
Try to post the "msg" to the mailbox. Returns ERR_MEM if this one
is full, else, ERR_OK if the "msg" is posted.
- 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). If "timeout" is 0, the thread should
be blocked until a message arrives. The "msg" argument is 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.
The return values are the same as for the sys_arch_sem_wait() function:
SYS_ARCH_TIMEOUT if there was a timeout, any other value if a messages
is received.
Note that a function with a similar name, sys_mbox_fetch(), is
implemented by lwIP.
- 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.
To allow for efficient implementations, this can be defined as a
function-like macro in sys_arch.h instead of a normal function. For
example, a naive implementation could be:
#define sys_arch_mbox_tryfetch(mbox,msg) \
sys_arch_mbox_fetch(mbox,msg,1)
although this would introduce unnecessary delays.
- int sys_mbox_valid(sys_mbox_t *mbox)
Returns 1 if the mailbox is valid, 0 if it is not valid.
When using pointers, a simple way is to check the pointer for != NULL.
When directly using OS structures, implementing this may be more complex.
This may also be a define, in which case the function is not prototyped.
- void sys_mbox_set_invalid(sys_mbox_t *mbox)
Invalidate a mailbox so that sys_mbox_valid() returns 0.
ATTENTION: This does NOT mean that the mailbox shall be deallocated:
sys_mbox_free() is always called before calling this function!
This may also be a define, in which case the function is not prototyped.
If threads are supported by the underlying operating system and if
such functionality is needed in lwIP, the following function will have
to be implemented as well:
- sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio)
Starts a new thread named "name" with priority "prio" that will begin its
execution in the function "thread()". The "arg" argument will be passed as an
argument to the thread() function. The stack size to used for this thread is
the "stacksize" parameter. The id of the new thread is returned. Both the id
and the priority are system dependent.
When lwIP is used from more than one context (e.g. from multiple threads OR from
main-loop and from interrupts), the SYS_LIGHTWEIGHT_PROT protection SHOULD be enabled!
- sys_prot_t sys_arch_protect(void)
This optional function does a "fast" critical region protection. This function
is only called during very short critical regions. An embedded system which
supports ISR-based drivers might want to implement this function by disabling
interrupts. Task-based systems might want to implement this by using a mutex
or disabling tasking. This function should support recursive calls from the
same task or interrupt. In other words, sys_arch_protect() could be called
while already protected.
The return value is opaque to lwip and passed to the sys_arch_unprotect() call
matching the sys_arch_protect() call at the same nesting level. This value
might be used to restore the status. However implementations may depend on
every call to sys_arch_protect() having a matching call to sys_arch_unprotect()
and thus can use a nesting count or a recursive mutex.
sys_arch_protect() is only required if your port is supporting an operating
system.
- void sys_arch_unprotect(sys_prot_t pval)
This optional function does a "fast" exit of critical region protection
nesting level. The value passed in pval is the opaque value returned the
respective call to sys_arch_protect(). See the documentation for
sys_arch_protect() for more information. This function is only required if
your port is supporting an operating system.
For some configurations, you also need:
- u32_t sys_now(void)
This optional function returns the current time in milliseconds (don't care
for wraparound, this is only used for time diffs).
Not implementing this function means you cannot use some modules (e.g. TCP
timestamps, internal timeouts for NO_SYS==1).
Note:
Be careful with using mem_malloc() in sys_arch. When malloc() refers to

View File

@ -125,39 +125,51 @@ typedef void (*lwip_thread_fn)(void *arg);
* Create a new mutex.
* Note that mutexes are expected to not be taken recursively by the lwIP code,
* so both implementation types (recursive or non-recursive) should work.
* The mutex is allocated to the memory that 'mutex'
* points to (which can be both a pointer or the actual OS structure).
* If the mutex has been created, ERR_OK should be returned. Returning any
* other error will provide a hint what went wrong, but except for assertions,
* no real error handling is implemented.
*
* @param mutex pointer to the mutex to create
* @return ERR_OK if successful, another err_t otherwise
*/
err_t sys_mutex_new(sys_mutex_t *mutex);
/**
* @ingroup sys_mutex
* Lock a mutex
* Blocks the thread until the mutex can be grabbed.
* @param mutex the mutex to lock
*/
void sys_mutex_lock(sys_mutex_t *mutex);
/**
* @ingroup sys_mutex
* Unlock a mutex
* Releases the mutex previously locked through 'sys_mutex_lock()'.
* @param mutex the mutex to unlock
*/
void sys_mutex_unlock(sys_mutex_t *mutex);
/**
* @ingroup sys_mutex
* Delete a semaphore
* Deallocates a mutex.
* @param mutex the mutex to delete
*/
void sys_mutex_free(sys_mutex_t *mutex);
#ifndef sys_mutex_valid
/**
* @ingroup sys_mutex
* Check if a mutex is valid/allocated: return 1 for valid, 0 for invalid
* Returns 1 if the mutes is valid, 0 if it is not valid.
* When using pointers, a simple way is to check the pointer for != NULL.
* When directly using OS structures, implementing this may be more complex.
* This may also be a define, in which case the function is not prototyped.
*/
int sys_mutex_valid(sys_mutex_t *mutex);
#endif
#ifndef sys_mutex_set_invalid
/**
* @ingroup sys_mutex
* Set a mutex invalid so that sys_mutex_valid returns 0
* Invalidate a mutex so that sys_mutex_valid() returns 0.
* ATTENTION: This does NOT mean that the mutex shall be deallocated:
* sys_mutex_free() is always called before calling this function!
* This may also be a define, in which case the function is not prototyped.
*/
void sys_mutex_set_invalid(sys_mutex_t *mutex);
#endif
@ -168,6 +180,14 @@ void sys_mutex_set_invalid(sys_mutex_t *mutex);
/**
* @ingroup sys_sem
* Create a new semaphore
* Creates a new semaphore. The semaphore is allocated to the memory that 'sem'
* points to (which can be both a pointer or the actual OS structure).
* The "count" argument specifies the initial state of the semaphore (which is
* either 0 or 1).
* If the semaphore has been created, ERR_OK should be returned. Returning any
* other error will provide a hint what went wrong, but except for assertions,
* no real error handling is implemented.
*
* @param sem pointer to the semaphore to create
* @param count initial count of the semaphore
* @return ERR_OK if successful, another err_t otherwise
@ -181,7 +201,17 @@ err_t sys_sem_new(sys_sem_t *sem, u8_t count);
void sys_sem_signal(sys_sem_t *sem);
/**
* @ingroup sys_sem
* Wait for a semaphore for the specified timeout
* Blocks the thread while waiting for the semaphore to be signaled. If the
* "timeout" argument is non-zero, the thread should only be blocked for the
* specified time (measured in milliseconds). If the "timeout" argument is zero,
* the thread should be blocked until the semaphore is signalled.
*
* The return value is SYS_ARCH_TIMEOUT if the semaphore wasn't signaled within
* the specified time or any other value if it was signaled (with or without
* waiting).
* Notice that lwIP implements a function with a similar name,
* sys_sem_wait(), that uses the sys_arch_sem_wait() function.
*
* @param sem the semaphore to wait for
* @param timeout timeout in milliseconds to wait (0 = wait forever)
* @return SYS_ARCH_TIMEOUT on timeout, any other value on success
@ -189,7 +219,7 @@ void sys_sem_signal(sys_sem_t *sem);
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout);
/**
* @ingroup sys_sem
* Delete a semaphore
* Deallocates a semaphore.
* @param sem semaphore to delete
*/
void sys_sem_free(sys_sem_t *sem);
@ -198,14 +228,20 @@ void sys_sem_free(sys_sem_t *sem);
#ifndef sys_sem_valid
/**
* @ingroup sys_sem
* Check if a semaphore is valid/allocated: return 1 for valid, 0 for invalid
* Returns 1 if the semaphore is valid, 0 if it is not valid.
* When using pointers, a simple way is to check the pointer for != NULL.
* When directly using OS structures, implementing this may be more complex.
* This may also be a define, in which case the function is not prototyped.
*/
int sys_sem_valid(sys_sem_t *sem);
#endif
#ifndef sys_sem_set_invalid
/**
* @ingroup sys_sem
* Set a semaphore invalid so that sys_sem_valid returns 0
* Invalidate a semaphore so that sys_sem_valid() returns 0.
* ATTENTION: This does NOT mean that the semaphore shall be deallocated:
* sys_sem_free() is always called before calling this function!
* This may also be a define, in which case the function is not prototyped.
*/
void sys_sem_set_invalid(sys_sem_t *sem);
#endif
@ -234,7 +270,14 @@ void sys_msleep(u32_t ms); /* only has a (close to) 1 ms resolution. */
/**
* @ingroup sys_mbox
* Create a new mbox of specified size
* Creates an empty mailbox for maximum "size" elements. Elements stored
* in mailboxes are pointers. You have to define macros "_MBOX_SIZE"
* in your lwipopts.h, or ignore this parameter in your implementation
* and use a default size.
* If the mailbox has been created, ERR_OK should be returned. Returning any
* other error will provide a hint what went wrong, but except for assertions,
* no real error handling is implemented.
*
* @param mbox pointer to the mbox to create
* @param size (minimum) number of messages in this mbox
* @return ERR_OK if successful, another err_t otherwise
@ -243,21 +286,38 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size);
/**
* @ingroup sys_mbox
* Post a message to an mbox - may not fail
* -> blocks if full, only used from tasks not from ISR
* -> blocks if full, only to be used from tasks NOT from ISR!
*
* @param mbox mbox to posts the message
* @param msg message to post (ATTENTION: can be NULL)
*/
void sys_mbox_post(sys_mbox_t *mbox, void *msg);
/**
* @ingroup sys_mbox
* Try to post a message to an mbox - may fail if full or ISR
* Try to post a message to an mbox - may fail if full.
* Can be used from ISR.
* Returns ERR_MEM if it is full, else, ERR_OK if the "msg" is posted.
*
* @param mbox mbox to posts the message
* @param msg message to post (ATTENTION: can be NULL)
*/
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg);
/**
* @ingroup sys_mbox
* Wait for a new message to arrive in the mbox
* 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). If "timeout" is 0, the thread should
* be blocked until a message arrives. The "msg" argument is 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.
* The return values are the same as for the sys_arch_sem_wait() function:
* SYS_ARCH_TIMEOUT if there was a timeout, any other value if a messages
* is received.
*
* Note that a function with a similar name, sys_mbox_fetch(), is
* implemented by lwIP.
*
* @param mbox mbox to get a message from
* @param msg pointer where the message is stored
* @param timeout maximum time (in milliseconds) to wait for a message (0 = wait forever)
@ -268,7 +328,15 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout);
#ifndef sys_arch_mbox_tryfetch
/**
* @ingroup sys_mbox
* Wait for a new message to arrive in the mbox
* 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.
* To allow for efficient implementations, this can be defined as a
* function-like macro in sys_arch.h instead of a normal function. For
* example, a naive implementation could be:
* \#define sys_arch_mbox_tryfetch(mbox,msg) sys_arch_mbox_fetch(mbox,msg,1)
* although this would introduce unnecessary delays.
*
* @param mbox mbox to get a message from
* @param msg pointer where the message is stored
* @return 0 (milliseconds) if a message has been received
@ -282,7 +350,10 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg);
#define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg)
/**
* @ingroup sys_mbox
* Delete an 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.
*
* @param mbox mbox to delete
*/
void sys_mbox_free(sys_mbox_t *mbox);
@ -290,14 +361,20 @@ void sys_mbox_free(sys_mbox_t *mbox);
#ifndef sys_mbox_valid
/**
* @ingroup sys_mbox
* Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid
* Returns 1 if the mailbox is valid, 0 if it is not valid.
* When using pointers, a simple way is to check the pointer for != NULL.
* When directly using OS structures, implementing this may be more complex.
* This may also be a define, in which case the function is not prototyped.
*/
int sys_mbox_valid(sys_mbox_t *mbox);
#endif
#ifndef sys_mbox_set_invalid
/**
* @ingroup sys_mbox
* Set an mbox invalid so that sys_mbox_valid returns 0
* Invalidate a mailbox so that sys_mbox_valid() returns 0.
* ATTENTION: This does NOT mean that the mailbox shall be deallocated:
* sys_mbox_free() is always called before calling this function!
* This may also be a define, in which case the function is not prototyped.
*/
void sys_mbox_set_invalid(sys_mbox_t *mbox);
#endif
@ -318,8 +395,13 @@ void sys_mbox_set_invalid(sys_mbox_t *mbox);
/**
* @ingroup sys_misc
* The only thread function:
* Creates a new thread
* Starts a new thread named "name" with priority "prio" that will begin its
* execution in the function "thread()". The "arg" argument will be passed as an
* argument to the thread() function. The stack size to used for this thread is
* the "stacksize" parameter. The id of the new thread is returned. Both the id
* and the priority are system dependent.
* ATTENTION: although this function returns a value, it MUST NOT FAIL (ports have to assert this!)
*
* @param name human-readable name for the thread (used for debugging purposes)
* @param thread thread-function
* @param arg parameter passed to 'thread'
@ -329,7 +411,11 @@ sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
#endif /* NO_SYS */
/* sys_init() must be called before anything else. */
/**
* @ingroup sys_misc
* sys_init() must be called before anything else.
* Initialize the sys_arch layer.
*/
void sys_init(void);
#ifndef sys_jiffies
@ -343,6 +429,9 @@ u32_t sys_jiffies(void);
* @ingroup sys_time
* Returns the current time in milliseconds,
* may be the same as sys_jiffies or at least based on it.
* Don't care for wraparound, this is only used for time diffs.
* Not implementing this function means you cannot use some modules (e.g. TCP
* timestamps, internal timeouts for NO_SYS==1).
*/
u32_t sys_now(void);