florent ollivier / Mbed 2 deprecated Gyro

Dependencies:   mbed

Committer:
flo__
Date:
Mon Mar 28 15:54:19 2022 +0000
Revision:
0:b435eadf76b4
28/03/2022

Who changed what in which revision?

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