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