13#define UNUSED(x) ((void)(x))
20 "Acq mode = INT : 3",\
21 "Channel Configuration = DWORD : 131088",\
22 "Buffer organization = INT : 10",\
23 "Custom size = INT : 625",\
24 "Channel Mask = DWORD : 255",\
25 "Trigger Source = DWORD : 1073741824",\
26 "Trigger Output = DWORD : 1073741824",\
27 "Post Trigger = DWORD : 1000",\
29 "almost_full = DWORD : 850",\
34 "Threshold = DWORD[8] :",\
43 "NbOUThreshold = DWORD[8] :",\
52 "ZS_Threshold = INT[8] :",\
61 "ZS_NsAmp = DWORD[8] :",\
95 _settings_loaded=
false;
96 _settings_touched=
false;
112: _feindex(feindex), _link(link), _board(board), _moduleID(moduleID)
129v1720CONET2::~v1720CONET2()
174 if (
IsConnected()) { cout <<
"Error: trying to connect already connected board" << endl;
175 return (CAENComm_ErrorCode) 1; }
182 CAENComm_ErrorCode sCAEN;
185 sCAEN = CAENComm_Success;
191 if (sCAEN != CAENComm_Success)
_handle = -1;
202 if (!
IsConnected()) { cout <<
"Error: trying to disconnect already disconnected board" << endl;
return (CAENComm_ErrorCode)1; }
203 if (
IsRunning()) { cout <<
"Error: trying to disconnect running board" << endl;
return (CAENComm_ErrorCode)1; }
210 CAENComm_ErrorCode sCAEN;
213 sCAEN = CAENComm_Success;
215 sCAEN = CAENComm_CloseDevice(
_handle);
234 cout <<
"Error: trying to start already started board" << endl;
235 return (CAENComm_ErrorCode)1;
238 cout <<
"Error: trying to start disconnected board" << endl;
239 return (CAENComm_ErrorCode)1;
243 cm_msg(
MINFO,
"feoV1720",
"Note: settings on board %s touched. Re-initializing board.",
245 cout <<
"reinitializing" << endl;
249 CAENComm_ErrorCode
e =
AcqCtl(V1720_RUN_START);
250 if (
e == CAENComm_Success)
_running=
true;
264 if (!
IsRunning()) { cout <<
"Error: trying to stop already stopped board" << endl;
return (CAENComm_ErrorCode)1; }
265 if (!
IsConnected()) { cout <<
"Error: trying to stop disconnected board" << endl;
return (CAENComm_ErrorCode)1; }
266 CAENComm_ErrorCode
e =
AcqCtl(V1720_RUN_STOP);
267 if (
e == CAENComm_Success)
_running=
false;
284 return CAENComm_Success;
286 return ov1720_Setup(
_handle, mode);
300 return CAENComm_Success;
302 return ov1720_AcqCtl(
_handle, operation);
316 return CAENComm_Success;
318 return ov1720_ChannelConfig(
_handle, operation);
330 if (
verbose >= 2) cout <<
GetName() <<
"::ReadReg(" << hex << address <<
")" << endl;
332 return CAENComm_Success;
334 return CAENComm_Read32(
_handle, address, val);
346 if (
verbose >= 2) cout <<
GetName() <<
"::WriteReg(" << hex << address <<
"," << val <<
")" << endl;
348 return CAENComm_Success;
350 return CAENComm_Write32(
_handle, address, val);
364 return CAENComm_Success;
366 return CAENComm_Read32(
_handle, V1720_EVENT_STORED, val);
371#define MAX_BLT_READ_SIZE 10000
385 cout <<
"Error: trying to ReadEvent disconnected board" << endl;
386 return (CAENComm_ErrorCode)1;
388 DWORD size_remaining, *data_pos =
data, to_read;
394 CAENComm_ErrorCode sCAEN = CAENComm_Success;
397 CAENComm_ErrorCode sCAEN =
ReadReg(V1720_EVENT_SIZE, &size_remaining);
400 while (size_remaining > 0 && sCAEN == CAENComm_Success)
404 for (
WORD i = 0;
i < to_read;
i++)
405 *data_pos++ = rand();
406 sCAEN = CAENComm_Success;
411 sCAEN = CAENComm_BLTRead(
_handle, V1720_EVENT_READOUT_BUFFER, data_pos, to_read, &tempnw);
414 if (
verbose >= 2) cout << sCAEN <<
" = BLTRead(handle=" <<
_handle
415 <<
", addr=" << V1720_EVENT_READOUT_BUFFER
416 <<
", data_pos=" << data_pos
417 <<
", to_read=" << to_read
418 <<
", tempnw returned " << tempnw <<
");" << endl;
421 *dwords_read += tempnw;
422 size_remaining -= tempnw;
438 if (!
IsConnected()) { cout <<
"Error: trying to SendTrigger disconnected board" << endl;
return (CAENComm_ErrorCode)1; }
442 if (
verbose) cout <<
"Sending Trigger (l,b) = (" <<
_link <<
"," <<
_board <<
")" << endl;
445 return WriteReg(V1720_SW_TRIGGER, 0x1);
469 sprintf(set_str,
"/Equipment/FEv1720_SIM/Settings/Board%d",
_board);
472 sprintf(set_str,
"/Equipment/FEv1720I/Settings/Board%d",
_moduleID);
474 sprintf(set_str,
"/Equipment/FEv1720I%0d/Settings/Board%d",
_feindex,
_moduleID);
477 if (
verbose) cout <<
GetName() <<
"::SetODBRecord(" << h <<
"," << set_str <<
",...)" << endl;
519 cout <<
"Error: cannot call InitializeForAcq() without settings loaded properly" << endl;
522 cout <<
"Error: trying to call InitializeForAcq() to unconnected board" << endl;
525 cout <<
"Error: trying to call InitializeForAcq() to already running board" << endl;
531 CAENComm_ErrorCode sCAEN;
535 sCAEN =
WriteReg(V1720_FP_IO_CONTROL, 0x00000000);
538 sCAEN =
WriteReg(V1720_SW_RESET, 0x1);
539 sCAEN =
WriteReg(V1720_SW_CLEAR, 0x1);
542 printf(
"\nBusy daisy chaining \n\n");
543 sCAEN =
WriteReg(V1720_FP_IO_CONTROL, 0x104);
545 sCAEN =
WriteReg(V1720_ACQUISITION_CONTROL, 0x100);
548 cm_msg(
MINFO,
"feoV1720",
"Simulation, no firmware check");
557 uint32_t version = 0;
558 uint32_t prev_chan = 0;
561 const uint32_t amc_fw_ver = 0xc102000b;
562 const uint32_t roc_fw_ver = 0xc2080304;
563 const uint32_t roc_fw_ver_test = 0xc5250306;
565 for(
int iCh=0;iCh<8;iCh++) {
566 addr = 0x108c | (iCh << 8);
568 if((iCh != 0) && (prev_chan != version)) {
569 cm_msg(
MERROR,
"feoV1720",
"Error AMC Channels have different Firmware \n");
574 if(version != amc_fw_ver) {
575 cm_msg(
MERROR,
"feoV1720",
"Incorrect AMC Firmware Version: 0x%08x", version);
578 cm_msg(
MINFO,
"feoV1720",
"AMC Firmware Version: 0x%08x", version);
583 sCAEN =
ReadReg(V1720_ROC_FPGA_FW_REV, &version);
587 cm_msg(
MINFO,
"feoV1720",
"ROC Firmware Version: 0x%08x", version);
589 case roc_fw_ver_test:
590 cm_msg(
MINFO,
"feoV1720",
"*** WARNING *** using new ROC Firmware Version: 0x%08x", version);
593 cm_msg(
MERROR,
"feoV1720",
"Incorrect ROC Firmware Version: 0x%08x", version);
598 const uint32_t v1720_board_type = 0x03;
599 sCAEN =
ReadReg(V1720_BOARD_INFO, &version);
600 if((version & 0xFF) != v1720_board_type)
601 cm_msg(
MINFO,
"feoV1720",
"*** WARNING *** Trying to use a v1720 frontend with another"
602 " type of board. Results will be unexpected!");
619 AcqCtl(V1720_COUNT_ACCEPTED_TRIGGER);
626 WriteReg(V1720_VME_CONTROL, V1720_ALIGN64);
629 for (
int iChan=0; iChan<8; iChan++)
669 int dataType = ((aChannelConfig >> 11) & 0x1);
670 if(((aChannelConfig >> 16) & 0xF) == 0) {
675 cm_msg(
MINFO,
"FE",
"Data Type: Full data with 2.5 Packing");
681 cm_msg(
MINFO,
"FE",
"Data Type: Full data with 2 Packing");
684 else if(((aChannelConfig >> 16) & 0xF) == 2) {
688 cm_msg(
MINFO,
"FE",
"Data Type: ZLE data with 2.5 Packing");
694 cm_msg(
MINFO,
"FE",
"Data Type: ZLE data with 2 Packing");
699 cm_msg(
MERROR,
"FE",
"V1720 Data format Unrecognised reg: 0x%04x", 0x8000);
728 sprintf(tBankName,
"QT%02d",moduleID);
734 *QtData = *(pZLEData+2);
736 *QtData = *(pZLEData+3);
743 uint32_t chMask = pZLEData[1] & 0xFF;
744 for(
int iCh=0; iCh<8; iCh++){
745 if(chMask & (1<<iCh)){
756 uint32_t* nQt = QtData;
763 for(
int iCh=0; iCh<mNCh; iCh++){
764 uint32_t chSize = pZLEData[iPtr];
769 uint32_t prevGoodData=1;
770 while(iChPtr<chSize){
771 uint32_t goodData = ((pZLEData[iPtr]>>31) & 0x1);
772 uint32_t nWords = (pZLEData[iPtr] & 0xFFFFF);
773 if(prevGoodData==0 && goodData==0){
779 prevGoodData=goodData;
781 uint32_t iMin = iBin;
783 uint32_t baseline = (pZLEData[iPtr+1]&0xFFF);
784 for(uint32_t iWord=0; iWord<nWords; iWord++){
787 if(min > (pZLEData[iPtr]&0xFFF) ){
789 min = (pZLEData[iPtr]&0xFFF);
791 if(min > ((pZLEData[iPtr]>>16)&0xFFF) ){
792 iMin = iBin+iWord*2+1;
793 min = ((pZLEData[iPtr]>>16)&0xFFF);
800 *QtData = (((mChMap[iCh]<<28) & 0xF0000000) |
801 ((iMin<<16) & 0x0FFF0000) |
v1720CONET2(int feindex, int link, int board, int moduleID)
Constructor for the module object.
std::string GetName()
Get short string identifying the module's index, link and board number.
int _link
Optical link number.
bool _settings_loaded
ODB settings loaded.
CAENComm_ErrorCode WriteReg(DWORD, DWORD)
Write to 32-bit register.
BOOL IsZLEData()
Get ZLE setting.
CAENComm_ErrorCode SendTrigger()
Send a software trigger to the board.
int InitializeForAcq()
Initialize the hardware for data acquisition.
CAENComm_ErrorCode ChannelConfig(uint32_t)
Control data acquisition.
void fillQtBank(char *aDest, uint32_t *aZLEData, int aModule)
Fill Qt Bank.
int _handle
Device handler.
int _moduleID
Unique module ID.
bool _settings_touched
ODB settings touched.
CAENComm_ErrorCode SetupPreset(int)
Setup board registers using preset (see ov1720.c:ov1720_Setup())
CAENComm_ErrorCode ReadReg(DWORD, DWORD *)
Read 32-bit register.
CAENComm_ErrorCode Disconnect()
Disconnect the board through the optical link.
CAENComm_ErrorCode Poll(DWORD *)
Poll Event Stored register.
CAENComm_ErrorCode AcqCtl(uint32_t)
Control data acquisition.
static const char * config_str[]
Configuration string for this module. (ODB: /Equipment/[eq_name]/Settings/[board_name]/)
CAENComm_ErrorCode StartRun()
Start data acquisition.
BOOL mZLE
true if ZLE (Zero-length encoding) is enabled on all channels
CAENComm_ErrorCode StopRun()
Start data acquisition.
int _feindex
Frontend index number.
CAENComm_ErrorCode ReadEvent(DWORD *, int *)
Read event buffer.
bool IsRunning()
Get run status.
void getChannelConfig(DWORD aChannelConfig)
Get data type and ZLE configuration.
int SetODBRecord(HNDLE h, void(*cb_func)(INT, INT, void *))
Set the ODB record for this module.
bool IsConnected()
Get connected status.
HNDLE _odb_handle
ODB handle.
bool _running
Run in progress.
struct v1720CONET2::V1720_CONFIG_SETTINGS config
instance of config structure
int _board
Module/Board number.
CAENComm_ErrorCode Connect()
Connect the board through the optical link.
INT bk_close(void *event, void *pdata)
void bk_create(void *event, const char *name, WORD type, void **pdata)
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
INT db_open_record(HNDLE hDB, HNDLE hKey, void *ptr, INT rec_size, WORD access_mode, void(*dispatcher)(INT, INT, void *), void *info)
INT db_get_record(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT align)
char * strcomb(const char **list)
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
Settings structure for this v1740 module.
DWORD threshold[8]
0x1n80@[11.. 0]
DWORD nbouthreshold[8]
0x1n84@[11.. 0]
INT zs_threshold[8]
0x1n24@[31.. 0]
DWORD channel_config
0x8000@[19.. 0]
DWORD zs_nsamp[8]
0x1n28@[31.. 0]
DWORD dac[8]
0x1n98@[15.. 0]
INT acq_mode
0x8100@[ 1.. 0]
DWORD channel_mask
0x8120@[ 7.. 0]
INT buffer_organization
0x800C@[ 3.. 0]
DWORD trigger_source
0x810C@[31.. 0]
DWORD trigger_output
0x8110@[31.. 0]
DWORD post_trigger
0x8114@[31.. 0]
INT custom_size
0x8020@[31.. 0]
INT setup
Initial board setup mode number.
#define MAX_BLT_READ_SIZE
Maximum size of data to read using BLT (32-bit) cycle.