Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
OS Abstraction Layer (OSA)

The Kinetis SDK provides the timer services for all OSA layers. More...

Overview

Modules

 Bare Metal Abstraction Layer
 The Kinetis SDK provides the Bare Metal Abstraction Layer for synchronization, mutual exclusion, message queue, etc.
 
 FreeRTOS Abstraction Layer
 The Kinetis SDK provides the FreeRTOS Abstraction Layer for synchronization, mutual exclusion, message queue, etc.
 
 MQX RTOS Abstraction Layer
 The Kinetis SDK provides the MQX RTOS Abstraction Layer for synchronization, mutual exclusion, message queue, etc.
 
 µC/OS-II Abstraction Layer
 The Kinetis SDK provides the µC/OS-II Abstraction Layer for synchronization, mutual exclusion, message queue, etc.
 
 µC/OS-III Abstraction Layer
 The Kinetis SDK provides the µC/OS-III Abstraction Layer for synchronization, mutual exclusion, message queue, etc.
 

Typedefs

typedef void(* osa_int_handler_t )(void)
 OSA interrupt handler. More...
 

Enumerations

enum  osa_status_t {
  kStatus_OSA_Success = 0U,
  kStatus_OSA_Error = 1U,
  kStatus_OSA_Timeout = 2U,
  kStatus_OSA_Idle = 3U
}
 Defines the return status of OSA's functions. More...
 
enum  osa_event_clear_mode_t {
  kEventAutoClear = 0U,
  kEventManualClear = 1U
}
 The event flags are cleared automatically or manually. More...
 
enum  osa_critical_section_mode_t {
  kCriticalLockSched = 0U,
  kCriticalDisableInt = 1U
}
 Locks the task scheduler or disables interrupt in critical section. More...
 

Counting Semaphore

osa_status_t OSA_SemaCreate (semaphore_t *pSem, uint8_t initValue)
 Creates a semaphore with a given value. More...
 
osa_status_t OSA_SemaWait (semaphore_t *pSem, uint32_t timeout)
 Pending a semaphore with timeout. More...
 
osa_status_t OSA_SemaPost (semaphore_t *pSem)
 Signals for someone waiting on the semaphore to wake up. More...
 
osa_status_t OSA_SemaDestroy (semaphore_t *pSem)
 Destroys a previously created semaphore. More...
 

Mutex

osa_status_t OSA_MutexCreate (mutex_t *pMutex)
 Create an unlocked mutex. More...
 
osa_status_t OSA_MutexLock (mutex_t *pMutex, uint32_t timeout)
 Waits for a mutex and locks it. More...
 
osa_status_t OSA_MutexUnlock (mutex_t *pMutex)
 Unlocks a previously locked mutex. More...
 
osa_status_t OSA_MutexDestroy (mutex_t *pMutex)
 Destroys a previously created mutex. More...
 

Event signalling

osa_status_t OSA_EventCreate (event_t *pEvent, osa_event_clear_mode_t clearMode)
 Initializes an event object with all flags cleared. More...
 
osa_status_t OSA_EventWait (event_t *pEvent, event_flags_t flagsToWait, bool waitAll, uint32_t timeout, event_flags_t *setFlags)
 Waits for specified event flags to be set. More...
 
osa_status_t OSA_EventSet (event_t *pEvent, event_flags_t flagsToSet)
 Sets one or more event flags. More...
 
osa_status_t OSA_EventClear (event_t *pEvent, event_flags_t flagsToClear)
 Clears one or more flags. More...
 
event_flags_t OSA_EventGetFlags (event_t *pEvent)
 Gets event flags status. More...
 
osa_status_t OSA_EventDestroy (event_t *pEvent)
 Destroys a previously created event object. More...
 

Task management

osa_status_t OSA_TaskCreate (task_t task, uint8_t *name, uint16_t stackSize, task_stack_t *stackMem, uint16_t priority, task_param_t param, bool usesFloat, task_handler_t *handler)
 Creates a task. More...
 
osa_status_t OSA_TaskDestroy (task_handler_t handler)
 Destroys a previously created task. More...
 
osa_status_t OSA_TaskYield (void)
 Puts the active task to the end of scheduler's queue. More...
 
task_handler_t OSA_TaskGetHandler (void)
 Gets the handler of active task. More...
 
uint16_t OSA_TaskGetPriority (task_handler_t handler)
 Gets the priority of a task. More...
 
osa_status_t OSA_TaskSetPriority (task_handler_t handler, uint16_t priority)
 Sets the priority of a task. More...
 

Message queues

msg_queue_handler_t OSA_MsgQCreate (msg_queue_t *queue, uint16_t message_number, uint16_t message_size)
 Initializes a message queue. More...
 
osa_status_t OSA_MsgQPut (msg_queue_handler_t handler, void *pMessage)
 Puts a message at the end of the queue. More...
 
osa_status_t OSA_MsgQGet (msg_queue_handler_t handler, void *pMessage, uint32_t timeout)
 Reads and remove a message at the head of the queue. More...
 
osa_status_t OSA_MsgQDestroy (msg_queue_handler_t handler)
 Destroys a previously created queue. More...
 

Memory Management

void * OSA_MemAlloc (size_t size)
 Reserves the requested amount of memory in bytes. More...
 
void * OSA_MemAllocZero (size_t size)
 Reserves the requested amount of memory in bytes and initializes it to 0. More...
 
osa_status_t OSA_MemFree (void *ptr)
 Releases the memory previously reserved. More...
 

Time management

void OSA_TimeDelay (uint32_t delay)
 Delays execution for a number of milliseconds. More...
 
uint32_t OSA_TimeGetMsec (void)
 Gets the current time since system boot in milliseconds. More...
 

Interrupt management

osa_int_handler_t OSA_InstallIntHandler (int32_t IRQNumber, osa_int_handler_t handler)
 Installs the interrupt handler. More...
 

Critical section

void OSA_EnterCritical (osa_critical_section_mode_t mode)
 Enters the critical section to ensure some code is not preempted. More...
 
void OSA_ExitCritical (osa_critical_section_mode_t mode)
 Exits the critical section. More...
 

OSA initialize

osa_status_t OSA_Init (void)
 Initializes the RTOS services. More...
 
osa_status_t OSA_Start (void)
 Starts the RTOS. More...
 

OS Abstraction Layer

Overview

Operating System Abstraction layer (OSA) provides a common set of services for drivers and applications so that they can work with or without the operating system. OSA provides services that abstract most of the OS kernel functionality. These services can either be mapped to the target OS functions directly, or implemented by OSA when no OS is used (bare metal) or when the service does not exist in the target OS. Freescale Kinetis SDK implements the OS abstraction layer for MQX™ RTOS, Free RTOS, µC/OS, and for OS-less usage (bare metal). The bare metal OS abstraction implementation is selected as the default option.
OSA provides these services: task management, semaphore, mutex, event, message queue, memory allocator, critical section, and time functions.

Task Management

With OSA, applications can create and destroy tasks dynamically. These services are mapped to the task functions of RTOSes. For bare metal, a function poll mechanism simulates a task scheduler.
OSA supports task priorities 0~15, where priority 0 is the highest priority and priority 15 is the lowest priority.
To create a task, applications must prepare different resources on different RTOSes. For example, µC/OS-II and µC/OS-III need pre-allocated task stack while other RTOSes do not need this. The µC/OS-III needs pre-allocated task control block OS_TCB while other RTOSes do not. To mask the differences, OSA uses a macro OSA_TASK_DEFINE to prepare resources for task creation. Then the function OSA_TaskCreate() creates a task based on the resources. This method makes it easy to use a copy of code on different RTOSes. However, it is not mandatory to use the OSA_TASK_DEFINE. Applications can also prepare the resources manually. There are two methods to create a task:

  1. Use the OSA_TASK_DEFINE macro and the function OSA_TaskCreate(). The macro OSA_TASK_DEFINE declares a task handler and task stack statically. The function OSA_TaskCreate() creates task base-on the resources declared by OSA_TASK_DEFINE.
    This is an example code to create a task using method 1:
    // Define the task with entry function task_func.
    OSA_TASK_DEFINE(task_func, TASK_STACK_SIZE);
    void main(void)
    {
    task_param_t parameter;
    // Create the task.
    OSA_TaskCreate(task_func, // Task function.
    "my_task", // Task name.
    TASK_STACK_SIZE, // Stack size.
    task_func_stack, // Stack address.
    TASK_PRIO, // Task priority.
    parameter, // Parameter.
    false, // Use float register or not.
    &task_func_task_handler); // Task handler.
    // ...
    }
  2. Prepare resources manually, then use the function OSA_TaskCreate() to create a task.
    For example:
    task_param_t parameter;
    task_handler_t task_handler;
    #if defined(FSL_RTOS_UCOSII)
    task_stack_t task_stack[TASK_STACK_SIZE/sizeof(task_stack_t)];
    OSA_TaskCreate(task_func, // Task function.
    "my_task", // Task name.
    TASK_STACK_SIZE, // Stack size.
    task_stack, // Stack address.
    TASK_PRIO, // Task priority.
    parameter, // Parameter.
    false, // Use float register or not.
    &task_handler); // Task handler.
    #elif defined(FSL_RTOS_UCOSIII)
    task_stack_t task_stack[TASK_STACK_SIZE/sizeof(task_stack_t)];
    OS_TCB TCB_task;
    task_handler = &TCB_task;
    OSA_TaskCreate(task_func, // Task function.
    "my_task", // Task name.
    TASK_STACK_SIZE, // Stack size.
    task_stack, // Stack address.
    TASK_PRIO, // Task priority.
    parameter, // Parameter.
    false, // Use float register or not.
    &task_handler); // Task handler.
    #else // For MQX RTOS, FreeRTOS OS and bare metal.
    OSA_TaskCreate(task_func, // Task function.
    "my_task", // Task name.
    TASK_STACK_SIZE, // Stack size.
    NULL, // Stack address.
    TASK_PRIO, // Task priority.
    parameter, // Parameter.
    false, // Use float register or not.
    &task_handler); // Task handler.
    #endif
Method one is easy to use. The disadvantage is that one task function can only create one task instance. Method two can create multiple task instances using one task function, but the code must be divided by macros for different RTOSes. Applications can choose either method according to requirements.
After a task is created successfully, task handler can be used to manage the task, for example, get or set task priority, destroy task and so on.If task is not used any more, use the OSA_TaskDestroy() function to destroy the task. If the task function does not contain an infinite loop, or, in other words, the task function returns, call the OSA_TaskDestroy() function at the end of the task function.

Semaphore

The OSA provides the drivers and applications with a counting semaphore. It can be used either to synchronize tasks or to synchronize a task and an ISR.
A semaphore must be initialized with the OSA_SemaCreate() function before using. The semaphore can be initialized with an initial value. When the semaphore is not used any more, use the OSA_SemaDestroy() function to destroy it.
Note that if multiple tasks are waiting for one semaphore, different RTOSes may have different behaviors, for example, wake up the task wait first or wake up the task with highest priority. Bare metal semaphore does not support multiple tasks wait with timeout.
This is an example code to create and destroy a semaphore:
// Initialize the semaphore with initial value.
OSA_SemaCreate(&sem, 0);
// Destroy the semaphore.
The function OSA_SemaWait() waits a semaphore within the timeout (in milliseconds). Passing a value 0 as a timeout means return immediately and passing the OSA_WAIT_FOREVER means wait indefinitely. This function should not be used in the ISR.
The function OSA_SemaPost() wakes up task which is waiting for the semaphore.

Mutex

A mutex is used for the mutual exclusion of tasks when they access a shared resource. OSA provides a non-recursive mutex, which means a task cannot try to lock a mutex it has already locked.
A mutex must be initialized to an unlocked status with the OSA_MutexCreate() function before using. When the mutex is not used any more, use the OSA_MutexDestroy() function to destroy it.
This is example code to create and destroy a mutex:
mutex_t mutex;
// Initialize the mutex
// Destroy the mutex
The function OSA_MutexLock() waits to lock a mutex within the timeout (in milliseconds). Passing a value 0 as a timeout means return immediately and passing the OSA_WAIT_FOREVER means waiting indefinitely.
The function OSA_MutexUnlock() unlocks a mutex which is locked by the current task.

Event

When using event, notice that if multiple tasks are waiting on one event, different RTOSes may have different behaviors. For example, only the first task in waiting list is woken up, or all tasks in waiting list are woken up. Bare metal event does not support multiple task waiting with timeout.
OSA provides two types of events:

  1. Auto-clear, which occurs when some task has get flags it is waiting for. These flags are cleared automatically.
  2. Manual-clear, which means that the flags could only be cleared manually.
The clear mode is a property of an event. After an event is created, the clear mode can't be changed.
An event must be initialized with the OSA_EventCreate() function before using. When it is created, its flags are all cleared. When the event is not used any more, use the event_destory() function to destroy it.
This is example code to create and destroy an event object:
event_t event;
// Initialize the event
// Destroy the event
The function OSA_EventWait() waits for specified flags of an event with the timeout (in milliseconds). Passing a value 0 as a timeout means return immediately and passing the OSA_WAIT_FOREVER means wait indefinitely. This function can be configured to wait for all specified flags or wait for any one flag in specified flags. The parameter setFlags saves the flags which wake up the waiting task. This function should not be used in the ISR.
The functions OSA_EventSet() and OSA_EventClear() are used to set and clear specified flags of an event. The function OSA_EventGetFlags() is used to get current event flags.

Message Queue

OSA provides the FIFO message queue. All messages in a queue have the same size. Message queue holds an internal memory area to save messages. While putting the message, the message entity is copied to this internal memory area. While getting message, message is copied from the internal memory area.
Note that if multiple tasks are waiting on one message queue, different RTOSes may have different behaviors. Bare metal message queue does not support multiple task waiting with timeout.
To create a message queue, use MSG_QUEUE_DECLARE() and OSA_MsgQCreate() functions as shown here:
// Declare the message queue.
MSG_QUEUE_DECLARE(my_message, msg_num, msg_size);
void main(void)
{
handler = OSA_MsgQCreate(my_message, msg_num, msg_size);
// ...
}
Note that the parameter message_size is in words and not in bytes. It means that the message queue can only transfer messages of multiple-byte size.
The function OSA_MsgQPut() puts a message to the queue. If the queue is full, an error returns.
The function OSA_MsgQGet() waits for a timeout in milliseconds to get the message from the queue. Passing a value 0 as a timeout means return immediately and passing the OSA_WAIT_FOREVER means wait indefinitely. This function should not be used in the ISR.
If the queue is not used any more, use the OSA_MsgQDestroy() function to destroy it.

Critical Section

OSA provides two types of critical sections. The first type disables the interrupt while the second type only disables the scheduler to stop the task preemption.

Memory Allocator

The function OSA_MemAlloc() allocates memory with specified size. The function OSA_MemAllocZero() allocates and cleans the memory. The function OSA_MemFree() frees the memory. For RTOSes that have internal memory manager, such as the MQX RTOS, OSA maps these functions directly. For other RTOSes or bare metal, the standard functions malloc/calloc/free are used.

Time Functions

OSA only provides two time functions, OSA_TimeDelay() and OSA_TimeGetMsec(). The function OSA_TimeDelay() delays specified time in milliseconds, while the function OSA_TimeGetMsec() gets the system time in milliseconds since POR.

Interrupt priority

For some RTOSes, a proper interrupt priority must be set if system services are called in this interrupt service routine.
For MQX RTOS, follow these criteria:

  1. Interrupt priority must be an even number.
  2. Interrupt priority >= 2*MQX_HARDWARE_INTERRUPT_LEVEL_MAX.
For FreeRTOS OS, the interrupt priority is defined in the configuration file FreeRTOSConfig.h. In the current configuration, priority 1~15 can be used for the ARM Cortex®-M4. See the FreeRTOS OS' official documents for details.

OSA initialization

To initialize and start RTOSes, OSA uses abstract functions OSA_Init() and OSA_Start(). Call OSA_Init() after calling hardware_init().This example shows how to use OSA_Init() and OSA_Start() functions:
#include <fsl_os_abstraction.h>
void task_func(task_param_t param)
{
//...
}
OSA_TASK_DEFINE(task_func, 512);
#if defined(FSL_RTOS_MQX)
void Main_Task(uint32_t param);
TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
{ 1L, Main_Task, 256L, MQX_MAIN_TASK_PRIORITY, "Main", MQX_AUTO_START_TASK},
{ 0L, 0L, 0L, 0L, 0L, 0L }
};
#endif
#if defined(FSL_RTOS_MQX)
void Main_Task(uint32_t param)
#else
void main(void)
#endif
{
hardware_init();
// Other application initialization functions.
// ...
OSA_TaskCreate(task_func, // Task function.
"my_task", // Task name.
512, // Stack size.
task_func_stack, // Stack address.
5, // Task priority.
(task_param_t)0, // Parameter.
false, // Use float register or not.
&task_func_task_handler); // Task handler.
}
Note that, for other RTOSes, the task scheduler is started up by the OSA_Start() function. However, for MQX RTOS, the task scheduler is started before the OSA_Init() function call. When creating tasks in the Main_Task() function with the MQX RTOS, the newly created task runs immediately if it has the highest priority. However, for other RTOSes, all newly created tasks do not run until the OSA_Start() function executes.

Typedef Documentation

typedef void(* osa_int_handler_t)(void)

Enumeration Type Documentation

Enumerator
kStatus_OSA_Success 

Success.

kStatus_OSA_Error 

Failed.

kStatus_OSA_Timeout 

Timeout occurs while waiting.

kStatus_OSA_Idle 

Used for bare metal only, the wait object is not ready and timeout still not occur.

Enumerator
kEventAutoClear 

The flags of the event will be cleared automatically.

kEventManualClear 

The flags of the event will be cleared manually.

Enumerator
kCriticalLockSched 

Lock scheduler in critical section.

kCriticalDisableInt 

Disable interrupt in critical selection.

Function Documentation

osa_status_t OSA_SemaCreate ( semaphore_t pSem,
uint8_t  initValue 
)

This function creates a semaphore and sets the value to the parameter initValue.

Parameters
pSemPointer to the semaphore.
initValueInitial value the semaphore will be set to.
Return values
kStatus_OSA_SuccessThe semaphore is created successfully.
kStatus_OSA_ErrorThe semaphore cannot be created.

Example:

OSA_SemaCreate(&mySem, 0);
osa_status_t OSA_SemaWait ( semaphore_t pSem,
uint32_t  timeout 
)

This function checks the semaphore's counting value. If it is positive, decreases it and returns kStatus_OSA_Success. Otherwise, a timeout is used to wait.

Parameters
pSemPointer to the semaphore.
timeoutThe maximum number of milliseconds to wait if semaphore is not positive. Pass OSA_WAIT_FOREVER to wait indefinitely, pass 0 will return kStatus_OSA_Timeout immediately.
Return values
kStatus_OSA_SuccessThe semaphore is received.
kStatus_OSA_TimeoutThe semaphore is not received within the specified 'timeout'.
kStatus_OSA_ErrorAn incorrect parameter was passed.
kStatus_OSA_IdleThe semaphore is not available and 'timeout' is not exhausted, This is only for bare metal.
Note
With bare metal, a semaphore cannot be waited on by more than one task at the same time.

Example:

osa_status_t status;
status = OSA_SemaWait(&mySem, 100);
switch(status)
{
//...
}
osa_status_t OSA_SemaPost ( semaphore_t pSem)

Wakes up one task that is waiting on the semaphore. If no task is waiting, increases the semaphore's counting value.

Parameters
pSemPointer to the semaphore to signal.
Return values
kStatus_OSA_SuccessThe semaphore is successfully signaled.
kStatus_OSA_ErrorThe object cannot be signaled or invalid parameter.

Example:

osa_status_t status;
status = OSA_SemaPost(&mySem);
switch(status)
{
//...
}
osa_status_t OSA_SemaDestroy ( semaphore_t pSem)
Parameters
pSemPointer to the semaphore to destroy.
Return values
kStatus_OSA_SuccessThe semaphore is successfully destroyed.
kStatus_OSA_ErrorThe semaphore cannot be destroyed.

Example:

osa_status_t status;
status = OSA_SemaDestroy(&mySem);
switch(status)
{
//...
}
osa_status_t OSA_MutexCreate ( mutex_t pMutex)

This function creates a non-recursive mutex and sets it to unlocked status.

Parameters
pMutexPointer to the Mutex.
Return values
kStatus_OSA_SuccessThe mutex is created successfully.
kStatus_OSA_ErrorThe mutex cannot be created.

Example:

mutex_t myMutex;
osa_status_t status;
status = OSA_MutexCreate(&myMutex);
switch (status)
{
//...
}
osa_status_t OSA_MutexLock ( mutex_t pMutex,
uint32_t  timeout 
)

This function checks the mutex's status. If it is unlocked, locks it and returns the kStatus_OSA_Success. Otherwise, waits for a timeout in milliseconds to lock.

Parameters
pMutexPointer to the Mutex.
timeoutThe maximum number of milliseconds to wait for the mutex. If the mutex is locked, Pass the value OSA_WAIT_FOREVER will wait indefinitely, pass 0 will return kStatus_OSA_Timeout immediately.
Return values
kStatus_OSA_SuccessThe mutex is locked successfully.
kStatus_OSA_TimeoutTimeout occurred.
kStatus_OSA_ErrorIncorrect parameter was passed.
kStatus_OSA_IdleThe mutex is not available and 'timeout' is not exhausted, This is only for bare metal.
Note
This is non-recursive mutex, a task cannot try to lock the mutex it has locked.

Example:

osa_status_t status;
status = OSA_MutexLock(&myMutex, 100);
switch (status)
{
//...
}
osa_status_t OSA_MutexUnlock ( mutex_t pMutex)
Parameters
pMutexPointer to the Mutex.
Return values
kStatus_OSA_SuccessThe mutex is successfully unlocked.
kStatus_OSA_ErrorThe mutex cannot be unlocked or invalid parameter.

Example:

osa_status_t status;
status = OSA_MutexUnlock(&myMutex);
switch (status)
{
//...
}
osa_status_t OSA_MutexDestroy ( mutex_t pMutex)
Parameters
pMutexPointer to the Mutex.
Return values
kStatus_OSA_SuccessThe mutex is successfully destroyed.
kStatus_OSA_ErrorThe mutex cannot be destroyed.

Example:

osa_status_t status;
status = OSA_MutexDestroy(&myMutex);
switch (status)
{
//...
}
osa_status_t OSA_EventCreate ( event_t pEvent,
osa_event_clear_mode_t  clearMode 
)

This function creates an event object and set its clear mode. If clear mode is kEventAutoClear, when a task gets the event flags, these flags will be cleared automatically. If clear mode is kEventManualClear, these flags must be cleared manually.

Parameters
pEventPointer to the event object to initialize.
clearModeThe event is auto-clear or manual-clear.
Return values
kStatus_OSA_SuccessThe event object is successfully created.
kStatus_OSA_ErrorThe event object is not created.

Example:

osa_status_t OSA_EventWait ( event_t pEvent,
event_flags_t  flagsToWait,
bool  waitAll,
uint32_t  timeout,
event_flags_t setFlags 
)

This function waits for a combination of flags to be set in an event object. Applications can wait for any/all bits to be set. Also this function could obtain the flags who wakeup the waiting task.

Parameters
pEventPointer to the event.
flagsToWaitFlags that to wait.
waitAllWait all flags or any flag to be set.
timeoutThe maximum number of milliseconds to wait for the event. If the wait condition is not met, pass OSA_WAIT_FOREVER will wait indefinitely, pass 0 will return kStatus_OSA_Timeout immediately.
setFlagsFlags that wakeup the waiting task are obtained by this parameter.
Return values
kStatus_OSA_SuccessThe wait condition met and function returns successfully.
kStatus_OSA_TimeoutHas not met wait condition within timeout.
kStatus_OSA_ErrorAn incorrect parameter was passed.
kStatus_OSA_IdleThe wait condition is not met and 'timeout' is not exhausted, This is only for bare metal.
Note
1. With bare metal, a event object cannot be waited on by more than one tasks at the same time.
  1. Please pay attention to the flags bit width, FreeRTOS uses the most significant 8 bis as control bits, so do not wait these bits while using FreeRTOS.

Example:

osa_status_t status;
event_flags_t setFlags;
status = OSA_EventWait(&myEvent, 0x01, true, 100, &setFlags);
switch (status)
{
//...
}
osa_status_t OSA_EventSet ( event_t pEvent,
event_flags_t  flagsToSet 
)

Sets specified flags of an event object.

Parameters
pEventPointer to the event.
flagsToSetFlags to be set.
Return values
kStatus_OSA_SuccessThe flags were successfully set.
kStatus_OSA_ErrorAn incorrect parameter was passed.

Example:

osa_status_t status;
status = OSA_EventSet(&myEvent, 0x01);
switch (status)
{
//...
}
osa_status_t OSA_EventClear ( event_t pEvent,
event_flags_t  flagsToClear 
)

Clears specified flags of an event object.

Parameters
pEventPointer to the event.
flagsToClearFlags to be clear.
Return values
kStatus_OSA_SuccessThe flags were successfully cleared.
kStatus_OSA_ErrorAn incorrect parameter was passed.

Example:

osa_status_t status;
status = OSA_EventClear(&myEvent, 0x01);
switch (status)
{
//...
}
event_flags_t OSA_EventGetFlags ( event_t pEvent)

Gets the event flags status.

Parameters
pEventPointer to the event.
Returns
event_flags_t Current event flags.

Example:

flags = OSA_EventGetFlags(&myEvent);
osa_status_t OSA_EventDestroy ( event_t pEvent)
Parameters
pEventPointer to the event.
Return values
kStatus_OSA_SuccessThe event is successfully destroyed.
kStatus_OSA_ErrorEvent destruction failed.

Example:

osa_status_t status;
status = OSA_EventDestroy(&myEvent);
switch (status)
{
//...
}
osa_status_t OSA_TaskCreate ( task_t  task,
uint8_t *  name,
uint16_t  stackSize,
task_stack_t stackMem,
uint16_t  priority,
task_param_t  param,
bool  usesFloat,
task_handler_t handler 
)

This function is used to create task based on the resources defined by the macro OSA_TASK_DEFINE.

Parameters
taskThe task function entry.
nameThe name of this task.
stackSizeThe stack size in byte.
stackMemPointer to the stack.
priorityInitial priority of the task.
paramPointer to be passed to the task when it is created.
usesFloatThis task will use float register or not.
handlerPointer to the task handler.
Return values
kStatus_OSA_SuccessThe task is successfully created.
kStatus_OSA_ErrorThe task cannot be created..

Example:

osa_status_t status;
OSA_TASK_DEFINE(task_func, stackSize);
status = OSA_TaskCreate(task_func,
"task_name",
stackSize,
task_func_stack,
prio,
param,
false,
&task_func_task_handler);
switch (status)
{
//...
}
Note
Use the return value to check whether the task is created successfully. DO NOT check handler. For uC/OS-III, handler is not NULL even if the task creation has failed.
osa_status_t OSA_TaskDestroy ( task_handler_t  handler)
Parameters
handlerThe handler of the task to destroy. Returned by the OSA_TaskCreate function.
Return values
kStatus_OSA_SuccessThe task was successfully destroyed.
kStatus_OSA_ErrorTask destruction failed or invalid parameter.

Example:

osa_status_t status;
status = OSA_TaskDestroy(myTaskHandler);
switch (status)
{
//...
}
osa_status_t OSA_TaskYield ( void  )

When a task calls this function, it gives up the CPU and puts itself to the end of a task ready list.

Return values
kStatus_OSA_SuccessThe function is called successfully.
kStatus_OSA_ErrorError occurs with this function.

Example:

osa_status_t status;
status = OSA_TaskYield();
switch (status)
{
//...
}
task_handler_t OSA_TaskGetHandler ( void  )
Returns
Handler to current active task.

Example:

uint16_t OSA_TaskGetPriority ( task_handler_t  handler)
Parameters
handlerThe handler of the task whose priority is received.
Returns
Task's priority.

Example:

uint16_t taskPrio = OSA_TaskGetPriority(taskHandler);
osa_status_t OSA_TaskSetPriority ( task_handler_t  handler,
uint16_t  priority 
)
Parameters
handlerThe handler of the task whose priority is received.
priorityThe priority to set.
Return values
kStatus_OSA_SuccessTask's priority is set successfully.
kStatus_OSA_ErrorTask's priority cannot be set.

Example:

osa_status_t status;
status = OSA_TaskSetPriority(taskHandler, newPrio);
switch (status)
{
//...
}
msg_queue_handler_t OSA_MsgQCreate ( msg_queue_t queue,
uint16_t  message_number,
uint16_t  message_size 
)

This function initializes the message queue that was declared previously. This is an example demonstrating the use of the function:

MSG_QUEUE_DECLARE(my_message, msg_num, msg_size);
handler = OSA_MsgQCreate(my_message, msg_num, msg_size);
Parameters
queueThe queue declared through the MSG_QUEUE_DECLARE macro.
message_numberThe number of elements in the queue.
message_sizeSize of every elements in words.
Returns
Handler to access the queue for put and get operations. If message queue created failed, return 0.
osa_status_t OSA_MsgQPut ( msg_queue_handler_t  handler,
void *  pMessage 
)

This function puts a message to the end of the message queue. If the queue is full, this function returns the kStatus_OSA_Error;

Parameters
handlerQueue handler returned by the OSA_MsgQCreate function.
pMessagePointer to the message to be put into the queue.
Return values
kStatus_OSA_SuccessMessage successfully put into the queue.
kStatus_OSA_ErrorThe queue was full or an invalid parameter was passed.

Example:

osa_status_t status;
struct MESSAGE messageToPut = ...;
status = OSA_MsgQPut(queueHandler, &messageToPut);
switch (status)
{
//...
}
osa_status_t OSA_MsgQGet ( msg_queue_handler_t  handler,
void *  pMessage,
uint32_t  timeout 
)

This function gets a message from the head of the message queue. If the queue is empty, timeout is used to wait.

Parameters
handlerQueue handler returned by the OSA_MsgQCreate function.
pMessagePointer to a memory to save the message.
timeoutThe number of milliseconds to wait for a message. If the queue is empty, pass OSA_WAIT_FOREVER will wait indefinitely, pass 0 will return kStatus_OSA_Timeout immediately.
Return values
kStatus_OSA_SuccessMessage successfully obtained from the queue.
kStatus_OSA_TimeoutThe queue remains empty after timeout.
kStatus_OSA_ErrorInvalid parameter.
kStatus_OSA_IdleThe queue is empty and 'timeout' is not exhausted, This is only for bare metal.
Note
With bere metal, there should be only one process waiting on the queue.

Example:

osa_status_t status;
struct MESSAGE messageToGet;
status = OSA_MsgQGet(queueHandler, &messageToGet, 100);
switch (status)
{
//...
}
osa_status_t OSA_MsgQDestroy ( msg_queue_handler_t  handler)
Parameters
handlerQueue handler returned by the OSA_MsgQCreate function.
Return values
kStatus_OSA_SuccessThe queue was successfully destroyed.
kStatus_OSA_ErrorMessage queue destruction failed.

Example:

osa_status_t status;
status = OSA_MsgQDestroy(queueHandler);
switch (status)
{
//...
}
void* OSA_MemAlloc ( size_t  size)
Parameters
sizeAmount of bytes to reserve.
Returns
Pointer to the reserved memory. NULL if memory could not be allocated.
void* OSA_MemAllocZero ( size_t  size)
Parameters
sizeAmount of bytes to reserve.
Returns
Pointer to the reserved memory. NULL if memory could not be allocated.
osa_status_t OSA_MemFree ( void *  ptr)
Parameters
ptrPointer to the start of the memory block previously reserved.
Return values
kStatus_OSA_SuccessMemory correctly freed.
kStatus_OSA_ErrorError occurs during free the memory.
void OSA_TimeDelay ( uint32_t  delay)
Parameters
delayThe time in milliseconds to wait.
uint32_t OSA_TimeGetMsec ( void  )
Returns
Current time in milliseconds.
osa_int_handler_t OSA_InstallIntHandler ( int32_t  IRQNumber,
osa_int_handler_t  handler 
)
Parameters
IRQNumberIRQ number of the interrupt.
handlerThe interrupt handler to install.
Returns
This function returns the old interrupt handler installed in vector table. If could not install ISR, this function returns NULL; The return value could be compared with OSA_DEFAULT_INT_HANDLER to detect whether this is the first interrupt handler installed.
void OSA_EnterCritical ( osa_critical_section_mode_t  mode)
Parameters
modeLock task scheduler of disable interrupt in critical section. Pass kCriticalLockSched to lock task scheduler, pass kCriticalDisableInt to disable interrupt.
void OSA_ExitCritical ( osa_critical_section_mode_t  mode)
Parameters
modeLock task scheduler of disable interrupt in critical section. Pass kCriticalLockSched to lock task scheduler, pass kCriticalDisableInt to disable interrupt.
osa_status_t OSA_Init ( void  )

This function sets up the basic RTOS services. It should be called first in the main function.

Return values
kStatus_OSA_SuccessRTOS services are initialized successfully.
kStatus_OSA_ErrorError occurs during initialization.
osa_status_t OSA_Start ( void  )

This function starts the RTOS scheduler and may never return.

Return values
kStatus_OSA_SuccessRTOS starts to run successfully.
kStatus_OSA_ErrorError occurs when start RTOS.