![]() |
WE310F5
39.00.000
|
This section describes the M2MB APIs to perform OS semaphore operations. More...
This section describes the M2MB APIs to perform OS semaphore operations.
#define M2MB_OS_SEM_INVALID 0 |
Definition at line 52 of file m2mb_os_sem.h.
#define M2MB_OS_SEM_INVALID_ATTR 0 |
Definition at line 53 of file m2mb_os_sem.h.
#define m2mb_os_sem_setAttrItem_ | ( | h, | |
args, | |||
... | |||
) | m2mb_os_sem_setAttrItem( h, CMDS_ARGS( args ) ) |
Definition at line 65 of file m2mb_os_sem.h.
typedef struct M2MB_OS_SEM_ATTR_HANDLE_TAG* M2MB_OS_SEM_ATTR_HANDLE |
Definition at line 108 of file m2mb_os_sem.h.
typedef struct M2MB_OS_SEM_HANDLE_TAG* M2MB_OS_SEM_HANDLE |
Definition at line 107 of file m2mb_os_sem.h.
Definition at line 81 of file m2mb_os_sem.h.
enum M2MB_OS_SEM_TYPE_E |
Enumerator | |
---|---|
M2MB_OS_SEM_GEN | |
M2MB_OS_SEM_BINARY | |
M2MB_OS_SEM_COUNTING | |
M2MB_OS_SEM_MAX |
Definition at line 68 of file m2mb_os_sem.h.
M2MB_OS_RESULT_E m2mb_os_sem_deinit | ( | M2MB_OS_SEM_HANDLE | semHandle | ) |
Semaphore deinit or deletion.
This service deletes the specified os semaphore. All tasks suspended waiting for a this semaphore are resumed with a
[in] | semHandle | handle of the semaphore |
semaphore. Allowed From tasks Preemption Possible Yes
Example
M2MB_OS_RESULT_E m2mb_os_sem_get | ( | M2MB_OS_SEM_HANDLE | semHandle, |
UINT32 | timeoutTicks | ||
) |
Get an instance of semaphore.
This service retrieves an instance (a single count) from the specified semaphore if its count is grater than 0. As a result, the specified semaphore’s count is decreased by one. If count is not availbale parameter timeoutTicks specifies how to behave: wait forever or set a limit to wait and then exit
[in] | semHandle | handle of semaphore |
[in] | timeoutTicks | If timeout is specified and semaphore count is zero, task will be suspended for a maximum time of timeout ticks |
Example
M2MB_OS_RESULT_E m2mb_os_sem_getItem | ( | M2MB_OS_SEM_HANDLE | semHandle, |
M2MB_OS_SEM_SEL_CMD_E | selCmd, | ||
MEM_W * | pOut, | ||
void * | pIn | ||
) |
Get specific semaphore properties.
This service retrieve value for specified parameter of the specified semaphore Selecting cmd, a parameter to be retrieved can be set To be used when semaphore is already created: its right usage is under application responsibility
[in] | semHandle | handle of semaphore |
[in] | selCmd | Select parameter to be retrieved (see M2MB_OS_SEM_SEL_CMD_E) |
[out] | pOut | pointer Output parameter got: its meaning depend on selCmd used. See examples. As general pointer it is set to MEM_W |
[in] | pIn | pointer to void general Parameter to be specified, if any, to get right output. See examples. If parameter is not needed, use NULL |
Example
M2MB_OS_RESULT_E m2mb_os_sem_hptf | ( | M2MB_OS_SEM_HANDLE | semHandle | ) |
Prioritize semaphore suspension list HPTF: Highest Priority Task First.
This service set the task waiting for this semaphore which has currently highest priority, on the top of FIFO task suspension list It is one shot operation. To have highest priority task served first for every put, see m2m_os_sem_setItem(..) or m2mb_os_sem_setAttrItem.
[in] | semHandle | handle of semaphore |
Example usage of m2mb_os_sem_hptf
M2MB_OS_RESULT_E m2mb_os_sem_init | ( | M2MB_OS_SEM_HANDLE * | pSemHandle, |
M2MB_OS_SEM_ATTR_HANDLE * | pSemAttr | ||
) |
Semaphore creation.
This service creates a counting semaphore for inter-intra task synchronization. The initial semaphore attribute are set inside M2MB_OS_SEM_ATTR_HANDLE as parameters.
[out] | pSemHandle | pointer to semaphore handle |
[in] | pSemAttr | pointer to semaphore attribute handle |
Example Semaphore creation using m2mb_os_sem_init
M2MB_OS_RESULT_E m2mb_os_sem_put | ( | M2MB_OS_SEM_HANDLE | semHandle | ) |
Place (put) an instance in semaphore.
This service puts an instance into the specified counting semaphore, which in reality increments the counting semaphore by one. In case of general counting semaphore (M2MB_OS_SEM_GEN), if this service is called when the semaphore count is all ones (OxFFFFFFFF), the new put operation will cause the semaphore to be reset to zero. When M2MB_OS_SEM_BINARY or M2MB_OS_SEM_COUNTING are the type of OS semaphore, count will be limited to 1 or maxCount as specified by M2MB_OS_SEM_SEL_CMD_MAX_COUNT attribute
[in] | semHandle | handle of semaphore |
Example
M2MB_OS_RESULT_E m2mb_os_sem_setAttrItem | ( | M2MB_OS_SEM_ATTR_HANDLE * | pSemAttrHandle, |
UINT8 | nCmds, | ||
... | |||
) |
Set semaphore attribute for creation.
This service set the attribute (or create it) to be used for semaphore creation
[in] | pSemAttrHandle | pointer to semaphore attribute of semaphore |
[in] | nCmds | number of commands to be issued at once |
[in] | ... | variable inputs, N cmds (see M2MB_OS_SEM_SEL_CMD_E) followed by N arguments for their respective issued commands. CMDS(...) and CMDS_ARGS(...) macro can be used to better insert cmd and parameters and to better control right insertion |
Example
M2MB_OS_RESULT_E m2mb_os_sem_setItem | ( | M2MB_OS_SEM_HANDLE | semHandle, |
M2MB_OS_SEM_SEL_CMD_E | selCmd, | ||
void * | pIn | ||
) |
Set specific semaphore properties.
This service set value for specified parameter of the specified semaphore if available Selecting cmd, a parameter to be set can be selected To be used when semaphore is already created: its right usage is under application responsibility
[in] | semHandle | handle of semaphore |
[in] | selCmd | Select parameter to be set (see M2MB_OS_SEM_SEL_CMD_E) |
[in] | pIn | pointer to value to be set. If a simple value, can be easily casted to (void*) e.g. int value -3 has to be passed, use (void*)-3 NULL if no value is needed |
Example