| Kinetis SDK API Reference Manual 1.0.0-beta Freescale Semiconductor, Inc.

- Introduction
- Related Pages
- API Usage

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures | Macros | Typedefs
Bare Metal Abstraction Layer
OS Abstraction Layer (OSA)

The Kinetis SDK provides the bare metal abstraction layer for synchronization, mutual exclusion, message queue, etc. More...

## Data Structures
struct | sync_object_t
| Type for an synchronization object. More...
struct | lock_object_t
| Type for a resource locking object. More...
struct | event_object_t
| Type for an event group object. More...
struct | msg_queue_t
| Type for a message queue declaration and creation. More...
struct | POLL_SLOT_STRUCT
| Poll function slot. More...
struct | POLL_STRUCT
| Poll structure. More...

## Macros
#define | kSyncWaitForever kSwTimerMaxTimeout
| Constant to pass as timeout value in order to wait indefinitely. More...
#define | FSL_RTOS_CURRENT_TASK ((task_handler_t)0)
| Macro passed to the task_destroy function to destroy the current task.

## Typedefs
typedef uint32_t | event_group_t
| Type for an event flags group, bit 32 is reserved.
typedef void(* | task_t )(void *param)
| Type for a task pointer.
typedef task_t | task_handler_t
| Type for a task handler, returned by the task_create function.
typedef uint32_t | task_stack_t
| Type for a task stack.
typedef msg_queue_t * | msg_queue_handler_t
| Type for a message queue declaration and creation.
typedef void * | msg_queue_item_t
| Type for a message queue item.

## Synchronization
#define | sync_object_declare(obj) sync_object_t obj
| Create the synchronization object. More...

## Resource locking
#define | lock_object_declare(obj) lock_object_t obj
| Create the locking object. More...

## Thread management
#define | FSL_RTOS_TASK_DEFINE(task, stackSize, name, usesFloat) uint8_t fslTaskName_##task[] = name
| Define a task. More...
#define | task_create(task, priority, param, handler)
| Creates and sets the task to active. More...

## Message queues
#define | MSG_QUEUE_DECLARE(name, number, size)
| This macro statically reserves the memory required for the queue. More...

## Critical Sections
#define | rtos_enter_critical interrupt_disable_global
| Ensures the following code will not be preempted.
#define | rtos_exit_critical interrupt_enable_global
| Allows preemption.

## Task poll
void | Poll (void)
| Poll every function registered in the POLL_STRUCT. More...
void | POLL_init (void)
| Initialize the POLL_STRUCT. More...
#define | POLL_MAX_NUM 5
| Maximum number of functions called every time Poll function is invoked.

### Bare Metal Abstraction Layer

# Overview

When RTOSes are not used, a bare metal abstraction layer provides synchronization, mutual exclusion, message queue, and so on.

# Task Management

Bare metal abstraction layer provides a poll mechanism to simulate a task. The task functions should not be infinite. When tasks are created, the task functions are registered to a global array and called one by one.This is an example code, which shows how to use a task with a bare metal abstraction layer.
void main(void)
{
task_handler_t handler;
POLL_init();
task_create(task_func, priority, param, &handler);
for(;;)
{
Poll();
}
}

## Data Structure Documentation

struct sync_object_t

### Data Fields
volatile bool | isWaiting
| Is any task waiting for a timeout on this object.
volatile uint8_t | semCount
| The count value of the object.
uint8_t | timerId
| The software timer channel this object bind to.

struct lock_object_t

### Data Fields
volatile bool | isWaiting
| Is any task waiting for a timeout on this lock.
volatile bool | isLocked
| Is the object locked or not.
uint8_t | timerId
| The software timer channel this lock bind to.

struct event_object_t

### Data Fields
volatile bool | isWaiting
| Is any task waiting for a timeout on this event.
uint8_t | timerId
| The software timer channel this event bind to.
volatile event_group_t | flags
| The flags status.
event_clear_type | clearType
| Auto clear or manual clear.

struct msg_queue_t

### Data Fields
void ** | queueMem
| Points to the queue memory.
uint16_t | number
| Stores the elements in the queue.
uint16_t | size
| Stores the size in words of each element.
uint16_t | head
| Index of the next element to be read.
uint16_t | tail
| Index of the next place to write to.
sync_object_t | queueSync
| Sync object wakeup tasks waiting for msg.
volatile bool | isEmpty
| Whether queue is empty.

struct POLL_SLOT_STRUCT

### Data Fields
task_t | p_func
| Task's entry.
void * | param
| Task's parameter.

struct POLL_STRUCT

### Data Fields
POLL_SLOT_STRUCT | p_slot [POLL_MAX_NUM]
| polling function pointer array
uint32_t | registered_no
| number of registered function

## Macro Definition Documentation

#define kSyncWaitForever kSwTimerMaxTimeout

#define sync_object_declare | ( |  | obj | ) | sync_object_t obj

To be used instead of a standard declaration.

Parameters

  obj | The sync object to create.

#define lock_object_declare | ( |  | obj | ) | lock_object_t obj

To be used instead of a standard declaration.

Parameters

  obj | The lock object to create.

#define FSL_RTOS_TASK_DEFINE | ( |  | task,
|  |  | stackSize,
|  |  | name,
|  |  | usesFloat
| ) |  | uint8_t fslTaskName_##task[] = name

This macro is used to define resources for a task statically, then task_create will create task based-on these resources.

Parameters

  task | The task function.
  stackSize | Number of elements in the stack for this task.
  name | String to assign to the task.
  usesFloat | Boolean that indicates whether the task uses the floating point unit.

#define task_create | ( |  | task,
|  |  | priority,
|  |  | param,
|  |  | handler
| ) |  |

Value:
__task_create(task, \
fslTaskName_##task, \
0, \
NULL, \
priority, \
param, \
false, \
handler)
__task_create
fsl_rtos_status __task_create(task_t task, uint8_t *name, uint16_t stackSize, task_stack_t *stackMem, uint16_t priority, void *param, bool usesFloat, task_handler_t *handler)
Create a task.

This macro is used with FSL_RTOS_TASK_DEFINE to create a task. Here is an example demonstrating how to use:

FSL_RTOS_TASK_DEFINE(task_func, stackSize, taskName, FALSE);
void main(void)
{
task_handler_t handler;
task_create(task_func, priority, param, &handler);
}

Parameters

  task | The task function.
  priority | Initial priority of the task.
  param | Parameter to be passed to the task when it is created.
  handler | Returns the identifier to be used afterwards to destroy the task.

Return values

  kSuccess | The task was successfully created.
  kError | The task creation failed.

#define MSG_QUEUE_DECLARE | ( |  | name,
|  |  | number,
|  |  | size
| ) |  |

Value:
void * queueMem##name[number]; \
msg_queue_t name = { \
.queueMem = queueMem##name \
}
msg_queue_t
xQueueHandle msg_queue_t
Type for a message queue declaration and creation.
Definition: fsl_os_abstraction_free_rtos.h:120

Parameters

  name | Identifier for the memory region.
  number | Number of elements in the queue.
  size | Size of every element in words.

## Function Documentation

void Poll | ( | void |  | ) |

Every task function registered in the POLL_STRUCT will be called in turn. This function should be used in a infinite loop in main.

Here is an example demonstrating how to use:

int main(void)
{
// System initialize functions.
POLL_init();
for(;;)
{
Poll();
}
return 0;
}

void POLL_init | ( | void |  | ) |

The struct POLL_STRUCT must be initialized before task functions are registered.