Committer:
donatien
Date:
Thu May 31 15:46:30 2012 +0000
Revision:
0:e6ccf0b3d718

        

Who changed what in which revision?

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