The code from https://github.com/vpcola/Nucleo

Committer:
sinrab
Date:
Wed Oct 08 11:00:24 2014 +0000
Revision:
0:5464d5e415e5
The code from https://github.com/vpcola/Nucleo

Who changed what in which revision?

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