mdot_rtos

Fork of mbed-rtos by mbed official

Committer:
emilmont
Date:
Fri Nov 23 09:57:31 2012 +0000
Revision:
6:350b53afb889
Child:
8:88a1a9c26ae3
Merge RTOS C++ API and RTX under the same library; Update RTX to version 4.60; Add proper Thread destructor;

Who changed what in which revision?

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