mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 31 06:02:27 2019 +0000
Revision:
1:9db0e321a9f4
Parent:
0:5b88d5760320
updated based on mbed-os5.15.0

Who changed what in which revision?

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