00001 // RTAI繧ソ繧ケ繧ッ�シ�螳滓凾髢薙�槭Ν繝√せ繝ャ繝�繝臥函謌舌�サ遐エ譽�繧ッ繝ゥ繧ケ 00002 // 2011/02/14 Yuki YOKOKURA 00003 // 00004 // RTAI繧ソ繧ケ繧ッ縺ィ隍�謨ー蛟九�ョ螳滓凾髢薙せ繝ャ繝�繝峨r逕滓�舌�サ遐エ譽�縺吶k 00005 // 00006 // Copyright (C) 2011 Yuki YOKOKURA 00007 // This program is free software; 00008 // you can redistribute it and/or modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 3 of the License, or any later version. 00010 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00011 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 // See the GNU General Public License for more details <http://www.gnu.org/licenses/>. 00013 // Besides, you can negotiate about other options of licenses instead of GPL. 00014 // If you would like to get other licenses, please contact us<yuki@katsura.sd.keio.ac.jp>. 00015 00016 #ifndef RTAITASK 00017 #define RTAITASK 00018 00019 #include <rtai_lxrt.h> 00020 #include <string.h> 00021 #include "RTAIthread.hh" 00022 00023 00024 typedef void (**FuncPtrs)(void*); // 髢「謨ー繝昴う繝ウ繧ソ驟榊�励く繝」繧ケ繝育畑 00025 00026 namespace ARCS { // ARCS蜷榊燕遨コ髢� 00027 // 蜍穂ス懃憾諷九�ョ螳夂セゥ 00028 enum TaskState { 00029 RTID_TASK_NORMAL, // 豁」蟶ク 00030 RTID_TASK_ERR, // 繧ソ繧ケ繧ッ蜀�繧ィ繝ゥ繝シ讀懷�コ 00031 RTID_THRD_ERR // 繧ケ繝ャ繝�繝牙��繧ィ繝ゥ繝シ讀懷�コ 00032 }; 00033 00034 class RTAItask { 00035 private: 00036 RTAItask(const RTAItask&); // 繧ウ繝斐�シ繧ウ繝ウ繧ケ繝医Λ繧ッ繧ソ菴ソ逕ィ遖∵ュ「 00037 const RTAItask& operator=(const RTAItask&); // 莉」蜈・貍皮ョ怜ュ蝉スソ逕ィ遖∵ュ「 00038 00039 static const unsigned int MAX_THREAD = 128; // 繧ケ繝ャ繝�繝画怙螟ァ謨ー (蜍慕噪霑ス蠕薙�ッ縺ゅ→縺ァ) 00040 static const int STACK_SIZE = 4096; // RTAI繧ケ繝ャ繝�繝峨せ繧ソ繝�繧ッ繧オ繧、繧コ 00041 static const unsigned long THREAD_EXIT_WAIT = 50000;// [us] 繧ケ繝ャ繝�繝臥オゆコ�蜃ヲ逅�蠕�讖滓凾髢� 00042 00043 const unsigned int NumOfThread; // 蜍穂ス懊&縺帙k繧ケ繝ャ繝�繝峨�ョ謨ー 00044 const unsigned long MinPeriodicTime; // [ns] 荳�逡ェ騾溘>繧ケ繝ャ繝�繝峨�ョ蛻カ蠕。蜻ィ譛� 00045 volatile int StateFlag; // 蜍穂ス懃憾諷九ヵ繝ゥ繧ー 00046 RT_TASK *RTtaskID; // 螳滓凾髢薙ち繧ケ繧ッ隴伜挨蟄� 00047 RTAIthread* pRTthread[MAX_THREAD]; // 螳滓凾髢薙せ繝ャ繝�繝� 0 �ス� MAX_THREAD 縺ク縺ョ繝昴う繝ウ繧ソ 00048 00049 public: 00050 // 繧ウ繝ウ繧ケ繝医Λ繧ッ繧ソ 00051 RTAItask( 00052 const unsigned int ThreadNum, // 蜍穂ス懊&縺帙k繧ケ繝ャ繝�繝峨�ョ謨ー 00053 void (** const PeriodicFuncs)(void*), // 蛻カ蠕。逕ィ蜻ィ譛溷ョ溯。碁未謨ー鄒、縺ク縺ョ髢「謨ー繝昴う繝ウ繧ソ 00054 void* const FuncArgs, // 髢「謨ー繝昴う繝ウ繧ソ蠑墓焚 00055 const unsigned long *PeriodicTime // 蛻カ蠕。蜻ィ譛� 00056 ); 00057 ~RTAItask(); // 繝�繧ケ繝医Λ繧ッ繧ソ 00058 void Start(void); // 螳滓凾髢薙せ繝ャ繝�繝峨r髢句ァ九&縺帙k髢「謨ー 00059 void Stop(void); // 螳滓凾髢薙せ繝ャ繝�繝峨r邨ゆコ�縺輔○繧矩未謨ー 00060 void SendState(const int State);// 蜍穂ス懃憾諷九r譖ク縺崎セシ繧� State�シ帶園譛帙�ョ蜍穂ス懃憾諷� 00061 int ReadState(void); // 蜍穂ス懃憾諷九r隱ュ縺ソ蜃コ縺� 謌サ繧雁�、�シ帷樟蝨ィ縺ョ蜍穂ス懃憾諷� 00062 // 髢句ァ九°繧峨�ョ邨碁℃譎る俣縺ィ險育ョ励↓隕√@縺滓カ郁イサ譎る俣繧貞叙蠕励☆繧矩未謨ー 00063 void GetTimeValue(volatile double *Time, volatile long *PeriodicTime, volatile long *ComputationTime); 00064 }; 00065 } 00066 00067 #endif 00068