RTOS Abstraction (abstraction-rtos)
Semaphore

General Description

APIs for acquiring and working with Semaphores.

cy_rslt_t cy_rtos_semaphore_init (cy_semaphore_t *semaphore, uint32_t maxcount, uint32_t initcount)
 Create a semaphore. More...
 
cy_rslt_t cy_rtos_semaphore_get (cy_semaphore_t *semaphore, cy_time_t timeout_ms)
 Get/Acquire a semaphore. More...
 
cy_rslt_t cy_rtos_semaphore_set (cy_semaphore_t *semaphore)
 Set/Release a semaphore. More...
 
cy_rslt_t cy_rtos_semaphore_get_count (cy_semaphore_t *semaphore, size_t *count)
 Get the count of a semaphore. More...
 
cy_rslt_t cy_rtos_semaphore_deinit (cy_semaphore_t *semaphore)
 Deletes a semaphore. More...
 
#define cy_rtos_init_semaphore(semaphore, maxcount, initcount)    cy_rtos_semaphore_init(semaphore, maxcount, initcount)
 Create a semaphore. More...
 
#define cy_rtos_get_semaphore(semaphore, timeout_ms, in_isr)   cy_rtos_semaphore_get(semaphore, timeout_ms)
 Get/Acquire a semaphore. More...
 
#define cy_rtos_set_semaphore(semaphore, in_isr)   cy_rtos_semaphore_set(semaphore)
 Set/Release a semaphore. More...
 
#define cy_rtos_get_count_semaphore(semaphore, count)   cy_rtos_semaphore_get_count(semaphore, count)
 Get the count of a semaphore. More...
 
#define cy_rtos_deinit_semaphore(semaphore)   cy_rtos_semaphore_deinit(semaphore)
 Deletes a semaphore. More...
 

Macro Definition Documentation

◆ cy_rtos_init_semaphore

#define cy_rtos_init_semaphore (   semaphore,
  maxcount,
  initcount 
)     cy_rtos_semaphore_init(semaphore, maxcount, initcount)

Create a semaphore.

This is basically a counting semaphore. It can be used for synchronization between tasks and tasks and interrupts.

Parameters
[in,out]semaphorePointer to the semaphore handle to be initialized
[in]maxcountThe maximum count for this semaphore
[in]initcountThe initial count for this semaphore
Returns
The status of the semaphore creation. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_get_semaphore

#define cy_rtos_get_semaphore (   semaphore,
  timeout_ms,
  in_isr 
)    cy_rtos_semaphore_get(semaphore, timeout_ms)

Get/Acquire a semaphore.

If the semaphore count is zero, waits until the semaphore count is greater than zero. Once the semaphore count is greater than zero, this function decrements the count and return. It may also return if the timeout is exceeded.

Parameters
[in]semaphorePointer to the semaphore handle
[in]timeout_msMaximum number of milliseconds to wait while attempting to get the semaphore. Use the CY_RTOS_NEVER_TIMEOUT constant to wait forever. Must be zero if in_isr is true.
[in]in_isrtrue if we are trying to get the semaphore from with an ISR
Returns
The status of get semaphore operation [CY_RSLT_SUCCESS, CY_RTOS_TIMEOUT, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_set_semaphore

#define cy_rtos_set_semaphore (   semaphore,
  in_isr 
)    cy_rtos_semaphore_set(semaphore)

Set/Release a semaphore.

Increments the semaphore count, up to the maximum count for this semaphore.

Parameters
[in]semaphorePointer to the semaphore handle
[in]in_isrValue of true indicates calling from interrupt context Value of false indicates calling from normal thread context
Returns
The status of set semaphore operation [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_get_count_semaphore

#define cy_rtos_get_count_semaphore (   semaphore,
  count 
)    cy_rtos_semaphore_get_count(semaphore, count)

Get the count of a semaphore.

Gets the number of available tokens on the semaphore.

Parameters
[in]semaphorePointer to the semaphore handle
[out]countPointer to the return count
Returns
The status of get semaphore count operation [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_deinit_semaphore

#define cy_rtos_deinit_semaphore (   semaphore)    cy_rtos_semaphore_deinit(semaphore)

Deletes a semaphore.

This function frees the resources associated with a semaphore.

Parameters
[in]semaphorePointer to the semaphore handle
Returns
The status of semaphore deletion [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

Function Documentation

◆ cy_rtos_semaphore_init()

cy_rslt_t cy_rtos_semaphore_init ( cy_semaphore_t semaphore,
uint32_t  maxcount,
uint32_t  initcount 
)

Create a semaphore.

This is basically a counting semaphore. It can be used for synchronization between tasks and tasks and interrupts.

Parameters
[in,out]semaphorePointer to the semaphore handle to be initialized
[in]maxcountThe maximum count for this semaphore
[in]initcountThe initial count for this semaphore
Returns
The status of the semaphore creation. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_semaphore_get()

cy_rslt_t cy_rtos_semaphore_get ( cy_semaphore_t semaphore,
cy_time_t  timeout_ms 
)

Get/Acquire a semaphore.

If the semaphore count is zero, waits until the semaphore count is greater than zero. Once the semaphore count is greater than zero, this function decrements the count and return. It may also return if the timeout is exceeded.

Parameters
[in]semaphorePointer to the semaphore handle
[in]timeout_msMaximum number of milliseconds to wait while attempting to get the semaphore. Use the CY_RTOS_NEVER_TIMEOUT constant to wait forever. Must be zero if in_isr is true.
Returns
The status of get semaphore operation [CY_RSLT_SUCCESS, CY_RTOS_TIMEOUT, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_semaphore_set()

cy_rslt_t cy_rtos_semaphore_set ( cy_semaphore_t semaphore)

Set/Release a semaphore.

Increments the semaphore count, up to the maximum count for this semaphore.

Parameters
[in]semaphorePointer to the semaphore handle Value of false indicates calling from normal thread context
Returns
The status of set semaphore operation [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_semaphore_get_count()

cy_rslt_t cy_rtos_semaphore_get_count ( cy_semaphore_t semaphore,
size_t *  count 
)

Get the count of a semaphore.

Gets the number of available tokens on the semaphore.

Parameters
[in]semaphorePointer to the semaphore handle
[out]countPointer to the return count
Returns
The status of get semaphore count operation [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]

◆ cy_rtos_semaphore_deinit()

cy_rslt_t cy_rtos_semaphore_deinit ( cy_semaphore_t semaphore)

Deletes a semaphore.

This function frees the resources associated with a semaphore.

Parameters
[in]semaphorePointer to the semaphore handle
Returns
The status of semaphore deletion [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]