Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.
Dependents: Assignment_3__Embedded_Software
Fork of mbed-rtos by
rtos/Thread.h@76:85a52b7ef44b, 2015-05-05 (annotated)
- Committer:
- mbed_official
- Date:
- Tue May 05 08:00:49 2015 +0100
- Revision:
- 76:85a52b7ef44b
- Parent:
- 31:015df9e602b6
- Child:
- 84:143955ffb790
Synchronized with git revision 16156f526db4b960762ba02dab48025d9d9a4531
Full URL: https://github.com/mbedmicro/mbed/commit/16156f526db4b960762ba02dab48025d9d9a4531/
Updated Thread.cpp|.h to support signal clear
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 | 31:015df9e602b6 | 91 | |
mbed_official | 31:015df9e602b6 | 92 | /** Wait for one or more Signal Flags to become signaled for the current RUNNING thread. |
emilmont | 8:88a1a9c26ae3 | 93 | @param signals wait until all specified signal flags set or 0 for any single signal flag. |
emilmont | 8:88a1a9c26ae3 | 94 | @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever). |
emilmont | 8:88a1a9c26ae3 | 95 | @return event flag information or error code. |
emilmont | 6:350b53afb889 | 96 | */ |
emilmont | 6:350b53afb889 | 97 | static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever); |
mbed_official | 31:015df9e602b6 | 98 | |
emilmont | 8:88a1a9c26ae3 | 99 | /** Wait for a specified time period in millisec: |
emilmont | 8:88a1a9c26ae3 | 100 | @param millisec time delay value |
mbed_official | 31:015df9e602b6 | 101 | @return status code that indicates the execution status of the function. |
emilmont | 6:350b53afb889 | 102 | */ |
emilmont | 6:350b53afb889 | 103 | static osStatus wait(uint32_t millisec); |
mbed_official | 31:015df9e602b6 | 104 | |
emilmont | 8:88a1a9c26ae3 | 105 | /** Pass control to next thread that is in state READY. |
emilmont | 8:88a1a9c26ae3 | 106 | @return status code that indicates the execution status of the function. |
emilmont | 6:350b53afb889 | 107 | */ |
emilmont | 6:350b53afb889 | 108 | static osStatus yield(); |
mbed_official | 31:015df9e602b6 | 109 | |
emilmont | 8:88a1a9c26ae3 | 110 | /** Get the thread id of the current running thread. |
emilmont | 8:88a1a9c26ae3 | 111 | @return thread ID for reference by other functions or NULL in case of error. |
emilmont | 6:350b53afb889 | 112 | */ |
emilmont | 6:350b53afb889 | 113 | static osThreadId gettid(); |
mbed_official | 31:015df9e602b6 | 114 | |
emilmont | 6:350b53afb889 | 115 | virtual ~Thread(); |
emilmont | 6:350b53afb889 | 116 | |
emilmont | 6:350b53afb889 | 117 | private: |
emilmont | 6:350b53afb889 | 118 | osThreadId _tid; |
emilmont | 6:350b53afb889 | 119 | osThreadDef_t _thread_def; |
emilmont | 6:350b53afb889 | 120 | bool _dynamic_stack; |
emilmont | 6:350b53afb889 | 121 | }; |
emilmont | 6:350b53afb889 | 122 | |
emilmont | 6:350b53afb889 | 123 | } |
emilmont | 6:350b53afb889 | 124 | #endif |