Mayank Gupta / Mbed OS pelion-example-frdm

Dependencies:   FXAS21002 FXOS8700Q

Embed: (wiki syntax)

« Back to documentation index

pal_rtos.h File Reference

pal_rtos.h File Reference

PAL RTOS. This file contains the real-time OS APIs and is a part of the PAL service API. More...

Go to the source code of this file.

Data Structures

struct  pal_threadLocalStore
 Thread local store struct. More...

Typedefs

typedef uintptr_t palThreadID_t
 Primitive ID type declarations.
typedef enum palTimerType palTimerType_t
 Timer types supported in PAL.
typedef void(* palTimerFuncPtr )(void const *funcArgument)
 PAL timer function prototype.
typedef void(* palThreadFuncPtr )(void const *funcArgument)
 PAL thread function prototype.
typedef enum pal_osPriority palThreadPriority_t
 Thread priority levels for PAL threads - each thread must have a different priority.
typedef struct pal_threadLocalStore palThreadLocalStore_t
 Thread local store struct.

Enumerations

enum  palTimerType { palOsTimerOnce = 0, palOsTimerPeriodic = 1 }
 

Timer types supported in PAL.

More...
enum  pal_osPriority { , PAL_osPriorityReservedDNS = 6, PAL_osPriorityReservedSockets = 7 , PAL_osPriorityReservedHighResTimer = 9 }
 

Available priorities in PAL implementation, each priority can appear only once.

More...

Functions

void pal_osReboot (void)
 Initiates a system reboot.
uint64_t pal_osKernelSysTick (void)
 Get the RTOS kernel system timer counter.
uint64_t pal_osKernelSysTickMicroSec (uint64_t microseconds)
 Converts a value from microseconds to kernel system ticks.
uint64_t pal_osKernelSysMilliSecTick (uint64_t sysTicks)
 Converts kernel system ticks to milliseconds.
uint64_t pal_osKernelSysTickFrequency (void)
 Get the system tick frequency.
palStatus_t pal_osThreadCreateWithAlloc (palThreadFuncPtr function, void *funcArgument, palThreadPriority_t priority, uint32_t stackSize, palThreadLocalStore_t *store, palThreadID_t *threadID)
 Allocates memory for the thread stack, creates and starts the thread function inside the PAL platform wrapper function.
palStatus_t pal_osThreadTerminate (palThreadID_t *threadID)
 Terminate the thread and free the data allocated for it.
palThreadID_t pal_osThreadGetId (void)
 Get the ID of the current thread.
palStatus_t pal_osDelay (uint32_t milliseconds)
 Wait for a specified time period in milliseconds.
palStatus_t pal_osTimerCreate (palTimerFuncPtr function, void *funcArgument, palTimerType_t timerType, palTimerID_t *timerID)
 Create a timer.
palStatus_t pal_osTimerStart (palTimerID_t timerID, uint32_t millisec)
 Start or restart a timer.
palStatus_t pal_osTimerStop (palTimerID_t timerID)
 Stop a timer.
palStatus_t pal_osTimerDelete (palTimerID_t *timerID)
 Delete a timer object.
palStatus_t pal_osMutexCreate (palMutexID_t *mutexID)
 Create and initialize a mutex object.
palStatus_t pal_osMutexWait (palMutexID_t mutexID, uint32_t millisec)
 Wait until a mutex becomes available.
palStatus_t pal_osMutexRelease (palMutexID_t mutexID)
 Release a mutex that was obtained by `osMutexWait`.
palStatus_t pal_osMutexDelete (palMutexID_t *mutexID)
 Delete a mutex object.
palStatus_t pal_osSemaphoreCreate (uint32_t count, palSemaphoreID_t *semaphoreID)
 Create and initialize a semaphore object.
palStatus_t pal_osSemaphoreWait (palSemaphoreID_t semaphoreID, uint32_t millisec, int32_t *countersAvailable)
 Wait until a semaphore token becomes available.
palStatus_t pal_osSemaphoreRelease (palSemaphoreID_t semaphoreID)
 Release a semaphore token.
palStatus_t pal_osSemaphoreDelete (palSemaphoreID_t *semaphoreID)
 Delete a semaphore object.
int32_t pal_osAtomicIncrement (int32_t *valuePtr, int32_t increment)
 Perform an atomic increment for a signed 32-bit value.
palStatus_t pal_RTOSInitialize (void *opaqueContext)
palStatus_t pal_RTOSDestroy (void)

Detailed Description

PAL RTOS. This file contains the real-time OS APIs and is a part of the PAL service API.

Random API is also provided. as well as random API and ROT (root of trust).

Definition in file pal_rtos.h.


Typedef Documentation

typedef void(* palThreadFuncPtr)(void const *funcArgument)

PAL thread function prototype.

Definition at line 67 of file pal_rtos.h.

typedef uintptr_t palThreadID_t

Primitive ID type declarations.

Definition at line 49 of file pal_rtos.h.

Thread local store struct.

Can be used to hold, for example, state and configurations inside the thread.

Thread priority levels for PAL threads - each thread must have a different priority.

typedef void(* palTimerFuncPtr)(void const *funcArgument)

PAL timer function prototype.

Definition at line 64 of file pal_rtos.h.

Timer types supported in PAL.


Enumeration Type Documentation

Available priorities in PAL implementation, each priority can appear only once.

Enumerator:
PAL_osPriorityReservedDNS 

Reserved for PAL's internal use

PAL_osPriorityReservedSockets 

Reserved for PAL's internal use

PAL_osPriorityReservedHighResTimer 

Reserved for PAL's internal use

Definition at line 70 of file pal_rtos.h.

Timer types supported in PAL.

Enumerator:
palOsTimerOnce 

One-shot timer.

palOsTimerPeriodic 

Periodic (repeating) timer.

Definition at line 57 of file pal_rtos.h.


Function Documentation

int32_t pal_osAtomicIncrement ( int32_t *  valuePtr,
int32_t  increment 
)

Perform an atomic increment for a signed 32-bit value.

Parameters:
[in,out]valuePtrThe address of the value to increment.
[in]incrementThe number by which to increment.
Returns:
The value of `valuePtr` after the increment operation.

Definition at line 250 of file pal_rtos.c.

palStatus_t pal_osDelay ( uint32_t  milliseconds )

Wait for a specified time period in milliseconds.

Parameters:
[in]millisecondsThe number of milliseconds to wait before proceeding.
Returns:
PAL_SUCCESS(0) in case of success, and a negative value indicating a specific error code in case of failure.

Definition at line 142 of file pal_rtos.c.

uint64_t pal_osKernelSysMilliSecTick ( uint64_t  sysTicks )

Converts kernel system ticks to milliseconds.

Parameters:
[in]sysTicksThe number of kernel system ticks to convert into milliseconds.
Returns:
Converted value in milliseconds.

Definition at line 98 of file pal_rtos.c.

uint64_t pal_osKernelSysTick ( void   )

Get the RTOS kernel system timer counter.

Note:
The system needs to supply a 64-bit tick counter. If only a 32-bit counter is supported, the counter wraps around very often (for example, once every 42 sec for 100Mhz).
Returns:
The RTOS kernel system timer counter.

Definition at line 74 of file pal_rtos.c.

uint64_t pal_osKernelSysTickFrequency ( void   )

Get the system tick frequency.

Returns:
The system tick frequency.
Note:
The system tick frequency MUST be more than 1KHz. In other words, there must be at least one tick per millisecond.

Definition at line 110 of file pal_rtos.c.

uint64_t pal_osKernelSysTickMicroSec ( uint64_t  microseconds )

Converts a value from microseconds to kernel system ticks.

Parameters:
[in]microsecondsThe number of microseconds to convert into system ticks.
Returns:
Converted value in system ticks.

Definition at line 91 of file pal_rtos.c.

palStatus_t pal_osMutexCreate ( palMutexID_t *  mutexID )

Create and initialize a mutex object.

Parameters:
[out]mutexIDThe created mutex ID handle. In case of error, this value is `NULL`.
Returns:
PAL_SUCCESS when the mutex was created successfully.
PAL_ERR_NO_MEMORY when there is no memory resource available to create a mutex object.

Definition at line 185 of file pal_rtos.c.

palStatus_t pal_osMutexDelete ( palMutexID_t *  mutexID )

Delete a mutex object.

Parameters:
[in,out]mutexIDThe mutex handle to delete. On success, `*mutexID` is changed to `NULL`.
Returns:
PAL_SUCCESS when the mutex was deleted successfully.
PAL_ERR_RTOS_RESOURCE Failure - mutex is already released.
PAL_ERR_RTOS_PARAMETER Failure - mutex ID is invalid.
PAL_ERR_RTOS_ISR Failure - cannot be called from the interrupt service routines.
Note:
After this call, the `mutexID` is no longer valid and cannot be used.

Definition at line 209 of file pal_rtos.c.

palStatus_t pal_osMutexRelease ( palMutexID_t  mutexID )

Release a mutex that was obtained by `osMutexWait`.

Parameters:
[in]mutexIDThe handle for the mutex.
Returns:
PAL_SUCCESS(0) in case of success, or another negative value indicating a specific error code in case of failure.

Definition at line 201 of file pal_rtos.c.

palStatus_t pal_osMutexWait ( palMutexID_t  mutexID,
uint32_t  millisec 
)

Wait until a mutex becomes available.

Parameters:
[in]mutexIDThe handle for the mutex.
[in]millisecThe timeout for waiting for the mutex to be available. PAL_RTOS_WAIT_FOREVER can be used as a parameter.
Returns:
PAL_SUCCESS(0) in case of success.
PAL_ERR_RTOS_RESOURCE Failure - mutex was not availabe but no timeout was set.
PAL_ERR_RTOS_TIMEOUT Failure - mutex was not available before timeout.
PAL_ERR_RTOS_PARAMETER Failure - mutex ID is invalid.
PAL_ERR_RTOS_ISR Failure - cannot be called from the interrupt service routines.

Definition at line 193 of file pal_rtos.c.

void pal_osReboot ( void   )

Initiates a system reboot.

Applications can provide their own implementation by defining PAL_USE_APPLICATION_REBOOT and providing the implementation for pal_plat_osApplicationReboot() function.

Definition at line 63 of file pal_rtos.c.

palStatus_t pal_osSemaphoreCreate ( uint32_t  count,
palSemaphoreID_t *  semaphoreID 
)

Create and initialize a semaphore object.

Parameters:
[in]countThe number of available resources.
[out]semaphoreIDThe created semaphore ID handle. In case of error, this value is `NULL`.
Returns:
PAL_SUCCESS when the semaphore was created successfully.
PAL_ERR_NO_MEMORY when there is no memory resource available to create a semaphore object.

Definition at line 217 of file pal_rtos.c.

palStatus_t pal_osSemaphoreDelete ( palSemaphoreID_t *  semaphoreID )

Delete a semaphore object.

Parameters:
[in,out]semaphoreIDThe semaphore handle to delete. On success, `*semaphoreID` is changed to `NULL`.
Returns:
PAL_SUCCESS when the semaphore was deleted successfully.
PAL_ERR_RTOS_RESOURCE Failure - the semaphore was already released.
PAL_ERR_RTOS_PARAMETER Failure - the semaphore ID is invalid.
Note:
After this call, the `semaphoreID` is no longer valid and cannot be used.

Definition at line 241 of file pal_rtos.c.

palStatus_t pal_osSemaphoreRelease ( palSemaphoreID_t  semaphoreID )

Release a semaphore token.

Parameters:
[in]semaphoreIDThe handle for the semaphore
Returns:
PAL_SUCCESS(0) in case of success, or a negative value indicating a specific error code in case of failure.

Definition at line 233 of file pal_rtos.c.

palStatus_t pal_osSemaphoreWait ( palSemaphoreID_t  semaphoreID,
uint32_t  millisec,
int32_t *  countersAvailable 
)

Wait until a semaphore token becomes available.

Parameters:
[in]semaphoreIDThe handle for the semaphore.
[in]millisecThe timeout for the waiting operation. If the timeout expires before the semaphore is released, an error is returned from the function. PAL_RTOS_WAIT_FOREVER can be used.
[out]countersAvailableThe number of semaphores available at the call if a semaphore is available. If the semaphore is not available due to timeout or error, `0` is returned. This parameter can be NULL
Returns:
PAL_SUCCESS(0) in case of success.
PAL_ERR_RTOS_TIMEOUT Failure - the semaphore was not available until timeout.
PAL_ERR_RTOS_PARAMETER Failure - the semaphore ID is invalid.

Definition at line 225 of file pal_rtos.c.

palStatus_t pal_osThreadCreateWithAlloc ( palThreadFuncPtr  function,
void *  funcArgument,
palThreadPriority_t  priority,
uint32_t  stackSize,
palThreadLocalStore_t store,
palThreadID_t threadID 
)

Allocates memory for the thread stack, creates and starts the thread function inside the PAL platform wrapper function.

Parameters:
[in]functionA function pointer to the thread callback function.
[in]funcArgumentAn argument for the thread function.
[in]priorityThe priority of the thread.
[in]stackSizeThe stack size of the thread, can NOT be 0.
[in]storeMUST be `NULL` - this functionality is not supported.
[out]threadID,:The created thread ID handle. In case of error, this value is `NULL`.
Returns:
PAL_SUCCESS when the thread was created successfully.
Note:
When the priority of the created thread function is higher than the current running thread, the created thread function starts instantly and becomes the new running thread.
Calling pal_osThreadTerminate() releases the thread stack.

Definition at line 117 of file pal_rtos.c.

palThreadID_t pal_osThreadGetId ( void   )

Get the ID of the current thread.

Returns:
The ID of the current thread.
PAL_MAX_UINT32 in case of error.

Definition at line 136 of file pal_rtos.c.

palStatus_t pal_osThreadTerminate ( palThreadID_t threadID )

Terminate the thread and free the data allocated for it.

Parameters:
[in]threadIDThe thread ID to stop and terminate.
Returns:
PAL_SUCCESS(0) in case of success, and a negative value indicating a specific error code in case of failure.
Note:
pal_osThreadTerminate is a non-blocking operation. It sends a cancellation request to the thread, and usually the thread exits immediately, but the system does not always guarantee this.

Definition at line 129 of file pal_rtos.c.

palStatus_t pal_osTimerCreate ( palTimerFuncPtr  function,
void *  funcArgument,
palTimerType_t  timerType,
palTimerID_t *  timerID 
)

Create a timer.

Parameters:
[in]functionA function pointer to the timer callback function.
[in]funcArgumentAn argument for the timer callback function.
[in]timerTypeThe timer type to be created, either periodic or one-shot.
[out]timerIDThe ID handle for the created timer. In case of error, this value is `NULL`.
Returns:
PAL_SUCCESS when the timer was created successfully.
PAL_ERR_NO_MEMORY when there is no memory resource available to create a timer object.
Note:
The timer function runs according to the platform resources of stack-size and priority.

Definition at line 149 of file pal_rtos.c.

palStatus_t pal_osTimerDelete ( palTimerID_t *  timerID )

Delete a timer object.

Parameters:
[in,out]timerIDThe ID handle for the timer to delete. On success, `*timerID` is changed to `NULL`.
Returns:
PAL_SUCCESS when timer was deleted successfully.
PAL_ERR_RTOS_PARAMETER when the `timerID` is incorrect.

Definition at line 177 of file pal_rtos.c.

palStatus_t pal_osTimerStart ( palTimerID_t  timerID,
uint32_t  millisec 
)

Start or restart a timer.

Parameters:
[in]timerIDThe ID handle for the timer to start or restart.
[in]millisecThe length of time in milliseconds to set the timer to. MUST be larger than 0.
Returns:
PAL_ERR_RTOS_VALUE In case the value of millisec was 0 .
PAL_SUCCESS(0) in case of success, and a negative value indicating a specific error code in case of failure.

Definition at line 157 of file pal_rtos.c.

palStatus_t pal_osTimerStop ( palTimerID_t  timerID )

Stop a timer.

Parameters:
[in]timerIDThe ID handle for the timer to stop.
Returns:
PAL_SUCCESS(0) in case of success, and a negative value indicating a specific error code in case of failure.

Definition at line 169 of file pal_rtos.c.

palStatus_t pal_RTOSDestroy ( void   )

This function removes PAL from the system and can be called after `pal_RTOSInitialize`.

Returns:
PAL_SUCCESS upon success.
PAL_ERR_NOT_INITIALIZED - if the user did not call `pal_RTOSInitialize()` first.

Definition at line 46 of file pal_rtos.c.

palStatus_t pal_RTOSInitialize ( void *  opaqueContext )

Initialize the RTOS module for PAL. This function can be called only once before running the system. To remove PAL from the system, call `pal_RTOSDestroy`. After calling `pal_RTOSDestroy`, you can call `pal_RTOSInitialize` again.

Parameters:
[in]opaqueContext,:context to be passed to the platform if needed.
Returns:
PAL_SUCCESS upon success.

Definition at line 26 of file pal_rtos.c.