/*============================================================================= Name: devAiPad.c Abs: Device support for LCLS Beam Charge 4 channel ADC module (Arcturus Coldfire 5282 processor with LTC2208 ADC) analog in records. Derived from $EPICS/base/src/rec/aiRecord.c Updated: 02-mar-2010, Shantha Condamoor (scondam): Initial version for Klystron Test Station 01 Interlocking with PAD. 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 "aiRecord.h" /* for aiRecord structure */ #include "epicsExport.h"/* for epicsExportAddress */ #include "epicsThread.h"/* for epicsThreadSleepQuantum */ #include /* for DEBUGPRINT */ #include "drvPad.h" /* for pad* */ typedef struct aiPad_s { int channel; } aiPad_t; LOCAL long init_record(); LOCAL long read_ai(); typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read_ai; DEVSUPFUN special_linconv; /* LESSON LEARNED! if you don't put this in, (even when you don't use it), you get the iocInit error that device support for init_record is missing, even though record is created and read_ai processes!!! */ } AIDSET; AIDSET devAiPad = { 6, NULL, NULL, init_record, NULL, read_ai, NULL }; epicsExportAddress(dset,devAiPad); #ifdef DEBUG_PRINT int devAiPadFlag = 4; int devAiSlowADCPadFlag = 4; #endif LOCAL long init_record(aiRecord *pai) { aiPad_t *paip; /* Allocate the memory for this records private data structure */ paip = (aiPad_t *) malloc(sizeof(aiPad_t)); if (paip == NULL) { DEBUGPRINT(DP_ERROR, devAiPadFlag, ("init_ai: %s: out of memory\n", pai->name)); return S_dev_noMemory; } paip->channel = 99; /* for debug */ /* Tell the record about its private data structure */ pai->dpvt = paip; switch(pai->inp.type) { case(INST_IO): sscanf(pai->inp.value.instio.string, "%d", &(paip->channel)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiPadFlag, ("init_ai: %s: init routine with channel: %d\n", pai->name, paip->channel)); #endif break; default: DEBUGPRINT(DP_ERROR, devAiPadFlag, ("init_ai: %s: unrecognized link type\n", pai->name)); return ERROR; } return OK; } LOCAL long read_ai(aiRecord *pai) { aiPad_t *paip; /* Set this to facilitate easy access to channel field */ if (pai->dpvt == NULL) { DEBUGPRINT(DP_ERROR, devAiPadFlag, ("read_ai: %s: dpvt is NULL\n", pai->name)); return ERROR; } paip = (aiPad_t *)pai->dpvt; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiSlowADCPadFlag, ("read_ai: %s: read routine with channel: %d has rval: %lu gets val: %lu\n", pai->name, paip->channel, pai->rval, pai->val)); #endif /* ASLO and AOFF applied by EPICS */ return OK; }