Beispiel #1
0
static long read_ai(aiRecord *pao)
{
  struct prngState* priv=pao->dpvt;

  if( ! pao->pact ){
    /* start async operation */
    pao->pact=TRUE;
    callbackSetUser(pao,&priv->cb);
    callbackRequestDelayed(&priv->cb,0.1);
    return 0;
  }else{
    /* complete operation */
    pao->pact=FALSE;
    return 0;
  }
}
static long dsetInit_devMbbiDirectAsyncGpib (mbbiDirectRecord *p_mbbiDirect) {
  CONTEXT *p_myContext;

  packageInfo();
  dsetLog(3,  __FILE__ "[%d] -> %s(%s) \n", __LINE__, __func__,p_mbbiDirect->name);

  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));

  sscanf(p_mbbiDirect->inp.value.instio.string,
		"gba=%d gpa=%d c=%[^\n]",
		&p_myContext->gpibBoardAddress,
		&p_myContext->gpibPrimaryAddress,
		p_myContext->p_gpibCommand);

  p_myContext->gpibSecondaryAddress=0;

  p_myContext->gpibDeviceHandle=gpibOpenDevice(
		  p_myContext->gpibBoardAddress,
		  p_myContext->gpibPrimaryAddress,
		  p_myContext->gpibSecondaryAddress);
		  		
  dsetLog(5, __FILE__ "[%d] Parsed options >%s<\n", 
		__LINE__, p_mbbiDirect->inp.value.instio.string);
  dsetLog(5, __FILE__ "[%d]  gpibBoardAddress    = %d\n",
		__LINE__,p_myContext->gpibBoardAddress);
  dsetLog(5, __FILE__ "[%d]  gpibPrimaryAddress  = %d\n",
		__LINE__, p_myContext->gpibPrimaryAddress);
  dsetLog(5, __FILE__ "[%d]  gpibSecondaryAddress= %d\n",
		__LINE__, p_myContext->gpibSecondaryAddress);
  dsetLog(5, __FILE__ "[%d]  p_gpibCommand       = >%s<\n",
		__LINE__, p_myContext->p_gpibCommand);
  dsetLog(5, __FILE__ "[%d]  gpibDeviceHandle    = %d\n",
		__LINE__, p_myContext->gpibDeviceHandle);

  p_myContext->p_callback=(CALLBACK *)(calloc(1,sizeof(CALLBACK)));
  callbackSetCallback(myCallback_devMbbiDirectAsyncGpib,p_myContext->p_callback);
  callbackSetUser(p_mbbiDirect,p_myContext->p_callback);

  p_mbbiDirect->dpvt=(void *)p_myContext;

  dsetLog(3,  __FILE__ "[%d] <- %s\n", __LINE__, __func__);

  return(SUCCESS);
}
Beispiel #3
0
/*****************************************************************************
 *
 * Initialize a sequence record.
 *
 * Allocate the callback request structure (tacked on dpvt.)
 * Initialize watch-dog ID
 * Initialize SELN based on the link-type of SELL
 * If SELL is a CA_LINK, inform CA about it
 * For each constant input link, fill in the DOV field
 *
 ******************************************************************************/
static long init_record(seqRecord *prec, int pass)
{
    int		index;
    linkDesc      *plink;
    callbackSeq *pcallbackSeq;

    if (pass==0) return(0);

    if (seqRecDebug > 5)
      printf("init_record(%s) entered\n", prec->name);

    /* Allocate a callback structure for use in processing */
    pcallbackSeq  = (callbackSeq *)calloc(1,sizeof(callbackSeq));
    pcallbackSeq->pseqRecord = prec;
    callbackSetCallback(processCallback,&pcallbackSeq->callback);
    callbackSetUser(pcallbackSeq,&pcallbackSeq->callback);
    callbackSetPriority(prec->prio,&pcallbackSeq->callback);
    prec->dpvt = (void *)pcallbackSeq;

    /* Get link selection if sell is a constant and nonzero */
    if (prec->sell.type==CONSTANT)
    {
      if (seqRecDebug > 5)
        printf("init_record(%s) SELL is a constant\n", prec->name);
      recGblInitConstantLink(&prec->sell,DBF_USHORT,&prec->seln);
    }

  /* Copy over ALL the input link constants here */
  plink = (linkDesc *)(&(prec->dly1));

  index = 0;
  while (index < NUM_LINKS)
  {

    if (plink->dol.type == CONSTANT)
	recGblInitConstantLink(&plink->dol,DBF_DOUBLE,&plink->dov);

    index++;

    plink++;
  }

  return(0);
}
Beispiel #4
0
/* -------------------------------------------------------------------- *\
 * DSET METHODS
\* -------------------------------------------------------------------- */
static long dsetInit_devMbboAsyncGpib(mbboRecord *pmbbo) {
    int myGpibBoardAddress;
    int myPrimaryAddress;
    int mySecondaryAddress;
    int myGpibDeviceHandle;
    CONTEXT *p_myContext;
    CALLBACK *p_myCallback;

    packageInfo();
    dsetLog(3,__FILE__ "[%d] -> %s(%s)\n", __LINE__, __func__,pmbbo->name );

    p_myContext = (CONTEXT *)calloc(1, sizeof(CONTEXT));
    p_myCallback = (CALLBACK *)calloc(1, sizeof(CALLBACK));
    callbackSetUser(pmbbo,p_myCallback);
    callbackSetCallback(myCallback_devMbboAsyncGpib,p_myCallback);

    sscanf(pmbbo->out.value.instio.string, "gba=%d gpa=%d",
           &myGpibBoardAddress, &myPrimaryAddress);
    mySecondaryAddress=0;

    dsetLog(5,__FILE__ "[%d] params           = >%s<\n",
            __LINE__, pmbbo->out.value.instio.string);
    dsetLog(5,__FILE__ "[%d] gpibBoardAddress = %d\n",
            __LINE__, myGpibBoardAddress);
    dsetLog(5,__FILE__ "[%d] primaryAddress   = %d\n",
            __LINE__, myPrimaryAddress);
    dsetLog(5,__FILE__ "[%d] secondayAddress  = %d\n",
            __LINE__, mySecondaryAddress);

    myGpibDeviceHandle = gpibOpenDevice(
                             myGpibBoardAddress,
                             myPrimaryAddress,
                             mySecondaryAddress);

    p_myContext->gpibBoardAddress=myGpibBoardAddress;
    p_myContext->gpibDeviceHandle=myGpibDeviceHandle;
    p_myContext->primaryAddress=myPrimaryAddress;
    p_myContext->p_callback=p_myCallback;

    pmbbo->dpvt = (void *)p_myContext;
    dsetLog(3, __FILE__ "[%d] <- %s\n", __LINE__, __func__);
    return(SUCCESS);
}
static long dsetInit_devAiAsyncEthernet(aiRecord *pai) {
  CONTEXT *p_myContext;
  int myServicePortNumber;
  SOCKET mySocket=-1;
  char p_myCommand[BUFLEN];
  char p_myServerName[BUFLEN];
  CALLBACK *p_myCallback;

  packageInfo();
  dsetLog(3, __FILE__ "[%d] -> %s(%s)\n", __LINE__, __func__, pai->name);


  if (sscanf(pai->inp.value.instio.string, "sn=%s spn=%d c=%[^\n]",
	p_myServerName, &myServicePortNumber, p_myCommand)!=3) {
      dsetLog(1, __FILE__ "[%d] Error: %s\n", __LINE__, pai->name);
      dsetLog(1, __FILE__ "[%d] Error: Couldn't parse parameters\n", __LINE__);
      dsetLog(1, __FILE__ "[%d] Error: Parameters >%s<\n",
                            __LINE__, pai->inp.value.instio.string);
      sleep(SLEEPTIME_ERROR);
      return(ERROR);
  }

  dsetLog(5,__FILE__ "[%d] p_serverName= >%s<\n",__LINE__,p_myServerName);
  dsetLog(5,__FILE__ "[%d] servicePort = %d\n",__LINE__,myServicePortNumber);
  dsetLog(5,__FILE__ "[%d] p_Command   = >%s<\n",__LINE__,p_myCommand);

  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));
  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetUser(pai,p_myCallback);
  callbackSetCallback(myCallback_devAiAsyncEthernet,p_myCallback);
  p_myContext->p_callback=p_myCallback;

  p_myContext->servicePortNumber=myServicePortNumber;
  p_myContext->socket=mySocket;
  strncpy(p_myContext->p_command, p_myCommand, BUFLEN);
  strncpy(p_myContext->p_serverName, p_myServerName, BUFLEN);
  pai->dpvt=(void *)p_myContext;

  dsetLog(3, __FILE__ "[%d] <- %s\n", __LINE__, __func__);
  return(SUCCESS);
} 
Beispiel #6
0
void scanIoInit(IOSCANPVT *pioscanpvt)
{
    ioscan_head *piosh = dbCalloc(1, sizeof(ioscan_head));
    int prio;

    ioscanInit();
    for (prio = 0; prio < NUM_CALLBACK_PRIORITIES; prio++) {
        io_scan_list *piosl = &piosh->iosl[prio];

        callbackSetCallback(ioscanCallback, &piosl->callback);
        callbackSetPriority(prio, &piosl->callback);
        callbackSetUser(piosh, &piosl->callback);
        ellInit(&piosl->scan_list.list);
        piosl->scan_list.lock = epicsMutexMustCreate();
    }
    epicsMutexMustLock(ioscan_lock);
    piosh->next = pioscan_list;
    pioscan_list = piosh;
    epicsMutexUnlock(ioscan_lock);
    *pioscanpvt = piosh;
}
Beispiel #7
0
event_list *eventNameToHandle(const char *eventname)
{
    int prio;
    event_list *pel;
    static epicsThreadOnceId onceId = EPICS_THREAD_ONCE_INIT;

    if (!eventname || eventname[0] == 0)
        return NULL;

    epicsThreadOnce(&onceId, eventOnce, NULL);
    epicsMutexMustLock(event_lock);
    for (pel = pevent_list[0]; pel; pel=pel->next) {
        if (strcmp(pel->event_name, eventname) == 0) break;
    }
    if (pel == NULL) {
        pel = dbCalloc(1, sizeof(event_list));
        strcpy(pel->event_name, eventname);
        for (prio = 0; prio < NUM_CALLBACK_PRIORITIES; prio++) {
            callbackSetUser(&pel->scan_list[prio], &pel->callback[prio]);
            callbackSetPriority(prio, &pel->callback[prio]);
            callbackSetCallback(eventCallback, &pel->callback[prio]);
            pel->scan_list[prio].lock = epicsMutexMustCreate();
            ellInit(&pel->scan_list[prio].list);
        }
        pel->next=pevent_list[0];
        pevent_list[0]=pel;
        { /* backward compatibility */
            char* p;
            long e = strtol(eventname, &p, 0);
            if (*p == 0 && e > 0 && e <= 255)
                pevent_list[e] = pel;
        }
    }
    epicsMutexUnlock(event_lock);
    return pel;
}
Beispiel #8
0
static void putNotifyInit(putNotify *ppn)
{
    putNotifyPvt *pputNotifyPvt;

    pputNotifyPvt = (putNotifyPvt *)ellFirst(&pnotifyGlobal->freeList);
    if(pputNotifyPvt) {
        ellDelete(&pnotifyGlobal->freeList,&pputNotifyPvt->node);
    } else {
        pputNotifyPvt = dbCalloc(1,sizeof(putNotifyPvt));
        pputNotifyPvt->cancelEvent = epicsEventCreate(epicsEventEmpty);
        pputNotifyPvt->userCallbackEvent = epicsEventCreate(epicsEventEmpty);
        pputNotifyPvt->magic = MAGIC;
        pputNotifyPvt->state = putNotifyNotActive;
    }
    pputNotifyPvt->state = putNotifyNotActive;
    callbackSetCallback(notifyCallback,&pputNotifyPvt->callback);
    callbackSetUser(ppn,&pputNotifyPvt->callback);
    callbackSetPriority(priorityLow,&pputNotifyPvt->callback);
    ellInit(&pputNotifyPvt->waitList);
    ppn->status = 0;
    pputNotifyPvt->state = putNotifyNotActive;
    pputNotifyPvt->cancelWait = pputNotifyPvt->userCallbackWait = 0;
    ppn->pputNotifyPvt = pputNotifyPvt;
}
Beispiel #9
0
static long dsetInit_devAiAsyncGpib(aiRecord *pai) {
  int gpibBoardAddress;	
  int gpibPrimaryAddress;
  int gpibSecondaryAddress=0;
  char *p_gpibCommand;	/* Pointer to the gpib read command	*/
  int index=0;		/* An array index			*/
  int gpibDeviceHandle;	/* A handle to communicate with the dev	*/
  CALLBACK *p_myCallback;
  CONTEXT *p_myContext;


  packageInfo(); 
  dsetLog(3, __FILE__ "[%d] -> %s(%s)\n", __LINE__, __func__, pai->name );

  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));

  sscanf(pai->inp.value.instio.string, "gba=%d gpa=%d c=%[^\n]", 
           &p_myContext->gpibBoardAddress, 
           &p_myContext->gpibPrimaryAddress, 
           p_myContext->p_gpibCommand);

  p_myContext->gpibSecondaryAddress=0;

  gpibBoardAddress=p_myContext->gpibBoardAddress;
  gpibPrimaryAddress=p_myContext->gpibPrimaryAddress;
  gpibSecondaryAddress=p_myContext->gpibSecondaryAddress;
  p_gpibCommand=p_myContext->p_gpibCommand;

  p_myContext->gpibDeviceHandle = 
    gpibOpenDevice(gpibBoardAddress, gpibPrimaryAddress, gpibSecondaryAddress);

  gpibDeviceHandle=p_myContext->gpibDeviceHandle;
    
  dsetLog(5, __FILE__ "[%d] Param             = >%s<\n", 
		    __LINE__, pai->inp.value.instio.string);
  dsetLog(5, __FILE__ "[%d] gpibBoardAddress  = %d\n", 
		  __LINE__, gpibBoardAddress);
  dsetLog(5, __FILE__ "[%d] gpibPrimaryAddress= %d\n",
		  __LINE__, gpibPrimaryAddress);
  dsetLog(5, __FILE__ "[%d] command           = >%s<\n", 
		  __LINE__, p_gpibCommand);
  dsetLog(5, __FILE__ "[%d] gpibDeviceHandle  = %d\n", 
		  __LINE__, gpibDeviceHandle);

    /* IOC and Instrument must agree on 	*/
    /* input/output format.			*/
    dsetLog(5, __FILE__ "[%d] -- %s -- Input Formating\n",__LINE__, __func__);

    if (p_myContext->gpibInitDevice) {
        /* initialize the device */
        index=0;
        while (dataFormatCommand[index]) {
            dsetLog(5, __FILE__ "[%d] Sending >%s< to %s\n", __LINE__ , 
                   dataFormatCommand[index], pai->name);
            /* Write command on gpib		*/
            gpibWrite(gpibDeviceHandle, dataFormatCommand[index]);
            usleep(30000);		/* Pause: Do not write on gpib too fast!*/
            index++;		/* Get ready to send following message	*/
        } /* end_of_while */
    }

  p_myCallback=(CALLBACK *)(calloc(1,sizeof(CALLBACK)));
  callbackSetCallback(myCallback_devAiAsyncGpib,p_myCallback);
  callbackSetUser(pai,p_myCallback);

  p_myContext->p_callback=p_myCallback;
  pai->dpvt=(void *)p_myContext;

  dsetLog(3,  __FILE__ "[%d] <- %s \n", __LINE__, __func__ );
  return(SUCCESS);
} 
static long dsetInit_devMbboAsyncSerial(mbboRecord *pmbbo) {
  CONTEXT *p_myContext;
  CALLBACK *p_myCallback;	
  int mySerialPrimaryAddress;
  int mySerialPortNumber;
  int myParity;
  int myNumberOfDataBits;
  int myNumberOfStopBits;
  int myBaudRate;
  char p_myCommand[BUFLEN];

  packageInfo();	
  dsetLog(3,__FILE__ "[%d] -> %s (%s)\n", __LINE__, __func__, pmbbo->name);

  if(sscanf(pmbbo->out.value.instio.string,
	 "spn=%d spa=%d br=%d nodb=%d p=%d nosb=%d c=%[^\n]",
	&mySerialPortNumber, &mySerialPrimaryAddress, &myBaudRate, 
	&myNumberOfDataBits, &myParity, &myNumberOfStopBits,
	p_myCommand)!=7) {
    dsetLog(1,__FILE__ "[%d] Error: Couldn't parse the parameters correctly!\n",
		    __LINE__ );
    dsetLog(1,__FILE__ "[%d] Params >%s<!\n", 
		    __LINE__, pmbbo->out.value.instio.string );
    sleep(SLEEPTIME_ERROR);
    return(ERROR);
  } 

  initSerialPort2(mySerialPortNumber);
  setBaudRate2(mySerialPortNumber,myBaudRate);
  setNumberOfDataBits2(mySerialPortNumber,myNumberOfDataBits);
  setParity2(mySerialPortNumber,myParity);
/* setFlowControl2(mySerialPortNumber,NO_FLOW_CONTROL); Required for this dev */
  setNumberOfStopBits2(mySerialPortNumber,myNumberOfStopBits);

  if (openSerialPort2(mySerialPortNumber) <= ERROR ) {
    dsetLog(1, __FILE__ "[%d] Error: Couldn't open serial port (%s)\n",
                 __LINE__, getSerialPortName2(mySerialPortNumber));
    sleep(SLEEPTIME_ERROR);
    return(ERROR);
  }


  dsetLog(5,__FILE__ "[%d] serialPortNumber       = %d\n", 
		__LINE__, mySerialPortNumber);
  dsetLog(5,__FILE__ "[%d] serialPrimaryAddress   = %d\n", 
		__LINE__, mySerialPrimaryAddress);
  dsetLog(5,__FILE__ "[%d] baudRate         = %d\n", 
		__LINE__, getBaudRate2(mySerialPortNumber));
  dsetLog(5,__FILE__ "[%d] numberOfDataBits = %d\n",
		__LINE__, getNumberOfDataBits2(mySerialPortNumber));
  dsetLog(5,__FILE__ "[%d] parity           = %d\n", 
		__LINE__, getParity2(mySerialPortNumber));
  dsetLog(5,__FILE__ "[%d] numberOfStopBits = %d\n",
		__LINE__, getNumberOfStopBits2(mySerialPortNumber));

  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetCallback(myCallback_devMbboAsyncSerial,p_myCallback);
  callbackSetUser(pmbbo,p_myCallback);
 
  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));
  p_myContext->serialPortNumber=mySerialPortNumber;
  p_myContext->p_callback=p_myCallback;
  p_myContext->serialPrimaryAddress=mySerialPrimaryAddress;
  strncpy(p_myContext->p_command, p_myCommand, BUFLEN);
  p_myContext->operatingMode=NORMAL_MODE;

  #ifdef WARMSTART
  p_myContext->operatingMode=WARMSTART_MODE;
  pmbbo->pini=1;
  pmbbo->omsl=menuOmslclosed_loop;
  #endif

  pmbbo->dpvt=(void *)p_myContext;

  dsetLog(3, __FILE__ "[%d] <- %s\n", __LINE__, __func__);

  return(SUCCESS);

} 
Beispiel #11
0
static long initCommon(dbCommon *pr, DBLINK *plink,
    userCallback processCallback,interruptCallbackFloat64 interruptCallback)
{
    devPvt *pPvt;
    asynStatus status;
    asynUser *pasynUser;
    asynInterface *pasynInterface;
    static const char *functionName="initCommon";

    pPvt = callocMustSucceed(1, sizeof(*pPvt), "%s::%s");
    pr->dpvt = pPvt;
    pPvt->pr = pr;
    /* Create asynUser */
    pasynUser = pasynManager->createAsynUser(processCallback, 0);
    pasynUser->userPvt = pPvt;
    pPvt->pasynUser = pasynUser;
    pPvt->devPvtLock = epicsMutexCreate();
    /* Parse the link to get addr and port */
    status = pasynEpicsUtils->parseLink(pasynUser, plink,
                &pPvt->portName, &pPvt->addr,&pPvt->userParam);
    if (status != asynSuccess) {
        printf("%s %s::%s %s\n",
                     pr->name, driverName, functionName,pasynUser->errorMessage);
        goto bad;
    }
    /* Connect to device */
    status = pasynManager->connectDevice(pasynUser, pPvt->portName, pPvt->addr);
    if (status != asynSuccess) {
        printf("%s %s::%s connectDevice failed %s\n",
                     pr->name, driverName, functionName,pasynUser->errorMessage);
        goto bad;
    }
    status = pasynManager->canBlock(pPvt->pasynUser, &pPvt->canBlock);
    if (status != asynSuccess) {
        printf("%s %s::%s canBlock failed %s\n",
                     pr->name, driverName, functionName,pasynUser->errorMessage);
        goto bad;
    }
    /*call drvUserCreate*/
    pasynInterface = pasynManager->findInterface(pasynUser,asynDrvUserType,1);
    if(pasynInterface && pPvt->userParam) {
        asynDrvUser *pasynDrvUser;
        void       *drvPvt;

        pasynDrvUser = (asynDrvUser *)pasynInterface->pinterface;
        drvPvt = pasynInterface->drvPvt;
        status = pasynDrvUser->create(drvPvt,pasynUser,pPvt->userParam,0,0);
        if(status!=asynSuccess) {
            printf("%s %s::%s drvUserCreate %s\n",
                     pr->name, driverName, functionName,pasynUser->errorMessage);
            goto bad;
        }
    }
    /* Get interface asynFloat64 */
    pasynInterface = pasynManager->findInterface(pasynUser, asynFloat64Type, 1);
    if (!pasynInterface) {
        printf("%s %s::%s findInterface asynFloat64Type %s\n",
                     pr->name, driverName, functionName,pasynUser->errorMessage);
        goto bad;
    }
    pPvt->pfloat64 = pasynInterface->pinterface;
    pPvt->float64Pvt = pasynInterface->drvPvt;

    /* Initialize synchronous interface */
    status = pasynFloat64SyncIO->connect(pPvt->portName, pPvt->addr,
                 &pPvt->pasynUserSync, pPvt->userParam);
    if (status != asynSuccess) {
        printf("%s %s::%s Float64SyncIO->connect failed %s\n",
               pr->name, driverName, functionName,pPvt->pasynUserSync->errorMessage);
        goto bad;
    }

    scanIoInit(&pPvt->ioScanPvt);
    pPvt->interruptCallback = interruptCallback;

    /* If the info field "asyn:READBACK" is 1 and interruptCallback is not NULL 
     * then register for callbacks on output records */
    if (interruptCallback) {
        int enableCallbacks=0;
        const char *callbackString;
        DBENTRY *pdbentry = dbAllocEntry(pdbbase);
        status = dbFindRecord(pdbentry, pr->name);
        if (status) {
            asynPrint(pPvt->pasynUser, ASYN_TRACE_ERROR,
                "%s %s::%s error finding record\n",
                pr->name, driverName, functionName);
            goto bad;
        }
        callbackString = dbGetInfo(pdbentry, "asyn:READBACK");
        if (callbackString) enableCallbacks = atoi(callbackString);
        if (enableCallbacks) {
            status = createRingBuffer(pr);
            if (status!=asynSuccess) goto bad;
            status = pPvt->pfloat64->registerInterruptUser(
               pPvt->float64Pvt,pPvt->pasynUser,
               pPvt->interruptCallback,pPvt,&pPvt->registrarPvt);
            if(status!=asynSuccess) {
                printf("%s %s::initRecord error calling registerInterruptUser %s\n",
                       pr->name, driverName,pPvt->pasynUser->errorMessage);
            }
            /* Initialize the interrupt callback */
            callbackSetCallback(outputCallbackCallback, &pPvt->outputCallback);
            callbackSetPriority(pr->prio, &pPvt->outputCallback);
            callbackSetUser(pPvt, &pPvt->outputCallback);
        }
    }
    return INIT_OK;
bad:
    recGblSetSevr(pr,LINK_ALARM,INVALID_ALARM);
    pr->pact=1;
    return INIT_ERROR;
}
Beispiel #12
0
void callbackSetProcess(CALLBACK *pcallback, int Priority, void *pRec)
{
    callbackSetCallback(ProcessCallback, pcallback);
    callbackSetPriority(Priority, pcallback);
    callbackSetUser(pRec, pcallback);
}
Beispiel #13
0
void
xycom566setup(
      int id,
      int cbase,
      int dbase,
      int level,
      int vec,
      int bipol
){
  xy566 *card;
  volatile epicsUInt8  **cb;
  volatile epicsUInt16 **db;
  epicsUInt16 junk;

  if(cbase<0 || cbase>0xffff){
    printf("config (A16) out of range\n");
    return;
  }
  if(dbase<0 || dbase>0xffffff){
    printf("data (A24) out of range\n");
    return;
  }

  if(level<0 || level>7){
    printf("Level out of range (0->7)\n");
    return;
  }
  if(vec<0 || vec>0xff){
    printf("Vector out of range (0->255)\n");
    return;
  }

  card=get566(id);
  if(!!card){
    printf("ID %d already exists\n",id);
    return;
  }

  card=malloc(sizeof(xy566));
  if(!card){
    printf("Out of memory!\n");
    return;
  }

  memset(&card->dlen,0,sizeof(card->dlen));
  memset(&card->cb_irq,0,sizeof(card->cb_irq));

  card->id=id;
  card->fail=0;
  card->clk_div=0; /* stc uninitialized */
  card->use_seq_clk=0;
  ellInit(&card->seq_ctor);

  if(!bipol)
    card->nchan=32;
  else
    card->nchan=16;
  card->ivec=vec;

  card->base_addr=cbase;
  card->data_addr=dbase;

  cb=&card->base;
  db=&card->data_base;

  if(devBusToLocalAddr(atVMEA16, card->base_addr, (volatile void **)cb)){
    printf("Failed to map A16 %lx for card %x\n", (unsigned long)card->base_addr,id);
    free(card);
    return;
  }

  if(devBusToLocalAddr(atVMEA24, card->data_addr, (volatile void **)db)){
    printf("Failed to map A24 %lx for card %x\n", (unsigned long)card->data_base,id);
    free(card);
    return;
  }

  if(devReadProbe(2, card->base+U16_XY566_CSR, &junk)){
    printf("Failed to read A16 %lx for card %x\n", (unsigned long)(card->base+U16_XY566_CSR),id);
    free(card);
    return;
  }

  if(devReadProbe(2, card->data_base, &junk)){
    printf("Failed to read A24 %lx for card %x\n", (unsigned long)(card->data_base),id);
    free(card);
    return;
  }

  WRITE16(card->base, XY566_CSR, XY566_CSR_RST); /* Reset */
  /* turn on green and red to indicate init start */
  WRITE16(card->base, XY566_CSR, XY566_CSR_GRN);

  WRITE16(card->base, XY566_RAM, 0);
  WRITE8(card->base, XY566_SEQ, 0);

  card->guard=epicsMutexMustCreate();
  scanIoInit(&card->seq_irq);
  callbackSetCallback(xycom566isrcb, &card->cb_irq);
  callbackSetPriority(priorityHigh, &card->cb_irq);
  callbackSetUser(card, &card->cb_irq);

  WRITE8(card->base, XY566_VEC, vec);

  devEnableInterruptLevelVME(level);
  assert(devConnectInterruptVME(vec, xycom566isr, card)==0);

  /* Configure card
   * Mode: continuous sequence (default)
   * 16 bit conversion (default)
   * sequence controller disable (will be enabled during drvsup init)
   */
  WRITE16(card->base, XY566_CSR,
    XY566_CSR_GRN);

  ellAdd(&xy566s,&card->node);
}
Beispiel #14
0
static long dsetInit_devSiAsyncGpib(stringinRecord *psi)
{
  CONTEXT *p_myContext;
  CALLBACK *p_myCallback;
  
  #ifdef DEBUG1
  printf( __FILE__ "[%d] -> %s(%s)\n", __LINE__, __func__, psi->name );
  #endif
  
  p_myContext = (CONTEXT *)calloc(1, sizeof(CONTEXT));
  psi->dpvt = (void *)p_myContext;

  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetCallback(myCallback_devSiAsyncGpib,p_myCallback);
  callbackSetUser(psi,p_myCallback);
  p_myContext->p_callback=p_myCallback;


  sscanf(psi->inp.value.instio.string, "gba=%d gpa=%d c=%[^\n]",
               &p_myContext->gpibBoardAddress,
               &p_myContext->primaryAddress,
               p_myContext->p_command);

  p_myContext->secondaryAddress=0;
  p_myContext->handleGroup=1;

  #ifdef DEBUG2
  printf( __FILE__ "[%d] gpibBoardAddress   = %d\n", 
		  __LINE__, p_myContext->gpibBoardAddress);
  printf( __FILE__ "[%d] primaryAddress= %d\n", 
		  __LINE__,p_myContext->primaryAddress);
  printf( __FILE__ "[%d] group         = %d\n", 
		  __LINE__,p_myContext->handleGroup);
  printf( __FILE__ "[%d] p_command       = %s\n", 
		  __LINE__, p_myContext->p_command);
  #endif

  /*
  sprintf(buffer, "gpib%d", p_myContext->gpibBoardAddress);

  p_myContext->gpibDeviceHandle = gpibOpenDevice(buffer, p_myContext->primaryAddress, 0,
                                  12, 1, 10, p_myContext->handleGroup, NULL, 0);

				  */
  p_myContext->gpibDeviceHandle=gpibOpenDevice(p_myContext->gpibBoardAddress,
	  			p_myContext->primaryAddress,
				p_myContext->secondaryAddress);

  #ifdef DEBUG2
  printf( __FILE__ "[%d] GPIB AI p_myContextured:\n", __LINE__ );
  printf( __FILE__ "[%d] gpibBoardAddress= %d\n", 
		  __LINE__, p_myContext->gpibBoardAddress);
  printf( __FILE__ "[%d] primaryAddress  = %d\n", 
		  __LINE__,p_myContext->primaryAddress);
  printf( __FILE__ "[%d] p_command       = %s\n", 
		  __LINE__, p_myContext->p_command);
  printf( __FILE__ "[%d] gpibDeviceHandle= %d\n", 
		  __LINE__, p_myContext->gpibDeviceHandle);
  #endif
  
  return(SUCCESS);

}
Beispiel #15
0
static long init_record(longoutRecord *plongout)
{
  struct link *plink = &plongout->out;
  int size;
  char *buf;
  char *pC;
  F3RP61_SEQ_DPVT *dpvt;
  MCMD_STRUCT *pmcmdStruct;
  MCMD_REQUEST *pmcmdRequest;
  M3_WRITE_SEQDEV *pM3WriteSeqdev;
  int srcSlot, destSlot, top;
  char device;
  char option;
  short BCD = 0;

  if (plongout->out.type != INST_IO) {
    recGblRecordError(S_db_badField,(void *)plongout,
		      "devLoF3RP61Seq (init_record) Illegal OUT field");
    plongout->pact = 1;
    return(S_db_badField);
  }
  size = strlen(plink->value.instio.string) + 1;
  buf = (char *) callocMustSucceed(size, sizeof(char), "calloc failed");
  strncpy(buf, plink->value.instio.string, size);
  buf[size - 1] = '\0';

  /* Parse option*/
  pC = strchr(buf, '&');
  if (pC) {
    *pC++ = '\0';
    if (sscanf(pC, "%c", &option) < 1) {
      errlogPrintf("devLoF3RP61Seq: can't get option for %s\n", plongout->name);
      plongout->pact = 1;
      return (-1);
      }
    if (option == 'B') {
       BCD = 1; /* flag is used for the possible double option case */
    }
  }

  /* Parse slot, device and register number*/
  if (sscanf(buf, "CPU%d,%c%d", &destSlot, &device, &top) < 3) {
    errlogPrintf("devLoF3RP61Seq: can't get device addresses for %s\n",
		 plongout->name);
    plongout->pact = 1;
    return (-1);
  }

  dpvt = (F3RP61_SEQ_DPVT *) callocMustSucceed(1,
					      sizeof(F3RP61_SEQ_DPVT),
					      "calloc failed");

  if (ioctl(f3rp61_fd, M3IO_GET_MYCPUNO, &srcSlot) < 0) {
    errlogPrintf("devLoF3RP61Seq: ioctl failed [%d]\n", errno);
    plongout->pact = 1;
    return (-1);
  }

  dpvt->BCD = BCD;
  pmcmdStruct = &dpvt->mcmdStruct;
  pmcmdStruct->timeOut = 1;
  pmcmdRequest = &pmcmdStruct->mcmdRequest;
  pmcmdRequest->formatCode = 0xf1;
  pmcmdRequest->responseOption = 1;
  pmcmdRequest->srcSlot = (unsigned char) srcSlot;
  pmcmdRequest->destSlot = (unsigned char) destSlot;
  pmcmdRequest->mainCode = 0x26;
  pmcmdRequest->subCode = 0x02;
  pmcmdRequest->dataSize = 12;
  pM3WriteSeqdev = (M3_WRITE_SEQDEV *) &pmcmdRequest->dataBuff.bData[0];
  pM3WriteSeqdev->accessType = 2;
  switch (device)
    {
    case 'D':
      pM3WriteSeqdev->devType = 0x04;
      break;
    case 'B':
      pM3WriteSeqdev->devType = 0x02;
      break;
    default:
      errlogPrintf("devLoF3RP61Seq: unsupported device in %s\n", plongout->name);
      plongout->pact = 1;
      return (-1);
    }
  pM3WriteSeqdev->dataNum = 1;
  pM3WriteSeqdev->topDevNo = top;
  callbackSetUser(plongout, &dpvt->callback);

  plongout->dpvt = dpvt;

  return(0);
}
Beispiel #16
0
static long init_record(acalcoutRecord *pcalc, int pass)
{
	DBLINK *plink;
	int i;
	double *pvalue;
	unsigned short *plinkValid;
	short error_number;
    acalcoutDSET *pacalcoutDSET;

	dbAddr       Addr;
	dbAddr       *pAddr = &Addr;
	rpvtStruct   *prpvt;

	if (pass==0) {
		pcalc->vers = VERSION;
		pcalc->rpvt = (void *)calloc(1, sizeof(struct rpvtStruct));
		if ((pcalc->nuse < 0) || (pcalc->nuse > pcalc->nelm)) {
			pcalc->nuse = pcalc->nelm;
			db_post_events(pcalc,&pcalc->nuse,DBE_VALUE|DBE_LOG);
		}
		return(0);
	}

	if (!(pacalcoutDSET = (acalcoutDSET *)pcalc->dset)) {
		recGblRecordError(S_dev_noDSET,(void *)pcalc,"acalcout:init_record");
		return(S_dev_noDSET);
	}
	/* must have write defined */
	if ((pacalcoutDSET->number < 5) || (pacalcoutDSET->write == NULL)) {
		recGblRecordError(S_dev_missingSup,(void *)pcalc,"acalcout:init_record");
		return(S_dev_missingSup);
	}

	prpvt = (rpvtStruct *)pcalc->rpvt;
	plink = &pcalc->inpa;
	pvalue = &pcalc->a;
	plinkValid = &pcalc->inav;
	for (i=0; i<(MAX_FIELDS+ARRAY_MAX_FIELDS+1); i++, plink++, pvalue++, plinkValid++) {
		if (plink->type == CONSTANT) {
			/* Don't InitConstantLink the array links or the output link. */
			if (i < MAX_FIELDS) { 
				recGblInitConstantLink(plink,DBF_DOUBLE,pvalue);
				db_post_events(pcalc,pvalue,DBE_VALUE);
			}
			*plinkValid = acalcoutINAV_CON;
			if (plink == &pcalc->out)
				prpvt->outlink_field_type = DBF_NOACCESS;
		} else if (!dbNameToAddr(plink->value.pv_link.pvname, pAddr)) {
			/* the PV we're linked to resides on this ioc */
			*plinkValid = acalcoutINAV_LOC;
			if (plink == &pcalc->out) {
				prpvt->outlink_field_type = pAddr->field_type;
				if ((pAddr->field_type >= DBF_INLINK) && (pAddr->field_type <= DBF_FWDLINK)) {
					if (!(plink->value.pv_link.pvlMask & pvlOptCA)) {
						printf("aCalcoutRecord(%s):init_record:non-CA link to link field\n",
							plink->value.pv_link.pvname);
					}
				}
				if (pcalc->wait && !(plink->value.pv_link.pvlMask & pvlOptCA)) {
					printf("aCalcoutRecord(%s):init_record: Can't wait with non-CA link attribute\n",
						plink->value.pv_link.pvname);
				}
			}
		} else {
			/* pv is not on this ioc. Callback later for connection stat */
			*plinkValid = acalcoutINAV_EXT_NC;
			prpvt->caLinkStat = CA_LINKS_NOT_OK;
			if (plink == &pcalc->out)
				prpvt->outlink_field_type = DBF_NOACCESS; /* don't know field type */
		}
		db_post_events(pcalc,plinkValid,DBE_VALUE);
	}

	pcalc->clcv = aCalcPostfix(pcalc->calc,pcalc->rpcl,&error_number);
	if (pcalc->clcv) {
		recGblRecordError(S_db_badField,(void *)pcalc,
			"acalcout: init_record: Illegal CALC field");
		if (aCalcoutRecordDebug >= 10)
			printf("acalcPostfix returns: %d\n", error_number);
	}
	db_post_events(pcalc,&pcalc->clcv,DBE_VALUE);

	pcalc->oclv = aCalcPostfix(pcalc->ocal, pcalc->orpc,&error_number);
	if (pcalc->oclv) {
		recGblRecordError(S_db_badField,(void *)pcalc,
			"acalcout: init_record: Illegal OCAL field");
		if (aCalcoutRecordDebug >= 10)
			printf("acalcPostfix returns: %d\n", error_number);
	}
	db_post_events(pcalc,&pcalc->oclv,DBE_VALUE);

	callbackSetCallback(checkLinksCallback, &prpvt->checkLinkCb);
	callbackSetPriority(0, &prpvt->checkLinkCb);
	callbackSetUser(pcalc, &prpvt->checkLinkCb);
	prpvt->wd_id_1_LOCK = 0;

	if (prpvt->caLinkStat == CA_LINKS_NOT_OK) {
		callbackRequestDelayed(&prpvt->checkLinkCb,1.0);
		prpvt->wd_id_1_LOCK = 1;
	}

	if (pacalcoutDSET->init_record ) {
		return (*pacalcoutDSET->init_record)(pcalc);
	}
	return(0);
}
Beispiel #17
0
static long dsetInit_devAiAsyncSerial(aiRecord *pai) {
  CONTEXT *p_myContext;
  CALLBACK *p_myCallback;
  int myPortNumber;
  int myPrimaryAddress;
  int myNumberOfDataBits;
  int myParity;
  int myNumberOfStopBits;
  int myBaudRate;
  char p_myCommand[BUFLEN];

  packageInfo();
  dsetLog(3, __FILE__ "[%d] -> %s(%s)\n", __LINE__, __func__, pai->name);

  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));
  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetUser(pai,p_myCallback);
  callbackSetCallback(myCallback_devAiAsyncSerial,p_myCallback);
  p_myContext->p_callback=p_myCallback;

  pai->dpvt = (void *)p_myContext;


  if (sscanf(pai->inp.value.instio.string, 
	"spn=%d spa=%d br=%d nodb=%d p=%d nosb=%d c=%[^\n]",
	&myPortNumber,
	&myPrimaryAddress,
	&myBaudRate,
	&myNumberOfDataBits,
	&myParity,
	&myNumberOfStopBits,
        p_myCommand)!=7) {
      dsetLog(1, __FILE__ "[%d] Error: Couldn't parse paramters\n", __LINE__);
      dsetLog(1, __FILE__ "[%d] Error: Parameters >%s<\n",
                            __LINE__, pai->inp.value.instio.string);
      sleep(SLEEPTIME_ERROR);
      return(ERROR);
  }

  dsetLog(5,__FILE__ "[%d] portNumber      = %d\n",__LINE__,myPortNumber);
  dsetLog(5,__FILE__ "[%d] baudRate        = %d\n",__LINE__,myBaudRate);
  dsetLog(5,__FILE__ "[%d] parity          = %d\n",__LINE__,myParity);
  dsetLog(5,__FILE__ "[%d] numberOfDataBits= %d\n",__LINE__,myNumberOfDataBits);
  dsetLog(5,__FILE__ "[%d] numberOfStopBits= %d\n",__LINE__,myNumberOfStopBits);
  dsetLog(5,__FILE__ "[%d] serialCommand   = >%s<\n",__LINE__,p_myCommand);

  initSerialPort2(myPortNumber);
  setBaudRate2(myPortNumber,myBaudRate);
  setNumberOfDataBits2(myPortNumber,myNumberOfDataBits);
  setParity2(myPortNumber,myParity);
  setFlowControl2(myPortNumber,COMBINED_FLOW_CONTROL); 
 /*  setFlowControl2(myPortNumber,NO_FLOW_CONTROL); 
  *  Required for this dev */
  setNumberOfStopBits2(myPortNumber,myNumberOfStopBits);

  openSerialPort2(myPortNumber);

  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetCallback(myCallback_devAiAsyncSerial,p_myCallback);
  callbackSetUser(pai,p_myCallback);

  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));
  p_myContext->portNumber=myPortNumber;
  p_myContext->p_callback=p_myCallback;
  p_myContext->primaryAddress=myPrimaryAddress;
  strncpy(p_myContext->p_command, p_myCommand, BUFLEN);
  pai->dpvt=(void *)p_myContext;

  dsetLog(3, __FILE__ "[%d] <- %s\n", __LINE__, __func__);
  return(SUCCESS);
} 
Beispiel #18
0
int ni1014Config(char *portNameA,char *portNameB,
    int base, int vector, int level, int priority, int noAutoConnect)
{
    niport *pniportArray[2] = {0,0};
    int    size;
    int    indPort,nports;
    long   status;

    if(nloopsPerMicrosecond==0)
	initAuxmrWait();

    nports = (portNameB==0 || strlen(portNameB)==0) ? 1 : 2;
    for(indPort=0; indPort<nports; indPort++) {
        niport *pniport;

        size = sizeof(niport);
        size += (indPort==0) ? strlen(portNameA) : strlen(portNameB);
        size += 1;
        pniport = callocMustSucceed(size,sizeof(char),"ni1014Config");
        pniportArray[indPort] = pniport;
        pniport->portName = (char *)(pniport+1);
        strcpy(pniport->portName,((indPort==0) ? portNameA : portNameB));
        pniport->base = base;
        pniport->vector = vector;
        pniport->level = level;
        pniport->eos = -1;
        pniport->waitForInterrupt = epicsEventMustCreate(epicsEventEmpty);
        callbackSetCallback(srqCallback,&pniport->callback);
        callbackSetUser(pniport,&pniport->callback);
        status = devRegisterAddress("drvNi1014", atVMEA16, pniport->base,
            PORT_REGISTER_SIZE/2,(volatile void **)&pniport->registers);
        if(status) {
            printf("%s ni1014Config devRegisterAddress failed\n",pniport->portName);
            return(-1);
        }
        /* attach the interrupt handler routines */
        status = devConnectInterrupt(intVME,pniport->vector,
            ni1014,(void *)pniport);
        if(status) {
            errMessage(status,"ni1014: devConnectInterrupt");
            return -1;
        }
        status = devConnectInterrupt(intVME,pniport->vector+1,
            ni1014Err,(void *)pniport);
        if(status) {
            errMessage(status,"ni1014: devConnectInterrupt");
            return -1;
        }
        status = devEnableInterruptLevel(intVME,pniport->level);
        if(status) {
            errMessage(status,"ni1014: devEnableInterruptLevel");
            return -1;
        }
        pniport->isPortA = (indPort==0) ? 1 : 0;
        pniport->asynGpibPvt = pasynGpib->registerPort(pniport->portName,
            ASYN_MULTIDEVICE|ASYN_CANBLOCK,
            !noAutoConnect,&gpibPort,pniport,priority,0);
        base = base + PORT_REGISTER_SIZE;
        vector += 2;
    }
    return 0;
}
Beispiel #19
0
static long dsetInit_devAiAsyncGpib(aiRecord *pai) {
  CONTEXT *p_myContext;
  CALLBACK *p_myCallback;
  char p_writeBuffer[BUFLEN];

  packageInfo();
  dsetLog(3, __FILE__ "[%d] -> %s (%s)\n", __LINE__, __func__, pai->name);

  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));
  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetUser(pai,p_myCallback);
  callbackSetCallback(myCallback_devAiAsyncGpib,p_myCallback);
  p_myContext->pcallback=p_myCallback;

  pai->dpvt = (void *)p_myContext;

  if ( sscanf(pai->inp.value.instio.string,
		"gba=%d gpa=%d c=%[^\n]",
                 &p_myContext->gpibBoardAddress,
	         &p_myContext->gpibPrimaryAddress,
		 p_myContext->p_gpibCommand)!=3) {
    dsetLog(1, __FILE__ "[%d] Error: Couldn't parse paramters\n", __LINE__);
    dsetLog(1, __FILE__ "[%d] Parameters >%s<\n", 
			__LINE__, pai->inp.value.instio.string);
    sleep(SLEEPTIME_ERROR);
    return(ERROR);
  }

                                /* Open the connection with the device  */
  p_myContext->gpibSecondaryAddress=0;
  p_myContext->gpibDeviceHandle = gpibOpenDevice(
                                        p_myContext->gpibBoardAddress,
                                        p_myContext->gpibPrimaryAddress,
                                        p_myContext->gpibSecondaryAddress);

  dsetLog(5, __FILE__ "[%d] %s\n", __LINE__,   pai->name);
  dsetLog(5, __FILE__ "[%d] gpibBoardAddress= %d\n", 
		 __LINE__, p_myContext->gpibBoardAddress);
  dsetLog(5, __FILE__ "[%d] primaryAddress  = %d\n", 
		 __LINE__, p_myContext->gpibPrimaryAddress);
  dsetLog(5, __FILE__ "[%d] p_gpibCommand  = >%s<\n", 
		 __LINE__, p_myContext->p_gpibCommand);
  dsetLog(5, __FILE__ "[%d] secondaryAddress= %d\n", 
		 __LINE__, p_myContext->gpibSecondaryAddress);
  dsetLog(5, __FILE__ "[%d] gpibDeviceHandle     = %d\n", 
		 __LINE__, p_myContext->gpibDeviceHandle);

  /* set units to farenheit & convert later for greater precision */
  sprintf(p_writeBuffer,"UNIT %d,FHRN\n", p_myContext->gpibSecondaryAddress);

  dsetLog(5,__FILE__ "[%d] Writing >%s< on %s\n",
		  __LINE__, p_writeBuffer, pai->name);

  if (gpibWrite(p_myContext->gpibDeviceHandle, p_writeBuffer)<=ERROR) {
    dsetLog(1, __FILE__ "[%d] Error: Couldn't write >%s< on %s\n",
		    __LINE__, p_writeBuffer, pai->name);
    sleep(SLEEPTIME_ERROR);
    return(ERROR);
  }
  sleep(1);  /* SR630 can't take commands too quickly */


  dsetLog(3, __FILE__ "[%d] <- %s\n", __LINE__, __func__ );
  return(SUCCESS);
}
Beispiel #20
0
static long init_record(calcoutRecord *prec, int pass)
{
    DBLINK *plink;
    int i;
    double *pvalue;
    epicsEnum16 *plinkValid;
    short error_number;
    calcoutDSET *pcalcoutDSET;

    DBADDR     dbaddr;
    DBADDR     *pAddr = &dbaddr;
    rpvtStruct *prpvt;

    if (pass == 0) {
        prec->rpvt = (rpvtStruct *) callocMustSucceed(1, sizeof(rpvtStruct), "calcoutRecord");
        return 0;
    }
    if (!(pcalcoutDSET = (calcoutDSET *)prec->dset)) {
        recGblRecordError(S_dev_noDSET, (void *)prec, "calcout:init_record");
        return S_dev_noDSET;
    }
    /* must have write defined */
    if ((pcalcoutDSET->number < 5) || (pcalcoutDSET->write ==NULL)) {
        recGblRecordError(S_dev_missingSup, (void *)prec, "calcout:init_record");
        return S_dev_missingSup;
    }
    prpvt = prec->rpvt;
    plink = &prec->inpa;
    pvalue = &prec->a;
    plinkValid = &prec->inav;
    for (i = 0; i <= CALCPERFORM_NARGS; i++, plink++, pvalue++, plinkValid++) {
        if (plink->type == CONSTANT) {
            /* Don't InitConstantLink the .OUT link */
            if (i < CALCPERFORM_NARGS) {
                recGblInitConstantLink(plink, DBF_DOUBLE, pvalue);
            }
            *plinkValid = calcoutINAV_CON;
        } else if (!dbNameToAddr(plink->value.pv_link.pvname, pAddr)) {
            /* PV resides on this ioc */
            *plinkValid = calcoutINAV_LOC;
        } else {
            /* pv is not on this ioc. Callback later for connection stat */
            *plinkValid = calcoutINAV_EXT_NC;
             prpvt->caLinkStat = CA_LINKS_NOT_OK;
        }
    }

    prec->clcv = postfix(prec->calc, prec->rpcl, &error_number);
    if (prec->clcv){
        recGblRecordError(S_db_badField, (void *)prec,
                          "calcout: init_record: Illegal CALC field");
        errlogPrintf("%s.CALC: %s in expression \"%s\"\n",
                     prec->name, calcErrorStr(error_number), prec->calc);
    }

    prec->oclv = postfix(prec->ocal, prec->orpc, &error_number);
    if (prec->dopt == calcoutDOPT_Use_OVAL && prec->oclv){
        recGblRecordError(S_db_badField, (void *)prec,
                          "calcout: init_record: Illegal OCAL field");
        errlogPrintf("%s.OCAL: %s in expression \"%s\"\n",
                     prec->name, calcErrorStr(error_number), prec->ocal);
    }

    prpvt = prec->rpvt;
    callbackSetCallback(checkLinksCallback, &prpvt->checkLinkCb);
    callbackSetPriority(0, &prpvt->checkLinkCb);
    callbackSetUser(prec, &prpvt->checkLinkCb);
    prpvt->cbScheduled = 0;

    prec->epvt = eventNameToHandle(prec->oevt);
    
    if (pcalcoutDSET->init_record) pcalcoutDSET->init_record(prec);
    prec->pval = prec->val;
    prec->mlst = prec->val;
    prec->alst = prec->val;
    prec->lalm = prec->val;
    prec->povl = prec->oval;
    return 0;
}
static long init_record(mbboDirectRecord *pmbboDirect)
{
  struct link *plink = &pmbboDirect->out;
  int size;
  char *buf;
  F3RP61_SEQ_DPVT *dpvt;
  MCMD_STRUCT *pmcmdStruct;
  MCMD_REQUEST *pmcmdRequest;
  M3_WRITE_SEQDEV *pM3WriteSeqdev;
  int srcSlot, destSlot, top;
  char device;

  if (pmbboDirect->out.type != INST_IO) {
    recGblRecordError(S_db_badField,(void *)pmbboDirect,
                      "devMbboDirectF3RP61Seq (init_record) Illegal OUT field");
    pmbboDirect->pact = 1;
    return(S_db_badField);
  }
  size = strlen(plink->value.instio.string) + 1;
  buf = (char *) callocMustSucceed(size, sizeof(char), "calloc failed");
  strncpy(buf, plink->value.instio.string, size);
  buf[size - 1] = '\0';

  if (sscanf(buf, "CPU%d,%c%d", &destSlot, &device, &top) < 3) {
    errlogPrintf("devMbboDirectF3RP61Seq: can't get device addresses for %s\n",
                 pmbboDirect->name);
    pmbboDirect->pact = 1;
    return (-1);
  }

  dpvt = (F3RP61_SEQ_DPVT *) callocMustSucceed(1,
                                               sizeof(F3RP61_SEQ_DPVT),
                                               "calloc failed");

  if (ioctl(f3rp61Seq_fd, M3CPU_GET_NUM, &srcSlot) < 0) {
    errlogPrintf("devMbboDirectF3RP61Seq: ioctl failed [%d]\n", errno);
    pmbboDirect->pact = 1;
    return (-1);
  }
  pmcmdStruct = &dpvt->mcmdStruct;
  pmcmdStruct->timeOut = 1;
  pmcmdRequest = &pmcmdStruct->mcmdRequest;
  pmcmdRequest->formatCode = 0xf1;
  pmcmdRequest->responseOption = 1;
  pmcmdRequest->srcSlot = (unsigned char) srcSlot;
  pmcmdRequest->destSlot = (unsigned char) destSlot;
  pmcmdRequest->mainCode = 0x26;
  pmcmdRequest->subCode = 0x02;
  pmcmdRequest->dataSize = 12;
  pM3WriteSeqdev = (M3_WRITE_SEQDEV *) &pmcmdRequest->dataBuff.bData[0];
  pM3WriteSeqdev->accessType = 2;
  switch (device)
  {
  case 'D':
    pM3WriteSeqdev->devType = 0x04;
    break;
  case 'B':
    pM3WriteSeqdev->devType = 0x02;
    break;
  default:
    errlogPrintf("devMbboDirectF3RP61Seq: unsupported device in %s\n",
                 pmbboDirect->name);
    pmbboDirect->pact = 1;
    return (-1);
  }
  pM3WriteSeqdev->dataNum = 1;
  pM3WriteSeqdev->topDevNo = top;
  callbackSetUser(pmbboDirect, &dpvt->callback);

  pmbboDirect->dpvt = dpvt;

  return(0);
}
Beispiel #22
0
/* initialize the epics record and the hardware */
static long dsetInit_devAiAsyncSerial(aiRecord *pai)
{
  CONTEXT *p_myContext;
  CALLBACK *p_myCallback;	
  char p_writeBuffer[BUFLEN];
  char p_readBuffer[BUFLEN];
  int myPrimaryAddress;
  int myPortNumber;
  int myParity;
  int myNumberOfDataBits;
  int myNumberOfStopBits;
  int myBaudRate;
  char p_myCommand[BUFLEN];

  #ifdef DEBUG1
  packageInfo();	
  printf(__FILE__ "[%d] -> %s (%s)\n", __LINE__, __func__, pai->name);
  #endif

				/* Parse the db file paramters		*/
				/* and set the value of key variables	*/
  if(sscanf(pai->inp.value.instio.string,
	 "spn=%d pad=%d br=%d nodb=%d p=%d nosb=%d c=%[^\n]",
	&myPortNumber, &myPrimaryAddress, &myBaudRate, 
	&myNumberOfDataBits, &myParity, &myNumberOfStopBits, p_myCommand)!=7) {
    printf( __FILE__ "[%d] Error: Couldn't parse the parameters correctly!", 
		    __LINE__ );
    printf( __FILE__ "[%d] >%s<!", __LINE__, pai->inp.value.instio.string );
    sleep(SLEEPTIME_ERROR);
    return(ERROR);
  } /* end_of_if */

  initSerialPort2(myPortNumber);
  setBaudRate2(myPortNumber,myBaudRate);
  setNumberOfDataBits2(myPortNumber,myNumberOfDataBits);
  setParity2(myPortNumber,myParity);
  setFlowControl2(myPortNumber,NO_FLOW_CONTROL); /* Required for this dev */
  setNumberOfStopBits2(myPortNumber,myNumberOfStopBits);

  #ifdef DEBUG2
  printf(__FILE__ "[%d] portNumber       = %d\n", 
		__LINE__, myPortNumber);
  printf(__FILE__ "[%d] primaryAddress   = %d\n", 
		__LINE__, myPrimaryAddress);
  printf(__FILE__ "[%d] baudRate         = %d\n", 
		__LINE__, getBaudRate2(myPortNumber));
  printf(__FILE__ "[%d] numberOfDataBits = %d\n",
		__LINE__, getNumberOfDataBits2(myPortNumber));
  printf(__FILE__ "[%d] parity           = %d\n", 
		__LINE__, getParity2(myPortNumber));
  printf(__FILE__ "[%d] numberOfStopBits = %d\n",
		__LINE__, getNumberOfStopBits2(myPortNumber));
  printf(__FILE__ "[%d] p_myCommand      = >%s<\n", 
		 __LINE__, p_myCommand); 
  #endif

  if (lockSerialPort2(myPortNumber,LOCK, pai->name)<=ERROR) {
	printf( __FILE__ "[%d] Error: Couldn't lock serial port (%s)\n",
			__LINE__, getSerialPortName2(myPortNumber));
	sleep(SLEEPTIME_ERROR);
	return(ERROR);
  }
  				/* Disable front panel 			*/
				/* This operation should work if 	*/
				/* communication parameters are ok	*/
  strcpy(p_writeBuffer,"XFRONT");
  strcat(p_writeBuffer,TERMINATOR); 

  openSerialPort2(myPortNumber);
  if (writeSerialPort2(myPortNumber, p_writeBuffer ) <= ERROR) {
	printf( __FILE__ "[%d] Error: Couldn't write on %s\n",
			__LINE__, getSerialPortName2(myPortNumber));
	sleep(SLEEPTIME_ERROR);
	return(ERROR);
  }
  usleep(USLEEPTIME_WRITE);

  memset(p_readBuffer,0,BUFLEN);

  if (readSerialPort2(myPortNumber, p_readBuffer, BUFLEN) <= ERROR) {
	printf( __FILE__ "[%d] Error: Couldn't read on %s\n",
			__LINE__, getSerialPortName2(myPortNumber));
	sleep(SLEEPTIME_ERROR);
	return(ERROR);
  }
  usleep(USLEEPTIME_READ);
  if (lockSerialPort2(myPortNumber,UNLOCK, pai->name)<=ERROR) {
    printf ( __FILE__ "Error");
    sleep(SLEEPTIME_ERROR);
    return(ERROR);
  }


  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetCallback(myCallback_devAiAsyncSerial,p_myCallback);
  callbackSetUser(pai,p_myCallback);
 
  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));
  p_myContext->portNumber=myPortNumber;
  p_myContext->p_callback=p_myCallback;
  p_myContext->primaryAddress=myPrimaryAddress;
  strncpy(p_myContext->p_command, p_myCommand, BUFLEN);
  pai->dpvt=(void *)p_myContext;

				/* Check acknowledgement		*/
  if (strncmp(p_readBuffer,"OK",2)!=0) {
      printf( __FILE__ "[%d] Error: Couldn't communicate with  %s\n",
		      __LINE__, pai->name);
      printf( __FILE__ "[%d] Check configuration parameters?\n", __LINE__);
      return(ERROR);
  }

  #ifdef DEBUG1
  printf( __FILE__ "[%d] <- %s\n", __LINE__, __func__);
  #endif

  return(SUCCESS);

} /* end init_press_record() */