TI-RTOS Drivers  tidrivers_cc13xx_cc26xx_2_20_01_10
Data Structures | Macros | Typedefs | Enumerations | Functions
SemaphoreP.h File Reference

Detailed Description

Semaphore module for the RTOS Porting Interface.

============================================================================

Semaphores can be counting semaphores or binary semaphores. Counting semaphores keep track of the number of times the semaphore has been posted with post functions. This is useful, for example, if you have a group of resources that are shared between tasks. Such tasks might call pend() to see if a resource is available before using one. A count of zero for a counting semaphore denotes that it is not available. A positive count denotes how many times a SemaphoreP_pend can be called before it is blocked (or returns SemaphoreP_TIMEOUT).

Binary semaphores can have only two states: available (count = 1) and unavailable (count = 0). They can be used to share a single resource between tasks. They can also be used for a basic signalling mechanism, where the semaphore can be posted multiple times. Binary semaphores do not keep track of the count; they simply track whether the semaphore has been posted or not.


#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
Include dependency graph for SemaphoreP.h:

Go to the source code of this file.

Data Structures

struct  SemaphoreP_Params
 Basic SemaphoreP Parameters. More...
 

Macros

#define SemaphoreP_WAIT_FOREVER   ~(0)
 Wait forever define. More...
 
#define SemaphoreP_NO_WAIT   (0)
 No wait define. More...
 

Typedefs

typedef enum SemaphoreP_Status SemaphoreP_Status
 Status codes for SemaphoreP APIs. More...
 
typedef void * SemaphoreP_Handle
 Opaque client reference to an instance of a SemaphoreP. More...
 
typedef enum SemaphoreP_Mode SemaphoreP_Mode
 Mode of the semaphore. More...
 
typedef struct SemaphoreP_Params SemaphoreP_Params
 Basic SemaphoreP Parameters. More...
 

Enumerations

enum  SemaphoreP_Status {
  SemaphoreP_OK = 0,
  SemaphoreP_FAILURE = -1,
  SemaphoreP_TIMEOUT = -2
}
 Status codes for SemaphoreP APIs. More...
 
enum  SemaphoreP_Mode {
  SemaphoreP_Mode_COUNTING = 0x0,
  SemaphoreP_Mode_BINARY = 0x1
}
 Mode of the semaphore. More...
 

Functions

SemaphoreP_Handle SemaphoreP_create (unsigned int count, SemaphoreP_Params *params)
 Function to create a semaphore. More...
 
SemaphoreP_Status SemaphoreP_delete (SemaphoreP_Handle handle)
 Function to delete a semaphore. More...
 
void SemaphoreP_Params_init (SemaphoreP_Params *params)
 Initialize params structure to default values. More...
 
SemaphoreP_Status SemaphoreP_pend (SemaphoreP_Handle handle, uint32_t timeout)
 Function to pend (wait) on a semaphore. More...
 
SemaphoreP_Status SemaphoreP_post (SemaphoreP_Handle handle)
 Function to post (signal) a semaphore. More...
 
SemaphoreP_Status SemaphoreP_postFromClock (SemaphoreP_Handle handle)
 Function to post (signal) a semaphore from an ClockP function. More...
 
SemaphoreP_Status SemaphoreP_postFromISR (SemaphoreP_Handle handle)
 Function to post (signal) a semaphore from an ISR. More...
 

Macro Definition Documentation

#define SemaphoreP_WAIT_FOREVER   ~(0)

Wait forever define.

#define SemaphoreP_NO_WAIT   (0)

No wait define.

Typedef Documentation

Status codes for SemaphoreP APIs.

typedef void* SemaphoreP_Handle

Opaque client reference to an instance of a SemaphoreP.

A SemaphoreP_Handle returned from the SemaphoreP_create represents that instance and is used in the other instance based functions (e.g. SemaphoreP_post or SemaphoreP_pend, etc.).

Mode of the semaphore.

Basic SemaphoreP Parameters.

Structure that contains the parameters are passed into SemaphoreP_create when creating a SemaphoreP instance. The SemaphoreP_Params_init function should be used to initialize the fields to default values before the application sets the fields manually. The SemaphoreP default parameters are noted in SemaphoreP_Params_init.

Enumeration Type Documentation

Status codes for SemaphoreP APIs.

Enumerator
SemaphoreP_OK 

API completed successfully

SemaphoreP_FAILURE 

API failed

SemaphoreP_TIMEOUT 

API failed because of a timeout

Mode of the semaphore.

Enumerator
SemaphoreP_Mode_COUNTING 
SemaphoreP_Mode_BINARY 

Function Documentation

SemaphoreP_Handle SemaphoreP_create ( unsigned int  count,
SemaphoreP_Params params 
)

Function to create a semaphore.

Parameters
countInitial count of the semaphore. For binary semaphores, only values of 0 or 1 are valid.
paramsPointer to the instance configuration parameters. NULL denotes to use the default parameters (SemaphoreP default parameters as noted in SemaphoreP_Params_init.
Returns
A SemaphoreP_Handle on success or a NULL on an error
SemaphoreP_Status SemaphoreP_delete ( SemaphoreP_Handle  handle)

Function to delete a semaphore.

Parameters
handleA SemaphoreP_Handle returned from SemaphoreP_create
Returns
Status of the functions
  • SemaphoreP_OK: Deleted the semaphore instance
  • SemaphoreP_FAILED: Failed to delete the semaphore instance
void SemaphoreP_Params_init ( SemaphoreP_Params params)

Initialize params structure to default values.

The default parameters are:

  • mode: SemaphoreP_Mode_COUNTING
  • name: NULL
Parameters
paramsPointer to the instance configuration parameters.
SemaphoreP_Status SemaphoreP_pend ( SemaphoreP_Handle  handle,
uint32_t  timeout 
)

Function to pend (wait) on a semaphore.

Parameters
handleA SemaphoreP_Handle returned from SemaphoreP_create
timeoutTimeout (in milliseconds) to wait for the semaphore to be posted (signalled).
Returns
Status of the functions
  • SemaphoreP_OK: Obtain the semaphore
  • SemaphoreP_TIMEOUT: Timed out. Semaphore was not obtained.
  • SemaphoreP_FAILED: Non-time out failure.
SemaphoreP_Status SemaphoreP_post ( SemaphoreP_Handle  handle)

Function to post (signal) a semaphore.

Parameters
handleA SemaphoreP_Handle returned from SemaphoreP_create
Returns
Status of the functions
  • SemaphoreP_OK: Released the semaphore
  • SemaphoreP_FAILED: Failed to post the semaphore
SemaphoreP_Status SemaphoreP_postFromClock ( SemaphoreP_Handle  handle)

Function to post (signal) a semaphore from an ClockP function.

Parameters
handleA SemaphoreP_Handle returned from SemaphoreP_create
Returns
Status of the functions
  • SemaphoreP_OK: Released the semaphore
  • SemaphoreP_FAILED: Failed to post the semaphore
SemaphoreP_Status SemaphoreP_postFromISR ( SemaphoreP_Handle  handle)

Function to post (signal) a semaphore from an ISR.

Parameters
handleA SemaphoreP_Handle returned from SemaphoreP_create
Returns
Status of the functions
  • SemaphoreP_OK: Released the semaphore
  • SemaphoreP_FAILED: Failed to post the semaphore
Copyright 2016, Texas Instruments Incorporated