コード例 #1
0
int CrateMsg_Read32(CrateMsgStruct *msg, int swap)
{
	if(swap)
	{
		msg->msg.m_Cmd_Read32.cnt = LSWAP(msg->msg.m_Cmd_Read32.cnt);
		msg->msg.m_Cmd_Read32.addr = LSWAP(msg->msg.m_Cmd_Read32.addr);
		msg->msg.m_Cmd_Read32.flags = LSWAP(msg->msg.m_Cmd_Read32.flags);
	}
	if(gServerCBFucntions.Read32)
		return (*gServerCBFucntions.Read32)(&msg->msg.m_Cmd_Read32, &msg->msg.m_Cmd_Read32_Rsp);
	
	return 0;
}
コード例 #2
0
ファイル: tdc1190_list.c プロジェクト: JeffersonLab/caen1190
void
rocTrigger(int arg)
{
  int ii, status, dma, count;
  int nwords;
  unsigned int datascan;

  tirIntOutput(2);

  *dma_dabufp++ = LSWAP(tirGetIntCount()); /* Insert Event Number */

  /* Check for valid data here */
  for(ii=0;ii<100;ii++) 
    {
      datascan = tdc1190Dready(0);
      if (datascan>0) 
	{
	  break;
	}
    }

  if(datascan>0) 
    {
      /* Get the TDC data from all modules... rflag=2 for Linked List DMA 
	 "64" is ignored in Linux */
      nwords = tdc1190ReadBlock(0,dma_dabufp,64,2);
    
      if(nwords < 0) 
	{
	  printf("ERROR: in transfer (event = %d), status = 0x%x\n", tirGetIntCount(),nwords);
	  *dma_dabufp++ = LSWAP(0xda000bad);
	} 
      else 
	{
	  dma_dabufp += nwords;
	}
    } 
  else 
    {
      printf("ERROR: Data not ready in event %d\n",tirGetIntCount());
      *dma_dabufp++ = LSWAP(0xda000bad);
    }

  *dma_dabufp++ = LSWAP(0xd00dd00d); /* Event EOB */

  tirIntOutput(0);
}
コード例 #3
0
int CrateMsg_Delay(CrateMsgStruct *msg, int swap)
{
	if(swap)
		msg->msg.m_Cmd_Delay.ms = LSWAP(msg->msg.m_Cmd_Delay.ms);
	if(gServerCBFucntions.Delay)
		(*gServerCBFucntions.Delay)(&msg->msg.m_Cmd_Delay);
	
	return 0;
}
コード例 #4
0
int CrateMsg_Write32(CrateMsgStruct *msg, int swap)
{
	int i;
	
	if(swap)
	{
		msg->msg.m_Cmd_Write32.cnt = LSWAP(msg->msg.m_Cmd_Write32.cnt);
		msg->msg.m_Cmd_Write32.addr = LSWAP(msg->msg.m_Cmd_Write32.addr);
		msg->msg.m_Cmd_Write32.flags = LSWAP(msg->msg.m_Cmd_Write32.flags);
		
		for(i = msg->msg.m_Cmd_Write32.cnt-1; i >= 0; i--)
			msg->msg.m_Cmd_Write32.vals[i] = LSWAP(msg->msg.m_Cmd_Write32.vals[i]);
	}
	if(gServerCBFucntions.Write32)
		(*gServerCBFucntions.Write32)(&msg->msg.m_Cmd_Write32);
	
	return 0;
}
コード例 #5
0
ファイル: ts_list.c プロジェクト: JeffersonLab/tsUtil
void
rocTrigger(int arg)
{
  int ii, status, dma, count;
  int nwords;
  unsigned int datascan, tirval, vme_addr;
  int length,size;

  *dma_dabufp++ = LSWAP(tsGetIntCount()); /* Insert Event Number */

  /* Insert some data here */
  for(ii=0; ii<20; ii++) 
    {
      *dma_dabufp++ = LSWAP(ii);
    }

  *dma_dabufp++ = LSWAP(0xd00dd00d); /* Event EOB */

}
コード例 #6
0
ファイル: tsPartTest.c プロジェクト: JeffersonLab/ts
/* Interrupt Service routine */
void
mytsISR(int arg)
{
  volatile unsigned short reg;
  int dCnt, len=0,idata;
  DMANODE *outEvent;
  int tsbready=0, timeout=0;
  int prescale=1;

  unsigned int tsIntCount = tsGetIntCount();

/*   tsPrintScalers(1); */
/*   printf(" tsIntCount = %d\n", tsIntCount); */
/*   tsPrintScalers(2); */
/*   tsPrintScalers(3); */

  GETEVENT(vmeIN,tsIntCount);

  dCnt = tsPartReadBlock(dma_dabufp,900>>2);
  if(dCnt<=0)
    {
      printf("No data or error.  dCnt = %d\n",dCnt);
    }
  else
    {
      dma_dabufp += dCnt;
/*       printf("dCnt = %d\n",dCnt); */
    
    }
  PUTEVENT(vmeOUT);
  
  outEvent = dmaPGetItem(vmeOUT);
#define READOUT
#ifdef READOUT
  if(tsIntCount%prescale==0)
    {
      printf("Received %d triggers...\n",
	     tsIntCount);

      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]));
	}
      printf("\n\n");
    }
#endif
  dmaPFreeItem(outEvent);
/*   tsStatus(); */
/*   sleep(1); */
}
コード例 #7
0
ファイル: tidprimary_list.c プロジェクト: camsonne/mpd-intel
void usrtrig(unsigned long EVTYPE,unsigned long EVSOURCE)
{
  long EVENT_LENGTH;
  int ii, len, data, type=0, lock_key;
  int syncFlag=0, lateFail=0;
  unsigned int event_number=0;
  DMANODE *outEvent;

  outEvent = dmaPGetItem(vmeOUT);
  if(outEvent != NULL) 
    {
      len = outEvent->length;
      type = outEvent->type;
      event_number = outEvent->nevent;

      CEOPEN(type, BT_UI4);

      if(rol->dabufp != NULL) 
	{
	  for(ii=0;ii<len;ii++) 
	    {
	      *rol->dabufp++ = LSWAP(outEvent->data[ii]);
	    }
	}
      else 
	{
	  printf("tidprimary_list: ERROR rol->dabufp is NULL -- Event lost\n");
	}

      /* Execute the doAck routine after freeing up the buffer.
	 This allows for an Acknowledge to be sent back to the TI Master,
	 if it is needed */
      outEvent->part->free_cmd = *doAck;

      CECLOSE;
      dmaPFreeItem(outEvent); /* IntAck performed in here, if NeedAck */
    }
  else
    {
      logMsg("Error: no Event in vmeOUT queue\n",0,0,0,0,0,0);
    }
  
  
  
} /*end trigger */
コード例 #8
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;
	  }
コード例 #9
0
data_counts
vscmParseFIFO(DMANODE* event, FILE *f)
{
  int i, n = event->length;
  long long trig1 = 0, trigtime = 0;
  data_counts cnt = {0, {0,0,0,0,0,0,0,0}};

  for(i = 0; i < n; i++) {
    uint32_t word = LSWAP(event->data[i]);
#ifdef DEBUG
    printf("0x%08X - ", word);
#endif
  
    if(word & 0x80000000) {
      int type = (word >> 27) & 0xF;
      switch(type) {
        case DATA_TYPE_BLKHDR:
#ifdef DEBUG
          printf(" {BLKHDR} SLOTID: %d", (word>>22)&0x1f);
          printf(" NEVENTS: %d", (word>>11)&0x7ff);
          printf(" BLOCK: %d\n", (word>>0)&0x7ff);
#endif
          break;
        case DATA_TYPE_BLKTLR:
#ifdef DEBUG
          printf(" {BLKTLR} SLOTID: %d", (word>>22)&0x1f);
          printf(" NWORDS: %d\n", (word>>0)&0x3fffff);
#endif
          break;
        case DATA_TYPE_EVTHDR:
/*
          if(((word & 0x7ffffff) % 100000) == 0)
            printf("Event: %d\n", word & 0x7ffffff);
*/
#ifdef DEBUG
          printf(" {EVTHDR} EVENT: %d\n", (word>>0)&0x7ffffff);
#endif
          break;
        case DATA_TYPE_TRGTIME:
          cnt.triggers++;
          trig1 = word & 0xffffff;
#ifdef DEBUG
          printf(" {TRGTIME1} %lld\n", trig1);
#endif
          break;
        case DATA_TYPE_BCOTIME:
/*
          if(f) 
            fprintf(f, "* %d, %d\n", (word & 0xff), (word >> 16) & 0xff);
*/
#ifdef DEBUG
          printf(" {BCOTIME}  %d, %d\n", (word & 0xff), (word >> 16) & 0xff); 
#endif
          break;
        case DATA_TYPE_FSSREVT:
          if(f) {
            fprintf(f, "%u, %u, %u, %u, %u\n",
                  (word>>22) & 1, (word>>19) & 7, (word>>12) & 0x7f,
                  (word>>4) & 0xff, word & 7);
          }
          cnt.adc[(word & 0x7)]++;
#ifdef DEBUG
          printf(" {FSSREVT}");
          printf(" HFCB: %1u", (word>>22)&1);
          printf(" CHIPID: %1u", (word>>19)&0x7);
          printf(" CH: %3u", (word>>12)&0x7F);
          printf(" BCO: %3u", (word>>4)&0xFF);
          printf(" ADC: %1u\n", (word>>0)&0x7);
#endif
          break;
        case DATA_TYPE_DNV:
#ifdef DEBUG
          printf(" {***DNV***}\n");
#endif
          break;
        case DATA_TYPE_FILLER:
#ifdef DEBUG
          printf(" {FILLER}\n");
#endif
          break;
        default:
#ifdef DEBUG
          printf(" {***DATATYPE ERROR***}\n");
#endif
          break;
      }
    }
    else {
コード例 #10
0
int
BOSrecordSwap(unsigned int *src, unsigned int *dest)
{
  unsigned int lwd;
  unsigned short swd;
  int ii, jj, ix, k;
  int hlen, tlen, blen, dlen, lform, dtype, typ;
  short shd;
  char cd;
  char *cp;
  unsigned short *sp, *spd;
  unsigned int *lp, *lpd;
  unsigned int bankid, banknum, ncol, nrow, lname, lfmt, fmtlen, nwords, bb;
  char *form;
  int nevent;

  /* if 'dest' == NULL, swap 'src' buffer in place */
  if(dest == NULL)
  {
    dest = src;
  }
  /*printf("src=0x%08x dest=0x%08x\n",src,dest);*/

  ii = 0;
  lp = (unsigned int *)&src[ii];
  lpd = (unsigned int *)&dest[ii];

  blen = *(lp+RECHEADLEN-1); /* last word in record header */

  /*
printf("\n\n\nFPACK record length = %d\n",blen);
  */

  /*
printf("3rd: 0x%08x %d\n",lp[2],lp[2]);
lp[2] = 0;
  */

  /* swap record header: RECHEADLEN words */
  for(jj=0; jj<RECHEADLEN; jj++)
  {
	/*
if(jj==5) printf("befor %d 0x%08x\n",*lp,*lp);
	*/
    /* do not swap record name */
    if((jj==3) || (jj==4))
    {
      *lpd++ = *lp;
      lp++;
      continue;
    }

	lwd = LSWAP(*lp);

    /* set endian signature (or automatically ???) */
    if(jj==1)
    {
#if defined(Linux) || defined(SunOS_i86pc)
      lwd = 1*16 + 8;
#else
      lwd = 4*16 + 8;
#endif
      lwd = LSWAP(lwd);
    }

	*lpd++ = lwd;
    lp++;
	/*
if(jj==5) printf("after %d 0x%08x\n",lwd,lwd);
	*/

  }

  ii += RECHEADLEN;



  /*********************************/
  /* loop over all banks in record */

  lp = (unsigned int *)&src[ii];
  lpd = (unsigned int *)&dest[ii];
  bb = 0;

  while(bb < blen)
  {

    hlen = *lp;            /* record header length (words) */
    dlen = *(lp+8);        /* data length (words) */
    lname = *(lp+1);       /* bank name */
    lform = *(lp+9);       /* first word of format string */
    form = (char *)(lp+9); /* remember the position of format description */


#ifdef SunOS_sun4u
	/*Sergey: temporary !!!*/
    if(lform==B16TAG0)
	{
      /*printf("WARN: B16TAG0 correction: befor >%4.4s<, ",form);*/
      lform = *(lp+9) = B16TAG;
      /*printf("after >%4.4s< (bank >%4.4s<) (nev=%d)\n",form,(char *)&lname,nevent);*/
	}
    if(lform==B32TAG0)
	{
	  /*printf("WARN: B32TAG0 correction: befor >%4.4s<, ",form);*/
      lform = *(lp+9) = B32TAG;
      /*printf("after >%4.4s< (bank >%4.4s<)\n",form,(char *)&lname);*/
	}
#endif


/*
printf("\nBANK record length=%d, header length=%d, name >%4.4s",
    dlen,hlen,&lname);
*/
	
/*if(blen==1406)*/
/*
{
  char *ffff = form;
  printf("\nBANK record length=%d, header length=%d, name >%4.4s<, format >",
    dlen,hlen,&lname);
  for(jj=0; jj<(hlen-9); jj++)
  {
    printf("%4.4s",ffff);
    ffff += 4;
  }
  printf("<\n");
}
*/

    /* swap BOS bank header; header length is 'hlen' but we will swap 9 first words
    only, excluding second and third which are bank name; words starting from 10th
    are format description and they should not be swapped as well */

    *lpd++ = LSWAP(*lp); lp++; /* swap first word */
    *lpd++ = *lp++;            /* copy second word (bank name) */
    *lpd++ = *lp++;            /* copy third word (bank name) */
    *lpd++ = LSWAP(*lp); lp++;
    *lpd++ = LSWAP(*lp); lp++;
    *lpd++ = LSWAP(*lp); lp++;
    *lpd++ = LSWAP(*lp); lp++;
    *lpd++ = LSWAP(*lp); lp++;
    *lpd++ = LSWAP(*lp); lp++;
    for(jj=9; jj<hlen; jj++) *lpd++ = *lp++; /* copy format description */
    bb += hlen;


    if(lform==B16TAG) /* short (look for 'B16 ')*/
	{
	  /*printf("B16 >%4.4s< (0x%08x)\n",form,lform);*/
      sp = (unsigned short *)lp;
      spd = (unsigned short *)lpd;
      for(jj=0; jj<dlen*2; jj++) {*spd++ = SSWAP(*sp); sp++;}
      lp += dlen;
      lpd += dlen;
    }
    else if(!strncmp(form,"(A)",3))
    {
      /*printf("format >%3.3s<\n",form);*/
      for(jj=0; jj<dlen; jj++) *lpd++ = *lp++;
    }
    else if(!strncmp(form,"(F,8A)",6))
    {
      /*printf("format >%6.6s< dlen=%d\n",form,dlen);*/
      for(jj=0; jj<dlen; jj+=9)
      {
        /*printf("value=%f\n",*((float *)lp));*/
        {*lpd++ = LSWAP(*lp); lp++;}
        for(k=0; k<8; k++) *lpd++ = *lp++;
	  }
    }
    else if(lform == B32TAG) /* int (look for 'B32 ')*/
    {
      for(jj=0; jj<dlen; jj++) {*lpd++ = LSWAP(*lp); lp++;}
    }
    else if( (!strncmp(form,"I",1)) || (!strncmp(form,"(I)",3)) )
    {
      if(!strncmp((char *)&lname,"HEAD",4))
      {
        nevent=lp[2];
        /*printf("nev=%d\n",nevent);*/
	  }
      for(jj=0; jj<dlen; jj++) {*lpd++ = LSWAP(*lp); lp++;}
    }
    else if( (!strncmp(form,"F",1)) || (!strncmp(form,"(F)",3)) )
    {
      for(jj=0; jj<dlen; jj++) {*lpd++ = LSWAP(*lp); lp++;}
    }
    else if( (!strncmp(form,"A",1)) || (!strncmp(form,"(A)",3)) ) /* ????? */
    {
      for(jj=0; jj<dlen; jj++) {*lpd++ = LSWAP(*lp); lp++;}
    }

    /* some special cases - until we have generic algorithm */
    else if( (!strncmp(form,"3I,6F",5)) )
    {
      for(jj=0; jj<dlen; jj++) {*lpd++ = LSWAP(*lp); lp++;}
    }

    else
    {
	  printf("ERROR: unsupported format >");
      for(jj=0; jj<hlen; jj++) printf("%c",form[jj]);
	  printf("< - copy 'as is'\n");

      for(jj=0; jj<dlen; jj++) {*lpd++ = *lp; lp++;}
	}

    bb += dlen;
  }

  return(0);
}
コード例 #11
0
ファイル: trig1.c プロジェクト: JeffersonLab/clas12-coda
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;
}
コード例 #12
0
ファイル: vfTDCLibTest.c プロジェクト: JeffersonLab/vfTDC
/* 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());                       
    }                                                                           
 
}
コード例 #13
0
void *ConnectionThread(void *parm)
{
	int swap, result, val;
	SocketThreadStruct *pParm = (SocketThreadStruct *)parm;

	val = CRATEMSG_HDR_ID;
	if(send(pParm->sock, &val, 4, 0) <= 0) 
	{
		printf("Error in %s: failed to send HDRID\n", __FUNCTION__);
		goto ConnectionThread_exit;
	}
	
	if(recv(pParm->sock, &val, 4, 0) != 4)
	{
		printf("Error in %s: failed to recv HDRID\n", __FUNCTION__);
		goto ConnectionThread_exit;
	}

	// determine sender endianess...
	if(val == CRATEMSG_HDR_ID)
	{
		printf("swap=0\n");
		swap = 0;
	}
	else if(val == LSWAP(CRATEMSG_HDR_ID))
	{
		printf("swap=1\n");
		swap = 1;
	}
	else
	{
		printf("Error in %s: bad recv HDRID\n", __FUNCTION__);
		goto ConnectionThread_exit;
	}
	
	while(1)
	{
		if(recv(pParm->sock, (char *)&pParm->msg, 8, 0) != 8)
			break;
		
		if(swap)
		{
			pParm->msg.len = LSWAP(pParm->msg.len);
			pParm->msg.type = LSWAP(pParm->msg.type);
		}
		
		if( (pParm->msg.len > MAX_MSG_SIZE) || (pParm->msg.len < 0) )
			break;
		
		if(pParm->msg.len && (recv(pParm->sock, (char *)&pParm->msg.msg, pParm->msg.len, 0) != pParm->msg.len))
			break;
		
		result = -1;	
		if(pParm->msg.type == CRATEMSG_TYPE_READ16)
			result = CrateMsg_Read16(&pParm->msg, swap);
		else if(pParm->msg.type == CRATEMSG_TYPE_WRITE16)
			result = CrateMsg_Write16(&pParm->msg, swap);
		else if(pParm->msg.type == CRATEMSG_TYPE_READ32)
			result = CrateMsg_Read32(&pParm->msg, swap);
		else if(pParm->msg.type == CRATEMSG_TYPE_WRITE32)
			result = CrateMsg_Write32(&pParm->msg, swap);
		else if(pParm->msg.type == CRATEMSG_TYPE_DELAY)
			result = CrateMsg_Delay(&pParm->msg, swap);
		else if(pParm->msg.type == CRATEMSG_TYPE_READSCALERS)
			result = CrateMsg_ReadScalers(&pParm->msg, swap);
		else
		{
			printf("Error in %s: unhandled message type %u\n", __FUNCTION__, pParm->msg.type);
			break;
		}
		
		if(result < 0)
		{
			printf("Error in %s: failed to process msg type %u\n", __FUNCTION__, pParm->msg.type);
			break;
		}
		else if(result > 0)
		{
			pParm->msg.len = result;
			pParm->msg.type = CMD_RSP(pParm->msg.type);
			if(send(pParm->sock, &pParm->msg, pParm->msg.len+8, 0) <= 0) 
			{
				printf("Error in %s: failed to send msg type %u\n", __FUNCTION__, pParm->msg.type);
				break;
			}
		}
	}
	
ConnectionThread_exit:
	printf("Closing connection...\n");
	
	close(pParm->sock);
	free(pParm);
	
	pthread_exit(NULL);
	
	return 0;
}
コード例 #14
0
ファイル: vendor.c プロジェクト: ChakaZulu/tuxbox_boot
 */
struct _FileDownHeader file_header;
struct _IO_REQUEST iorequest;

/*
 * currently not using...
 */
struct _vendor_header vh =
{
	SWAP(1),
	SWAP(VENDOR_DESC_LEN)
};

struct _vendor_desc vd =
{
	LSWAP(1),
	LSWAP(2),
	LSWAP(3)
};

void get_vendor_descript( void )
{
	unsigned char *buf;

	buf = upg_buffer;

	memcpy( &buf[0], &vh, sizeof(struct _vendor_header) );
	memcpy( &buf[sizeof(struct _vendor_header)], &vd, sizeof(struct _vendor_desc) );

	code_transmit( buf, VENDOR_DESC_LEN );
}
コード例 #15
0
ファイル: faInternalTrig.c プロジェクト: JeffersonLab/fadc
/* Interrupt Service routine */
void
myISR(int arg)
{
  volatile unsigned short reg;
  int dCnt, len=0,idata;
  DMANODE *outEvent;
  int tibready=0, timeout=0;
  int printout = 1;
  int iev=0;

  unsigned int tiIntCount = arg;

  GETEVENT(vmeIN,tiIntCount);

    /* Readout FADC */
  if(NFADC!=0)
    {
      FA_SLOT = fadcID[0];
      int itime=0, stat=0, roflag=1, islot=0;
      unsigned int gbready=0;
/*       for(itime=0;itime<10000;itime++)  */
/* 	{ */
/* 	  gbready = faGBready(); */
/* 	  stat = (gbready == fadcSlotMask); */
/* 	  if (stat>0)  */
/* 	    { */
/* 	      break; */
/* 	    } */
/* 	} */
/*       if(stat>0)  */
	{
	  if(NFADC>1) roflag=2; /* Use token passing scheme to readout all modules */
	  dCnt = faReadBlock(FA_SLOT,dma_dabufp,MAXFADCWORDS,roflag);
	  if(dCnt<=0)
	    {
	      printf("FADC%d: No data or error.  dCnt = %d\n",FA_SLOT,dCnt);
	    }
	  else
	    {
	      if(dCnt>MAXFADCWORDS)
		{
		  printf("%s: WARNING.. faReadBlock returned dCnt >= MAXFADCWORDS (%d >= %d)\n",
			 __FUNCTION__,dCnt, MAXFADCWORDS);
		}
	      else 
		dma_dabufp += dCnt;
	    }
	} 
/*       else  */
/* 	{ */
/* 	  printf ("FADC%d: no events   stat=%d  intcount = %d   gbready = 0x%08x  fadcSlotMask = 0x%08x\n", */
/* 		  FA_SLOT,stat,tiIntCount,gbready,fadcSlotMask); */
/* 	} */

      /* Reset the Token */
      if(roflag==2)
	{
	  for(islot=0; islot<NFADC; islot++)
	    {
	      FA_SLOT = fadcID[islot];
	      faResetToken(FA_SLOT);
	    }
	}
    }

  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++)
	{
	  faDataDecode(LSWAP(outEvent->data[idata]));
	}
      printf("\n\n");
    }
#endif
  dmaPFreeItem(outEvent);

  if(tiIntCount%printout==0)
    printf("intCount = %d\n",tiIntCount );

  /* Pulse flex io for next event */
  flexioWriteCsr(0, 0x101);


}
コード例 #16
0
ファイル: vme_list.c プロジェクト: JeffersonLab/vmeDSC
void
rocTrigger(int arg)
{
  int ii, status, dma, count;
  int nwords;
  unsigned int datascan, tirval, vme_addr;
  int length,size;
  unsigned long long time0, time1, time2, time3;

  tirIntOutput(1); /* Stop the gate to vmeDSC */

  tirval = tirIntType();

  *dma_dabufp++ = LSWAP(0xffdaf000); /* TI data header */
  *dma_dabufp++ = LSWAP(tirval);

  /* Check for valid data here */
  for(ii=0;ii<100;ii++) 
    {
      datascan = tdc1190Dready(0);
      if (datascan>0) 
	{
	  break;
	}
    }

  if(datascan>0) 
    {
      /* Get the TDC data from all modules... rflag=2 for Linked List DMA 
	 "64" is ignored in Linux */
      time0 = rdtsc();
      nwords = tdc1190ReadBlock(0,dma_dabufp,64,1);
      time1 = rdtsc();
    
      if(nwords < 0) 
	{
	  printf("ERROR: in transfer (event = %d), status = 0x%x\n", tirGetIntCount(),nwords);
	  *dma_dabufp++ = LSWAP(0xda000bad);
	} 
      else 
	{
	  dma_dabufp += nwords;
	}
    } 
  else 
    {
      printf("ERROR: Data not ready in event %d\n",tirGetIntCount());
      *dma_dabufp++ = LSWAP(0xda000bad);
    }

  for(ii=0; ii<1000; ii++)
    {
      tirval=tirIntType();
    }

  time2 = rdtsc();

  for(ii=0; ii<1000; ii++)
    {
      tirIntOutput(1); /* Stop the gate to vmeDSC */
    }

  time3 = rdtsc();

  /* Insert some data here */
  dscLatchScalers(0,2); /* latch both scalers */
  nwords = dscReadScalers(0,dma_dabufp,20,DSC_READOUT_TRGVME|DSC_READOUT_REF|DSC_READOUT_REFVME);
  dma_dabufp+=nwords;

  *dma_dabufp++ = LSWAP(0xcebaf009);
  *dma_dabufp++ = LSWAP((unsigned int)(time1-time0));
  *dma_dabufp++ = LSWAP((unsigned int)(time2-time1));
  *dma_dabufp++ = LSWAP((unsigned int)(time3-time2));
  *dma_dabufp++ = LSWAP((unsigned int)(dma_timer[0]-time0));
  *dma_dabufp++ = LSWAP((unsigned int)(dma_timer[1]-time0));
  *dma_dabufp++ = LSWAP((unsigned int)(dma_timer[2]-time0));
  *dma_dabufp++ = LSWAP((unsigned int)(dma_timer[3]-time0));
  *dma_dabufp++ = LSWAP((unsigned int)(dma_timer[4]-time0));
  *dma_dabufp++ = LSWAP((unsigned int)(dma_timer[5]-time0));

  *dma_dabufp++ = LSWAP(0xda0000ff);

/*   for(ii=0;ii<2000;ii++) */
/*     { */
/*       *dma_dabufp++ = LSWAP(0xda000000+ii); */
/*     } */

  tirIntOutput(0); 
}