skeleton for lab1

Dependencies:   AvailableMemory mbed-rtos mbed

Fork of helloaabbc by 32314 mbed

Committer:
y7jin
Date:
Thu Apr 03 22:56:32 2014 +0000
Revision:
0:1c8f2727e9f5
hello

Who changed what in which revision?

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