/* $Id: devWaveformBlm.c,v 1.5 2013/02/28 02:02:33 gwbrown 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 #include #include "drvBlm.h" #ifdef DEBUG_PRINT int devWaveformBlmFlag = 2; #endif /* 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; int s; long rval = -1; DrvPadUdpCommDpvt dpvt; /* Check DB configuration */ if ( waveform_ps->ftvl != menuFtypeLONG ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("init_waveform: Record %s: Error -- FTVL should be LONG (is %i)\n", waveform_ps->name, waveform_ps->ftvl)); #endif goto bail; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("init_waveform: Record %s: NELM is %u)\n", waveform_ps->name, waveform_ps->nelm)); #endif 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 goto bail; } s = waveform_ps->inp.value.vmeio.card; /* card-number is one-based */ if ( s < 1 || s > BLM_NUM_STATIONS ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformBlmFlag, ("init_waveform: Record %s: Error -- Card # %i out of range (1 - %i)\n", waveform_ps->name, s, BLM_NUM_STATIONS)); #endif goto bail; } dpvt = mallocMustSucceed( sizeof(*dpvt), "devWaveformBlm: no memory for DPVT" ); if ( drvPadUdpCommDpvtInit( dpvt, s ) ) { errlogPrintf("%s (devWaveformBlm - init_record): drvPadUdpCommDpvtInit() failed\n", waveform_ps->name); free(dpvt); goto bail; } waveform_ps->dpvt = dpvt; rval = 0; bail: if ( rval ) { waveform_ps->pact = 1; } return rval;; } static long read_waveform(void *record_p) { waveformRecord *waveform_ps = record_p; int n,i; struct vmeio *l = &waveform_ps->inp.value.vmeio; BlmStation stat_p; unsigned tout; n = BLM_NUM_CHANNELS; if ( n > waveform_ps->nelm ) n = waveform_ps->nelm; /* validity of station index was already verified in init_record() */ stat_p = blmGetStation(l->card); if ( ! stat_p ) { errlogPrintf("%s: read_waveform() -- invalid station index, setting PACT\n", waveform_ps->name); waveform_ps->pact = 1; return -1; } epicsMutexMustLock( stat_p->mutex ); tout = stat_p->timedout; for ( i=0; ibptr)[i] = (epicsInt32)stat_p->chnls[i].sum; } /* just use the time stamp of the *last* channel */ if ( epicsTimeEventDeviceTime == waveform_ps->tse ) { waveform_ps->time = stat_p->chnls[3].tsSum; } epicsMutexUnlock( stat_p->mutex ); if ( (tout & BLM_TIMEDOUT_ANY_RAW) ) { recGblSetSevr( waveform_ps, TIMEOUT_ALARM, INVALID_ALARM ); } if ( n != waveform_ps->nord ) { waveform_ps->nord = n; db_post_events(waveform_ps, &waveform_ps->nord, (DBE_VALUE|DBE_LOG)); } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformBlmFlag, ("read_waveform: Record %s done\n", waveform_ps->name)); #endif return 0; } 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);