create Reg class and implement the chaneg to ClassDigitizer.h/cpp, clean up ClassDigitizer.h/cpp

This commit is contained in:
carina@hades 2022-10-13 18:06:07 -04:00
parent 31a39defe7
commit 12d54d2e3b
4 changed files with 218 additions and 557 deletions

View File

@ -193,7 +193,7 @@ int Digitizer::OpenDigitizer(int boardID, int portID, bool program, bool verbose
ProgramBoard(); ProgramBoard();
} }
if( isConnected ) FillAllSettings(); if( isConnected ) ReadAllSettingsFromBoard();
return ret; return ret;
} }
@ -357,91 +357,32 @@ void Digitizer::ReadData(){
} }
//=========================================================== //===========================================================
void Digitizer::WriteRegister(uint32_t registerAddress, uint32_t value, int ch ){ void Digitizer::WriteRegister(Reg registerAddress, uint32_t value, int ch, bool isSave2MemAndFile){
if( !isConnected ) return; if( !isConnected ) return;
//printf("0x%X, ch:%02d, 0x%X=%u\n", registerAddress, ch, value, value); //printf("0x%X, ch:%02d, 0x%X=%u\n", registerAddress, ch, value, value);
if( registerAddress == 0x8180){ ret = CAEN_DGTZ_WriteRegister(handle, registerAddress.ActualAddress(ch), value);
if( ch < 0 ){ if( ret == 0 && isSave2MemAndFile) {
for( int i = 0; i < NChannel/2; i++){
ret = CAEN_DGTZ_WriteRegister(handle, registerAddress + 4*i, value);
if( ret == 0 ) {
SetSettingToMemory(registerAddress, value, i);
SaveSettingToFile(registerAddress, value, i);
}
///ReadRegister(registerAddress, i);
}
}else{
ret = CAEN_DGTZ_WriteRegister(handle, registerAddress + 4*(ch/2), value);
if( ret == 0 ) {
SetSettingToMemory(registerAddress, value, ch); SetSettingToMemory(registerAddress, value, ch);
SaveSettingToFile(registerAddress, value, ch); SaveSettingToFile(registerAddress, value, ch);
} }
///ReadRegister(registerAddress, ch);
}
}else if( registerAddress < 0x8000){
if( ch < 0 ) {
ret = CAEN_DGTZ_WriteRegister(handle, registerAddress + 0x7000, value);
if( ret == 0 ){
for( int i = 0; i < NChannel; i++) {
SetSettingToMemory(registerAddress, value, i);
SaveSettingToFile(registerAddress, value, i);
}
///for( int i = 0; i < NChannel; i++) ReadRegister(registerAddress, i);
}
}else{
ret = CAEN_DGTZ_WriteRegister(handle, registerAddress + (ch<<8), value);
if( ret == 0 ) {
SetSettingToMemory(registerAddress, value, ch);
SaveSettingToFile(registerAddress, value, ch);
}
///ReadRegister(registerAddress, ch);
}
}else{
ret = CAEN_DGTZ_WriteRegister(handle, registerAddress, value);
if( ret == 0 ) {
SetSettingToMemory(registerAddress, value);
SaveSettingToFile(registerAddress, value);
}
//ReadRegister(registerAddress);
}
/// for grouped address
if( registerAddress == Register::DPP::RecordLength_G ||
registerAddress == Register::DPP::NumberEventsPerAggregate_G ||
registerAddress == Register::DPP::PHA::DPPAlgorithmControl2_G ||
registerAddress == Register::DPP::PSD::DPPAlgorithmControl2_G ||
registerAddress == Register::DPP::TriggerValidationMask_G
){
//ReadRegister(registerAddress, ch + (ch%2 == 1 ? -1 : +1));
if( ret == 0 ) {
SetSettingToMemory(registerAddress, value, ch);
SaveSettingToFile(registerAddress, value, ch);
}
}
ErrorMsg("WriteRegister:" + std::to_string(registerAddress)); ErrorMsg("WriteRegister:" + std::to_string(registerAddress));
} }
uint32_t Digitizer::ReadRegister(uint32_t registerAddress, int ch, string str ){ uint32_t Digitizer::ReadRegister(Reg registerAddress, unsigned short ch, bool isSave2MemAndFile, string str ){
if( !isConnected ) return 0; if( !isConnected ) return 0;
uint32_t actualAddress = registerAddress ;
if( registerAddress == 0x8180 ){
if( ch < 0 ) ch = 0;
actualAddress = registerAddress + 4*(ch/2);
}
if( registerAddress < 0x8000) {
if( ch >= 0 ) actualAddress = registerAddress + (ch << 8);
}
uint32_t data[1]; uint32_t data[1];
ret = CAEN_DGTZ_ReadRegister(handle, actualAddress, data); ret = CAEN_DGTZ_ReadRegister(handle, registerAddress.ActualAddress(ch), data);
if( ret == 0 ) SaveSettingToFile(registerAddress, data[0], ch); if( ret == 0 && isSave2MemAndFile) {
SetSettingToMemory(registerAddress, data[0], ch);
SaveSettingToFile(registerAddress, data[0], ch);
}
ErrorMsg("ReadRegister:" + std::to_string(registerAddress)); ErrorMsg("ReadRegister:" + std::to_string(registerAddress));
if( str != "" ) printf("%s : 0x%04X(0x%04X) is 0x%08X \n", str.c_str(), actualAddress, registerAddress, data[0]); if( str != "" ) printf("%s : 0x%04X(0x%04X) is 0x%08X \n", str.c_str(),
registerAddress.ActualAddress(ch), registerAddress.GetAddress(), data[0]);
return data[0]; return data[0];
} }
@ -526,49 +467,11 @@ void Digitizer::SetTriggerPolarity(bool RiseingIsZero, int ch ){
//============================== DPP-Alpgorthm Control //============================== DPP-Alpgorthm Control
void Digitizer::SetDPPAlgorithmControl(uint32_t bit, int ch){ void Digitizer::SetDPPAlgorithmControl(uint32_t bit, int ch){
///============= DPP algorithm control is 32 bit
/// [ 0: 5] Trapazoid Rescaling. the trapazoid ADC is 48 bit. it need to bit-shift before the 0x3FFF (14 bit filter)
/// [ 8: 9] Decimation. 00 = disable, 01 = 2 samples, 10 = 4 samples, 11 = 8 sample
/// [10:11] Decimation Gain. This gain apply to the Trapazoid Rescaling and fine gain
/// [12:13] Peak Mean. sample for averaging the trapezoid height calculation. 00 = 1 sample, 01 = 4 samples, 10 = 16 sample, 11 = 64 sample
/// [16] pulse polarity. 0 = positve, 1 = negative
/// [18:19] Trigger mode. 00 = normal, 01 = coincident, 10 = reserved. 11 = anti coincident
/// [20:22] number of samples for the baseline average calculation. 000 = baseline disable (energy not subtraced with baseline)
/// 001 = 16 samples
/// 010 = 64 samples
/// 011 = 256 samples
/// 100 = 1024 samples
/// 101 = 4096 samples
/// 110 = 16384 samples
/// 111 = resertved.
/// [24] Disable self trigger. 0 = selftrigger used to acquire and propagated to the trigger logic;
/// 1 = selftrigger only propagated to the trigger logic.
/// [26] Enable Roll-Over flag. see manual 0 = disable, 1 = enable
/// [27] Enable pile-up flag.
///============= PHA - DPP algorithm control 2 is 32 bit
/// [ 0: 1] Local Shaped Trigger mode. see manual
/// [ 2] Enable Local Shaped Trigger
/// [ 4: 5] Local Trigger Validation mode, see manual
/// [ 6] Enable Local Trigger Validation
/// [ 8:10] Extra 2 word option. 000 = [0:15] baseline *4 [16:31] extended time stamp
/// 001 = reserved
/// 010 = [0:15] fine time stamp [16:31] extended time stamp
/// 011 = reserved
/// 100 = [0:15] total tigger counter [16:31] Lost trigger counter
/// 101 = [0:15] event after the zero crosiing [16:31] event before zero crossing
/// 110, 111 = reserved.
/// [14:15] source of veto. 00 = disable, 01 veto is common to all channels, 10 = veto for coupled channels, 11 = veto comes from negative saturation
/// [16:17] Select the step for the trigger counter rate flag. see manual
/// [18] baseline calculation is active also when the acquisition is not running. 0 = disbale, 1 = enable
/// [19] Tag correlated events. see manual 0 = disbale, 1 = enable
/// [29] Enable the optimization of the Baseline Restorer to avoid tails in the energy peaks. 0 = disbale, 1 = enable
WriteRegister( Register::DPP::DPPAlgorithmControl, bit, ch); WriteRegister( Register::DPP::DPPAlgorithmControl, bit, ch);
if( ret != 0 ) ErrorMsg(__func__); if( ret != 0 ) ErrorMsg(__func__);
} }
unsigned int Digitizer::ReadBits(uint32_t address, unsigned int bitLength, unsigned int bitSmallestPos, int ch ){ unsigned int Digitizer::ReadBits(Reg address, unsigned int bitLength, unsigned int bitSmallestPos, int ch ){
int tempCh = ch; int tempCh = ch;
if (ch < 0 && address < 0x8000 ) tempCh = 0; /// take ch-0 if (ch < 0 && address < 0x8000 ) tempCh = 0; /// take ch-0
uint32_t bit = ReadRegister(address, tempCh); uint32_t bit = ReadRegister(address, tempCh);
@ -576,7 +479,7 @@ unsigned int Digitizer::ReadBits(uint32_t address, unsigned int bitLength, unsig
return bit; return bit;
} }
void Digitizer::SetBits(uint32_t address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch){ void Digitizer::SetBits(Reg address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch){
///printf("address : 0x%X, value : 0x%X, len : %d, pos : %d, ch : %d \n", address, bitValue, bitLength, bitSmallestPos, ch); ///printf("address : 0x%X, value : 0x%X, len : %d, pos : %d, ch : %d \n", address, bitValue, bitLength, bitSmallestPos, ch);
uint32_t bit ; uint32_t bit ;
uint32_t bitmask = (uint(pow(2, bitLength)-1) << bitSmallestPos); uint32_t bitmask = (uint(pow(2, bitLength)-1) << bitSmallestPos);
@ -690,210 +593,95 @@ int Digitizer::ProgramPHABoard(){
printf("End of program board and channels\n"); printf("End of program board and channels\n");
isSettingFilledinMemeory = false; isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard();
FillAllSettings(); ReadAllSettingsFromBoard();
return ret; return ret;
} }
//========================================== setting file IO //========================================== setting file IO
unsigned short Digitizer::CalSettingIndex(uint32_t registerAddress, int ch){ void Digitizer::ReadAllSettingsFromBoard(){
if( !isConnected ) return;
if( isSettingFilledinMemeory ) return;
unsigned short index; /// board setting
uint32_t newAddress; for( int p = 0; p < (int) RegisterDPPList[p]; p++){
if( RegisterDPPList[p].GetType() == RW::WriteONLY) continue;
if( registerAddress == 0x8180){ ReadRegister(RegisterDPPList[p]);
///if( ch%2 ==1 ) return 0xFFFF; }
newAddress = registerAddress + 4*(ch/2); /// Channels Setting
index = (newAddress & 0x0FFF) / 4; for( int ch = 0; ch < NChannel; ch ++){
}else if( registerAddress < 0x8000){ if( DPPType == V1730_DPP_PHA_CODE ){
if( ch < 0 ) ch = 0; for( int p = 0; p < (int) RegisterPHAList[p]; p++){
newAddress = registerAddress + (ch << 8); if( RegisterPHAList[p].GetType() == RW::WriteONLY) continue;
index = newAddress / 4; ReadRegister(RegisterPHAList[p], ch);
}else{
newAddress = registerAddress;
if(registerAddress < 0xF000) {
index = (newAddress & 0x0FFF) / 4;
}else{
index = ((newAddress & 0x0FFF) + 0x0200 ) / 4;
} }
} }
//printf("---------address : 0x%04X = %5d = index : %6.1f (%d)\n", newAddress, newAddress, (newAddress & 0x0FFF) / 4., index); if( DPPType == V1730_DPP_PSD_CODE ){
return index; for( int p = 0; p < (int) RegisterPSDList[p]; p++){
if( RegisterPSDList[p].GetType() == RW::WriteONLY) continue;
ReadRegister(RegisterPSDList[p], ch);
}
}
}
isSettingFilledinMemeory = true;
} }
void Digitizer::FillSetting(uint32_t registerAddress, int ch){ void Digitizer::SetSettingFromMemory(Reg registerAddress, int ch){
WriteRegister(registerAddress, GetSettingFromMemory(registerAddress, ch), ch, false);
unsigned short index = CalSettingIndex(registerAddress, ch);
if( index > SETTINGSIZE ) return;
//if( setting[index] != 0 ) printf("##############################\n");
setting[index] = ReadRegister(registerAddress, ch);
} }
void Digitizer::SetSettingToMemory(uint32_t registerAddress, unsigned int value, int ch ){ void Digitizer::ProgramSettingsToBoard(){
unsigned short index = CalSettingIndex(registerAddress, ch); if( !isConnected ) return;
/// board setting
for( int p = 0; p < (int) RegisterDPPList[p]; p++){
if( RegisterDPPList[p].GetType() == RW::ReadONLY) continue;
ReadRegister(RegisterDPPList[p]);
}
/// Channels Setting
for( int ch = 0; ch < NChannel; ch ++){
if( DPPType == V1730_DPP_PHA_CODE ){
for( int p = 0; p < (int) RegisterPHAList[p]; p++){
if( RegisterPHAList[p].GetType() == RW::ReadONLY) continue;
ReadRegister(RegisterPHAList[p], ch);
}
}
if( DPPType == V1730_DPP_PSD_CODE ){
for( int p = 0; p < (int) RegisterPSDList[p]; p++){
if( RegisterPSDList[p].GetType() == RW::ReadONLY) continue;
ReadRegister(RegisterPSDList[p], ch);
}
}
}
}
void Digitizer::SetSettingToMemory(Reg registerAddress, unsigned int value, int ch ){
unsigned short index = registerAddress.Index(ch);
if( index > SETTINGSIZE ) return; if( index > SETTINGSIZE ) return;
setting[index] = value; setting[index] = value;
} }
unsigned int Digitizer::GetSettingFromMemory(uint32_t registerAddress, int ch ){ unsigned int Digitizer::GetSettingFromMemory(Reg registerAddress, int ch ){
unsigned short index = CalSettingIndex(registerAddress, ch); unsigned short index = registerAddress.Index(ch);
if( index > SETTINGSIZE ) return 0xFFFF; if( index > SETTINGSIZE ) return 0xFFFF;
return setting[index] ; return setting[index] ;
} }
void Digitizer::SetSettingFromMemory(uint32_t registerAddress, int ch){
WriteRegister(registerAddress, GetSettingFromMemory(registerAddress, ch), ch);
}
void Digitizer::FillAllSettings(){
/// for 1 digitizer, 16 channels, needs 0x10XX to 0x1FXX
/// -------------------------------------
/// for 1 channel is 0x2000 = 8192 byte should be enough for all setting for 1 board
if( isSettingFilledinMemeory) return;
for( int ch = 0; ch < NChannel; ch ++){
FillSetting(Register::DPP::RecordLength_G , ch); /// 0x1020; /// R/W
FillSetting(Register::DPP::InputDynamicRange , ch); /// 0x1028; /// R/W
FillSetting(Register::DPP::NumberEventsPerAggregate_G , ch); /// 0x1034; /// R/W
FillSetting(Register::DPP::PreTrigger , ch); /// 0x1038; /// R/W
FillSetting(Register::DPP::DPPAlgorithmControl , ch); /// 0x1080; /// R/W
FillSetting(Register::DPP::ChannelStatus_R , ch); /// 0x1088; /// R
FillSetting(Register::DPP::AMCFirmwareRevision_R , ch); /// 0x108C; /// R
FillSetting(Register::DPP::ChannelDCOffset , ch); /// 0x1098; /// R/W
FillSetting(Register::DPP::ChannelADCTemperature_R , ch); /// 0x10A8; /// R
FillSetting(Register::DPP::VetoWidth , ch); /// 0x10D4; /// R/W
FillSetting(Register::DPP::TriggerValidationMask_G , ch); /// 0x8180; /// R/W, 0x8180 + 4n
if( DPPType == V1730_DPP_PHA_CODE ){
FillSetting(Register::DPP::PHA::ChannelStopAcquisition , ch); /// 0x1040; /// R/W not sure
FillSetting(Register::DPP::PHA::RCCR2SmoothingFactor , ch); /// 0x1054; /// R/W Trigger Filter smoothing, triggerSmoothingFactor
FillSetting(Register::DPP::PHA::InputRiseTime , ch); /// 0x1058; /// R/W OK
FillSetting(Register::DPP::PHA::TrapezoidRiseTime , ch); /// 0x105C; /// R/W OK
FillSetting(Register::DPP::PHA::TrapezoidFlatTop , ch); /// 0x1060; /// R/W OK
FillSetting(Register::DPP::PHA::PeakingTime , ch); /// 0x1064; /// R/W OK
FillSetting(Register::DPP::PHA::DecayTime , ch); /// 0x1068; /// R/W OK
FillSetting(Register::DPP::PHA::TriggerThreshold , ch); /// 0x106C; /// R/W OK
FillSetting(Register::DPP::PHA::RiseTimeValidationWindow, ch); /// 0x1070; /// R/W OK
FillSetting(Register::DPP::PHA::TriggerHoldOffWidth , ch); /// 0x1074; /// R/W OK
FillSetting(Register::DPP::PHA::PeakHoldOff , ch); /// 0x1078; /// R/W OK
FillSetting(Register::DPP::PHA::ShapedTriggerWidth , ch); /// 0x1084; /// R/W not sure
FillSetting(Register::DPP::PHA::DPPAlgorithmControl2_G , ch); /// 0x10A0; /// R/W OK
FillSetting(Register::DPP::PHA::FineGain , ch); /// 0x10C4; /// R/W OK
}
if( DPPType == V1730_DPP_PSD_CODE ){
FillSetting(Register::DPP::PSD::CFDSetting , ch); /// 0x103C; /// R/W
FillSetting(Register::DPP::PSD::ChargeZeroSuppressionThreshold, ch); /// 0x1044; /// R/W
FillSetting(Register::DPP::PSD::ShortGateWidth , ch); /// 0x1054; /// R/W
FillSetting(Register::DPP::PSD::LongGateWidth , ch); /// 0x1058; /// R/W
FillSetting(Register::DPP::PSD::GateOffset , ch); /// 0x105C; /// R/W
FillSetting(Register::DPP::PSD::TriggerThreshold , ch); /// 0x1060; /// R/W
FillSetting(Register::DPP::PSD::FixedBaseline , ch); /// 0x1064; /// R/W
FillSetting(Register::DPP::PSD::TriggerLatency , ch); /// 0x106C; /// R/W
FillSetting(Register::DPP::PSD::ShapedTriggerWidth , ch); /// 0x1070; /// R/W
FillSetting(Register::DPP::PSD::TriggerHoldOffWidth , ch); /// 0x1074; /// R/W
FillSetting(Register::DPP::PSD::ThresholdForPSDCut , ch); /// 0x1078; /// R/W
FillSetting(Register::DPP::PSD::PurGapThreshold , ch); /// 0x107C; /// R/W
FillSetting(Register::DPP::PSD::DPPAlgorithmControl2_G , ch); /// 0x1084; /// R/W
FillSetting(Register::DPP::PSD::EarlyBaselineFreeze , ch); /// 0x10D8; /// R/W
}
}
FillSetting(Register::DPP::BoardConfiguration ); /// 0x8000; /// R/W
FillSetting(Register::DPP::AggregateOrganization ); /// 0x800C; /// R/W
FillSetting(Register::DPP::AcquisitionControl ); /// 0x8100; /// R/W
FillSetting(Register::DPP::AcquisitionStatus_R ); /// 0x8104; /// R
FillSetting(Register::DPP::GlobalTriggerMask ); /// 0x810C; /// R/W
FillSetting(Register::DPP::FrontPanelTRGOUTEnableMask ); /// 0x8110; /// R/W
FillSetting(Register::DPP::LVDSIOData ); /// 0x8118; /// R/W
FillSetting(Register::DPP::FrontPanelIOControl ); /// 0x811C; /// R/W
FillSetting(Register::DPP::ChannelEnableMask ); /// 0x8120; /// R/W
FillSetting(Register::DPP::ROCFPGAFirmwareRevision_R ); /// 0x8124; /// R
FillSetting(Register::DPP::EventStored_R ); /// 0x812C; /// R
FillSetting(Register::DPP::VoltageLevelModeConfig ); /// 0x8138; /// R/W
FillSetting(Register::DPP::BoardInfo_R ); /// 0x8140; /// R /// [0:7] 0x0E = 725, 0x0B = 730, [8:15] 0x01 = 640 kSample, 0x08 = 5.12 MSample, [16:23] channel number
FillSetting(Register::DPP::AnalogMonitorMode ); /// 0x8144; /// R/W
FillSetting(Register::DPP::EventSize_R ); /// 0x814C; /// R
FillSetting(Register::DPP::TimeBombDowncounter_R ); /// 0x8158; /// R
FillSetting(Register::DPP::FanSpeedControl ); /// 0x8168; /// R/W
FillSetting(Register::DPP::RunStartStopDelay ); /// 0x8170; /// R/W
FillSetting(Register::DPP::BoardFailureStatus_R ); /// 0x8178; /// R
FillSetting(Register::DPP::DisableExternalTrigger ); /// 0x817C; /// R/W
FillSetting(Register::DPP::FrontPanelLVDSIONewFeatures ); /// 0x81A0; /// R/W
FillSetting(Register::DPP::BufferOccupancyGain ); /// 0x81B4; /// R/W
FillSetting(Register::DPP::ExtendedVetoDelay ); /// 0x81C4; /// R/W
FillSetting(Register::DPP::ReadoutControl ); /// 0xEF00; /// R/W
FillSetting(Register::DPP::ReadoutStatus_R ); /// 0xEF04; /// R
FillSetting(Register::DPP::BoardID ); /// 0xEF08; /// R/W /// Geo address on VME crate
FillSetting(Register::DPP::MCSTBaseAddressAndControl ); /// 0xEF0C; /// R/W
FillSetting(Register::DPP::RelocationAddress ); /// 0xEF10; /// R/W
FillSetting(Register::DPP::InterruptStatusID ); /// 0xEF14; /// R/W
FillSetting(Register::DPP::InterruptEventNumber ); /// 0xEF18; /// R/W
FillSetting(Register::DPP::MaxAggregatePerBlockTransfer); /// 0xEF1C; /// R/W
FillSetting(Register::DPP::Scratch ); /// 0xEF20; /// R/W
FillSetting(Register::DPP::ROMChecksum_R ); /// 0xF000; /// R
FillSetting(Register::DPP::ROMChecksumByte2_R ); /// 0xF004; /// R
FillSetting(Register::DPP::ROMChecksumByte1_R ); /// 0xF008; /// R
FillSetting(Register::DPP::ROMChecksumByte0_R ); /// 0xF00C; /// R
FillSetting(Register::DPP::ROMConstantByte2_R ); /// 0xF010; /// R
FillSetting(Register::DPP::ROMConstantByte1_R ); /// 0xF014; /// R
FillSetting(Register::DPP::ROMConstantByte0_R ); /// 0xF018; /// R
FillSetting(Register::DPP::ROM_C_Code_R ); /// 0xF01C; /// R
FillSetting(Register::DPP::ROM_R_Code_R ); /// 0xF020; /// R
FillSetting(Register::DPP::ROM_IEEE_OUI_Byte2_R ); /// 0xF024; /// R
FillSetting(Register::DPP::ROM_IEEE_OUI_Byte1_R ); /// 0xF028; /// R
FillSetting(Register::DPP::ROM_IEEE_OUI_Byte0_R ); /// 0xF02C; /// R
FillSetting(Register::DPP::ROM_BoardVersion_R ); /// 0xF030; /// R
FillSetting(Register::DPP::ROM_BoardFromFactor_R ); /// 0xF034; /// R
FillSetting(Register::DPP::ROM_BoardIDByte1_R ); /// 0xF038; /// R
FillSetting(Register::DPP::ROM_BoardIDByte0_R ); /// 0xF03C; /// R
FillSetting(Register::DPP::ROM_PCB_rev_Byte3_R ); /// 0xF040; /// R
FillSetting(Register::DPP::ROM_PCB_rev_Byte2_R ); /// 0xF044; /// R
FillSetting(Register::DPP::ROM_PCB_rev_Byte1_R ); /// 0xF048; /// R
FillSetting(Register::DPP::ROM_PCB_rev_Byte0_R ); /// 0xF04C; /// R
FillSetting(Register::DPP::ROM_FlashType_R ); /// 0xF050; /// R
FillSetting(Register::DPP::ROM_BoardSerialNumByte1_R ); /// 0xF080; /// R
FillSetting(Register::DPP::ROM_BoardSerialNumByte0_R ); /// 0xF084; /// R
FillSetting(Register::DPP::ROM_VCXO_Type_R ); /// 0xF088; /// R
isSettingFilledinMemeory = true;
}
void Digitizer::PrintSettingFromMemory(){ void Digitizer::PrintSettingFromMemory(){
for( int i = 0; i < SETTINGSIZE; i++) printf("%4d | 0x%04X |0x%08X = %u \n", i, i*4, setting[i], setting[i]); for( int i = 0; i < SETTINGSIZE; i++) printf("%4d | 0x%04X |0x%08X = %u \n", i, i*4, setting[i], setting[i]);
} }
void Digitizer::OpenSettingBinary(string fileName){ void Digitizer::OpenSettingBinary(string fileName){
delete settingFile; if( settingFile != NULL ) delete settingFile;
settingFile = fopen(fileName.c_str(), "r+"); settingFile = fopen(fileName.c_str(), "r+");
if( settingFile == NULL ){ if( settingFile == NULL ){
this->settingFileName = ""; printf("cannot open file %s. Create one.\n", fileName.c_str());
printf("cannot open file %s. \n", fileName.c_str());
CreateAndSaveSettingToFile(fileName);
}else{
this->settingFileName = fileName; this->settingFileName = fileName;
settingFileExist = true;
printf("setting file already exist.\n");
}
}
void Digitizer::CreateAndSaveSettingToFile(string fileName){
settingFileName = fileName;
settingFile = fopen(settingFileName.c_str(), "w+"); settingFile = fopen(settingFileName.c_str(), "w+");
if( isSettingFilledinMemeory == false) FillAllSettings(); if( isSettingFilledinMemeory == false) ReadAllSettingsFromBoard();
fwrite(setting, SETTINGSIZE * sizeof(unsigned int), 1, settingFile); fwrite(setting, SETTINGSIZE * sizeof(unsigned int), 1, settingFile);
@ -902,9 +690,12 @@ void Digitizer::CreateAndSaveSettingToFile(string fileName){
printf("Created file : %s. file size : %d Byte\n", settingFileName.c_str(), inFileSize); printf("Created file : %s. file size : %d Byte\n", settingFileName.c_str(), inFileSize);
fclose (settingFile); fclose (settingFile);
settingFileExist = true; settingFileExist = true;
}else{
this->settingFileName = fileName;
settingFileExist = true;
printf("setting file already exist. do nothing. Should program the digitizer\n");
}
} }
void Digitizer::LoadSettingBinary(string fileName){ void Digitizer::LoadSettingBinary(string fileName){
@ -919,88 +710,18 @@ void Digitizer::LoadSettingBinary(string fileName){
settingFileExist = true; settingFileExist = true;
settingFileName = fileName; settingFileName = fileName;
/// load binary to memoery
size_t dummy = fread( setting, SETTINGSIZE * sizeof(unsigned int), 1, settingFile); size_t dummy = fread( setting, SETTINGSIZE * sizeof(unsigned int), 1, settingFile);
if( isConnected ) { ProgramSettingsToBoard();
for( int ch = 0; ch < NChannel; ch ++){
SetSettingFromMemory(Register::DPP::RecordLength_G , ch); /// 0x1020; /// R/W
SetSettingFromMemory(Register::DPP::InputDynamicRange , ch); /// 0x1028; /// R/W
SetSettingFromMemory(Register::DPP::NumberEventsPerAggregate_G , ch); /// 0x1034; /// R/W
SetSettingFromMemory(Register::DPP::PreTrigger , ch); /// 0x1038; /// R/W
SetSettingFromMemory(Register::DPP::DPPAlgorithmControl , ch); /// 0x1080; /// R/W
SetSettingFromMemory(Register::DPP::ChannelDCOffset , ch); /// 0x1098; /// R/W
SetSettingFromMemory(Register::DPP::VetoWidth , ch); /// 0x10D4; /// R/W
SetSettingFromMemory(Register::DPP::TriggerValidationMask_G , ch); /// 0x8180; /// R/W, 0x8180 + 4n
if( DPPType == V1730_DPP_PHA_CODE ){
SetSettingFromMemory(Register::DPP::PHA::ChannelStopAcquisition , ch); /// 0x1040; /// R/W not sure
SetSettingFromMemory(Register::DPP::PHA::RCCR2SmoothingFactor , ch); /// 0x1054; /// R/W Trigger Filter smoothing, triggerSmoothingFactor
SetSettingFromMemory(Register::DPP::PHA::InputRiseTime , ch); /// 0x1058; /// R/W OK
SetSettingFromMemory(Register::DPP::PHA::TrapezoidRiseTime , ch); /// 0x105C; /// R/W OK
SetSettingFromMemory(Register::DPP::PHA::TrapezoidFlatTop , ch); /// 0x1060; /// R/W OK
SetSettingFromMemory(Register::DPP::PHA::PeakingTime , ch); /// 0x1064; /// R/W OK
SetSettingFromMemory(Register::DPP::PHA::DecayTime , ch); /// 0x1068; /// R/W OK
SetSettingFromMemory(Register::DPP::PHA::TriggerThreshold , ch); /// 0x106C; /// R/W OK
SetSettingFromMemory(Register::DPP::PHA::RiseTimeValidationWindow, ch); /// 0x1070; /// R/W OK
SetSettingFromMemory(Register::DPP::PHA::TriggerHoldOffWidth , ch); /// 0x1074; /// R/W OK
SetSettingFromMemory(Register::DPP::PHA::PeakHoldOff , ch); /// 0x1078; /// R/W OK
SetSettingFromMemory(Register::DPP::PHA::ShapedTriggerWidth , ch); /// 0x1084; /// R/W not sure
SetSettingFromMemory(Register::DPP::PHA::DPPAlgorithmControl2_G , ch); /// 0x10A0; /// R/W OK
SetSettingFromMemory(Register::DPP::PHA::FineGain , ch); /// 0x10C4; /// R/W OK
}
if( DPPType == V1730_DPP_PSD_CODE ){
SetSettingFromMemory(Register::DPP::PSD::CFDSetting , ch); /// 0x103C; /// R/W
SetSettingFromMemory(Register::DPP::PSD::ChargeZeroSuppressionThreshold, ch); /// 0x1044; /// R/W
SetSettingFromMemory(Register::DPP::PSD::ShortGateWidth , ch); /// 0x1054; /// R/W
SetSettingFromMemory(Register::DPP::PSD::LongGateWidth , ch); /// 0x1058; /// R/W
SetSettingFromMemory(Register::DPP::PSD::GateOffset , ch); /// 0x105C; /// R/W
SetSettingFromMemory(Register::DPP::PSD::TriggerThreshold , ch); /// 0x1060; /// R/W
SetSettingFromMemory(Register::DPP::PSD::FixedBaseline , ch); /// 0x1064; /// R/W
SetSettingFromMemory(Register::DPP::PSD::TriggerLatency , ch); /// 0x106C; /// R/W
SetSettingFromMemory(Register::DPP::PSD::ShapedTriggerWidth , ch); /// 0x1070; /// R/W
SetSettingFromMemory(Register::DPP::PSD::TriggerHoldOffWidth , ch); /// 0x1074; /// R/W
SetSettingFromMemory(Register::DPP::PSD::ThresholdForPSDCut , ch); /// 0x1078; /// R/W
SetSettingFromMemory(Register::DPP::PSD::PurGapThreshold , ch); /// 0x107C; /// R/W
SetSettingFromMemory(Register::DPP::PSD::DPPAlgorithmControl2_G , ch); /// 0x1084; /// R/W
SetSettingFromMemory(Register::DPP::PSD::EarlyBaselineFreeze , ch); /// 0x10D8; /// R/W
} }
} }
SetSettingFromMemory(Register::DPP::BoardConfiguration ); /// 0x8000; /// R/W unsigned int Digitizer::ReadSettingFromFile(Reg registerAddress, int ch){
SetSettingFromMemory(Register::DPP::AggregateOrganization ); /// 0x800C; /// R/W
SetSettingFromMemory(Register::DPP::AcquisitionControl ); /// 0x8100; /// R/W
SetSettingFromMemory(Register::DPP::GlobalTriggerMask ); /// 0x810C; /// R/W
SetSettingFromMemory(Register::DPP::FrontPanelTRGOUTEnableMask ); /// 0x8110; /// R/W
SetSettingFromMemory(Register::DPP::LVDSIOData ); /// 0x8118; /// R/W
SetSettingFromMemory(Register::DPP::FrontPanelIOControl ); /// 0x811C; /// R/W
SetSettingFromMemory(Register::DPP::ChannelEnableMask ); /// 0x8120; /// R/W
SetSettingFromMemory(Register::DPP::VoltageLevelModeConfig ); /// 0x8138; /// R/W
SetSettingFromMemory(Register::DPP::AnalogMonitorMode ); /// 0x8144; /// R/W
SetSettingFromMemory(Register::DPP::FanSpeedControl ); /// 0x8168; /// R/W
SetSettingFromMemory(Register::DPP::RunStartStopDelay ); /// 0x8170; /// R/W
SetSettingFromMemory(Register::DPP::DisableExternalTrigger ); /// 0x817C; /// R/W
SetSettingFromMemory(Register::DPP::FrontPanelLVDSIONewFeatures ); /// 0x81A0; /// R/W
SetSettingFromMemory(Register::DPP::BufferOccupancyGain ); /// 0x81B4; /// R/W
SetSettingFromMemory(Register::DPP::ExtendedVetoDelay ); /// 0x81C4; /// R/W
SetSettingFromMemory(Register::DPP::ReadoutControl ); /// 0xEF00; /// R/W
SetSettingFromMemory(Register::DPP::BoardID ); /// 0xEF08; /// R/W /// Geo address on VME crate
SetSettingFromMemory(Register::DPP::MCSTBaseAddressAndControl ); /// 0xEF0C; /// R/W
SetSettingFromMemory(Register::DPP::RelocationAddress ); /// 0xEF10; /// R/W
SetSettingFromMemory(Register::DPP::InterruptStatusID ); /// 0xEF14; /// R/W
SetSettingFromMemory(Register::DPP::InterruptEventNumber ); /// 0xEF18; /// R/W
SetSettingFromMemory(Register::DPP::MaxAggregatePerBlockTransfer); /// 0xEF1C; /// R/W
SetSettingFromMemory(Register::DPP::Scratch ); /// 0xEF20; /// R/W
}
}
}
unsigned int Digitizer::ReadSettingFromFile(uint32_t registerAddress, int ch){
if ( !settingFileExist ) return -1; if ( !settingFileExist ) return -1;
unsigned short index = CalSettingIndex(registerAddress, ch); unsigned short index = registerAddress.Index(ch);
settingFile = fopen (settingFileName.c_str(),"r"); settingFile = fopen (settingFileName.c_str(),"r");
///fseek( settingFile, address, SEEK_SET); ///fseek( settingFile, address, SEEK_SET);
@ -1014,10 +735,10 @@ unsigned int Digitizer::ReadSettingFromFile(uint32_t registerAddress, int ch){
} }
void Digitizer::SaveSettingToFile(uint32_t registerAddress, unsigned int value, int ch){ void Digitizer::SaveSettingToFile(Reg registerAddress, unsigned int value, int ch){
if ( !settingFileExist ) return ; if ( !settingFileExist ) return ;
unsigned short index = CalSettingIndex(registerAddress, ch); unsigned short index = registerAddress,Index(ch);
setting[index] = value; setting[index] = value;
settingFile = fopen (settingFileName.c_str(),"r+"); settingFile = fopen (settingFileName.c_str(),"r+");
@ -1038,173 +759,35 @@ void Digitizer::SaveSettingAsText(string fileName){
return; return;
} }
uint32_t address = 0; /// this is the actual address Reg * haha = new Reg();
uint32_t registerAddress = 0; /// this is the register address from RegisterAddress.h
string name = "";
for( int i = 0; i < SETTINGSIZE ; i++){ for( unsigned int i = 0; i < SETTINGSIZE ; i++){
haha->SetName("");
uint32_t actualAddress = haha->CalAddress(i);
name = ""; ///printf("%7d--- 0x%04X, 0x%04X\n", i, haha->GetAddress(), haha->ActualAddress());
registerAddress = i * 4;
if( i < 0x0200 /4 ) {address = i * 4 + 0x8000; registerAddress = address; } /// board setting
if( 0x0200 / 4 <= i && i < 0x0300 /4 ) {address = i * 4 + 0xEE00; registerAddress = address; }/// EE00 == F000 - 0200
if( 0x0300 / 4 <= i && i < 0x0F00 /4 ) continue;
if( 0x0F00 / 4 <= i && i < 0x1000 /4 ) {address = i * 4 + 0xE000; registerAddress = address; }
if( 0x1000 / 4 <= i ) { address = i * 4; registerAddress = address & 0xF0FF ; }
///for TriggerValidationMask
if( i == ((0x8180 + 4) & 0x0FFF) / 4 ) {address = 0x8180 + 4; registerAddress = 0x8180;} /// 1
if( i == ((0x8180 + 8) & 0x0FFF) / 4 ) {address = 0x8180 + 8; registerAddress = 0x8180;} /// 2
if( i == ((0x8180 + 12) & 0x0FFF) / 4 ) {address = 0x8180 + 12; registerAddress = 0x8180;} /// 3
if( i == ((0x8180 + 16) & 0x0FFF) / 4 ) {address = 0x8180 + 16; registerAddress = 0x8180;} /// 4
if( i == ((0x8180 + 20) & 0x0FFF) / 4 ) {address = 0x8180 + 20; registerAddress = 0x8180;} /// 5
if( i == ((0x8180 + 24) & 0x0FFF) / 4 ) {address = 0x8180 + 24; registerAddress = 0x8180;} /// 6
if( i == ((0x8180 + 28) & 0x0FFF) / 4 ) {address = 0x8180 + 28; registerAddress = 0x8180;} /// 7
printf("==============%4d, 0x%04X , 0x%04X, 0x%04X \n", i, i*4, address, registerAddress);
if( DPPType == V1730_DPP_PSD_CODE || DPPType == V1730_DPP_PHA_CODE) {
for( int p = 0; p < (int) RegisterDPPList.size(); p++){ for( int p = 0; p < (int) RegisterDPPList.size(); p++){
if( registerAddress == (uint32_t) RegisterDPPList[p] ) { if( haha->GetAddress() == (uint32_t) RegisterDPPList[p] ) haha->SetName(RegisterDPPList[p].GetName() );
printf("0x%04X, 0x%04X, 0x%04X \n", i, registerAddress, (uint32_t) RegisterDPPList[p]);
name = RegisterDPPList[p].GetName();
}
}
} }
if( DPPType == V1730_DPP_PHA_CODE) { if( DPPType == V1730_DPP_PHA_CODE) {
for( int p = 0; p < (int) RegisterPHAList.size(); p++){ for( int p = 0; p < (int) RegisterPHAList.size(); p++){
if( registerAddress == (uint32_t) RegisterPHAList[p] ) name = RegisterPHAList[p].GetName(); if( haha->GetAddress() == (uint32_t) RegisterPHAList[p] ) haha->SetName(RegisterPHAList[p].GetName() );
} }
} }
if( DPPType == V1730_DPP_PSD_CODE) { if( DPPType == V1730_DPP_PSD_CODE) {
for( int p = 0; p < (int) RegisterPSDList.size(); p++){ for( int p = 0; p < (int) RegisterPSDList.size(); p++){
if( registerAddress == (uint32_t) RegisterPSDList[p] ) name = RegisterPSDList[p].GetName(); if( haha->GetAddress() == (uint32_t) RegisterPSDList[p] ) haha->SetName(RegisterPSDList[p].GetName() );
} }
} }
if( name != "" ) fprintf( txtFile, "0x%04X %35s 0x%08X %d\n", address, name.c_str(), setting[i], setting[i]); if( haha->GetName() != "" ) fprintf( txtFile, "0x%04X %35s 0x%08X %d\n", actualAddress, haha->GetNameChar(), setting[i], setting[i]);
/****
if( DPPType == V1730_DPP_PSD_CODE || DPPType == V1730_DPP_PHA_CODE) {
switch( registerAddress ){
case Register::DPP::RecordLength_G : name = "DPP::RecordLength_G "; break;
case Register::DPP::InputDynamicRange : name = "DPP::InputDynamicRange "; break;
case Register::DPP::NumberEventsPerAggregate_G : name = "DPP::NumberEventsPerAggregate_G "; break;
case Register::DPP::PreTrigger : name = "DPP::PreTrigger "; break;
case Register::DPP::TriggerThreshold : name = "DPP::TriggerThreshold "; break;
case Register::DPP::TriggerHoldOffWidth : name = "DPP::TriggerHoldOffWidth "; break;
case Register::DPP::DPPAlgorithmControl : name = "DPP::DPPAlgorithmControl "; break;
case Register::DPP::ChannelStatus_R : name = "DPP::ChannelStatus_R "; break;
case Register::DPP::AMCFirmwareRevision_R : name = "DPP::AMCFirmwareRevision_R "; break;
case Register::DPP::ChannelDCOffset : name = "DPP::ChannelDCOffset "; break;
case Register::DPP::ChannelADCTemperature_R : name = "DPP::ChannelADCTemperature_R "; break;
case Register::DPP::VetoWidth : name = "DPP::VetoWidth "; break;
case Register::DPP::BoardConfiguration : name = "DPP::BoardConfiguration "; break;
case Register::DPP::AggregateOrganization : name = "DPP::AggregateOrganization "; break;
case Register::DPP::AcquisitionControl : name = "DPP::AcquisitionControl "; break;
case Register::DPP::AcquisitionStatus_R : name = "DPP::AcquisitionStatus_R "; break;
case Register::DPP::GlobalTriggerMask : name = "DPP::GlobalTriggerMask "; break;
case Register::DPP::FrontPanelTRGOUTEnableMask : name = "DPP::FrontPanelTRGOUTEnableMask "; break;
case Register::DPP::LVDSIOData : name = "DPP::LVDSIOData "; break;
case Register::DPP::FrontPanelIOControl : name = "DPP::FrontPanelIOControl "; break;
case Register::DPP::ChannelEnableMask : name = "DPP::ChannelEnableMask "; break;
case Register::DPP::ROCFPGAFirmwareRevision_R : name = "DPP::ROCFPGAFirmwareRevision_R "; break;
case Register::DPP::EventStored_R : name = "DPP::EventStored_R "; break;
case Register::DPP::VoltageLevelModeConfig : name = "DPP::VoltageLevelModeConfig "; break;
case Register::DPP::BoardInfo_R : name = "DPP::BoardInfo_R "; break;
case Register::DPP::AnalogMonitorMode : name = "DPP::AnalogMonitorMode "; break;
case Register::DPP::EventSize_R : name = "DPP::EventSize_R "; break;
case Register::DPP::TimeBombDowncounter_R : name = "DPP::TimeBombDowncounter_R "; break;
case Register::DPP::FanSpeedControl : name = "DPP::FanSpeedControl "; break;
case Register::DPP::RunStartStopDelay : name = "DPP::RunStartStopDelay "; break;
case Register::DPP::BoardFailureStatus_R : name = "DPP::BoardFailureStatus_R "; break;
case Register::DPP::DisableExternalTrigger : name = "DPP::DisableExternalTrigger "; break;
case Register::DPP::TriggerValidationMask_G : name = "DPP::TriggerValidationMask_G "; break;
case Register::DPP::FrontPanelLVDSIONewFeatures : name = "DPP::FrontPanelLVDSIONewFeatures "; break;
case Register::DPP::BufferOccupancyGain : name = "DPP::BufferOccupancyGain "; break;
case Register::DPP::ExtendedVetoDelay : name = "DPP::ExtendedVetoDelay "; break;
case Register::DPP::ReadoutControl : name = "DPP::ReadoutControl "; break;
case Register::DPP::ReadoutStatus_R : name = "DPP::ReadoutStatus_R "; break;
case Register::DPP::BoardID : name = "DPP::BoardID "; break;
case Register::DPP::MCSTBaseAddressAndControl : name = "DPP::MCSTBaseAddressAndControl "; break;
case Register::DPP::RelocationAddress : name = "DPP::RelocationAddress "; break;
case Register::DPP::InterruptStatusID : name = "DPP::InterruptStatusID "; break;
case Register::DPP::InterruptEventNumber : name = "DPP::InterruptEventNumber "; break;
case Register::DPP::MaxAggregatePerBlockTransfer : name = "DPP::MaxAggregatePerBlockTransfer "; break;
case Register::DPP::Scratch : name = "DPP::Scratch "; break;
case Register::DPP::ROMChecksum_R : name = "DPP::ROMChecksum_R "; break;
case Register::DPP::ROMChecksumByte2_R : name = "DPP::ROMChecksumByte2_R "; break;
case Register::DPP::ROMChecksumByte1_R : name = "DPP::ROMChecksumByte1_R "; break;
case Register::DPP::ROMChecksumByte0_R : name = "DPP::ROMChecksumByte0_R "; break;
case Register::DPP::ROMConstantByte2_R : name = "DPP::ROMConstantByte2_R "; break;
case Register::DPP::ROMConstantByte1_R : name = "DPP::ROMConstantByte1_R "; break;
case Register::DPP::ROMConstantByte0_R : name = "DPP::ROMConstantByte0_R "; break;
case Register::DPP::ROM_C_Code_R : name = "DPP::ROM_C_Code_R "; break;
case Register::DPP::ROM_R_Code_R : name = "DPP::ROM_R_Code_R "; break;
case Register::DPP::ROM_IEEE_OUI_Byte2_R : name = "DPP::ROM_IEEE_OUI_Byte2_R "; break;
case Register::DPP::ROM_IEEE_OUI_Byte1_R : name = "DPP::ROM_IEEE_OUI_Byte1_R "; break;
case Register::DPP::ROM_IEEE_OUI_Byte0_R : name = "DPP::ROM_IEEE_OUI_Byte0_R "; break;
case Register::DPP::ROM_BoardVersion_R : name = "DPP::ROM_BoardVersion_R "; break;
case Register::DPP::ROM_BoardFromFactor_R : name = "DPP::ROM_BoardFromFactor_R "; break;
case Register::DPP::ROM_BoardIDByte1_R : name = "DPP::ROM_BoardIDByte1_R "; break;
case Register::DPP::ROM_BoardIDByte0_R : name = "DPP::ROM_BoardIDByte0_R "; break;
case Register::DPP::ROM_PCB_rev_Byte3_R : name = "DPP::ROM_PCB_rev_Byte3_R "; break;
case Register::DPP::ROM_PCB_rev_Byte2_R : name = "DPP::ROM_PCB_rev_Byte2_R "; break;
case Register::DPP::ROM_PCB_rev_Byte1_R : name = "DPP::ROM_PCB_rev_Byte1_R "; break;
case Register::DPP::ROM_PCB_rev_Byte0_R : name = "DPP::ROM_PCB_rev_Byte0_R "; break;
case Register::DPP::ROM_FlashType_R : name = "DPP::ROM_FlashType_R "; break;
case Register::DPP::ROM_BoardSerialNumByte1_R : name = "DPP::ROM_BoardSerialNumByte1_R "; break;
case Register::DPP::ROM_BoardSerialNumByte0_R : name = "DPP::ROM_BoardSerialNumByte0_R "; break;
case Register::DPP::ROM_VCXO_Type_R : name = "DPP::ROM_VCXO_Type_R "; break;
}
}
if( DPPType == V1730_DPP_PSD_CODE ) {
switch (registerAddress) {
case Register::DPP::PSD::CFDSetting : name = "DPP::PSD::CFDSetting "; break;
case Register::DPP::PSD::ChargeZeroSuppressionThreshold : name = "DPP::PSD::ChargeZeroSuppressionThreshold "; break;
case Register::DPP::PSD::ShortGateWidth : name = "DPP::PSD::ShortGateWidth "; break;
case Register::DPP::PSD::LongGateWidth : name = "DPP::PSD::LongGateWidth "; break;
case Register::DPP::PSD::GateOffset : name = "DPP::PSD::GateOffset "; break;
case Register::DPP::PSD::TriggerThreshold : name = "DPP::PSD::TriggerThreshold "; break;
case Register::DPP::PSD::FixedBaseline : name = "DPP::PSD::FixedBaseline "; break;
case Register::DPP::PSD::TriggerLatency : name = "DPP::PSD::TriggerLatency "; break;
case Register::DPP::PSD::ShapedTriggerWidth : name = "DPP::PSD::ShapedTriggerWidth "; break;
case Register::DPP::PSD::TriggerHoldOffWidth : name = "DPP::PSD::TriggerHoldOffWidth "; break;
case Register::DPP::PSD::ThresholdForPSDCut : name = "DPP::PSD::ThresholdForPSDCut "; break;
case Register::DPP::PSD::PurGapThreshold : name = "DPP::PSD::PurGapThreshold "; break;
case Register::DPP::PSD::DPPAlgorithmControl2_G : name = "DPP::PSD::DPPAlgorithmControl2_G "; break;
case Register::DPP::PSD::EarlyBaselineFreeze : name = "DPP::PSD::EarlyBaselineFreeze "; break;
}
}
if( DPPType == V1730_DPP_PHA_CODE ) {
switch (registerAddress) {
case Register::DPP::PHA::ChannelStopAcquisition : name = "DPP::PHA::ChannelStopAcquisition "; break;
case Register::DPP::PHA::RCCR2SmoothingFactor : name = "DPP::PHA::RCCR2SmoothingFactor "; break;
case Register::DPP::PHA::InputRiseTime : name = "DPP::PHA::InputRiseTime "; break;
case Register::DPP::PHA::TrapezoidRiseTime : name = "DPP::PHA::TrapezoidRiseTime "; break;
case Register::DPP::PHA::TrapezoidFlatTop : name = "DPP::PHA::TrapezoidFlatTop "; break;
case Register::DPP::PHA::PeakingTime : name = "DPP::PHA::PeakingTime "; break;
case Register::DPP::PHA::DecayTime : name = "DPP::PHA::DecayTime "; break;
case Register::DPP::PHA::TriggerThreshold : name = "DPP::PHA::TriggerThreshold "; break;
case Register::DPP::PHA::RiseTimeValidationWindow : name = "DPP::PHA::RiseTimeValidationWindow "; break;
case Register::DPP::PHA::TriggerHoldOffWidth : name = "DPP::PHA::TriggerHoldOffWidth "; break;
case Register::DPP::PHA::PeakHoldOff : name = "DPP::PHA::PeakHoldOff "; break;
case Register::DPP::PHA::ShapedTriggerWidth : name = "DPP::PHA::ShapedTriggerWidth "; break;
case Register::DPP::PHA::DPPAlgorithmControl2_G : name = "DPP::PHA::DPPAlgorithmControl2_G "; break;
case Register::DPP::PHA::FineGain : name = "DPP::PHA::FineGain "; break;
}
}
***********/
} }
delete haha;
} }

View File

@ -33,10 +33,11 @@ class Digitizer{
///=================Settings ///=================Settings
/// write value to digitizer, memory, and settingFile (if exist) /// write value to digitizer, memory, and settingFile (if exist)
void WriteRegister(uint32_t registerAddress, uint32_t value, int ch = -1); void WriteRegister(Reg registerAddress, uint32_t value, int ch = -1, bool isSave2MemAndFile = true);
/// read value from digitizer and memory, and settingFile(if exist), /// read value from digitizer and memory, and save to memory, and settingFile(if exist),
/// when ch == -1 for register < 0x8000, read ch = 0; /// ch must be >= 0,
uint32_t ReadRegister(uint32_t registerAddress, int ch = -1, string str = ""); /// for board setting, ignore ch
uint32_t ReadRegister(Reg registerAddress, unsigned short ch = 0, bool isSave2MemAndFile = true, string str = "" );
///common for PHA and PSD digitizers ///common for PHA and PSD digitizers
void SetDPPType (int type) { this->DPPType = type;} /// for manual override, or, digitizer does not open void SetDPPType (int type) { this->DPPType = type;} /// for manual override, or, digitizer does not open
@ -53,7 +54,7 @@ class Digitizer{
void SetAggregateOrganization (unsigned int bit); void SetAggregateOrganization (unsigned int bit);
void SetMaxAggregatePerBlockTransfer (unsigned int numEvent); void SetMaxAggregatePerBlockTransfer (unsigned int numEvent);
void SetBits(uint32_t address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch = -1); void SetBits(Reg address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch = -1);
void SetDPPAlgorithmControl(uint32_t bit, int ch = -1); void SetDPPAlgorithmControl(uint32_t bit, int ch = -1);
void SetACQControl(uint32_t bit); void SetACQControl(uint32_t bit);
@ -92,7 +93,7 @@ class Digitizer{
unsigned int GetAggregateOrganization() {return ReadRegister(Register::DPP::AggregateOrganization);} unsigned int GetAggregateOrganization() {return ReadRegister(Register::DPP::AggregateOrganization);}
unsigned int GetMaxNumberOfAggregatePerBlockTransfer() {return ReadRegister(Register::DPP::MaxAggregatePerBlockTransfer);} unsigned int GetMaxNumberOfAggregatePerBlockTransfer() {return ReadRegister(Register::DPP::MaxAggregatePerBlockTransfer);}
unsigned int ReadBits(uint32_t address, unsigned int bitLength, unsigned int bitSmallestPos, int ch = -1 ); unsigned int ReadBits(Reg address, unsigned int bitLength, unsigned int bitSmallestPos, int ch = -1 );
unsigned int GetDPPAlgorithmControl(int ch = -1) {return ReadRegister(Register::DPP::DPPAlgorithmControl, ch);} unsigned int GetDPPAlgorithmControl(int ch = -1) {return ReadRegister(Register::DPP::DPPAlgorithmControl, ch);}
bool IsRunning() {return AcqRun;} bool IsRunning() {return AcqRun;}
@ -114,24 +115,26 @@ class Digitizer{
int ProgramPHABoard(); int ProgramPHABoard();
///================ Setting ///================ Setting
unsigned short CalSettingIndex (uint32_t registerAddress, int ch = -1); /// real address is CalSettingIndex() * 4 //unsigned short CalSettingIndex (uint32_t registerAddress, int ch = -1); /// real address is CalSettingIndex() * 4
void FillSetting (uint32_t registerAddress, int ch = -1); //void FillSetting (Reg registerAddress, int ch = -1); /// Read DIgitizer Setting and save to memory and binary
void SetSettingToMemory (uint32_t registerAddress, unsigned int value, int ch = -1); /// board <--> memory functions
unsigned int GetSettingFromMemory (uint32_t registerAddress, int ch = -1); void ReadAllSettingsFromBoard ();
void FillAllSettings (); void SetSettingFromMemory (Reg registerAddress, int ch = -1); /// write to digitizer
void ProgramSettingsToBoard ();
/// simply read settings from memory
void SetSettingToMemory (Reg registerAddress, unsigned int value, int ch = -1);
unsigned int GetSettingFromMemory (Reg registerAddress, int ch = -1);
void PrintSettingFromMemory (); void PrintSettingFromMemory ();
unsigned int * GetSetting() {return setting;};
void SetSettingFromMemory (uint32_t registerAddress, int ch = -1);
/// memory <--> file
void OpenSettingBinary (string fileName); /// Open setting file, if file not exist, call CreateAndSaveSetiingFile, if file exit simple set the settignFileName void OpenSettingBinary (string fileName); /// Open setting file, if file not exist, call CreateAndSaveSetiingFile, if file exit simple set the settignFileName
void LoadSettingBinary (string fileName); /// load settign file to memory, if digitizer connected, program digitizer void LoadSettingBinary (string fileName); /// load settign file to memory, if digitizer connected, program digitizer
void CreateAndSaveSettingToFile (string fileName); void SaveSettingToFile (Reg registerAddress, unsigned int value, int ch = -1);
void SaveSettingToFile (uint32_t registerAddress, unsigned int value, int ch = -1); unsigned int ReadSettingFromFile (Reg registerAddress, int ch = -1); /// read from setting binary
unsigned int ReadSettingFromFile (uint32_t registerAddress, int ch = -1); /// read from setting binary
void SaveSettingAsText (string fileName); void SaveSettingAsText (string fileName);
///void TranslateSettingBin2Text (string binFileName, int DPPType, string txtFileName);
unsigned int * GetSetting() {return setting;};
string GetSettingFileName() {return settingFileName;} string GetSettingFileName() {return settingFileName;}

View File

@ -17,8 +17,16 @@
/// Reg haha("haha", 0x1234); /// Reg haha("haha", 0x1234);
/// uint32_t papa = haha; /// papa = 0x1234 /// uint32_t papa = haha; /// papa = 0x1234
enum RW { ReadWrite = 0, ReadONLY = 1, WriteONLY = 2};
class Reg{ class Reg{
public: public:
Reg(){
this->name = "";
this->address = 0;
this->type = 0;
this->group = 0;
}
Reg(std::string name, uint32_t address, char type = 0, bool group = 0 ){ Reg(std::string name, uint32_t address, char type = 0, bool group = 0 ){
this->name = name; this->name = name;
this->address = address; this->address = address;
@ -36,13 +44,63 @@ class Reg{
char GetType() const {return this->type;} char GetType() const {return this->type;}
bool GetGroup() const {return this->group;} bool GetGroup() const {return this->group;}
uint32_t ActualAddress(int ch = -1){
if( address == 0x8180 ) return (ch < 0 ? address : (address + 4*(ch/2)));
if( address < 0x8000 ) return (ch < 0 ? (address + 0x7000) : (address + (ch << 8)) );
if( address >= 0x8000 ) return address;
return 0;
}
unsigned short Index (unsigned short ch);
uint32_t CalAddress(unsigned int index); /// output actual address, also write the registerAddress
void SetName(std::string str) {this->name = str;}
private: private:
uint32_t address; uint32_t address; /// This is the table of register, the actual address should call ActualAddress();
std::string name; std::string name;
char type; /// read/write = 0; read = 1; write = 2 char type; /// read/write = 0; read = 1; write = 2
bool group; bool group;
}; };
inline unsigned short Reg::Index (unsigned short ch){
unsigned short index;
if( address == 0x8180){
index = ((address + 4*(ch/2)) & 0x0FFF) / 4;
}else if( address < 0x8000){
index = (address + (ch << 8)) / 4;
}else{
if(address < 0xF000) {
index = (address & 0x0FFF) / 4;
}else{
index = ((address & 0x0FFF) + 0x0200 ) / 4;
}
}
return index;
}
inline uint32_t Reg::CalAddress(unsigned int index){
uint32_t actualAddress = 0xFFFF;
this->address = 0xFFFF;
if( index < 0x0200 /4 ) {actualAddress = index * 4 + 0x8000; this->address = index * 4 + 0x8000; }
if( 0x0200 / 4 <= index && index < 0x0300 /4 ) {actualAddress = index * 4 + 0xEE00; this->address = index * 4 + 0xEE00; }/// EE00 == F000 - 0200
if( 0x0F00 / 4 <= index && index < 0x1000 /4 ) {actualAddress = index * 4 + 0xE000; this->address = index * 4 + 0xE000; }
if( 0x1000 / 4 <= index ) {actualAddress = index * 4; this->address = (index * 4) & 0xF0FF; }
///for TriggerValidationMask
if( index == ((0x8180 + 4) & 0x0FFF) / 4 ) {actualAddress = 0x8180 + 4; address = 0x8180;} /// 1
if( index == ((0x8180 + 8) & 0x0FFF) / 4 ) {actualAddress = 0x8180 + 8; address = 0x8180;} /// 2
if( index == ((0x8180 + 12) & 0x0FFF) / 4 ) {actualAddress = 0x8180 + 12; address = 0x8180;} /// 3
if( index == ((0x8180 + 16) & 0x0FFF) / 4 ) {actualAddress = 0x8180 + 16; address = 0x8180;} /// 4
if( index == ((0x8180 + 20) & 0x0FFF) / 4 ) {actualAddress = 0x8180 + 20; address = 0x8180;} /// 5
if( index == ((0x8180 + 24) & 0x0FFF) / 4 ) {actualAddress = 0x8180 + 24; address = 0x8180;} /// 6
if( index == ((0x8180 + 28) & 0x0FFF) / 4 ) {actualAddress = 0x8180 + 28; address = 0x8180;} /// 7
return actualAddress;
}
namespace Register { namespace Register {
@ -238,7 +296,23 @@ const std::vector<Reg> RegisterPHAList = {
Register::DPP::PHA::PeakHoldOff , Register::DPP::PHA::PeakHoldOff ,
Register::DPP::PHA::ShapedTriggerWidth , Register::DPP::PHA::ShapedTriggerWidth ,
Register::DPP::PHA::DPPAlgorithmControl2_G , Register::DPP::PHA::DPPAlgorithmControl2_G ,
Register::DPP::PHA::FineGain Register::DPP::PHA::FineGain ,
Register::DPP::RecordLength_G ,
Register::DPP::InputDynamicRange ,
Register::DPP::NumberEventsPerAggregate_G ,
Register::DPP::PreTrigger ,
Register::DPP::TriggerThreshold ,
Register::DPP::TriggerHoldOffWidth ,
Register::DPP::DPPAlgorithmControl ,
Register::DPP::ChannelStatus_R ,
Register::DPP::AMCFirmwareRevision_R ,
Register::DPP::ChannelDCOffset ,
Register::DPP::ChannelADCTemperature_R ,
Register::DPP::IndividualSoftwareTrigger_W,
Register::DPP::VetoWidth ,
Register::DPP::TriggerValidationMask_G
}; };
const std::vector<Reg> RegisterPSDList = { const std::vector<Reg> RegisterPSDList = {
@ -256,10 +330,7 @@ const std::vector<Reg> RegisterPSDList = {
Register::DPP::PSD::ThresholdForPSDCut , Register::DPP::PSD::ThresholdForPSDCut ,
Register::DPP::PSD::PurGapThreshold , Register::DPP::PSD::PurGapThreshold ,
Register::DPP::PSD::DPPAlgorithmControl2_G , Register::DPP::PSD::DPPAlgorithmControl2_G ,
Register::DPP::PSD::EarlyBaselineFreeze Register::DPP::PSD::EarlyBaselineFreeze ,
};
const std::vector<Reg> RegisterDPPList = {
Register::DPP::RecordLength_G , Register::DPP::RecordLength_G ,
Register::DPP::InputDynamicRange , Register::DPP::InputDynamicRange ,
@ -275,6 +346,12 @@ const std::vector<Reg> RegisterDPPList = {
Register::DPP::IndividualSoftwareTrigger_W, Register::DPP::IndividualSoftwareTrigger_W,
Register::DPP::VetoWidth , Register::DPP::VetoWidth ,
Register::DPP::TriggerValidationMask_G
};
/// Only Board Setting
const std::vector<Reg> RegisterDPPList = {
Register::DPP::BoardConfiguration , Register::DPP::BoardConfiguration ,
Register::DPP::AggregateOrganization , Register::DPP::AggregateOrganization ,
Register::DPP::ADCCalibration_W , Register::DPP::ADCCalibration_W ,
@ -299,7 +376,6 @@ const std::vector<Reg> RegisterDPPList = {
Register::DPP::RunStartStopDelay , Register::DPP::RunStartStopDelay ,
Register::DPP::BoardFailureStatus_R , Register::DPP::BoardFailureStatus_R ,
Register::DPP::DisableExternalTrigger , Register::DPP::DisableExternalTrigger ,
Register::DPP::TriggerValidationMask_G ,
Register::DPP::FrontPanelLVDSIONewFeatures , Register::DPP::FrontPanelLVDSIONewFeatures ,
Register::DPP::BufferOccupancyGain , Register::DPP::BufferOccupancyGain ,
Register::DPP::ExtendedVetoDelay , Register::DPP::ExtendedVetoDelay ,

View File

@ -103,7 +103,6 @@ int main(int argc, char* argv[]){
int board = i % 3; int board = i % 3;
int port = i/3; int port = i/3;
dig[i] = new Digitizer(board, port, false, true); dig[i] = new Digitizer(board, port, false, true);
dig[i]->CreateAndSaveSettingToFile("setting_" + to_string(dig[i]->GetSerialNumber()) + ".bin");
//dig[i]->OpenSettingBinary("setting_" + to_string(dig[i]->GetSerialNumber()) + ".bin"); //dig[i]->OpenSettingBinary("setting_" + to_string(dig[i]->GetSerialNumber()) + ".bin");
} }