/*============================================================================= Name: devMbboPad.c Abs: Device support for LCLS Beam Charge 4 channel ADC module (Arcturus Coldfire 5282 processor with LTC2208 ADC) multi-bit binary out records. Derived from $EPICS/base/src/rec/mbboRecord.c Auth: 16-nov-2005, Dayle Kotturi (dayle): Initial version for LLRF 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 "mbboRecord.h" /* for longoutRecord structure */ #include "epicsExport.h"/* for epicsExportAddress */ #include /* for DEBUGPRINT */ #include "padLan9118Macros.h" #include "drvPadLan9118.h" /* for padSetOperationMode, padSetCalibrationControl */ typedef struct mbboPad_s { int routine; /* O=state, 1=calibration */ } mbboPad_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write_write; } MBBODSET; #ifdef DEBUG_PRINT int devMbboPadFlag = 2; #endif LOCAL long init_mbbo(); LOCAL long mbbo_ioinfo(); LOCAL long write_mbbo(); MBBODSET devMbboPad = {5, NULL, NULL, init_mbbo, mbbo_ioinfo, write_mbbo}; epicsExportAddress(dset, devMbboPad); LOCAL long init_mbbo(struct mbboRecord *pmbbo) { mbboPad_t *pmbbop; /* Allocate the memory for this records private data structure */ pmbbop = (mbboPad_t *) malloc(sizeof(mbboPad_t)); if (pmbbop == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devMbboPadFlag, ("init_mbbo: %s: out of memory\n", pmbbo->name)); #endif return S_dev_noMemory; } /* Read the DBLINK "out" field to get the routine */ sscanf(pmbbo->out.value.instio.string, "%d", &(pmbbop->routine)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devMbboPadFlag, ("init_mbbo: %s: has parm: %s\n", pmbbo->name, pmbbo->out.value.instio.string)); DEBUGPRINT(DP_INFO, devMbboPadFlag, ("init_mbbo: %s's dpvt has routine: %d\n", pmbbo->name, pmbbop->routine)); #endif /* Tell the record about its private data structure */ pmbbo->dpvt = pmbbop; return 0; } LOCAL long mbbo_ioinfo( int cmd, struct mbboRecord *pmbbo, IOSCANPVT *ppvt ) { return 0; } LOCAL long write_mbbo(struct mbboRecord *pmbbo) { int rc; mbboPad_t *pmbbop; /* Set this to facilitate easy access to index field */ if (pmbbo->dpvt == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devMbboPadFlag, ("write_mbbo: %s: dpvt is NULL\n", pmbbo->name)); #endif return ERROR; } pmbbop = (mbboPad_t *)pmbbo->dpvt; switch (pmbbop->routine) { case 0: rc = padSetOperationMode((int)pmbbo->val); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devMbboPadFlag, ("write_mbbo: %s: setting operation mode to: %d\n", pmbbo->name, (int) pmbbo->val)); #endif #ifdef DEBUG_PRINT if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devMbboPadFlag, ("write_mbbo: %s: unable to set operation mode to: %d\n", pmbbo->name, (int) pmbbo->val)); /*pmbbo->sevr = INVALID; or something */ } #endif break; case 1: rc = padSetCalibrationControl((int)pmbbo->val); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devMbboPadFlag, ("write_mbbo: %s: setting calibration control to: %d\n", pmbbo->name, (int) pmbbo->val)); #endif #ifdef DEBUG_PRINT if (rc == ERROR) { DEBUGPRINT(DP_ERROR, devMbboPadFlag, ("write_mbbo: %s: unable to set calibration control to: %d\n", pmbbo->name, (int) pmbbo->val)); /* pmbbo->sevr = INVALID; or something */ } #endif break; default: rc = ERROR; #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devMbboPadFlag, ("write_mbbo: %s: unrecognized value in routine: %d\n", pmbbo->name, (int) pmbbop->routine)); #endif /* pmbbo->sevr = INVALID; or something */ } return rc; }