/*============================================================================= Name: devWaveformBcc.c Abs: Device support for LCLS Beam Charge 4 channel ADC module (Arcturus Coldfire 5282 processor with LTC2208 ADC) waveform records. Derived from $EPICS/base/src/rec/waveformRecord.c Auth: 16-nov-2005, Dayle Kotturi (dayle): Initial version for LLRF BCC -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) 18-jan-2007, Dayle Kotturi: Adapted for BeamChargeCFApp =============================================================================*/ #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 "BeamChargeCFMacros.h" #include "drvBeamChargeCF.h" /* for bccGetSampleSize, bccGetSignal, BCC_FIFO_SIZE */ /* 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 waveformBcc_s { unsigned long initialNelm; /* not useful. could be removed */ int channel; } waveformBcc_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read_write; } WFDSET; #ifdef DEBUG_PRINT int devWaveformBccFlag = 4; #endif int bccOverwriting = FALSE; int bccWF = 0; LOCAL long init_waveform(); LOCAL long waveform_ioinfo(); LOCAL long read_waveform(); #ifndef SCANIO short * bccFakeSignal(int n); short fakeSignal[BCC_FIFO_SIZE]; #endif WFDSET devWaveformBeamChargeCF = {5, NULL, NULL, init_waveform, waveform_ioinfo, read_waveform}; epicsExportAddress(dset, devWaveformBeamChargeCF); /* 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 */ LOCAL long init_waveform(struct waveformRecord *pwaveform) { waveformBcc_t *pwaveformp; switch(pwaveform->inp.type) { case(INST_IO): /* Allocate the memory for this records private data structure */ pwaveformp = (waveformBcc_t *) malloc(sizeof(waveformBcc_t)); if (pwaveformp == NULL) { return S_dev_noMemory; } /* Tell the record about its private data structure */ pwaveform->dpvt = pwaveformp; /* The first value in "string" specifies what is to be done 0 : read the FIFO (this is the case for acquiring the raw ADC data) 1 : read from a file (this is the case for the scalar correction) */ sscanf(pwaveform->inp.value.instio.string, "%d", &(pwaveformp->channel)); pwaveformp->initialNelm = pwaveform->nelm; pwaveform->nord = pwaveform->nelm; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBccFlag, ("init_waveform %s:\n", pwaveform->name)); DEBUGPRINT(DP_INFO, devWaveformBccFlag, (" has instio.string: %s\n", pwaveform->inp.value.instio.string)); DEBUGPRINT(DP_INFO, devWaveformBccFlag, (" has channel: %d\n", pwaveformp->channel)); DEBUGPRINT(DP_INFO, devWaveformBccFlag, (" has nelm: %lu\n", pwaveform->nelm)); DEBUGPRINT(DP_INFO, devWaveformBccFlag, (" has initialNelm: %lu\n", pwaveformp->initialNelm)); DEBUGPRINT(DP_INFO, devWaveformBccFlag, (" has nord: %lu\n", pwaveform->nord)); DEBUGPRINT(DP_INFO, devWaveformBccFlag, (" has val: 0x%08x\n", (unsigned int) pwaveform->val)); #endif /* Changes here. 3/24/2006. Reasons: 1) to avoid memcpy into bptr in the read (below), bptr is getting freed and set to bccSignal. 2) nelm is going to be changed on-the-fly via records so allocating bptr to an array of length NELM in iocInit no longer makes sense */ free(pwaveform->bptr); pwaveform->udf = 0; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBccFlag, ("init_waveform: %s: unrecognized link type: %d", pwaveform->name, (int) pwaveform->inp.type)); #endif break; } return OK; } LOCAL long waveform_ioinfo( int cmd, struct waveformRecord *pwaveform, IOSCANPVT *ppvt ) { #ifdef SCANIO *ppvt = bccGetIoScanPvt(); #endif return OK; } LOCAL long read_waveform(struct waveformRecord *pwaveform) { waveformBcc_t *pwaveformp; /* Facilitate access to device private structure */ pwaveformp = (waveformBcc_t *)pwaveform->dpvt; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBccFlag, ("read_waveform %s:\n", pwaveform->name)); DEBUGPRINT(DP_INFO, devWaveformBccFlag, (" has channel: %d\n", pwaveformp->channel)); #endif /* bccGetSignal returns array based on args passed in */ pwaveform->bptr = bccGetSignal(pwaveformp->channel); bccWF++; pwaveform->nelm = bccGetSampleSize(pwaveformp->channel); /* If SCAN is "I/O Intr", use timestamp from EVR; otherwise leave alone if (pwaveform->scan == SCAN_IO_EVENT && pwaveform->tse == -2) { bccOverwriting = TRUE; pwaveform->time = ...; }*/ pwaveform->val = pwaveform->bptr; /* from RRM: Device support must set nord when it completes. */ pwaveform->nord = pwaveform->nelm; pwaveform->udf = 0; return OK; } #ifndef SCANIO short * bccFakeSignal(int nelm) { int i; if (nelm > BCC_FIFO_SIZE) { nelm = BCC_FIFO_SIZE; } for (i=0; i