/* $Id: devWfRawSig.c,v 1.6 2008/01/30 05:44:15 till Exp $ */ /*============================================================================= Name: devWfRawSig.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: -----------------------------------------------------------------------------*/ #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 #define DEVSUPNAM "devWfRawSig" #define DEBUG_PROC 1 int devWfRawSigDebug = 0; typedef struct DevWfRawSigDpvt_ts_ { struct DrvPadUdpCommDpvtRec_ drvPadUdpCommPart; } DevWfRawSigDpvt_ts, *DevWfRawSigDpvt_tps; /* Forward Declarations */ static long report(int interest) { epicsPrintf(DEVSUPNAM": raw BPM digitizer data into a single waveform\n"); 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 ) { epicsPrintf(DEVSUPNAM": Error -- FTVL should be SHORT (is %i)\n", waveform_ps->ftvl); goto egress; } /* Set NELM to what the driver is configured for */ free(waveform_ps->bptr); waveform_ps->nelm = 4 * drvPadUdpCommGetNsamples(); if ( !(waveform_ps->bptr = calloc(waveform_ps->nelm, sizeof(short))) ) { /* If there's no memory we are unlikely to be able to print something */ goto egress; } if ( VME_IO != waveform_ps->inp.type ) { epicsPrintf(DEVSUPNAM": Error -- INP is not VME_IO (but type %i)\n", waveform_ps->inp.type); goto egress; } if ( !(dpvt_ps = calloc(1, sizeof(*dpvt_ps))) ) { epicsPrintf(DEVSUPNAM": Error -- no memory\n"); goto egress; } waveform_ps->dpvt = dpvt_ps; if ( drvPadUdpCommDpvtInit(&dpvt_ps->drvPadUdpCommPart, waveform_ps->inp.value.vmeio.card) ) goto egress; return 0; egress: waveform_ps->pact = 1; return -1; } #if 0 static long get_ioint_info(int cmd, struct dbCommon *record_ps, IOSCANPVT *pvt_ps) { DevWfRawSigDpvt_tps dpvt_ps = record_ps->dpvt; *pvt_ps = *dpvt_ps->scan_p; return 0; } #endif static long read_waveform(void *record_p) { waveformRecord *waveform_ps = record_p; #if 0 DevWfRawSigDpvt_tps dpvt_ps = waveform_ps->dpvt; #endif void *data; PadReply rply; long rval = 0; int post = 0; int n; struct vmeio *l = &waveform_ps->inp.value.vmeio; if ( devWfRawSigDebug & DEBUG_PROC ) epicsPrintf("Entering READ\n"); if ( !(data = padDataGet(l->card, (PadDataKind)l->signal)) ) { recGblSetSevr(waveform_ps, READ_ALARM, INVALID_ALARM); } else { rply = padReplyFind(data); /* TODO: set timestamp based on value in 'reply' */ n = PADRPLY_STRM_NSAMPLES(ntohs(rply->nBytes)) * 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); } 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)); if ( devWfRawSigDebug & DEBUG_PROC ) epicsPrintf("Leaving READ\n"); return rval; } struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read; } devWfRawSig = { 5, report, init, init_record, drvPadUdpCommGetIointInfo, read_waveform }; epicsExportAddress(dset, devWfRawSig);