/*============================================================================= Name: devWaveformMps.c Abs: Device support for LCLS MPS Link Node waveform records. Derived from $EPICS/base/src/rec/waveformRecord.c At time of creation, only the MPS Link Nodes of BYKIK mode need this record. So, while this record will be loaded onto all the nodes because they all load the same database, this record will not process for the other types of link nodes. Auth: 17-dec-2008, Dayle Kotturi (dayle): Initial version -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) xx-xxx-2007, Dayle Kotturi: xxxxxxxxxxxxxxxxxxx =============================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include /* for SCAN_IO_EVENT */ #include #include /* for waveformRecord structure */ #include /* for epicsExportAddress */ #include /* for DEBUGPRINT */ #include "mpsLinkNodeMacros.h" /* for MODE */ #include "drvMpsLinkNode.h" /* for mpsGetWaveform */ /* 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 waveformMps_s { int inputType; /* raw vs. processed */ int rise; int run; int offset; } waveformMps_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read_write; } WFDSET; #ifdef DEBUG_PRINT int devWaveformMpsFlag = 4; #endif int mpsOverwriting = FALSE; LOCAL long init_waveform(); LOCAL long waveform_ioinfo(); LOCAL long read_waveform(); #ifndef SCANIO short* mpsFakeSignal(int n); short fakeSignal[MPS_FIFO_SIZE]; #endif WFDSET devWaveformMpsLinkNode = {5, NULL, NULL, init_waveform, waveform_ioinfo, read_waveform}; epicsExportAddress(dset, devWaveformMpsLinkNode); /* 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) { waveformMps_t *pwaveformp; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformMpsFlag, ("init_waveform %s:\n", pwaveform->name)); #endif switch(pwaveform->inp.type) { case(INST_IO): /* Allocate the memory for this records private data structure */ pwaveformp = (waveformMps_t *) malloc(sizeof(waveformMps_t)); if (pwaveformp == NULL) { return S_dev_noMemory; } /* Tell the record about its private data structure */ pwaveform->dpvt = pwaveformp; sscanf(pwaveform->inp.value.instio.string, "%d %d %d %d", &(pwaveformp->inputType), &(pwaveformp->rise), &(pwaveformp->run), &(pwaveformp->offset)); pwaveform->nord = pwaveform->nelm; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformMpsFlag, (" has instio.string: %s\n", pwaveform->inp.value.instio.string)); DEBUGPRINT(DP_INFO, devWaveformMpsFlag, (" has inputType: %d\n", pwaveformp->inputType)); DEBUGPRINT(DP_INFO, devWaveformMpsFlag, (" has rise: %d\n", pwaveformp->rise)); DEBUGPRINT(DP_INFO, devWaveformMpsFlag, (" has run: %d\n", pwaveformp->run)); DEBUGPRINT(DP_INFO, devWaveformMpsFlag, (" has offset: %d\n", pwaveformp->offset)); DEBUGPRINT(DP_INFO, devWaveformMpsFlag, (" has nelm: %lu\n", pwaveform->nelm)); DEBUGPRINT(DP_INFO, devWaveformMpsFlag, (" has nord: %lu\n", pwaveform->nord)); DEBUGPRINT(DP_INFO, devWaveformMpsFlag, (" has val: 0x%08x\n", (unsigned int) pwaveform->val)); #endif pwaveform->val = pwaveform->bptr; pwaveform->udf = 0; break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformMpsFlag, ("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 = mpsGetIoScanPvt(); #endif return OK; } LOCAL long read_waveform(struct waveformRecord *pwaveform) { waveformMps_t *pwaveformp; mpsNode_t* node_ptr; unsigned short* data_ptr; /* Facilitate access to device private structure */ pwaveformp = (waveformMps_t *)pwaveform->dpvt; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s:\n", pwaveform->name)); #endif switch (pwaveformp->inputType) { case 0: /* Raw */ pwaveform->bptr = (unsigned short*) mpsGetRawWaveform(); pwaveform->val = pwaveform->bptr; break; case 1: /* Processed */ pwaveform->bptr = (short*) mpsGetWaveform(pwaveformp->rise, pwaveformp->run, pwaveformp->offset, pwaveform->nelm); pwaveform->val = pwaveform->bptr; break; case 2: /* Low Threshold */ node_ptr = mpsGetNode(); pwaveform->bptr = (void*) &(node_ptr->BYKThresholdLowCountsArray); pwaveform->val = pwaveform->bptr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: node_ptr->BYKThresholdLowCounts=%hd\n", pwaveform->name, node_ptr->BYKThresholdLowCountsArray[0])); #endif break; case 3: /* High Threshold. Put same value in two endpoints to be able to draw horizontal line on xy graph */ node_ptr = mpsGetNode(); pwaveform->bptr = (void*) &(node_ptr->BYKThresholdHighCountsArray); pwaveform->val = pwaveform->bptr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: node_ptr->BYKThresholdHighCounts=%hd\n", pwaveform->name, node_ptr->BYKThresholdHighCountsArray[0])); #endif break; case 4: /* array is constant. just used for display */ data_ptr = pwaveform->bptr; *data_ptr = 0; data_ptr++; *data_ptr = 1000; break; } /* from RRM: Device support must set nord when it completes. */ pwaveform->nord = pwaveform->nelm; pwaveform->udf = 0; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: nord,nelm=%d\n", pwaveform->name, (int) pwaveform->nelm)); #endif return OK; } #ifndef SCANIO short* mpsFakeSignal(int nelm) { int i; if (nelm > MPS_FIFO_SIZE) { nelm = MPS_FIFO_SIZE; } for (i=0; i