00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
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