#include "fec2rorc_lib.h" #include "fec2rorc_rcu.h" #include "pca16.h" //======================================================================== int main(int argc, char **argv) { int32_t rorc[3] = {5044, 5046, 5055}; // Hardcoded RORC serials for this LDC!!!! arguments.rcu = -1; arguments.serial = -1; arguments.rev = 4; arguments.channel = 0; arguments.fecs = -1; arguments.tb = 1008; arguments.acqstart = 0; arguments.zsthr = 1; arguments.gf = 1; arguments.pres = 1; arguments.posts = 3; arguments.bc1cfg = 8; // For PCA16: (f(din)- fpd) arguments.gain = 0; // 12mV/fC arguments.shaping = 0; // 120ns arguments.polneg = 1; arguments.sampling = 0; // 50ns arguments.dac = 500; arguments.verbosity = 4; arguments.off = false; arguments.swtrg = false; arguments.sparse = false; arguments.skip = false; arguments.zsen = false; arguments.fpedfile = false; arguments.pwsv = true; arguments.pca16 = true; // Parse arguments; every option seen by parse_opt will be reflected in arguments argp_parse(&argp, argc, argv, 0, 0, &arguments); if ( (arguments.rcu < 0) && (arguments.serial<0) ) { logger(LOG_FATAL, "Either RCU/partition (0..2) or RORC S/N has to be provided!"); return 1; } else if ( arguments.rcu>3 ) { logger(LOG_FATAL, "RCU (0..2) or RORC S/N has to be provided!"); return 1; } else if ( arguments.rcu>=0 ) { arguments.serial = rorc[arguments.rcu]; } char desc[256]; sprintf(desc, "STARTING CONFIGURATION FOR RP%d", arguments.rcu); logger(LOG_ALWAYS, desc); int32_t retval; signal(SIGINT,signal_handler); signal(SIGQUIT,signal_handler); signal(SIGTERM,signal_handler); /* allocate a new RCU model and set values */ rcu_model_t *rcu = get_new_rcu_model(); rcu->ddl_serial = arguments.serial; rcu->ddl_revision = arguments.rev; rcu->ddl_channel = arguments.channel; rcu->key = get_channel(arguments.rev, arguments.serial, arguments.channel); if (rcu->key->err != 0) { sprintf (desc, "Failed to open RORC (rev=%d, s/n=%d, channel=%d)", arguments.rev, arguments.serial, arguments.channel); logger(LOG_FATAL, desc); return(rcu->key->err); } sprintf(desc, "RORC open (rev=%d, s/n=%d, channel=%d)", arguments.rev, arguments.serial, arguments.channel); logger(LOG_INFO, desc); // Reset link logger(LOG_INFO, "Reset RORC/DIU/SIU"); if ( RORC_Reset_all(rcu) ) { logger(LOG_FATAL, "Function RORC_Reset_all() failed!"); free_rcu_model(rcu); return 1; } /* Reset RCU and FECs */ logger(LOG_INFO, "Reset RCU/FECs"); if ( clearall(rcu) ) { logger(LOG_FATAL, "Function clearall() failed!"); free_rcu_model(rcu); return 1; } /* switch FECs */ if ( arguments.off ) logger(LOG_INFO, "Switching OFF all FECs"); if ( arguments.fecs >= 0 ) { logger(LOG_INFO, "Switching FECs"); retval = switchFecs(rcu); if ( retval ) { free_rcu_model(rcu); logger(LOG_FATAL, "Function switchFecs() failed!"); return retval; } } else { logger(LOG_INFO, "Checking FECs!"); retval = checkFecs(rcu); if ( retval ) { free_rcu_model(rcu); logger(LOG_FATAL, "Function checkFecs() failed!"); return retval; } } if ( !arguments.off ) { /* Reset RCU and FECs again */ logger(LOG_INFO, "Reset RCU/FECs second time"); if ( clearall(rcu) ) { logger(LOG_FATAL, "Function clearall() failed!"); free_rcu_model(rcu); return 1; } // configure PCA16 (broadcast) if ( arguments.pca16 ) { logger(LOG_INFO, "Configure PCA16 (broadcast) .."); int polarity = arguments.polneg ? 1 : 0; if ( config_pca16(rcu, 0 /*preamp enabled*/, arguments.gain, arguments.shaping, 0 /*poweron*/, polarity /* positive or negative (for GEMs) signals */, arguments.dac) ) { logger(LOG_FATAL, "Function config_pca16() failed!"); free_rcu_model(rcu); return 1; } } // configure RCU and FECs (broadcast) logger(LOG_INFO, "Configure RCU and FECs (broadcast) .."); if ( config_common(rcu) ) { logger(LOG_FATAL, "Function config_common() failed!"); free_rcu_model(rcu); return 1; } // channel by channel logger(LOG_INFO, "Configure pedestal memories and ROLMs .."); if ( config_rolm_channel(rcu) ) { logger(LOG_ERROR, "Function config_rolm_channel() failed!"); free_rcu_model(rcu); return 1; } // configure FPED register with data from file if ( arguments.fpedfile ) { logger(LOG_INFO, "Configuring pedestals from file .."); if ( writeFPED(rcu) ) { logger(LOG_ERROR, "Function writeFPED() failed!"); free_rcu_model(rcu); return 1; } } // configure DPCFG (broadcast) logger(LOG_INFO, "Configure DPCFG and DPCF2 (broadcast) .."); if ( config_dpcfX(rcu) ) { logger(LOG_ERROR, "Function config_dpcfX() failed!"); free_rcu_model(rcu); return 1; } } // end if switch OFF free_rcu_model(rcu); logger(LOG_ALWAYS, "SUCCESS!"); return 0; }