#if !defined(_L1C8051_H) #define _L1C8051_H #if defined(__BORLANDC__) || defined(__WIN32) #include #endif #include "utils.h" struct deviceHeader_t { unsigned char cmd; unsigned char dummy; unsigned short length; static const unsigned char Data = 0x1; static const unsigned char DataAcknowledge = 0x2; // Deprecated static const unsigned char Status = 0x3; static const unsigned char StatusRequest = 0x4; static const unsigned char FlushRequest = 0x5; // Deprecated static const unsigned char PacketRequest = 0x6; static const unsigned char GenerateLHCbEvent = 0x7; static const unsigned char PIOWriteRequest = 0x8; static const unsigned char PIOReadRequest = 0x9; static const unsigned char GenerateALICEEvent = 0xa; static const unsigned char ResetRequest = 0xb; static const unsigned char ConfigurationData = 0xc; static const unsigned char Int0Enable = 0xd; static const unsigned char Int0Disable = 0xe; static const unsigned char Int0 = 0xf; static const unsigned char GenerateClockBurst = 0x10; static const unsigned char ReadAddress = 0x11; static const unsigned char L1ResetRequest = 0x12; static const unsigned char Idle = 0xa5; static const unsigned char Idle2 = 0x25; }; struct statusData_t { unsigned short generalStatus; // General status unsigned short e100MDI[4]; // E100 registers unsigned short TTCL0Count; unsigned short bufferCount[2]; unsigned short eventCount[2]; unsigned char parityErrorCount[4]; unsigned short txd[2]; unsigned short TTCIdSense; unsigned short egressCount; unsigned short channelStatus[12]; unsigned char TTCControlRegisterId; unsigned char TTCControlRegister; unsigned char TTCBunchCounterRegister; unsigned char TTCBunchCounterRegisterId; unsigned char TTCEventCounterLowRegister; unsigned char TTCEventCounterLowRegisterId; unsigned char TTCEventCounterHighRegister; unsigned char TTCEventCounterHighRegisterId; }; struct configData_t { unsigned char Id; // Register ID unsigned char dummy; unsigned short Data; // Register value }; struct devicePacket_t { unsigned char cmd; unsigned char dummy; unsigned short length; union { unsigned char uc[64]; unsigned short us[32]; unsigned ui[16]; statusData_t status; configData_t config; }; }; typedef void * L1C8051ID; const SI_STATUS SI_WRITE_UNDERRUN = 0xa; // C-callable interface int L1C8051Open( L1C8051ID *, char *, unsigned ); int L1C8051Close( L1C8051ID ); void L1C8051ShowErrorTrace( L1C8051ID ); int L1C8051Dispatch( L1C8051ID, devicePacket_t &, unsigned ); int L1C8051Receive( L1C8051ID, devicePacket_t &, unsigned ); int L1C8051DispatchTriggerBurstRequest( L1C8051ID, unsigned, unsigned ); int L1C8051DispatchConfiguration( L1C8051ID, unsigned, unsigned ); void L1C8051ShowLastStatus( L1C8051ID, devicePacket_t & ); void L1C8051ShowLastData( L1C8051ID, devicePacket_t & ); unsigned L1C8051FlushBuffer( L1C8051ID, unsigned, bool ); class l1c8051 { protected: HANDLE deviceHandle; tracestream errors; tracestream trace; public: l1c8051( const char *, unsigned ); ~l1c8051(); operator void*(){ return errors.tellp() > 0 ? 0 : this; } bool operator !(){ return errors.tellp() <= 0 ? false : true; } void showErrorTrace(); void showInfoTrace(); // Low level message read/write functions void dispatch( devicePacket_t &, unsigned ); void receive( devicePacket_t &, unsigned ); // Higher level/compound messages void dispatchTriggerBurstRequest( unsigned, unsigned ); unsigned flushBuffer( unsigned, bool ); // Utility functions void showLastStatus( devicePacket_t & ); void showLastData( devicePacket_t & ); }; #endif