メインページ   モジュール   名前空間一覧   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

TSoftwareInterruptRegisterModule.cc

解説を見る。
00001 // =====================================================================
00002 //  $Id: TSoftwareInterruptRegisterModule.cc,v 1.4 2004/03/07 10:30:31 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TSoftwareInterruptRegisterModule.cc,v $
00005 //  Revision 1.4  2004/03/07 10:30:31  goiwai
00006 //  ROOTに組みこむためのおまじないマクロを埋めこみました。
00007 //  全てにおいて完全に動作するわけではありません。
00008 //
00009 //  Revision 1.3  2003/10/06 17:02:40  goiwai
00010 //  *** empty log message ***
00011 //
00012 //  Revision 1.2  2003/07/30 16:19:11  goiwai
00013 //  ファイルにコミットログをつけることにしました.
00014 //
00015 // =====================================================================
00016 #include "TSoftwareInterruptRegisterModule.hh"
00017 #include "TDataSegment.hh"
00018 #include "TDataElement.hh"
00019 #include "TRandomFlat.hh"
00020 #include "TRandomEngine.hh"
00021 
00022 static TRandomEngine _engine = TRandomEngine( ( (Tlong)time( 0 ) ) );
00023 static TRandomFlat _register( _engine );
00024 static TRandomFlat _nanosec( _engine );
00025 static const Tint initmask = 0x00ff;
00026 static const Tint initscale = 0x00ff;
00027 
00028 TSoftwareInterruptRegisterModule::TSoftwareInterruptRegisterModule( Tint nch, Tint frequency )
00029   : TSoftwareModule( nch ), 
00030     theInterruptRegister( 0 ), theInterruptMaskRegister( initmask ), 
00031     theFrequency( frequency )
00032 {;}
00033 
00034 TSoftwareInterruptRegisterModule::TSoftwareInterruptRegisterModule( const TSoftwareInterruptRegisterModule& right )
00035   : TSoftwareModule( right ),
00036     theInterruptRegister( 0 ),
00037     theInterruptMaskRegister( right.theInterruptMaskRegister ),
00038     theFrequency( right.theFrequency )
00039 {;}
00040 
00041 TSoftwareInterruptRegisterModule::~TSoftwareInterruptRegisterModule()
00042 {;}
00043 
00044 const TSoftwareInterruptRegisterModule& TSoftwareInterruptRegisterModule::operator=( const TSoftwareInterruptRegisterModule& right )
00045 {
00046   *( (TSoftwareModule*)this ) = *( (TSoftwareModule*)(&right) );
00047   theInterruptMaskRegister = 0;
00048   theInterruptMaskRegister = right.theInterruptMaskRegister;
00049   theFrequency = right.theFrequency;
00050   return *this;
00051 }
00052 
00053 Tbool TSoftwareInterruptRegisterModule::operator==( const TSoftwareInterruptRegisterModule& right ) const
00054 {
00055   Tbool retval = Ttrue;
00056   retval &= ( *( (TSoftwareModule*)this ) == *( (TSoftwareModule*)(&right) ) );
00057   retval &= ( theInterruptMaskRegister == right.theInterruptMaskRegister );
00058   retval &= ( theFrequency == right.theFrequency );
00059   return retval;
00060 }
00061 
00062 Tbool TSoftwareInterruptRegisterModule::operator!=( const TSoftwareInterruptRegisterModule& right ) const
00063 {
00064   Tbool retval = Tfalse;
00065   retval |= ( *( (TSoftwareModule*)this ) != *( (TSoftwareModule*)(&right) ) );
00066   retval |= ( theInterruptMaskRegister != right.theInterruptMaskRegister );
00067   retval |= ( theFrequency != right.theFrequency );
00068   return retval;
00069 }
00070 
00071 Tvoid TSoftwareInterruptRegisterModule::FillData( TDataElement& element, Tint channel )
00072 {
00073   if ( channel < 0 || channel >= theNumberOfChannels ) {
00074     Tcerr << "TSoftwareInterruptRegisterModule::FillData: invalid ID " << channel << Tendl;
00075     theStatus = -EFAULT;
00076     element.FillData( &theStatus, tTypeInt, 1 );
00077   } else if ( channel == 0 ) {
00078     element.FillData( &theInterruptRegister, tTypeInt, 1 );
00079   } else if ( channel == 1 ) {
00080     element.FillData( &theInterruptMaskRegister, tTypeInt, 1 );
00081   } else {
00082     // status filled
00083     theStatus = -EFAULT;
00084     ( (TDataElement*)(&element) ) -> FillData( &theStatus, tTypeInt, 1 );
00085   }
00086   return;
00087 }
00088 
00089 Tint TSoftwareInterruptRegisterModule::Clear()
00090 {
00091   theInterruptRegister = 0;
00092   return theStatus = tStatusSuccess;
00093 }
00094 
00095 Tint TSoftwareInterruptRegisterModule::Update()
00096 {
00097   theInterruptRegister = _register.fireInt( initscale );
00098   theInterruptRegister &= ~theInterruptMaskRegister;
00099   return theStatus = tStatusSuccess;
00100 }
00101 
00102 Tint TSoftwareInterruptRegisterModule::Initialize()
00103 {
00104   theInterruptRegister = 0;
00105   theInterruptMaskRegister = initmask;
00106   theFrequency = 1;
00107   return theStatus = tStatusSuccess;
00108 }
00109 
00110 Tint TSoftwareInterruptRegisterModule::ReadInterruptRegister()
00111 {
00112   static struct timespec req;
00113   req.tv_sec = 0;
00114   req.tv_nsec = _nanosec.fireInt( 1000000000 / theFrequency );
00115   nanosleep( &req, 0 );
00116   Update();
00117   return theInterruptRegister;
00118 }
00119 
00120 #ifdef __CLDAQ_ROOT_DLL
00121     ClassImp(TSoftwareInterruptRegisterModule)
00122 #endif


CLDAQ - a Class Library for DataAcQuisition (Version 1.14.3)
Go IWAI -- goiwai at users.sourceforge.jp