/*============================================================================= Name: devWaveformPll.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 PAD -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) 28-jan-2008, Robert Steele: Adaptation for LLRF PLL xx-xxx-2007, Dayle Kotturi: xxxxxxxxxxxxxxxxxxx =============================================================================*/ #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" #include "link.h" #include "waveformRecord.h" /* for waveformRecord structure */ #include "epicsExport.h" /* for epicsExportAddress */ #include /* for DEBUGPRINT */ #include "pllMacros.h" #include "pllChannel.hxx" /* 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 waveformPll_s { int inputType; /* defined in macros header */ int channel; int sample; char filename[100]; } waveformPll_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read_write; } WFDSET; #ifdef DEBUG_PRINT int devWaveformPllFlag = 2; #endif LOCAL long init_waveform(); LOCAL long waveform_ioinfo(); LOCAL long read_waveform(); WFDSET devWaveformPll = {5, NULL, NULL, init_waveform, waveform_ioinfo, read_waveform}; epicsExportAddress(dset, devWaveformPll); /* 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) { waveformPll_t *pwaveformp; DEBUGPRINT(DP_INFO, devWaveformPllFlag, ("init_waveform %s:\n", pwaveform->name)); switch(pwaveform->inp.type) { case(INST_IO): /* Allocate the memory for this records private data structure */ pwaveformp = (waveformPll_t *) malloc(sizeof(waveformPll_t)); if (pwaveformp == NULL) { return S_dev_noMemory; } /* Tell the record about its private data structure */ pwaveform->dpvt = pwaveformp; /* The first value in inp.value.instio.string specifies input type 0 : interlaced raw data from ADC's FIFO */ sscanf(pwaveform->inp.value.instio.string, "%d %d %d %s", &(pwaveformp->inputType), &(pwaveformp->channel), &(pwaveformp->sample), (pwaveformp->filename)); pwaveform->nord = pwaveform->nelm; DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has instio.string: %s\n", pwaveform->inp.value.instio.string)); DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has inputType: %d\n", pwaveformp->inputType)); DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has channel: %d\n", pwaveformp->channel)); DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has sample: %d\n", pwaveformp->sample)); DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has filename: %s\n", pwaveformp->filename)); DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has nelm: %lu\n", pwaveform->nelm)); DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has nord: %lu\n", pwaveform->nord)); DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has val: 0x%08x\n", (unsigned int) pwaveform->val)); switch (pwaveformp->inputType) { case PLL_RawWaveform: case PLL_TrackingBuffer: case PLL_Memory_read: case PLL_hardware_image: break; default: DEBUGPRINT(DP_ERROR, devWaveformPllFlag, ("init_waveform: %s: unrecognized inputType: %d\n", pwaveform->name, (int) pwaveformp->inputType)); break; } pwaveform->val = pwaveform->bptr; pwaveform->udf = 0; break; default: DEBUGPRINT(DP_ERROR, devWaveformPllFlag, ("init_waveform: %s: unrecognized link type: %d", pwaveform->name, (int) pwaveform->inp.type)); break; } return OK; } LOCAL long waveform_ioinfo( int cmd, struct waveformRecord *pwaveform, IOSCANPVT *ppvt ) { *ppvt = pllGetIoScanPvt(); return OK; } LOCAL long read_waveform(struct waveformRecord *pwaveform) { waveformPll_t *pwaveformp; /* Facilitate access to device private structure */ pwaveformp = (waveformPll_t *)pwaveform->dpvt; DEBUGPRINT(DP_INFO, devWaveformPllFlag, ("read_waveform %s:\n", pwaveform->name)); /* DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has inputType: %d\n", pwaveformp->inputType)); DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has channel: %d\n", pwaveformp->channel)); DEBUGPRINT(DP_INFO, devWaveformPllFlag, (" has sample: %d\n", pwaveformp->sample)); */ /* pllGetSignal returns array based on args passed in */ pwaveform->bptr = (short *) pllGetSignal( pwaveformp->inputType ); switch (pwaveformp->inputType) { case PLL_RawWaveform: pwaveform->nelm = pllGetSampleWidth(); DEBUGPRINT(DP_DEBUG, devWaveformPllFlag, ("read_waveform %s: nelm=%d from pllGetSampleWidth\n", pwaveform->name, (int) pwaveform->nelm)); break; case PLL_TrackingBuffer: DEBUGPRINT(DP_DEBUG, devWaveformPllFlag, ("read_waveform %s: retrieved 2K buffer of tracking\n", pwaveform->name)); break; case PLL_Memory_read: pwaveform->nelm = pllReadMemoryDataSize(); break; case PLL_hardware_image: pwaveform->nelm = 12; /* fixme! */ break; default: DEBUGPRINT(DP_ERROR, devWaveformPllFlag, ("read_waveform %s: unrecognized inputType: %d\n", pwaveform->name, (int) pwaveformp->inputType)); break; } pwaveform->val = pwaveform->bptr; /* from RRM: Device support must set nord when it completes. */ pwaveform->nord = pwaveform->nelm; pwaveform->udf = 0; DEBUGPRINT(DP_DEBUG, devWaveformPllFlag, ("read_waveform %s: nord,nelm=%d\n", pwaveform->name, (int) pwaveform->nelm)); return OK; }