First Commit

Dependents:   uLCD_Multiscreen

Committer:
Mkuchnik3
Date:
Wed Mar 11 21:31:16 2015 +0000
Revision:
0:8b4ab67d92b2
First Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mkuchnik3 0:8b4ab67d92b2 1 /* mbed Microcontroller Library
Mkuchnik3 0:8b4ab67d92b2 2 * Copyright (c) 2006-2012 ARM Limited
Mkuchnik3 0:8b4ab67d92b2 3 *
Mkuchnik3 0:8b4ab67d92b2 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
Mkuchnik3 0:8b4ab67d92b2 5 * of this software and associated documentation files (the "Software"), to deal
Mkuchnik3 0:8b4ab67d92b2 6 * in the Software without restriction, including without limitation the rights
Mkuchnik3 0:8b4ab67d92b2 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Mkuchnik3 0:8b4ab67d92b2 8 * copies of the Software, and to permit persons to whom the Software is
Mkuchnik3 0:8b4ab67d92b2 9 * furnished to do so, subject to the following conditions:
Mkuchnik3 0:8b4ab67d92b2 10 *
Mkuchnik3 0:8b4ab67d92b2 11 * The above copyright notice and this permission notice shall be included in
Mkuchnik3 0:8b4ab67d92b2 12 * all copies or substantial portions of the Software.
Mkuchnik3 0:8b4ab67d92b2 13 *
Mkuchnik3 0:8b4ab67d92b2 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Mkuchnik3 0:8b4ab67d92b2 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Mkuchnik3 0:8b4ab67d92b2 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Mkuchnik3 0:8b4ab67d92b2 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Mkuchnik3 0:8b4ab67d92b2 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Mkuchnik3 0:8b4ab67d92b2 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Mkuchnik3 0:8b4ab67d92b2 20 * SOFTWARE.
Mkuchnik3 0:8b4ab67d92b2 21 */
Mkuchnik3 0:8b4ab67d92b2 22 #ifndef THREAD_H
Mkuchnik3 0:8b4ab67d92b2 23 #define THREAD_H
Mkuchnik3 0:8b4ab67d92b2 24
Mkuchnik3 0:8b4ab67d92b2 25 #include <stdint.h>
Mkuchnik3 0:8b4ab67d92b2 26 #include "cmsis_os.h"
Mkuchnik3 0:8b4ab67d92b2 27
Mkuchnik3 0:8b4ab67d92b2 28 namespace rtos {
Mkuchnik3 0:8b4ab67d92b2 29
Mkuchnik3 0:8b4ab67d92b2 30 /** The Thread class allow defining, creating, and controlling thread functions in the system. */
Mkuchnik3 0:8b4ab67d92b2 31 class Thread {
Mkuchnik3 0:8b4ab67d92b2 32 public:
Mkuchnik3 0:8b4ab67d92b2 33 /** Create a new thread, and start it executing the specified function.
Mkuchnik3 0:8b4ab67d92b2 34 @param task function to be executed by this thread.
Mkuchnik3 0:8b4ab67d92b2 35 @param argument pointer that is passed to the thread function as start argument. (default: NULL).
Mkuchnik3 0:8b4ab67d92b2 36 @param priority initial priority of the thread function. (default: osPriorityNormal).
Mkuchnik3 0:8b4ab67d92b2 37 @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
Mkuchnik3 0:8b4ab67d92b2 38 @param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
Mkuchnik3 0:8b4ab67d92b2 39 */
Mkuchnik3 0:8b4ab67d92b2 40 Thread(void (*task)(void const *argument), void *argument=NULL,
Mkuchnik3 0:8b4ab67d92b2 41 osPriority priority=osPriorityNormal,
Mkuchnik3 0:8b4ab67d92b2 42 uint32_t stack_size=DEFAULT_STACK_SIZE,
Mkuchnik3 0:8b4ab67d92b2 43 unsigned char *stack_pointer=NULL);
Mkuchnik3 0:8b4ab67d92b2 44
Mkuchnik3 0:8b4ab67d92b2 45 /** Terminate execution of a thread and remove it from Active Threads
Mkuchnik3 0:8b4ab67d92b2 46 @return status code that indicates the execution status of the function.
Mkuchnik3 0:8b4ab67d92b2 47 */
Mkuchnik3 0:8b4ab67d92b2 48 osStatus terminate();
Mkuchnik3 0:8b4ab67d92b2 49
Mkuchnik3 0:8b4ab67d92b2 50 /** Set priority of an active thread
Mkuchnik3 0:8b4ab67d92b2 51 @param priority new priority value for the thread function.
Mkuchnik3 0:8b4ab67d92b2 52 @return status code that indicates the execution status of the function.
Mkuchnik3 0:8b4ab67d92b2 53 */
Mkuchnik3 0:8b4ab67d92b2 54 osStatus set_priority(osPriority priority);
Mkuchnik3 0:8b4ab67d92b2 55
Mkuchnik3 0:8b4ab67d92b2 56 /** Get priority of an active thread
Mkuchnik3 0:8b4ab67d92b2 57 @return current priority value of the thread function.
Mkuchnik3 0:8b4ab67d92b2 58 */
Mkuchnik3 0:8b4ab67d92b2 59 osPriority get_priority();
Mkuchnik3 0:8b4ab67d92b2 60
Mkuchnik3 0:8b4ab67d92b2 61 /** Set the specified Signal Flags of an active thread.
Mkuchnik3 0:8b4ab67d92b2 62 @param signals specifies the signal flags of the thread that should be set.
Mkuchnik3 0:8b4ab67d92b2 63 @return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
Mkuchnik3 0:8b4ab67d92b2 64 */
Mkuchnik3 0:8b4ab67d92b2 65 int32_t signal_set(int32_t signals);
Mkuchnik3 0:8b4ab67d92b2 66
Mkuchnik3 0:8b4ab67d92b2 67 /** State of the Thread */
Mkuchnik3 0:8b4ab67d92b2 68 enum State {
Mkuchnik3 0:8b4ab67d92b2 69 Inactive, /**< Not created or terminated */
Mkuchnik3 0:8b4ab67d92b2 70 Ready, /**< Ready to run */
Mkuchnik3 0:8b4ab67d92b2 71 Running, /**< Running */
Mkuchnik3 0:8b4ab67d92b2 72 WaitingDelay, /**< Waiting for a delay to occur */
Mkuchnik3 0:8b4ab67d92b2 73 WaitingInterval, /**< Waiting for an interval to occur */
Mkuchnik3 0:8b4ab67d92b2 74 WaitingOr, /**< Waiting for one event in a set to occur */
Mkuchnik3 0:8b4ab67d92b2 75 WaitingAnd, /**< Waiting for multiple events in a set to occur */
Mkuchnik3 0:8b4ab67d92b2 76 WaitingSemaphore, /**< Waiting for a semaphore event to occur */
Mkuchnik3 0:8b4ab67d92b2 77 WaitingMailbox, /**< Waiting for a mailbox event to occur */
Mkuchnik3 0:8b4ab67d92b2 78 WaitingMutex, /**< Waiting for a mutex event to occur */
Mkuchnik3 0:8b4ab67d92b2 79 };
Mkuchnik3 0:8b4ab67d92b2 80
Mkuchnik3 0:8b4ab67d92b2 81 /** State of this Thread
Mkuchnik3 0:8b4ab67d92b2 82 @return the State of this Thread
Mkuchnik3 0:8b4ab67d92b2 83 */
Mkuchnik3 0:8b4ab67d92b2 84 State get_state();
Mkuchnik3 0:8b4ab67d92b2 85
Mkuchnik3 0:8b4ab67d92b2 86 /** Wait for one or more Signal Flags to become signaled for the current RUNNING thread.
Mkuchnik3 0:8b4ab67d92b2 87 @param signals wait until all specified signal flags set or 0 for any single signal flag.
Mkuchnik3 0:8b4ab67d92b2 88 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
Mkuchnik3 0:8b4ab67d92b2 89 @return event flag information or error code.
Mkuchnik3 0:8b4ab67d92b2 90 */
Mkuchnik3 0:8b4ab67d92b2 91 static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever);
Mkuchnik3 0:8b4ab67d92b2 92
Mkuchnik3 0:8b4ab67d92b2 93 /** Wait for a specified time period in millisec:
Mkuchnik3 0:8b4ab67d92b2 94 @param millisec time delay value
Mkuchnik3 0:8b4ab67d92b2 95 @return status code that indicates the execution status of the function.
Mkuchnik3 0:8b4ab67d92b2 96 */
Mkuchnik3 0:8b4ab67d92b2 97 static osStatus wait(uint32_t millisec);
Mkuchnik3 0:8b4ab67d92b2 98
Mkuchnik3 0:8b4ab67d92b2 99 /** Pass control to next thread that is in state READY.
Mkuchnik3 0:8b4ab67d92b2 100 @return status code that indicates the execution status of the function.
Mkuchnik3 0:8b4ab67d92b2 101 */
Mkuchnik3 0:8b4ab67d92b2 102 static osStatus yield();
Mkuchnik3 0:8b4ab67d92b2 103
Mkuchnik3 0:8b4ab67d92b2 104 /** Get the thread id of the current running thread.
Mkuchnik3 0:8b4ab67d92b2 105 @return thread ID for reference by other functions or NULL in case of error.
Mkuchnik3 0:8b4ab67d92b2 106 */
Mkuchnik3 0:8b4ab67d92b2 107 static osThreadId gettid();
Mkuchnik3 0:8b4ab67d92b2 108
Mkuchnik3 0:8b4ab67d92b2 109 virtual ~Thread();
Mkuchnik3 0:8b4ab67d92b2 110
Mkuchnik3 0:8b4ab67d92b2 111 private:
Mkuchnik3 0:8b4ab67d92b2 112 osThreadId _tid;
Mkuchnik3 0:8b4ab67d92b2 113 osThreadDef_t _thread_def;
Mkuchnik3 0:8b4ab67d92b2 114 bool _dynamic_stack;
Mkuchnik3 0:8b4ab67d92b2 115 };
Mkuchnik3 0:8b4ab67d92b2 116
Mkuchnik3 0:8b4ab67d92b2 117 }
Mkuchnik3 0:8b4ab67d92b2 118 #endif