/****************************************************************************** * * Title : rwConfig_sct.c * Version: 25 March 2003 * * Description: ABCD module configuration structure utility functions * Related files: ABCDconfig.h * Documentation: http://s.home.cern.ch/s/sct/public/sctdaq/sctdaq.html * * Author: Peter W Phillips, P.W.Phillips@rl.ac.uk ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include #include #include #include #if !defined(SCT_ROD) void stub1() { //define a mini function so that file can always be included in } //the project. #else /*============================================================================= * showConfigChipBasic() *============================================================================= * * prints contents of ABCDBasic structure to the console * */ void showConfigChipBasic(ABCDChip *chip){ printf(" config MSB->LSB %d %d %d %d %d %d %d %d %d %d %d\n", chip->basic.config.feedThrough, chip->basic.config.end, chip->basic.config.master, chip->basic.config.outputBypass, chip->basic.config.inputBypass, chip->basic.config.accumulate, chip->basic.config.mask, chip->basic.config.edgeDetect, chip->basic.config.trimRange, chip->basic.config.calibMode, chip->basic.config.readoutMode); printf(" mask 3->0 0x%08x %08x %08x %08x\n", chip->basic.mask[3], chip->basic.mask[2], chip->basic.mask[1], chip->basic.mask[0]); printf(" vthr 0x%02x vcal 0x%02x delay 0x%02x preamp 0x%02x shaper 0x%02x\n", chip->basic.vthr, chip->basic.vcal, chip->basic.delay, chip->basic.preamp, chip->basic.shaper); return; } /*============================================================================= * showConfigChipCaldata() *============================================================================= * * prints contents of ABCDCaldata structure to the console * */ void showConfigChipCaldata(ABCDChip *chip){ printf(" rc_function %d p0 %3.2e p1 %3.2e p2 %3.2e c_factor %3.2f\n", chip->caldata.rc_function, chip->caldata.rc_params[0], chip->caldata.rc_params[1], chip->caldata.rc_params[2], chip->caldata.c_factor); printf(" trim_target %d\n", chip->target); return; } /*============================================================================= * showConfigChipTrim() *============================================================================= * * prints contents of ABCD trim array to the console * */ void showConfigChipTrim(ABCDChip *chip){ int channel, index; for(index=0;index<4;index++){ printf(" index %d 0x",index); for(channel=index;channel<128;channel+=4){ printf("%x ",chip->trim[channel]); } } return; } /*============================================================================= * showConfigChip() *============================================================================= * * prints contents of ABCDChip structure to the console * */ void showConfigChip(ABCDChip *chip){ printf("Chip Address 0x%02d Active 0d%d\n", chip->address, chip->active); showConfigChipBasic(chip); showConfigChipCaldata(chip); showConfigChipTrim(chip); return; } /*============================================================================= * showConfigModule() *============================================================================= * * prints contents of ABCDModule structure to the console * */ void showConfigModule(ABCDModule *module){ int chipIndex; ABCDChip *chip; printf("Module Active %d Select %d pTTC %d rTTC %d Group ID %d.\n", module->active, module->select, module->pTTC, module->rTTC, module->groupId); for(chipIndex=0;chipIndexchip[chipIndex]; showConfigChip(chip); } return; } /*============================================================================= * writeConfigModule() *============================================================================= * * writes contents of ABCDModule structure to a text file * */ INT32 writeConfigModule(ABCDModule *module, char* filename){ FILE* file; int chipIndex; int channel, start, word, nibble; UINT32 data; ABCDChip *chip; file = fopen(filename,"w"); if (file == NULL){ printf("writeConfigModule: cannot open file\n",filename); return (-1); } fprintf(file, "Module Active %d Select %d pTTC %d rTTC %d rx[0] %d rx[1] %d Group ID %d\n", module->active, module->select, module->pTTC, module->rTTC, module->rx[0], module->rx[1], module->groupId); for(chipIndex=0;chipIndexchip[chipIndex]; fprintf(file,"Chip %02d address 0x%02x active %d\n", chipIndex, chip->address, chip->active); fprintf(file," config MSB->LSB %d %d %d %d %d %d %d %d %d %d %d\n", chip->basic.config.feedThrough, chip->basic.config.end, chip->basic.config.master, chip->basic.config.outputBypass, chip->basic.config.inputBypass, chip->basic.config.accumulate, chip->basic.config.mask, chip->basic.config.edgeDetect, chip->basic.config.trimRange, chip->basic.config.calibMode, chip->basic.config.readoutMode); fprintf(file," mask 3->0 0x%08x 0x%08x 0x%08x 0x%08x\n", chip->basic.mask[3], chip->basic.mask[2], chip->basic.mask[1], chip->basic.mask[0]); fprintf(file," vthr 0x%02x vcal 0x%02x delay 0x%02x preamp 0x%02x shaper 0x%02x\n", chip->basic.vthr, chip->basic.vcal, chip->basic.delay, chip->basic.preamp, chip->basic.shaper); fprintf(file," rc_function %d p0 %3.2e p1 %3.2e p2 %3.2e c_factor %3.2f\n", chip->caldata.rc_function, chip->caldata.rc_params[0], chip->caldata.rc_params[1], chip->caldata.rc_params[2], chip->caldata.c_factor); fprintf(file," trim-target %d\n", chip->target); for(start=0;start<128;start+=32){ fprintf(file," trim %02x-%02x ",start,start+31); channel = start; for(word=0;word<4;word++){ data = 0; for(nibble=0;nibble<7;nibble++){ data|=(chip->trim[channel++]&0x0f); data<<=4; } data|=(chip->trim[channel++]&0x0f); fprintf(file," %08x",data); } fprintf(file,"\n"); } } fclose(file); return 0; } /*============================================================================= * readConfigModule() *============================================================================= * * reads contents of ABCDModule structure from a text file * */ INT32 readConfigModule(ABCDModule *module, char* filename){ FILE* file; char line[128]; int nargs; int chipIndex; int start, stop; int word, nibble; UINT32 arg[12]; FLOAT32 farg[4]; ABCDChip *chip = 0; file = fopen(filename,"r"); if (file == NULL){ printf("readConfigModule: cannot open file\n",filename); return (-1); } while(fgets(line,128,file) != (char*) NULL) { if(strncmp(line,"Module",6)==0){ /* first useful line */ nargs=sscanf(line, "Module Active %d Select %d pTTC %d rTTC %d rx[0] %d rx[1] %d Group ID %d", &arg[0], &arg[1], &arg[2], &arg[3], &arg[4], &arg[5], &arg[6]); module->active = (UINT8) arg[0]; module->select = (UINT8) arg[1]; module->pTTC = (UINT8) arg[2]; module->rTTC = (UINT8) arg[3]; module->rx[0] = (UINT8) arg[4]; module->rx[1] = (UINT8) arg[5]; module->groupId = (UINT8) arg[6]; chip=0; } else if(strncmp(line,"Chip",4)==0){ /* new chip */ nargs=sscanf(line,"Chip %d address 0x%x active %d", &chipIndex, &arg[0], &arg[1]); if((chipIndex>=0)&&(chipIndexchip[chipIndex]; chip->address = (UINT8) arg[0]; chip->active = (UINT8) arg[1]; } else{ chip = 0; } } else if(strncmp(line," config",8)==0){ /* basic line 1 */ nargs=sscanf(line, " config MSB->LSB %d %d %d %d %d %d %d %d %d %d %d", &arg[0], &arg[1], &arg[2], &arg[3], &arg[4], &arg[5], &arg[6], &arg[7], &arg[8], &arg[9], &arg[10]); if(chip){ chip->basic.config.feedThrough = arg[0]; chip->basic.config.end = arg[1]; chip->basic.config.master = arg[2]; chip->basic.config.outputBypass = arg[3]; chip->basic.config.inputBypass = arg[4]; chip->basic.config.accumulate = arg[5]; chip->basic.config.mask = arg[6]; chip->basic.config.edgeDetect = arg[7]; chip->basic.config.trimRange = arg[8]; chip->basic.config.calibMode = arg[9]; chip->basic.config.readoutMode = arg[10]; } } else if(strncmp(line," mask",6)==0){ /* basic line 2 */ nargs=sscanf(line," mask 3->0 0x%x 0x%x 0x%x 0x%x ", &arg[0], &arg[1], &arg[2], &arg[3]); if(chip){ chip->basic.mask[3] = arg[0]; chip->basic.mask[2] = arg[1]; chip->basic.mask[1] = arg[2]; chip->basic.mask[0] = arg[3]; } } else if(strncmp(line," vthr",6)==0){ /* basic line 3 */ nargs=sscanf(line, " vthr 0x%x vcal 0x%x delay 0x%x preamp 0x%x shaper 0x%x ", &arg[0], &arg[1], &arg[2], &arg[3], &arg[4]); if(chip){ chip->basic.vthr = (UINT8) arg[0]; chip->basic.vcal = (UINT8) arg[1]; chip->basic.delay = (UINT8) arg[2]; chip->basic.preamp = (UINT8) arg[3]; chip->basic.shaper = (UINT8) arg[4]; } } else if(strncmp(line," rc_function",11)==0){ /* caldata */ nargs=sscanf(line," rc_function %d p0 %f p1 %f p2 %f c_factor %f", &arg[0], &farg[0], &farg[1], &farg[2], &farg[3]); if(chip){ chip->caldata.rc_function = arg[0]; chip->caldata.rc_params[0] = farg[0]; chip->caldata.rc_params[1] = farg[1]; chip->caldata.rc_params[2] = farg[2]; chip->caldata.c_factor = farg[3]; } } else if(strncmp(line," trim-target",13)==0){ /* trim target */ nargs=sscanf(line," trim-target %d", &arg[0]); if(chip){ chip->target= arg[0]; } } else if(strncmp(line," trim",6)==0){ /* trimdata */ nargs=sscanf(line," trim %x-%x %x %x %x %x", &start, &stop, &arg[0], &arg[1], &arg[2], &arg[3]); if(chip){ for(word=0;word<4;word++){ for(nibble=7;nibble>=0;nibble--){ chip->trim[start+nibble]=(UINT8)(arg[word]&0x0f); arg[word]>>=4; } start+=8; } } } } /* end (while) */ if(file){ fclose(file); } return 0; } #endif /* SCT function block. */