/* ts2config.c - Trigger Supervisor 2 configuration/status */ #include #include #include #include #include #include #include #include #include extern int rocMask; int branchEnable=0; unsigned long time_offset=0; /* holds time interval in seconds between force syncs */ int forceSyncInterval = 0; /* #include unresolved symbol 'theIntHandler' */ volatile struct vme_ts { volatile unsigned long csr; volatile unsigned long csr2; volatile unsigned long trig; volatile unsigned long roc; volatile unsigned long sync; volatile unsigned long trigCount; volatile unsigned long trigData; volatile unsigned long lrocData; volatile unsigned long prescale[8]; volatile unsigned long timer[5]; volatile unsigned long intVec; volatile unsigned long rocBufStatus; volatile unsigned long lrocBufStatus; volatile unsigned long rocAckStatus; volatile unsigned long userData1; volatile unsigned long userData2; volatile unsigned long state; volatile unsigned long test; volatile unsigned long blank1; volatile unsigned long scalAssign; volatile unsigned long scalControl; volatile unsigned long scaler[18]; volatile unsigned long scalEvent; volatile unsigned long scalLive1; volatile unsigned long scalLive2; volatile unsigned long id; } VME_TS; volatile struct vme_ts *ts; volatile unsigned long *tsmem; unsigned long ts_memory[4096]; unsigned int events_this_phase, max_events_this_phase; int current_phase = -1; #define TS_ADDR 0xed0000 #define MEM_ADDR (TS_ADDR+0x4000) #define isthis(A) !strncmp(name,A,strlen(A)) void SetTrigEnable(char *name, int val); void SetTrigPrescale(char *name, int val); void SetFastTriggerMode(char *name, int val); void SetSyncEnable(char *name, int val); void SetSyncPeriod(char *name, int val); void SetScaler(char *name, int val); void SetFrontEndBusyEnable(char *name, int val); void SetBusyTimer(char *name, int val); void SetBusyTimerEnable(char *name, int val); void SetBranchEnable(char *name, int val); void SetBranch5Enable(char *name, int val); void SetROCLock(char *name, int val); void ReadMLUData(FILE *f); int TSClearScalers(void); int PrintTimeOffset(); /*------------------ /* TSInit /*------------------*/ int TSInit(void) { /* This routine initializes the TS. It was originally done in TSConfigure() below, but that needs to be called multiple times per run with the implementation of phases. It appears there is some magic in the prestart routine which gets undone by a TS initialize so that it will lock up (as though it is not getting the interrupt.) Hence, this routine which gets called at prestart so the TS is initialized just once per run. */ CheckTSPointer(); /* Initialize trigger supervisor */ ts->csr = 0x1<<15; /* Reset all bits in CSR1 and CSR2 */ ts->csr = 0x0; ts->csr2 = 0x0; ts->trig = 0x1; return 0; } /*---------------- /* TSConfigure /*----------------*/ int TSConfigure(void) { /* Look for the current CODA configuration and try to open a TS config file based on that name. If the CODA configuration is not available, then use "DEFAULT". This turns out to be rather complicated. The main motivation here is for the proper roc mask to be set. In principle, this is supposed to be set automatically in the rocMask global, but in practice, it is not. Therefore, we set the rocMask (i.e. branchenable) in the TS configuration file and use that to program the TS roc mask explicitly. We thus need 1 file per CODA configuration. This has the added benefit of setting trigger bit enables and prescales according to CODA configuration without having to change them each time the CODA configuration changes. It does not appear as though the CODA configuration is easily accessible from here. It *must* exist in the ROC in a TCL variable somewhere, wbut I don't know how to access it. The work-around is to have the event builder run a script on the main DAQ computer that will get the current CODA configuration out of the mini-SQL database and write it into a file that can be read from here. (I told you it was complicated!) For the Hall-D BCAL test, the script is /usr/local/halld/online/scripts/get_coda_config.pl. An entry is made in each of the CODA configurations XXX_script tables to run this script which probes the mSQL database and writes the results into /usr/local/halld/config/coda/coda_config.txt . */ FILE *f; unsigned long laddr; char name[64]; char coda_config[64] = "DEFAULT"; char ts_config_fname[256]; int err; int n; /* Check that pointers have been correctly set up */ if((unsigned long)ts == 0x00000000) { printf("ts memory location not configured. ts=0x%08x should be 0x%08x\n", (unsigned long)ts,TS_ADDR); err=sysBusToLocalAdrs(VME_AM_STD_SUP_DATA,(long *)TS_ADDR,(long **)&ts); printf("ts memory now set to 0x%08x\n",(unsigned long)ts); } if((unsigned long)tsmem != MEM_ADDR) { printf("tsmem memory location not configured. tsmem=0x%08x should be 0x%08x\n" ,(unsigned long)tsmem,MEM_ADDR); err=sysBusToLocalAdrs(VME_AM_STD_SUP_DATA,(long *)MEM_ADDR,(long **)&tsmem); printf("tsmem memory now set to 0x%08x\n",(unsigned long)tsmem); } /* Get CODA configuration */ f = fopen("/usr/local/halld/config/coda/coda_config.txt","r"); if(f){ n = fread(coda_config,1,63,f); fclose(f); if(n>0){ coda_config[n] = 0; /* ensure terminating NULL is present */ } } /* Determine TS configuration file name */ sprintf(ts_config_fname,"/usr/local/halld/config/%s.trig",coda_config); /* Test if config file exists. If not, switch to DEFAULT */ f = fopen(ts_config_fname,"r"); if(!f){ printf("%s doesn't exist. Trying DEFAULT ...\n",ts_config_fname); sprintf(ts_config_fname,"/usr/local/halld/config/%s.trig","DEFAULT"); f = fopen(ts_config_fname,"r"); } /* Open file to read from */ if(!f) { printf("%s:%d Error opening file: %s \n",__FILE__,__LINE__,ts_config_fname); return(0x03); } /* Print status message */ printf("Reading TS configuration from %s\n",ts_config_fname); /* Enable the external busy input */ SetFrontEndBusyEnable(NULL, 1); printf("Set Ext. Front End Busy\n"); /* Read in strings until we get one that we know */ while(1 == fscanf(f,"%s",name)) { char *valptr; int val = -1; valptr = strstr(name,"="); if(valptr)val = atoi(++valptr); if(isthis("enable_trig")) SetTrigEnable(name, val); else if(isthis("prescale_trig")) SetTrigPrescale(name, val); else if(isthis("sync_enable")) SetSyncEnable(name, val); else if(isthis("sync_period")) SetSyncPeriod(name, val); else if(isthis("scaler")) SetScaler(name, val); else if(isthis("busyfrontendenable")) SetFrontEndBusyEnable(name, val); else if(isthis("busytimerenable")) SetBusyTimerEnable(name, val); else if(isthis("busytimer")) SetBusyTimer(name, val); else if(isthis("branchenable")) SetBranchEnable(name, val); else if(isthis("branch5enable")) SetBranch5Enable(name, val); else if(isthis("roc_lock")) SetROCLock(name, val); else if(isthis("FastTriggerMode")) SetFastTriggerMode(name, val); else if(isthis("MLU-data")) ReadMLUData(f); else printf("Skipping string \"%s\"\n",name); } /* rocMask global doesn't get set properly by CODA. */ /* The global branchEnable is set in SetBranchEnable */ ts->roc = branchEnable; /* Close file */ fclose(f); /* Reset all of the scalers */ TSClearScalers(); /* Print status message */ printf("TS configuration complete.\n"); return(0x0); } /*---------------- /* WriteModuleMapToFile /*----------------*/ int WriteModuleMapToFile(char *myhostname) { char filename[512]; FILE *file=NULL; int slot; sprintf(filename,"/usr/local/primex/online/config/%s_modules.map", myhostname); file = fopen(filename, "w"); if(!file){ printf("Unable to open \"%s\" for writing!\n", filename); return -1; } printf("Writing module map to \"%s\"\n",filename); /* For the TS2 crate, the module map is just the TS2 itself in slot 0 */ fprintf(file,"%2d TS2\n", 0); for(slot=1;slot<25;slot++)fprintf(file,"%2d UNKNOWN\n", slot); fclose(file); return 0; } /*---------------- /* SetTrigEnable /*----------------*/ void SetTrigEnable(char *name, int val) { int i; i=atoi(&name[strlen("enable_trig")]); if(val<0 || val>1 || i<1 || i>12) { printf("%s:%d Bad value in \"%s\"\n",__FILE__,__LINE__,name); return; } if(val) ts->trig |= 0x1<trig &= ~(0x1<8; bad_value |= val<0 || val>=(1<<(i<=4 ? 24:16)); if(bad_value) { printf("%s:%d Bad value in \"%s\"\n",__FILE__,__LINE__,name); return; } ts->prescale[i-1] = val; } /*---------------- /* SetFastTriggerMode /*----------------*/ void SetFastTriggerMode(char *name, int val) { if(val<0 || val>1) { printf("%s:%d Bad value in \"%s\"\n",__FILE__,__LINE__,name); return; } printf("%s:%d Setting fast trigger mode to %d\n",__FILE__,__LINE__,val); if(val==1)ts->csr2 |= (1<<15); if(val==0)ts->csr2 &= (~(1<<15)); } /*---------------- /* SetSyncEnable /*----------------*/ void SetSyncEnable(char *name, int val) { if(val<0 || val>1) { printf("%s:%d Bad value in \"%s\"\n",__FILE__,__LINE__,name); return; } if(val==1) ts->csr2 |= 0x0001; else ts->csr2 &=~0x0001; } /*---------------- /* SetSyncPeriod /*----------------*/ void SetSyncPeriod(char *name, int val) { if(val<0 || val>=(1<<16)) { printf("%s:%d Bad value in \"%s\"\n",__FILE__,__LINE__,name); return; } ts->sync = val; } /*---------------- /* SetScaler /*----------------*/ void SetScaler(char *name, int val) { int i, bad_value=0; i=atoi(&name[strlen("scaler")]); bad_value = i<13 || i>18; /* only scalers 13-18 are programmable */ bad_value |= val<0 || val>0x0F; if(bad_value) { printf("%s:%d Bad value in \"%s\"\n",__FILE__,__LINE__,name); return; } ts->scalAssign |= (val&0x0f)<<(i-13); } /*---------------- /* SetFrontEndBusyEnable /*----------------*/ void SetFrontEndBusyEnable(char *name, int val) { val &=0x1; if(val==1)ts->csr2 |= (1<<4); if(val==0)ts->csr2 &= (~(1<<4)); } /*---------------- /* SetBusyTimer /*----------------*/ void SetBusyTimer(char *name, int val) { int i, bad_value=0; bad_value = val<0 || val>0x00FFFF; if(bad_value) { printf("%s:%d Bad value in \"%s\"\n",__FILE__,__LINE__,name); return; } ts->timer[3] = val; } /*---------------- /* SetBusyTimerEnable /*----------------*/ void SetBusyTimerEnable(char *name, int val) { val &=0x1; if(val==1)ts->csr2 |= (1<<2); if(val==0)ts->csr2 &= (~(1<<2)); } /*---------------- /* SetBranchEnable /*----------------*/ void SetBranchEnable(char *name, int val) { /* The commented out code below was left over from PrimEx. From it, it looks like "val" was giving ROC numbers and this was translating them into bits on the TS branches. I'm not sure why this is since the trigConf program allowed the user to specify the bits on each branch. Regardless, this routine was not called for PrimEx anyway (it was commentd out in TSConfig() above. Now we just copy "val" into "brancEnable" directly. */ branchEnable = val; #if 0 /* rocMask is an external variable set by the coda_roc */ /* copy it to our own global here so the TS2 can use it */ /* when configured */ branchEnable=0; if((val>>4)&0x1)branchEnable |= 1<<(4+0); /* primexroc4 */ if((val>>5)&0x1)branchEnable |= 1<<(5+8); /* primexroc5 */ if((val>>6)&0x1)branchEnable |= 1<<(6+16); /* primexroc6 */ if((val>>15)&0x1)branchEnable |= 1<<(4+24); /* tage */ if((val>>16)&0x1)branchEnable |= 1<<(5+24); /* tage2 */ #endif printf("Set branchEnable to 0x%08x for rocMask=0x%08x\n", branchEnable, val); /* this is a 32 bit word so all values must be valid */ ts->roc = branchEnable; } /*---------------- /* SetBranch5Enable /*----------------*/ void SetBranch5Enable(char *name, int val) { if(val<0 || val>1){ printf("%s:%d Bad value in \"%s\" (val=%d)\n",__FILE__,__LINE__,name,val); return; } if(val==0)ts->csr2 &= ~(0x1<<12); /* unset branch 5 */ if(val==1)ts->csr2 |= (0x1<<12); /* set branch 5 */ /* Enable interrupt */ if(val==0)ts->csr2 &= ~(0x1<<11); /* disable interrupt */ if(val==1)ts->csr2 |= (0x1<<11); /* enable interrupt */ } /*---------------- /* SetROCLock /*----------------*/ void SetROCLock(char* name, int val) { int i, bad_value=0; char cmd[256]; i=atoi(&name[strlen("roc_lock")]); bad_value = i<1 || i>5; bad_value |= val<0 || val>1; if(bad_value){printf("%s:%d Bad value in \"%s\" (i=%d,val=%d)\n",__FILE__,__LINE__,name,i,val);return;} if(val==0)ts->csr2 &= ~(0x1<<(5+i-1)); /* unset roc-lock */ if(val==1)ts->csr2 |= (0x1<<(5+i-1)); /* set roc-lock */ } /*---------------- /* ReadMLUData /*----------------*/ void ReadMLUData(FILE *f) { int i; int n_conv; unsigned long laddr; /* Read MLU program into temporary memory */ printf("Reading MLU program"); for(i=0; i<4096; i++) { n_conv = fscanf(f,"%x",&ts_memory[i]); if(i%256 == 1) { printf("."); fflush(stdout); } if(n_conv !=1) { printf("%s:%d MLU section short of values !!\n",__FILE__,__LINE__); break; } } printf("Done\n"); /* Copy MLU program into TS */ for(laddr=0; laddr<=4095; laddr++) tsmem[laddr] = ts_memory[laddr]; /* Set test MLU program printf("Setting test program in MLU. Configuration file info ignored\n"); for(laddr=0; laddr<=4095; laddr++) tsmem[laddr] = 0x03ffff03; */ } /*---------------- /* SetProgram1Event /*----------------*/ void SetProgram1Event(int eventType, int syncFlag) { sysBusToLocalAdrs(VME_AM_STD_SUP_DATA, (long *)TS_ADDR, (long **)&ts); ts->userData1 = (eventType&0xF) + ((syncFlag&0x1)<<7); /* 4-bit type ! */ } /*---------------- /* SetProgram2Event /*----------------*/ void SetProgram2Event(int eventType, int syncFlag) { sysBusToLocalAdrs(VME_AM_STD_SUP_DATA, (long *)TS_ADDR, (long **)&ts); ts->userData2 = (eventType&0xF) + ((syncFlag&0x1)<<7); /* 4-bit type ! */ } /*---------------- /* SendProgram1Event /*----------------*/ void SendProgram1Event(void) { sysBusToLocalAdrs(VME_AM_STD_SUP_DATA, (long *)TS_ADDR, (long **)&ts); ts->csr = 0x10; } /*---------------- /* SendProgram2Event /*----------------*/ void SendProgram2Event(void) { sysBusToLocalAdrs(VME_AM_STD_SUP_DATA, (long *)TS_ADDR, (long **)&ts); ts->csr = 0x20; } /* function for forcing synch. event every 10 seconds; use command taskSpawn "FORCE_SYNC",119,0,6000,force_synch in the boot script */ /*---------------- /* force_synch /*----------------*/ void force_synch() { int eventType, syncFlag, word; extern unsigned long sysClkRateGet(); sysBusToLocalAdrs(VME_AM_STD_SUP_DATA, (long *)TS_ADDR, (long **)&ts); eventType = 0; syncFlag = 1; ts->csr = 0x8000; /* initialize TS board */ SetProgram1Event(eventType, syncFlag); while(1) { taskDelay(sysClkRateGet()*10); word = ts->csr; if(word & 0x1) /* check if 'Go' bit is set */ { /*logMsg("force_synch: 'Go' bit is set - SendProgram1Event\n",0,0,0,0,0,0);*/ SendProgram1Event(); } else { /*logMsg("force_synch: 'Go' bit is not set - do nothing\n",0,0,0,0,0,0);*/ } } } /*---------------------------------------------------------------*/ /*---------------- /* pause_run /*----------------*/ void pause_run(void) { sysBusToLocalAdrs(VME_AM_STD_SUP_DATA, (long *)TS_ADDR, (long **)&ts); /*ts->csr = 0x40; /* reset 'Go' bit */ ts->csr = 0x10000; /* reset 'Go' bit */ } /*---------------- /* resume_run /*----------------*/ void resume_run(void) { sysBusToLocalAdrs(VME_AM_STD_SUP_DATA, (long *)TS_ADDR, (long **)&ts); ts->csr = 0x41; /* set 'Go'bit */ } /*---------------------------------------------------------------*/ /*---------------- /* CheckTSPointer /*----------------*/ int CheckTSPointer(void) { int err; /* Check that pointers have been correctly set up */ if((unsigned long)ts == 0x00000000){ printf("ts memory location not configured. ts=0x%08x should be 0x%08x\n", (unsigned long)ts,TS_ADDR); err = sysBusToLocalAdrs(VME_AM_STD_SUP_DATA, (long *)TS_ADDR, (long **)&ts); printf("ts memory now set to 0x%08x\n",(unsigned long)ts); } return(0); } /*---------------- /* TSVersion /*----------------*/ int TSVersion(void) { char b[4]; *(unsigned long*)b = ts->id; printf("TS version : %c.%c.%c.%c %d.%d.%d.%d 0x%08x\n", b[0],b[1],b[2],b[3],(int)b[0],(int)b[1],(int)b[2],(int)b[3], *(unsigned long*)b); return(0); } /*---------------- /* TSstatus /*----------------*/ int TSstatus(void) { int branch; unsigned int status; int i; int rocenabled; unsigned long b; CheckTSPointer(); /* CSR1 */ status = ts->csr; printf("CSR 1 (0x0):\n"); printf("\t Go : %d\n", (status>>0)&1); printf("\t Pause on Next scheduled Sync : %d\n", (status>>1)&1); printf("\t Sync and Pause : %d\n", (status>>2)&1); printf("\t Initiate Sync Event : %d\n", (status>>3)&1); printf("\t Initiate Program 1 Event : %d\n", (status>>4)&1); printf("\t Initiate Program 2 Event : %d\n", (status>>5)&1); printf("\t Enable Level 1 (drives outputs) : %d\n", (status>>6)&1); printf("\t Override Inhibit : %d\n", (status>>7)&1); printf("\t Test Mode : %d\n", (status>>8)&1); printf("\t Reserved : %d\n", (status>>9)&1); printf("\t Reset : %d\n", (status>>14)&1); printf("\t Initialize : %d\n", (status>>15)&1); printf("\n"); printf("\t Sync Event occurred : %d\n", (status>>16)&1); printf("\t Program 1 Event occurred : %d\n", (status>>17)&1); printf("\t Program 2 Event occurred : %d\n", (status>>18)&1); printf("\t Late Fail occurred : %d\n", (status>>19)&1); printf("\t Inhibit occurred : %d\n", (status>>20)&1); printf("\t Write FIFO error occurred : %d\n", (status>>21)&1); printf("\t Read FIFO error occurreds : %d\n", (status>>22)&1); /* CSR2 */ status = ts->csr2; printf("CSR 2 (0x4):\n"); printf("\t Enable Scheduled Sync : %d\n", (status>>0)&1); printf("\t Use Clear Permit Timer : %d\n", (status>>1)&1); printf("\t Use Front Busy Timer : %d\n", (status>>2)&1); printf("\t Use Clear Hold Timer : %d\n", (status>>3)&1); printf("\t Use External Front Busy : %d\n", (status>>4)&1); printf("\t Lock ROC Branch 1 : %d\n", (status>>5)&1); printf("\t Lock ROC Branch 2 : %d\n", (status>>6)&1); printf("\t Lock ROC Branch 3 : %d\n", (status>>7)&1); printf("\t Lock ROC Branch 4 : %d\n", (status>>8)&1); printf("\t Lock ROC Branch 5 : %d\n", (status>>9)&1); printf("\t Enable Program 1 front panel input : %d\n", (status>>10)&1); printf("\t Enable Interrupt : %d\n", (status>>11)&1); printf("\t Enable local ROC (branch 5) : %d\n", (status>>12)&1); printf("\t Disable Level1 Inputs 9-12 : %d\n", (status>>14)&1); printf("\t Use Fast Mode (no MLU) : %d\n", (status>>15)&1); printf("\n"); /* Interrupt Vector */ printf("VME interrupt vector : 0x%x\n",ts->intVec); printf("\n"); /* ROC Enable Register */ rocenabled = ts->roc; printf("ROC Enable Register (0x60) val=0x%x:\n",rocenabled); for(branch=1;branch<=4;branch++){ printf("Branch %d: 0x%2x bits: ", branch, rocenabled&0xFF); for(i=0;i<=7;i++)printf("%d",(rocenabled>>(7-i))&0x01); printf("\n"); rocenabled >>=8; } printf("\n"); /* ROC Acknowledge Status Register */ status = ts->rocAckStatus; printf("ROC Acknowledge Status Register (0x60): val=0x%x\n",status); for(branch=1;branch<=4;branch++){ printf("Branch %d: 0x%2x bits: ", branch, status&0xFF); for(i=0;i<=7;i++)printf("%d",(status>>(7-i))&0x01); printf(" masked: "); for(i=0;i<=7;i++)printf("%d",(status>>(7-i))&0x01&(rocenabled>>(7-i))); printf("\n"); status >>=8; } printf("\n"); /* Front Busy Timer Register */ printf("Front Busy Timer Register = %d\n\n",ts->timer[3]&0xFFFF); /* State Register */ status = ts->state; printf("State Register (0x6C):\n"); printf("\t Level 1 Accept : %d\n", (status>>0)&1); printf("\t Start Level 2 Trigger : %d\n", (status>>1)&1); printf("\t Level 2 Pass Latched : %d\n", (status>>2)&1); printf("\t Level 2 Fail Latched : %d\n", (status>>3)&1); printf("\t Level 2 Accept : %d\n", (status>>4)&1); printf("\t Start Level 3 Trigger : %d\n", (status>>5)&1); printf("\t Level 3 Pass Latched : %d\n", (status>>6)&1); printf("\t Level 3 Fail Latched : %d\n", (status>>7)&1); printf("\t Level 3 Accept : %d\n", (status>>8)&1); printf("\t Clear : %d\n", (status>>9)&1); printf("\t Front End Busy (external) : %d\n", (status>>10)&1); printf("\t External Inhibit : %d\n", (status>>11)&1); printf("\t Latched Trigger : %d\n", (status>>12)&1); printf("\t TS Busy : %d\n", (status>>13)&1); printf("\t TS Active : %d\n", (status>>14)&1); printf("\t TS Ready : %d\n", (status>>15)&1); printf("\t Main Sequencer Active : %d\n", (status>>16)&1); printf("\t Synchronization Sequencer Active : %d\n", (status>>17)&1); printf("\t Program 1 Event Sequencer Active : %d\n", (status>>18)&1); printf("\t Program 2 Event Sequencer Active : %d\n", (status>>19)&1); printf("\n\n"); /* Trigger Word Count Register */ status = ts->trigCount; printf("Trigger Word Count Register (0x14): %d\n",status&0x0FFF); /* ROC buffer status */ b = ts->rocBufStatus; printf("Trigger FIFO : %d\n",ts->trigCount&0xFFFF); printf("Buffer Counts\n"); printf(" Branch 1 : %d (empty=%d full=%d)\n",(b>>0 )&0x0f,(b>>6 )&0x1,(b>>7 )&0x1); printf(" Branch 2 : %d (empty=%d full=%d)\n",(b>>8 )&0x0f,(b>>14)&0x1,(b>>15)&0x1); printf(" Branch 3 : %d (empty=%d full=%d)\n",(b>>16)&0x0f,(b>>22)&0x1,(b>>23)&0x1); printf(" Branch 4 : %d (empty=%d full=%d)\n",(b>>24)&0x0f,(b>>30)&0x1,(b>>31)&0x1); b = ts->lrocBufStatus; printf(" Branch 5 : %d (empty=%d full=%d)\n",(b>>0 )&0x0f,(b>>6 )&0x1,(b>>7 )&0x1); printf("\n"); return 0; } /*---------------- /* TSsettings /*----------------*/ int TSsettings(void) { int i; unsigned long current_time; CheckTSPointer(); printf("\n ---------- TS settings ----------- \n"); current_time = time(NULL); printf("%s\n",ctime(¤t_time)); printf("Trigger Bits:\n"); printf("Non-common strobe mode:%d\n" ,ts->trig&0x1); for(i=1;i<=12;i++){ int prescale; char *enabled; prescale = ts->prescale[i-1]; prescale &= i<=4 ? 0xFFFFFF:0xFFFF; enabled = (ts->trig>>i)&0x1 ? "enabled":""; if(i<=8) printf("\t %2d %s prescale: %u\n", i, enabled, prescale); else printf("\t %2d %s\n", i, enabled); } printf("\n"); } /*---------------- /* TSscalers /*----------------*/ int TSscalers(void) { int i; CheckTSPointer(); for(i=1;i<=18;i++){ if(i<=12){ printf("Trigger Input %d Count : %d\n",i,ts->scaler[i-1]); }else if(i<=18){ printf("Scaler %d Count : %d\n",i,ts->scaler[i-1]); } } printf("Event Count : %d\n",ts->scalEvent); printf("Live 1 Count : %d\n",ts->scalLive1); printf("Live 2 Count : %d\n\n",ts->scalLive2); return 0; } /*---------------- /* TSClearScalers /*----------------*/ int TSClearScalers(void) { int i; CheckTSPointer(); ts->scalControl |= 0xfffff; /* Resets all scalers including event and livetime scalers */ return 0; } /*---------------- /* TSLiveTime /*----------------*/ int TSLiveTime(void) { float diff_livetime=-1.0, int_livetime=-1.0; static unsigned long last_scalLive1=0, last_scalLive2=0; unsigned long live1, live2; unsigned long b, diff1=0,diff2=0; CheckTSPointer(); live1 = ts->scalLive1; live2 = ts->scalLive2; if(live2>0){ int_livetime = 100.0*(float)live1/(float)live2; } diff1 = live1-last_scalLive1; diff2 = live2-last_scalLive2; if(diff2>0){ diff_livetime = 100.0*(float)diff1/(float)diff2; } b = ts->rocBufStatus; printf(" Livetime : Differential=%3.1f%% Integral=%3.1f%%\n",diff_livetime,int_livetime); printf("Trigger FIFO : %d\n",ts->trigCount&0xFFFF); printf("Buffer Counts\n"); printf(" Branch 1 : %d (empty=%d full=%d)\n",(b>>0 )&0x0f,(b>>6 )&0x1,(b>>7 )&0x1); printf(" Branch 2 : %d (empty=%d full=%d)\n",(b>>8 )&0x0f,(b>>14)&0x1,(b>>15)&0x1); printf(" Branch 3 : %d (empty=%d full=%d)\n",(b>>16)&0x0f,(b>>22)&0x1,(b>>23)&0x1); printf(" Branch 4 : %d (empty=%d full=%d)\n",(b>>24)&0x0f,(b>>30)&0x1,(b>>31)&0x1); b = ts->lrocBufStatus; printf(" Branch 5 : %d (empty=%d full=%d)\n",(b>>0 )&0x0f,(b>>6 )&0x1,(b>>7 )&0x1); printf("\n"); printf("live1=%d(prev=%d) live2=%d(prev=%d)\n", live1, last_scalLive1,live2,last_scalLive2); last_scalLive1 = live1; last_scalLive2 = live2; return 0; } /*---------------- /* livetime /*----------------*/ int livetime(void) { float diff_livetime=-1.0; static unsigned long last_scalLive1=0, last_scalLive2=0; unsigned long live1, live2; unsigned long diff1=0,diff2=0; live1 = ts->scalLive1; live2 = ts->scalLive2; CheckTSPointer(); diff1 = live1-last_scalLive1; diff2 = live2-last_scalLive2; if(diff2>0){ diff_livetime = 100.0*(float)diff1/(float)diff2; } printf("%3.1f\n",diff_livetime); last_scalLive1 = live1; last_scalLive2 = live2; return 0; } /*---------------- /* SetTimeOffset /*----------------*/ int SetTimeOffset(unsigned long current_time) { /* Since the system clock is reset on re-boot, we have to */ /* add an offset to the time returned by time(NULL) if we */ /* want the correct time to show up in the EventID bank */ /* This routine should be called with the current time in */ /* seconds as returned by time(NULL) on a system with the */ /* correct system clock. */ time_offset = current_time - time(NULL); PrintTimeOffset(); return 0; } /*---------------- /* PrintTimeOffset /*----------------*/ int PrintTimeOffset() { printf("time_offset set to %d\n",time_offset); return 0; } /*---------------- /* forceSyncTask /* /* function for forcing synch. event every 'forceSyncInterval' seconds */ /*----------------*/ void forceSyncTask() { extern unsigned long sysClkRateGet(); int val; CheckTSPointer(); while(1) { /* if interval==0, wait 1 sec and check again */ if(forceSyncInterval==0) { taskDelay(sysClkRateGet()); continue; } else { /* force sync if go is set */ taskDelay(sysClkRateGet()*forceSyncInterval); val=ts->csr; if(val&0x1) ts->csr=0x8; } } }