Dependencies:   Servo mbed

Fork of FYDP_Final2 by Mark Vandermeulen

Committer:
tntmarket
Date:
Wed Mar 25 09:58:50 2015 +0000
Revision:
5:d2e955a94940
Parent:
0:21019d94ad33
only imu output

Who changed what in which revision?

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