Code for controlling mbed hardware (LED's, motors), as well as code for the Raspberry Pi to run a Support Vector Machine that identifies objects using the Pi camera

Dependencies:   mbed Motordriver mbed-rtos PololuLedStrip

Committer:
arogliero3
Date:
Fri Dec 06 00:58:02 2019 -0500
Revision:
3:a3ed7ff99772
Parent:
0:e0dbd261724a
update img6

Who changed what in which revision?

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