IC Eurobot 2012 Program published from Shuto's account

Dependents:   Eurobot2012_Primary

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Thread.h Source File

Thread.h

00001 /* Copyright (c) 2012 mbed.org */
00002 #ifndef THREAD_H
00003 #define THREAD_H 
00004 
00005 #include <stdint.h>
00006 #include "cmsis_os.h"
00007 
00008 namespace rtos {
00009 
00010 /*! The Thread class allow defining, creating, and controlling thread functions in the system. */
00011 class Thread  {
00012 public:
00013     /*! Create a new thread, and start it executing the specified function.
00014       \param   task      function to be executed by this thread.
00015       \param   argument  pointer that is passed to the thread function as start argument. (default: NULL).
00016       \param   priority  initial priority of the thread function. (default: osPriorityNormal).
00017       \param   stacksz   stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
00018     */
00019     Thread (void (*task)(void const *argument),
00020            void *argument=NULL,
00021            osPriority priority=osPriorityNormal,
00022            uint32_t stacksize=DEFAULT_STACK_SIZE);
00023     
00024     /*! Terminate execution of a thread and remove it from Active Threads
00025       \return  status code that indicates the execution status of the function.
00026     */
00027     osStatus terminate ();
00028     
00029     /*! Set priority of an active thread
00030       \param   priority  new priority value for the thread function.
00031       \return  status code that indicates the execution status of the function.
00032     */
00033     osStatus set_priority (osPriority priority);
00034     
00035     /*! Get priority of an active thread
00036       \ return  current priority value of the thread function.
00037     */
00038     osPriority get_priority ();
00039     
00040     /*! Set the specified Signal Flags of an active thread.
00041       \param   signals  specifies the signal flags of the thread that should be set.
00042       \return  previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
00043     */
00044     int32_t signal_set (int32_t signals);
00045     
00046     /*! Wait for one or more Signal Flags to become signaled for the current RUNNING thread. 
00047       \param   signals   wait until all specified signal flags set or 0 for any single signal flag.
00048       \param   millisec  timeout value or 0 in case of no time-out. (default: osWaitForever).
00049       \return  event flag information or error code.
00050     */
00051     static osEvent signal_wait (int32_t signals, uint32_t millisec=osWaitForever);
00052     
00053     
00054     /*! Wait for a specified time period in millisec:
00055       \param   millisec  time delay value
00056       \return  status code that indicates the execution status of the function. 
00057     */
00058     static osStatus wait (uint32_t millisec);
00059     
00060     /*! Pass control to next thread that is in state READY.
00061       \return  status code that indicates the execution status of the function.
00062     */
00063     static osStatus yield ();
00064     
00065     /*! Get the thread id of the current running thread.
00066       \return  thread ID for reference by other functions or NULL in case of error.
00067     */
00068     static osThreadId gettid ();
00069 
00070 private:
00071     osThreadId _tid;
00072     osThreadDef_t _thread_def;
00073 };
00074 
00075 }
00076 #endif