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