/*============================================================================= Name: devWaveformPad.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) 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" /* for SCAN_IO_EVENT */ #include "link.h" #include "waveformRecord.h" /* for waveformRecord structure */ #include "epicsExport.h" /* for epicsExportAddress */ #include /* for DEBUGPRINT */ #include "padLan9118Macros.h" #include "drvPadLan9118.h" /* for padGetSampleSize, padGetSignal, PAD_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 waveformPad_s { int inputType; /* defined in padMacros.h */ int channel; int sample; char filename[100]; } waveformPad_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read_write; } WFDSET; #ifdef DEBUG_PRINT int devWaveformPadFlag = 2; #endif int padOverwriting = FALSE; LOCAL long init_waveform(); LOCAL long waveform_ioinfo(); LOCAL long read_waveform(); #ifndef SCANIO short * padFakeSignal(int n); short fakeSignal[PAD_FIFO_SIZE]; #endif WFDSET devWaveformPad = {5, NULL, NULL, init_waveform, waveform_ioinfo, read_waveform}; epicsExportAddress(dset, devWaveformPad); /* 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) { waveformPad_t *pwaveformp; int rc; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformPadFlag, ("init_waveform %s:\n", pwaveform->name)); #endif switch(pwaveform->inp.type) { case(INST_IO): /* Allocate the memory for this records private data structure */ pwaveformp = (waveformPad_t *) malloc(sizeof(waveformPad_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 1 : data read from a file (this is the case for the scalar correction) 2 : processed data generated by multiplying raw data by a correction 3 : non-interlaced raw I data from ADC's FIFO (i.e. for signals not running at a multiple of 25.5 MHz where digital downmixing poss. 4 : non-interlaced raw Q data from ADC's FIFO (i.e. for signals not running at a multiple of 25.5 MHz where digital downmixing poss. 5 : data read from a file (scalar non-interlaced I) 6 : data read from a file (scalar non-interlaced Q) */ sscanf(pwaveform->inp.value.instio.string, "%d %d %d %s", &(pwaveformp->inputType), &(pwaveformp->channel), &(pwaveformp->sample), (pwaveformp->filename)); pwaveform->nord = pwaveform->nelm; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has instio.string: %s\n", pwaveform->inp.value.instio.string)); DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has inputType: %d\n", pwaveformp->inputType)); DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has channel: %d\n", pwaveformp->channel)); DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has sample: %d\n", pwaveformp->sample)); DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has filename: %s\n", pwaveformp->filename)); DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has nelm: %lu\n", pwaveform->nelm)); DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has nord: %lu\n", pwaveform->nord)); DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has val: 0x%08x\n", (unsigned int) pwaveform->val)); #endif /* 11/17/2006: If data is to be read in from a file, do it now. The scalar correction arrays are examples of this. TO DO: make filenames embed the PRIM, LOCA, UNIT so that they can be distinguished by instance and co-located */ switch (pwaveformp->inputType) { case PAD_RAW: case PAD_NON_INTERLACED_RAW: case PAD_PROCESSED: case PAD_PROCESSED_NON_INTERLACED_I: case PAD_PROCESSED_NON_INTERLACED_Q: break; case PAD_SCALAR: case PAD_SCALAR_NON_INTERLACED_I: case PAD_SCALAR_NON_INTERLACED_Q: case PAD_CONSTANT: rc = padInitialiseScalarFromFile (pwaveformp->channel, pwaveformp->inputType, pwaveformp->filename); if (rc != OK) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformPadFlag, ("init_waveform: %s: error returned by padInitialseScalarFromFile: channel:%d, filename: %s\n", pwaveform->name, (int) pwaveformp->channel, pwaveformp->filename)); #endif return ERROR; } break; case PAD_PCAV: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformPadFlag, ("init_waveform: %s: has phase cavity waveform type: %d\n", pwaveform->name, (int) pwaveformp->inputType)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformPadFlag, ("init_waveform: %s: unrecognized inputType: %d\n", pwaveform->name, (int) pwaveformp->inputType)); #endif } pwaveform->val = pwaveform->bptr; pwaveform->udf = 0; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformPadFlag, ("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 SCAN_IO *ppvt = padGetIoScanPvt(); #endif return OK; } LOCAL long read_waveform(struct waveformRecord *pwaveform) { waveformPad_t *pwaveformp; /* Facilitate access to device private structure */ pwaveformp = (waveformPad_t *)pwaveform->dpvt; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformPadFlag, ("read_waveform %s:\n", pwaveform->name)); DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has inputType: %d\n", pwaveformp->inputType)); DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has channel: %d\n", pwaveformp->channel)); DEBUGPRINT(DP_INFO, devWaveformPadFlag, (" has sample: %d\n", pwaveformp->sample)); #endif switch (pwaveformp->inputType) { case PAD_SCALAR: case PAD_SCALAR_NON_INTERLACED_I: case PAD_SCALAR_NON_INTERLACED_Q: pwaveform->bptr = (short*) padGetSignal(pwaveformp->channel, pwaveformp->sample, pwaveformp->inputType); break; case PAD_RAW: case PAD_PROCESSED: case PAD_NON_INTERLACED_RAW: case PAD_PROCESSED_NON_INTERLACED_I: case PAD_PROCESSED_NON_INTERLACED_Q: pwaveform->bptr = (short*) padGetSignal(pwaveformp->channel, pwaveformp->sample, pwaveformp->inputType); pwaveform->nelm = padGetSampleSize(pwaveformp->channel, pwaveformp->sample); break; case PAD_CONSTANT: pwaveform->bptr = (short*) padGetSignal(pwaveformp->channel, pwaveformp->sample, pwaveformp->inputType); pwaveform->nelm = 1; break; case PAD_PCAV: pwaveform->bptr = (long*) padGetSignal(pwaveformp->channel, pwaveformp->sample, pwaveformp->inputType); #ifdef DEBUG_DEBUG DEBUGPRINT(DP_INFO, devWaveformPadFlag, ("read_waveform %s: bptr contains: %hd %hd %hd %hd %hd %hd\n", pwaveform->name, *(pwaveform->bptr), *(pwaveform->bptr+1), *(pwaveform->bptr+2), *(pwaveform->bptr+3), *(pwaveform->bptr+4), *(pwaveform->bptr+5), *(pwaveform->bptr+6))); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformPadFlag, ("read_waveform %s: unrecognized inputType: %d\n", pwaveform->name, (int) pwaveformp->inputType)); #endif } pwaveform->val = pwaveform->bptr; /* from RRM: Device support must set nord when it completes. */ pwaveform->nord = pwaveform->nelm; pwaveform->udf = 0; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformPadFlag, ("read_waveform %s: nord,nelm=%d\n", pwaveform->name, (int) pwaveform->nelm)); #endif return OK; } #ifndef SCANIO short * padFakeSignal(int nelm) { int i; if (nelm > PAD_FIFO_SIZE) { nelm = PAD_FIFO_SIZE; } for (i=0; i