Example #1
0
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;
}
Example #2
0
/* Interrupt Service routine */
void
mytiISR(int arg)
{
  volatile unsigned short reg;
  int dCnt, len=0,idata;
  DMANODE *outEvent;
  int blkReady=0, timeout=0;
  int printout = 1;

  unsigned int tiIntCount = tiGetIntCount();

#ifdef DO_READOUT
  GETEVENT(vmeIN,tiIntCount);

#ifdef DOINT
  blkReady = tiBReady();
  if(blkReady==ERROR)
    {
      printf("%s: ERROR: tiIntPoll returned ERROR.\n",__FUNCTION__);
      return;
    }

  if(blkReady==0 && timeout<100)
    {
      printf("NOT READY!\n");
      blkReady=tiBReady();
      timeout++;
    }

  if(timeout>=100)
    {
      printf("TIMEOUT!\n");
      return;
    }
#endif

/*   dCnt = tiReadBlock(dma_dabufp,3*BLOCKLEVEL+10,1); */
  dCnt = tiReadTriggerBlock(dma_dabufp);
  if(dCnt<=0)
    {
      printf("No data or error.  dCnt = %d\n",dCnt);
    }
  else
    {
      tiCheckTriggerBlock(dma_dabufp);
/*       dma_dabufp += dCnt; */
      /*       printf("dCnt = %d\n",dCnt); */
    
    }

  timeout=0;
  blkReady = vfTDCBReady(0);
  if(blkReady==0 && timeout<100)
    {
      printf("NOT READY!\n");
      blkReady = vfTDCBReady(0);
      timeout++;
    }

  if(timeout>=100)
    {
      printf("TIMEOUT!\n");
      return;
    }

  dCnt = vfTDCReadBlock(0,dma_dabufp,BLOCKLEVEL*(10*192+10),1);
  if(dCnt<=0)
    {
      printf("No data or error.  dCnt = %d\n",dCnt);
    }
  else
    {
      dma_dabufp += dCnt;
    }



  PUTEVENT(vmeOUT);

  outEvent = dmaPGetItem(vmeOUT);
#define READOUT
#ifdef READOUT
  if(tiIntCount%printout==0)
    {
      printf("Received %d triggers...\n",
	     tiIntCount);

      len = outEvent->length;
      
      for(idata=0;idata<len;idata++)
	{
/* 	  if((idata%5)==0) printf("\n\t"); */
/* 	  printf("  0x%08x ",(unsigned int)LSWAP(outEvent->data[idata])); */
	  vfTDCDataDecode(LSWAP(outEvent->data[idata]));
	}
      printf("\n\n");
    }
#endif
  dmaPFreeItem(outEvent);
#else /* DO_READOUT */
  /*   tiResetBlockReadout(); */

#endif /* DO_READOUT */
  if(tiIntCount%printout==0)
    printf("intCount = %d\n",tiIntCount );
/*     sleep(1); */

  static int bl = BLOCKLEVEL;
  if(tiGetSyncEventFlag())                                                      
    {                                                                           
/*       tiSetBlockLevel(bl++);                                               */
      printf("SE: Curr BL = %d\n",tiGetCurrentBlockLevel());                    
      printf("SE: Next BL = %d\n",tiGetNextBlockLevel());                       
    }                                                                           
 
}