Exemplo n.º 1
0
STATUS
v851SetWaveformLogic(int mode, int id)
{
  if(v851p == NULL)
  {
    printf("v851SetWaveformLogic: ERROR, v851 not initialized\n");
    return(ERROR);
  }

  if(mode<0||mode>7)
  {
    printf("v851SetWaveformLogic: ERROR, mode=%d, must be 0<=mode<=7\n",mode);
    return(ERROR);
  }

  /* set all outputs to oneshot (pulsed) mode */

  vmeWrite16(&v851p[id]->waveForm1_2,
	     V851_WF1_ONESHOT |  mode |
	     V851_WF2_ONESHOT | (mode<<4));
  vmeWrite16(&v851p[id]->waveForm3_4,
	     V851_WF3_ONESHOT |  mode |
	     V851_WF4_ONESHOT | (mode<<4));
  vmeWrite16(&v851p[id]->waveForm5_6,
	     V851_WF5_ONESHOT |  mode |
	     V851_WF6_ONESHOT | (mode<<4));

  return(OK);
}
Exemplo n.º 2
0
/*---------------------------------------------------------*/
int
v288Reset(UINT32 addr)
{
  volatile UINT16 *statreg = (volatile UINT16 *) (addr+2);
  volatile UINT16 *resetreg = (volatile UINT16 *) (addr+6);
  int i=0;
  UINT16 q=0;
#ifdef VXWORKS
  int delay=10000000;
#else
  int delay=1000000000;
#endif

  /*printf("v288Reset reached\n");*/

  while(q!=QQ && i<=11)
  {
	v288ActiveLoop(delay);
    vmeWrite16(resetreg, MEK);
    v288ActiveLoop(delay);
    q = vmeRead16(statreg);
    /*printf("q=0x%08x\n",q);*/
    i++;
  }
  if(i>11) printf("v288Reset: error: q=0x%08x, i=%d\n",q,i);
  /*else printf("v288Reset: info: q=0x%08x, i=%d\n",q,i);*/

  return((i==11) ? 11 : OK);
}
Exemplo n.º 3
0
 /* reset module at base address addr */
void
adc1182reset(int id)
{
  vmeWrite16((unsigned short *)vmeaddress[id],0x0104);

  return;
}
Exemplo n.º 4
0
STATUS
v851SetTrigLevel(short level, int id)
{
  UINT16 rlevel;

  if(v851p == NULL)
  {
    printf("v851SetTrigLevel: ERROR, v851 not initialized\n");
    return(ERROR);
  }

  /* Voltage levels should be passed in millivolts

     so  level    -2500< level <2500
   */

  if((level<-2500)||(level>2500))
  {
    printf("Trigger level (%d millivolts) out of range (-2500<level<2500)\n",level);
    return(ERROR);
  }

  if(level == 0)
  {
    rlevel = 0x8000;
  }
  else
  {
    rlevel = ((UINT16)((float)(2500-level)*13.107)) & 0xFF00;
  }

  vmeWrite16(&v851p[id]->trigLevel,rlevel);

  return(OK);
}
Exemplo n.º 5
0
STATUS
v851SetRate(int rate, int id)
{
  UINT32 rval;

  if(v851p == NULL)
  {
    printf("v851SetRate: ERROR, v851 not initialized\n");
    return(ERROR);
  }

  if((rate<1)||(rate>2500000))
  {
    printf("v851SetRate: ERROR: 1 <= rate <= %d Hz\n", 2500000);
    return(ERROR);
  }
  else
  {
    if(rate<5000) rval = (UINT32)(50000/rate);
    else          rval = (UINT32)(5000000/rate);
 }

  vmeWrite16(&v851p[id]->intRate,rval);

  return(OK);
}
Exemplo n.º 6
0
UINT16
v851Enable(int id)
{

  v851ControlReg = ~V851_CONTROL_DISARM&v851ControlReg;
  vmeWrite16(&v851p[id]->control,v851ControlReg);

  return(v851ControlReg);

}
Exemplo n.º 7
0
int
v851Init(unsigned long addr, int id)
{
  int    res;
  UINT32 boardID=0;

  if (addr == 0)
  {
    /* Use default */
    v851p[id] = (struct v851_struct *)V851_BASE_ADDR;
  }
  else if ((addr>0)&&(addr<0xffff))
  {
    /* A16 Local address - find translation */
#ifdef VXWORKS
    res = sysBusToLocalAdrs(0x29,(char *)addr,(char **)&v851p[id]);
    if (res != 0)
    {
      printf("v851Init: ERROR in sysBusToLocalAdrs(0x29,0x%x,&laddr) \n",(int)addr);
      return(ERROR);
    }
#else
    res = vmeBusToLocalAdrs(0x29,(char *)addr,(char **)&v851p[id]);
    if (res != 0)
    {
      printf("v851Init: ERROR in vmeBusToLocalAdrs(0x29,0x%x,&laddr) \n",(int)addr);
      return(ERROR);
    }
#endif
  }
  else
  {
    /* NO TRANSLATION */
    v851p[id] = (struct v851_struct *)addr;
  }

  boardID = vmeRead16(&v851p[id]->id);
#ifdef SP_DEBUG
  printf("  ModuleID = (0x%x) , address = 0x%x\n",boardID,(int)v851p[id]);
#endif

  if(boardID != V851_MODULE_ID) {
    printf("v851Init: ERROR: Invalid Module ID (0x%x) at address 0x%x\n",
	   boardID,(int)v851p[id]);
    v851p[id]=0;
    return(ERROR);
  }

  /* Initialize Control Register and readback variable */
  v851ControlReg  = V851_CONTROL_DISARM;
  vmeWrite16(&v851p[id]->control,v851ControlReg);

  return(OK);
}
Exemplo n.º 8
0
STATUS
v851SetVout(short lo, short hi, int id)
{
  UINT16 rlo=0, rhi=0;

  if(v851p == NULL)
  {
    printf("v851SetVout: ERROR, v851 not initialized\n");
    return(ERROR);
  }

  /* Voltage levels should be passed in millivolts

     so   Vlow  is negitive   -2000 <= Vlow  <= 0
     and  Vhigh is positive       0 <= Vhigh <= 5000
  */

  if((lo<-2000)||(lo>0))
  {
    printf("Vlow (%d millivolts) out of range (-2000<Vlow<0)\n",lo);
    return(ERROR);
  }

  if((hi<0)||(hi>5000))
  {
    printf("Vhigh (%d millivolts) out of range (0>Vhigh>5000\n",hi);
    return(ERROR);
  }

  rlo = ((UINT16)((float)(-lo)*32.64)) & 0xFF00;
  rhi = ((UINT16)((float)(hi)*13.056)) & 0xFF00;
#ifdef SP_DEBUG
  printf("v851SetVout: Vmin/Vmax=%d/%d -> rlo=%d(0x%04x) rhi=%d(0x%04x)\n",
    lo,hi,rlo,rlo,rhi,rhi);
#endif

  vmeWrite16(&v851p[id]->voutHigh,rhi);
  vmeWrite16(&v851p[id]->voutLow, rlo);

  return(OK);
}
Exemplo n.º 9
0
void
v851Trig(int id)
{
  if(v851VmeTrigEnable)
  {
    vmeWrite16(&v851p[id]->actions,V851_ACTION_FIRE);
  }
  else
  {
    logMsg("v851Trig: ERROR: VME Triggers not Enabled\n",0,0,0,0,0,0);
  }
}
Exemplo n.º 10
0
int
v851SetDelay(int chan, unsigned int delay, int xfr, int id)
{
  UINT32 rdelay=0;

  if(v851p == NULL)
  {
    printf("v851SetDelay: ERROR, v851 not initialized\n");
    return(ERROR);
  }

  if(delay == 0)
  {
    printf("v851SetDelay: Error: delay must be > 0\n");
    return(ERROR);
  }
  else
  {
    rdelay = (UINT32)(((float)delay*128.0)/5.0); /* delay/39.0625ps */
  }

  switch(chan)
  {
  case 1:
    vmeWrite16(&v851p[id]->delay1high,(rdelay>>16)&0xFFFF);
    vmeWrite16(&v851p[id]->delay1low,rdelay&0xFFFF);
    break;
  case 2:
    vmeWrite16(&v851p[id]->delay2high,(rdelay>>16)&0xFFFF);
    vmeWrite16(&v851p[id]->delay2low,rdelay&0xFFFF);
    break;
  case 3:
    vmeWrite16(&v851p[id]->delay3high,(rdelay>>16)&0xFFFF);
    vmeWrite16(&v851p[id]->delay3low,rdelay&0xFFFF);
    break;
  case 4:
    vmeWrite16(&v851p[id]->delay4high,(rdelay>>16)&0xFFFF);
    vmeWrite16(&v851p[id]->delay4low,rdelay&0xFFFF);
    break;
  case 5:
    vmeWrite16(&v851p[id]->delay5high,(rdelay>>16)&0xFFFF);
    vmeWrite16(&v851p[id]->delay5low,rdelay&0xFFFF);
    break;
  case 6:
    vmeWrite16(&v851p[id]->delay6high,(rdelay>>16)&0xFFFF);
    vmeWrite16(&v851p[id]->delay6low,rdelay&0xFFFF);
    break;
  default:
    printf("v851SetDelay ERROR: bad channelnumber=%d\n",chan);
  }
#ifdef SP_DEBUG
  printf("v851SetDelay: delay=%d, rdelay=%d(0x%08x), registers: high=0x%04x low=0x%04x\n",
		 delay,rdelay,rdelay,(rdelay>>16)&0xFFFF,rdelay&0xFFFF);
#endif

  /* if transfer flag set then update the delay */
  if(xfr) v851UpdateDelay(id);  

  return(0);
}
Exemplo n.º 11
0
STATUS
v851SetOneShot(int id)
{
  if(v851p == NULL)
  {
    printf("v851SetOneShot: ERROR, v851 not initialized\n");
    return(ERROR);
  }

  /* set all outputs to oneshot (pulsed) mode */

  vmeWrite16(&v851p[id]->waveForm1_2,
	     V851_WF1_ONESHOT | V851_WF1_MODE0 |
	     V851_WF2_ONESHOT | V851_WF2_MODE0);
  vmeWrite16(&v851p[id]->waveForm3_4,
	     V851_WF3_ONESHOT | V851_WF3_MODE0 |
	     V851_WF4_ONESHOT | V851_WF4_MODE0);
  vmeWrite16(&v851p[id]->waveForm5_6,
	     V851_WF5_ONESHOT | V851_WF5_MODE0 |
	     V851_WF6_ONESHOT | V851_WF6_MODE0);

  return(OK);
}
Exemplo n.º 12
0
/*---------------------------------------------------------*/
int
v288Reset(UINT32 addr)
{
  volatile UINT16 *statreg = (volatile UINT16 *) (addr+2);
  volatile UINT16 *resetreg = (volatile UINT16 *) (addr+6);
  int i=0;
  UINT16 q=0;
#ifdef VXWORKS
  int delay=10000000;
#else
  int delay=1000000000;
#endif

  /*printf("v288Reset reached\n");*/

  // NAB:  Is this 11 iterations optimized / appropriate?
  //       Why is there no delay in this loop?

  while(q!=QQ && i<=11)
  {
    v288ActiveLoop(delay);
    vmeWrite16(resetreg, MEK);
    v288ActiveLoop(delay);
    q = vmeRead16(statreg);
    /*printf("q=0x%08x\n",q);*/
    i++;
  }

  //if(i>11) printf("v288Reset: error: q=0x%08x, i=%d\n",q,i);
  /*else printf("v288Reset: info: q=0x%08x, i=%d\n",q,i);*/

  //return((i==11) ? 11 : OK);

  // NAB:
  //return((i>11) ? i : OK);
  //return i;
  
  if(i>11)
  {
    printf("v288Reset: ERROR: q=0x%08x, i=%d\n",q,i);
    return i;
  }
  else
  {
    printf("v288Reset: INFO: q=0x%08x, i=%d\n",q,i);
    return OK;
  }

}
Exemplo n.º 13
0
/*
     addr   - base address of v288 board
     offset - register offset (in bytes) we want to access:
                 0 - base reg
                 2 - stat reg
                 4 - trans reg
                 6 - reset reg
     vmedat - data to write into the register
     spas   -  parameter for delay active loop
 */
int
v288Transmit(UINT32 addr, UINT32 offset, UINT16 vmedat, int spas)
{
  volatile UINT16 *vmeaddress = (volatile UINT16 *) (addr+offset);
  volatile UINT16 *statreg = (volatile UINT16 *) (addr+2);
  int i=0;
  UINT16 q=0;

  /*printf("v288Transmit reached\n");*/

  while(q!=QQ && i<=TIMEOUT)
  {
    /*v288ActiveLoop(spas);*/
    vmeWrite16(vmeaddress, vmedat);
    /*v288ActiveLoop(spas);*/
    q = vmeRead16(statreg);
    i++;
  }
  if(i>=TIMEOUT) printf("v288Transmit: error: q=0x%08x, i=%d\n",q,i);
  /*else printf("v288Transmit: info: q=0x%08x, i=%d\n",q,i);*/

  return((i==TIMEOUT) ? TIMEOUT : OK);
}
Exemplo n.º 14
0
UINT16
v851SetMode(int mode, int option, int id)
{
  UINT32 rate, MAX_rate;

  if(v851p == NULL)
  {
    printf("v851SetMode: ERROR, v851 not initialized\n");
    return(ERROR);
  }
  
  if((mode==0)||(mode>3))
  {
    printf("Usage: v851SetMode  <mode>, [option], [id]\n");
    printf("    mode = 1  External Triggers\n");
    printf("      option = 0/1 negative/positive edge input\n");
    printf("\n");
    printf("    mode = 2  Internal Triggers (Pulser)\n");
    printf("      option = rate(Hz) (1Hz - %dHz)\n", 2500000);
    printf("\n");
    printf("    mode = 3  VME Triggers\n");
    printf("      option flag ignored (use v851Trig(id) to trigger)\n");
    return(0);
  }

  switch(mode)
  {
  case 1:
    if(option!=0)
    {
      v851ControlReg = V851_CONTROL_DISARM;
    }
    else
    {
      v851ControlReg = V851_CONTROL_DISARM | V851_CONTROL_SLOPE;
    }
    vmeWrite16(&v851p[id]->control,v851ControlReg);
    v851VmeTrigEnable = 0;
    break;
  case 2:

    if(option<5000) MAX_rate = 50000;
    else            MAX_rate = 5000000;

    printf("v851SetMode:  MAX_rate = %d,  rate= %d Hz \n", MAX_rate, option);

    if((option<=0)||(option>2500000))
      rate = MAX_rate; /* Set to 1 Hz */
    else
      rate = (UINT32)(MAX_rate/option);

    if(MAX_rate == 50000)
      v851ControlReg = V851_CONTROL_DISARM | V851_CONTROL_ITRIG |
	               V851_CONTROL_PRESCALE | V851_CONTROL_LOAD;
    else
      v851ControlReg = V851_CONTROL_DISARM | V851_CONTROL_ITRIG |
                       V851_CONTROL_LOAD;

    vmeWrite16(&v851p[id]->intRate,rate);
    vmeWrite16(&v851p[id]->control,v851ControlReg);
    v851VmeTrigEnable = 0;
    break;
  case 3:
    v851ControlReg = V851_CONTROL_DISARM | V851_CONTROL_VTRIG;
    vmeWrite16(&v851p[id]->control,v851ControlReg);
    v851VmeTrigEnable = 1;
  }

  return(v851ControlReg);
}
Exemplo n.º 15
0
void
v851UpdateDelay(int id)
{
  vmeWrite16(&v851p[id]->actions,(V851_ACTION_XFR | V851_ACTION_FEOD));
}