asd
Fork of mbed-rtos by
rtos/Thread.h@123:58563e6cba1e, 2016-11-14 (annotated)
- Committer:
- c1728p9
- Date:
- Mon Nov 14 17:14:42 2016 -0600
- Revision:
- 123:58563e6cba1e
- Parent:
- 120:4dc938e301cc
Configure RTOS to behave as it did before 5.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 8:88a1a9c26ae3 | 1 | /* mbed Microcontroller Library |
emilmont | 8:88a1a9c26ae3 | 2 | * Copyright (c) 2006-2012 ARM Limited |
emilmont | 8:88a1a9c26ae3 | 3 | * |
emilmont | 8:88a1a9c26ae3 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
emilmont | 8:88a1a9c26ae3 | 5 | * of this software and associated documentation files (the "Software"), to deal |
emilmont | 8:88a1a9c26ae3 | 6 | * in the Software without restriction, including without limitation the rights |
emilmont | 8:88a1a9c26ae3 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
emilmont | 8:88a1a9c26ae3 | 8 | * copies of the Software, and to permit persons to whom the Software is |
emilmont | 8:88a1a9c26ae3 | 9 | * furnished to do so, subject to the following conditions: |
emilmont | 8:88a1a9c26ae3 | 10 | * |
emilmont | 8:88a1a9c26ae3 | 11 | * The above copyright notice and this permission notice shall be included in |
emilmont | 8:88a1a9c26ae3 | 12 | * all copies or substantial portions of the Software. |
emilmont | 8:88a1a9c26ae3 | 13 | * |
emilmont | 8:88a1a9c26ae3 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
emilmont | 8:88a1a9c26ae3 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
emilmont | 8:88a1a9c26ae3 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
emilmont | 8:88a1a9c26ae3 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
emilmont | 8:88a1a9c26ae3 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
emilmont | 8:88a1a9c26ae3 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
emilmont | 8:88a1a9c26ae3 | 20 | * SOFTWARE. |
emilmont | 8:88a1a9c26ae3 | 21 | */ |
emilmont | 6:350b53afb889 | 22 | #ifndef THREAD_H |
emilmont | 8:88a1a9c26ae3 | 23 | #define THREAD_H |
emilmont | 6:350b53afb889 | 24 | |
emilmont | 6:350b53afb889 | 25 | #include <stdint.h> |
emilmont | 6:350b53afb889 | 26 | #include "cmsis_os.h" |
c1728p9 | 123:58563e6cba1e | 27 | #include "platform/Callback.h" |
c1728p9 | 123:58563e6cba1e | 28 | #include "platform/toolchain.h" |
c1728p9 | 123:58563e6cba1e | 29 | #include "rtos/Semaphore.h" |
c1728p9 | 123:58563e6cba1e | 30 | #include "rtos/Mutex.h" |
emilmont | 6:350b53afb889 | 31 | |
emilmont | 6:350b53afb889 | 32 | namespace rtos { |
c1728p9 | 123:58563e6cba1e | 33 | /** \addtogroup rtos */ |
c1728p9 | 123:58563e6cba1e | 34 | /** @{*/ |
emilmont | 6:350b53afb889 | 35 | |
c1728p9 | 123:58563e6cba1e | 36 | /** The Thread class allow defining, creating, and controlling thread functions in the system. |
c1728p9 | 123:58563e6cba1e | 37 | * |
c1728p9 | 123:58563e6cba1e | 38 | * Example: |
c1728p9 | 123:58563e6cba1e | 39 | * @code |
c1728p9 | 123:58563e6cba1e | 40 | * #include "mbed.h" |
c1728p9 | 123:58563e6cba1e | 41 | * #include "rtos.h" |
c1728p9 | 123:58563e6cba1e | 42 | * |
c1728p9 | 123:58563e6cba1e | 43 | * Thread thread; |
c1728p9 | 123:58563e6cba1e | 44 | * DigitalOut led1(LED1); |
c1728p9 | 123:58563e6cba1e | 45 | * volatile bool running = true; |
c1728p9 | 123:58563e6cba1e | 46 | * |
c1728p9 | 123:58563e6cba1e | 47 | * // Blink function toggles the led in a long running loop |
c1728p9 | 123:58563e6cba1e | 48 | * void blink(DigitalOut *led) { |
c1728p9 | 123:58563e6cba1e | 49 | * while (running) { |
c1728p9 | 123:58563e6cba1e | 50 | * *led = !*led; |
c1728p9 | 123:58563e6cba1e | 51 | * Thread::wait(1000); |
c1728p9 | 123:58563e6cba1e | 52 | * } |
c1728p9 | 123:58563e6cba1e | 53 | * } |
c1728p9 | 123:58563e6cba1e | 54 | * |
c1728p9 | 123:58563e6cba1e | 55 | * // Spawns a thread to run blink for 5 seconds |
c1728p9 | 123:58563e6cba1e | 56 | * int main() { |
c1728p9 | 123:58563e6cba1e | 57 | * thread.start(led1, blink); |
c1728p9 | 123:58563e6cba1e | 58 | * Thread::wait(5000); |
c1728p9 | 123:58563e6cba1e | 59 | * running = false; |
c1728p9 | 123:58563e6cba1e | 60 | * thread.join(); |
c1728p9 | 123:58563e6cba1e | 61 | * } |
c1728p9 | 123:58563e6cba1e | 62 | * @endcode |
c1728p9 | 123:58563e6cba1e | 63 | */ |
emilmont | 6:350b53afb889 | 64 | class Thread { |
emilmont | 6:350b53afb889 | 65 | public: |
Kojto | 118:6635230e06ba | 66 | /** Allocate a new thread without starting execution |
Kojto | 118:6635230e06ba | 67 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
Kojto | 118:6635230e06ba | 68 | @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). |
Kojto | 118:6635230e06ba | 69 | @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). |
Kojto | 118:6635230e06ba | 70 | */ |
Kojto | 118:6635230e06ba | 71 | Thread(osPriority priority=osPriorityNormal, |
Kojto | 118:6635230e06ba | 72 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
Kojto | 118:6635230e06ba | 73 | unsigned char *stack_pointer=NULL) { |
Kojto | 118:6635230e06ba | 74 | constructor(priority, stack_size, stack_pointer); |
Kojto | 118:6635230e06ba | 75 | } |
Kojto | 118:6635230e06ba | 76 | |
emilmont | 8:88a1a9c26ae3 | 77 | /** Create a new thread, and start it executing the specified function. |
emilmont | 8:88a1a9c26ae3 | 78 | @param task function to be executed by this thread. |
emilmont | 8:88a1a9c26ae3 | 79 | @param argument pointer that is passed to the thread function as start argument. (default: NULL). |
emilmont | 8:88a1a9c26ae3 | 80 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
emilmont | 8:88a1a9c26ae3 | 81 | @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). |
emilmont | 8:88a1a9c26ae3 | 82 | @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). |
Kojto | 118:6635230e06ba | 83 | @deprecated |
c1728p9 | 123:58563e6cba1e | 84 | Thread-spawning constructors hide errors. Replaced by thread.start(task). |
c1728p9 | 123:58563e6cba1e | 85 | |
c1728p9 | 123:58563e6cba1e | 86 | @code |
c1728p9 | 123:58563e6cba1e | 87 | Thread thread(priority, stack_size, stack_pointer); |
Kojto | 118:6635230e06ba | 88 | |
c1728p9 | 123:58563e6cba1e | 89 | osStatus status = thread.start(task); |
c1728p9 | 123:58563e6cba1e | 90 | if (status != osOK) { |
c1728p9 | 123:58563e6cba1e | 91 | error("oh no!"); |
c1728p9 | 123:58563e6cba1e | 92 | } |
c1728p9 | 123:58563e6cba1e | 93 | @endcode |
emilmont | 6:350b53afb889 | 94 | */ |
Kojto | 120:4dc938e301cc | 95 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
c1728p9 | 123:58563e6cba1e | 96 | "Thread-spawning constructors hide errors. " |
c1728p9 | 123:58563e6cba1e | 97 | "Replaced by thread.start(task).") |
Kojto | 118:6635230e06ba | 98 | Thread(mbed::Callback<void()> task, |
Kojto | 118:6635230e06ba | 99 | osPriority priority=osPriorityNormal, |
Kojto | 118:6635230e06ba | 100 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
Kojto | 118:6635230e06ba | 101 | unsigned char *stack_pointer=NULL) { |
Kojto | 118:6635230e06ba | 102 | constructor(task, priority, stack_size, stack_pointer); |
Kojto | 118:6635230e06ba | 103 | } |
Kojto | 118:6635230e06ba | 104 | |
Kojto | 118:6635230e06ba | 105 | /** Create a new thread, and start it executing the specified function. |
Kojto | 118:6635230e06ba | 106 | @param obj argument to task. |
Kojto | 118:6635230e06ba | 107 | @param method function to be executed by this thread. |
Kojto | 118:6635230e06ba | 108 | @param argument pointer that is passed to the thread function as start argument. (default: NULL). |
Kojto | 118:6635230e06ba | 109 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
Kojto | 118:6635230e06ba | 110 | @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). |
Kojto | 118:6635230e06ba | 111 | @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). |
Kojto | 118:6635230e06ba | 112 | @deprecated |
c1728p9 | 123:58563e6cba1e | 113 | Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)). |
c1728p9 | 123:58563e6cba1e | 114 | |
c1728p9 | 123:58563e6cba1e | 115 | @code |
c1728p9 | 123:58563e6cba1e | 116 | Thread thread(priority, stack_size, stack_pointer); |
Kojto | 118:6635230e06ba | 117 | |
c1728p9 | 123:58563e6cba1e | 118 | osStatus status = thread.start(callback(task, argument)); |
c1728p9 | 123:58563e6cba1e | 119 | if (status != osOK) { |
c1728p9 | 123:58563e6cba1e | 120 | error("oh no!"); |
c1728p9 | 123:58563e6cba1e | 121 | } |
c1728p9 | 123:58563e6cba1e | 122 | @endcode |
Kojto | 118:6635230e06ba | 123 | */ |
Kojto | 118:6635230e06ba | 124 | template <typename T> |
Kojto | 120:4dc938e301cc | 125 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
c1728p9 | 123:58563e6cba1e | 126 | "Thread-spawning constructors hide errors. " |
c1728p9 | 123:58563e6cba1e | 127 | "Replaced by thread.start(callback(task, argument)).") |
c1728p9 | 123:58563e6cba1e | 128 | Thread(T *argument, void (T::*task)(), |
Kojto | 118:6635230e06ba | 129 | osPriority priority=osPriorityNormal, |
Kojto | 118:6635230e06ba | 130 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
Kojto | 118:6635230e06ba | 131 | unsigned char *stack_pointer=NULL) { |
c1728p9 | 123:58563e6cba1e | 132 | constructor(mbed::callback(task, argument), |
Kojto | 118:6635230e06ba | 133 | priority, stack_size, stack_pointer); |
Kojto | 118:6635230e06ba | 134 | } |
Kojto | 118:6635230e06ba | 135 | |
Kojto | 118:6635230e06ba | 136 | /** Create a new thread, and start it executing the specified function. |
Kojto | 118:6635230e06ba | 137 | @param obj argument to task. |
Kojto | 118:6635230e06ba | 138 | @param method function to be executed by this thread. |
Kojto | 118:6635230e06ba | 139 | @param argument pointer that is passed to the thread function as start argument. (default: NULL). |
Kojto | 118:6635230e06ba | 140 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
Kojto | 118:6635230e06ba | 141 | @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). |
Kojto | 118:6635230e06ba | 142 | @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). |
Kojto | 118:6635230e06ba | 143 | @deprecated |
c1728p9 | 123:58563e6cba1e | 144 | Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)). |
c1728p9 | 123:58563e6cba1e | 145 | |
c1728p9 | 123:58563e6cba1e | 146 | @code |
c1728p9 | 123:58563e6cba1e | 147 | Thread thread(priority, stack_size, stack_pointer); |
Kojto | 118:6635230e06ba | 148 | |
c1728p9 | 123:58563e6cba1e | 149 | osStatus status = thread.start(callback(task, argument)); |
c1728p9 | 123:58563e6cba1e | 150 | if (status != osOK) { |
c1728p9 | 123:58563e6cba1e | 151 | error("oh no!"); |
c1728p9 | 123:58563e6cba1e | 152 | } |
c1728p9 | 123:58563e6cba1e | 153 | @endcode |
Kojto | 118:6635230e06ba | 154 | */ |
Kojto | 118:6635230e06ba | 155 | template <typename T> |
Kojto | 120:4dc938e301cc | 156 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
c1728p9 | 123:58563e6cba1e | 157 | "Thread-spawning constructors hide errors. " |
c1728p9 | 123:58563e6cba1e | 158 | "Replaced by thread.start(callback(task, argument)).") |
c1728p9 | 123:58563e6cba1e | 159 | Thread(T *argument, void (*task)(T *), |
Kojto | 118:6635230e06ba | 160 | osPriority priority=osPriorityNormal, |
Kojto | 118:6635230e06ba | 161 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
Kojto | 118:6635230e06ba | 162 | unsigned char *stack_pointer=NULL) { |
c1728p9 | 123:58563e6cba1e | 163 | constructor(mbed::callback(task, argument), |
Kojto | 118:6635230e06ba | 164 | priority, stack_size, stack_pointer); |
Kojto | 118:6635230e06ba | 165 | } |
Kojto | 118:6635230e06ba | 166 | |
Kojto | 118:6635230e06ba | 167 | /** Create a new thread, and start it executing the specified function. |
Kojto | 118:6635230e06ba | 168 | Provided for backwards compatibility |
Kojto | 118:6635230e06ba | 169 | @param task function to be executed by this thread. |
Kojto | 118:6635230e06ba | 170 | @param argument pointer that is passed to the thread function as start argument. (default: NULL). |
Kojto | 118:6635230e06ba | 171 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
Kojto | 118:6635230e06ba | 172 | @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). |
Kojto | 118:6635230e06ba | 173 | @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). |
Kojto | 118:6635230e06ba | 174 | @deprecated |
c1728p9 | 123:58563e6cba1e | 175 | Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)). |
c1728p9 | 123:58563e6cba1e | 176 | |
c1728p9 | 123:58563e6cba1e | 177 | @code |
c1728p9 | 123:58563e6cba1e | 178 | Thread thread(priority, stack_size, stack_pointer); |
Kojto | 118:6635230e06ba | 179 | |
c1728p9 | 123:58563e6cba1e | 180 | osStatus status = thread.start(callback(task, argument)); |
c1728p9 | 123:58563e6cba1e | 181 | if (status != osOK) { |
c1728p9 | 123:58563e6cba1e | 182 | error("oh no!"); |
c1728p9 | 123:58563e6cba1e | 183 | } |
c1728p9 | 123:58563e6cba1e | 184 | @endcode |
Kojto | 118:6635230e06ba | 185 | */ |
Kojto | 120:4dc938e301cc | 186 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
c1728p9 | 123:58563e6cba1e | 187 | "Thread-spawning constructors hide errors. " |
c1728p9 | 123:58563e6cba1e | 188 | "Replaced by thread.start(callback(task, argument)).") |
emilmont | 6:350b53afb889 | 189 | Thread(void (*task)(void const *argument), void *argument=NULL, |
emilmont | 6:350b53afb889 | 190 | osPriority priority=osPriorityNormal, |
emilmont | 6:350b53afb889 | 191 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
Kojto | 118:6635230e06ba | 192 | unsigned char *stack_pointer=NULL) { |
c1728p9 | 123:58563e6cba1e | 193 | constructor(mbed::callback((void (*)(void *))task, argument), |
Kojto | 118:6635230e06ba | 194 | priority, stack_size, stack_pointer); |
Kojto | 118:6635230e06ba | 195 | } |
Kojto | 118:6635230e06ba | 196 | |
Kojto | 118:6635230e06ba | 197 | /** Starts a thread executing the specified function. |
Kojto | 118:6635230e06ba | 198 | @param task function to be executed by this thread. |
Kojto | 118:6635230e06ba | 199 | @return status code that indicates the execution status of the function. |
Kojto | 118:6635230e06ba | 200 | */ |
Kojto | 118:6635230e06ba | 201 | osStatus start(mbed::Callback<void()> task); |
Kojto | 118:6635230e06ba | 202 | |
Kojto | 118:6635230e06ba | 203 | /** Starts a thread executing the specified function. |
Kojto | 118:6635230e06ba | 204 | @param obj argument to task |
Kojto | 118:6635230e06ba | 205 | @param method function to be executed by this thread. |
Kojto | 118:6635230e06ba | 206 | @return status code that indicates the execution status of the function. |
c1728p9 | 123:58563e6cba1e | 207 | @deprecated |
c1728p9 | 123:58563e6cba1e | 208 | The start function does not support cv-qualifiers. Replaced by start(callback(obj, method)). |
Kojto | 118:6635230e06ba | 209 | */ |
Kojto | 118:6635230e06ba | 210 | template <typename T, typename M> |
c1728p9 | 123:58563e6cba1e | 211 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
c1728p9 | 123:58563e6cba1e | 212 | "The start function does not support cv-qualifiers. " |
c1728p9 | 123:58563e6cba1e | 213 | "Replaced by thread.start(callback(obj, method)).") |
Kojto | 118:6635230e06ba | 214 | osStatus start(T *obj, M method) { |
c1728p9 | 123:58563e6cba1e | 215 | return start(mbed::callback(obj, method)); |
Kojto | 118:6635230e06ba | 216 | } |
Kojto | 118:6635230e06ba | 217 | |
Kojto | 118:6635230e06ba | 218 | /** Wait for thread to terminate |
Kojto | 118:6635230e06ba | 219 | @return status code that indicates the execution status of the function. |
Kojto | 118:6635230e06ba | 220 | @note not callable from interrupt |
Kojto | 118:6635230e06ba | 221 | */ |
Kojto | 118:6635230e06ba | 222 | osStatus join(); |
mbed_official | 31:015df9e602b6 | 223 | |
emilmont | 8:88a1a9c26ae3 | 224 | /** Terminate execution of a thread and remove it from Active Threads |
emilmont | 8:88a1a9c26ae3 | 225 | @return status code that indicates the execution status of the function. |
emilmont | 6:350b53afb889 | 226 | */ |
emilmont | 6:350b53afb889 | 227 | osStatus terminate(); |
mbed_official | 31:015df9e602b6 | 228 | |
emilmont | 8:88a1a9c26ae3 | 229 | /** Set priority of an active thread |
emilmont | 8:88a1a9c26ae3 | 230 | @param priority new priority value for the thread function. |
emilmont | 8:88a1a9c26ae3 | 231 | @return status code that indicates the execution status of the function. |
emilmont | 6:350b53afb889 | 232 | */ |
emilmont | 6:350b53afb889 | 233 | osStatus set_priority(osPriority priority); |
mbed_official | 31:015df9e602b6 | 234 | |
emilmont | 8:88a1a9c26ae3 | 235 | /** Get priority of an active thread |
emilmont | 8:88a1a9c26ae3 | 236 | @return current priority value of the thread function. |
emilmont | 6:350b53afb889 | 237 | */ |
emilmont | 6:350b53afb889 | 238 | osPriority get_priority(); |
mbed_official | 31:015df9e602b6 | 239 | |
emilmont | 8:88a1a9c26ae3 | 240 | /** Set the specified Signal Flags of an active thread. |
emilmont | 8:88a1a9c26ae3 | 241 | @param signals specifies the signal flags of the thread that should be set. |
emilmont | 8:88a1a9c26ae3 | 242 | @return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. |
emilmont | 6:350b53afb889 | 243 | */ |
emilmont | 6:350b53afb889 | 244 | int32_t signal_set(int32_t signals); |
mbed_official | 31:015df9e602b6 | 245 | |
mbed_official | 76:85a52b7ef44b | 246 | /** Clears the specified Signal Flags of an active thread. |
mbed_official | 76:85a52b7ef44b | 247 | @param signals specifies the signal flags of the thread that should be cleared. |
mbed_official | 76:85a52b7ef44b | 248 | @return resultant signal flags of the specified thread or 0x80000000 in case of incorrect parameters. |
mbed_official | 76:85a52b7ef44b | 249 | */ |
mbed_official | 76:85a52b7ef44b | 250 | int32_t signal_clr(int32_t signals); |
mbed_official | 76:85a52b7ef44b | 251 | |
emilmont | 8:88a1a9c26ae3 | 252 | /** State of the Thread */ |
emilmont | 8:88a1a9c26ae3 | 253 | enum State { |
emilmont | 8:88a1a9c26ae3 | 254 | Inactive, /**< Not created or terminated */ |
emilmont | 8:88a1a9c26ae3 | 255 | Ready, /**< Ready to run */ |
emilmont | 8:88a1a9c26ae3 | 256 | Running, /**< Running */ |
emilmont | 8:88a1a9c26ae3 | 257 | WaitingDelay, /**< Waiting for a delay to occur */ |
emilmont | 8:88a1a9c26ae3 | 258 | WaitingInterval, /**< Waiting for an interval to occur */ |
emilmont | 8:88a1a9c26ae3 | 259 | WaitingOr, /**< Waiting for one event in a set to occur */ |
emilmont | 8:88a1a9c26ae3 | 260 | WaitingAnd, /**< Waiting for multiple events in a set to occur */ |
emilmont | 8:88a1a9c26ae3 | 261 | WaitingSemaphore, /**< Waiting for a semaphore event to occur */ |
emilmont | 8:88a1a9c26ae3 | 262 | WaitingMailbox, /**< Waiting for a mailbox event to occur */ |
emilmont | 8:88a1a9c26ae3 | 263 | WaitingMutex, /**< Waiting for a mutex event to occur */ |
Kojto | 119:19af2d39a542 | 264 | |
Kojto | 119:19af2d39a542 | 265 | /* Not in sync with RTX below here */ |
Kojto | 119:19af2d39a542 | 266 | Deleted, /**< The task has been deleted */ |
emilmont | 8:88a1a9c26ae3 | 267 | }; |
mbed_official | 31:015df9e602b6 | 268 | |
emilmont | 8:88a1a9c26ae3 | 269 | /** State of this Thread |
emilmont | 8:88a1a9c26ae3 | 270 | @return the State of this Thread |
emilmont | 8:88a1a9c26ae3 | 271 | */ |
emilmont | 8:88a1a9c26ae3 | 272 | State get_state(); |
mbed_official | 84:143955ffb790 | 273 | |
mbed_official | 84:143955ffb790 | 274 | /** Get the total stack memory size for this Thread |
mbed_official | 84:143955ffb790 | 275 | @return the total stack memory size in bytes |
mbed_official | 84:143955ffb790 | 276 | */ |
mbed_official | 84:143955ffb790 | 277 | uint32_t stack_size(); |
mbed_official | 84:143955ffb790 | 278 | |
mbed_official | 84:143955ffb790 | 279 | /** Get the currently unused stack memory for this Thread |
mbed_official | 84:143955ffb790 | 280 | @return the currently unused stack memory in bytes |
mbed_official | 84:143955ffb790 | 281 | */ |
mbed_official | 84:143955ffb790 | 282 | uint32_t free_stack(); |
mbed_official | 84:143955ffb790 | 283 | |
mbed_official | 84:143955ffb790 | 284 | /** Get the currently used stack memory for this Thread |
mbed_official | 84:143955ffb790 | 285 | @return the currently used stack memory in bytes |
mbed_official | 84:143955ffb790 | 286 | */ |
mbed_official | 84:143955ffb790 | 287 | uint32_t used_stack(); |
mbed_official | 84:143955ffb790 | 288 | |
mbed_official | 84:143955ffb790 | 289 | /** Get the maximum stack memory usage to date for this Thread |
mbed_official | 84:143955ffb790 | 290 | @return the maximum stack memory usage to date in bytes |
mbed_official | 84:143955ffb790 | 291 | */ |
mbed_official | 84:143955ffb790 | 292 | uint32_t max_stack(); |
mbed_official | 31:015df9e602b6 | 293 | |
mbed_official | 31:015df9e602b6 | 294 | /** Wait for one or more Signal Flags to become signaled for the current RUNNING thread. |
emilmont | 8:88a1a9c26ae3 | 295 | @param signals wait until all specified signal flags set or 0 for any single signal flag. |
emilmont | 8:88a1a9c26ae3 | 296 | @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever). |
emilmont | 8:88a1a9c26ae3 | 297 | @return event flag information or error code. |
Kojto | 118:6635230e06ba | 298 | @note not callable from interrupt |
emilmont | 6:350b53afb889 | 299 | */ |
emilmont | 6:350b53afb889 | 300 | static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever); |
mbed_official | 31:015df9e602b6 | 301 | |
emilmont | 8:88a1a9c26ae3 | 302 | /** Wait for a specified time period in millisec: |
emilmont | 8:88a1a9c26ae3 | 303 | @param millisec time delay value |
mbed_official | 31:015df9e602b6 | 304 | @return status code that indicates the execution status of the function. |
Kojto | 118:6635230e06ba | 305 | @note not callable from interrupt |
emilmont | 6:350b53afb889 | 306 | */ |
emilmont | 6:350b53afb889 | 307 | static osStatus wait(uint32_t millisec); |
mbed_official | 31:015df9e602b6 | 308 | |
emilmont | 8:88a1a9c26ae3 | 309 | /** Pass control to next thread that is in state READY. |
emilmont | 8:88a1a9c26ae3 | 310 | @return status code that indicates the execution status of the function. |
Kojto | 118:6635230e06ba | 311 | @note not callable from interrupt |
emilmont | 6:350b53afb889 | 312 | */ |
emilmont | 6:350b53afb889 | 313 | static osStatus yield(); |
mbed_official | 31:015df9e602b6 | 314 | |
emilmont | 8:88a1a9c26ae3 | 315 | /** Get the thread id of the current running thread. |
emilmont | 8:88a1a9c26ae3 | 316 | @return thread ID for reference by other functions or NULL in case of error. |
emilmont | 6:350b53afb889 | 317 | */ |
emilmont | 6:350b53afb889 | 318 | static osThreadId gettid(); |
mbed_official | 107:bdd541595fc5 | 319 | |
mbed_official | 107:bdd541595fc5 | 320 | /** Attach a function to be called by the RTOS idle task |
mbed_official | 107:bdd541595fc5 | 321 | @param fptr pointer to the function to be called |
mbed_official | 107:bdd541595fc5 | 322 | */ |
mbed_official | 107:bdd541595fc5 | 323 | static void attach_idle_hook(void (*fptr)(void)); |
mbed_official | 31:015df9e602b6 | 324 | |
c1728p9 | 123:58563e6cba1e | 325 | /** Attach a function to be called when a task is killed |
c1728p9 | 123:58563e6cba1e | 326 | @param fptr pointer to the function to be called |
c1728p9 | 123:58563e6cba1e | 327 | */ |
c1728p9 | 123:58563e6cba1e | 328 | static void attach_terminate_hook(void (*fptr)(osThreadId id)); |
c1728p9 | 123:58563e6cba1e | 329 | |
emilmont | 6:350b53afb889 | 330 | virtual ~Thread(); |
emilmont | 6:350b53afb889 | 331 | |
emilmont | 6:350b53afb889 | 332 | private: |
Kojto | 118:6635230e06ba | 333 | // Required to share definitions without |
Kojto | 118:6635230e06ba | 334 | // delegated constructors |
Kojto | 118:6635230e06ba | 335 | void constructor(osPriority priority=osPriorityNormal, |
Kojto | 118:6635230e06ba | 336 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
Kojto | 118:6635230e06ba | 337 | unsigned char *stack_pointer=NULL); |
Kojto | 118:6635230e06ba | 338 | void constructor(mbed::Callback<void()> task, |
Kojto | 118:6635230e06ba | 339 | osPriority priority=osPriorityNormal, |
Kojto | 118:6635230e06ba | 340 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
Kojto | 118:6635230e06ba | 341 | unsigned char *stack_pointer=NULL); |
Kojto | 119:19af2d39a542 | 342 | static void _thunk(const void * thread_ptr); |
Kojto | 118:6635230e06ba | 343 | |
Kojto | 118:6635230e06ba | 344 | mbed::Callback<void()> _task; |
emilmont | 6:350b53afb889 | 345 | osThreadId _tid; |
emilmont | 6:350b53afb889 | 346 | osThreadDef_t _thread_def; |
emilmont | 6:350b53afb889 | 347 | bool _dynamic_stack; |
Kojto | 119:19af2d39a542 | 348 | Semaphore _join_sem; |
Kojto | 119:19af2d39a542 | 349 | Mutex _mutex; |
emilmont | 6:350b53afb889 | 350 | }; |
emilmont | 6:350b53afb889 | 351 | |
emilmont | 6:350b53afb889 | 352 | } |
emilmont | 6:350b53afb889 | 353 | #endif |
c1728p9 | 123:58563e6cba1e | 354 | |
c1728p9 | 123:58563e6cba1e | 355 | /** @}*/ |