TI-RTOS Drivers
tidrivers_tivac_2_16_01_13
|
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>
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... | |
#define SemaphoreP_WAIT_FOREVER ~(0) |
Wait forever define.
#define SemaphoreP_NO_WAIT (0) |
No wait define.
typedef enum SemaphoreP_Status SemaphoreP_Status |
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.).
typedef enum SemaphoreP_Mode SemaphoreP_Mode |
Mode of the semaphore.
typedef struct SemaphoreP_Params SemaphoreP_Params |
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.
enum SemaphoreP_Status |
enum SemaphoreP_Mode |
SemaphoreP_Handle SemaphoreP_create | ( | unsigned int | count, |
SemaphoreP_Params * | params | ||
) |
Function to create a semaphore.
count | Initial count of the semaphore. For binary semaphores, only values of 0 or 1 are valid. |
params | Pointer to the instance configuration parameters. NULL denotes to use the default parameters (SemaphoreP default parameters as noted in SemaphoreP_Params_init. |
SemaphoreP_Status SemaphoreP_delete | ( | SemaphoreP_Handle | handle | ) |
Function to delete a semaphore.
handle | A SemaphoreP_Handle returned from SemaphoreP_create |
void SemaphoreP_Params_init | ( | SemaphoreP_Params * | params | ) |
Initialize params structure to default values.
The default parameters are:
params | Pointer to the instance configuration parameters. |
SemaphoreP_Status SemaphoreP_pend | ( | SemaphoreP_Handle | handle, |
uint32_t | timeout | ||
) |
Function to pend (wait) on a semaphore.
handle | A SemaphoreP_Handle returned from SemaphoreP_create |
timeout | Timeout (in milliseconds) to wait for the semaphore to be posted (signalled). |
SemaphoreP_Status SemaphoreP_post | ( | SemaphoreP_Handle | handle | ) |
Function to post (signal) a semaphore.
handle | A SemaphoreP_Handle returned from SemaphoreP_create |
SemaphoreP_Status SemaphoreP_postFromClock | ( | SemaphoreP_Handle | handle | ) |
Function to post (signal) a semaphore from an ClockP function.
handle | A SemaphoreP_Handle returned from SemaphoreP_create |
SemaphoreP_Status SemaphoreP_postFromISR | ( | SemaphoreP_Handle | handle | ) |
Function to post (signal) a semaphore from an ISR.
handle | A SemaphoreP_Handle returned from SemaphoreP_create |