/*============================================================================= Name: devLongoutPad.c Abs: Device support for LCLS LLRF VME Derived from $EPICS/base/src/rec/longoutRecord.c Auth: 07-jul-2008, Dayle Kotturi (dayle): Initial version for LLRF VME -----------------------------------------------------------------------------*/ #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 "drvLlrf.h" /* for llrfSet* */ typedef struct longoutLlrf_s { int routine; int station; int channel; } loLlrf_t; typedef struct { long number; DEVSUPFUN dev_report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write_longout; } LONGDSET; /* 11/21/8 Writing errors (level 2) has become too invasive to the processor w.r.t. processing the incoming data streams. Set this to 0 */ #ifdef DEBUG_PRINT int devLongoutLlrfFlag = 0; #endif LOCAL long init_longout(); LOCAL long longout_ioinfo(); LOCAL long write_longout(); LONGDSET devLongoutLlrf = {5, NULL, NULL, init_longout, longout_ioinfo, write_longout}; epicsExportAddress(dset, devLongoutLlrf); LOCAL long init_longout(struct longoutRecord *plongout) { loLlrf_t *plop; /* Allocate the memory for this records private data structure */ plop = (loLlrf_t *) malloc(sizeof(loLlrf_t)); if (plop == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutLlrfFlag, ("init_longout: %s: out of memory\n", plongout->name)); #endif return S_dev_noMemory; } /* Read the DBLINK "out" field to get the routine */ sscanf(plongout->out.value.instio.string, "%d %d %d", &(plop->routine), &(plop->station), &(plop->channel)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutLlrfFlag, ("init_longout: %s: has val: %g\n", plongout->name, plongout->val)); DEBUGPRINT(DP_INFO, devLongoutLlrfFlag, ("init_longout: %s: has parm: %s\n", plongout->name, plongout->out.value.instio.string)); DEBUGPRINT(DP_INFO, devLongoutLlrfFlag, ("init_longout: %s's dpvt has routine: %d, station: %d and channel %d\n", plongout->name, (int) plop->routine, (int) plop->station, (int) 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; } /* 6/18/8 These write to the global structures for each station. These values change infrequently and so by storing them in global they can be used in pulse by pulse calcs without wasting a subroutine INP field to pass them. What's missing is the first arg for all the Set routines: the station. */ LOCAL long write_longout(struct longoutRecord *plongout) { int rc; loLlrf_t *plop; /* Set this to facilitate easy access to index field */ plop = (loLlrf_t *)plongout->dpvt; DEBUGPRINT(DP_INFO, devLongoutLlrfFlag, ("write_longout: %s: st %d ch %d val %d", plongout->name, plop->station, plop->channel, (int) plongout->val)); switch (plop->routine) { case 0: rc = llrfSetPhaseOffsetCorrection(plop->station, plop->channel,(double)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutLlrfFlag, ("write_longout: %s: unable to set phase offset correction for st %d ch %d to: %d", plongout->name, plop->station, plop->channel, (int) plongout->val)); /*plongout->sevr = INVALID; or something */ } break; case 1: rc = llrfSetPowerScaleFactor(plop->station, plop->channel,(double)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutLlrfFlag, ("write_longout: %s: unable to set voltage scale factor for st %d ch %d to: %d", plongout->name, plop->station, plop->channel, (int) plongout->val)); /*plongout->sevr = INVALID; or something */ } break; case 2: rc = llrfSetVoltageScaleFactor(plop->station, plop->channel,(double)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutLlrfFlag, ("write_longout: %s: unable to set voltage scale factor for st %d ch %d to: %d", plongout->name, plop->station, plop->channel, (int) plongout->val)); /*plongout->sevr = INVALID; or something */ } break; case 3: rc = llrfSetPhaseWeightingFactor(plop->station, plop->channel,(double)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutLlrfFlag, ("write_longout: %s: unable to set phase weighting factor for st %d ch %d to: %d", plongout->name, plop->station, plop->channel, (int) plongout->val)); } break; case 4: rc = llrfSetAmplWeightingFactor(plop->station, plop->channel,(double)plongout->val); if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devLongoutLlrfFlag, ("write_longout: %s: unable to set ampl weighting factor for st %d ch %d to: %d", plongout->name, plop->station, plop->channel, (int) plongout->val)); } break; default: rc = ERROR; DEBUGPRINT(DP_ERROR, devLongoutLlrfFlag, ("write_longout: %s: unrecognized value in routine: %d", plongout->name, (int) plop->routine)); /* plongout->sevr = INVALID; or something */ } return rc; }