/*============================================================================= 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 = 2; #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 ftvl: %d\n", pwaveform->ftvl)); 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", (unsigned long) pwaveform->nelm)); DEBUGPRINT(DP_INFO, devWaveformMpsFlag, (" has nord: %lu\n", (unsigned long) 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* x_data_ptr; short* y_volts_data_ptr; unsigned short* y_counts_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 BYKIK waveform in offset binary [0,65535] */ pwaveform->bptr = (unsigned short*) mpsGetRawWaveform(); #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: calling mpsGetRawWaveform()\n", pwaveform->name)); #endif break; case 1: /* BYKIK waveform in volts [-10,10] */ /* 9/24/9 change from float* to double* */ pwaveform->bptr = (double*) mpsGetWaveform(pwaveformp->rise, pwaveformp->run, pwaveformp->offset, pwaveform->nelm); #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: calling mpsGetWaveform(rise:%d, run:%d, offset:%d, nelm:%d)\n", pwaveform->name, pwaveformp->rise, pwaveformp->run, pwaveformp->offset, pwaveform->nelm)); #endif break; case 2: /* Raw High Threshold in offset binary [0,65535]. Put same value in two endpoints to be able to draw horizontal line on xy graph */ node_ptr = mpsGetNode(); /* 9/24/9 change from void* to unsigned short* */ pwaveform->bptr = (unsigned short*) &(node_ptr->BYKThresholdHighCountsArray); #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: setting bptr to BYKThresholdHighCountsArray\n", pwaveform->name)); #endif break; case 3: /* Raw Low Threshold in offset binary [0,65535] */ node_ptr = mpsGetNode(); /* 9/24/9 change from void* to unsigned short* */ pwaveform->bptr = (unsigned short*) &(node_ptr->BYKThresholdLowCountsArray); #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: setting bptr to BYKThresholdLowCountsArray\n", pwaveform->name)); #endif break; case 4: /* Array of constants used for X variable */ x_data_ptr = pwaveform->bptr; *x_data_ptr = 0; x_data_ptr++; *x_data_ptr = 1000; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: setting array to [-10,10]\n", pwaveform->name)); #endif break; case 5: /* High Threshold in volts [-10,10] */ node_ptr = mpsGetNode(); /* 9/24/9 change from void* to double* */ pwaveform->bptr = (double*) &(node_ptr->BYKThresholdHighVoltsArray); #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: node_ptr->BYKThresholdHighVolts=%g\n", pwaveform->name, node_ptr->BYKThresholdHighVoltsArray[0])); #endif break; case 6: /* Low Threshold in volts [-10,10] */ node_ptr = mpsGetNode(); /* 9/24/9 change from void* to double* */ pwaveform->bptr = (double*) &(node_ptr->BYKThresholdLowVoltsArray); #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: node_ptr->BYKThresholdLowVolts=%g\n", pwaveform->name, node_ptr->BYKThresholdLowVoltsArray[0])); #endif break; case 7: /* BYKIK ADC presample wf */ pwaveform->bptr = mpsGetBYKBeginSample(); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformMpsFlag, ("read_waveform %s: node_ptr->BYKADCPresampleArray=%hd,%hd\n", pwaveform->name, *((short*) (pwaveform->bptr)), *((short*) (pwaveform->bptr+1)))); #endif break; case 8: /* BYKIK ADC sample wf */ pwaveform->bptr = mpsGetBYKEndSample(); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformMpsFlag, ("read_waveform %s: node_ptr->BYKADCSampleArray=%hd,%hd\n", pwaveform->name, *((short*) (pwaveform->bptr)), *((short*) (pwaveform->bptr+1)))); #endif break; case 9: /* Array of constants used for Y volts variable */ y_volts_data_ptr = pwaveform->bptr; *y_volts_data_ptr = -10; y_volts_data_ptr++; *y_volts_data_ptr = 10; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: setting array to [-10,10]\n", pwaveform->name)); #endif break; case 10: /* Array of constants used for Y counts variable */ y_counts_data_ptr = pwaveform->bptr; *y_counts_data_ptr = 0; y_counts_data_ptr++; *y_counts_data_ptr = 65535; #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devWaveformMpsFlag, ("read_waveform %s: setting array to [0,65535]\n", pwaveform->name)); #endif break; } /* from RRM: Device support must set nord when it completes. */ pwaveform->val = pwaveform->bptr; 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