Beispiel #1
0
/* init: just calculate address offset */
int
adc1182init(unsigned int *addr, int nboards)
{
  int ii, res;
  unsigned int laddr;

  n1182 = 0;
  for(ii=0; ii<nboards; ii++)
  {
#ifdef VXWORKS
    res = sysBusToLocalAdrs(0x39,(char *)addr[ii],(char **)&laddr);
    if(res != 0) 
	{
	  printf("adc1182init: ERROR in sysBusToLocalAdrs(0x39,0x%x,&laddr) \n",addr[ii]);
	  return(ERROR);
	}
#else
    res = vmeBusToLocalAdrs(0x39,(char *)addr[ii],(char **)&laddr);
    if (res != 0) 
	{
	  printf("adc1182init: ERROR in vmeBusToLocalAdrs(0x39,0x%x,&laddr) \n",addr[ii]);
	  return(ERROR);
	}
#endif
    printf("ADC1182 board %d at vme address 0x%08x\n",n1182,(unsigned int)laddr);
    vmeaddress[n1182++] = (unsigned int)laddr;
  }

  return(n1182);
}
Beispiel #2
0
/* input: SystemName - name we assigned to mainframe (arbitrary)
          LinkType - LINKTYPE_CAENET for sy527
          Arg - sy527_VMEADDRESS_CRATE#
          UserName - irrelevant here
          Passwd - irrelevant here
 */
int
CAENHVInitSystem(const char *SystemName, int LinkType, void *Arg,
                 const char *UserName, const char *Passwd)
{
  int i, addr;
  char arg1[256], arg2[256], arg3[256];
  char *ch1, *ch2;

  if(LinkType != LINKTYPE_CAENET) return(CAENHV_SYSERR);

  /* search for empty slot */
  for(i=0; i<MAX_HVPS; i++)
  {
    if(sy527[i].vmeaddr == 0) /* empty, will use it */
	{
      sy527[i].id = i;
      strcpy(sy527[i].name,SystemName);

      ch1 = (char *)Arg;
      ch2 = arg1;
      while(*ch1 != '_') *ch2++ = *ch1++;
      *ch2 = '\0';

      ch1++;
      ch2 = arg2;
      while(*ch1 != '_') *ch2++ = *ch1++;
      *ch2 = '\0';

      ch1++;
      ch2 = arg3;
      while(*ch1 != '\0') *ch2++ = *ch1++;
      *ch2 = '\0';

      /*printf("CAENHVInitSystem: arg's    -> >%s< >%s< >%s<\n",arg1,arg2,arg3);*/

      strcpy(sy527[i].type,arg1);

      addr = strtol(arg2, (char **)NULL, 0); /*0x7fffffff max!!??*/
#ifdef VXWORKS
      sysBusToLocalAdrs(0x39, addr, (char **)&sy527[i].vmeaddr);
#else
      vmeBusToLocalAdrs(0x39, addr, (char **)&sy527[i].vmeaddr);
#endif
      sy527[i].CrNum = strtol(arg3, (char **)NULL, 0);
	  /*
      printf("CAENHVInitSystem: decode's -> >%s< 0x%08x %d\n",
        sy527[i].type,sy527[i].vmeaddr,sy527[i].CrNum);
	  */
      return(CAENHV_OK);
	}
  }

  return(CAENHV_SYSERR); /* no empty slots */
}
Beispiel #3
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);
}
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 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;
}
Beispiel #7
0
STATUS 
c792Init (UINT32 addr, UINT32 addr_inc, int nadc, UINT16 crateID)
{
  int ii, res, rdata, errFlag = 0;
  int boardID = 0;
  unsigned long laddr, lladdr;
  volatile struct c792_ROM_struct *rp;

  
  /* Check for valid address */
  if(addr==0) {
    printf("c792Init: ERROR: Must specify a Bus (VME-based A32/A24) address for QDC 0\n");
    return(ERROR);
  }else if(addr < 0x00ffffff) { /* A24 Addressing */
    if((addr_inc==0)||(nadc==0))
      nadc = 1; /* assume only one QDC to initialize */

    /* get the QDCs address */
#ifdef VXWORKS
    res = sysBusToLocalAdrs(0x39,(char *)addr,(char **)&laddr);
    if (res != 0) {
      printf("c792Init: ERROR in sysBusToLocalAdrs(0x39,0x%x,&laddr) \n",addr);
      return(ERROR);
    }
#else
    res = vmeBusToLocalAdrs(0x39,(char *)addr,(char **)&laddr);
    if (res != 0) {
      printf("c792Init: ERROR in vmeBusToLocalAdrs(0x39,0x%x,&laddr) \n",addr);
      return(ERROR);
    }
#endif
    c792MemOffset = laddr - addr;
  }else{ /* A32 Addressing */


    if((addr_inc==0)||(nadc==0))
      nadc = 1; /* assume only one QDC to initialize */

    /* get the QDC address */
#ifdef VXWORKS
    res = sysBusToLocalAdrs(0x09,(char *)addr,(char **)&laddr);
    if (res != 0) {
      printf("c792Init: ERROR in sysBusToLocalAdrs(0x09,0x%x,&laddr) \n",addr);
      return(ERROR);
    }
#else
    res = vmeBusToLocalAdrs(0x09,(char *)addr,(char **)&laddr);
    if (res != 0) {
      printf("c792Init: ERROR in vmeBusToLocalAdrs(0x09,0x%x,&laddr) \n",addr);
      return(ERROR);
    }
#endif
    c792MemOffset = laddr - addr;
  }

  lladdr = laddr;

  Nc792 = 0;
  for (ii=0;ii<nadc;ii++)
  {
    c792p[ii] = (struct c792_struct *)(laddr + ii*addr_inc);
    c792pl[ii]  = (struct c792_struct *)(lladdr + ii*addr_inc);
    /* Check if Board exists at that address */
#ifdef VXWORKS
    res = vxMemProbe((char *) &(c792p[ii]->rev),0,2,(char *)&rdata);
#else
    res = vmeMemProbe((char *) &(c792p[ii]->rev),2,(char *)&rdata);
#endif
    if(res < 0)
    {
      printf("c792Init: ERROR: No addressable board at addr=0x%x\n",(UINT32) c792p[ii]);
      c792p[ii] = NULL;
      /*sergey: errFlag = 1;*/
      break;
    }
    else
    {
      /* Check if this is a Model 792 */
      rp = (struct c792_ROM_struct *)((UINT32)c792p[ii] + C792_ROM_OFFSET);
      boardID = ((c792Read(&rp->ID_3)&(0xff))<<16) + 
	     ((c792Read(&rp->ID_2)&(0xff))<<8) + (c792Read(&rp->ID_1)&(0xff)); 

      /* set 1 for tdc, 2 for adc */
      if(boardID == C775_BOARD_ID)      use792[Nc792] = 1;
      else if(boardID == C792_BOARD_ID) use792[Nc792] = 2;
      else
      {
	    printf(" ERROR: Board ID does not match: %d \n",boardID);
	    return(ERROR);
      }
    }
    Nc792++;
#ifdef VXWORKS
    printf("Initialized QDC ID %d at address 0x%08x \n",ii,(UINT32) c792p[ii]);
#else
    printf("Initialized QDC ID %d at VME (USER) address 0x%08x (0x%08x) \n",ii,
	   (UINT32)(c792p[ii]) - c792MemOffset, (UINT32) c792p[ii]);
#endif
  }

#ifdef VXWORKS
  /* Initialize/Create Semephore */
  if(c792Sem != 0) {
    semFlush(c792Sem);
    semDelete(c792Sem);
  }
  c792Sem = semBCreate(SEM_Q_PRIORITY,SEM_EMPTY);
  if(c792Sem <= 0) {
    printf("c792Init: ERROR: Unable to create Binary Semephore\n");
    return(ERROR);
  }
#endif
  
  /* Disable/Clear all QDCs */
  for(ii=0;ii<Nc792;ii++) {
    C792_EXEC_SOFT_RESET(ii);
    C792_EXEC_DATA_RESET(ii);
    c792Write(&c792p[ii]->intLevel,0);        /* Disable Interrupts */
    c792Write(&c792p[ii]->evTrigger,0);       /* Zero interrupt trigger count */
    c792Write(&c792p[ii]->crateSelect,crateID);  /* Set Crate ID Register */
    c792Write(&c792p[ii]->bitClear2,C792_INCR_ALL_TRIG); /* Increment event count only on
							    accepted gates */

    c792EventCount[ii] =  0;          /* Initialize the Event Count */
    c792EvtReadCnt[ii] = -1;          /* Initialize the Read Count */
  }
  /* Initialize Interrupt variables */
  c792IntID = -1;
  c792IntRunning = FALSE;
  c792IntLevel = 0;
  c792IntVec = 0;
  c792IntRoutine = NULL;
  c792IntArg = 0;
  c792IntEvCount = 0;
    
#ifdef VXWORKSPPC
  bzero((char *)&c792Fpr,sizeof(c792Fpr));
#endif

  if(Nc792 > 0) printf("c792Init: %d QDC(s) successfully initialized\n",Nc792);
  if(errFlag > 0)
  {
    printf("c792Init: ERROR: Unable to initialize all QDC Modules, errFlag=%d\n",errFlag);
    return(ERROR);
  }
  else
  {
    return(Nc792);
  }

}