/*============================================================================= Name: devLongoutBcc.c Abs: Device support for LCLS Beam Charge 4 channel ADC module (Arcturus Coldfire 5282 processor with LTC2208 ADC) long output records. Derived from $EPICS/base/src/rec/longoutRecord.c Auth: 16-nov-2005, Dayle Kotturi (dayle): Initial version for LLRF PAD -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) 18-jan-2007, Dayle Kotturi: Adapted for BeamChargeCFApp =============================================================================*/ #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 "drvBeamChargeCF.h" /* for bcc* */ typedef struct loBcc_s { int routine; /* O=sample offset, 1=sample size */ int channel; } loBcc_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write_write; } LONGDSET; #ifdef DEBUG_PRINT int devLongoutBccFlag = 4; #endif LOCAL long init_longout(); LOCAL long longout_ioinfo(); LOCAL long write_longout(); LONGDSET devLongoutBeamChargeCF = {5, NULL, NULL, init_longout, longout_ioinfo, write_longout}; epicsExportAddress(dset, devLongoutBeamChargeCF); LOCAL long init_longout(struct longoutRecord *plongout) { loBcc_t *plop; /* Allocate the memory for this records private data structure */ plop = (loBcc_t *) malloc(sizeof(loBcc_t)); if (plop == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutBccFlag, ("init_longout: %s: out of memory\n", plongout->name)); #endif return S_dev_noMemory; } /* Read the DBLINK "out" field to get the routine */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutBccFlag, ("init_longout: %s: has parm: %s\n", plongout->name, plongout->out.value.instio.string)); sscanf(plongout->out.value.instio.string, "%d %d", &(plop->routine), &(plop->channel)); DEBUGPRINT(DP_INFO, devLongoutBccFlag, ("init_longout: %s's dpvt has routine: %d, channel %d\n", plongout->name, plop->routine, plop->channel)); #endif /* 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; loBcc_t *plop; /* Set this to facilitate easy access to index field */ if (plongout->dpvt == NULL) { DEBUGPRINT(DP_ERROR, devLongoutBccFlag, ("write_longout: %s: dpvt is NULL\n", plongout->name)); return ERROR; } plop = (loBcc_t *)plongout->dpvt; switch (plop->routine) { case 0: rc = bccSetSampleOffset(plop->channel, (int)plongout->val); if (rc == ERROR) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutBccFlag, ("write_longout: %s: unable to set sample offset to: %d", plongout->name, (int) plongout->val)); #endif /*plongout->sevr = INVALID; or something */ } break; case 1: rc = bccSetSampleSize(plop->channel, (int)plongout->val); if (rc == ERROR) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutBccFlag, ("write_longout: %s: unable to set sample size to: %d", plongout->name, (int) plongout->val)); #endif /* plongout->sevr = INVALID; or something */ } break; default: rc = ERROR; #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutBccFlag, ("write_longout: %s: unrecognized value in routine: %d", plongout->name, (int) plop->routine)); #endif /* plongout->sevr = INVALID; or something */ } return rc; }