#include #include #include #include "alarm.h" #include "cvtTable.h" #include "dbDefs.h" #include "devLib.h" #include "dbAccess.h" #include "recSup.h" #include "callback.h" #include "devSup.h" #include "dbScan.h" /* for SCAN_IO_EVENT */ #include "link.h" #include "waveformRecord.h" /* for waveformRecord structure */ #include "epicsExport.h" /* for epicsExportAddress */ #include /* for DEBUGPRINT */ #include "drvPac.h" /* for PAC_I_DATA, PAC_Q_DATA */ /* key fields for waveformRecord epicsEnum16 ftvl; Field Type of Value short busy; Busy Indicator unsigned long nord; Number elements read void * bptr; Buffer Pointer */ typedef struct waveformPac_s { int inputType; } waveformPac_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read_write; } WFDSET; #ifdef DEBUG_PRINT int devWaveformPacFlag = 4; #endif int pacOverwriting = FALSE; int pacWF = 0; LOCAL long init_waveform(); LOCAL long waveform_ioinfo(); LOCAL long write_waveform(); WFDSET devWaveformPac = {5, NULL, NULL, init_waveform, waveform_ioinfo, write_waveform}; epicsExportAddress(dset, devWaveformPac); /* INFO: Generic case is to use init_waveform to: Using NELM and FTVL space for the array is allocated. The array address is stored in the record. This routine initializes SIMM with the value of SIML if SIML type is CONSTANT link or creates a channel access link if SIML type is PV_LINK. VAL is likewise initialized if SIOL is CONSTANT or PV_LINK. This routine next checks to see that device support is available and a device support read routine is defined. If either does not exist, an error message is issued and processing is terminated 12feb2007: set inputType from what what passed in. write_waveform does the real work now. */ LOCAL long init_waveform(struct waveformRecord *pwaveform) { waveformPac_t *pwaveformp; switch(pwaveform->inp.type) { case(INST_IO): /* Allocate the memory for this records private data structure */ pwaveformp = (waveformPac_t *) malloc(sizeof(waveformPac_t)); if (pwaveformp == NULL) { return S_dev_noMemory; } sscanf(pwaveform->inp.value.instio.string, "%d", &(pwaveformp->inputType)); /* inputType specifies the type of waveform: ICal, QCal, IRef, QRef, ICalRef, QCalRef, I FPGA, Q FPGA */ pwaveform->nord = pwaveform->nelm; pwaveform->val = pwaveform->bptr; pwaveform->udf = 0; /* Save the device private structure in the record */ pwaveform->dpvt = pwaveformp; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformPacFlag, ("init_waveform for '%s': instio string is: %s\n", pwaveform->name, pwaveform->inp.value.instio.string)); DEBUGPRINT(DP_INFO, devWaveformPacFlag, ("init_waveform for '%s': pwaveformp addr: 0x%08x\n", pwaveform->name, (unsigned int) pwaveformp)); DEBUGPRINT(DP_INFO, devWaveformPacFlag, ("init_waveform for '%s': inputType: %d\n", pwaveform->name, pwaveformp->inputType)); DEBUGPRINT(DP_INFO, devWaveformPacFlag, ("init_waveform for '%s': nord: %lu\n", pwaveform->name, pwaveform->nord)); DEBUGPRINT(DP_INFO, devWaveformPacFlag, ("init_waveform for '%s': val:0x%08x\n", pwaveform->name, (unsigned int) pwaveform->val)); DEBUGPRINT(DP_INFO, devWaveformPacFlag, ("init_waveform for '%s': udf: %d\n", pwaveform->name, pwaveform->udf)); #endif break; default: DEBUGPRINT(DP_ERROR, devWaveformPacFlag, ("init_waveform: %s: illegal INP field: %d", pwaveform->name, (int) pwaveform->inp.type)); break; } return OK; } LOCAL long waveform_ioinfo( int cmd, struct waveformRecord *pwaveform, IOSCANPVT *ppvt ) { #ifdef SCANIO *ppvt = pacGetIoScanPvt(); #endif return OK; } /* 1/8/2007: changing this routine from handling the update of FPGA to be only called to multiply the gain (if inputType 0 or 1) or amplitude (if inputType 2 or 3) */ LOCAL long write_waveform(struct waveformRecord *pwaveform) { waveformPac_t *pwaveformp; /* Facilitate access to device private structure */ pwaveformp = (waveformPac_t *)pwaveform->dpvt; /* Free the malloc'd space free(pwaveform->bptr); */ switch (pwaveformp->inputType) { /* case (PAC_I_DATA): not used. no waveform for this, since now that FPGA scales in gain, this wf is identical to I_REF */ /* case (PAC_Q_DATA): not used. identical to Q_REF now */ case (PAC_I_CAL): case (PAC_Q_CAL): /* Scale by the amplitude. still need this as of 10/1/8, but may be done by FPGA later on */ pwaveform->bptr = ( short*) pacScaleCalWaveformByAmplitude(pwaveformp->inputType); if (pwaveform->bptr == NULL) { pwaveform->udf = 1; return ERROR; } pwaveform->nord = pwaveform->nelm; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformPacFlag, ("write_waveform: record name: '%s' of type: %d scaled cal wf by ampl\n", pwaveform->name, pwaveformp->inputType)); #endif break; case (PAC_I_REF): case (PAC_Q_REF): case (PAC_I_CALREF): case (PAC_Q_CALREF): case (SPAC_I_REF): case (SPAC_Q_REF): /* Change the contents of the reference waveforms by reading in the new desired waveforms from file. The choice is coming from a global variable which has been set by an mbbo record */ pwaveform->bptr = pacLoadWaveformFromFile(pwaveformp->inputType, pwaveform->nelm); if (pwaveform->bptr == NULL) { pwaveform->udf = 1; return ERROR; } pwaveform->nord = pwaveform->nelm; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformPacFlag, ("write_waveform: record name: '%s' of type: %d loaded wf from file\n", pwaveform->name, pwaveformp->inputType)); #endif break; /* This type is used by slow update PVs to draw that waveform on GUI */ case (PAC_I_FPGA): case (PAC_Q_FPGA): case (PAC_I_DIAG): case (PAC_Q_DIAG): pwaveform->bptr = pacCopyFPGAContents(pwaveformp->inputType); pwaveform->nord = PAC_FPGA_SIZE; if (pwaveform->bptr == NULL) { pwaveform->udf = 1; return ERROR; } break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformPacFlag, ("write_waveform: record name: '%s' has unrecognized type: %d\n", pwaveform->name, pwaveformp->inputType)); #endif pwaveform->udf = 1; return ERROR; } pwaveform->val = pwaveform->bptr; pwaveform->udf = 0; return OK; }