Jump to main content

##

# 1.4.4.1 OSAL_SEM_Create Function

## C

    OSAL_RESULT OSAL_SEM_Create(OSAL_SEM_HANDLE_TYPE* semID, OSAL_SEM_TYPE type, uint8_t maxCount, uint8_t initialCount)

## Summary

Creates an OSAL Semaphore.

## Description

This function creates an OSAL binary or counting semaphore. If OSAL_SEM_TYPE_BINARY is specified, the maxcount and initialCount values are ignored.

## Precondition

Semaphore must have been declared.

## Parameters

Param | Description
--- | ---
semID | Pointer to the Semaphore ID. Updated with valid semaphore handle if call was successful
type | If OSAL_SEM_TYPE_BINARY, create a binary semaphore. If OSAL_SEM_TYPE_COUNTING, create a counting semaphore with the specified count values
maxCount | Maximum value for a counting semaphore (ignored for a BINARY semaphore). This parameter is ignored for ThreadX and Micrium/OS-III as these RTOS libraries do not support this parameter
initialCount | Starting count value for the semaphore (ignored for a BINARY semaphore) This should be less than or equal to maxCount when used with a RTOS library that supports the maxCount parameter (i.e., FreeRTOS and OPENRTOS)

## Returns

OSAL_RESULT_TRUE - Semaphore created

OSAL_RESULT_FALSE - Semaphore creation failed

## Example

    OSAL_SEM_Create(&mySemID, OSAL_SEM_TYPE_COUNTING, 10, 5);

## Remarks

None.