00001 // RTAI螳滓凾髢薙せ繝ャ繝�繝臥函謌舌�サ遐エ譽�繧ッ繝ゥ繧ケ 00002 // 2011/02/14 Yuki YOKOKURA 00003 // 00004 // RTAI螳滓凾髢薙せ繝ャ繝�繝峨r逕滓�舌�サ遐エ譽�縺吶k 00005 // 螳滄圀縺ォ險域クャ縺輔l縺溷宛蠕。蜻ィ譛溘d險育ョ玲カ郁イサ譎る俣繧よ署萓帙☆繧� 00006 // 00007 // Copyright (C) 2011 Yuki YOKOKURA 00008 // This program is free software; 00009 // you can redistribute it and/or modify it under the terms of the GNU General Public License 00010 // as published by the Free Software Foundation; either version 3 of the License, or any later version. 00011 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00012 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00013 // See the GNU General Public License for more details <http://www.gnu.org/licenses/>. 00014 // Besides, you can negotiate about other options of licenses instead of GPL. 00015 // If you would like to get other licenses, please contact us<yuki@katsura.sd.keio.ac.jp>. 00016 00017 #ifndef RTAITHREADING 00018 #define RTAITHREADING 00019 00020 #include <stdio.h> 00021 #include <rtai_lxrt.h> 00022 #include <sys/io.h> 00023 00024 00025 namespace ARCS { // ARCS蜷榊燕遨コ髢� 00026 // 蜍穂ス懃憾諷九�ョ螳夂セゥ 00027 enum ThreadState { 00028 RTID_ERROR, // 繧ィ繝ゥ繝シ讀懷�コ 00029 RTID_STOP, // 蛛懈ュ「迥カ諷� 00030 RTID_RUN, // 蜍穂ス應クュ 00031 RTID_EXCMPL // 邨ゆコ�蜍穂ス懷ョ御コ� 00032 }; 00033 00034 class RTAIthread { 00035 // RTAI螳滓凾髢薙せ繝ャ繝�繝臥函謌舌け繝ゥ繧ケ 00036 private: 00037 RTAIthread(const RTAIthread&); // 繧ウ繝斐�シ繧ウ繝ウ繧ケ繝医Λ繧ッ繧ソ菴ソ逕ィ遖∵ュ「 00038 const RTAIthread& operator=(const RTAIthread&); // 莉」蜈・貍皮ョ怜ュ蝉スソ逕ィ遖∵ュ「 00039 static const int STACK_SIZE = 4096; // 繧ケ繝ャ繝�繝峨せ繧ソ繝�繧ッ繧オ繧、繧コ 00040 volatile int StateFlag; // 蜍穂ス懃憾諷九ヵ繝ゥ繧ー 00041 const char *TaskName; // 螳滓凾髢薙せ繝ャ繝�繝牙錐(6譁�蟄励∪縺ァ) 00042 const unsigned long Ts; // 蛻カ蠕。蜻ィ譛� 00043 const int Priority; // 螳滓凾髢薙せ繝ャ繝�繝牙━蜈磯��菴� 00044 void (* const pRTfunc)(void*); // 蛻カ蠕。逕ィ螳溯。碁未謨ー縺ク縺ョ繝昴う繝ウ繧ソ 00045 void* const pArg; // 髢「謨ー繝昴う繝ウ繧ソ縺ョ蠑墓焚 00046 long RealTimeThread_ID; // 螳滓凾髢薙せ繝ャ繝�繝芽ュ伜挨蟄� 00047 unsigned long NowTime; // 譎ょ綾 ( 遞シ蜒阪〒縺阪k譎る俣 = Ts*2^(sizeof(unsigned long)*8) = 100e-6*2^32 = 邏�119譎る俣(萓�) ) 遞シ蜒肴凾髢薙r莨ク縺ー縺励◆縺代l縺ー縲蛍nsigned long long縲阪↓縺吶k 00048 long PeriodicTime; // 險域クャ縺輔l縺溷ョ滄圀縺ョ蜻ィ譛滓凾髢� 00049 long ComputationTime; // 險育ョ励↓繧医▲縺ヲ豸郁イサ縺輔l縺滓凾髢� (縺、縺セ繧� ComputationTime < PeriodicTime 縺ァ縺ェ縺代l縺ー縺ェ繧峨↑縺�) 00050 static void RealTimeThread(RTAIthread *pParam); // 螳滓凾髢薙せ繝ャ繝�繝� 00051 00052 public: 00053 // 繧ウ繝ウ繧ケ繝医Λ繧ッ繧ソ Name�シ帙せ繝ャ繝�繝牙錐�シ卦ime�シ帛宛蠕。蜻ィ譛滂シ訓rio�シ帛━蜈磯��菴搾シ軍Tfunc�シ帛宛蠕。逕ィ螳溯。碁未謨ー(髢「謨ー繝昴う繝ウ繧ソ) 00054 RTAIthread(const char *Name, const unsigned long Time, const int Prio, void (* const RTfunc)(void*), void* const Arg); 00055 ~RTAIthread(); // 繝�繧ケ繝医Λ繧ッ繧ソ 00056 void SendState(const int State); // 蜍穂ス懃憾諷九r譖ク縺崎セシ繧� State�シ帶園譛帙�ョ蜍穂ス懃憾諷� 00057 int ReadState(void); // 蜍穂ス懃憾諷九r隱ュ縺ソ蜃コ縺� 謌サ繧雁�、�シ帷樟蝨ィ縺ョ蜍穂ス懃憾諷� 00058 unsigned long GetTime(void);// 譎ょ綾繧貞叙蠕励☆繧矩未謨ー 00059 long GetSmplTime(void); // 險域クャ縺輔l縺溷ョ滄圀縺ョ繧オ繝ウ繝励Μ繝ウ繧ー譎る俣繧貞叙蠕励☆繧矩未謨ー 00060 long GetCompTime(void); // 險域クャ縺輔l縺滓カ郁イサ譎る俣繧貞叙蠕励☆繧矩未謨ー 00061 }; 00062 } 00063 00064 #endif 00065