Wiring OS API

Wiring OS API

Description
A wrapper to CMSIS (Cortex Microcontroller Software Interface Standard) OS API which serves as an RTOS to create the multi-threaded application with real-time behavior.

Syntax
NA

Members

Public Methods 
os_thread_createCreate a thread and add it to Active Threads and set it to state READY.
os_thread_get_idReturn the thread ID of the current running thread.
os_thread_terminateTerminate execution of a thread and remove it from Active Threads.
os_thread_yieldPass control to next thread that is in state READY.
os_thread_set_priorityChange priority of an active thread.
os_thread_get_priorityGet current priority of an active thread.
os_signal_setSet the specified Signal Flags of an active thread.
os_signal_clearClear the specified Signal Flags of an active thread.
os_signal_waitWait for one or more Signal Flags to become signalled for the current RUNNING thread.
os_timer_createCreate a timer.
os_timer_startStart or restart a timer.
os_timer_stopStop the timer.
os_timer_deleteDelete a timer that was created by os_timer_create.
os_semaphore_createCreate and initialize a Semaphore object used for managing resources.
os_semaphore_waitWait until a Semaphore token becomes available.
os_semaphore_releaseRelease a Semaphore token.
os_semaphore_deleteDelete a Semaphore that was created by os_semaphore_create.
os_get_free_heap_sizeReturn the available heap memory space when called.

os_thread_create

Description
Create a thread and add it to Active Threads and set it to state READY.

Syntax
uint32_t os_thread_create(void (*task)(const void *argument), void *argument, int priority, uint32_t stack_size);

Parameters
task: task Function pointer which is the thread body. It should not run into the end of function unless os_thread_terminate is invoked
argument: the data pointer which brings to task
priority: The underlying os is FreeRTOS. It executes tasks with highest priority which are not in idle state.
stack_size: The stack_size is used as memory heap only for this task.

Returns
This function returns the thread id which is used in thread operation and signalling.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_thread_get_id

Description
Get the thread ID of the current running thread.

Syntax
uint32_t os_thread_get_id(void);

Parameters
NA

Returns
This function returns current thread id which calls os_thread_get_id.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_thread_terminate

Description
Terminate execution of a thread and remove it from Active Threads.

Syntax
uint32_t os_thread_terminate(uint32_t thread_id);

Parameters
thread_id: Terminate the thread with specific thread_id.

Returns
This function returns the os_status code.

Example Code
NA

Notes and Warnings
Thread should not end without terminate first. “wiring_os.h” must be included to use the class function.

os_thread_yield

Description
Pass control to next thread that is in state READY.

Syntax
uint32_t os_thread_yield(void);

Parameters
NA

Returns
This function returns the os_status code.

Example Code
NA

Notes and Warnings
The smallest execution unit by default is one millisecond. When a thread with a lower priority wants to instantly give execution rights to a thread with a higher priority rather than waiting for the current 1 millisecond to expire, calling os_thread yield can transfer execution rights to the OS’s idle task and determine which thread will execute next.
“wiring_os.h” must be included to use the class function.

os_thread_set_priority

Description
Change priority of an active thread.

Syntax
uint32_t os_thread_set_priority(uint32_t thread_id, int priority);

Parameters
thread_id: The target thread with the thread id to be changed.
priority: The updated priority.

Returns
NA

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_thread_get_priority

Description
Get current priority of an active thread.

Syntax
uint32_t os_thread_get_priority(uint32_t thread_id);

Parameters
thread_id: The target thread with the thread id to be searched.

Returns
This function returns os_priority.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_signal_set

Description
Set the specified Signal Flags of an active thread.

Syntax
int32_t os_signal_set(uint32_t thread_id, int32_t signals);

Parameters
thread_id: Send signal to a thread with the thread id.
signals: the signals to be send.

Returns
This function returns os_status code.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_signal_clear

Description
Clear the specified Signal Flags of an active thread.

Syntax
int32_t os_signal_clear(uint32_t thread_id, int32_t signals);

Parameters
thread_id: Clear signal to a thread with the thread id.
signals: The signals to be clear.

Returns
This function returns os_status code.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_signal_wait

Description
Wait for one or more Signal Flags to become signalled for the current RUNNING thread.

Syntax
os_event_t os_signal_wait(int32_t signals, uint32_t millisec);

Parameters
signals: the signals to be wait.
millisec: the timeout value if no signal comes in. Fill in 0xFFFFFFFF for infinite wait.

Returns
This function returns os_status code.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_timer_create

Description
Create a timer.

Syntax
uint32_t os_timer_create(void (*callback)(void const *argument), uint8_t isPeriodic, void *argument);

Parameters
callback: The function to be invoke when timer timeout.
isPeriodic: OS_TIMER_ONCE or OS_TIMER_PERIODIC.
argument: The argument that is brought into callback function.

Returns
This function returns the timer id.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_timer_start

Description
Start or restart a timer.

Syntax
uint32_t os_timer_start(uint32_t timer_id, uint32_t millisec);

Parameters
timer_id: The timer id obtained from os_timer_create.
millisec: The delay after timer starts.

Returns
This function returns os_status code.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_timer_stop

Description
Stop the timer.

Syntax
uint32_t os_timer_stop(uint32_t timer_id);

Parameters
timer_id: The timer id obtained from os_timer_create.

Returns
This function returns os_status code.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_timer_delete

Description
Delete a timer that was created by os_timer_create.

Syntax
uint32_t os_timer_delete(uint32_t timer_id);

Parameters
timer_id: The timer id obtained from os_timer_create

Returns
This function returns os_status code.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_semaphore_create

Description
Create and initialize a Semaphore object used for managing resources.

Syntax
uint32_t os_semaphore_create(int32_t count);

Parameters
count: The number of available resources.

Returns
This function returns semaphore ID.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_semaphore_wait

Description
Wait until a Semaphore token becomes available.

Syntax
int32_t os_semaphore_wait(uint32_t semaphore_id, uint32_t millisec);

Parameters
semaphore_id: semaphore id obtained from os_semaphore_create
millisec: timeout value

Returns
This function returns os_status code.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_semaphore_release

Description
Release a Semaphore token.

Syntax
uint32_t os_semaphore_release(uint32_t semaphore_id);

Parameters
semaphore_id: semaphore id obtained from os_semaphore_create

Returns
This function returns os_status code.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_semaphore_delete

Description
Delete a Semaphore that was created by os_semaphore_create.

Syntax
uint32_t os_semaphore_delete(uint32_t semaphore_id);

Parameters
semaphore_id: semaphore id obtained from os_semaphore_create.

Returns
This function returns os_status code.

Example Code
NA

Notes and Warnings
“wiring_os.h” must be included to use the class function.

os_get_free_heap_size

Description
Get the available heap memory space when called.

Syntax
size_t os_get_free_heap_size(void);

Parameters
NA

Returns
This function returns the current free heap size.

Example Code
Example: MemInfo
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Sys/examples/MemInfo/MemInfo.ino)

Notes and Warnings
“wiring_os.h” must be included to use the class function.

Please confirm that QQ communication software is installed
請先確認已安裝QQ通訊軟體