desp koval / mbed-rtos

Dependents:   Mecatro_Filtre

Committer:
mecatro_prod
Date:
Mon Mar 15 14:18:11 2021 +0000
Revision:
0:4a2c9c1f5b9e
Pas de changement

Who changed what in which revision?

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