int main(int argc, char *argv[]) { int res; char myname[256]; unsigned int addr, laddr; int iflag, ntd, slot = 0; /* printf("\n"); if(argc==2||argc==3) { strncpy(myname, argv[1], 255); printf("Use argument >%s< as bin file name\n",myname); if(argc==3) { slot = atoi(argv[2]); printf("Upgrade board at slot=%d only\n",slot); } else { slot = 0; printf("Upgrade all boards in crate\n"); } } else { printf("Usage: dsc2init <bin file> [slot]\n"); exit(0); } printf("\n"); */ /* Open the default VME windows */ vmeOpenDefaultWindows(); printf("\n"); ntd = 0; iflag = 1; tdInit((3<<19),0x80000,20,iflag); ntd = tdGetNtds(); /* actual number of TD boards found */ tdGStatus(0); exit(0); }
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; #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 TI board */ #ifdef VXWORKS CDOINIT(TSPRIMARY); #else CDOINIT(TSPRIMARY,TIR_SOURCE); #endif /************/ /* init daq */ daqInit(); DAQ_READ_CONF_FILE; /*************************************/ /* redefine TS settings if neseccary */ /* 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()); tdGStatus(0); /*************************************** * SD SETUP ***************************************/ vmeBusLock(); sdInit(1); /* Initialize the SD library */ sdSetActiveVmeSlots(tdslotmask); /* Use the tdslotmask to configure the SD */ sdStatus(); vmeBusUnlock(); /* 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); }