Exemplo n.º 1
0
static int fetch_values(acalcoutRecord *pcalc)
{
	DBLINK	*plink;	/* structure of the link field  */
	double	*pvalue;
	double	**pavalue;
	long	status = 0;
	int		i, j;
	unsigned short *plinkValid;
	long numElements;

#if MIND_UNUSED_ELEMENTS
	numElements = pcalc->nelm;
#else
	numElements = acalcGetNumElements( pcalc );
#endif
	if (aCalcoutRecordDebug >= 10)
		printf("acalcoutRecord(%s):fetch_values: entry\n", pcalc->name);
	for (i=0, plink=&pcalc->inpa, pvalue=&pcalc->a; i<MAX_FIELDS; 
			i++, plink++, pvalue++) {
		status = dbGetLink(plink, DBR_DOUBLE, pvalue, 0, 0);
		if (!RTN_SUCCESS(status)) return(status);
	}

	if (aCalcoutRecordDebug >= 10) printf("acalcoutRecord(%s):fetch_values: arrays\n", pcalc->name);
	plinkValid = &pcalc->iaav;
	for (i=0, plink=&pcalc->inaa, pavalue=(double **)(&pcalc->aa); i<ARRAY_MAX_FIELDS; 
			i++, plink++, pavalue++, plinkValid++) {
		if ((*plinkValid==acalcoutINAV_EXT) || (*plinkValid==acalcoutINAV_LOC)) {
			long	nRequest;
			if (aCalcoutRecordDebug >= 10) printf("acalcoutRecord(%s):fetch_values: field %c%c, pointer=%p\n",
				pcalc->name, (int)('A'+i), (int)('A'+i), *pavalue);
			if (*pavalue == NULL) {
				if (aCalcoutRecordDebug) printf("acalcoutRecord(%s): allocating for field %c%c\n",
					pcalc->name, (int)('A'+i), (int)('A'+i));
				*pavalue = (double *)calloc(pcalc->nelm, sizeof(double));
			}
			/* save current array value */
			if (pcalc->paa == NULL) {
				if (aCalcoutRecordDebug) printf("acalcoutRecord(%s): allocating for field PAA\n",
					pcalc->name);
				pcalc->paa = (double *)calloc(pcalc->nelm, sizeof(double));
			}
			for (j=0; j<numElements; j++) pcalc->paa[j] = (*pavalue)[j];
			/* get new value */
			nRequest = acalcGetNumElements( pcalc );
			status = dbGetLink(plink, DBR_DOUBLE, *pavalue, 0, &nRequest);
			if (!RTN_SUCCESS(status)) return(status);
			if (nRequest<numElements) {
				for (j=nRequest; j<numElements; j++) (*pavalue)[j] = 0;
			}
			/* compare new array value with saved value */
			for (j=0; j<numElements; j++) {
				if (pcalc->paa[j] != (*pavalue)[j]) {pcalc->newm |= 1<<i; break;}
			}
		}
	}
	if (aCalcoutRecordDebug >= 10)
		printf("acalcoutRecord(%s):fetch_values: returning\n", pcalc->name);
	return(0);
}
Exemplo n.º 2
0
/**************************************************
* scalerISRSetup()
***************************************************/
STATIC int scalerISRSetup(int card)
{
	long status;
	volatile char *addr;
	int intLevel;
	
	Debug(5, "scalerISRSetup: Entry, card #%d\n", card);
	if ((card+1) > scaler_total_cards) return(ERROR);
	addr = scaler_state[card]->localAddr;

	status = devConnectInterrupt(intVME, vsc_InterruptVector + card,
		(void *) &scalerISR, (void *) card);
	if (!RTN_SUCCESS(status)) {
		errPrintf(status, __FILE__, __LINE__, "Can't connect to vector %ld\n",
			  vsc_InterruptVector + card);
		return (ERROR);
	}

	/* get interrupt level from hardware, and enable that level in EPICS */
	intLevel = readReg16(addr,IRQ_LEVEL_ENABLE_OFFSET) & 5 /*3*/;
	Debug(5, "scalerISRSetup: Interrupt level %d\n", intLevel);
	status = devEnableInterruptLevel(intVME, intLevel);
	if (!RTN_SUCCESS(status)) {
		errPrintf(status, __FILE__, __LINE__,
			  "Can't enable enterrupt level %d\n", intLevel);
		return (ERROR);
	}
	/* Write interrupt vector to hardware */
	writeReg16(addr,IRQ_VECTOR_OFFSET,(unsigned short) (vsc_InterruptVector + card));
	Debug(5, "scalerISRSetup: Exit, card #%d\n", card);
	return (OK);
}
Exemplo n.º 3
0
/*
 * FETCH_VALUES
 *
 * fetch the values for the variables from which to select
 */
static int fetch_values(selRecord *prec)
{
    struct link	*plink;
    double	*pvalue;
    int		i;
    long	status;

    plink = &prec->inpa;
    pvalue = &prec->a;
    /* If mechanism is selSELM_Specified, only get the selected input*/
    if(prec->selm == selSELM_Specified) {
	/* fetch the select index */
	status=dbGetLink(&(prec->nvl),DBR_USHORT,&(prec->seln),0,0);
	if (!RTN_SUCCESS(status) || (prec->seln >= SEL_MAX))
	    return(status);

	plink += prec->seln;
	pvalue += prec->seln;

	status=dbGetLink(plink,DBR_DOUBLE, pvalue,0,0);
	return(status);
    }
    /* fetch all inputs*/
    for(i=0; i<SEL_MAX; i++, plink++, pvalue++) {
	status=dbGetLink(plink,DBR_DOUBLE, pvalue,0,0);
    }
    return(status);
}
Exemplo n.º 4
0
static long process(epidRecord *pepid)
{
    struct epidDSET *pdset = (struct epidDSET *)(pepid->dset);
    long  status;
    int pact=pepid->pact;

    if (!pact) { /* If this is not a callback from device support */
        /* fetch the setpoint */
        if(pepid->smsl == menuOmslclosed_loop) {
            status = dbGetLink(&(pepid->stpl),DBR_DOUBLE, &(pepid->val),0,0);
            if (RTN_SUCCESS(status)) pepid->udf=FALSE;
        }
        if (pepid->udf == TRUE ) {
#if LT_EPICSBASE(3,15,0,2)
            recGblSetSevr(pepid,UDF_ALARM,INVALID_ALARM);
#else
            recGblSetSevr(pepid,UDF_ALARM,pepid->udfs);
#endif
            return(0);
        }
    }

    status = (*pdset->do_pid)(pepid);
    /* See if device support set pact=true, meaning  it will call us back */
    if (!pact && pepid->pact) return(0);
    pepid->pact = TRUE;
    recGblGetTimeStamp(pepid);
    checkAlarms(pepid);
    monitor(pepid);
    recGblFwdLink(pepid);
    pepid->pact=FALSE;
    return(status);
}
Exemplo n.º 5
0
static long writeValue(longoutRecord *prec)
{
	long status;
        struct longoutdset *pdset = (struct longoutdset *) (prec->dset);

	if (prec->pact == TRUE){
		status=(*pdset->write_longout)(prec);
		return(status);
	}

	status=dbGetLink(&(prec->siml),DBR_USHORT,&(prec->simm),0,0);
	if (!RTN_SUCCESS(status))
		return(status);

	if (prec->simm == menuYesNoNO){
		status=(*pdset->write_longout)(prec);
		return(status);
	}
	if (prec->simm == menuYesNoYES){
		status=dbPutLink(&prec->siol,DBR_LONG,&prec->val,1);
	} else {
		status=-1;
		recGblSetSevr(prec,SOFT_ALARM,INVALID_ALARM);
		return(status);
	}
        recGblSetSevr(prec,SIMM_ALARM,prec->sims);

	return(status);
}
Exemplo n.º 6
0
/*----------------------------------------------------------------------*/
static long dsetRead_devSiSyncSoft(stringinRecord *psi) {
  long status;

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

  status = dbGetLink(&psi->inp,DBR_STRING,psi->val,0,0);
  if(psi->inp.type!=CONSTANT && RTN_SUCCESS(status)) psi->udf=FALSE;
  dsetLog(3, __FILE__ "[%d] <- %s\n", __LINE__, __func__);
  return(status);
}
Exemplo n.º 7
0
static long dsetRead_devMbbiSyncSoft(mbbiRecord *pmbbi) {
    long status;

  dsetLog(3, __FILE__ "[%d] -> %s(%s)\n", __LINE__, __func__, pmbbi->name);
  status = dbGetLink(&pmbbi->inp,DBR_USHORT,&pmbbi->val,0,0);
  dsetLog(7, __FILE__ "[%d] %d -> %s\n", __LINE__, pmbbi->val, pmbbi->name);
  if(pmbbi->inp.type!=CONSTANT && RTN_SUCCESS(status)) pmbbi->udf=FALSE;
  dsetLog(3, __FILE__ "[%d] <- %s\n", __LINE__, __func__);
  return(DO_NOT_CONVERT);
}
Exemplo n.º 8
0
static long process(stringoutRecord *prec)
{
	struct stringoutdset	*pdset = (struct stringoutdset *)(prec->dset);
	long		 status=0;
	unsigned char    pact=prec->pact;

	if( (pdset==NULL) || (pdset->write_stringout==NULL) ) {
		prec->pact=TRUE;
		recGblRecordError(S_dev_missingSup,(void *)prec,"write_stringout");
		return(S_dev_missingSup);
	}
        if (!prec->pact
        && (prec->dol.type != CONSTANT)
        && (prec->omsl == menuOmslclosed_loop)) {
		status = dbGetLink(&(prec->dol),
			DBR_STRING,prec->val,0,0);
		if(prec->dol.type!=CONSTANT && RTN_SUCCESS(status)) prec->udf=FALSE;
	}

        if(prec->udf == TRUE ){
                recGblSetSevr(prec,UDF_ALARM,INVALID_ALARM);
        }

        if (prec->nsev < INVALID_ALARM )
                status=writeValue(prec); /* write the new value */
        else {
                switch (prec->ivoa) {
                    case (menuIvoaContinue_normally) :
                        status=writeValue(prec); /* write the new value */
                        break;
                    case (menuIvoaDon_t_drive_outputs) :
                        break;
                    case (menuIvoaSet_output_to_IVOV) :
                        if(prec->pact == FALSE){
                                strcpy(prec->val,prec->ivov);
                        }
                        status=writeValue(prec); /* write the new value */
                        break;
                    default :
                        status=-1;
                        recGblRecordError(S_db_badField,(void *)prec,
                                "stringout:process Illegal IVOA field");
                }
        }

	/* check if device support set pact */
	if ( !pact && prec->pact ) return(0);

	prec->pact = TRUE;
	recGblGetTimeStamp(prec);
	monitor(prec);
	recGblFwdLink(prec);
	prec->pact=FALSE;
	return(status);
}
Exemplo n.º 9
0
/**************************************************
* scalerEndOfGateISRSetup()
***************************************************/
STATIC int scalerEndOfGateISRSetup(int card)
{
	long status;
	volatile char *addr;
	volatile uint16 u16;

	Debug(5, "scalerEndOfGateISRSetup: Entry, card #%d\n", card);
	if (card >= scalerVS_total_cards) return(ERROR);
	addr = scalerVS_state[card]->localAddr;

	status = devConnectInterruptVME(vs_InterruptVector + card,
		(void *) &scalerEndOfGateISR, (void *)card);
	if (!RTN_SUCCESS(status)) {
		errPrintf(status, __FILE__, __LINE__, "Can't connect to vector %d\n",
			  vs_InterruptVector + card);
		return (ERROR);
	}

	/* write interrupt level to hardware, and tell EPICS to enable that level */
	u16 = readReg16(addr,IRQ_SETUP_OFFSET) & 0x0ff;
	/* OR in level for end-of-gate interrupt */
	writeReg16(addr,IRQ_SETUP_OFFSET, u16 | (vs_InterruptLevel << 8));
	status = devEnableInterruptLevelVME(vs_InterruptLevel);
	if (!RTN_SUCCESS(status)) {
		errPrintf(status, __FILE__, __LINE__,
			  "Can't enable enterrupt level %d\n", vs_InterruptLevel);
		return (ERROR);
	}
	Debug(5, "scalerEndOfGateISRSetup: Wrote interrupt level, %d, to hardware\n",
	      vs_InterruptLevel);

	/* Write interrupt vector to hardware */
	writeReg16(addr,IRQ_3_GATE_VECTOR_OFFSET, (uint16)(vs_InterruptVector + card));
	Debug(5, "scalerEndOfGateISRSetup: Wrote interrupt vector, %d, to hardware\n",
	      vs_InterruptVector + card);

	Debug(5, "scalerEndOfGateISRSetup: Read interrupt vector, %d, from hardware\n",
	      readReg16(addr,IRQ_3_GATE_VECTOR_OFFSET) & 0x0ff);

	Debug(5, "scalerEndOfGateISRSetup: Exit, card #%d\n", card);
	return (OK);
}
Exemplo n.º 10
0
static long dsetRead_devAiSyncSoft(aiRecord *pai) {
  long status;

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

  status = dbGetLink(&(pai->inp),DBR_DOUBLE, &(pai->val),0,0);
  if (pai->inp.type!=CONSTANT && RTN_SUCCESS(status)) pai->udf = FALSE;

  dsetLog(3, __FILE__ "[%d] <- %s\n", __LINE__, __func__);
  return(DO_NOT_CONVERT); 
}
Exemplo n.º 11
0
/*----------------------------------------------------------------------*/
static long dsetRead_devBiSyncSoft(biRecord *pbi) {
    long status;

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

    status = dbGetLink(&pbi->inp, DBR_USHORT, &pbi->val,0,0);
    if(pbi->inp.type!=CONSTANT && RTN_SUCCESS(status)) pbi->udf=FALSE;

    dsetLog(2, __FILE__ "[%d] %s --(%d)-> %s\n",
            __LINE__, pbi->inp.value.instio.string, pbi->val, pbi->name);

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

    return(DO_NOT_CONVERT);
}
Exemplo n.º 12
0
/*----------------------------------------------------------------------*/
static long dsetRead_devSiSyncSoft(stringinRecord *pstringin)
{
  long status;

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

  status = dbGetLink(&pstringin->inp,DBR_STRING,pstringin->val,0,0);
  if(pstringin->inp.type!=CONSTANT && RTN_SUCCESS(status)) pstringin->udf=FALSE;

  #ifdef DEBUG1
  printf( __FILE__ "[%d] <- %s(%ld)\n", __LINE__, __func__, status);
  #endif
  return(status);
}
Exemplo n.º 13
0
static long process(selRecord *prec)
{
    prec->pact = TRUE;
    if ( RTN_SUCCESS(fetch_values(prec)) ) {
	do_sel(prec);
    }

    recGblGetTimeStamp(prec);
    /* check for alarms */
    checkAlarms(prec);


    /* check event list */
    monitor(prec);

    /* process the forward scan link record */
    recGblFwdLink(prec);

    prec->pact=FALSE;
    return(0);
}
Exemplo n.º 14
0
/***************************************************
* initialize all software and hardware
* scaler_init()
****************************************************/
STATIC long scaler_init(int after)
{
	volatile char *localAddr;
	unsigned long status;
	void *baseAddr;
	int card, i;
	uint32 probeValue = 0;
 
	Debug(2,"scaler_init(): entry, after = %d\n", after);
	if (after || (vsc_num_cards == 0)) return(0);

	/* allocate scaler_state structures, array of pointers */
	if (scaler_state == NULL) {
	scaler_state = (struct scaler_state **)
				calloc(1, vsc_num_cards * sizeof(struct scaler_state *));

		scaler_total_cards=0;
		for (card=0; card<vsc_num_cards; card++) {
		    scaler_state[card] = (struct scaler_state *)
					calloc(1, sizeof(struct scaler_state));
		}
	}

	/* Check out the hardware. */
	for (card=0; card<vsc_num_cards; card++) {
		baseAddr = (void *)(vsc_addrs + card*CARD_ADDRESS_SPACE);

		/* Can we reserve the required block of VME address space? */
		status = devRegisterAddress(__FILE__, atVMEA32, (size_t)baseAddr,
			CARD_ADDRESS_SPACE, (volatile void **)&localAddr);
		if (!RTN_SUCCESS(status)) {
			errPrintf(status, __FILE__, __LINE__,
				"Can't register 0x%x-byte block at address %p\n", CARD_ADDRESS_SPACE, baseAddr);
			return (ERROR);
		}

		if (devReadProbe(4,(volatile void *)(localAddr+DATA_0_OFFSET),(void*)&probeValue)) {
			printf("no VSC card at %p\n",localAddr);
			return(0);
		}
		
		/* Declare victory. */
		Debug(2,"scaler_init: we own 256 bytes starting at %p\n",localAddr);
		scaler_state[card]->localAddr = localAddr;
		scaler_total_cards++;

		/* reset this card */
		writeReg16(localAddr,RESET_OFFSET,0);

		/* get this card's identification */
		scaler_state[card]->ident = readReg16(localAddr,REV_SERIAL_NO_OFFSET);
		Debug(3,"scaler_init: Serial # = %d\n", scaler_state[card]->ident);
		scaler_state[card]->card_exists = 1;

		/* get this card's type (8 or 16 channels?) */
		Debug(2,"scaler_init:Base Address=0x%8.8x\n",(int)baseAddr);
		Debug(2,"scaler_init:Local Address=0x%8.8x\n",(int)localAddr);
		scaler_state[card]->num_channels =  readReg16(localAddr,MODULE_TYPE_OFFSET) & 0x18;
		Debug(3,"scaler_init: nchan = %d\n", scaler_state[card]->num_channels);
		if (scaler_state[card]->num_channels < 8) {
		    scaler_state[card]->card_exists = 0;
		    continue;
		}
		for (i=0; i<MAX_SCALER_CHANNELS; i++) {
			scaler_state[card]->preset[i] = 0;
		}
	}

	Debug(3,"scaler_init: Total cards = %d\n\n",scaler_total_cards);

#ifdef vxWorks
    if (epicsAtExit(scaler_shutdown, 0) < 0)
		epicsPrintf ("scaler_init: epicsAtExit() failed\n"); 
#endif

	Debug(3, "%s", "scaler_init: scalers initialized\n");
	return(0);
}
Exemplo n.º 15
0
static long process(longoutRecord *prec)
{
	struct longoutdset	*pdset = (struct longoutdset *)(prec->dset);
	long		 status=0;
	epicsInt32	 value;
	unsigned char    pact=prec->pact;

	if( (pdset==NULL) || (pdset->write_longout==NULL) ) {
		prec->pact=TRUE;
		recGblRecordError(S_dev_missingSup,(void *)prec,"write_longout");
		return(S_dev_missingSup);
	}
	if (!prec->pact) {
		if((prec->dol.type != CONSTANT)
                && (prec->omsl == menuOmslclosed_loop)) {
			status = dbGetLink(&(prec->dol),DBR_LONG,
				&value,0,0);
			if (prec->dol.type!=CONSTANT && RTN_SUCCESS(status))
				prec->udf=FALSE;
		}
		else {
			value = prec->val;
		}
		if (!status) convert(prec,value);
	}

	/* check for alarms */
	checkAlarms(prec);

        if (prec->nsev < INVALID_ALARM )
                status=writeValue(prec); /* write the new value */
        else {
                switch (prec->ivoa) {
                    case (menuIvoaContinue_normally) :
                        status=writeValue(prec); /* write the new value */
                        break;
                    case (menuIvoaDon_t_drive_outputs) :
                        break;
                    case (menuIvoaSet_output_to_IVOV) :
                        if(prec->pact == FALSE){
                                prec->val=prec->ivov;
                        }
                        status=writeValue(prec); /* write the new value */
                        break;
                    default :
                        status=-1;
                        recGblRecordError(S_db_badField,(void *)prec,
                                "longout:process Illegal IVOA field");
                }
        }

	/* check if device support set pact */
	if ( !pact && prec->pact ) return(0);
	prec->pact = TRUE;

	recGblGetTimeStamp(prec);

	/* check event list */
	monitor(prec);

	/* process the forward scan link record */
	recGblFwdLink(prec);

	prec->pact=FALSE;
	return(status);
}
Exemplo n.º 16
0
/***************************************************
* initialize all software and hardware
* scalerVS_init()
****************************************************/
STATIC long scalerVS_init(int after)
{
	volatile char *localAddr;
	unsigned long status;
	char *baseAddr;
	int card, card_type;
	uint32 probeValue = 0;

	Debug(2,"scalerVS_init(): entry, after = %d\n", after);
	if (after || (vs_num_cards == 0)) return(0);

	/* allocate scalerVS_state structures, array of pointers */
	if (scalerVS_state == NULL) {
    	scalerVS_state = (struct scalerVS_state **)
				calloc(1, vs_num_cards * sizeof(struct scalerVS_state *));

		scalerVS_total_cards=0;
		for (card=0; card<vs_num_cards; card++) {
		    scalerVS_state[card] = (struct scalerVS_state *)
					calloc(1, sizeof(struct scalerVS_state));
		}
	}

	/* Check out the hardware. */
	for (card=0; card<vs_num_cards; card++) {
		baseAddr = (char *)(vs_addrs + card*CARD_ADDRESS_SPACE);

		/* Can we reserve the required block of VME address space? */
		status = devRegisterAddress(__FILE__, atVMEA16, (size_t)baseAddr,
			CARD_ADDRESS_SPACE, (volatile void **)&localAddr);
		if (!RTN_SUCCESS(status)) {
			errPrintf(status, __FILE__, __LINE__,
				"Can't register 2048-byte block in VME A16 at address %p\n", baseAddr);
			return (ERROR);
		}

		if (devReadProbe(4,(volatile void *)(localAddr+READ_XFER_REG_OFFSET),(void*)&probeValue)) {
			printf("scalerVS_init: no VSxx card at %p\n",localAddr);
			return(0);
		}
		
		/* Declare victory. */
		Debug(2,"scalerVS_init: we own 2048 bytes in VME A16 starting at %p\n", localAddr);
		scalerVS_state[card]->localAddr = localAddr;
		scalerVS_total_cards++;

		/* reset this card */
		/* any write to this address causes reset */
		writeReg16(localAddr,MASTER_RESET_OFFSET,0);
		/* get this card's type and serial number */
		scalerVS_state[card]->ident = readReg16(localAddr,ID_OFFSET);
		Debug(3,"scalerVS_init: Serial # = %d\n", scalerVS_state[card]->ident & 0x3FF);

		/* get this card's type */
		card_type = scalerVS_state[card]->ident >> 10;
		if ((card_type > 22) || (card_type < 16)) {
			errPrintf(status, __FILE__, __LINE__, "unrecognized module\n");
			scalerVS_state[card]->num_channels = 0;
			scalerVS_state[card]->card_exists = 0;
			/*
			 * Something's wrong with this card, but we still count it in scalerVS_total_cards.
			 * A bad card retains its address space; otherwise we can't talk to the next one.
			 */
		} else {
			scalerVS_state[card]->num_channels = VS_module_types[card_type-16].num_channels;
			scalerVS_state[card]->card_exists = 1;
		}
		Debug(3,"scalerVS_init: nchan = %d\n", scalerVS_state[card]->num_channels);
	}

	Debug(3,"scalerVS_init: Total cards = %d\n\n",scalerVS_total_cards);

#ifdef vxWorks
    if (epicsAtExit(scalerVS_shutdown, 0) < 0)
		epicsPrintf ("scalerVS_init: epicsAtExit() failed\n");
#endif
	Debug(3,"%s", "scalerVS_init: scalers initialized\n");
	return(0);
}