static void __end() { int iwait=0; int blocksLeft=0; int id; tiSoftTrig(1,0,0x1123,1); CDODISABLE(TIPRIMARY,TIR_SOURCE,0); /* Before disconnecting... wait for blocks to be emptied */ vmeBusLock(); blocksLeft = tiBReady(); vmeBusUnlock(); printf(">>>>>>>>>>>>>>>>>>>>>>> %d blocks left on the TI\n",blocksLeft);fflush(stdout); if(blocksLeft) { printf(">>>>>>>>>>>>>>>>>>>>>>> before while ... %d blocks left on the TI\n",blocksLeft);fflush(stdout); while(iwait < 10) { taskDelay(10); if(blocksLeft <= 0) break; vmeBusLock(); blocksLeft = tiBReady(); printf(">>>>>>>>>>>>>>>>>>>>>>> inside while ... %d blocks left on the TI\n",blocksLeft);fflush(stdout); vmeBusUnlock(); iwait++; } printf(">>>>>>>>>>>>>>>>>>>>>>> after while ... %d blocks left on the TI\n",blocksLeft);fflush(stdout); } vmeBusLock(); tiStatus(1); vmeBusUnlock(); #ifdef EVENT_CYCLE //reset lms phase printf("INFO: trying to reset lms phase."); vmeBusLock(); lms_phase_change((6 + 1 - lms_phase)%6); vmeBusUnlock(); #endif printf("INFO: End1 Executed\n\n\n");fflush(stdout); return; }
static void __go() { int ii, jj, id, slot; logMsg("INFO: Entering Go 1\n",1,2,3,4,5,6); #ifndef TI_SLAVE /* set sync event interval (in blocks) */ vmeBusLock(); tiSetSyncEventInterval(100000/*10000*//*block_level*/); printf("TI: Sync Event Block-Interval = %d\n", tiGetSyncEventInterval()); vmeBusUnlock(); #endif #ifdef USE_PRAD /* Enable modules, if needed, here */ #ifdef USE_V767 vmeBusLock(); v767Clear(0); vmeBusUnlock(); #endif #ifdef USE_V1190 vmeBusLock(); tdc1190Clear(0); vmeBusUnlock(); #endif /* DCS2 dsc2LatchScalers(0,1); */ #endif tiStatus(1); /* always clear exceptions */ jlabgefClearException(1); nusertrig = 0; ndone = 0; CDOENABLE(TIPRIMARY,TIR_SOURCE,0); /* bryan has (,1,1) ... */ tiSoftTrig(1,1,0x448C,1); logMsg("INFO: Go 1 Executed\n",1,2,3,4,5,6); }
int main(int argc, char *argv[]) { unsigned int laddr; unsigned int taddr = 0x0ed0; int stat; int inputchar=10; vmeOpenDefaultWindows(); while(1 && (inputchar==10)) { printf("Grab mutex lock\n"); vmeBusLock(); printf("Press return to unlock mutex..\n"); getchar(); vmeBusUnlock(); printf("I think it's unlocked now... return to kill it\n"); inputchar = getchar(); } CLOSE: vmeCloseDefaultWindows(); exit(0); }
int main(int argc, char *argv[]) { int ret; unsigned int addr = 0xd000; /* Open the default VME windows */ vmeOpenDefaultWindows(); /* vmeBusLock(); tiInit((21<<19),2,0); tiStatus(1); vmeBusUnlock(); */ printf("argc=%d\n",argc); if(argc==2) { printf("argv=>%s<\n",argv[1]); addr = strtol(argv[1], (char **)NULL, 16); } printf("use addr=0x%04x\n",addr); vmeBusLock(); ret = v851Init(addr,0); v851_start(1000000); vmeBusUnlock(); exit(0); }
static void __go() { int ii, jj, id, slot; logMsg("INFO: Entering Go 1\n",1,2,3,4,5,6); /* set sync event interval (in blocks) */ vmeBusLock(); tsSetSyncEventInterval(0/*10000*//*block_level*/); vmeBusUnlock(); /* always clear exceptions */ jlabgefClearException(1); nusertrig = 0; ndone = 0; CDOENABLE(TSPRIMARY,TIR_SOURCE,0); /* bryan has (,1,1) ... */ logMsg("INFO: Go 1 Executed\n",1,2,3,4,5,6); }
static void __end() { int iwait=0; int blocksLeft=0; int id; printf("\n\nINFO: End1 Reached\n");fflush(stdout); CDODISABLE(TSPRIMARY,TIR_SOURCE,0); /* Before disconnecting... wait for blocks to be emptied */ vmeBusLock(); blocksLeft = tsBReady(); vmeBusUnlock(); printf(">>>>>>>>>>>>>>>>>>>>>>> %d blocks left on the TS\n",blocksLeft);fflush(stdout); if(blocksLeft) { printf(">>>>>>>>>>>>>>>>>>>>>>> before while ... %d blocks left on the TS\n",blocksLeft);fflush(stdout); while(iwait < 10) { taskDelay(10); if(blocksLeft <= 0) break; vmeBusLock(); blocksLeft = tsBReady(); printf(">>>>>>>>>>>>>>>>>>>>>>> inside while ... %d blocks left on the TS\n",blocksLeft);fflush(stdout); vmeBusUnlock(); iwait++; } printf(">>>>>>>>>>>>>>>>>>>>>>> after while ... %d blocks left on the TS\n",blocksLeft);fflush(stdout); } vmeBusLock(); tsStatus(1); vmeBusUnlock(); printf("INFO: End1 Executed\n\n\n");fflush(stdout); return; }
int Vme_Write32(Cmd_Write32 *pCmd_Write32) { int *pRd = pCmd_Write32->vals; int *pWr; int c = pCmd_Write32->cnt; vmeBusToLocalAdrs(0x39, (char *)((long)pCmd_Write32->addr),(char **)&pWr); vmeBusLock(); if(pCmd_Write32->flags & CRATE_MSG_FLAGS_ADRINC) while(c--) *pWr++ = swap32(*pRd++); else while(c--) *pWr = swap32(*pRd++); vmeBusUnlock(); return 0; }
int main(int argc, char *argv[]) { int stat; vmeOpenDefaultWindows(); vmeBusLock(); printf("Press return to assert SYSRESET\n"); getchar(); stat = vmeSysReset(); printf("vmeSysReset returned 0x%x\n",stat); vmeBusUnlock(); vmeCloseDefaultWindows(); exit(0); }
int Vme_Read32(Cmd_Read32 *pCmd_Read32, Cmd_Read32_Rsp *pCmd_Read32_Rsp) { int *pRd; int *pWr = pCmd_Read32_Rsp->vals; int c = pCmd_Read32->cnt; int size = 4+4*c; vmeBusToLocalAdrs(0x39, (char *)((long)pCmd_Read32->addr),(char **)&pRd); pCmd_Read32_Rsp->cnt = c; vmeBusLock(); if(pCmd_Read32->flags & CRATE_MSG_FLAGS_ADRINC) while(c--) *pWr++ = swap32(*pRd++); else while(c--) *pWr++ = swap32(*pRd); vmeBusUnlock(); return size; }
int Vme_Read16(Cmd_Read16 *pCmd_Read16, Cmd_Read16_Rsp *pCmd_Read16_Rsp) { short *pRd; short *pWr = (short *)((long)pCmd_Read16_Rsp->vals); int c = pCmd_Read16->cnt; int size = 4+2*c; vmeBusToLocalAdrs(0x39, (char *)((long)pCmd_Read16->addr),(char **)&pRd); pCmd_Read16_Rsp->cnt = c; vmeBusLock(); if(pCmd_Read16->flags & CRATE_MSG_FLAGS_ADRINC) while(c--) *pWr++ = swap16(*pRd++); else while(c--) *pWr++ = swap16(*pRd); vmeBusUnlock(); return size; }
void faPoll(void) { unsigned int faReady=0; int stat; printf("%s: I'm in\n",__FUNCTION__); while(1) { pthread_testcancel(); /* If still need Ack, don't test the Trigger Status */ if(faStopped>0) { continue; } faReady = faGBready(); stat = (faReady == fadcSlotMask); if(stat>0) { vmeBusLock(); intCount++; myISR(intCount); vmeBusUnlock(); } } printf("%s: Read ERROR: Exiting Thread\n",__FUNCTION__); pthread_exit(0); }
static void __download() { int i1, i2, i3; char *ch, tmp[64]; #ifdef POLLING_MODE rol->poll = 1; #else rol->poll = 0; #endif printf("\n>>>>>>>>>>>>>>> ROCID=%d, CLASSID=%d <<<<<<<<<<<<<<<<\n",rol->pid,rol->classid); printf("CONFFILE >%s<\n\n",rol->confFile); printf("LAST COMPILED: %s %s\n", __DATE__, __TIME__); printf("USRSTRING >%s<\n\n",rol->usrString); /* if slave, get fiber port number from user string */ #ifdef TI_SLAVE ti_slave_fiber_port = 1; /* default */ ch = strstr(rol->usrString,"fp="); if(ch != NULL) { strcpy(tmp,ch+strlen("fp=")); printf("tmp >>>>>>>>>>>>>>>>>>>>>%s<<<<<<<<<<<<<<<<<<<<<\n",tmp); ti_slave_fiber_port = atoi(tmp); printf("ti_slave_fiber_port =%d\n",ti_slave_fiber_port); tiSetFiberIn_preInit(ti_slave_fiber_port); } #endif /* printf("rol1: downloading DDL table ...\n"); clonbanks_(); printf("rol1: ... done.\n"); */ /**/ CTRIGINIT; /* initialize OS windows and TI board */ #ifdef VXWORKS CDOINIT(TIPRIMARY); #else CDOINIT(TIPRIMARY,TIR_SOURCE); #endif /************/ /* init daq */ daqInit(); DAQ_READ_CONF_FILE; /*************************************/ /* redefine TI settings if neseccary */ #ifndef TI_SLAVE /* TS 1-6 create physics trigger, no sync event pin, no trigger 2 */ vmeBusLock(); tiLoadTriggerTable(3); tiSetTriggerWindow(14); // (7+1)*4ns trigger it coincidence time to form trigger type /* tiSetTriggerHoldoff(1,20,1); tiSetTriggerHoldoff(2,0,1); tiSetTriggerHoldoff(3,0,1); tiSetTriggerHoldoff(4,0,1); */ // tiAddSlave(7); // tiAddSlave(8); vmeBusUnlock(); #endif /*********************************************************/ /*********************************************************/ #ifdef USE_PRAD /* (width + 3)*4 ns, 300 ns width */ vmeBusLock(); tiSetPromptTriggerWidth(60); int ii; for(ii = 1; ii <= 6; ++ii) tiSetTSInputDelay(ii, 0); vmeBusUnlock(); #endif /* set wide pulse */ vmeBusLock(); /*sergey: WAS tiSetSyncDelayWidth(1,127,1);*/ /*worked for bit pattern latch tiSetSyncDelayWidth(0x54,127,1);*/ vmeBusUnlock(); usrVmeDmaSetConfig(2,5,1); /*A32,2eSST,267MB/s*/ /*usrVmeDmaSetConfig(2,5,0);*/ /*A32,2eSST,160MB/s*/ /*usrVmeDmaSetConfig(2,3,0);*/ /*A32,MBLT*/ /* if(rol->pid==18) { usrVmeDmaSetConfig(2,3,0); } */ /* usrVmeDmaSetChannel(1); printf("===== Use DMA Channel %d\n\n\n",usrVmeDmaGetChannel()); */ tdcbuf = (unsigned int *)i2_from_rol1; /******************/ /* USER code here */ #ifdef USE_PRAD vmeBusLock(); dsc2Init(0x400000,0x80000,5,0/*1<<19*/); ndsc2 = dsc2GetNdsc(); printf("!!!!!!!!!!! ndsc2=%d\n",ndsc2); if(ndsc2>0) { DSC2_READ_CONF_FILE; ndsc2_daq = dsc2GetNdsc_daq(); printf("!!!!!!!!!!! ndsc2_daq=%d\n",ndsc2_daq); } printf("Set Gate Source... \n"); dsc2SetGateSource(9, 1, 1); //dsc2SetGateSource(9, 2, 3); /* dsc2Init(0x480000,0x80000,5,1<<19); int dsc_ch, dsc_sl; for(dsc_ch = 0; dsc_ch < 6; ++dsc_ch) dsc2SetThreshold(0, dsc_ch, 100, TDCTRG); for(dsc_sl = 1; dsc_sl < 5; ++dsc_sl) { dsc2SetDelay(dsc_sl, 0, 3); for(dsc_ch = 0; dsc_ch < 16; ++dsc_ch) dsc2SetThreshold(dsc_sl, dsc_ch, 10, TDCTRG); } dsc2SetChannelMask(0,0xffff,TDCTRG); dsc2SetChannelORMask(0,0xffff,TDCTRG); dsc2Status(0,0); */ vmeBusUnlock(); #ifdef USE_V767 /***************** * V767 SETUP *****************/ /*vmeBusLock();*/ v767Init(V767_ADDR1,V767_OFF,1,0); // turn off test mode v767WriteMicro(0, 0x0200); /* select stop trigger matching, substraction of trigger time, all channels on, autoload on, and save configuration */ // v767SetAcqMode(0,0); // v767SetDReadyMode(0,0); /* v767BusErrEnable(0); */ /* v767SetBLKEndMode(0, 1); */ /* v767AutoloadDisable(itdc); */ /* v767AddrRotary(itdc); */ // v767SetEdgeDetectionMode(0,1); /* v767OverlapTrigDisable(itdc); */ v767TriggerConfig(0,2000,1000,0); /* v767ChannelMask(itdc,channelmask); */ v767Status(0, 0, 0); // v767TriggerConfig(0,0,0,0); /* Print current trigger config */ printf("v767 8\n");fflush(stdout); /*vmeBusUnlock();*/ /* v767SaveConfig(itdc); */ #endif #ifdef USE_V1190 vmeBusLock(); tdc1190Init(V1190_ADDR1, V1190_OFF, 1, 0); TDC_READ_CONF_FILE; vmeBusUnlock(); #endif #endif /* USE_PRAD */ sprintf(rcname,"RC%02d",rol->pid); printf("rcname >%4.4s<\n",rcname); #ifdef SSIPC sprintf(ssname,"%s_%s",getenv("HOST"),rcname); printf("Smartsockets unique name >%s<\n",ssname); epics_msg_sender_init(getenv("EXPID"), ssname); /* SECOND ARG MUST BE UNIQUE !!! */ #endif logMsg("INFO: User Download Executed\n",1,2,3,4,5,6); }
static void __prestart() { int ii, i1, i2, i3; int ret; /* Clear some global variables etc for a clean start */ *(rol->nevents) = 0; event_number = 0; /*tsEnableVXSSignals();TS*/ #ifdef POLLING_MODE CTRIGRSS(TSPRIMARY, TIR_SOURCE, usrtrig, usrtrig_done); #else CTRIGRSA(TSPRIMARY, TIR_SOURCE, usrtrig, usrtrig_done); #endif /**************************************************************************/ /* setting TS busy conditions, based on boards found in Download */ /* tsInit() does nothing for busy, tsConfig() sets fiber, we set the rest */ /* NOTE: if ts is busy, it will not send trigger enable over fiber, since */ /* it is the same fiber and busy has higher priority */ vmeBusLock(); tsSetBusySource(TS_BUSY_LOOPBACK,0); /*tsSetBusySource(TS_BUSY_FP,0);*/ vmeBusUnlock(); /*****************************************************************/ /*****************************************************************/ /* USER code here */ /******************/ vmeBusLock(); tsIntDisable(); vmeBusUnlock(); /* NOT USED !!!!!!!!!!!!!!!!!!!! vmeBusLock(); tsSyncReset(1); vmeBusUnlock(); sleep(1); vmeBusLock(); ret = tsGetSyncResetRequest(); vmeBusUnlock(); if(ret) { printf("ERROR: syncrequest still ON after tsSyncReset(); trying again\n"); sleep(1); vmeBusLock(); tsSyncReset(1); vmeBusUnlock(); sleep(1); } */ /* SYNC RESET - reset event number (and clear FIFOs) in TIs */ sleep(1); vmeBusLock(); tsSyncReset(1); /* '1' will push 'next_block_level' to 'block_level' in slave TI's (not TD's !), we did it already in download */ vmeBusUnlock(); sleep(1); /* USER RESET - use it because 'SYNC RESET' produces too short pulse, still need 'SYNC RESET' above because 'USER RESET' does not do everything 'SYNC RESET' does (in paticular does not reset event number) */ vmeBusLock(); tsUserSyncReset(1); tsUserSyncReset(0); vmeBusUnlock(); vmeBusLock(); ret = tsGetSyncResetRequest(); vmeBusUnlock(); if(ret) { printf("ERROR: syncrequest still ON after tsSyncReset(); try 'tcpClient <rocname> tsSyncReset'\n"); } else { printf("INFO: syncrequest is OFF now\n"); } printf("holdoff rule 1 set to %d\n",tsGetTriggerHoldoff(1)); printf("holdoff rule 2 set to %d\n",tsGetTriggerHoldoff(2)); /* set block level in all boards where it is needed; it will overwrite any previous block level settings */ /* #ifdef USE_VSCM for(ii=0; ii<nvscm1; ii++) { slot = vscmSlot(ii); vmeBusLock(); vscmSetBlockLevel(slot, block_level); vmeBusUnlock(); } #endif */ /* { char portfile[1024]; sprintf(portfile,"%s/portnames_%s.txt",getenv("CLON_PARMS"),getenv("EXPID")); printf("Loading port names from file >%s<\n",portfile); tdLoadPortNames(portfile); } */ vmeBusLock(); tsStatus(1); vmeBusUnlock(); vmeBusLock(); ret = tdGStatus(block_level); vmeBusUnlock(); if(ret) { logMsg("ERROR: Go 1: WRONG BLOCK_LEVEL, START NEW RUN FROM 'CONFIGURE !!!\n",1,2,3,4,5,6); logMsg("ERROR: Go 1: WRONG BLOCK_LEVEL, START NEW RUN FROM 'CONFIGURE !!!\n",1,2,3,4,5,6); logMsg("ERROR: Go 1: WRONG BLOCK_LEVEL, START NEW RUN FROM 'CONFIGURE !!!\n",1,2,3,4,5,6); UDP_user_request(MSGERR, "rol1", "WRONG BLOCK_LEVEL, START NEW RUN FROM 'CONFIGURE !!!"); } else { UDP_user_request(0, "rol1", "BLOCK_LEVEL IS OK"); } printf("INFO: Prestart1 Executed\n");fflush(stdout); *(rol->nevents) = 0; rol->recNb = 0; return; }
static void __download() { int ii, i1, i2, i3, id, slot; char filename[1024]; #ifdef POLLING_MODE rol->poll = 1; #else rol->poll = 0; #endif printf("\n>>>>>>>>>>>>>>> ROCID=%d, CLASSID=%d <<<<<<<<<<<<<<<<\n",rol->pid,rol->classid); printf("CONFFILE >%s<\n\n",rol->confFile); printf("LAST COMPILED: %s %s\n", __DATE__, __TIME__); printf("USRSTRING >%s<\n\n",rol->usrString); /**/ CTRIGINIT; /* initialize OS windows and TS board */ #ifdef VXWORKS CDOINIT(TSPRIMARY); #else CDOINIT(TSPRIMARY,TIR_SOURCE); #endif /************/ /* init daq */ daqInit(); DAQ_READ_CONF_FILE; /*************************************/ /* redefine TS settings if neseccary */ tsSetUserSyncResetReceive(1); /* TS 1-6 create physics trigger, no sync event pin, no trigger 2 */ vmeBusLock(); /*tsLoadTriggerTable();*/ /*tsSetTriggerWindow(7);TS*/ // (7+1)*4ns trigger it coincidence time to form trigger type vmeBusUnlock(); /*********************************************************/ /*********************************************************/ /* set wide pulse */ vmeBusLock(); /*sergey: WAS tsSetSyncDelayWidth(1,127,1);*/ /*worked for bit pattern latch tsSetSyncDelayWidth(0x54,127,1);*/ vmeBusUnlock(); usrVmeDmaSetConfig(2,5,1); /*A32,2eSST,267MB/s*/ /*usrVmeDmaSetConfig(2,5,0);*/ /*A32,2eSST,160MB/s*/ /*usrVmeDmaSetConfig(2,3,0);*/ /*A32,MBLT*/ tdcbuf = (unsigned int *)i2_from_rol1; /******************/ /* USER code here */ /* TD setup */ ntd = 0; tdInit((3<<19),0x80000,20,0); ntd = tdGetNtds(); /* actual number of TD boards found */ tdGSetBlockLevel(block_level); tdGSetBlockBufferLevel(buffer_level); //tdAddSlave(17,2); // TI Slave - Bottom Crate (payload) //tdAddSlave(17,5); // TI Slave - Bench (GTP) tdslotmask = 0; for(id=0; id<ntd; id++) { slot = tdSlot(id); tdslotmask |= (1<<slot); printf("=======================> tdslotmask=0x%08x\n",tdslotmask); } printf("TDSLOTMASK: tdslotmask=0x%08x (from library 0x%08x)\n",tdslotmask,tdSlotMask()); sprintf(filename,"%s/portnames_%s.txt",getenv("CLON_PARMS"),getenv("EXPID")); printf("loading portnames from file >%s<\n",filename); tdLoadPortNames(filename); /* tdGStatus(0); */ /*************************************** * SD SETUP ***************************************/ printf("SD init starts\n"); vmeBusLock(); printf("SD init 1\n"); sdInit(1); /* Initialize the SD library */ sdSetActiveVmeSlots(tdslotmask); /* Use the tdslotmask to configure the SD */ sdStatus(); vmeBusUnlock(); printf("SD init done\n"); /* if TDs are present, set busy from SD board */ if(ntd>0) { printf("Set BUSY from SWB for TDs\n"); vmeBusLock(); tsSetBusySource(TS_BUSY_SWB,0); vmeBusUnlock(); } /*sergey: following piece from tsConfig.c, doing it there not always propagate correct block_level to slaves; doing it again here seems helps, have to investigate */ tsSetInstantBlockLevelChange(1); /* enable immediate block level setting */ printf("trig1: setting block_level = %d\n",block_level); sleep(1); tsSetBlockLevel(block_level); sleep(1); tsSetInstantBlockLevelChange(0); /* disable immediate block level setting */ sprintf(rcname,"RC%02d",rol->pid); printf("rcname >%4.4s<\n",rcname); #ifdef SSIPC sprintf(ssname,"%s_%s",getenv("HOST"),rcname); printf("Smartsockets unique name >%s<\n",ssname); epics_msg_sender_init(getenv("EXPID"), ssname); /* SECOND ARG MUST BE UNIQUE !!! */ #endif logMsg("INFO: User Download Executed\n",1,2,3,4,5,6); }
static void __prestart() { int ii, i1, i2, i3; int ret; /* Clear some global variables etc for a clean start */ *(rol->nevents) = 0; event_number = 0; /*tsEnableVXSSignals();TS*/ #ifdef POLLING_MODE CTRIGRSS(TSPRIMARY, TIR_SOURCE, usrtrig, usrtrig_done); #else CTRIGRSA(TSPRIMARY, TIR_SOURCE, usrtrig, usrtrig_done); #endif /**************************************************************************/ /* setting TS busy conditions, based on boards found in Download */ /* tsInit() does nothing for busy, tsConfig() sets fiber, we set the rest */ /* NOTE: if ts is busy, it will not send trigger enable over fiber, since */ /* it is the same fiber and busy has higher priority */ vmeBusLock(); tsSetBusySource(TS_BUSY_LOOPBACK,0); /*tsSetBusySource(TS_BUSY_FP,0);*/ vmeBusUnlock(); /*****************************************************************/ /*****************************************************************/ /* USER code here */ /******************/ vmeBusLock(); tsIntDisable(); vmeBusUnlock(); /* master and standalone crates, NOT slave */ sleep(1); vmeBusLock(); tsSyncReset(1); vmeBusUnlock(); sleep(1); vmeBusLock(); tsSyncReset(1); vmeBusUnlock(); sleep(1); vmeBusLock(); ret = tsGetSyncResetRequest(); vmeBusUnlock(); if(ret) { printf("ERROR: syncrequest still ON after tsSyncReset(); trying again\n"); sleep(1); vmeBusLock(); tsSyncReset(1); vmeBusUnlock(); sleep(1); } vmeBusLock(); ret = tsGetSyncResetRequest(); vmeBusUnlock(); if(ret) { printf("ERROR: syncrequest still ON after tsSyncReset(); try 'tcpClient <rocname> tsSyncReset'\n"); } else { printf("INFO: syncrequest is OFF now\n"); } printf("holdoff rule 1 set to %d\n",tsGetTriggerHoldoff(1)); printf("holdoff rule 2 set to %d\n",tsGetTriggerHoldoff(2)); /* set block level in all boards where it is needed; it will overwrite any previous block level settings */ /* #ifdef USE_VSCM for(ii=0; ii<nvscm1; ii++) { slot = vscmSlot(ii); vmeBusLock(); vscmSetBlockLevel(slot, block_level); vmeBusUnlock(); } #endif */ vmeBusLock(); tsStatus(1); vmeBusUnlock(); printf("INFO: Prestart1 Executed\n");fflush(stdout); *(rol->nevents) = 0; rol->recNb = 0; return; }
static void __prestart() { int ii, i1, i2, i3; int ret; /* Clear some global variables etc for a clean start */ *(rol->nevents) = 0; event_number = 0; tiEnableVXSSignals(); #ifdef POLLING_MODE CTRIGRSS(TIPRIMARY, TIR_SOURCE, usrtrig, usrtrig_done); #else CTRIGRSA(TIPRIMARY, TIR_SOURCE, usrtrig, usrtrig_done); #endif printf(">>>>>>>>>> next_block_level = %d, block_level = %d, use next_block_level\n",next_block_level,block_level); block_level = next_block_level; /**************************************************************************/ /* setting TI busy conditions, based on boards found in Download */ /* tiInit() does nothing for busy, tiConfig() sets fiber, we set the rest */ /* NOTE: if ti is busy, it will not send trigger enable over fiber, since */ /* it is the same fiber and busy has higher priority */ #ifndef TI_SLAVE vmeBusLock(); tiSetBusySource(TI_BUSY_LOOPBACK,0); /*tiSetBusySource(TI_BUSY_FP,0);*/ vmeBusUnlock(); #endif #ifdef USE_PRAD #ifdef USE_V767 vmeBusLock(); v767Clear(0); v767Status(0, 0, 0); vmeBusUnlock(); #endif #ifdef USE_V1190 vmeBusLock(); tdc1190Clear(0); tdc1190Status(0); vmeBusUnlock(); #endif /*if(nfadc>0)*/ { printf("Set BUSY from FP for FASTBUS\n"); vmeBusLock(); tiSetBusySource(TI_BUSY_FP, 0); vmeBusUnlock(); } #endif /* USER code here */ /******************/ vmeBusLock(); tiIntDisable(); vmeBusUnlock(); /* master and standalone crates, NOT slave */ #ifndef TI_SLAVE sleep(1); vmeBusLock(); tiSyncReset(1); vmeBusUnlock(); sleep(1); vmeBusLock(); tiSyncReset(1); vmeBusUnlock(); sleep(1); vmeBusLock(); ret = tiGetSyncResetRequest(); vmeBusUnlock(); if(ret) { printf("ERROR: syncrequest still ON after tiSyncReset(); trying again\n"); sleep(1); vmeBusLock(); tiSyncReset(1); vmeBusUnlock(); sleep(1); } vmeBusLock(); ret = tiGetSyncResetRequest(); vmeBusUnlock(); if(ret) { printf("ERROR: syncrequest still ON after tiSyncReset(); try 'tcpClient <rocname> tiSyncReset'\n"); } else { printf("INFO: syncrequest is OFF now\n"); } /* printf("holdoff rule 1 set to %d\n",tiGetTriggerHoldoff(1)); printf("holdoff rule 2 set to %d\n",tiGetTriggerHoldoff(2)); */ #endif /* set block level in all boards where it is needed; it will overwrite any previous block level settings */ #ifdef TI_SLAVE /* assume that for master and standalone TIs block level is set from config file */ vmeBusLock(); tiSetBlockLevel(block_level); vmeBusUnlock(); #endif #ifdef USE_V1190 tdc1190SetBLTEventNumber(0, block_level); #endif vmeBusLock(); tdc1190Status(0); vmeBusUnlock(); #ifdef EVENT_CYCLE event_count = 0; #endif vmeBusLock(); printf("TISTATUS 1\n"); tiStatus(1); vmeBusUnlock(); vmeBusLock(); ti_usetrg(0); tiSetTriggerSource(TI_TRIGGER_PULSER); // ti_usetrg(TRG_TOTALSUM); // tiSetInputPrescale(5, 3); vmeBusUnlock(); vmeBusLock(); printf("TISTATUS 2\n"); tiStatus(1); vmeBusUnlock(); printf("INFO: Prestart1 Executed\n");fflush(stdout); *(rol->nevents) = 0; rol->recNb = 0; return; }
void usrtrig(unsigned int EVTYPE, unsigned int EVSOURCE) { int *jw, ind, ind2, i, ii, jj, jjj, blen, len, rlen, itdcbuf, nbytes; unsigned int *tdcbuf_save, *tdc, trailer; unsigned int *dabufp1, *dabufp2; int njjloops, slot; int nwords; #ifndef VXWORKS TIMERL_VAR; #endif char *chptr, *chptr0; /*printf("EVTYPE=%d syncFlag=%d\n",EVTYPE,syncFlag);*/ if(syncFlag) printf("EVTYPE=%d syncFlag=%d\n",EVTYPE,syncFlag); rol->dabufp = NULL; /* usleep(100); */ /* sleep(1); */ CEOPEN(EVTYPE, BT_BANKS); /* reformatted on CODA_format.c !!! */ if((syncFlag<0)||(syncFlag>1)) /* illegal */ { printf("Illegal1: syncFlag=%d EVTYPE=%d\n",syncFlag,EVTYPE); } else if((syncFlag==0)&&(EVTYPE==0)) /* illegal */ { printf("Illegal2: syncFlag=%d EVTYPE=%d\n",syncFlag,EVTYPE); } else if((syncFlag==1)&&(EVTYPE==0)) /* force_sync (scaler) events */ { ; /* !!! we are geting here on End transition: syncFlag=1 EVTYPE=0 !!! */ } else if((syncFlag==0)&&(EVTYPE==15)) /* helicity strob events */ { ; } else /* physics and physics_sync events */ { /* for EVIO format, will dump raw data */ tdcbuf_save = tdcbuf; /*************/ /* TS stuff */ /* Set high, the first output port tsSetOutputPort(1,0,0,0,0,0); */ /* Grab the data from the TS */ vmeBusLock(); len = tsReadBlock(tdcbuf,1000,1); vmeBusUnlock(); if(len<=0) { printf("ERROR in tsReadBlock : No data or error, len = %d\n",len); sleep(1); } else { ; /* printf("ts: len=%d\n",len); for(jj=0; jj<len; jj++) printf("ts[%2d] 0x%08x\n",jj,LSWAP(tdcbuf[jj])); */ /* ts: len=8 ts[ 0] 0x8555d101 ts[ 1] 0xff102001 ts[ 2] 0x3a010004 ts[ 3] 0x000001d1 ts[ 4] 0x3f0bb0db ts[ 5] 0x00000005 ts[ 6] 0x02000000 ts[ 7] 0x8d400008 */ BANKOPEN(0xe10A,1,rol->pid); for(jj=0; jj<len; jj++) *rol->dabufp++ = tdcbuf[jj]; BANKCLOSE; } /* Turn off all output ports tsSetOutputPort(0,0,0,0,0,0); */ /* TS stuff */ /*************/ #ifdef DEBUG printf("trig1: start trigger processing\n");fflush(stdout); #endif #ifndef VXWORKS TIMERL_START; #endif /* create HEAD bank if master and standalone crates, NOT slave */ event_number = (EVENT_NUMBER) * block_level - block_level; BANKOPEN(0xe112,1,0); dabufp1 = rol->dabufp; *rol->dabufp ++ = LSWAP((0x10<<27)+block_level); /*block header*/ for(ii=0; ii<block_level; ii++) { event_number ++; /* printf(">>>>>>>>>>>>> %d %d\n",(EVENT_NUMBER),event_number); sleep(1); */ *rol->dabufp ++ = LSWAP((0x12<<27)+(event_number&0x7FFFFFF)); /*event header*/ nwords = 6; /* UPDATE THAT IF THE NUMBER OF DATA WORDS CHANGED BELOW !!! */ *rol->dabufp ++ = LSWAP((0x14<<27)+nwords); /*head data*/ /* COUNT DATA WORDS FROM HERE */ *rol->dabufp ++ = 0; /*version number */ *rol->dabufp ++ = LSWAP(RUN_NUMBER); /*run number */ *rol->dabufp ++ = LSWAP(event_number); /*event number */ if(ii==(block_level-1)) { *rol->dabufp ++ = LSWAP(time(0)); /*event unix time */ *rol->dabufp ++ = LSWAP(EVTYPE); /*event type */ *rol->dabufp ++ = 0; /*reserved for L3 info*/ } else { *rol->dabufp ++ = 0; *rol->dabufp ++ = 0; *rol->dabufp ++ = 0; } /* END OF DATA WORDS */ } nwords = ((int)rol->dabufp-(int)dabufp1)/4 + 1; trailer = (0x11<<27)+nwords; /*printf("ROL1: nwords=%d, block trailer = %d (0x%08x)\n",nwords,trailer,trailer);*/ *rol->dabufp ++ = LSWAP(trailer); /*block trailer*/ BANKCLOSE; #ifndef VXWORKS TIMERL_STOP(100000/block_level,1000+rol->pid); #endif /* read boards configurations */ if(syncFlag==1 || EVENT_NUMBER==1) { printf("SYNC: read boards configurations\n"); BANKOPEN(0xe10E,3,rol->pid); chptr = chptr0 =(char *)rol->dabufp; nbytes = 0; /* add one 'return' to make evio2xml output nicer */ *chptr++ = '\n'; nbytes ++; vmeBusLock(); len = tsUploadAll(chptr, 10000); vmeBusUnlock(); /*printf("\nTS len=%d\n",len); printf(">%s<\n",chptr);*/ chptr += len; nbytes += len; #if 0 /* temporary for crates with GTP */ if(rol->pid==37||rol->pid==39) { #define TEXT_STR 1000 char *roc; int ii, kk, stt = 0; char result[TEXT_STR]; /* string for messages from tcpClientCmd */ char exename[200]; /* command to be executed by tcpServer */ if(rol->pid==37) roc = "hps1gtp"; else roc = "hps2gtp"; sprintf(exename,"gtpUploadAllPrint()"); /*printf("gtptest1: roc >%s< exename >%s<\n",roc,exename);*/ memset(result,0,TEXT_STR); tcpClientSetMysqlHost(mysql_host); tcpClientCmd(roc, exename, result); len = strlen(result) - 2; /* 'result' has 2 extra chars in the end we do not want ????? */ /*printf("gtptest1: len=%d, >%s<",len,result);*/ strncpy(chptr,result,len); chptr += len; nbytes += len; } #endif /* 'nbytes' does not includes end_of_string ! */ chptr[0] = '\n'; chptr[1] = '\n'; chptr[2] = '\n'; chptr[3] = '\n'; nbytes = (((nbytes+1)+3)/4)*4; chptr0[nbytes-1] = '\0'; nwords = nbytes/4; rol->dabufp += nwords; BANKCLOSE; printf("SYNC: read boards configurations - done\n"); } /* read scaler(s) */ if(syncFlag==1 || EVENT_NUMBER==1) { printf("SYNC: read scalers\n"); #ifdef USE_DSC2 /*printf("ndsc2_daq=%d\n",ndsc2_daq);*/ if(ndsc2_daq>0) { BANKOPEN(0xe115,1,rol->pid); for(jj=0; jj<ndsc2_daq; jj++) { slot = dsc2Slot_daq(jj); vmeBusLock(); /* in following argument 4 set to 0xFF means latch and read everything, 0x3F - do not latch and read everything */ nwords = dsc2ReadScalers(slot, tdcbuf, 0x10000, 0xFF, 1); /*printf("nwords=%d, nwords = 0x%08x 0x%08x 0x%08x 0x%08x\n",nwords,tdcbuf[0],tdcbuf[1],tdcbuf[2],tdcbuf[3]);*/ vmeBusUnlock(); #ifdef SSIPC /* { int status, mm; unsigned int dd[72]; for(mm=0; mm<72; mm++) dd[mm] = tdcbuf[mm]; status = epics_msg_send("hallb_dsc2_hps2_slot2","uint",72,dd); } */ #endif /* unlike other boards, dcs2 scaler readout already swapped in 'dsc2ReadScalers', so swap it back, because rol2.c expects big-endian format*/ for(ii=0; ii<nwords; ii++) *rol->dabufp ++ = LSWAP(tdcbuf[ii]); } BANKCLOSE; } #endif printf("SYNC: read scalers - done\n"); } /* print and send livetime, event rate, event count if(syncFlag==1) { printf("SYNC: livetime\n"); int livetime, live_percent; vmeBusLock(); tsLatchTimers(); livetime = tsLive(0); vmeBusUnlock(); live_percent = livetime/10; printf("============= Livetime=%3d percent\n",live_percent); #ifdef SSIPC { int status; status = epics_msg_send("hallb_livetime","int",1,&live_percent); } #endif printf("SYNC: livetime - done\n"); } */ /* for physics sync event, make sure all board buffers are empty */ if(syncFlag==1) { printf("SYNC: make sure all board buffers are empty\n"); int nblocks; nblocks = 0;/*tsGetNumberOfBlocksInBuffer();TS*/ /*printf(" Blocks ready for readout: %d\n\n",nblocks);*/ if(nblocks) { printf("SYNC ERROR: TS nblocks = %d\n",nblocks);fflush(stdout); sleep(10); } printf("SYNC: make sure all board buffers are empty - done\n"); } } /* close event */ CECLOSE; /* nusertrig ++; printf("usrtrig called %d times\n",nusertrig);fflush(stdout); */ return; }
int main(int argc, char *argv[]) { int status; int stat=0; char *mcs_filename; int inputchar=10; unsigned int fadc_address=0; printf("\nJLAB fADC125 firmware update\n"); printf("----------------------------\n"); progName = argv[0]; if(argc<3) { printf(" ERROR: Must specify two arguments\n"); Usage(); exit(-1); } else { mcs_filename = argv[1]; fadc_address = (unsigned int) strtoll(argv[2],NULL,16)&0xffffffff; } fa125FirmwareSetDebug(0); if(fa125FirmwareReadMcsFile(mcs_filename) != OK) { exit(-1); } vmeSetQuietFlag(0); status = vmeOpenDefaultWindows(); if(status<0) { printf(" Unable to initialize VME driver\n"); exit(-1); } int iFlag = (1<<18); /* Do not perform firmware check */ iFlag |= (2<<4); /* Internal Clock */ stat = fa125Init(fadc_address,0x0,1,iFlag); if(stat<0) { printf(" Unable to initialize FADC.\n"); goto CLOSE; } /* Should get the firmware versions here and print them out */ printf(" Will update firmware with file: \n %s\n",mcs_filename); printf(" for fADC125 with VME address = 0x%08x\n",fadc_address); printf(" <ENTER> to continue... or q and <ENTER> to quit without update\n"); inputchar = getchar(); if((inputchar == 113) || (inputchar == 81)) { printf(" Exitting without update\n"); goto CLOSE; } vmeBusLock(); fa125FirmwareSetDebug(FA125_FIRMWARE_DEBUG_MEASURE_TIMES | FA125_FIRMWARE_DEBUG_VERIFY_ERASE); if(fa125FirmwareEraseFull(0)!=OK) { vmeBusUnlock(); goto CLOSE; } if(fa125FirmwareWriteFull(0)!=OK) { vmeBusUnlock(); goto CLOSE; } vmeBusUnlock(); CLOSE: fa125FirmwarePrintTimes(); status = vmeCloseDefaultWindows(); if (status != GEF_SUCCESS) { printf("vmeCloseDefaultWindows failed: code 0x%08x\n",status); return -1; } exit(0); }
void usrtrig(unsigned int EVTYPE, unsigned int EVSOURCE) { int *jw, ind, ind2, i, ii, jj, jjj, blen, len, rlen, itdcbuf, nbytes; unsigned int *tdcbuf_save, *tdc; unsigned int *dabufp1, *dabufp2; int njjloops, slot; int nwords; #ifndef VXWORKS TIMERL_VAR; #endif #ifdef USE_PRAD int islot; int stat, dCnt, idata; unsigned int sync_or_unbuff; unsigned int *dma_dabufp; #endif char *chptr, *chptr0; /*printf("EVTYPE=%d syncFlag=%d\n",EVTYPE,syncFlag);*/ if(syncFlag) printf("EVTYPE=%d syncFlag=%d\n",EVTYPE,syncFlag); rol->dabufp = (int *) 0; /* usleep(100); */ /* sleep(1); */ CEOPEN(EVTYPE, BT_BANKS); /* reformatted on CODA_format.c !!! */ if((syncFlag<0)||(syncFlag>1)) /* illegal */ { printf("Illegal1: syncFlag=%d EVTYPE=%d\n",syncFlag,EVTYPE); } else if((syncFlag==0)&&(EVTYPE==0)) /* illegal */ { printf("Illegal2: syncFlag=%d EVTYPE=%d\n",syncFlag,EVTYPE); } else if((syncFlag==1)&&(EVTYPE==0)) /* force_sync (scaler) events */ { ; /* !!! we are geting here on End transition: syncFlag=1 EVTYPE=0 !!! */ } else if((syncFlag==0)&&(EVTYPE==15)) /* helicity strob events */ { ; } else /* physics and physics_sync events */ { /* for EVIO format, will dump raw data */ tdcbuf_save = tdcbuf; /*************/ /* TI stuff */ /* Set high, the first output port tiSetOutputPort(1,0,0,0); */ /* Grab the data from the TI */ vmeBusLock(); len = tiReadBlock(tdcbuf,900>>2,1); vmeBusUnlock(); BANKOPEN(0xe10A,1,rol->pid); if(len<=0) { printf("ERROR in tiReadBlock : No data or error, len = %d\n",len); sleep(1); } else { ; /* printf("ti: len=%d\n",len); for(jj=0; jj<len; jj++) printf("ti[%2d] 0x%08x\n",jj,LSWAP(tdcbuf[jj])); */ for(jj=0; jj<len; jj++) *rol->dabufp++ = tdcbuf[jj]; } *rol->dabufp++ = LSWAP((lms_phase<<16) | trigger_type); /* *rol->dabufp++ = LSWAP(tiGetScalar(1,0)); *rol->dabufp++ = LSWAP(tiGetScalar(2,0)); *rol->dabufp++ = LSWAP(tiGetScalar(3,0)); *rol->dabufp++ = LSWAP(tiGetScalar(4,0)); *rol->dabufp++ = LSWAP(tiGetScalar(5,0)); *rol->dabufp++ = LSWAP(tiGetScalar(6,0)); */ BANKCLOSE; /* Turn off all output ports tiSetOutputPort(0,0,0,0); */ /* TI stuff */ /*************/ #ifdef DEBUG printf("fadc1: start fadc processing\n");fflush(stdout); #endif #ifndef VXWORKS TIMERL_START; #endif #ifdef USE_PRAD #ifdef USE_V767 BANKOPEN(0xe121,1,rol->pid); dma_dabufp = rol->dabufp; vmeBusLock(); stat = v767Dready(0); vmeBusUnlock(); jj = 0; while( (jj<100) && (stat==0) ) { vmeBusLock(); stat = v767Dready(0); vmeBusUnlock(); jj++; } if(stat) { vmeBusLock(); dCnt = v767ReadEvent(0, dma_dabufp, 256); vmeBusUnlock(); if(dCnt <= 0) /*Error*/ { *dma_dabufp++ = LSWAP(0xed767bad); printf("v767(%d): No data or error. dCnt = %d\n", ii, dCnt); } else { dma_dabufp += dCnt; /*printf("Read: %d\n", dCnt);*/ } } else { printf("v767(%d): Timeout. Data not ready.\n", ii); } rol->dabufp = dma_dabufp; BANKCLOSE; #endif #ifdef USE_V1190 int icheck = 0, maxcheck = 200, nev = 0; for(icheck = 0; icheck < maxcheck; icheck++) { nev = tdc1190Dready(0); if(nev > 0) break; } if(nev > 0) { vmeBusLock(); rlen = tdc1190ReadBoard(0, tdcbuf); vmeBusUnlock(); if(rlen > 0) { BANKOPEN(0xe121,1,rol->pid); for(jj=0; jj<rlen; jj++) { *rol->dabufp++ = LSWAP(tdcbuf[jj]); #ifdef V1190_TEST if(!((*rol->nevents)%1000)) { printf("Read %d words. \n", rlen); if((tdcbuf[jj]&0xf8000000) == 0) printf("channel %d, value %d\n", (tdcbuf[jj] >> 18)&0x7f, (tdcbuf[jj]&0x3ffff)); } #endif } BANKCLOSE; }
int main(int argc, char *argv[]) { int stat; printf("\nJLAB fADC250-V2 Tests\n"); printf("----------------------------\n"); /* remexSetCmsgServer("dafarm28"); */ /* remexInit(NULL,1); */ vmeOpenDefaultWindows(); /* Setup Address and data modes for DMA transfers * * vmeDmaConfig(addrType, dataType, sstMode); * * addrType = 0 (A16) 1 (A24) 2 (A32) * dataType = 0 (D16) 1 (D32) 2 (BLK32) 3 (MBLK) 4 (2eVME) 5 (2eSST) * sstMode = 0 (SST160) 1 (SST267) 2 (SST320) */ vmeDmaConfig(2,5,1); /* INIT dmaPList */ dmaPFreeAll(); vmeIN = dmaPCreate("vmeIN",MAX_EVENT_LENGTH,MAX_EVENT_POOL,0); vmeOUT = dmaPCreate("vmeOUT",0,0,0); dmaPStatsAll(); dmaPReInitAll(); /* gefVmeSetDebugFlags(vmeHdl,0x0); */ vmeSetQuietFlag(1); /* skip the errors associated with BUS Errors */ /* Setup FlexIO */ flexioInit(0xee0, FLEXIO_MODE_POLL); flexioWriteCsr(0, 0x8000); // reset flexioWriteCsr(0, 0x1); // output in vme pulse mode /* Setup output data pattern */ flexioWriteData(0, 0xeded); /* flexioWriteData(0, 0xeded); */ /* Setup fADC250 */ NFADC = 16+2; /* 16 slots + 2 (for the switch slots) */ fadcA32Base=0x09000000; /* Setup the iFlag.. flags for FADC initialization */ int iFlag=0; /* Sync Source */ iFlag |= (0<<0); /* VME */ /* Trigger Source */ iFlag |= (4<<1); /* Internal */ /* Clock Source */ iFlag |= FA_INIT_INT_CLKSRC; /* Self */ iFlag |= FA_INIT_SKIP_FIRMWARE_CHECK; /* faInit((unsigned int)(3<<19),(1<<19),NFADC,iFlag); */ faInit(0xed0000,0,1,iFlag); NFADC=nfadc; /* Redefine our NFADC with what was found from the driver */ vmeSetQuietFlag(0); /* Turn the error statements back on */ faItrigDisable(0, 1); MAXFADCWORDS = NFADC * BLOCKLEVEL * (1+2+FADC_WINDOW_WIDTH*16) + 3; printf("**************************************************\n"); printf("* Calculated MAX FADC words per block = %d\n",MAXFADCWORDS); printf("**************************************************\n"); if(NFADC>1) faEnableMultiBlock(1); if(NFADC==0) goto CLOSE; /* Additional Configuration for each module */ fadcSlotMask=0; int islot=0; for(islot=0;islot<NFADC;islot++) { FA_SLOT = fadcID[islot]; /* Grab the current module's slot number */ fadcSlotMask |= (1<<FA_SLOT); /* Add it to the mask */ /* faDataInsertAdcParameters(FA_SLOT,1); */ /* faDataSuppressTriggerTime(FA_SLOT,2); */ /* Set the internal DAC level */ faSetDAC(FA_SLOT,FADC_DAC_LEVEL,0); /* Set the threshold for data readout */ faSetThreshold(FA_SLOT,FADC_THRESHOLD,0); /* Setup option 1 processing - RAW Window Data <-- */ /* option 2 - RAW Pulse Data */ /* option 3 - Integral Pulse Data */ /* Setup 200 nsec latency (PL = 50) */ /* Setup 80 nsec Window (PTW = 20) */ /* Setup Pulse widths of 36ns (NSB(3)+NSA(6) = 9) */ /* Setup up to 1 pulse processed */ /* Setup for both ADC banks(0 - all channels 0-15) */ /* Integral Pulse Data */ faSetProcMode(FA_SLOT,faMode,FADC_WINDOW_LAT,FADC_WINDOW_WIDTH,3,6,3,0); /* Bus errors to terminate block transfers (preferred) */ faEnableBusError(FA_SLOT); /* Set the Block level */ faSetBlockLevel(FA_SLOT,BLOCKLEVEL); /* Set the individual channel pedestals for the data that is sent * to the CTP */ int ichan; for(ichan=0; ichan<16; ichan++) { faSetChannelPedestal(FA_SLOT,ichan,0); } faSetTriggerPathThreshold(FA_SLOT, 500); } /************************************************************ * * Setup Internal Triggering * * Four Modes of Operation (tmode) * 0) Table Mode * 1) Coincidence Mode * 2) Window Mode * 3) INVALID * 4) Sum Mode * * wMask = Mask of 16 channels to be enabled for Window Mode * wWidth = Width of trigger window before latching (in clocks) * cMask = Mask of 16 channels to be enabled for Coincidence Mode * sumThresh = 10-12 bit threshold for Sum trigger to be latched * tTable = pointer to trigger table (65536 values) to be loaded */ int tmode=0; unsigned int wWidth=5, wMask=0x0, cMask=0xeded, sumThresh=0, tTable[65536]; memset((char *)tTable,0,65536*sizeof(unsigned int)); tTable[0xeded] = 1; faItrigSetMode(FA_SLOT, tmode, wWidth, wMask, cMask, sumThresh, (uint32_t *)tTable); faItrigSetHBwidth(0, 2, 0xffff); faGStatus(0); /* FADC Perform some resets, status */ for(islot=0;islot<NFADC;islot++) { FA_SLOT = fadcID[islot]; /* faSetClockSource(FA_SLOT,2); */ faClear(FA_SLOT); faResetToken(FA_SLOT); faResetTriggerCount(FA_SLOT); } faGStatus(0); faItrigStatus(0,0); faItrigPrintHBinfo(0); /* Enable FADC */ for(islot=0;islot<NFADC;islot++) { FA_SLOT = fadcID[islot]; faEnableSyncSrc(FA_SLOT); } faSync(0); taskDelay(1); /* faGStatus(0); */ int pti_status; void *res; pti_status = pthread_create(&fapollthread, NULL, (void*(*)(void *)) faPoll, (void *)NULL); if(pti_status!=0) { printf("%s: ERROR: FA Polling Thread could not be started.\n", __FUNCTION__); printf("\t pthread_create returned: %d\n",pti_status); } printf("Hit enter to start triggers\n"); getchar(); faGEnable(1,0); faItrigEnable(0, 1); faItrigStatus(0,0); faStopped=0; flexioWriteCsr(0, 0x101); // send first pulse printf("Hit any key to Disable TID and exit.\n"); getchar(); vmeBusLock(); /* FADC Disable */ faGDisable(1); faStopped=1; vmeBusUnlock(); if(fapollthread) { if(pthread_cancel(fapollthread)<0) perror("pthread_cancel"); if(pthread_join(fapollthread,&res)<0) perror("pthread_join"); if (res == PTHREAD_CANCELED) printf("%s: Polling thread canceled\n",__FUNCTION__); else printf("%s: ERROR: Polling thread NOT canceled\n",__FUNCTION__); } faGStatus(0); faPrintAuxScal(0); CLOSE: dmaPFreeAll(); vmeCloseDefaultWindows(); exit(0); }