BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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