/*============================================================================= Name: devLongoutPad.c Abs: Device support for LCLS PAD 4 channel ADC module (Arcturus Coldfire 5282 processor with LTC2208 ADC) longout records. Derived from $EPICS/base/src/rec/longoutRecord.c Auth: 16-nov-2005, Dayle Kotturi (dayle): Initial version for LLRF PAD Updated: 02-mar-2010, Shantha Condamoor (scondam): Initial version for Klystron Test Station 01 Interlocking with PAD. -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) xx-xxx-2007, Dayle Kotturi: xxxxxxxxxxxxxxxxxxx =============================================================================*/ #include #include #include #include "alarm.h" #include "cvtTable.h" #include "dbDefs.h" #include "devLib.h" #include "dbAccess.h" #include "recSup.h" #include "callback.h" #include "devSup.h" #include "dbScan.h" /* for SCAN_IO_EVENT */ #include "link.h" #include "longoutRecord.h" /* for longoutRecord structure */ #include "epicsExport.h"/* for epicsExportAddress */ #include /* for DEBUGPRINT */ #include "padMacros.h" #include "drvPadLan9118.h" /* for pad* */ typedef struct loPad_s { int routine; /* O=sample offset, 1=sample size */ int type; /* 0=raw interlaced, 1=raw non-interlaced */ int channel; int sample; } loPad_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write_write; } LONGDSET; #ifdef DEBUG_PRINT int devLongoutPadFlag = 2; #endif LOCAL long init_longout(); LOCAL long longout_ioinfo(); LOCAL long write_longout(); LONGDSET devLongoutPad = {5, NULL, NULL, init_longout, longout_ioinfo, write_longout}; epicsExportAddress(dset, devLongoutPad); LOCAL long init_longout(struct longoutRecord *plongout) { loPad_t *plop; /* Allocate the memory for this records private data structure */ plop = (loPad_t *) malloc(sizeof(loPad_t)); if (plop == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutPadFlag, ("init_longout: %s: out of memory\n", plongout->name)); #endif return S_dev_noMemory; } /* Read the DBLINK "out" field to get the routine */ DEBUGPRINT(DP_INFO, devLongoutPadFlag, ("init_longout: %s: has parm: %s\n", plongout->name, plongout->out.value.instio.string)); sscanf(plongout->out.value.instio.string, "%d %d %d %d", &(plop->routine), &(plop->type), &(plop->channel), &(plop->sample)); DEBUGPRINT(DP_INFO, devLongoutPadFlag, ("init_longout: %s's dpvt has routine: %d, type: %d, channel %d and sample: %d\n", plongout->name, plop->routine, plop->type, plop->channel, plop->sample)); /* Tell the record about its private data structure */ plongout->dpvt = plop; return 0; } LOCAL long longout_ioinfo( int cmd, struct longoutRecord *plongout, IOSCANPVT *ppvt ) { return 0; } LOCAL long write_longout(struct longoutRecord *plongout) { int rc; loPad_t *plop; /* Set this to facilitate easy access to index field */ if (plongout->dpvt == NULL) { DEBUGPRINT(DP_ERROR, devLongoutPadFlag, ("write_longout: %s: dpvt is NULL\n", plongout->name)); return ERROR; } plop = (loPad_t *)plongout->dpvt; switch (plop->routine) { case 0: rc = padSetSampleOffset(plop->channel, plop->sample, (int)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutPadFlag, ("write_longout: %s: unable to set sample offset to: %d", plongout->name, (int) plongout->val)); /*plongout->sevr = INVALID; or something */ } break; case 1: rc = padSetSampleSize(plop->type, plop->channel, plop->sample, (int)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutPadFlag, ("write_longout: %s: unable to set sample size to: %d", plongout->name, (int) plongout->val)); /* plongout->sevr = INVALID; or something */ } break; #ifdef PAD_SIMPLE_PROCESSING /* cases 2-5 are specific to Interlocking PADs only */ case 2: rc = padSetThreshold(plop->channel, (int)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutPadFlag, ("write_longout: %s: unable to set threshold to: %d", plongout->name, (int) plongout->val)); /* plongout->sevr = INVALID; or something */ } break; case 3: rc = padSetPulseAverage(plop->channel, (int)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutPadFlag, ("write_longout: %s: unable to set number of pulses to average to: %d", plongout->name, (int) plongout->val)); /* plongout->sevr = INVALID; or something */ } break; case 4: rc = padSetScalarS(plop->channel, (short)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutPadFlag, ("write_longout: %s: unable to set the scalar value to: %d", plongout->name, (int) plongout->val)); /* plongout->sevr = INVALID; or something */ } break; case 5: rc = padSetAverageOutPedestal(plop->channel, (int)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutPadFlag, ("write_longout: %s: unable to set pedestal value of Average Out to: %d", plongout->name, (int) plongout->val)); /* plongout->sevr = INVALID; or something */ } break; #endif default: rc = ERROR; DEBUGPRINT(DP_ERROR, devLongoutPadFlag, ("write_longout: %s: unrecognized value in routine: %d", plongout->name, (int) plop->routine)); /* plongout->sevr = INVALID; or something */ } return rc; }