PAL
A Platform Abstraction Layer connects the mbed-client with the underlying platform.
Functions
pal_rtos.c File Reference
#include "pal_rtos.h"
#include "pal_plat_rtos.h"

Functions

void pal_osReboot (void)
 
uint32_t pal_osKernelSysTick (void)
 
uint64_t pal_osKernelSysTick64 (void)
 
uint64_t pal_osKernelSysTickMicroSec (uint64_t microseconds)
 
uint64_t pal_osKernelSysMilliSecTick (uint64_t sysTicks)
 
uint64_t pal_osKernelSysTickFrequency (void)
 
palStatus_t pal_osThreadCreate (palThreadFuncPtr function, void *funcArgument, palThreadPriority_t priority, uint32_t stackSize, uint32_t *stackPtr, palThreadLocalStore_t *store, palThreadID_t *threadID)
 
palStatus_t pal_osThreadTerminate (palThreadID_t *threadID)
 
palThreadID_t pal_osThreadGetId (void)
 
void * pal_osThreadGetLocalStore (void)
 
palStatus_t pal_osDelay (uint32_t milliseconds)
 
palStatus_t pal_osTimerCreate (palTimerFuncPtr function, void *funcArgument, palTimerType_t timerType, palTimerID_t *timerID)
 
palStatus_t pal_osTimerStart (palTimerID_t timerID, uint32_t millisec)
 
palStatus_t pal_osTimerStop (palTimerID_t timerID)
 
palStatus_t pal_osTimerDelete (palTimerID_t *timerID)
 
palStatus_t pal_osMutexCreate (palMutexID_t *mutexID)
 
palStatus_t pal_osMutexWait (palMutexID_t mutexID, uint32_t millisec)
 
palStatus_t pal_osMutexRelease (palMutexID_t mutexID)
 
palStatus_t pal_osMutexDelete (palMutexID_t *mutexID)
 
palStatus_t pal_osSemaphoreCreate (uint32_t count, palSemaphoreID_t *semaphoreID)
 
palStatus_t pal_osSemaphoreWait (palSemaphoreID_t semaphoreID, uint32_t millisec, int32_t *countersAvailable)
 
palStatus_t pal_osSemaphoreRelease (palSemaphoreID_t semaphoreID)
 
palStatus_t pal_osSemaphoreDelete (palSemaphoreID_t *semaphoreID)
 
palStatus_t pal_osPoolCreate (uint32_t blockSize, uint32_t blockCount, palMemoryPoolID_t *memoryPoolID)
 
void * pal_osPoolAlloc (palMemoryPoolID_t memoryPoolID)
 
void * pal_osPoolCAlloc (palMemoryPoolID_t memoryPoolID)
 
palStatus_t pal_osPoolFree (palMemoryPoolID_t memoryPoolID, void *block)
 
palStatus_t pal_osPoolDestroy (palMemoryPoolID_t *memoryPoolID)
 
palStatus_t pal_osMessageQueueCreate (uint32_t messageQSize, palMessageQID_t *messageQID)
 
palStatus_t pal_osMessagePut (palMessageQID_t messageQID, uint32_t info, uint32_t timeout)
 
palStatus_t pal_osMessageGet (palMessageQID_t messageQID, uint32_t timeout, uint32_t *messageValue)
 
palStatus_t pal_osMessageQueueDestroy (palMessageQID_t *messageQID)
 
int32_t pal_osAtomicIncrement (int32_t *valuePtr, int32_t increment)
 
void dbgPrintf (const char *function, uint32_t line, const char *format,...)
 

Function Documentation

void dbgPrintf ( const char *  function,
uint32_t  line,
const char *  format,
  ... 
)

Printf like function with prefix of function and line.

Parameters
[in]functionname of the current function
[in]lineline number to be printed
[in]formatprint format (just like printf)
Returns
the function returns the value of the valuePtr after the increment operation.
int32_t pal_osAtomicIncrement ( int32_t *  valuePtr,
int32_t  increment 
)

Perform an atomic increment for a signed32 bit value

Parameters
[in,out]valuePtrthe address of the value to increment
palStatus_t pal_osDelay ( uint32_t  milliseconds)

Wait for a specified time period in milliseconds.

Parameters
[in]millisecondsthe amount of milliseconds to wait before proceeding.
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure
uint64_t pal_osKernelSysMilliSecTick ( uint64_t  sysTicks)

Converts value from kernel system ticks to milliseconds.

Parameters
[in]sysTicksthe amount of kernel system ticks to convert into millieseconds
Returns
converted value in system ticks
uint32_t pal_osKernelSysTick ( void  )

Get the RTOS kernel system timer counter.

Note
this counter will wrap around very often (e.g. once every 42 sec for 100Mhz)
Returns
the RTOS kernel system timer counter
uint64_t pal_osKernelSysTick64 ( void  )

Get the RTOS kernel system timer counter.

Returns
the RTOS kernel system timer counter
uint64_t pal_osKernelSysTickFrequency ( void  )

Get the system tick frequency

Returns
the system tick frequency
uint64_t pal_osKernelSysTickMicroSec ( uint64_t  microseconds)

Converts value from microseconds to kernel sys tick

Parameters
[in]microsecondsthe amount of microseconds to convert into system ticks
Returns
converted value in system ticks
palStatus_t pal_osMessageGet ( palMessageQID_t  messageQID,
uint32_t  timeout,
uint32_t *  messageValue 
)

Get a Message or Wait for a Message from a Queue.

Parameters
[in]messageQIDthe handle for the memory pool
[in]timeouttimeout in milliseconds
[out]eventthe data to send
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and one of the following error codes in case of failure: PAL_ERR_RTOS_RESOURCE - in case semaphore was not available but not due to time out. PAL_ERR_RTOS_TIMEOUT - no message arrived during the timeout period. PAL_ERR_RTOS_RESOURCE - no message received and there was no timeout
palStatus_t pal_osMessagePut ( palMessageQID_t  messageQID,
uint32_t  info,
uint32_t  timeout 
)

Put a Message to a Queue.

Parameters
[in]messageQIDthe handle for the memory pool
[in]infothe data to send
[in]timeouttimeout in milliseconds
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure
palStatus_t pal_osMessageQueueCreate ( uint32_t  messageQSize,
palMessageQID_t messageQID 
)

Create and initialize a message queue.

Parameters
[in]messageQSizesize of the message queue.
[out]memoryPoolIDholds the created memory pool ID handle - zero value indecates an error.
Returns
PAL_SUCCESS when message queue created successfully. PAL_ERR_NO_MEMORY: no memory resource available to create message queue object.
palStatus_t pal_osMessageQueueDestroy ( palMessageQID_t messageQID)

Delete a message queue object.

Parameters
[in,out]messageQIDthe handle for the message queue, in success:(*messageQID = NULL).
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure
palStatus_t pal_osMutexCreate ( palMutexID_t mutexID)

Create and initialize Mutex object

Parameters
[out]mutexIDholds the created mutex ID handle - zero value indecates an error.
Returns
PAL_SUCCESS when mutex created successfully. PAL_ERR_NO_MEMORY: no memory resource available to create mutex object.
palStatus_t pal_osMutexDelete ( palMutexID_t mutexID)

Delete a Mutex object.

Parameters
[in,out]mutexIDMutex handle to delete, in success:(*mutexID = NULL).
Returns
PAL_SUCCESS when mutex deleted successfully. PAL_ERR_RTOS_RESOURCE - mutex already released. PAL_ERR_RTOS_PARAMETER - mutex id is invalid. PAL_ERR_RTOS_ISR - cannot be called from interrupt service routines.
Note
After this call the mutex_id is no longer valid and cannot be used.
palStatus_t pal_osMutexRelease ( palMutexID_t  mutexID)

Release a Mutex that was obtained by osMutexWait.

Parameters
[in]mutexIDthe handle for the mutex
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure
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 the waiting operation if the timeout expires before the semaphore is released and error will be returned from the function, PAL_RTOS_WAIT_FOREVER can be used.
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and one of the following error codes in case of failure: PAL_ERR_RTOS_RESOURCE - mutex not avaialbe but no time out set. PAL_ERR_RTOS_TIMEOUT - mutex was not available until timeout expired. PAL_ERR_RTOS_PARAMETER - mutex id is invalid PAL_ERR_RTOS_ISR - cannot be called from interrupt service routines
void* pal_osPoolAlloc ( palMemoryPoolID_t  memoryPoolID)

Allocate a single memory block from a memory pool.

Parameters
[in]memoryPoolIDthe handle for the memory pool
Returns
the function returns a pointer to a single allocated memory from the pool or NULL in case of failure.
void* pal_osPoolCAlloc ( palMemoryPoolID_t  memoryPoolID)

Allocate a single memory block from a memory pool and set memory block to zero.

Parameters
[in]memoryPoolIDthe handle for the memory pool
Returns
the function returns a pointer to a single allocated memory from the pool or NULL in case of failure.
palStatus_t pal_osPoolCreate ( uint32_t  blockSize,
uint32_t  blockCount,
palMemoryPoolID_t memoryPoolID 
)

Create and initialize a memory pool.

Parameters
[in]blockSizesize of single block in bytes.
[in]blockCountmaximum number of blocks in memory pool.
[out]memoryPoolIDholds the created memory pool ID handle - zero value indecates an error.
Returns
PAL_SUCCESS when memory pool created successfully. PAL_ERR_NO_MEMORY: no memory resource available to create memory pool object.
palStatus_t pal_osPoolDestroy ( palMemoryPoolID_t memoryPoolID)

Delete a memory pool object.

Parameters
[in,out]memoryPoolIDthe handle for the memory pool, in success:(*memoryPoolID = NULL).
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure
palStatus_t pal_osPoolFree ( palMemoryPoolID_t  memoryPoolID,
void *  block 
)

Return an memoryPoolID memory block back to a specific memory pool.

Parameters
[in]memoryPoolHandlethe handle for the memory pool
[in]blockthe block to free
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure
void pal_osReboot ( void  )

Initiates a system reboot

palStatus_t pal_osSemaphoreCreate ( uint32_t  count,
palSemaphoreID_t semaphoreID 
)

Create and initialize a Semaphore object

Parameters
[in]countnumber of available resources
[out]semaphoreIDholds the created semaphore ID handle - zero value indecates an error.
Returns
PAL_SUCCESS when semaphore created successfully. PAL_ERR_NO_MEMORY: no memory resource available to create semaphore object.
palStatus_t pal_osSemaphoreDelete ( palSemaphoreID_t semaphoreID)

Delete a Semaphore object

Parameters
[in,out]semaphoreIDSemaphore handle to delete, in success:(*semaphoreID = NULL).
Returns
PAL_SUCCESS when semaphore deleted successfully. PAL_ERR_RTOS_RESOURCE - semaphore already released. PAL_ERR_RTOS_PARAMETER - semaphore id is invalid.
Note
After this call the semaphore_id is no longer valid and cannot be used.
palStatus_t pal_osSemaphoreRelease ( palSemaphoreID_t  semaphoreID)

Release a Semaphore token.

Parameters
[in]semaphoreIDthe handle for the semaphore
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure
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 and error will be returned from the function, PAL_RTOS_WAIT_FOREVER can be used.
[out]counteresAvailablethe number of semaphore available at the call if semaphore is available, if semaphore was not available (timeout/error) zero is returned.
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and one of the following error codes in case of failure: PAL_ERR_RTOS_TIMEOUT - semaphore was not available until timeout expired. PAL_ERR_RTOS_PARAMETER - semaphore id is invalid.
palStatus_t pal_osThreadCreate ( palThreadFuncPtr  function,
void *  funcArgument,
palThreadPriority_t  priority,
uint32_t  stackSize,
uint32_t *  stackPtr,
palThreadLocalStore_t store,
palThreadID_t threadID 
)

Creates and starts thread function.

Parameters
[in]functionfunction pointer to the thread callback function.
[in]funcArgumentargument for the thread function.
[in]prioritypriotity of the thread.
[in]stackSizethe stack size of the thread can NOT be 0.
[in]stackPtrpointer to the thread's stack can NOT be NULL.
[in]storepointer to thread's local sotre, can be NULL.
[out]threadIDholds the created thread ID handle - zero value indecates an error.
Returns
PAL_SUCCESS when thread created successfully. PAL_ERR_RTOS_PRIORITY : the given priority already used before in the system.
Note
Each thread MUST be with unique priority.
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.
palThreadID_t pal_osThreadGetId ( void  )

Get ID of the current thread

Returns
the ID of the current thread - in case of error return PAL_MAX_UINT32
Note
for thread with Real Time priority the function will always return PAL_MAX_UINT32
void* pal_osThreadGetLocalStore ( void  )

Get the storage of current thread

Returns
the storage of the current thread
palStatus_t pal_osThreadTerminate ( palThreadID_t threadID)

Terminates and free allocated data for the thread.

Parameters
[in]threadIDthread ID to stop and terminate.
Returns
palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure PAL_ERR_RTOS_RESOURCE: if the thread ID is not correct.
palStatus_t pal_osTimerCreate ( palTimerFuncPtr  function,
void *  funcArgument,
palTimerType_t  timerType,
palTimerID_t timerID 
)

Creates a Timer.

Parameters
[in]functionfunction pointer to the timer callback function.
[in]funcArgumentfuncArgument for the timer callback function.
[in]timerTypetimer type to be created - (periodic or oneShot).
[out]timerIDholds the created timer ID handle - zero value indecates an error.
Returns
PAL_SUCCESS when timer created successfully. PAL_ERR_NO_MEMORY: no memory resource available to create timer object.
Note
the timer function runs according to the platform resources of stack-size and priority.
palStatus_t pal_osTimerDelete ( palTimerID_t timerID)

Delete the timer object

Parameters
[in,out]timerIDthe handle for the timer to delete, in success:(*timerID = NULL).
Returns
PAL_SUCCESS when timer deleted successfully. PAL_ERR_RTOS_PARAMETER when timerID is incorrect.
palStatus_t pal_osTimerStart ( palTimerID_t  timerID,
uint32_t  millisec 
)

Start or restart a timer.

Parameters
[in]timerIDthe handle for the timer to start
[in]millisecthe amount of time in milliseconds to set the timer to.
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure
palStatus_t pal_osTimerStop ( palTimerID_t  timerID)

Stop a timer.

Parameters
[in]timerIDthe handle for the timer to stop
Returns
the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure