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