RTOS lib used for Eurobot 2012

Dependents:   Eurobot2012_Secondary Team_Sprint2 Team_Sprint2 Rafi_Final ... more

Committer:
narshu
Date:
Tue Aug 07 10:24:02 2012 +0000
Revision:
0:e477ba491a3b
[mbed] converted /Eurobot_2012_Secondary/rtos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
narshu 0:e477ba491a3b 1 /* Copyright (c) 2012 mbed.org */
narshu 0:e477ba491a3b 2 #ifndef THREAD_H
narshu 0:e477ba491a3b 3 #define THREAD_H
narshu 0:e477ba491a3b 4
narshu 0:e477ba491a3b 5 #include <stdint.h>
narshu 0:e477ba491a3b 6 #include "cmsis_os.h"
narshu 0:e477ba491a3b 7
narshu 0:e477ba491a3b 8 namespace rtos {
narshu 0:e477ba491a3b 9
narshu 0:e477ba491a3b 10 /*! The Thread class allow defining, creating, and controlling thread functions in the system. */
narshu 0:e477ba491a3b 11 class Thread {
narshu 0:e477ba491a3b 12 public:
narshu 0:e477ba491a3b 13 /*! Create a new thread, and start it executing the specified function.
narshu 0:e477ba491a3b 14 \param task function to be executed by this thread.
narshu 0:e477ba491a3b 15 \param argument pointer that is passed to the thread function as start argument. (default: NULL).
narshu 0:e477ba491a3b 16 \param priority initial priority of the thread function. (default: osPriorityNormal).
narshu 0:e477ba491a3b 17 \param stacksz stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
narshu 0:e477ba491a3b 18 */
narshu 0:e477ba491a3b 19 Thread(void (*task)(void const *argument),
narshu 0:e477ba491a3b 20 void *argument=NULL,
narshu 0:e477ba491a3b 21 osPriority priority=osPriorityNormal,
narshu 0:e477ba491a3b 22 uint32_t stacksize=DEFAULT_STACK_SIZE);
narshu 0:e477ba491a3b 23
narshu 0:e477ba491a3b 24 /*! Terminate execution of a thread and remove it from Active Threads
narshu 0:e477ba491a3b 25 \return status code that indicates the execution status of the function.
narshu 0:e477ba491a3b 26 */
narshu 0:e477ba491a3b 27 osStatus terminate();
narshu 0:e477ba491a3b 28
narshu 0:e477ba491a3b 29 /*! Set priority of an active thread
narshu 0:e477ba491a3b 30 \param priority new priority value for the thread function.
narshu 0:e477ba491a3b 31 \return status code that indicates the execution status of the function.
narshu 0:e477ba491a3b 32 */
narshu 0:e477ba491a3b 33 osStatus set_priority(osPriority priority);
narshu 0:e477ba491a3b 34
narshu 0:e477ba491a3b 35 /*! Get priority of an active thread
narshu 0:e477ba491a3b 36 \ return current priority value of the thread function.
narshu 0:e477ba491a3b 37 */
narshu 0:e477ba491a3b 38 osPriority get_priority();
narshu 0:e477ba491a3b 39
narshu 0:e477ba491a3b 40 /*! Set the specified Signal Flags of an active thread.
narshu 0:e477ba491a3b 41 \param signals specifies the signal flags of the thread that should be set.
narshu 0:e477ba491a3b 42 \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
narshu 0:e477ba491a3b 43 */
narshu 0:e477ba491a3b 44 int32_t signal_set(int32_t signals);
narshu 0:e477ba491a3b 45
narshu 0:e477ba491a3b 46 /*! Wait for one or more Signal Flags to become signaled for the current RUNNING thread.
narshu 0:e477ba491a3b 47 \param signals wait until all specified signal flags set or 0 for any single signal flag.
narshu 0:e477ba491a3b 48 \param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
narshu 0:e477ba491a3b 49 \return event flag information or error code.
narshu 0:e477ba491a3b 50 */
narshu 0:e477ba491a3b 51 static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever);
narshu 0:e477ba491a3b 52
narshu 0:e477ba491a3b 53
narshu 0:e477ba491a3b 54 /*! Wait for a specified time period in millisec:
narshu 0:e477ba491a3b 55 \param millisec time delay value
narshu 0:e477ba491a3b 56 \return status code that indicates the execution status of the function.
narshu 0:e477ba491a3b 57 */
narshu 0:e477ba491a3b 58 static osStatus wait(uint32_t millisec);
narshu 0:e477ba491a3b 59
narshu 0:e477ba491a3b 60 /*! Pass control to next thread that is in state READY.
narshu 0:e477ba491a3b 61 \return status code that indicates the execution status of the function.
narshu 0:e477ba491a3b 62 */
narshu 0:e477ba491a3b 63 static osStatus yield();
narshu 0:e477ba491a3b 64
narshu 0:e477ba491a3b 65 /*! Get the thread id of the current running thread.
narshu 0:e477ba491a3b 66 \return thread ID for reference by other functions or NULL in case of error.
narshu 0:e477ba491a3b 67 */
narshu 0:e477ba491a3b 68 static osThreadId gettid();
narshu 0:e477ba491a3b 69
narshu 0:e477ba491a3b 70 private:
narshu 0:e477ba491a3b 71 osThreadId _tid;
narshu 0:e477ba491a3b 72 osThreadDef_t _thread_def;
narshu 0:e477ba491a3b 73 };
narshu 0:e477ba491a3b 74
narshu 0:e477ba491a3b 75 }
narshu 0:e477ba491a3b 76 #endif