PeriodicThread.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef ORO_PERIODIC_THREAD_HPP
00039 #define ORO_PERIODIC_THREAD_HPP
00040
00041
00042 #include "../rtt-config.h"
00043 #include "fosi.h"
00044
00045 #include "RunnableInterface.hpp"
00046 #include "ThreadInterface.hpp"
00047
00048 #include <string>
00049
00050 namespace RTT
00051 {
00052 class DigitalOutInterface;
00053
00054 namespace OS {
00065 class PeriodicThread
00066 : public OS::ThreadInterface
00067 {
00068 friend void* periodicThread( void* t );
00069
00070 public:
00071
00081 PeriodicThread(int priority,const std::string & name, double period, OS::RunnableInterface* r=0);
00082
00093 PeriodicThread(int scheduler, int priority,const std::string & name, double period, OS::RunnableInterface* r=0);
00094
00095 virtual ~PeriodicThread();
00096
00097 virtual bool run( OS::RunnableInterface* r);
00098
00102 virtual bool start();
00106 virtual bool stop();
00111 bool setPeriod( Seconds s );
00116 bool setPeriod( secs s, nsecs ns );
00121 void getPeriod( secs& s, nsecs& ns ) const;
00122
00126 virtual Seconds getPeriod() const;
00127
00131 virtual nsecs getPeriodNS() const;
00132
00136 virtual bool isRunning() const;
00137
00141 virtual const char* getName() const;
00142
00147 virtual RTOS_TASK * getTask(){return &rtos_task;};
00148
00149 virtual bool setScheduler(int sched_type);
00150 virtual int getScheduler() const;
00151
00155 bool setPeriod( TIME_SPEC p );
00156
00157 virtual bool setPriority(int priority);
00158
00159 virtual int getPriority() const;
00160
00161 virtual void yield();
00162
00163 void setMaxOverrun( int m );
00164 int getMaxOverrun() const;
00170 void terminate();
00171
00172 void emergencyStop();
00173 protected:
00174
00175 virtual void continuousStepping(bool yes_no);
00182 virtual bool setToStop();
00183
00184 virtual void step();
00185
00186 virtual bool initialize();
00187
00188 virtual void finalize();
00189 private:
00190
00191 void setup(int _priority, const std::string& name);
00192
00196 void configure();
00197
00204 RTOS_TASK rtos_task;
00205
00209 int msched_type;
00210
00215 bool running;
00216
00217 bool prepareForExit;
00218
00219 bool wait_for_step;
00220
00221 rt_sem_t sem;
00222 rt_sem_t confDone;
00226 OS::RunnableInterface* runComp;
00227
00228 int maxOverRun;
00229
00230
00231 NANO_TIME period;
00232
00233 #ifdef OROPKG_OS_THREAD_SCOPE
00234
00235 DigitalOutInterface * d;
00236 #endif
00237 };
00238
00239 }}
00240
00241 #endif