2013-02-18 15:32:11 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2012 ARM Limited
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
#ifndef THREAD_H
|
|
|
|
#define THREAD_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2017-05-15 14:55:45 +00:00
|
|
|
#include "cmsis_os2.h"
|
|
|
|
#include "mbed_rtos1_types.h"
|
|
|
|
#include "mbed_rtos_storage.h"
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "platform/Callback.h"
|
2017-01-27 11:10:28 +00:00
|
|
|
#include "platform/mbed_toolchain.h"
|
2017-06-20 12:01:28 +00:00
|
|
|
#include "platform/NonCopyable.h"
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "rtos/Semaphore.h"
|
|
|
|
#include "rtos/Mutex.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
namespace rtos {
|
2016-10-04 20:02:44 +00:00
|
|
|
/** \addtogroup rtos */
|
|
|
|
/** @{*/
|
2017-10-24 15:05:45 +00:00
|
|
|
/**
|
|
|
|
* \defgroup rtos_Thread Thread class
|
|
|
|
* @{
|
|
|
|
*/
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2016-08-25 18:08:35 +00:00
|
|
|
/** The Thread class allow defining, creating, and controlling thread functions in the system.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* #include "mbed.h"
|
|
|
|
* #include "rtos.h"
|
|
|
|
*
|
|
|
|
* Thread thread;
|
|
|
|
* DigitalOut led1(LED1);
|
|
|
|
* volatile bool running = true;
|
|
|
|
*
|
|
|
|
* // Blink function toggles the led in a long running loop
|
|
|
|
* void blink(DigitalOut *led) {
|
|
|
|
* while (running) {
|
|
|
|
* *led = !*led;
|
2016-12-20 16:42:29 +00:00
|
|
|
* wait(1);
|
2016-08-25 18:08:35 +00:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // Spawns a thread to run blink for 5 seconds
|
|
|
|
* int main() {
|
2016-12-19 20:43:38 +00:00
|
|
|
* thread.start(callback(blink, &led1));
|
2016-12-20 16:42:29 +00:00
|
|
|
* wait(5);
|
2016-08-25 18:08:35 +00:00
|
|
|
* running = false;
|
|
|
|
* thread.join();
|
|
|
|
* }
|
|
|
|
* @endcode
|
2017-05-15 14:55:45 +00:00
|
|
|
*
|
|
|
|
* @note
|
|
|
|
* Memory considerations: The thread control structures will be created on current thread's stack, both for the mbed OS
|
|
|
|
* and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
|
|
|
|
* Additionally the stack memory for this thread will be allocated on the heap, if it wasn't supplied to the constructor.
|
2018-04-04 17:28:57 +00:00
|
|
|
*
|
|
|
|
* @note
|
|
|
|
* MBED_TZ_DEFAULT_ACCESS (default:0) flag can be used to change the default access of all user threads in non-secure mode.
|
|
|
|
* MBED_TZ_DEFAULT_ACCESS set to 1, means all non-secure user threads have access to call secure functions.
|
|
|
|
* MBED_TZ_DEFAULT_ACCESS set to 0, means none of the non-secure user thread have access to call secure functions,
|
|
|
|
* to give access to particular thread used overloaded constructor with `tz_module` as argument during thread creation.
|
|
|
|
*
|
|
|
|
* MBED_TZ_DEFAULT_ACCESS is target specific define, should be set in targets.json file for Cortex-M23/M33 devices.
|
2016-08-25 18:08:35 +00:00
|
|
|
*/
|
2017-10-13 16:37:44 +00:00
|
|
|
|
2017-06-20 12:01:28 +00:00
|
|
|
class Thread : private mbed::NonCopyable<Thread> {
|
2013-02-18 15:32:11 +00:00
|
|
|
public:
|
2016-04-22 06:03:53 +00:00
|
|
|
/** Allocate a new thread without starting execution
|
|
|
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
2017-05-15 14:55:45 +00:00
|
|
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
|
|
|
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
|
|
|
@param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: NULL)
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-03-29 21:48:53 +00:00
|
|
|
@note Default value of tz_module will be MBED_TZ_DEFAULT_ACCESS
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2016-04-22 06:03:53 +00:00
|
|
|
*/
|
2017-10-13 16:37:44 +00:00
|
|
|
|
2018-08-27 09:23:50 +00:00
|
|
|
Thread(osPriority priority = osPriorityNormal,
|
|
|
|
uint32_t stack_size = OS_STACK_SIZE,
|
|
|
|
unsigned char *stack_mem = NULL, const char *name = NULL)
|
|
|
|
{
|
2018-03-29 21:48:53 +00:00
|
|
|
constructor(priority, stack_size, stack_mem, name);
|
2016-06-01 17:11:05 +00:00
|
|
|
}
|
2016-04-22 06:03:53 +00:00
|
|
|
|
2018-03-29 21:48:53 +00:00
|
|
|
/** Allocate a new thread without starting execution
|
|
|
|
@param tz_module trustzone thread identifier (osThreadAttr_t::tz_module)
|
2018-04-04 17:28:57 +00:00
|
|
|
Context of RTOS threads in non-secure state must be saved when calling secure functions.
|
|
|
|
tz_module ID is used to allocate context memory for threads, and it can be safely set to zero for
|
|
|
|
threads not using secure calls at all. See "TrustZone RTOS Context Management" for more details.
|
2018-03-29 21:48:53 +00:00
|
|
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
|
|
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
|
|
|
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
|
|
|
@param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: NULL)
|
|
|
|
|
|
|
|
@note You cannot call this function from ISR context.
|
|
|
|
*/
|
|
|
|
|
2018-08-27 09:23:50 +00:00
|
|
|
Thread(uint32_t tz_module, osPriority priority = osPriorityNormal,
|
|
|
|
uint32_t stack_size = OS_STACK_SIZE,
|
|
|
|
unsigned char *stack_mem = NULL, const char *name = NULL)
|
|
|
|
{
|
2018-03-29 21:48:53 +00:00
|
|
|
constructor(tz_module, priority, stack_size, stack_mem, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
/** Create a new thread, and start it executing the specified function.
|
|
|
|
@param task function to be executed by this thread.
|
|
|
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
2017-05-15 14:55:45 +00:00
|
|
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
|
|
|
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
2016-06-28 19:33:22 +00:00
|
|
|
@deprecated
|
2016-08-25 18:08:35 +00:00
|
|
|
Thread-spawning constructors hide errors. Replaced by thread.start(task).
|
2016-06-28 19:33:22 +00:00
|
|
|
|
2016-08-25 18:08:35 +00:00
|
|
|
@code
|
2017-05-15 14:55:45 +00:00
|
|
|
Thread thread(priority, stack_size, stack_mem);
|
2016-08-25 18:08:35 +00:00
|
|
|
|
|
|
|
osStatus status = thread.start(task);
|
|
|
|
if (status != osOK) {
|
|
|
|
error("oh no!");
|
|
|
|
}
|
|
|
|
@endcode
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
2016-08-17 01:30:20 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2018-08-27 09:23:50 +00:00
|
|
|
"Thread-spawning constructors hide errors. "
|
|
|
|
"Replaced by thread.start(task).")
|
2016-05-15 21:50:45 +00:00
|
|
|
Thread(mbed::Callback<void()> task,
|
2018-08-27 09:23:50 +00:00
|
|
|
osPriority priority = osPriorityNormal,
|
|
|
|
uint32_t stack_size = OS_STACK_SIZE,
|
|
|
|
unsigned char *stack_mem = NULL)
|
|
|
|
{
|
2017-05-15 14:55:45 +00:00
|
|
|
constructor(task, priority, stack_size, stack_mem);
|
2016-05-15 21:50:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Create a new thread, and start it executing the specified function.
|
|
|
|
@param argument pointer that is passed to the thread function as start argument. (default: NULL).
|
2017-06-06 01:51:37 +00:00
|
|
|
@param task argument to task.
|
2016-05-15 21:50:45 +00:00
|
|
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
2017-05-15 14:55:45 +00:00
|
|
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
|
|
|
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
2016-06-28 19:33:22 +00:00
|
|
|
@deprecated
|
2016-09-23 08:29:14 +00:00
|
|
|
Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
|
2016-08-25 18:08:35 +00:00
|
|
|
|
|
|
|
@code
|
2017-05-15 14:55:45 +00:00
|
|
|
Thread thread(priority, stack_size, stack_mem);
|
2016-06-28 19:33:22 +00:00
|
|
|
|
2016-09-23 08:29:14 +00:00
|
|
|
osStatus status = thread.start(callback(task, argument));
|
2016-08-25 18:08:35 +00:00
|
|
|
if (status != osOK) {
|
|
|
|
error("oh no!");
|
|
|
|
}
|
|
|
|
@endcode
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2016-05-15 21:50:45 +00:00
|
|
|
*/
|
|
|
|
template <typename T>
|
2016-08-17 01:30:20 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2018-08-27 09:23:50 +00:00
|
|
|
"Thread-spawning constructors hide errors. "
|
|
|
|
"Replaced by thread.start(callback(task, argument)).")
|
2016-08-25 18:08:35 +00:00
|
|
|
Thread(T *argument, void (T::*task)(),
|
2018-08-27 09:23:50 +00:00
|
|
|
osPriority priority = osPriorityNormal,
|
|
|
|
uint32_t stack_size = OS_STACK_SIZE,
|
|
|
|
unsigned char *stack_mem = NULL)
|
|
|
|
{
|
2016-09-23 08:29:14 +00:00
|
|
|
constructor(mbed::callback(task, argument),
|
2017-05-15 14:55:45 +00:00
|
|
|
priority, stack_size, stack_mem);
|
2016-05-15 21:50:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Create a new thread, and start it executing the specified function.
|
|
|
|
@param argument pointer that is passed to the thread function as start argument. (default: NULL).
|
2017-06-06 01:51:37 +00:00
|
|
|
@param task argument to task.
|
2016-05-15 21:50:45 +00:00
|
|
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
2017-05-15 14:55:45 +00:00
|
|
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
|
|
|
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
2016-06-28 19:33:22 +00:00
|
|
|
@deprecated
|
2016-09-23 08:29:14 +00:00
|
|
|
Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
|
2016-06-28 19:33:22 +00:00
|
|
|
|
2016-08-25 18:08:35 +00:00
|
|
|
@code
|
2017-05-15 14:55:45 +00:00
|
|
|
Thread thread(priority, stack_size, stack_mem);
|
2016-08-25 18:08:35 +00:00
|
|
|
|
2016-09-23 08:29:14 +00:00
|
|
|
osStatus status = thread.start(callback(task, argument));
|
2016-08-25 18:08:35 +00:00
|
|
|
if (status != osOK) {
|
|
|
|
error("oh no!");
|
|
|
|
}
|
|
|
|
@endcode
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2016-05-15 21:50:45 +00:00
|
|
|
*/
|
|
|
|
template <typename T>
|
2016-08-17 01:30:20 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2018-08-27 09:23:50 +00:00
|
|
|
"Thread-spawning constructors hide errors. "
|
|
|
|
"Replaced by thread.start(callback(task, argument)).")
|
2016-08-25 18:08:35 +00:00
|
|
|
Thread(T *argument, void (*task)(T *),
|
2018-08-27 09:23:50 +00:00
|
|
|
osPriority priority = osPriorityNormal,
|
|
|
|
uint32_t stack_size = OS_STACK_SIZE,
|
|
|
|
unsigned char *stack_mem = NULL)
|
|
|
|
{
|
2016-09-23 08:29:14 +00:00
|
|
|
constructor(mbed::callback(task, argument),
|
2017-05-15 14:55:45 +00:00
|
|
|
priority, stack_size, stack_mem);
|
2016-05-15 21:50:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Create a new thread, and start it executing the specified function.
|
|
|
|
Provided for backwards compatibility
|
|
|
|
@param task function to be executed by this thread.
|
|
|
|
@param argument pointer that is passed to the thread function as start argument. (default: NULL).
|
|
|
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
2017-05-15 14:55:45 +00:00
|
|
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
|
|
|
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
2016-06-28 19:33:22 +00:00
|
|
|
@deprecated
|
2016-09-23 08:29:14 +00:00
|
|
|
Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
|
2016-08-25 18:08:35 +00:00
|
|
|
|
|
|
|
@code
|
2017-05-15 14:55:45 +00:00
|
|
|
Thread thread(priority, stack_size, stack_mem);
|
2016-06-28 19:33:22 +00:00
|
|
|
|
2016-09-23 08:29:14 +00:00
|
|
|
osStatus status = thread.start(callback(task, argument));
|
2016-08-25 18:08:35 +00:00
|
|
|
if (status != osOK) {
|
|
|
|
error("oh no!");
|
|
|
|
}
|
|
|
|
@endcode
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2016-05-15 21:50:45 +00:00
|
|
|
*/
|
2016-08-17 01:30:20 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2018-08-27 09:23:50 +00:00
|
|
|
"Thread-spawning constructors hide errors. "
|
|
|
|
"Replaced by thread.start(callback(task, argument)).")
|
|
|
|
Thread(void (*task)(void const *argument), void *argument = NULL,
|
|
|
|
osPriority priority = osPriorityNormal,
|
|
|
|
uint32_t stack_size = OS_STACK_SIZE,
|
|
|
|
unsigned char *stack_mem = NULL)
|
|
|
|
{
|
2016-09-23 08:29:14 +00:00
|
|
|
constructor(mbed::callback((void (*)(void *))task, argument),
|
2017-05-15 14:55:45 +00:00
|
|
|
priority, stack_size, stack_mem);
|
2016-05-15 21:50:45 +00:00
|
|
|
}
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2016-04-22 06:03:53 +00:00
|
|
|
/** Starts a thread executing the specified function.
|
|
|
|
@param task function to be executed by this thread.
|
|
|
|
@return status code that indicates the execution status of the function.
|
2017-03-01 20:37:55 +00:00
|
|
|
@note a thread can only be started once
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function ISR context.
|
2016-04-22 06:03:53 +00:00
|
|
|
*/
|
2016-06-01 17:11:05 +00:00
|
|
|
osStatus start(mbed::Callback<void()> task);
|
|
|
|
|
|
|
|
/** Starts a thread executing the specified function.
|
|
|
|
@param obj argument to task
|
|
|
|
@param method function to be executed by this thread.
|
|
|
|
@return status code that indicates the execution status of the function.
|
Added support for cv-qualifiers in Callback class
Additionally, the following changes were don to avoid combinatorial
explosion in function overloads as a result of adding cv-qualifiers:
- Added convenience function for inferred type
- Deprecated callback overloads qhere cv-qualifiers are not scalable
Supported overloads:
callback(void (*f)(A...));
callback(const Callback<R(A...)> &);
callback(T *t, void (*f)(T*, A...));
callback(const T *t, void (*f)(const T*, A...));
callback(volatile T *t, void (*f)(volatile T*, A...));
callback(const volatile T *t, void (*f)(const volatile T*, A...));
callback(T *t, void (T::*f)(A...));
callback(const T *t, void (T::*f)(A...) const);
callback(volatile T *t, void (T::*f)(A...) volatile);
callback(const volatile T *t, void (T::*f)(A...) const volatile);
2016-08-18 18:28:57 +00:00
|
|
|
@deprecated
|
2016-08-25 18:08:35 +00:00
|
|
|
The start function does not support cv-qualifiers. Replaced by start(callback(obj, method)).
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2016-06-01 17:11:05 +00:00
|
|
|
*/
|
|
|
|
template <typename T, typename M>
|
Added support for cv-qualifiers in Callback class
Additionally, the following changes were don to avoid combinatorial
explosion in function overloads as a result of adding cv-qualifiers:
- Added convenience function for inferred type
- Deprecated callback overloads qhere cv-qualifiers are not scalable
Supported overloads:
callback(void (*f)(A...));
callback(const Callback<R(A...)> &);
callback(T *t, void (*f)(T*, A...));
callback(const T *t, void (*f)(const T*, A...));
callback(volatile T *t, void (*f)(volatile T*, A...));
callback(const volatile T *t, void (*f)(const volatile T*, A...));
callback(T *t, void (T::*f)(A...));
callback(const T *t, void (T::*f)(A...) const);
callback(volatile T *t, void (T::*f)(A...) volatile);
callback(const volatile T *t, void (T::*f)(A...) const volatile);
2016-08-18 18:28:57 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2018-08-27 09:23:50 +00:00
|
|
|
"The start function does not support cv-qualifiers. "
|
|
|
|
"Replaced by thread.start(callback(obj, method)).")
|
|
|
|
osStatus start(T *obj, M method)
|
|
|
|
{
|
Added support for cv-qualifiers in Callback class
Additionally, the following changes were don to avoid combinatorial
explosion in function overloads as a result of adding cv-qualifiers:
- Added convenience function for inferred type
- Deprecated callback overloads qhere cv-qualifiers are not scalable
Supported overloads:
callback(void (*f)(A...));
callback(const Callback<R(A...)> &);
callback(T *t, void (*f)(T*, A...));
callback(const T *t, void (*f)(const T*, A...));
callback(volatile T *t, void (*f)(volatile T*, A...));
callback(const volatile T *t, void (*f)(const volatile T*, A...));
callback(T *t, void (T::*f)(A...));
callback(const T *t, void (T::*f)(A...) const);
callback(volatile T *t, void (T::*f)(A...) volatile);
callback(const volatile T *t, void (T::*f)(A...) const volatile);
2016-08-18 18:28:57 +00:00
|
|
|
return start(mbed::callback(obj, method));
|
2016-06-01 17:11:05 +00:00
|
|
|
}
|
2016-04-22 06:03:53 +00:00
|
|
|
|
|
|
|
/** Wait for thread to terminate
|
|
|
|
@return status code that indicates the execution status of the function.
|
|
|
|
@note not callable from interrupt
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2016-04-22 06:03:53 +00:00
|
|
|
*/
|
|
|
|
osStatus join();
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
/** Terminate execution of a thread and remove it from Active Threads
|
|
|
|
@return status code that indicates the execution status of the function.
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
|
|
|
osStatus terminate();
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
/** Set priority of an active thread
|
|
|
|
@param priority new priority value for the thread function.
|
|
|
|
@return status code that indicates the execution status of the function.
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
|
|
|
osStatus set_priority(osPriority priority);
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
/** Get priority of an active thread
|
|
|
|
@return current priority value of the thread function.
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
|
|
|
osPriority get_priority();
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2017-06-21 10:32:02 +00:00
|
|
|
/** Set the specified Thread Flags for the thread.
|
2013-02-18 15:32:11 +00:00
|
|
|
@param signals specifies the signal flags of the thread that should be set.
|
2017-09-14 09:00:09 +00:00
|
|
|
@return signal flags after setting or osFlagsError in case of incorrect parameters.
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You may call this function from ISR context.
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
|
|
|
int32_t signal_set(int32_t signals);
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
/** State of the Thread */
|
|
|
|
enum State {
|
2017-06-22 10:50:22 +00:00
|
|
|
Inactive, /**< NOT USED */
|
2013-02-18 15:32:11 +00:00
|
|
|
Ready, /**< Ready to run */
|
|
|
|
Running, /**< Running */
|
|
|
|
WaitingDelay, /**< Waiting for a delay to occur */
|
2017-06-22 10:50:22 +00:00
|
|
|
WaitingJoin, /**< Waiting for thread to join. Only happens when using RTX directly. */
|
2017-05-15 14:55:45 +00:00
|
|
|
WaitingThreadFlag, /**< Waiting for a thread flag to be set */
|
|
|
|
WaitingEventFlag, /**< Waiting for a event flag to be set */
|
|
|
|
WaitingMutex, /**< Waiting for a mutex event to occur */
|
|
|
|
WaitingSemaphore, /**< Waiting for a semaphore event to occur */
|
|
|
|
WaitingMemoryPool, /**< Waiting for a memory pool */
|
|
|
|
WaitingMessageGet, /**< Waiting for message to arrive */
|
|
|
|
WaitingMessagePut, /**< Waiting for message to be send */
|
2017-06-22 10:50:22 +00:00
|
|
|
WaitingInterval, /**< NOT USED */
|
|
|
|
WaitingOr, /**< NOT USED */
|
|
|
|
WaitingAnd, /**< NOT USED */
|
|
|
|
WaitingMailbox, /**< NOT USED (Mail is implemented as MemoryPool and Queue) */
|
2016-08-01 20:07:49 +00:00
|
|
|
|
|
|
|
/* Not in sync with RTX below here */
|
2017-06-22 10:50:22 +00:00
|
|
|
Deleted, /**< The task has been deleted or not started */
|
2013-02-18 15:32:11 +00:00
|
|
|
};
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
/** State of this Thread
|
|
|
|
@return the State of this Thread
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
|
|
|
State get_state();
|
2018-08-27 09:23:50 +00:00
|
|
|
|
2015-05-27 17:43:55 +00:00
|
|
|
/** Get the total stack memory size for this Thread
|
|
|
|
@return the total stack memory size in bytes
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2015-05-27 17:43:55 +00:00
|
|
|
*/
|
|
|
|
uint32_t stack_size();
|
2018-08-27 09:23:50 +00:00
|
|
|
|
2015-05-27 17:43:55 +00:00
|
|
|
/** Get the currently unused stack memory for this Thread
|
|
|
|
@return the currently unused stack memory in bytes
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2015-05-27 17:43:55 +00:00
|
|
|
*/
|
|
|
|
uint32_t free_stack();
|
2018-08-27 09:23:50 +00:00
|
|
|
|
2015-05-27 17:43:55 +00:00
|
|
|
/** Get the currently used stack memory for this Thread
|
|
|
|
@return the currently used stack memory in bytes
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2015-05-27 17:43:55 +00:00
|
|
|
*/
|
|
|
|
uint32_t used_stack();
|
2018-08-27 09:23:50 +00:00
|
|
|
|
2015-05-27 17:43:55 +00:00
|
|
|
/** Get the maximum stack memory usage to date for this Thread
|
|
|
|
@return the maximum stack memory usage to date in bytes
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2015-05-27 17:43:55 +00:00
|
|
|
*/
|
|
|
|
uint32_t max_stack();
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2017-05-15 14:55:45 +00:00
|
|
|
/** Get thread name
|
|
|
|
@return thread name or NULL if the name was not set.
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You may call this function from ISR context.
|
2017-05-15 14:55:45 +00:00
|
|
|
*/
|
|
|
|
const char *get_name();
|
|
|
|
|
2017-06-21 10:32:02 +00:00
|
|
|
/** Clears the specified Thread Flags of the currently running thread.
|
|
|
|
@param signals specifies the signal flags of the thread that should be cleared.
|
2017-09-14 09:00:09 +00:00
|
|
|
@return signal flags before clearing or osFlagsError in case of incorrect parameters.
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2017-06-21 10:32:02 +00:00
|
|
|
*/
|
|
|
|
static int32_t signal_clr(int32_t signals);
|
|
|
|
|
|
|
|
/** Wait for one or more Thread Flags to become signaled for the current RUNNING thread.
|
2017-05-15 14:55:45 +00:00
|
|
|
@param signals wait until all specified signal flags are set or 0 for any single signal flag.
|
2013-02-18 15:32:11 +00:00
|
|
|
@param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
|
2017-06-21 10:32:02 +00:00
|
|
|
@return event flag information or error code. @note if @a millisec is set to 0 and flag is no set the event carries osOK value.
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
2018-08-27 09:23:50 +00:00
|
|
|
static osEvent signal_wait(int32_t signals, uint32_t millisec = osWaitForever);
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2017-11-10 15:49:00 +00:00
|
|
|
/** Wait for a specified time period in milliseconds
|
|
|
|
Being tick-based, the delay will be up to the specified time - eg for
|
|
|
|
a value of 1 the system waits until the next millisecond tick occurs,
|
|
|
|
leading to a delay of 0-1 milliseconds.
|
2013-02-18 15:32:11 +00:00
|
|
|
@param millisec time delay value
|
2014-05-29 13:36:51 +00:00
|
|
|
@return status code that indicates the execution status of the function.
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
|
|
|
static osStatus wait(uint32_t millisec);
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2017-11-10 15:49:00 +00:00
|
|
|
/** Wait until a specified time in millisec
|
|
|
|
The specified time is according to Kernel::get_ms_count().
|
|
|
|
@param millisec absolute time in millisec
|
|
|
|
@return status code that indicates the execution status of the function.
|
|
|
|
@note not callable from interrupt
|
|
|
|
@note if millisec is equal to or lower than the current tick count, this
|
|
|
|
returns immediately, either with an error or "osOK".
|
|
|
|
@note the underlying RTOS may have a limit to the maximum wait time
|
|
|
|
due to internal 32-bit computations, but this is guaranteed to work if the
|
|
|
|
delay is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded,
|
|
|
|
it may return with an immediate error, or wait for the maximum delay.
|
|
|
|
|
|
|
|
@note You cannot call this function from ISR context.
|
|
|
|
*/
|
|
|
|
static osStatus wait_until(uint64_t millisec);
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
/** Pass control to next thread that is in state READY.
|
|
|
|
@return status code that indicates the execution status of the function.
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You cannot call this function from ISR context.
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
|
|
|
static osStatus yield();
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
/** Get the thread id of the current running thread.
|
|
|
|
@return thread ID for reference by other functions or NULL in case of error.
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You may call this function from ISR context.
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
|
|
|
static osThreadId gettid();
|
2017-05-15 14:55:45 +00:00
|
|
|
|
2016-03-08 16:48:02 +00:00
|
|
|
/** Attach a function to be called by the RTOS idle task
|
|
|
|
@param fptr pointer to the function to be called
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You may call this function from ISR context.
|
2016-03-08 16:48:02 +00:00
|
|
|
*/
|
|
|
|
static void attach_idle_hook(void (*fptr)(void));
|
2014-05-29 13:36:51 +00:00
|
|
|
|
2016-09-07 05:19:48 +00:00
|
|
|
/** Attach a function to be called when a task is killed
|
|
|
|
@param fptr pointer to the function to be called
|
2017-12-27 14:46:00 +00:00
|
|
|
|
2018-01-09 00:01:02 +00:00
|
|
|
@note You may call this function from ISR context.
|
2016-09-07 05:19:48 +00:00
|
|
|
*/
|
|
|
|
static void attach_terminate_hook(void (*fptr)(osThreadId id));
|
|
|
|
|
2017-12-27 14:46:00 +00:00
|
|
|
/** Thread destructor
|
|
|
|
*
|
2018-01-09 00:01:02 +00:00
|
|
|
* @note You cannot call this function from ISR context.
|
2017-12-27 14:46:00 +00:00
|
|
|
*/
|
2013-02-18 15:32:11 +00:00
|
|
|
virtual ~Thread();
|
|
|
|
|
|
|
|
private:
|
2016-05-15 21:50:45 +00:00
|
|
|
// Required to share definitions without
|
|
|
|
// delegated constructors
|
2018-08-27 09:23:50 +00:00
|
|
|
void constructor(osPriority priority = osPriorityNormal,
|
|
|
|
uint32_t stack_size = OS_STACK_SIZE,
|
|
|
|
unsigned char *stack_mem = NULL,
|
|
|
|
const char *name = NULL);
|
2016-05-15 21:50:45 +00:00
|
|
|
void constructor(mbed::Callback<void()> task,
|
2018-08-27 09:23:50 +00:00
|
|
|
osPriority priority = osPriorityNormal,
|
|
|
|
uint32_t stack_size = OS_STACK_SIZE,
|
|
|
|
unsigned char *stack_mem = NULL,
|
|
|
|
const char *name = NULL);
|
2018-03-29 21:48:53 +00:00
|
|
|
void constructor(uint32_t tz_module,
|
2018-08-27 09:23:50 +00:00
|
|
|
osPriority priority = osPriorityNormal,
|
|
|
|
uint32_t stack_size = OS_STACK_SIZE,
|
|
|
|
unsigned char *stack_mem = NULL,
|
|
|
|
const char *name = NULL);
|
|
|
|
static void _thunk(void *thread_ptr);
|
2017-05-15 14:55:45 +00:00
|
|
|
|
|
|
|
mbed::Callback<void()> _task;
|
|
|
|
osThreadId_t _tid;
|
|
|
|
osThreadAttr_t _attr;
|
|
|
|
bool _dynamic_stack;
|
|
|
|
Semaphore _join_sem;
|
|
|
|
Mutex _mutex;
|
|
|
|
mbed_rtos_storage_thread_t _obj_mem;
|
|
|
|
bool _finished;
|
2013-02-18 15:32:11 +00:00
|
|
|
};
|
2017-10-24 15:05:45 +00:00
|
|
|
/** @}*/
|
|
|
|
/** @}*/
|
2013-02-18 15:32:11 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-10-04 20:02:44 +00:00
|
|
|
|
2017-10-24 15:05:45 +00:00
|
|
|
|