Semaphores API Changes
The table below shows the difference in API for semaphore management.
µC/OS-II (os_sem.c ) | µC/OS-III (os_sem.c ) | Note |
---|---|---|
INT16U OSSemAccept( OS_EVENT *pevent); | (1) | |
OS_EVENT * OSSemCreate( INT16U cnt); | void OSSemCreate( OS_SEM *p_sem, CPU_CHAR *p_name, OS_SEM_CTR cnt, OS_ERR *p_err); | (2) |
OS_EVENT * OSSemDel( OS_EVENT *pevent, INT8U opt, INT8U *perr); | OS_OBJ_QTY, OSSemDel( OS_SEM *p_sem, OS_OPT opt, OS_ERR *p_err); | |
void OSSemPend( OS_EVENT *pevent, INT32U timeout, INT8U *perr); | OS_SEM_CTR OSSemPend( OS_SEM *p_sem, OS_TICK timeout, OS_OPT opt, CPU_TS *p_ts, OS_ERR *p_err); | (3) |
INT8U OSSemPendAbort( OS_EVENT *pevent, INT8U opt, INT8U *perr); | OS_OBJ_QTY OSSemPendAbort( OS_SEM *p_sem, OS_OPT opt, OS_ERR *p_err); | |
void OSSemPost( OS_EVENT *pevent); | void OSSemPost( OS_SEM *p_sem, OS_OPT opt, OS_ERR *p_err); | |
INT8U OSSemQuery( OS_EVENT *pevent, OS_SEM_DATA *p_sem_data); | (4) | |
void OSSemSet( OS_EVENT *pevent, INT16U cnt, INT8U *perr); | void OSSemSet( OS_SEM *p_sem, OS_SEM_CTR cnt, OS_ERR *p_err); |
(1) In µC/OS-III, there is no “accept” API since this feature is built into the OSSemPend()
by specifying the OS_OPT_PEND_NON_BLOCKING
option.
(2) In µC/OS-II, OSSemCreate()
returns the address of an OS_EVENT
, which is used as the “handle” to the semaphore. In µC/OS-III, the application must allocate storage for an OS_SEM
object, which serves the same purpose as the OS_EVENT
. The benefit in µC/OS-III is that it is not necessary to predetermine the number of semaphores at compile time.
(3) µC/OS-III returns additional information when a semaphore is signaled. The ISR or task that signals the semaphore takes a snapshot of the current timestamp and stores this in the OS_SEM
object signaled. The receiver of the signal therefore knows when the signal was sent.
(4) µC/OS-III does not provide query services, as they were rarely used.