takashi kadono
/
Nucleo_446
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/rtos/Thread.h@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2006-2012 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
kadonotakashi | 0:8fdf9a60065b | 5 | * of this software and associated documentation files (the "Software"), to deal |
kadonotakashi | 0:8fdf9a60065b | 6 | * in the Software without restriction, including without limitation the rights |
kadonotakashi | 0:8fdf9a60065b | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
kadonotakashi | 0:8fdf9a60065b | 8 | * copies of the Software, and to permit persons to whom the Software is |
kadonotakashi | 0:8fdf9a60065b | 9 | * furnished to do so, subject to the following conditions: |
kadonotakashi | 0:8fdf9a60065b | 10 | * |
kadonotakashi | 0:8fdf9a60065b | 11 | * The above copyright notice and this permission notice shall be included in |
kadonotakashi | 0:8fdf9a60065b | 12 | * all copies or substantial portions of the Software. |
kadonotakashi | 0:8fdf9a60065b | 13 | * |
kadonotakashi | 0:8fdf9a60065b | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
kadonotakashi | 0:8fdf9a60065b | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
kadonotakashi | 0:8fdf9a60065b | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
kadonotakashi | 0:8fdf9a60065b | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
kadonotakashi | 0:8fdf9a60065b | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kadonotakashi | 0:8fdf9a60065b | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
kadonotakashi | 0:8fdf9a60065b | 20 | * SOFTWARE. |
kadonotakashi | 0:8fdf9a60065b | 21 | */ |
kadonotakashi | 0:8fdf9a60065b | 22 | #ifndef THREAD_H |
kadonotakashi | 0:8fdf9a60065b | 23 | #define THREAD_H |
kadonotakashi | 0:8fdf9a60065b | 24 | |
kadonotakashi | 0:8fdf9a60065b | 25 | #include <stdint.h> |
kadonotakashi | 0:8fdf9a60065b | 26 | #include "cmsis_os2.h" |
kadonotakashi | 0:8fdf9a60065b | 27 | #include "mbed_rtos1_types.h" |
kadonotakashi | 0:8fdf9a60065b | 28 | #include "mbed_rtos_storage.h" |
kadonotakashi | 0:8fdf9a60065b | 29 | #include "platform/Callback.h" |
kadonotakashi | 0:8fdf9a60065b | 30 | #include "platform/mbed_toolchain.h" |
kadonotakashi | 0:8fdf9a60065b | 31 | #include "platform/NonCopyable.h" |
kadonotakashi | 0:8fdf9a60065b | 32 | #include "rtos/Semaphore.h" |
kadonotakashi | 0:8fdf9a60065b | 33 | #include "rtos/Mutex.h" |
kadonotakashi | 0:8fdf9a60065b | 34 | |
kadonotakashi | 0:8fdf9a60065b | 35 | namespace rtos { |
kadonotakashi | 0:8fdf9a60065b | 36 | /** \addtogroup rtos */ |
kadonotakashi | 0:8fdf9a60065b | 37 | /** @{*/ |
kadonotakashi | 0:8fdf9a60065b | 38 | /** |
kadonotakashi | 0:8fdf9a60065b | 39 | * \defgroup rtos_Thread Thread class |
kadonotakashi | 0:8fdf9a60065b | 40 | * @{ |
kadonotakashi | 0:8fdf9a60065b | 41 | */ |
kadonotakashi | 0:8fdf9a60065b | 42 | |
kadonotakashi | 0:8fdf9a60065b | 43 | /** The Thread class allow defining, creating, and controlling thread functions in the system. |
kadonotakashi | 0:8fdf9a60065b | 44 | * |
kadonotakashi | 0:8fdf9a60065b | 45 | * Example: |
kadonotakashi | 0:8fdf9a60065b | 46 | * @code |
kadonotakashi | 0:8fdf9a60065b | 47 | * #include "mbed.h" |
kadonotakashi | 0:8fdf9a60065b | 48 | * #include "rtos.h" |
kadonotakashi | 0:8fdf9a60065b | 49 | * |
kadonotakashi | 0:8fdf9a60065b | 50 | * Thread thread; |
kadonotakashi | 0:8fdf9a60065b | 51 | * DigitalOut led1(LED1); |
kadonotakashi | 0:8fdf9a60065b | 52 | * volatile bool running = true; |
kadonotakashi | 0:8fdf9a60065b | 53 | * |
kadonotakashi | 0:8fdf9a60065b | 54 | * // Blink function toggles the led in a long running loop |
kadonotakashi | 0:8fdf9a60065b | 55 | * void blink(DigitalOut *led) { |
kadonotakashi | 0:8fdf9a60065b | 56 | * while (running) { |
kadonotakashi | 0:8fdf9a60065b | 57 | * *led = !*led; |
kadonotakashi | 0:8fdf9a60065b | 58 | * wait(1); |
kadonotakashi | 0:8fdf9a60065b | 59 | * } |
kadonotakashi | 0:8fdf9a60065b | 60 | * } |
kadonotakashi | 0:8fdf9a60065b | 61 | * |
kadonotakashi | 0:8fdf9a60065b | 62 | * // Spawns a thread to run blink for 5 seconds |
kadonotakashi | 0:8fdf9a60065b | 63 | * int main() { |
kadonotakashi | 0:8fdf9a60065b | 64 | * thread.start(callback(blink, &led1)); |
kadonotakashi | 0:8fdf9a60065b | 65 | * wait(5); |
kadonotakashi | 0:8fdf9a60065b | 66 | * running = false; |
kadonotakashi | 0:8fdf9a60065b | 67 | * thread.join(); |
kadonotakashi | 0:8fdf9a60065b | 68 | * } |
kadonotakashi | 0:8fdf9a60065b | 69 | * @endcode |
kadonotakashi | 0:8fdf9a60065b | 70 | * |
kadonotakashi | 0:8fdf9a60065b | 71 | * @note |
kadonotakashi | 0:8fdf9a60065b | 72 | * Memory considerations: The thread control structures will be created on current thread's stack, both for the mbed OS |
kadonotakashi | 0:8fdf9a60065b | 73 | * and underlying RTOS objects (static or dynamic RTOS memory pools are not being used). |
kadonotakashi | 0:8fdf9a60065b | 74 | * Additionally the stack memory for this thread will be allocated on the heap, if it wasn't supplied to the constructor. |
kadonotakashi | 0:8fdf9a60065b | 75 | * |
kadonotakashi | 0:8fdf9a60065b | 76 | * @note |
kadonotakashi | 0:8fdf9a60065b | 77 | * MBED_TZ_DEFAULT_ACCESS (default:0) flag can be used to change the default access of all user threads in non-secure mode. |
kadonotakashi | 0:8fdf9a60065b | 78 | * MBED_TZ_DEFAULT_ACCESS set to 1, means all non-secure user threads have access to call secure functions. |
kadonotakashi | 0:8fdf9a60065b | 79 | * MBED_TZ_DEFAULT_ACCESS set to 0, means none of the non-secure user thread have access to call secure functions, |
kadonotakashi | 0:8fdf9a60065b | 80 | * to give access to particular thread used overloaded constructor with `tz_module` as argument during thread creation. |
kadonotakashi | 0:8fdf9a60065b | 81 | * |
kadonotakashi | 0:8fdf9a60065b | 82 | * MBED_TZ_DEFAULT_ACCESS is target specific define, should be set in targets.json file for Cortex-M23/M33 devices. |
kadonotakashi | 0:8fdf9a60065b | 83 | */ |
kadonotakashi | 0:8fdf9a60065b | 84 | |
kadonotakashi | 0:8fdf9a60065b | 85 | class Thread : private mbed::NonCopyable<Thread> { |
kadonotakashi | 0:8fdf9a60065b | 86 | public: |
kadonotakashi | 0:8fdf9a60065b | 87 | /** Allocate a new thread without starting execution |
kadonotakashi | 0:8fdf9a60065b | 88 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
kadonotakashi | 0:8fdf9a60065b | 89 | @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
kadonotakashi | 0:8fdf9a60065b | 90 | @param stack_mem pointer to the stack area to be used by this thread (default: NULL). |
kadonotakashi | 0:8fdf9a60065b | 91 | @param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: NULL) |
kadonotakashi | 0:8fdf9a60065b | 92 | |
kadonotakashi | 0:8fdf9a60065b | 93 | @note Default value of tz_module will be MBED_TZ_DEFAULT_ACCESS |
kadonotakashi | 0:8fdf9a60065b | 94 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 95 | */ |
kadonotakashi | 0:8fdf9a60065b | 96 | |
kadonotakashi | 0:8fdf9a60065b | 97 | Thread(osPriority priority = osPriorityNormal, |
kadonotakashi | 0:8fdf9a60065b | 98 | uint32_t stack_size = OS_STACK_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 99 | unsigned char *stack_mem = NULL, const char *name = NULL) |
kadonotakashi | 0:8fdf9a60065b | 100 | { |
kadonotakashi | 0:8fdf9a60065b | 101 | constructor(priority, stack_size, stack_mem, name); |
kadonotakashi | 0:8fdf9a60065b | 102 | } |
kadonotakashi | 0:8fdf9a60065b | 103 | |
kadonotakashi | 0:8fdf9a60065b | 104 | /** Allocate a new thread without starting execution |
kadonotakashi | 0:8fdf9a60065b | 105 | @param tz_module trustzone thread identifier (osThreadAttr_t::tz_module) |
kadonotakashi | 0:8fdf9a60065b | 106 | Context of RTOS threads in non-secure state must be saved when calling secure functions. |
kadonotakashi | 0:8fdf9a60065b | 107 | tz_module ID is used to allocate context memory for threads, and it can be safely set to zero for |
kadonotakashi | 0:8fdf9a60065b | 108 | threads not using secure calls at all. See "TrustZone RTOS Context Management" for more details. |
kadonotakashi | 0:8fdf9a60065b | 109 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
kadonotakashi | 0:8fdf9a60065b | 110 | @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
kadonotakashi | 0:8fdf9a60065b | 111 | @param stack_mem pointer to the stack area to be used by this thread (default: NULL). |
kadonotakashi | 0:8fdf9a60065b | 112 | @param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: NULL) |
kadonotakashi | 0:8fdf9a60065b | 113 | |
kadonotakashi | 0:8fdf9a60065b | 114 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 115 | */ |
kadonotakashi | 0:8fdf9a60065b | 116 | |
kadonotakashi | 0:8fdf9a60065b | 117 | Thread(uint32_t tz_module, osPriority priority = osPriorityNormal, |
kadonotakashi | 0:8fdf9a60065b | 118 | uint32_t stack_size = OS_STACK_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 119 | unsigned char *stack_mem = NULL, const char *name = NULL) |
kadonotakashi | 0:8fdf9a60065b | 120 | { |
kadonotakashi | 0:8fdf9a60065b | 121 | constructor(tz_module, priority, stack_size, stack_mem, name); |
kadonotakashi | 0:8fdf9a60065b | 122 | } |
kadonotakashi | 0:8fdf9a60065b | 123 | |
kadonotakashi | 0:8fdf9a60065b | 124 | |
kadonotakashi | 0:8fdf9a60065b | 125 | /** Create a new thread, and start it executing the specified function. |
kadonotakashi | 0:8fdf9a60065b | 126 | @param task function to be executed by this thread. |
kadonotakashi | 0:8fdf9a60065b | 127 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
kadonotakashi | 0:8fdf9a60065b | 128 | @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
kadonotakashi | 0:8fdf9a60065b | 129 | @param stack_mem pointer to the stack area to be used by this thread (default: NULL). |
kadonotakashi | 0:8fdf9a60065b | 130 | @deprecated |
kadonotakashi | 0:8fdf9a60065b | 131 | Thread-spawning constructors hide errors. Replaced by thread.start(task). |
kadonotakashi | 0:8fdf9a60065b | 132 | |
kadonotakashi | 0:8fdf9a60065b | 133 | @code |
kadonotakashi | 0:8fdf9a60065b | 134 | Thread thread(priority, stack_size, stack_mem); |
kadonotakashi | 0:8fdf9a60065b | 135 | |
kadonotakashi | 0:8fdf9a60065b | 136 | osStatus status = thread.start(task); |
kadonotakashi | 0:8fdf9a60065b | 137 | if (status != osOK) { |
kadonotakashi | 0:8fdf9a60065b | 138 | error("oh no!"); |
kadonotakashi | 0:8fdf9a60065b | 139 | } |
kadonotakashi | 0:8fdf9a60065b | 140 | @endcode |
kadonotakashi | 0:8fdf9a60065b | 141 | |
kadonotakashi | 0:8fdf9a60065b | 142 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 143 | */ |
kadonotakashi | 0:8fdf9a60065b | 144 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
kadonotakashi | 0:8fdf9a60065b | 145 | "Thread-spawning constructors hide errors. " |
kadonotakashi | 0:8fdf9a60065b | 146 | "Replaced by thread.start(task).") |
kadonotakashi | 0:8fdf9a60065b | 147 | Thread(mbed::Callback<void()> task, |
kadonotakashi | 0:8fdf9a60065b | 148 | osPriority priority = osPriorityNormal, |
kadonotakashi | 0:8fdf9a60065b | 149 | uint32_t stack_size = OS_STACK_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 150 | unsigned char *stack_mem = NULL) |
kadonotakashi | 0:8fdf9a60065b | 151 | { |
kadonotakashi | 0:8fdf9a60065b | 152 | constructor(task, priority, stack_size, stack_mem); |
kadonotakashi | 0:8fdf9a60065b | 153 | } |
kadonotakashi | 0:8fdf9a60065b | 154 | |
kadonotakashi | 0:8fdf9a60065b | 155 | /** Create a new thread, and start it executing the specified function. |
kadonotakashi | 0:8fdf9a60065b | 156 | @param argument pointer that is passed to the thread function as start argument. (default: NULL). |
kadonotakashi | 0:8fdf9a60065b | 157 | @param task argument to task. |
kadonotakashi | 0:8fdf9a60065b | 158 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
kadonotakashi | 0:8fdf9a60065b | 159 | @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
kadonotakashi | 0:8fdf9a60065b | 160 | @param stack_mem pointer to the stack area to be used by this thread (default: NULL). |
kadonotakashi | 0:8fdf9a60065b | 161 | @deprecated |
kadonotakashi | 0:8fdf9a60065b | 162 | Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)). |
kadonotakashi | 0:8fdf9a60065b | 163 | |
kadonotakashi | 0:8fdf9a60065b | 164 | @code |
kadonotakashi | 0:8fdf9a60065b | 165 | Thread thread(priority, stack_size, stack_mem); |
kadonotakashi | 0:8fdf9a60065b | 166 | |
kadonotakashi | 0:8fdf9a60065b | 167 | osStatus status = thread.start(callback(task, argument)); |
kadonotakashi | 0:8fdf9a60065b | 168 | if (status != osOK) { |
kadonotakashi | 0:8fdf9a60065b | 169 | error("oh no!"); |
kadonotakashi | 0:8fdf9a60065b | 170 | } |
kadonotakashi | 0:8fdf9a60065b | 171 | @endcode |
kadonotakashi | 0:8fdf9a60065b | 172 | |
kadonotakashi | 0:8fdf9a60065b | 173 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 174 | */ |
kadonotakashi | 0:8fdf9a60065b | 175 | template <typename T> |
kadonotakashi | 0:8fdf9a60065b | 176 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
kadonotakashi | 0:8fdf9a60065b | 177 | "Thread-spawning constructors hide errors. " |
kadonotakashi | 0:8fdf9a60065b | 178 | "Replaced by thread.start(callback(task, argument)).") |
kadonotakashi | 0:8fdf9a60065b | 179 | Thread(T *argument, void (T::*task)(), |
kadonotakashi | 0:8fdf9a60065b | 180 | osPriority priority = osPriorityNormal, |
kadonotakashi | 0:8fdf9a60065b | 181 | uint32_t stack_size = OS_STACK_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 182 | unsigned char *stack_mem = NULL) |
kadonotakashi | 0:8fdf9a60065b | 183 | { |
kadonotakashi | 0:8fdf9a60065b | 184 | constructor(mbed::callback(task, argument), |
kadonotakashi | 0:8fdf9a60065b | 185 | priority, stack_size, stack_mem); |
kadonotakashi | 0:8fdf9a60065b | 186 | } |
kadonotakashi | 0:8fdf9a60065b | 187 | |
kadonotakashi | 0:8fdf9a60065b | 188 | /** Create a new thread, and start it executing the specified function. |
kadonotakashi | 0:8fdf9a60065b | 189 | @param argument pointer that is passed to the thread function as start argument. (default: NULL). |
kadonotakashi | 0:8fdf9a60065b | 190 | @param task argument to task. |
kadonotakashi | 0:8fdf9a60065b | 191 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
kadonotakashi | 0:8fdf9a60065b | 192 | @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
kadonotakashi | 0:8fdf9a60065b | 193 | @param stack_mem pointer to the stack area to be used by this thread (default: NULL). |
kadonotakashi | 0:8fdf9a60065b | 194 | @deprecated |
kadonotakashi | 0:8fdf9a60065b | 195 | Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)). |
kadonotakashi | 0:8fdf9a60065b | 196 | |
kadonotakashi | 0:8fdf9a60065b | 197 | @code |
kadonotakashi | 0:8fdf9a60065b | 198 | Thread thread(priority, stack_size, stack_mem); |
kadonotakashi | 0:8fdf9a60065b | 199 | |
kadonotakashi | 0:8fdf9a60065b | 200 | osStatus status = thread.start(callback(task, argument)); |
kadonotakashi | 0:8fdf9a60065b | 201 | if (status != osOK) { |
kadonotakashi | 0:8fdf9a60065b | 202 | error("oh no!"); |
kadonotakashi | 0:8fdf9a60065b | 203 | } |
kadonotakashi | 0:8fdf9a60065b | 204 | @endcode |
kadonotakashi | 0:8fdf9a60065b | 205 | |
kadonotakashi | 0:8fdf9a60065b | 206 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 207 | */ |
kadonotakashi | 0:8fdf9a60065b | 208 | template <typename T> |
kadonotakashi | 0:8fdf9a60065b | 209 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
kadonotakashi | 0:8fdf9a60065b | 210 | "Thread-spawning constructors hide errors. " |
kadonotakashi | 0:8fdf9a60065b | 211 | "Replaced by thread.start(callback(task, argument)).") |
kadonotakashi | 0:8fdf9a60065b | 212 | Thread(T *argument, void (*task)(T *), |
kadonotakashi | 0:8fdf9a60065b | 213 | osPriority priority = osPriorityNormal, |
kadonotakashi | 0:8fdf9a60065b | 214 | uint32_t stack_size = OS_STACK_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 215 | unsigned char *stack_mem = NULL) |
kadonotakashi | 0:8fdf9a60065b | 216 | { |
kadonotakashi | 0:8fdf9a60065b | 217 | constructor(mbed::callback(task, argument), |
kadonotakashi | 0:8fdf9a60065b | 218 | priority, stack_size, stack_mem); |
kadonotakashi | 0:8fdf9a60065b | 219 | } |
kadonotakashi | 0:8fdf9a60065b | 220 | |
kadonotakashi | 0:8fdf9a60065b | 221 | /** Create a new thread, and start it executing the specified function. |
kadonotakashi | 0:8fdf9a60065b | 222 | Provided for backwards compatibility |
kadonotakashi | 0:8fdf9a60065b | 223 | @param task function to be executed by this thread. |
kadonotakashi | 0:8fdf9a60065b | 224 | @param argument pointer that is passed to the thread function as start argument. (default: NULL). |
kadonotakashi | 0:8fdf9a60065b | 225 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
kadonotakashi | 0:8fdf9a60065b | 226 | @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE). |
kadonotakashi | 0:8fdf9a60065b | 227 | @param stack_mem pointer to the stack area to be used by this thread (default: NULL). |
kadonotakashi | 0:8fdf9a60065b | 228 | @deprecated |
kadonotakashi | 0:8fdf9a60065b | 229 | Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)). |
kadonotakashi | 0:8fdf9a60065b | 230 | |
kadonotakashi | 0:8fdf9a60065b | 231 | @code |
kadonotakashi | 0:8fdf9a60065b | 232 | Thread thread(priority, stack_size, stack_mem); |
kadonotakashi | 0:8fdf9a60065b | 233 | |
kadonotakashi | 0:8fdf9a60065b | 234 | osStatus status = thread.start(callback(task, argument)); |
kadonotakashi | 0:8fdf9a60065b | 235 | if (status != osOK) { |
kadonotakashi | 0:8fdf9a60065b | 236 | error("oh no!"); |
kadonotakashi | 0:8fdf9a60065b | 237 | } |
kadonotakashi | 0:8fdf9a60065b | 238 | @endcode |
kadonotakashi | 0:8fdf9a60065b | 239 | |
kadonotakashi | 0:8fdf9a60065b | 240 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 241 | */ |
kadonotakashi | 0:8fdf9a60065b | 242 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
kadonotakashi | 0:8fdf9a60065b | 243 | "Thread-spawning constructors hide errors. " |
kadonotakashi | 0:8fdf9a60065b | 244 | "Replaced by thread.start(callback(task, argument)).") |
kadonotakashi | 0:8fdf9a60065b | 245 | Thread(void (*task)(void const *argument), void *argument = NULL, |
kadonotakashi | 0:8fdf9a60065b | 246 | osPriority priority = osPriorityNormal, |
kadonotakashi | 0:8fdf9a60065b | 247 | uint32_t stack_size = OS_STACK_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 248 | unsigned char *stack_mem = NULL) |
kadonotakashi | 0:8fdf9a60065b | 249 | { |
kadonotakashi | 0:8fdf9a60065b | 250 | constructor(mbed::callback((void (*)(void *))task, argument), |
kadonotakashi | 0:8fdf9a60065b | 251 | priority, stack_size, stack_mem); |
kadonotakashi | 0:8fdf9a60065b | 252 | } |
kadonotakashi | 0:8fdf9a60065b | 253 | |
kadonotakashi | 0:8fdf9a60065b | 254 | /** Starts a thread executing the specified function. |
kadonotakashi | 0:8fdf9a60065b | 255 | @param task function to be executed by this thread. |
kadonotakashi | 0:8fdf9a60065b | 256 | @return status code that indicates the execution status of the function. |
kadonotakashi | 0:8fdf9a60065b | 257 | @note a thread can only be started once |
kadonotakashi | 0:8fdf9a60065b | 258 | |
kadonotakashi | 0:8fdf9a60065b | 259 | @note You cannot call this function ISR context. |
kadonotakashi | 0:8fdf9a60065b | 260 | */ |
kadonotakashi | 0:8fdf9a60065b | 261 | osStatus start(mbed::Callback<void()> task); |
kadonotakashi | 0:8fdf9a60065b | 262 | |
kadonotakashi | 0:8fdf9a60065b | 263 | /** Starts a thread executing the specified function. |
kadonotakashi | 0:8fdf9a60065b | 264 | @param obj argument to task |
kadonotakashi | 0:8fdf9a60065b | 265 | @param method function to be executed by this thread. |
kadonotakashi | 0:8fdf9a60065b | 266 | @return status code that indicates the execution status of the function. |
kadonotakashi | 0:8fdf9a60065b | 267 | @deprecated |
kadonotakashi | 0:8fdf9a60065b | 268 | The start function does not support cv-qualifiers. Replaced by start(callback(obj, method)). |
kadonotakashi | 0:8fdf9a60065b | 269 | |
kadonotakashi | 0:8fdf9a60065b | 270 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 271 | */ |
kadonotakashi | 0:8fdf9a60065b | 272 | template <typename T, typename M> |
kadonotakashi | 0:8fdf9a60065b | 273 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
kadonotakashi | 0:8fdf9a60065b | 274 | "The start function does not support cv-qualifiers. " |
kadonotakashi | 0:8fdf9a60065b | 275 | "Replaced by thread.start(callback(obj, method)).") |
kadonotakashi | 0:8fdf9a60065b | 276 | osStatus start(T *obj, M method) |
kadonotakashi | 0:8fdf9a60065b | 277 | { |
kadonotakashi | 0:8fdf9a60065b | 278 | return start(mbed::callback(obj, method)); |
kadonotakashi | 0:8fdf9a60065b | 279 | } |
kadonotakashi | 0:8fdf9a60065b | 280 | |
kadonotakashi | 0:8fdf9a60065b | 281 | /** Wait for thread to terminate |
kadonotakashi | 0:8fdf9a60065b | 282 | @return status code that indicates the execution status of the function. |
kadonotakashi | 0:8fdf9a60065b | 283 | |
kadonotakashi | 0:8fdf9a60065b | 284 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 285 | */ |
kadonotakashi | 0:8fdf9a60065b | 286 | osStatus join(); |
kadonotakashi | 0:8fdf9a60065b | 287 | |
kadonotakashi | 0:8fdf9a60065b | 288 | /** Terminate execution of a thread and remove it from Active Threads |
kadonotakashi | 0:8fdf9a60065b | 289 | @return status code that indicates the execution status of the function. |
kadonotakashi | 0:8fdf9a60065b | 290 | |
kadonotakashi | 0:8fdf9a60065b | 291 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 292 | */ |
kadonotakashi | 0:8fdf9a60065b | 293 | osStatus terminate(); |
kadonotakashi | 0:8fdf9a60065b | 294 | |
kadonotakashi | 0:8fdf9a60065b | 295 | /** Set priority of an active thread |
kadonotakashi | 0:8fdf9a60065b | 296 | @param priority new priority value for the thread function. |
kadonotakashi | 0:8fdf9a60065b | 297 | @return status code that indicates the execution status of the function. |
kadonotakashi | 0:8fdf9a60065b | 298 | |
kadonotakashi | 0:8fdf9a60065b | 299 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 300 | */ |
kadonotakashi | 0:8fdf9a60065b | 301 | osStatus set_priority(osPriority priority); |
kadonotakashi | 0:8fdf9a60065b | 302 | |
kadonotakashi | 0:8fdf9a60065b | 303 | /** Get priority of an active thread |
kadonotakashi | 0:8fdf9a60065b | 304 | @return current priority value of the thread function. |
kadonotakashi | 0:8fdf9a60065b | 305 | |
kadonotakashi | 0:8fdf9a60065b | 306 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 307 | */ |
kadonotakashi | 0:8fdf9a60065b | 308 | osPriority get_priority() const; |
kadonotakashi | 0:8fdf9a60065b | 309 | |
kadonotakashi | 0:8fdf9a60065b | 310 | /** Set the specified Thread Flags for the thread. |
kadonotakashi | 0:8fdf9a60065b | 311 | @param flags specifies the flags of the thread that should be set. |
kadonotakashi | 0:8fdf9a60065b | 312 | @return thread flags after setting or osFlagsError in case of incorrect parameters. |
kadonotakashi | 0:8fdf9a60065b | 313 | |
kadonotakashi | 0:8fdf9a60065b | 314 | @note You may call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 315 | */ |
kadonotakashi | 0:8fdf9a60065b | 316 | uint32_t flags_set(uint32_t flags); |
kadonotakashi | 0:8fdf9a60065b | 317 | |
kadonotakashi | 0:8fdf9a60065b | 318 | /** Set the specified Thread Flags for the thread. |
kadonotakashi | 0:8fdf9a60065b | 319 | @param signals specifies the signal flags of the thread that should be set. |
kadonotakashi | 0:8fdf9a60065b | 320 | @return signal flags after setting or osFlagsError in case of incorrect parameters. |
kadonotakashi | 0:8fdf9a60065b | 321 | |
kadonotakashi | 0:8fdf9a60065b | 322 | @note You may call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 323 | @deprecated Other signal_xxx methods have been deprecated in favour of ThisThread::flags functions. |
kadonotakashi | 0:8fdf9a60065b | 324 | To match this naming scheme, derived from CMSIS-RTOS2, Thread::flags_set is now provided. |
kadonotakashi | 0:8fdf9a60065b | 325 | */ |
kadonotakashi | 0:8fdf9a60065b | 326 | MBED_DEPRECATED_SINCE("mbed-os-5.10", |
kadonotakashi | 0:8fdf9a60065b | 327 | "Other signal_xxx methods have been deprecated in favour of ThisThread::flags functions. " |
kadonotakashi | 0:8fdf9a60065b | 328 | "To match this naming scheme, derived from CMSIS-RTOS2, Thread::flags_set is now provided.") |
kadonotakashi | 0:8fdf9a60065b | 329 | int32_t signal_set(int32_t signals); |
kadonotakashi | 0:8fdf9a60065b | 330 | |
kadonotakashi | 0:8fdf9a60065b | 331 | /** State of the Thread */ |
kadonotakashi | 0:8fdf9a60065b | 332 | enum State { |
kadonotakashi | 0:8fdf9a60065b | 333 | Inactive, /**< NOT USED */ |
kadonotakashi | 0:8fdf9a60065b | 334 | Ready, /**< Ready to run */ |
kadonotakashi | 0:8fdf9a60065b | 335 | Running, /**< Running */ |
kadonotakashi | 0:8fdf9a60065b | 336 | WaitingDelay, /**< Waiting for a delay to occur */ |
kadonotakashi | 0:8fdf9a60065b | 337 | WaitingJoin, /**< Waiting for thread to join. Only happens when using RTX directly. */ |
kadonotakashi | 0:8fdf9a60065b | 338 | WaitingThreadFlag, /**< Waiting for a thread flag to be set */ |
kadonotakashi | 0:8fdf9a60065b | 339 | WaitingEventFlag, /**< Waiting for a event flag to be set */ |
kadonotakashi | 0:8fdf9a60065b | 340 | WaitingMutex, /**< Waiting for a mutex event to occur */ |
kadonotakashi | 0:8fdf9a60065b | 341 | WaitingSemaphore, /**< Waiting for a semaphore event to occur */ |
kadonotakashi | 0:8fdf9a60065b | 342 | WaitingMemoryPool, /**< Waiting for a memory pool */ |
kadonotakashi | 0:8fdf9a60065b | 343 | WaitingMessageGet, /**< Waiting for message to arrive */ |
kadonotakashi | 0:8fdf9a60065b | 344 | WaitingMessagePut, /**< Waiting for message to be send */ |
kadonotakashi | 0:8fdf9a60065b | 345 | WaitingInterval, /**< NOT USED */ |
kadonotakashi | 0:8fdf9a60065b | 346 | WaitingOr, /**< NOT USED */ |
kadonotakashi | 0:8fdf9a60065b | 347 | WaitingAnd, /**< NOT USED */ |
kadonotakashi | 0:8fdf9a60065b | 348 | WaitingMailbox, /**< NOT USED (Mail is implemented as MemoryPool and Queue) */ |
kadonotakashi | 0:8fdf9a60065b | 349 | |
kadonotakashi | 0:8fdf9a60065b | 350 | /* Not in sync with RTX below here */ |
kadonotakashi | 0:8fdf9a60065b | 351 | Deleted, /**< The task has been deleted or not started */ |
kadonotakashi | 0:8fdf9a60065b | 352 | }; |
kadonotakashi | 0:8fdf9a60065b | 353 | |
kadonotakashi | 0:8fdf9a60065b | 354 | /** State of this Thread |
kadonotakashi | 0:8fdf9a60065b | 355 | @return the State of this Thread |
kadonotakashi | 0:8fdf9a60065b | 356 | |
kadonotakashi | 0:8fdf9a60065b | 357 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 358 | */ |
kadonotakashi | 0:8fdf9a60065b | 359 | State get_state() const; |
kadonotakashi | 0:8fdf9a60065b | 360 | |
kadonotakashi | 0:8fdf9a60065b | 361 | /** Get the total stack memory size for this Thread |
kadonotakashi | 0:8fdf9a60065b | 362 | @return the total stack memory size in bytes |
kadonotakashi | 0:8fdf9a60065b | 363 | |
kadonotakashi | 0:8fdf9a60065b | 364 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 365 | */ |
kadonotakashi | 0:8fdf9a60065b | 366 | uint32_t stack_size() const; |
kadonotakashi | 0:8fdf9a60065b | 367 | |
kadonotakashi | 0:8fdf9a60065b | 368 | /** Get the currently unused stack memory for this Thread |
kadonotakashi | 0:8fdf9a60065b | 369 | @return the currently unused stack memory in bytes |
kadonotakashi | 0:8fdf9a60065b | 370 | |
kadonotakashi | 0:8fdf9a60065b | 371 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 372 | */ |
kadonotakashi | 0:8fdf9a60065b | 373 | uint32_t free_stack() const; |
kadonotakashi | 0:8fdf9a60065b | 374 | |
kadonotakashi | 0:8fdf9a60065b | 375 | /** Get the currently used stack memory for this Thread |
kadonotakashi | 0:8fdf9a60065b | 376 | @return the currently used stack memory in bytes |
kadonotakashi | 0:8fdf9a60065b | 377 | |
kadonotakashi | 0:8fdf9a60065b | 378 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 379 | */ |
kadonotakashi | 0:8fdf9a60065b | 380 | uint32_t used_stack() const; |
kadonotakashi | 0:8fdf9a60065b | 381 | |
kadonotakashi | 0:8fdf9a60065b | 382 | /** Get the maximum stack memory usage to date for this Thread |
kadonotakashi | 0:8fdf9a60065b | 383 | @return the maximum stack memory usage to date in bytes |
kadonotakashi | 0:8fdf9a60065b | 384 | |
kadonotakashi | 0:8fdf9a60065b | 385 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 386 | */ |
kadonotakashi | 0:8fdf9a60065b | 387 | uint32_t max_stack() const; |
kadonotakashi | 0:8fdf9a60065b | 388 | |
kadonotakashi | 0:8fdf9a60065b | 389 | /** Get thread name |
kadonotakashi | 0:8fdf9a60065b | 390 | @return thread name or NULL if the name was not set. |
kadonotakashi | 0:8fdf9a60065b | 391 | |
kadonotakashi | 0:8fdf9a60065b | 392 | @note You may call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 393 | */ |
kadonotakashi | 0:8fdf9a60065b | 394 | const char *get_name() const; |
kadonotakashi | 0:8fdf9a60065b | 395 | |
kadonotakashi | 0:8fdf9a60065b | 396 | /** Get thread id |
kadonotakashi | 0:8fdf9a60065b | 397 | @return thread ID for reference by other functions. |
kadonotakashi | 0:8fdf9a60065b | 398 | |
kadonotakashi | 0:8fdf9a60065b | 399 | @note You may call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 400 | */ |
kadonotakashi | 0:8fdf9a60065b | 401 | osThreadId_t get_id() const; |
kadonotakashi | 0:8fdf9a60065b | 402 | |
kadonotakashi | 0:8fdf9a60065b | 403 | /** Clears the specified Thread Flags of the currently running thread. |
kadonotakashi | 0:8fdf9a60065b | 404 | @param signals specifies the signal flags of the thread that should be cleared. |
kadonotakashi | 0:8fdf9a60065b | 405 | @return signal flags before clearing or osFlagsError in case of incorrect parameters. |
kadonotakashi | 0:8fdf9a60065b | 406 | |
kadonotakashi | 0:8fdf9a60065b | 407 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 408 | @deprecated Static methods only affecting current thread cause confusion. Replaced by ThisThread::flags_clear. |
kadonotakashi | 0:8fdf9a60065b | 409 | */ |
kadonotakashi | 0:8fdf9a60065b | 410 | MBED_DEPRECATED_SINCE("mbed-os-5.10", |
kadonotakashi | 0:8fdf9a60065b | 411 | "Static methods only affecting current thread cause confusion. " |
kadonotakashi | 0:8fdf9a60065b | 412 | "Replaced by ThisThread::flags_clear.") |
kadonotakashi | 0:8fdf9a60065b | 413 | static int32_t signal_clr(int32_t signals); |
kadonotakashi | 0:8fdf9a60065b | 414 | |
kadonotakashi | 0:8fdf9a60065b | 415 | /** Wait for one or more Thread Flags to become signaled for the current RUNNING thread. |
kadonotakashi | 0:8fdf9a60065b | 416 | @param signals wait until all specified signal flags are set or 0 for any single signal flag. |
kadonotakashi | 0:8fdf9a60065b | 417 | @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever). |
kadonotakashi | 0:8fdf9a60065b | 418 | @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. |
kadonotakashi | 0:8fdf9a60065b | 419 | |
kadonotakashi | 0:8fdf9a60065b | 420 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 421 | @deprecated Static methods only affecting current thread cause confusion. |
kadonotakashi | 0:8fdf9a60065b | 422 | Replaced by ThisThread::flags_wait_all, ThisThread::flags_wait_all_for, ThisThread::flags_wait_any and ThisThread:wait_any_for. |
kadonotakashi | 0:8fdf9a60065b | 423 | */ |
kadonotakashi | 0:8fdf9a60065b | 424 | MBED_DEPRECATED_SINCE("mbed-os-5.10", |
kadonotakashi | 0:8fdf9a60065b | 425 | "Static methods only affecting current thread cause confusion. " |
kadonotakashi | 0:8fdf9a60065b | 426 | "Replaced by ThisThread::flags_wait_all, ThisThread::flags_wait_all_for, ThisThread::flags_wait_any and ThisThread:wait_any_for.") |
kadonotakashi | 0:8fdf9a60065b | 427 | static osEvent signal_wait(int32_t signals, uint32_t millisec = osWaitForever); |
kadonotakashi | 0:8fdf9a60065b | 428 | |
kadonotakashi | 0:8fdf9a60065b | 429 | /** Wait for a specified time period in milliseconds |
kadonotakashi | 0:8fdf9a60065b | 430 | Being tick-based, the delay will be up to the specified time - eg for |
kadonotakashi | 0:8fdf9a60065b | 431 | a value of 1 the system waits until the next millisecond tick occurs, |
kadonotakashi | 0:8fdf9a60065b | 432 | leading to a delay of 0-1 milliseconds. |
kadonotakashi | 0:8fdf9a60065b | 433 | @param millisec time delay value |
kadonotakashi | 0:8fdf9a60065b | 434 | @return status code that indicates the execution status of the function. |
kadonotakashi | 0:8fdf9a60065b | 435 | |
kadonotakashi | 0:8fdf9a60065b | 436 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 437 | @deprecated Static methods only affecting current thread cause confusion. Replaced by ThisThread::sleep_for. |
kadonotakashi | 0:8fdf9a60065b | 438 | */ |
kadonotakashi | 0:8fdf9a60065b | 439 | MBED_DEPRECATED_SINCE("mbed-os-5.10", |
kadonotakashi | 0:8fdf9a60065b | 440 | "Static methods only affecting current thread cause confusion. " |
kadonotakashi | 0:8fdf9a60065b | 441 | "Replaced by ThisThread::sleep_for.") |
kadonotakashi | 0:8fdf9a60065b | 442 | static osStatus wait(uint32_t millisec); |
kadonotakashi | 0:8fdf9a60065b | 443 | |
kadonotakashi | 0:8fdf9a60065b | 444 | /** Wait until a specified time in millisec |
kadonotakashi | 0:8fdf9a60065b | 445 | The specified time is according to Kernel::get_ms_count(). |
kadonotakashi | 0:8fdf9a60065b | 446 | @param millisec absolute time in millisec |
kadonotakashi | 0:8fdf9a60065b | 447 | @return status code that indicates the execution status of the function. |
kadonotakashi | 0:8fdf9a60065b | 448 | @note not callable from interrupt |
kadonotakashi | 0:8fdf9a60065b | 449 | @note if millisec is equal to or lower than the current tick count, this |
kadonotakashi | 0:8fdf9a60065b | 450 | returns immediately, either with an error or "osOK". |
kadonotakashi | 0:8fdf9a60065b | 451 | @note the underlying RTOS may have a limit to the maximum wait time |
kadonotakashi | 0:8fdf9a60065b | 452 | due to internal 32-bit computations, but this is guaranteed to work if the |
kadonotakashi | 0:8fdf9a60065b | 453 | delay is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, |
kadonotakashi | 0:8fdf9a60065b | 454 | it may return with an immediate error, or wait for the maximum delay. |
kadonotakashi | 0:8fdf9a60065b | 455 | |
kadonotakashi | 0:8fdf9a60065b | 456 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 457 | @deprecated Static methods only affecting current thread cause confusion. Replaced by ThisThread::sleep_until. |
kadonotakashi | 0:8fdf9a60065b | 458 | */ |
kadonotakashi | 0:8fdf9a60065b | 459 | MBED_DEPRECATED_SINCE("mbed-os-5.10", |
kadonotakashi | 0:8fdf9a60065b | 460 | "Static methods only affecting current thread cause confusion. " |
kadonotakashi | 0:8fdf9a60065b | 461 | "Replaced by ThisThread::sleep_until.") |
kadonotakashi | 0:8fdf9a60065b | 462 | static osStatus wait_until(uint64_t millisec); |
kadonotakashi | 0:8fdf9a60065b | 463 | |
kadonotakashi | 0:8fdf9a60065b | 464 | /** Pass control to next thread that is in state READY. |
kadonotakashi | 0:8fdf9a60065b | 465 | @return status code that indicates the execution status of the function. |
kadonotakashi | 0:8fdf9a60065b | 466 | |
kadonotakashi | 0:8fdf9a60065b | 467 | @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 468 | @deprecated Static methods only affecting current thread cause confusion. Replaced by ThisThread::sleep_until. |
kadonotakashi | 0:8fdf9a60065b | 469 | */ |
kadonotakashi | 0:8fdf9a60065b | 470 | MBED_DEPRECATED_SINCE("mbed-os-5.10", |
kadonotakashi | 0:8fdf9a60065b | 471 | "Static methods only affecting current thread cause confusion. " |
kadonotakashi | 0:8fdf9a60065b | 472 | "Replaced by ThisThread::yield.") |
kadonotakashi | 0:8fdf9a60065b | 473 | static osStatus yield(); |
kadonotakashi | 0:8fdf9a60065b | 474 | |
kadonotakashi | 0:8fdf9a60065b | 475 | /** Get the thread id of the current running thread. |
kadonotakashi | 0:8fdf9a60065b | 476 | @return thread ID for reference by other functions or NULL in case of error. |
kadonotakashi | 0:8fdf9a60065b | 477 | |
kadonotakashi | 0:8fdf9a60065b | 478 | @note You may call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 479 | @deprecated Static methods only affecting current thread cause confusion. Replaced by ThisThread::get_id. |
kadonotakashi | 0:8fdf9a60065b | 480 | Use Thread::get_id for the ID of a specific Thread. |
kadonotakashi | 0:8fdf9a60065b | 481 | */ |
kadonotakashi | 0:8fdf9a60065b | 482 | MBED_DEPRECATED_SINCE("mbed-os-5.10", |
kadonotakashi | 0:8fdf9a60065b | 483 | "Static methods only affecting current thread cause confusion. " |
kadonotakashi | 0:8fdf9a60065b | 484 | "Replaced by ThisThread::get_id. Use Thread::get_id for the ID of a specific Thread.") |
kadonotakashi | 0:8fdf9a60065b | 485 | static osThreadId gettid(); |
kadonotakashi | 0:8fdf9a60065b | 486 | |
kadonotakashi | 0:8fdf9a60065b | 487 | /** Attach a function to be called by the RTOS idle task |
kadonotakashi | 0:8fdf9a60065b | 488 | @param fptr pointer to the function to be called |
kadonotakashi | 0:8fdf9a60065b | 489 | |
kadonotakashi | 0:8fdf9a60065b | 490 | @note You may call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 491 | @deprecated Static methods affecting system cause confusion. Replaced by Kernel::attach_idle_hook. |
kadonotakashi | 0:8fdf9a60065b | 492 | */ |
kadonotakashi | 0:8fdf9a60065b | 493 | MBED_DEPRECATED_SINCE("mbed-os-5.10", |
kadonotakashi | 0:8fdf9a60065b | 494 | "Static methods affecting system cause confusion. " |
kadonotakashi | 0:8fdf9a60065b | 495 | "Replaced by Kernel::attach_idle_hook.") |
kadonotakashi | 0:8fdf9a60065b | 496 | static void attach_idle_hook(void (*fptr)(void)); |
kadonotakashi | 0:8fdf9a60065b | 497 | |
kadonotakashi | 0:8fdf9a60065b | 498 | /** Attach a function to be called when a task is killed |
kadonotakashi | 0:8fdf9a60065b | 499 | @param fptr pointer to the function to be called |
kadonotakashi | 0:8fdf9a60065b | 500 | |
kadonotakashi | 0:8fdf9a60065b | 501 | @note You may call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 502 | @deprecated Static methods affecting system cause confusion. Replaced by Kernel::attach_thread_terminate_hook. |
kadonotakashi | 0:8fdf9a60065b | 503 | */ |
kadonotakashi | 0:8fdf9a60065b | 504 | MBED_DEPRECATED_SINCE("mbed-os-5.10", |
kadonotakashi | 0:8fdf9a60065b | 505 | "Static methods affecting system cause confusion. " |
kadonotakashi | 0:8fdf9a60065b | 506 | "Replaced by Kernel::attach_thread_terminate_hook.") |
kadonotakashi | 0:8fdf9a60065b | 507 | static void attach_terminate_hook(void (*fptr)(osThreadId id)); |
kadonotakashi | 0:8fdf9a60065b | 508 | |
kadonotakashi | 0:8fdf9a60065b | 509 | /** Thread destructor |
kadonotakashi | 0:8fdf9a60065b | 510 | * |
kadonotakashi | 0:8fdf9a60065b | 511 | * @note You cannot call this function from ISR context. |
kadonotakashi | 0:8fdf9a60065b | 512 | */ |
kadonotakashi | 0:8fdf9a60065b | 513 | virtual ~Thread(); |
kadonotakashi | 0:8fdf9a60065b | 514 | |
kadonotakashi | 0:8fdf9a60065b | 515 | private: |
kadonotakashi | 0:8fdf9a60065b | 516 | // Required to share definitions without |
kadonotakashi | 0:8fdf9a60065b | 517 | // delegated constructors |
kadonotakashi | 0:8fdf9a60065b | 518 | void constructor(osPriority priority = osPriorityNormal, |
kadonotakashi | 0:8fdf9a60065b | 519 | uint32_t stack_size = OS_STACK_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 520 | unsigned char *stack_mem = NULL, |
kadonotakashi | 0:8fdf9a60065b | 521 | const char *name = NULL); |
kadonotakashi | 0:8fdf9a60065b | 522 | void constructor(mbed::Callback<void()> task, |
kadonotakashi | 0:8fdf9a60065b | 523 | osPriority priority = osPriorityNormal, |
kadonotakashi | 0:8fdf9a60065b | 524 | uint32_t stack_size = OS_STACK_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 525 | unsigned char *stack_mem = NULL, |
kadonotakashi | 0:8fdf9a60065b | 526 | const char *name = NULL); |
kadonotakashi | 0:8fdf9a60065b | 527 | void constructor(uint32_t tz_module, |
kadonotakashi | 0:8fdf9a60065b | 528 | osPriority priority = osPriorityNormal, |
kadonotakashi | 0:8fdf9a60065b | 529 | uint32_t stack_size = OS_STACK_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 530 | unsigned char *stack_mem = NULL, |
kadonotakashi | 0:8fdf9a60065b | 531 | const char *name = NULL); |
kadonotakashi | 0:8fdf9a60065b | 532 | static void _thunk(void *thread_ptr); |
kadonotakashi | 0:8fdf9a60065b | 533 | |
kadonotakashi | 0:8fdf9a60065b | 534 | mbed::Callback<void()> _task; |
kadonotakashi | 0:8fdf9a60065b | 535 | osThreadId_t _tid; |
kadonotakashi | 0:8fdf9a60065b | 536 | osThreadAttr_t _attr; |
kadonotakashi | 0:8fdf9a60065b | 537 | bool _dynamic_stack; |
kadonotakashi | 0:8fdf9a60065b | 538 | Semaphore _join_sem; |
kadonotakashi | 0:8fdf9a60065b | 539 | mutable Mutex _mutex; |
kadonotakashi | 0:8fdf9a60065b | 540 | mbed_rtos_storage_thread_t _obj_mem; |
kadonotakashi | 0:8fdf9a60065b | 541 | bool _finished; |
kadonotakashi | 0:8fdf9a60065b | 542 | }; |
kadonotakashi | 0:8fdf9a60065b | 543 | /** @}*/ |
kadonotakashi | 0:8fdf9a60065b | 544 | /** @}*/ |
kadonotakashi | 0:8fdf9a60065b | 545 | } |
kadonotakashi | 0:8fdf9a60065b | 546 | #endif |
kadonotakashi | 0:8fdf9a60065b | 547 | |
kadonotakashi | 0:8fdf9a60065b | 548 |