MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
OSA_Adapter: Operatin System Abstraction Adapter

Overview

Modules

 OSA BM
 
 OSA FreeRTOS
 

Data Structures

struct  osa_task_def_t
 Thread Definition structure contains startup information of a thread. More...
 
struct  osa_time_def_t
 Definition structure contains timer parameters. More...
 

Macros

#define USE_RTOS   (0)
 
More...
 
#define osaWaitForever_c   ((uint32_t)(-1))
 Constant to pass as timeout value in order to wait indefinitely. More...
 

Typedefs

typedef uint16_t osa_task_priority_t
 
More...
 
typedef void * osa_task_handle_t
 Type for a task handler.
 
typedef void * osa_task_param_t
 Type for the parameter to be passed to the task at its creation.
 
typedef void(* osa_task_ptr_t )(osa_task_param_t task_param)
 Type for task pointer. More...
 
typedef void * osa_semaphore_handle_t
 Type for the semaphore handler.
 
typedef void * osa_mutex_handle_t
 Type for the mutex handler.
 
typedef void * osa_event_handle_t
 Type for the event handler.
 
typedef uint32_t osa_event_flags_t
 Type for an event flags group, bit 32 is reserved. More...
 
typedef void * osa_msg_handle_t
 Message definition. More...
 
typedef void * osa_msgq_handle_t
 Type for the message queue handler.
 
typedef void * osa_timer_handle_t
 Type for the Timer handler.
 
typedef void(* osa_timer_fct_ptr_t )(void const *argument)
 Type for the Timer callback function pointer. More...
 

Enumerations

enum  osa_timer_t {
  KOSA_TimerOnce = 0,
  KOSA_TimerPeriodic = 1
}
 Type for the timer definition. More...
 
enum  osa_status_t {
  KOSA_StatusSuccess = kStatus_Success,
  KOSA_StatusError = MAKE_STATUS(kStatusGroup_OSA, 1),
  KOSA_StatusTimeout = MAKE_STATUS(kStatusGroup_OSA, 2),
  KOSA_StatusIdle = MAKE_STATUS(kStatusGroup_OSA, 3)
}
 Defines the return status of OSA's functions. More...
 

Task management


Public functions

osa_status_t OSA_TaskCreate (osa_task_handle_t taskHandle, osa_task_def_t *thread_def, osa_task_param_t task_param)
 Creates a task. More...
 
osa_task_handle_t OSA_TaskGetCurrentHandle (void)
 Gets the handler of active task. More...
 
osa_status_t OSA_TaskYield (void)
 Puts the active task to the end of scheduler's queue. More...
 
osa_task_priority_t OSA_TaskGetPriority (osa_task_handle_t taskHandle)
 Gets the priority of a task. More...
 
osa_status_t OSA_TaskSetPriority (osa_task_handle_t taskHandle, osa_task_priority_t taskPriority)
 Sets the priority of a task. More...
 
osa_status_t OSA_TaskDestroy (osa_task_handle_t taskHandle)
 Destroys a previously created task. More...
 
osa_status_t OSA_SemaphoreCreate (osa_semaphore_handle_t semaphoreHandle, uint32_t initValue)
 Creates a semaphore with a given value. More...
 
osa_status_t OSA_SemaphoreDestroy (osa_semaphore_handle_t semaphoreHandle)
 Destroys a previously created semaphore. More...
 
osa_status_t OSA_SemaphoreWait (osa_semaphore_handle_t semaphoreHandle, uint32_t millisec)
 Pending a semaphore with timeout. More...
 
osa_status_t OSA_SemaphorePost (osa_semaphore_handle_t semaphoreHandle)
 Signals for someone waiting on the semaphore to wake up. More...
 
osa_status_t OSA_MutexCreate (osa_mutex_handle_t mutexHandle)
 Create an unlocked mutex. More...
 
osa_status_t OSA_MutexLock (osa_mutex_handle_t mutexHandle, uint32_t millisec)
 Waits for a mutex and locks it. More...
 
osa_status_t OSA_MutexUnlock (osa_mutex_handle_t mutexHandle)
 Unlocks a previously locked mutex. More...
 
osa_status_t OSA_MutexDestroy (osa_mutex_handle_t mutexHandle)
 Destroys a previously created mutex. More...
 
osa_status_t OSA_EventCreate (osa_event_handle_t eventHandle, uint8_t autoClear)
 Initializes an event object with all flags cleared. More...
 
osa_status_t OSA_EventSet (osa_event_handle_t eventHandle, osa_event_flags_t flagsToSet)
 Sets one or more event flags. More...
 
osa_status_t OSA_EventClear (osa_event_handle_t eventHandle, osa_event_flags_t flagsToClear)
 Clears one or more flags. More...
 
osa_status_t OSA_EventWait (osa_event_handle_t eventHandle, osa_event_flags_t flagsToWait, uint8_t waitAll, uint32_t millisec, osa_event_flags_t *pSetFlags)
 Waits for specified event flags to be set. More...
 
osa_status_t OSA_EventDestroy (osa_event_handle_t eventHandle)
 Destroys a previously created event object. More...
 
osa_status_t OSA_MsgQCreate (osa_msgq_handle_t msgqHandle, uint32_t msgNo)
 Initializes a message queue. More...
 
osa_status_t OSA_MsgQPut (osa_msgq_handle_t msgqHandle, osa_msg_handle_t pMessage)
 Puts a message at the end of the queue. More...
 
osa_status_t OSA_MsgQGet (osa_msgq_handle_t msgqHandle, osa_msg_handle_t pMessage, uint32_t millisec)
 Reads and remove a message at the head of the queue. More...
 
osa_status_t OSA_MsgQDestroy (osa_msgq_handle_t msgqHandle)
 Destroys a previously created queue. More...
 
void OSA_InterruptEnable (void)
 Enable all interrupts.
 
void OSA_InterruptDisable (void)
 Disable all interrupts.
 
void OSA_EnableIRQGlobal (void)
 Enable all interrupts using PRIMASK.
 
void OSA_DisableIRQGlobal (void)
 Disable all interrupts using PRIMASK.
 
void OSA_TimeDelay (uint32_t millisec)
 Delays execution for a number of milliseconds. More...
 
uint32_t OSA_TimeGetMsec (void)
 This function gets current time in milliseconds. More...
 
void OSA_InstallIntHandler (uint32_t IRQNumber, void(*handler)(void))
 Installs the interrupt handler. More...
 

Data Structure Documentation

struct osa_task_def_t

Data Fields

osa_task_ptr_t pthread
 start address of thread function
 
uint32_t tpriority
 initial thread priority
 
uint32_t instances
 maximum number of instances of that thread function
 
uint32_t stacksize
 stack size requirements in bytes; 0 is default stack size
 
uint32_t * tstack
 stack pointer
 
void * tlink
 link pointer
 
uint8_t * tname
 name pointer
 
uint8_t useFloat
 is use float
 
struct osa_thread_link_t

Data Fields

uint8_t link [12]
 link
 
osa_task_handle_t osThreadId
 thread id
 
osa_task_def_tosThreadDefHandle
 pointer of thread define handle
 
uint32_t * osThreadStackHandle
 pointer of thread stack handle
 
struct osa_time_def_t

Macro Definition Documentation

#define USE_RTOS   (0)

Public macros

#define osaWaitForever_c   ((uint32_t)(-1))

Typedef Documentation

typedef uint16_t osa_task_priority_t

Public type definitions

Type for the Task Priority

typedef void(* osa_task_ptr_t)(osa_task_param_t task_param)

Task prototype declaration

typedef uint32_t osa_event_flags_t
typedef void* osa_msg_handle_t
typedef void(* osa_timer_fct_ptr_t)(void const *argument)

Enumeration Type Documentation

Enumerator
KOSA_TimerOnce 

one-shot timer

KOSA_TimerPeriodic 

repeating timer

Enumerator
KOSA_StatusSuccess 

Success.

KOSA_StatusError 

Failed.

KOSA_StatusTimeout 

Timeout occurs while waiting.

KOSA_StatusIdle 

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

Function Documentation

osa_status_t OSA_TaskCreate ( osa_task_handle_t  taskHandle,
osa_task_def_t thread_def,
osa_task_param_t  task_param 
)

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

Parameters
taskHandlePointer to a memory space of size #OSA_TASK_HANDLE_SIZE allocated by the caller, task handle.
thread_defpointer to theosa_task_def_t structure which defines the task.
task_paramPointer to be passed to the task when it is created.
Return values
KOSA_StatusSuccessThe task is successfully created.
KOSA_StatusErrorThe task can not be created. Example:
uint8_t taskHandle[OSA_TASK_HANDLE_SIZE];
OSA_TASK_DEFINE( Job1, OSA_PRIORITY_HIGH, 1, 800, 0);
OSA_TaskCreate((osa_task_handle_t)taskHandle, OSA_TASK(Job1), (osa_task_param_t)NULL);
osa_task_handle_t OSA_TaskGetCurrentHandle ( void  )
Returns
Handler to current active task.
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
KOSA_StatusSuccessThe function is called successfully.
KOSA_StatusErrorError occurs with this function.
osa_task_priority_t OSA_TaskGetPriority ( osa_task_handle_t  taskHandle)
Parameters
taskHandleThe handler of the task whose priority is received.
Returns
Task's priority.
osa_status_t OSA_TaskSetPriority ( osa_task_handle_t  taskHandle,
osa_task_priority_t  taskPriority 
)
Parameters
taskHandleThe handler of the task whose priority is set.
taskPriorityThe priority to set.
Return values
KOSA_StatusSuccessTask's priority is set successfully.
KOSA_StatusErrorTask's priority can not be set.
osa_status_t OSA_TaskDestroy ( osa_task_handle_t  taskHandle)
Parameters
taskHandleThe handler of the task to destroy.
Return values
KOSA_StatusSuccessThe task was successfully destroyed.
KOSA_StatusErrorTask destruction failed or invalid parameter.
osa_status_t OSA_SemaphoreCreate ( osa_semaphore_handle_t  semaphoreHandle,
uint32_t  initValue 
)

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

Parameters
semaphoreHandlePointer to a memory space of size #OSA_SEM_HANDLE_SIZE allocated by the caller, semaphore handle.
initValueInitial value the semaphore will be set to.
Return values
KOSA_StatusSuccessthe new semaphore if the semaphore is created successfully.
KOSA_StatusErrorif the semaphore can not be created.
osa_status_t OSA_SemaphoreDestroy ( osa_semaphore_handle_t  semaphoreHandle)
Parameters
semaphoreHandleThe semaphore handle.
Return values
KOSA_StatusSuccessThe semaphore is successfully destroyed.
KOSA_StatusErrorThe semaphore can not be destroyed.
osa_status_t OSA_SemaphoreWait ( osa_semaphore_handle_t  semaphoreHandle,
uint32_t  millisec 
)

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

Parameters
semaphoreHandleThe semaphore handle.
millisecThe maximum number of milliseconds to wait if semaphore is not positive. Pass osaWaitForever_c to wait indefinitely, pass 0 will return KOSA_StatusTimeout immediately.
Return values
KOSA_StatusSuccessThe semaphore is received.
KOSA_StatusTimeoutThe semaphore is not received within the specified 'timeout'.
KOSA_StatusErrorAn incorrect parameter was passed.
osa_status_t OSA_SemaphorePost ( osa_semaphore_handle_t  semaphoreHandle)

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

Parameters
semaphoreHandleThe semaphore handle to signal.
Return values
KOSA_StatusSuccessThe semaphore is successfully signaled.
KOSA_StatusErrorThe object can not be signaled or invalid parameter.
osa_status_t OSA_MutexCreate ( osa_mutex_handle_t  mutexHandle)

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

Parameters
mutexHandlePointer to a memory space of size #OSA_MUTEX_HANDLE_SIZE allocated by the caller, mutex handle.
Return values
KOSA_StatusSuccessthe new mutex if the mutex is created successfully.
KOSA_StatusErrorif the mutex can not be created.
osa_status_t OSA_MutexLock ( osa_mutex_handle_t  mutexHandle,
uint32_t  millisec 
)

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

Parameters
mutexHandleThe mutex handle.
millisecThe maximum number of milliseconds to wait for the mutex. If the mutex is locked, Pass the value osaWaitForever_c will wait indefinitely, pass 0 will return KOSA_StatusTimeout immediately.
Return values
KOSA_StatusSuccessThe mutex is locked successfully.
KOSA_StatusTimeoutTimeout occurred.
KOSA_StatusErrorIncorrect parameter was passed.
Note
This is non-recursive mutex, a task can not try to lock the mutex it has locked.
osa_status_t OSA_MutexUnlock ( osa_mutex_handle_t  mutexHandle)
Parameters
mutexHandleThe mutex handle.
Return values
KOSA_StatusSuccessThe mutex is successfully unlocked.
KOSA_StatusErrorThe mutex can not be unlocked or invalid parameter.
osa_status_t OSA_MutexDestroy ( osa_mutex_handle_t  mutexHandle)
Parameters
mutexHandleThe mutex handle.
Return values
KOSA_StatusSuccessThe mutex is successfully destroyed.
KOSA_StatusErrorThe mutex can not be destroyed.
osa_status_t OSA_EventCreate ( osa_event_handle_t  eventHandle,
uint8_t  autoClear 
)

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

Parameters
eventHandlePointer to a memory space of size #OSA_EVENT_HANDLE_SIZE allocated by the caller, Event handle.
autoClearTRUE The event is auto-clear. FALSE The event manual-clear
Return values
KOSA_StatusSuccessthe new event if the event is created successfully.
KOSA_StatusErrorif the event can not be created.
osa_status_t OSA_EventSet ( osa_event_handle_t  eventHandle,
osa_event_flags_t  flagsToSet 
)

Sets specified flags of an event object.

Parameters
eventHandleThe event handle.
flagsToSetFlags to be set.
Return values
KOSA_StatusSuccessThe flags were successfully set.
KOSA_StatusErrorAn incorrect parameter was passed.
osa_status_t OSA_EventClear ( osa_event_handle_t  eventHandle,
osa_event_flags_t  flagsToClear 
)

Clears specified flags of an event object.

Parameters
eventHandleThe event handle.
flagsToClearFlags to be clear.
Return values
KOSA_StatusSuccessThe flags were successfully cleared.
KOSA_StatusErrorAn incorrect parameter was passed.
osa_status_t OSA_EventWait ( osa_event_handle_t  eventHandle,
osa_event_flags_t  flagsToWait,
uint8_t  waitAll,
uint32_t  millisec,
osa_event_flags_t pSetFlags 
)

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
eventHandleThe event handle.
flagsToWaitFlags that to wait.
waitAllWait all flags or any flag to be set.
millisecThe maximum number of milliseconds to wait for the event. If the wait condition is not met, pass osaWaitForever_c will wait indefinitely, pass 0 will return KOSA_StatusTimeout immediately.
setFlagsFlags that wakeup the waiting task are obtained by this parameter.
Return values
KOSA_StatusSuccessThe wait condition met and function returns successfully.
KOSA_StatusTimeoutHas not met wait condition within timeout.
KOSA_StatusErrorAn incorrect parameter was passed.
Note
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.
osa_status_t OSA_EventDestroy ( osa_event_handle_t  eventHandle)
Parameters
eventHandleThe event handle.
Return values
KOSA_StatusSuccessThe event is successfully destroyed.
KOSA_StatusErrorEvent destruction failed.
osa_status_t OSA_MsgQCreate ( osa_msgq_handle_t  msgqHandle,
uint32_t  msgNo 
)

This function allocates memory for and initializes a message queue. Message queue elements are hardcoded as void*.

Parameters
msgqHandlePointer to a memory space of size #(OSA_MSGQ_HANDLE_SIZE + msgNo*OSA_MSG_HANDLE_SIZE) allocated by the caller, message queue handle.
msgNo:number of messages the message queue should accommodate.
Return values
KOSA_StatusSuccessMessage queue successfully Create.
KOSA_StatusErrorMessage queue create failure.
osa_status_t OSA_MsgQPut ( osa_msgq_handle_t  msgqHandle,
osa_msg_handle_t  pMessage 
)

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

Parameters
msgqHandleMessage Queue handler.
pMessagePointer to the message to be put into the queue.
Return values
KOSA_StatusSuccessMessage successfully put into the queue.
KOSA_StatusErrorThe queue was full or an invalid parameter was passed.
osa_status_t OSA_MsgQGet ( osa_msgq_handle_t  msgqHandle,
osa_msg_handle_t  pMessage,
uint32_t  millisec 
)

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

Parameters
msgqHandleMessage Queue handler.
pMessagePointer to a memory to save the message.
millisecThe number of milliseconds to wait for a message. If the queue is empty, pass osaWaitForever_c will wait indefinitely, pass 0 will return KOSA_StatusTimeout immediately.
Return values
KOSA_StatusSuccessMessage successfully obtained from the queue.
KOSA_StatusTimeoutThe queue remains empty after timeout.
KOSA_StatusErrorInvalid parameter.
osa_status_t OSA_MsgQDestroy ( osa_msgq_handle_t  msgqHandle)
Parameters
msgqHandleMessage Queue handler.
Return values
KOSA_StatusSuccessThe queue was successfully destroyed.
KOSA_StatusErrorMessage queue destruction failed.
void OSA_TimeDelay ( uint32_t  millisec)
Parameters
millisecThe time in milliseconds to wait.
uint32_t OSA_TimeGetMsec ( void  )
Return values
currenttime in milliseconds
void OSA_InstallIntHandler ( uint32_t  IRQNumber,
void(*)(void)  handler 
)
Parameters
IRQNumberIRQ number of the interrupt.
handlerThe interrupt handler to install.