Committer:
borlanic
Date:
Thu Mar 29 07:02:09 2018 +0000
Revision:
0:380207fcb5c1
Encoder, IMU --> OK; Controller --> in bearbeitung

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 /* mbed Microcontroller Library
borlanic 0:380207fcb5c1 2 * Copyright (c) 2006-2012 ARM Limited
borlanic 0:380207fcb5c1 3 *
borlanic 0:380207fcb5c1 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
borlanic 0:380207fcb5c1 5 * of this software and associated documentation files (the "Software"), to deal
borlanic 0:380207fcb5c1 6 * in the Software without restriction, including without limitation the rights
borlanic 0:380207fcb5c1 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
borlanic 0:380207fcb5c1 8 * copies of the Software, and to permit persons to whom the Software is
borlanic 0:380207fcb5c1 9 * furnished to do so, subject to the following conditions:
borlanic 0:380207fcb5c1 10 *
borlanic 0:380207fcb5c1 11 * The above copyright notice and this permission notice shall be included in
borlanic 0:380207fcb5c1 12 * all copies or substantial portions of the Software.
borlanic 0:380207fcb5c1 13 *
borlanic 0:380207fcb5c1 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
borlanic 0:380207fcb5c1 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
borlanic 0:380207fcb5c1 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
borlanic 0:380207fcb5c1 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
borlanic 0:380207fcb5c1 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
borlanic 0:380207fcb5c1 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
borlanic 0:380207fcb5c1 20 * SOFTWARE.
borlanic 0:380207fcb5c1 21 */
borlanic 0:380207fcb5c1 22 #ifndef THREAD_H
borlanic 0:380207fcb5c1 23 #define THREAD_H
borlanic 0:380207fcb5c1 24
borlanic 0:380207fcb5c1 25 #include <stdint.h>
borlanic 0:380207fcb5c1 26 #include "cmsis_os2.h"
borlanic 0:380207fcb5c1 27 #include "mbed_rtos1_types.h"
borlanic 0:380207fcb5c1 28 #include "mbed_rtos_storage.h"
borlanic 0:380207fcb5c1 29 #include "platform/Callback.h"
borlanic 0:380207fcb5c1 30 #include "platform/mbed_toolchain.h"
borlanic 0:380207fcb5c1 31 #include "platform/NonCopyable.h"
borlanic 0:380207fcb5c1 32 #include "rtos/Semaphore.h"
borlanic 0:380207fcb5c1 33 #include "rtos/Mutex.h"
borlanic 0:380207fcb5c1 34
borlanic 0:380207fcb5c1 35 namespace rtos {
borlanic 0:380207fcb5c1 36 /** \addtogroup rtos */
borlanic 0:380207fcb5c1 37 /** @{*/
borlanic 0:380207fcb5c1 38 /**
borlanic 0:380207fcb5c1 39 * \defgroup rtos_Thread Thread class
borlanic 0:380207fcb5c1 40 * @{
borlanic 0:380207fcb5c1 41 */
borlanic 0:380207fcb5c1 42
borlanic 0:380207fcb5c1 43 /** The Thread class allow defining, creating, and controlling thread functions in the system.
borlanic 0:380207fcb5c1 44 *
borlanic 0:380207fcb5c1 45 * Example:
borlanic 0:380207fcb5c1 46 * @code
borlanic 0:380207fcb5c1 47 * #include "mbed.h"
borlanic 0:380207fcb5c1 48 * #include "rtos.h"
borlanic 0:380207fcb5c1 49 *
borlanic 0:380207fcb5c1 50 * Thread thread;
borlanic 0:380207fcb5c1 51 * DigitalOut led1(LED1);
borlanic 0:380207fcb5c1 52 * volatile bool running = true;
borlanic 0:380207fcb5c1 53 *
borlanic 0:380207fcb5c1 54 * // Blink function toggles the led in a long running loop
borlanic 0:380207fcb5c1 55 * void blink(DigitalOut *led) {
borlanic 0:380207fcb5c1 56 * while (running) {
borlanic 0:380207fcb5c1 57 * *led = !*led;
borlanic 0:380207fcb5c1 58 * wait(1);
borlanic 0:380207fcb5c1 59 * }
borlanic 0:380207fcb5c1 60 * }
borlanic 0:380207fcb5c1 61 *
borlanic 0:380207fcb5c1 62 * // Spawns a thread to run blink for 5 seconds
borlanic 0:380207fcb5c1 63 * int main() {
borlanic 0:380207fcb5c1 64 * thread.start(callback(blink, &led1));
borlanic 0:380207fcb5c1 65 * wait(5);
borlanic 0:380207fcb5c1 66 * running = false;
borlanic 0:380207fcb5c1 67 * thread.join();
borlanic 0:380207fcb5c1 68 * }
borlanic 0:380207fcb5c1 69 * @endcode
borlanic 0:380207fcb5c1 70 *
borlanic 0:380207fcb5c1 71 * @note
borlanic 0:380207fcb5c1 72 * Memory considerations: The thread control structures will be created on current thread's stack, both for the mbed OS
borlanic 0:380207fcb5c1 73 * and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
borlanic 0:380207fcb5c1 74 * Additionally the stack memory for this thread will be allocated on the heap, if it wasn't supplied to the constructor.
borlanic 0:380207fcb5c1 75 */
borlanic 0:380207fcb5c1 76 class Thread : private mbed::NonCopyable<Thread> {
borlanic 0:380207fcb5c1 77 public:
borlanic 0:380207fcb5c1 78 /** Allocate a new thread without starting execution
borlanic 0:380207fcb5c1 79 @param priority initial priority of the thread function. (default: osPriorityNormal).
borlanic 0:380207fcb5c1 80 @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
borlanic 0:380207fcb5c1 81 @param stack_mem pointer to the stack area to be used by this thread (default: NULL).
borlanic 0:380207fcb5c1 82 @param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: NULL)
borlanic 0:380207fcb5c1 83
borlanic 0:380207fcb5c1 84 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 85 */
borlanic 0:380207fcb5c1 86 Thread(osPriority priority=osPriorityNormal,
borlanic 0:380207fcb5c1 87 uint32_t stack_size=OS_STACK_SIZE,
borlanic 0:380207fcb5c1 88 unsigned char *stack_mem=NULL, const char *name=NULL) {
borlanic 0:380207fcb5c1 89 constructor(priority, stack_size, stack_mem, name);
borlanic 0:380207fcb5c1 90 }
borlanic 0:380207fcb5c1 91
borlanic 0:380207fcb5c1 92 /** Create a new thread, and start it executing the specified function.
borlanic 0:380207fcb5c1 93 @param task function to be executed by this thread.
borlanic 0:380207fcb5c1 94 @param priority initial priority of the thread function. (default: osPriorityNormal).
borlanic 0:380207fcb5c1 95 @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
borlanic 0:380207fcb5c1 96 @param stack_mem pointer to the stack area to be used by this thread (default: NULL).
borlanic 0:380207fcb5c1 97 @deprecated
borlanic 0:380207fcb5c1 98 Thread-spawning constructors hide errors. Replaced by thread.start(task).
borlanic 0:380207fcb5c1 99
borlanic 0:380207fcb5c1 100 @code
borlanic 0:380207fcb5c1 101 Thread thread(priority, stack_size, stack_mem);
borlanic 0:380207fcb5c1 102
borlanic 0:380207fcb5c1 103 osStatus status = thread.start(task);
borlanic 0:380207fcb5c1 104 if (status != osOK) {
borlanic 0:380207fcb5c1 105 error("oh no!");
borlanic 0:380207fcb5c1 106 }
borlanic 0:380207fcb5c1 107 @endcode
borlanic 0:380207fcb5c1 108
borlanic 0:380207fcb5c1 109 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 110 */
borlanic 0:380207fcb5c1 111 MBED_DEPRECATED_SINCE("mbed-os-5.1",
borlanic 0:380207fcb5c1 112 "Thread-spawning constructors hide errors. "
borlanic 0:380207fcb5c1 113 "Replaced by thread.start(task).")
borlanic 0:380207fcb5c1 114 Thread(mbed::Callback<void()> task,
borlanic 0:380207fcb5c1 115 osPriority priority=osPriorityNormal,
borlanic 0:380207fcb5c1 116 uint32_t stack_size=OS_STACK_SIZE,
borlanic 0:380207fcb5c1 117 unsigned char *stack_mem=NULL) {
borlanic 0:380207fcb5c1 118 constructor(task, priority, stack_size, stack_mem);
borlanic 0:380207fcb5c1 119 }
borlanic 0:380207fcb5c1 120
borlanic 0:380207fcb5c1 121 /** Create a new thread, and start it executing the specified function.
borlanic 0:380207fcb5c1 122 @param argument pointer that is passed to the thread function as start argument. (default: NULL).
borlanic 0:380207fcb5c1 123 @param task argument to task.
borlanic 0:380207fcb5c1 124 @param priority initial priority of the thread function. (default: osPriorityNormal).
borlanic 0:380207fcb5c1 125 @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
borlanic 0:380207fcb5c1 126 @param stack_mem pointer to the stack area to be used by this thread (default: NULL).
borlanic 0:380207fcb5c1 127 @deprecated
borlanic 0:380207fcb5c1 128 Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
borlanic 0:380207fcb5c1 129
borlanic 0:380207fcb5c1 130 @code
borlanic 0:380207fcb5c1 131 Thread thread(priority, stack_size, stack_mem);
borlanic 0:380207fcb5c1 132
borlanic 0:380207fcb5c1 133 osStatus status = thread.start(callback(task, argument));
borlanic 0:380207fcb5c1 134 if (status != osOK) {
borlanic 0:380207fcb5c1 135 error("oh no!");
borlanic 0:380207fcb5c1 136 }
borlanic 0:380207fcb5c1 137 @endcode
borlanic 0:380207fcb5c1 138
borlanic 0:380207fcb5c1 139 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 140 */
borlanic 0:380207fcb5c1 141 template <typename T>
borlanic 0:380207fcb5c1 142 MBED_DEPRECATED_SINCE("mbed-os-5.1",
borlanic 0:380207fcb5c1 143 "Thread-spawning constructors hide errors. "
borlanic 0:380207fcb5c1 144 "Replaced by thread.start(callback(task, argument)).")
borlanic 0:380207fcb5c1 145 Thread(T *argument, void (T::*task)(),
borlanic 0:380207fcb5c1 146 osPriority priority=osPriorityNormal,
borlanic 0:380207fcb5c1 147 uint32_t stack_size=OS_STACK_SIZE,
borlanic 0:380207fcb5c1 148 unsigned char *stack_mem=NULL) {
borlanic 0:380207fcb5c1 149 constructor(mbed::callback(task, argument),
borlanic 0:380207fcb5c1 150 priority, stack_size, stack_mem);
borlanic 0:380207fcb5c1 151 }
borlanic 0:380207fcb5c1 152
borlanic 0:380207fcb5c1 153 /** Create a new thread, and start it executing the specified function.
borlanic 0:380207fcb5c1 154 @param argument pointer that is passed to the thread function as start argument. (default: NULL).
borlanic 0:380207fcb5c1 155 @param task argument to task.
borlanic 0:380207fcb5c1 156 @param priority initial priority of the thread function. (default: osPriorityNormal).
borlanic 0:380207fcb5c1 157 @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
borlanic 0:380207fcb5c1 158 @param stack_mem pointer to the stack area to be used by this thread (default: NULL).
borlanic 0:380207fcb5c1 159 @deprecated
borlanic 0:380207fcb5c1 160 Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
borlanic 0:380207fcb5c1 161
borlanic 0:380207fcb5c1 162 @code
borlanic 0:380207fcb5c1 163 Thread thread(priority, stack_size, stack_mem);
borlanic 0:380207fcb5c1 164
borlanic 0:380207fcb5c1 165 osStatus status = thread.start(callback(task, argument));
borlanic 0:380207fcb5c1 166 if (status != osOK) {
borlanic 0:380207fcb5c1 167 error("oh no!");
borlanic 0:380207fcb5c1 168 }
borlanic 0:380207fcb5c1 169 @endcode
borlanic 0:380207fcb5c1 170
borlanic 0:380207fcb5c1 171 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 172 */
borlanic 0:380207fcb5c1 173 template <typename T>
borlanic 0:380207fcb5c1 174 MBED_DEPRECATED_SINCE("mbed-os-5.1",
borlanic 0:380207fcb5c1 175 "Thread-spawning constructors hide errors. "
borlanic 0:380207fcb5c1 176 "Replaced by thread.start(callback(task, argument)).")
borlanic 0:380207fcb5c1 177 Thread(T *argument, void (*task)(T *),
borlanic 0:380207fcb5c1 178 osPriority priority=osPriorityNormal,
borlanic 0:380207fcb5c1 179 uint32_t stack_size=OS_STACK_SIZE,
borlanic 0:380207fcb5c1 180 unsigned char *stack_mem=NULL) {
borlanic 0:380207fcb5c1 181 constructor(mbed::callback(task, argument),
borlanic 0:380207fcb5c1 182 priority, stack_size, stack_mem);
borlanic 0:380207fcb5c1 183 }
borlanic 0:380207fcb5c1 184
borlanic 0:380207fcb5c1 185 /** Create a new thread, and start it executing the specified function.
borlanic 0:380207fcb5c1 186 Provided for backwards compatibility
borlanic 0:380207fcb5c1 187 @param task function to be executed by this thread.
borlanic 0:380207fcb5c1 188 @param argument pointer that is passed to the thread function as start argument. (default: NULL).
borlanic 0:380207fcb5c1 189 @param priority initial priority of the thread function. (default: osPriorityNormal).
borlanic 0:380207fcb5c1 190 @param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
borlanic 0:380207fcb5c1 191 @param stack_mem pointer to the stack area to be used by this thread (default: NULL).
borlanic 0:380207fcb5c1 192 @deprecated
borlanic 0:380207fcb5c1 193 Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
borlanic 0:380207fcb5c1 194
borlanic 0:380207fcb5c1 195 @code
borlanic 0:380207fcb5c1 196 Thread thread(priority, stack_size, stack_mem);
borlanic 0:380207fcb5c1 197
borlanic 0:380207fcb5c1 198 osStatus status = thread.start(callback(task, argument));
borlanic 0:380207fcb5c1 199 if (status != osOK) {
borlanic 0:380207fcb5c1 200 error("oh no!");
borlanic 0:380207fcb5c1 201 }
borlanic 0:380207fcb5c1 202 @endcode
borlanic 0:380207fcb5c1 203
borlanic 0:380207fcb5c1 204 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 205 */
borlanic 0:380207fcb5c1 206 MBED_DEPRECATED_SINCE("mbed-os-5.1",
borlanic 0:380207fcb5c1 207 "Thread-spawning constructors hide errors. "
borlanic 0:380207fcb5c1 208 "Replaced by thread.start(callback(task, argument)).")
borlanic 0:380207fcb5c1 209 Thread(void (*task)(void const *argument), void *argument=NULL,
borlanic 0:380207fcb5c1 210 osPriority priority=osPriorityNormal,
borlanic 0:380207fcb5c1 211 uint32_t stack_size=OS_STACK_SIZE,
borlanic 0:380207fcb5c1 212 unsigned char *stack_mem=NULL) {
borlanic 0:380207fcb5c1 213 constructor(mbed::callback((void (*)(void *))task, argument),
borlanic 0:380207fcb5c1 214 priority, stack_size, stack_mem);
borlanic 0:380207fcb5c1 215 }
borlanic 0:380207fcb5c1 216
borlanic 0:380207fcb5c1 217 /** Starts a thread executing the specified function.
borlanic 0:380207fcb5c1 218 @param task function to be executed by this thread.
borlanic 0:380207fcb5c1 219 @return status code that indicates the execution status of the function.
borlanic 0:380207fcb5c1 220 @note a thread can only be started once
borlanic 0:380207fcb5c1 221
borlanic 0:380207fcb5c1 222 @note You cannot call this function ISR context.
borlanic 0:380207fcb5c1 223 */
borlanic 0:380207fcb5c1 224 osStatus start(mbed::Callback<void()> task);
borlanic 0:380207fcb5c1 225
borlanic 0:380207fcb5c1 226 /** Starts a thread executing the specified function.
borlanic 0:380207fcb5c1 227 @param obj argument to task
borlanic 0:380207fcb5c1 228 @param method function to be executed by this thread.
borlanic 0:380207fcb5c1 229 @return status code that indicates the execution status of the function.
borlanic 0:380207fcb5c1 230 @deprecated
borlanic 0:380207fcb5c1 231 The start function does not support cv-qualifiers. Replaced by start(callback(obj, method)).
borlanic 0:380207fcb5c1 232
borlanic 0:380207fcb5c1 233 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 234 */
borlanic 0:380207fcb5c1 235 template <typename T, typename M>
borlanic 0:380207fcb5c1 236 MBED_DEPRECATED_SINCE("mbed-os-5.1",
borlanic 0:380207fcb5c1 237 "The start function does not support cv-qualifiers. "
borlanic 0:380207fcb5c1 238 "Replaced by thread.start(callback(obj, method)).")
borlanic 0:380207fcb5c1 239 osStatus start(T *obj, M method) {
borlanic 0:380207fcb5c1 240 return start(mbed::callback(obj, method));
borlanic 0:380207fcb5c1 241 }
borlanic 0:380207fcb5c1 242
borlanic 0:380207fcb5c1 243 /** Wait for thread to terminate
borlanic 0:380207fcb5c1 244 @return status code that indicates the execution status of the function.
borlanic 0:380207fcb5c1 245 @note not callable from interrupt
borlanic 0:380207fcb5c1 246
borlanic 0:380207fcb5c1 247 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 248 */
borlanic 0:380207fcb5c1 249 osStatus join();
borlanic 0:380207fcb5c1 250
borlanic 0:380207fcb5c1 251 /** Terminate execution of a thread and remove it from Active Threads
borlanic 0:380207fcb5c1 252 @return status code that indicates the execution status of the function.
borlanic 0:380207fcb5c1 253
borlanic 0:380207fcb5c1 254 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 255 */
borlanic 0:380207fcb5c1 256 osStatus terminate();
borlanic 0:380207fcb5c1 257
borlanic 0:380207fcb5c1 258 /** Set priority of an active thread
borlanic 0:380207fcb5c1 259 @param priority new priority value for the thread function.
borlanic 0:380207fcb5c1 260 @return status code that indicates the execution status of the function.
borlanic 0:380207fcb5c1 261
borlanic 0:380207fcb5c1 262 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 263 */
borlanic 0:380207fcb5c1 264 osStatus set_priority(osPriority priority);
borlanic 0:380207fcb5c1 265
borlanic 0:380207fcb5c1 266 /** Get priority of an active thread
borlanic 0:380207fcb5c1 267 @return current priority value of the thread function.
borlanic 0:380207fcb5c1 268
borlanic 0:380207fcb5c1 269 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 270 */
borlanic 0:380207fcb5c1 271 osPriority get_priority();
borlanic 0:380207fcb5c1 272
borlanic 0:380207fcb5c1 273 /** Set the specified Thread Flags for the thread.
borlanic 0:380207fcb5c1 274 @param signals specifies the signal flags of the thread that should be set.
borlanic 0:380207fcb5c1 275 @return signal flags after setting or osFlagsError in case of incorrect parameters.
borlanic 0:380207fcb5c1 276
borlanic 0:380207fcb5c1 277 @note You may call this function from ISR context.
borlanic 0:380207fcb5c1 278 */
borlanic 0:380207fcb5c1 279 int32_t signal_set(int32_t signals);
borlanic 0:380207fcb5c1 280
borlanic 0:380207fcb5c1 281 /** State of the Thread */
borlanic 0:380207fcb5c1 282 enum State {
borlanic 0:380207fcb5c1 283 Inactive, /**< NOT USED */
borlanic 0:380207fcb5c1 284 Ready, /**< Ready to run */
borlanic 0:380207fcb5c1 285 Running, /**< Running */
borlanic 0:380207fcb5c1 286 WaitingDelay, /**< Waiting for a delay to occur */
borlanic 0:380207fcb5c1 287 WaitingJoin, /**< Waiting for thread to join. Only happens when using RTX directly. */
borlanic 0:380207fcb5c1 288 WaitingThreadFlag, /**< Waiting for a thread flag to be set */
borlanic 0:380207fcb5c1 289 WaitingEventFlag, /**< Waiting for a event flag to be set */
borlanic 0:380207fcb5c1 290 WaitingMutex, /**< Waiting for a mutex event to occur */
borlanic 0:380207fcb5c1 291 WaitingSemaphore, /**< Waiting for a semaphore event to occur */
borlanic 0:380207fcb5c1 292 WaitingMemoryPool, /**< Waiting for a memory pool */
borlanic 0:380207fcb5c1 293 WaitingMessageGet, /**< Waiting for message to arrive */
borlanic 0:380207fcb5c1 294 WaitingMessagePut, /**< Waiting for message to be send */
borlanic 0:380207fcb5c1 295 WaitingInterval, /**< NOT USED */
borlanic 0:380207fcb5c1 296 WaitingOr, /**< NOT USED */
borlanic 0:380207fcb5c1 297 WaitingAnd, /**< NOT USED */
borlanic 0:380207fcb5c1 298 WaitingMailbox, /**< NOT USED (Mail is implemented as MemoryPool and Queue) */
borlanic 0:380207fcb5c1 299
borlanic 0:380207fcb5c1 300 /* Not in sync with RTX below here */
borlanic 0:380207fcb5c1 301 Deleted, /**< The task has been deleted or not started */
borlanic 0:380207fcb5c1 302 };
borlanic 0:380207fcb5c1 303
borlanic 0:380207fcb5c1 304 /** State of this Thread
borlanic 0:380207fcb5c1 305 @return the State of this Thread
borlanic 0:380207fcb5c1 306
borlanic 0:380207fcb5c1 307 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 308 */
borlanic 0:380207fcb5c1 309 State get_state();
borlanic 0:380207fcb5c1 310
borlanic 0:380207fcb5c1 311 /** Get the total stack memory size for this Thread
borlanic 0:380207fcb5c1 312 @return the total stack memory size in bytes
borlanic 0:380207fcb5c1 313
borlanic 0:380207fcb5c1 314 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 315 */
borlanic 0:380207fcb5c1 316 uint32_t stack_size();
borlanic 0:380207fcb5c1 317
borlanic 0:380207fcb5c1 318 /** Get the currently unused stack memory for this Thread
borlanic 0:380207fcb5c1 319 @return the currently unused stack memory in bytes
borlanic 0:380207fcb5c1 320
borlanic 0:380207fcb5c1 321 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 322 */
borlanic 0:380207fcb5c1 323 uint32_t free_stack();
borlanic 0:380207fcb5c1 324
borlanic 0:380207fcb5c1 325 /** Get the currently used stack memory for this Thread
borlanic 0:380207fcb5c1 326 @return the currently used stack memory in bytes
borlanic 0:380207fcb5c1 327
borlanic 0:380207fcb5c1 328 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 329 */
borlanic 0:380207fcb5c1 330 uint32_t used_stack();
borlanic 0:380207fcb5c1 331
borlanic 0:380207fcb5c1 332 /** Get the maximum stack memory usage to date for this Thread
borlanic 0:380207fcb5c1 333 @return the maximum stack memory usage to date in bytes
borlanic 0:380207fcb5c1 334
borlanic 0:380207fcb5c1 335 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 336 */
borlanic 0:380207fcb5c1 337 uint32_t max_stack();
borlanic 0:380207fcb5c1 338
borlanic 0:380207fcb5c1 339 /** Get thread name
borlanic 0:380207fcb5c1 340 @return thread name or NULL if the name was not set.
borlanic 0:380207fcb5c1 341
borlanic 0:380207fcb5c1 342 @note You may call this function from ISR context.
borlanic 0:380207fcb5c1 343 */
borlanic 0:380207fcb5c1 344 const char *get_name();
borlanic 0:380207fcb5c1 345
borlanic 0:380207fcb5c1 346 /** Clears the specified Thread Flags of the currently running thread.
borlanic 0:380207fcb5c1 347 @param signals specifies the signal flags of the thread that should be cleared.
borlanic 0:380207fcb5c1 348 @return signal flags before clearing or osFlagsError in case of incorrect parameters.
borlanic 0:380207fcb5c1 349
borlanic 0:380207fcb5c1 350 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 351 */
borlanic 0:380207fcb5c1 352 static int32_t signal_clr(int32_t signals);
borlanic 0:380207fcb5c1 353
borlanic 0:380207fcb5c1 354 /** Wait for one or more Thread Flags to become signaled for the current RUNNING thread.
borlanic 0:380207fcb5c1 355 @param signals wait until all specified signal flags are set or 0 for any single signal flag.
borlanic 0:380207fcb5c1 356 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
borlanic 0:380207fcb5c1 357 @return event flag information or error code. @note if @a millisec is set to 0 and flag is no set the event carries osOK value.
borlanic 0:380207fcb5c1 358
borlanic 0:380207fcb5c1 359 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 360 */
borlanic 0:380207fcb5c1 361 static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever);
borlanic 0:380207fcb5c1 362
borlanic 0:380207fcb5c1 363 /** Wait for a specified time period in milliseconds
borlanic 0:380207fcb5c1 364 Being tick-based, the delay will be up to the specified time - eg for
borlanic 0:380207fcb5c1 365 a value of 1 the system waits until the next millisecond tick occurs,
borlanic 0:380207fcb5c1 366 leading to a delay of 0-1 milliseconds.
borlanic 0:380207fcb5c1 367 @param millisec time delay value
borlanic 0:380207fcb5c1 368 @return status code that indicates the execution status of the function.
borlanic 0:380207fcb5c1 369
borlanic 0:380207fcb5c1 370 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 371 */
borlanic 0:380207fcb5c1 372 static osStatus wait(uint32_t millisec);
borlanic 0:380207fcb5c1 373
borlanic 0:380207fcb5c1 374 /** Wait until a specified time in millisec
borlanic 0:380207fcb5c1 375 The specified time is according to Kernel::get_ms_count().
borlanic 0:380207fcb5c1 376 @param millisec absolute time in millisec
borlanic 0:380207fcb5c1 377 @return status code that indicates the execution status of the function.
borlanic 0:380207fcb5c1 378 @note not callable from interrupt
borlanic 0:380207fcb5c1 379 @note if millisec is equal to or lower than the current tick count, this
borlanic 0:380207fcb5c1 380 returns immediately, either with an error or "osOK".
borlanic 0:380207fcb5c1 381 @note the underlying RTOS may have a limit to the maximum wait time
borlanic 0:380207fcb5c1 382 due to internal 32-bit computations, but this is guaranteed to work if the
borlanic 0:380207fcb5c1 383 delay is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded,
borlanic 0:380207fcb5c1 384 it may return with an immediate error, or wait for the maximum delay.
borlanic 0:380207fcb5c1 385
borlanic 0:380207fcb5c1 386 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 387 */
borlanic 0:380207fcb5c1 388 static osStatus wait_until(uint64_t millisec);
borlanic 0:380207fcb5c1 389
borlanic 0:380207fcb5c1 390 /** Pass control to next thread that is in state READY.
borlanic 0:380207fcb5c1 391 @return status code that indicates the execution status of the function.
borlanic 0:380207fcb5c1 392
borlanic 0:380207fcb5c1 393 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 394 */
borlanic 0:380207fcb5c1 395 static osStatus yield();
borlanic 0:380207fcb5c1 396
borlanic 0:380207fcb5c1 397 /** Get the thread id of the current running thread.
borlanic 0:380207fcb5c1 398 @return thread ID for reference by other functions or NULL in case of error.
borlanic 0:380207fcb5c1 399
borlanic 0:380207fcb5c1 400 @note You may call this function from ISR context.
borlanic 0:380207fcb5c1 401 */
borlanic 0:380207fcb5c1 402 static osThreadId gettid();
borlanic 0:380207fcb5c1 403
borlanic 0:380207fcb5c1 404 /** Attach a function to be called by the RTOS idle task
borlanic 0:380207fcb5c1 405 @param fptr pointer to the function to be called
borlanic 0:380207fcb5c1 406
borlanic 0:380207fcb5c1 407 @note You may call this function from ISR context.
borlanic 0:380207fcb5c1 408 */
borlanic 0:380207fcb5c1 409 static void attach_idle_hook(void (*fptr)(void));
borlanic 0:380207fcb5c1 410
borlanic 0:380207fcb5c1 411 /** Attach a function to be called when a task is killed
borlanic 0:380207fcb5c1 412 @param fptr pointer to the function to be called
borlanic 0:380207fcb5c1 413
borlanic 0:380207fcb5c1 414 @note You may call this function from ISR context.
borlanic 0:380207fcb5c1 415 */
borlanic 0:380207fcb5c1 416 static void attach_terminate_hook(void (*fptr)(osThreadId id));
borlanic 0:380207fcb5c1 417
borlanic 0:380207fcb5c1 418 /** Thread destructor
borlanic 0:380207fcb5c1 419 *
borlanic 0:380207fcb5c1 420 * @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 421 */
borlanic 0:380207fcb5c1 422 virtual ~Thread();
borlanic 0:380207fcb5c1 423
borlanic 0:380207fcb5c1 424 private:
borlanic 0:380207fcb5c1 425 // Required to share definitions without
borlanic 0:380207fcb5c1 426 // delegated constructors
borlanic 0:380207fcb5c1 427 void constructor(osPriority priority=osPriorityNormal,
borlanic 0:380207fcb5c1 428 uint32_t stack_size=OS_STACK_SIZE,
borlanic 0:380207fcb5c1 429 unsigned char *stack_mem=NULL,
borlanic 0:380207fcb5c1 430 const char *name=NULL);
borlanic 0:380207fcb5c1 431 void constructor(mbed::Callback<void()> task,
borlanic 0:380207fcb5c1 432 osPriority priority=osPriorityNormal,
borlanic 0:380207fcb5c1 433 uint32_t stack_size=OS_STACK_SIZE,
borlanic 0:380207fcb5c1 434 unsigned char *stack_mem=NULL,
borlanic 0:380207fcb5c1 435 const char *name=NULL);
borlanic 0:380207fcb5c1 436 static void _thunk(void * thread_ptr);
borlanic 0:380207fcb5c1 437
borlanic 0:380207fcb5c1 438 mbed::Callback<void()> _task;
borlanic 0:380207fcb5c1 439 osThreadId_t _tid;
borlanic 0:380207fcb5c1 440 osThreadAttr_t _attr;
borlanic 0:380207fcb5c1 441 bool _dynamic_stack;
borlanic 0:380207fcb5c1 442 Semaphore _join_sem;
borlanic 0:380207fcb5c1 443 Mutex _mutex;
borlanic 0:380207fcb5c1 444 mbed_rtos_storage_thread_t _obj_mem;
borlanic 0:380207fcb5c1 445 bool _finished;
borlanic 0:380207fcb5c1 446 };
borlanic 0:380207fcb5c1 447 /** @}*/
borlanic 0:380207fcb5c1 448 /** @}*/
borlanic 0:380207fcb5c1 449 }
borlanic 0:380207fcb5c1 450 #endif
borlanic 0:380207fcb5c1 451
borlanic 0:380207fcb5c1 452