f
Dependents: Active-WolfMan_V2-5-All-Frank-Board-Functions_copy
rtos/Thread.h@107:bdd541595fc5, 2016-03-15 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Mar 15 09:00:39 2016 +0000
- Revision:
- 107:bdd541595fc5
- Parent:
- 84:143955ffb790
- Child:
- 118:6635230e06ba
Synchronized with git revision 3afb55095212c88fc1c17177348bc1e16259c1ca
Full URL: https://github.com/mbedmicro/mbed/commit/3afb55095212c88fc1c17177348bc1e16259c1ca/
[STM32F4] Add DEVICE_RTC_LSI=0 to all targets
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 8:88a1a9c26ae3 | 1 | /* mbed Microcontroller Library |
emilmont | 8:88a1a9c26ae3 | 2 | * Copyright (c) 2006-2012 ARM Limited |
emilmont | 8:88a1a9c26ae3 | 3 | * |
emilmont | 8:88a1a9c26ae3 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
emilmont | 8:88a1a9c26ae3 | 5 | * of this software and associated documentation files (the "Software"), to deal |
emilmont | 8:88a1a9c26ae3 | 6 | * in the Software without restriction, including without limitation the rights |
emilmont | 8:88a1a9c26ae3 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
emilmont | 8:88a1a9c26ae3 | 8 | * copies of the Software, and to permit persons to whom the Software is |
emilmont | 8:88a1a9c26ae3 | 9 | * furnished to do so, subject to the following conditions: |
emilmont | 8:88a1a9c26ae3 | 10 | * |
emilmont | 8:88a1a9c26ae3 | 11 | * The above copyright notice and this permission notice shall be included in |
emilmont | 8:88a1a9c26ae3 | 12 | * all copies or substantial portions of the Software. |
emilmont | 8:88a1a9c26ae3 | 13 | * |
emilmont | 8:88a1a9c26ae3 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
emilmont | 8:88a1a9c26ae3 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
emilmont | 8:88a1a9c26ae3 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
emilmont | 8:88a1a9c26ae3 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
emilmont | 8:88a1a9c26ae3 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
emilmont | 8:88a1a9c26ae3 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
emilmont | 8:88a1a9c26ae3 | 20 | * SOFTWARE. |
emilmont | 8:88a1a9c26ae3 | 21 | */ |
emilmont | 6:350b53afb889 | 22 | #ifndef THREAD_H |
emilmont | 8:88a1a9c26ae3 | 23 | #define THREAD_H |
emilmont | 6:350b53afb889 | 24 | |
emilmont | 6:350b53afb889 | 25 | #include <stdint.h> |
emilmont | 6:350b53afb889 | 26 | #include "cmsis_os.h" |
emilmont | 6:350b53afb889 | 27 | |
emilmont | 6:350b53afb889 | 28 | namespace rtos { |
emilmont | 6:350b53afb889 | 29 | |
emilmont | 8:88a1a9c26ae3 | 30 | /** The Thread class allow defining, creating, and controlling thread functions in the system. */ |
emilmont | 6:350b53afb889 | 31 | class Thread { |
emilmont | 6:350b53afb889 | 32 | public: |
emilmont | 8:88a1a9c26ae3 | 33 | /** Create a new thread, and start it executing the specified function. |
emilmont | 8:88a1a9c26ae3 | 34 | @param task function to be executed by this thread. |
emilmont | 8:88a1a9c26ae3 | 35 | @param argument pointer that is passed to the thread function as start argument. (default: NULL). |
emilmont | 8:88a1a9c26ae3 | 36 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
emilmont | 8:88a1a9c26ae3 | 37 | @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). |
emilmont | 8:88a1a9c26ae3 | 38 | @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). |
emilmont | 6:350b53afb889 | 39 | */ |
emilmont | 6:350b53afb889 | 40 | Thread(void (*task)(void const *argument), void *argument=NULL, |
emilmont | 6:350b53afb889 | 41 | osPriority priority=osPriorityNormal, |
emilmont | 6:350b53afb889 | 42 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
emilmont | 6:350b53afb889 | 43 | unsigned char *stack_pointer=NULL); |
mbed_official | 31:015df9e602b6 | 44 | |
emilmont | 8:88a1a9c26ae3 | 45 | /** Terminate execution of a thread and remove it from Active Threads |
emilmont | 8:88a1a9c26ae3 | 46 | @return status code that indicates the execution status of the function. |
emilmont | 6:350b53afb889 | 47 | */ |
emilmont | 6:350b53afb889 | 48 | osStatus terminate(); |
mbed_official | 31:015df9e602b6 | 49 | |
emilmont | 8:88a1a9c26ae3 | 50 | /** Set priority of an active thread |
emilmont | 8:88a1a9c26ae3 | 51 | @param priority new priority value for the thread function. |
emilmont | 8:88a1a9c26ae3 | 52 | @return status code that indicates the execution status of the function. |
emilmont | 6:350b53afb889 | 53 | */ |
emilmont | 6:350b53afb889 | 54 | osStatus set_priority(osPriority priority); |
mbed_official | 31:015df9e602b6 | 55 | |
emilmont | 8:88a1a9c26ae3 | 56 | /** Get priority of an active thread |
emilmont | 8:88a1a9c26ae3 | 57 | @return current priority value of the thread function. |
emilmont | 6:350b53afb889 | 58 | */ |
emilmont | 6:350b53afb889 | 59 | osPriority get_priority(); |
mbed_official | 31:015df9e602b6 | 60 | |
emilmont | 8:88a1a9c26ae3 | 61 | /** Set the specified Signal Flags of an active thread. |
emilmont | 8:88a1a9c26ae3 | 62 | @param signals specifies the signal flags of the thread that should be set. |
emilmont | 8:88a1a9c26ae3 | 63 | @return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. |
emilmont | 6:350b53afb889 | 64 | */ |
emilmont | 6:350b53afb889 | 65 | int32_t signal_set(int32_t signals); |
mbed_official | 31:015df9e602b6 | 66 | |
mbed_official | 76:85a52b7ef44b | 67 | /** Clears the specified Signal Flags of an active thread. |
mbed_official | 76:85a52b7ef44b | 68 | @param signals specifies the signal flags of the thread that should be cleared. |
mbed_official | 76:85a52b7ef44b | 69 | @return resultant signal flags of the specified thread or 0x80000000 in case of incorrect parameters. |
mbed_official | 76:85a52b7ef44b | 70 | */ |
mbed_official | 76:85a52b7ef44b | 71 | int32_t signal_clr(int32_t signals); |
mbed_official | 76:85a52b7ef44b | 72 | |
emilmont | 8:88a1a9c26ae3 | 73 | /** State of the Thread */ |
emilmont | 8:88a1a9c26ae3 | 74 | enum State { |
emilmont | 8:88a1a9c26ae3 | 75 | Inactive, /**< Not created or terminated */ |
emilmont | 8:88a1a9c26ae3 | 76 | Ready, /**< Ready to run */ |
emilmont | 8:88a1a9c26ae3 | 77 | Running, /**< Running */ |
emilmont | 8:88a1a9c26ae3 | 78 | WaitingDelay, /**< Waiting for a delay to occur */ |
emilmont | 8:88a1a9c26ae3 | 79 | WaitingInterval, /**< Waiting for an interval to occur */ |
emilmont | 8:88a1a9c26ae3 | 80 | WaitingOr, /**< Waiting for one event in a set to occur */ |
emilmont | 8:88a1a9c26ae3 | 81 | WaitingAnd, /**< Waiting for multiple events in a set to occur */ |
emilmont | 8:88a1a9c26ae3 | 82 | WaitingSemaphore, /**< Waiting for a semaphore event to occur */ |
emilmont | 8:88a1a9c26ae3 | 83 | WaitingMailbox, /**< Waiting for a mailbox event to occur */ |
emilmont | 8:88a1a9c26ae3 | 84 | WaitingMutex, /**< Waiting for a mutex event to occur */ |
emilmont | 8:88a1a9c26ae3 | 85 | }; |
mbed_official | 31:015df9e602b6 | 86 | |
emilmont | 8:88a1a9c26ae3 | 87 | /** State of this Thread |
emilmont | 8:88a1a9c26ae3 | 88 | @return the State of this Thread |
emilmont | 8:88a1a9c26ae3 | 89 | */ |
emilmont | 8:88a1a9c26ae3 | 90 | State get_state(); |
mbed_official | 84:143955ffb790 | 91 | |
mbed_official | 84:143955ffb790 | 92 | /** Get the total stack memory size for this Thread |
mbed_official | 84:143955ffb790 | 93 | @return the total stack memory size in bytes |
mbed_official | 84:143955ffb790 | 94 | */ |
mbed_official | 84:143955ffb790 | 95 | uint32_t stack_size(); |
mbed_official | 84:143955ffb790 | 96 | |
mbed_official | 84:143955ffb790 | 97 | /** Get the currently unused stack memory for this Thread |
mbed_official | 84:143955ffb790 | 98 | @return the currently unused stack memory in bytes |
mbed_official | 84:143955ffb790 | 99 | */ |
mbed_official | 84:143955ffb790 | 100 | uint32_t free_stack(); |
mbed_official | 84:143955ffb790 | 101 | |
mbed_official | 84:143955ffb790 | 102 | /** Get the currently used stack memory for this Thread |
mbed_official | 84:143955ffb790 | 103 | @return the currently used stack memory in bytes |
mbed_official | 84:143955ffb790 | 104 | */ |
mbed_official | 84:143955ffb790 | 105 | uint32_t used_stack(); |
mbed_official | 84:143955ffb790 | 106 | |
mbed_official | 84:143955ffb790 | 107 | /** Get the maximum stack memory usage to date for this Thread |
mbed_official | 84:143955ffb790 | 108 | @return the maximum stack memory usage to date in bytes |
mbed_official | 84:143955ffb790 | 109 | */ |
mbed_official | 84:143955ffb790 | 110 | uint32_t max_stack(); |
mbed_official | 31:015df9e602b6 | 111 | |
mbed_official | 31:015df9e602b6 | 112 | /** Wait for one or more Signal Flags to become signaled for the current RUNNING thread. |
emilmont | 8:88a1a9c26ae3 | 113 | @param signals wait until all specified signal flags set or 0 for any single signal flag. |
emilmont | 8:88a1a9c26ae3 | 114 | @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever). |
emilmont | 8:88a1a9c26ae3 | 115 | @return event flag information or error code. |
emilmont | 6:350b53afb889 | 116 | */ |
emilmont | 6:350b53afb889 | 117 | static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever); |
mbed_official | 31:015df9e602b6 | 118 | |
emilmont | 8:88a1a9c26ae3 | 119 | /** Wait for a specified time period in millisec: |
emilmont | 8:88a1a9c26ae3 | 120 | @param millisec time delay value |
mbed_official | 31:015df9e602b6 | 121 | @return status code that indicates the execution status of the function. |
emilmont | 6:350b53afb889 | 122 | */ |
emilmont | 6:350b53afb889 | 123 | static osStatus wait(uint32_t millisec); |
mbed_official | 31:015df9e602b6 | 124 | |
emilmont | 8:88a1a9c26ae3 | 125 | /** Pass control to next thread that is in state READY. |
emilmont | 8:88a1a9c26ae3 | 126 | @return status code that indicates the execution status of the function. |
emilmont | 6:350b53afb889 | 127 | */ |
emilmont | 6:350b53afb889 | 128 | static osStatus yield(); |
mbed_official | 31:015df9e602b6 | 129 | |
emilmont | 8:88a1a9c26ae3 | 130 | /** Get the thread id of the current running thread. |
emilmont | 8:88a1a9c26ae3 | 131 | @return thread ID for reference by other functions or NULL in case of error. |
emilmont | 6:350b53afb889 | 132 | */ |
emilmont | 6:350b53afb889 | 133 | static osThreadId gettid(); |
mbed_official | 107:bdd541595fc5 | 134 | |
mbed_official | 107:bdd541595fc5 | 135 | /** Attach a function to be called by the RTOS idle task |
mbed_official | 107:bdd541595fc5 | 136 | @param fptr pointer to the function to be called |
mbed_official | 107:bdd541595fc5 | 137 | */ |
mbed_official | 107:bdd541595fc5 | 138 | static void attach_idle_hook(void (*fptr)(void)); |
mbed_official | 31:015df9e602b6 | 139 | |
emilmont | 6:350b53afb889 | 140 | virtual ~Thread(); |
emilmont | 6:350b53afb889 | 141 | |
emilmont | 6:350b53afb889 | 142 | private: |
emilmont | 6:350b53afb889 | 143 | osThreadId _tid; |
emilmont | 6:350b53afb889 | 144 | osThreadDef_t _thread_def; |
emilmont | 6:350b53afb889 | 145 | bool _dynamic_stack; |
emilmont | 6:350b53afb889 | 146 | }; |
emilmont | 6:350b53afb889 | 147 | |
emilmont | 6:350b53afb889 | 148 | } |
emilmont | 6:350b53afb889 | 149 | #endif |