Code for our FYDP -only one IMU works right now -RTOS is working

Dependencies:   mbed

Committer:
majik
Date:
Wed Mar 18 22:23:48 2015 +0000
Revision:
0:964eb6a2ef00
This is our FYDP code, but only one IMU works with the RTOS.

Who changed what in which revision?

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