/* $Id: devWaveformBlm.c,v 1.4 2010/03/04 23:12:48 qing Exp $ */ /*============================================================================= Name: devWaveformBlm.c Abs: Device support for saving raw digitizer data into a waveform (4 channels into a single, row-major array). Auth: 10-nov-2006, Till Straumann (TSS) Rev: 11-aug-2008, Dayle Kotturi adapted for bunch length monitor -----------------------------------------------------------------------------*/ #if 0 #include "copyright_SLAC.h" /* SLAC copyright comments */ #endif /*----------------------------------------------------------------------------- Mod: (see CVS log) =============================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "drvBlm.h" #ifdef DEBUG_PRINT int devWaveformBlmFlag = 2; #endif typedef struct DevWfRawSigDpvt_ts_ { struct DrvPadUdpCommDpvtRec_ drvPadUdpCommPart; int station_type; } DevWfRawSigDpvt_ts, *DevWfRawSigDpvt_tps; /* Forward Declarations */ static long report(int interest) { return 0; } static long init(int after) { return 0; } static long init_record(void *record_p) { waveformRecord *waveform_ps = record_p; DevWfRawSigDpvt_tps dpvt_ps; /* Check DB configuration */ /* if ( waveform_ps->ftvl != menuFtypeSHORT ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("init_waveform: Record %s: Error -- FTVL should be SHORT (is %i)\n", waveform_ps->name, waveform_ps->ftvl)); #endif waveform_ps->pact = 1; return -1; } */ /* Set NELM to what the driver is configured for */ free(waveform_ps->bptr); if ( waveform_ps->ftvl == menuFtypeLONG ) { waveform_ps->nelm = 2*drvPadUdpCommGetNsamples(); } if ( waveform_ps->ftvl == menuFtypeSHORT ) { waveform_ps->nelm = 4*drvPadUdpCommGetNsamples(); } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("init_waveform: Record %s: NELM is %lu)\n", waveform_ps->name, waveform_ps->nelm)); #endif if ( !(waveform_ps->bptr = calloc(waveform_ps->nelm, sizeof(short))) ) { /* If there's no memory we are unlikely to be able to print something */ waveform_ps->pact = 1; return -1; } if ( VME_IO != waveform_ps->inp.type ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("init_waveform: Record %s: Error -- INP is not VME_IO (but type %i)\n", waveform_ps->name, waveform_ps->inp.type)); #endif waveform_ps->pact = 1; return -1; } if ( !(dpvt_ps = calloc(1, sizeof(*dpvt_ps))) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("init_waveform: Record %s: Error -- no memory)\n", waveform_ps->name)); #endif waveform_ps->pact = 1; return -1; } waveform_ps->dpvt = dpvt_ps; if ( drvPadUdpCommDpvtInit(&dpvt_ps->drvPadUdpCommPart, waveform_ps->inp.value.vmeio.card) ) { waveform_ps->pact = 1; return -1; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("init_waveform: Record %s: DPVT initialized)\n", waveform_ps->name)); #endif dpvt_ps->station_type = waveform_ps->inp.value.vmeio.card; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("init_waveform: Record %s setting station to card #%d\n", waveform_ps->name, dpvt_ps->station_type)); #endif return 0; } static long read_waveform(void *record_p) { waveformRecord *waveform_ps = record_p; DevWfRawSigDpvt_tps dpvt_ps = waveform_ps->dpvt; void *data; PadReply rply; long rval = 0; int post = 0; int n; struct vmeio *l = &waveform_ps->inp.value.vmeio; blm_station_t* pblm_2101; blm_station_t* pblm_2102; blm_station_t* pblm_2401; blm_station_t* pblm_2402; blm_station_t* pblf_und1; /* Note: l->card is redundant with dpvt_ps->station_type */ if ( !(data = padDataGet(l->card, (PadDataKind)l->signal)) ) { recGblSetSevr(waveform_ps, READ_ALARM, INVALID_ALARM); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("read_waveform: Record %s bad read of card %d and data kind %d\n", waveform_ps->name, l->card, (int)l->signal)); #endif } else { rply = padReplyFind(data); n = PADRPLY_STRM_NSAMPLES(rply) * PADRPLY_STRM_NCHANNELS; if ( n > waveform_ps->nelm ) n = waveform_ps->nelm; if ( n != waveform_ps->nord ) { waveform_ps->nord = n; post |= 1; } memcpy(waveform_ps->bptr, rply->data, n * sizeof(int16_t)); /* release data object */ padDataFree(data); switch (dpvt_ps->station_type) { case BLM_2101: pblm_2101=(blm_station_t*) blmGetStation(dpvt_ps->station_type); if (pblm_2101 == (blm_station_t*) NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("read_waveform: Record %s got NULL from llrfGetFeedbackStation\n", waveform_ps->name)); #endif return ERROR; } pblm_2101->sum[0]=*(long*) (waveform_ps->bptr); pblm_2101->sum[1]=*(long*) (waveform_ps->bptr+4); pblm_2101->sum[2]=*(long*) (waveform_ps->bptr+8); pblm_2101->sum[3]=*(long*) (waveform_ps->bptr+12); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("read_waveform: Record %s has averages ch0: %ld ch1: %ld ch2: %ld ch3: %ld\n", waveform_ps->name, pblm_2101->sum[0], pblm_2101->sum[1], pblm_2101->sum[2], pblm_2101->sum[3])); #endif break; case BLM_2102: pblm_2102=(blm_station_t*) blmGetStation(dpvt_ps->station_type); if (pblm_2102 == (blm_station_t*) NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("read_waveform: Record %s got NULL from llrfGetFeedbackStation\n", waveform_ps->name)); #endif return ERROR; } pblm_2102->sum[0]=*(long*) (waveform_ps->bptr); pblm_2102->sum[1]=*(long*) (waveform_ps->bptr+4); pblm_2102->sum[2]=*(long*) (waveform_ps->bptr+8); pblm_2102->sum[3]=*(long*) (waveform_ps->bptr+12); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("read_waveform: Record %s has averages ch0: %ld ch1: %ld ch2: %ld ch3: %ld\n", waveform_ps->name, pblm_2102->sum[0], pblm_2102->sum[1], pblm_2102->sum[2], pblm_2102->sum[3])); #endif break; case BLM_2401: pblm_2401=(blm_station_t*) blmGetStation(dpvt_ps->station_type); if (pblm_2401 == (blm_station_t*) NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("read_waveform: Record %s got NULL from llrfGetFeedbackStation\n", waveform_ps->name)); #endif return ERROR; } /* pblm_2401->sum[0]=*(short*) (waveform_ps->bptr); pblm_2401->sum[1]=*(short*) (waveform_ps->bptr+2); pblm_2401->sum[2]=*(short*) (waveform_ps->bptr+4); pblm_2401->sum[3]=*(short*) (waveform_ps->bptr+6); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("read_waveform: Record %s has averages ch0: %hd ch1: %hd ch2: %hd ch3: %hd\n", waveform_ps->name, pblm_2401->sum[0], pblm_2401->sum[1], pblm_2401->sum[2], pblm_2401->sum[3])); #endif */ pblm_2401->sum[0]=*(long*) (waveform_ps->bptr); pblm_2401->sum[1]=*(long*) (waveform_ps->bptr+4); pblm_2401->sum[2]=*(long*) (waveform_ps->bptr+8); pblm_2401->sum[3]=*(long*) (waveform_ps->bptr+12); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("read_waveform: Record %s has averages ch0: %ld ch1: %ld ch2: %ld ch3: %ld\n", waveform_ps->name, pblm_2401->sum[0], pblm_2401->sum[1], pblm_2401->sum[2], pblm_2401->sum[3])); #endif break; case BLM_2402: pblm_2402=(blm_station_t*) blmGetStation(dpvt_ps->station_type); if (pblm_2402 == (blm_station_t*) NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("read_waveform: Record %s got NULL from llrfGetFeedbackStation\n", waveform_ps->name)); #endif return ERROR; } pblm_2402->sum[0]=*(long*) (waveform_ps->bptr); pblm_2402->sum[1]=*(long*) (waveform_ps->bptr+4); pblm_2402->sum[2]=*(long*) (waveform_ps->bptr+8); pblm_2402->sum[3]=*(long*) (waveform_ps->bptr+12); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("read_waveform: Record %s has averages ch0: %ld ch1: %ld ch2: %ld ch3: %ld\n", waveform_ps->name, pblm_2402->sum[0], pblm_2402->sum[1], pblm_2402->sum[2], pblm_2402->sum[3])); #endif break; case BLF_UND1: pblf_und1=(blm_station_t*) blmGetStation(dpvt_ps->station_type); if (pblf_und1 == (blm_station_t*) NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("read_waveform: Record %s got NULL from llrfGetFeedbackStation\n", waveform_ps->name)); #endif return ERROR; } pblf_und1->sum[0]=*(long*) (waveform_ps->bptr); pblf_und1->sum[1]=*(long*) (waveform_ps->bptr+4); pblf_und1->sum[2]=*(long*) (waveform_ps->bptr+8); pblf_und1->sum[3]=*(long*) (waveform_ps->bptr+12); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("read_waveform: Record %s has averages ch0: %ld ch1: %ld ch2: %ld ch3: %ld\n", waveform_ps->name, pblf_und1->sum[0], pblf_und1->sum[1], pblf_und1->sum[2], pblf_und1->sum[3])); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("read_waveform: Record %s unrecognized station type: %d\n", waveform_ps->name, dpvt_ps->station_type)); #endif return ERROR; } } if ( post & 1 ) db_post_events(waveform_ps, &waveform_ps->nord, (DBE_VALUE|DBE_LOG)); if ( post & 2 ) db_post_events(waveform_ps, &waveform_ps->rarm, (DBE_VALUE|DBE_LOG)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("read_waveform: Record %s done\n", waveform_ps->name)); #endif return rval; } struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read; } devWaveformBlm = { 5, report, init, init_record, drvPadUdpCommGetIointInfo, read_waveform }; epicsExportAddress(dset, devWaveformBlm);