Semaphore

group group_abstraction_rtos_semaphore

APIs for acquiring and working with Semaphores.

Unnamed Group

cy_rslt_t cy_rtos_init_semaphore(cy_semaphore_t *semaphore, uint32_t maxcount, uint32_t initcount)

Create a semaphore.

This is basically a counting semaphore.

Return

The status of the semaphore creation. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

Parameters
  • [inout] semaphore: Pointer to the semaphore handle to be initialized

  • [in] maxcount: The maximum count for this semaphore

  • [in] initcount: The initial count for this semaphore

cy_rslt_t cy_rtos_get_semaphore(cy_semaphore_t *semaphore, cy_time_t timeout_ms, bool in_isr)

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.

Return

The status of get semaphore operation [CY_RSLT_SUCCESS, CY_RTOS_TIMEOUT, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

Parameters
  • [in] semaphore: Pointer to the semaphore handle

  • [in] timeout_ms: Maximum number of milliseconds to wait while attempting to get the semaphore. Use the CY_RTOS_NEVER_TIMEOUT constant to wait forever. Must be zero is in_isr is true

  • [in] in_isr: true if we are trying to get the semaphore from with an ISR

cy_rslt_t cy_rtos_set_semaphore(cy_semaphore_t *semaphore, bool in_isr)

Set/Release a semaphore.

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

Return

The status of set semaphore operation [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

Parameters
  • [in] semaphore: Pointer to the semaphore handle

  • [in] in_isr: Value of true indicates calling from interrupt context Value of false indicates calling from normal thread context

cy_rslt_t cy_rtos_get_count_semaphore(cy_semaphore_t *semaphore, size_t *count)

Get the count of a semaphore.

Gets the number of available tokens on the semaphore.

Return

The status of get semaphore count operation [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]

Parameters
  • [in] semaphore: Pointer to the semaphore handle

  • [out] count: Pointer to the return count

cy_rslt_t cy_rtos_deinit_semaphore(cy_semaphore_t *semaphore)

Deletes a semaphore.

This function frees the resources associated with a semaphore.

Return

The status of semaphore deletion [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]

Parameters
  • [in] semaphore: Pointer to the semaphore handle