|
SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Typedefs | |
| typedef enum cy_thread_state | cy_thread_state_t |
| typedef void(* | cy_thread_entry_fn_t) (cy_thread_arg_t arg) |
APIs for creating and working with Threads.
| #define cy_rtos_create_thread | ( | thread, | |
| entry_function, | |||
| name, | |||
| stack, | |||
| stack_size, | |||
| priority, | |||
| arg ) |
Create a thread with specific thread argument.
This function is called to startup a new thread. If the thread can exit, it must call cy_rtos_exit_thread() just before doing so. All created threads that can terminate, either by themselves or forcefully by another thread MUST have cy_rtos_join_thread() called on them by another thread in order to cleanup any resources that might have been allocated for them.
| [out] | thread | Pointer to a variable which will receive the new thread handle |
| [in] | entry_function | Function pointer which points to the main function for the new thread |
| [in] | name | String thread name used for a debugger |
| [in] | stack | The buffer to use for the thread stack. This must be aligned to CY_RTOS_ALIGNMENT_MASK with a size of at least CY_RTOS_MIN_STACK_SIZE. If stack is null, cy_rtos_create_thread will allocate a stack from the heap. |
| [in] | stack_size | The size of the thread stack in bytes |
| [in] | priority | The priority of the thread. Values are operating system specific, but some common priority levels are defined: CY_THREAD_PRIORITY_LOW CY_THREAD_PRIORITY_NORMAL CY_THREAD_PRIORITY_HIGH |
| [in] | arg | The argument to pass to the new thread |
Definition at line 1002 of file cyabs_rtos.h.
| #define cy_rtos_exit_thread cy_rtos_thread_exit |
Exit the current thread.
This function is called just before a thread exits. In some cases it is sufficient for a thread to just return to exit, but in other cases, the RTOS must be explicitly signaled. In cases where a return is sufficient, this should be a null function. In cases where the RTOS must be signaled, this function should perform that operation. In code using RTOS services, this function should be placed at any location where the main thread function will return, exiting the thread. Threads that can exit must still be joined (cy_rtos_join_thread) to ensure their resources are fully cleaned up.
Definition at line 1125 of file cyabs_rtos.h.
| #define cy_rtos_get_thread_handle | ( | thread | ) |
Get current thread handle
Returns the unique thread handle of the current running thread.
| [out] | thread | Handle of the current running thread |
Definition at line 1090 of file cyabs_rtos.h.
| #define cy_rtos_get_thread_state | ( | thread, | |
| state ) |
Gets the state the thread is currently in
This function is called to determine if a thread is running/blocked/inactive/ready etc.
| [in] | thread | Handle of the terminated thread to delete |
| [out] | state | Returns the state the thread is currently in |
Definition at line 1063 of file cyabs_rtos.h.
| #define cy_rtos_is_thread_running | ( | thread, | |
| running ) |
Checks if the thread is running
This function is called to determine if a thread is actively running or not. For information on the thread state, use the cy_rtos_get_thread_state() function.
| [in] | thread | Handle of the terminated thread to delete |
| [out] | running | Returns true if the thread is running, otherwise false |
Definition at line 1016 of file cyabs_rtos.h.
| #define cy_rtos_join_thread | ( | thread | ) |
Waits for a thread to complete.
This must be called on any thread that can complete to ensure that any resources that were allocated for it are cleaned up.
| [in] | thread | Handle of the thread to wait for |
Definition at line 1079 of file cyabs_rtos.h.
| #define cy_rtos_set_thread_notification | ( | thread, | |
| in_isr ) |
Set the thread notification for a thread
This function sets the thread notification for the target thread. The target thread waiting for the notification to be set will resume from suspended state.
| [in] | thread | Handle of the target thread |
| [in] | in_isr | If true this is being called from within an ISR |
Definition at line 1032 of file cyabs_rtos.h.
| #define cy_rtos_terminate_thread | ( | thread | ) |
Terminates another thread.
This function is called to terminate another thread and reap the resources claimed by the thread. This should be called both when forcibly terminating another thread as well as any time a thread can exit on its own. For some RTOS implementations this is not required as the thread resources are claimed as soon as it exits. In other cases, this must be called to reclaim resources. Threads that are terminated must still be joined (cy_rtos_join_thread) to ensure their resources are fully cleaned up.
| [in] | thread | Handle of the thread to terminate |
Definition at line 1110 of file cyabs_rtos.h.
| #define cy_rtos_wait_thread_notification | ( | timeout_ms | ) |
Suspend current thread until notification is received
This function suspends the execution of current thread until it is notified by cy_rtos_set_thread_notification from another thread or ISR, or timed out with specify timeout value
| [in] | timeout_ms | Maximum number of milliseconds to wait Use the CY_RTOS_NEVER_TIMEOUT constant to wait forever. |
Definition at line 1049 of file cyabs_rtos.h.
| typedef void(* cy_thread_entry_fn_t) (cy_thread_arg_t arg) |
The type of a function that is the entry point for a thread
| [in] | arg | the argument passed from the thread create call to the entry function |
Definition at line 179 of file cyabs_rtos.h.
| typedef enum cy_thread_state cy_thread_state_t |
The state a thread can be in
| enum cy_thread_state |
The state a thread can be in
Definition at line 129 of file cyabs_rtos.h.
| cy_rslt_t cy_rtos_thread_create | ( | cy_thread_t * | thread, |
| cy_thread_entry_fn_t | entry_function, | ||
| const char * | name, | ||
| void * | stack, | ||
| uint32_t | stack_size, | ||
| cy_thread_priority_t | priority, | ||
| cy_thread_arg_t | arg ) |
Create a thread with specific thread argument.
This function is called to startup a new thread. If the thread can exit, it must call cy_rtos_thread_exit() just before doing so. All created threads that can terminate, either by themselves or forcefully by another thread MUST have cy_rtos_thread_join() called on them by another thread in order to cleanup any resources that might have been allocated for them.
| [out] | thread | Pointer to a variable which will receive the new thread handle |
| [in] | entry_function | Function pointer which points to the main function for the new thread |
| [in] | name | String thread name used for a debugger |
| [in] | stack | The buffer to use for the thread stack. This must be aligned to CY_RTOS_ALIGNMENT_MASK with a size of at least CY_RTOS_MIN_STACK_SIZE. If stack is null, cy_rtos_create_thread will allocate a stack from the heap. |
| [in] | stack_size | The size of the thread stack in bytes |
| [in] | priority | The priority of the thread. Values are operating system specific, but some common priority levels are defined: CY_THREAD_PRIORITY_LOW CY_THREAD_PRIORITY_NORMAL CY_THREAD_PRIORITY_HIGH |
| [in] | arg | The argument to pass to the new thread |
< not allowed in this context (ISR, scheduler not running or locked, not a thread created by cy_rtos_thread_create())
< no error
< thread or its stack is already known to the kernel
< kernel is not initialized (see cy_rtos_stk_kernel_init())
Definition at line 441 of file cyabs_rtos_stk.cpp.
References stk::ADD_FAIL_DUPLICATE, stk::ADD_FAIL_POOL_FULL, stk::ADD_OK, CY_RTOS_ALIGNMENT_ERROR, CY_RTOS_ALIGNMENT_MASK, CY_RTOS_BAD_PARAM, CY_RTOS_MIN_STACK_SIZE, CY_RTOS_NO_MEMORY, CY_RTOS_STK_ERR_CONTEXT, CY_RTOS_STK_ERR_DUPLICATE, CY_RTOS_STK_ERR_KERNEL_STATE, CY_RTOS_STK_ERR_NONE, CY_RTOS_STK_FREE, CY_RTOS_STK_MALLOC, CY_RTOS_STK_PRIORITY_LEVELS, g_Kernel, cy_stk_thread::m_magic, STK_STACK_MEMORY_ALIGN, and cy_stk_thread::~cy_stk_thread().
Referenced by app_init(), and app_main().
| cy_rslt_t cy_rtos_thread_exit | ( | void | ) |
Exit the current thread.
This function is called just before a thread exits. In some cases it is sufficient for a thread to just return to exit, but in other cases, the RTOS must be explicitly signaled. In cases where a return is sufficient, this should be a null function. In cases where the RTOS must be signaled, this function should perform that operation. In code using RTOS services, this function should be placed at any location where the main thread function will return, exiting the thread. Threads that can exit must still be joined (cy_rtos_thread_join) to ensure their resources are fully cleaned up.
< not allowed in this context (ISR, scheduler not running or locked, not a thread created by cy_rtos_thread_create())
Definition at line 522 of file cyabs_rtos_stk.cpp.
References CY_RTOS_STK_ERR_CONTEXT, stk::ExitTask(), and cy_stk_thread::m_finished.
| cy_rslt_t cy_rtos_thread_get_handle | ( | cy_thread_t * | thread | ) |
Get current thread handle
Returns the unique thread handle of the current running thread.
| [out] | thread | Handle of the current running thread |
< not allowed in this context (ISR, scheduler not running or locked, not a thread created by cy_rtos_thread_create())
Definition at line 697 of file cyabs_rtos_stk.cpp.
References CY_RTOS_BAD_PARAM, and CY_RTOS_STK_ERR_CONTEXT.
| cy_rslt_t cy_rtos_thread_get_name | ( | const cy_thread_t * | thread, |
| const char ** | thread_name ) |
Get the name of a thread
This function returns the name of the target thread
| [in] | thread | Handle of the target thread |
| [out] | thread_name | Will be updated to point to the thread name. Can return NULL in the case of no thread name. |
Definition at line 753 of file cyabs_rtos_stk.cpp.
References CY_RTOS_BAD_PARAM, and cy_stk_thread::m_name.
| cy_rslt_t cy_rtos_thread_get_state | ( | const cy_thread_t * | thread, |
| cy_thread_state_t * | state ) |
Gets the state the thread is currently in
This function is called to determine if a thread is running/blocked/inactive/ready etc.
| [in] | thread | Handle of the terminated thread to delete |
| [out] | state | Returns the state the thread is currently in |
Definition at line 648 of file cyabs_rtos_stk.cpp.
References CY_RTOS_BAD_PARAM, CY_THREAD_STATE_BLOCKED, CY_THREAD_STATE_READY, CY_THREAD_STATE_RUNNING, CY_THREAD_STATE_TERMINATED, CY_THREAD_STATE_UNKNOWN, g_Kernel, cy_stk_thread::m_finished, cy_stk_thread::m_removed, stk::TaskStateInfo::state, stk::TASK_STATE_EXITING, stk::TASK_STATE_READY, stk::TASK_STATE_REMOVED, stk::TASK_STATE_SLEEPING, stk::TASK_STATE_SUSPENDED, stk::TASK_STATE_WAITING, and stk::WAIT_INFINITE.
| cy_rslt_t cy_rtos_thread_is_running | ( | const cy_thread_t * | thread, |
| bool * | running ) |
Checks if the thread is running
This function is called to determine if a thread is actively running or not. For information on the thread state, use the cy_rtos_thread_get_state() function.
| [in] | thread | Handle of the terminated thread to delete |
| [out] | running | Returns true if the thread is running, otherwise false |
Definition at line 633 of file cyabs_rtos_stk.cpp.
References CY_RTOS_BAD_PARAM.
| cy_rslt_t cy_rtos_thread_join | ( | cy_thread_t * | thread | ) |
Waits for a thread to complete.
This must be called on any thread that can complete to ensure that any resources that were allocated for it are cleaned up.
| [in] | thread | Handle of the thread to wait for |
< not allowed in this context (ISR, scheduler not running or locked, not a thread created by cy_rtos_thread_create())
< the kernel rejected the wait / sleep
Definition at line 592 of file cyabs_rtos_stk.cpp.
References CY_RTOS_BAD_PARAM, CY_RTOS_STK_ERR_CONTEXT, CY_RTOS_STK_ERR_WAIT_FAILED, CY_RTOS_STK_FREE, cy_stk_thread::m_join, cy_stk_thread::m_magic, cy_stk_thread::m_raw, cy_stk_thread::m_removed, stk::WAIT_INFINITE, stk::WAIT_RESULT_FAIL, stk::sync::SemaphoreT< T >::WaitEx(), and cy_stk_thread::~cy_stk_thread().
| cy_rslt_t cy_rtos_thread_set_notification | ( | const cy_thread_t * | thread | ) |
Set the thread notification for a thread
This function sets the thread notification for the target thread. The target thread waiting for the notification to be set will resume from suspended state.
| [in] | thread | Handle of the target thread |
Definition at line 738 of file cyabs_rtos_stk.cpp.
References CY_RTOS_BAD_PARAM, cy_stk_thread::m_notify, and stk::sync::SemaphoreT< T >::TrySignal().
| cy_rslt_t cy_rtos_thread_terminate | ( | const cy_thread_t * | thread | ) |
Terminates another thread.
This function is called to terminate another thread and reap the resources claimed by the thread. This should be called both when forcibly terminating another thread as well as any time a thread can exit on its own. For some RTOS implementations this is not required as the thread resources are claimed as soon as it exits. In other cases, this must be called to reclaim resources. Threads that are terminated must still be joined (cy_rtos_thread_join) to ensure their resources are fully cleaned up.
| [in] | thread | Handle of the thread to terminate |
< not allowed in this context (ISR, scheduler not running or locked, not a thread created by cy_rtos_thread_create())
< kernel is not initialized (see cy_rtos_stk_kernel_init())
Definition at line 538 of file cyabs_rtos_stk.cpp.
References CY_RTOS_BAD_PARAM, CY_RTOS_STK_ERR_CONTEXT, CY_RTOS_STK_ERR_KERNEL_STATE, stk::ExitTask(), g_Kernel, stk::IKernel::KSTATE_INACTIVE, stk::IKernel::KSTATE_READY, cy_stk_thread::m_finished, cy_stk_thread::m_join, cy_stk_thread::m_removed, and stk::sync::SemaphoreT< T >::TrySignal().
| cy_rslt_t cy_rtos_thread_wait_notification | ( | cy_time_t | timeout_ms | ) |
Suspend current thread until notification is received
This function suspends the execution of current thread until it is notified by cy_rtos_thread_set_notification from another thread or ISR, or timed out with specify timeout value
| [in] | timeout_ms | Maximum number of milliseconds to wait Use the CY_RTOS_NEVER_TIMEOUT constant to wait forever. |
< not allowed in this context (ISR, scheduler not running or locked, not a thread created by cy_rtos_thread_create())
Definition at line 718 of file cyabs_rtos_stk.cpp.
References CY_RTOS_STK_ERR_CONTEXT, CY_RTOS_TIMEOUT, cy_stk_thread::m_notify, and stk::sync::SemaphoreT< T >::WaitEx().
Referenced by app_main().