/*============================================================================= 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 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 "padLan9118Macros.h" #include "drvPadLan9118.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 = 1; int devAiSlowADCPadFlag = 1; #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)); DEBUGPRINT(DP_INFO, devAiPadFlag, ("init_ai: %s: init routine with channel: %d\n", pai->name, paip->channel)); 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 USING_QSPI /* set up the MUX with value = (channel << 4) + 8 (channel in upper nibble and highest bit of lower nibble set */ padQSPISetMUX(paip->channel*16+8); /* Need a wait between 50 and 150 usec after SetMUX, before the read */ /* 10*epicsThreadSleepQuantum measured to be 200 usec */ /* 2aug06: using 8 so that it gets done fast enough for the 5 sec scan */ epicsThreadSleep(8*epicsThreadSleepQuantum()); pai->rval = padQSPIReadData(); #endif DEBUGPRINT(DP_INFO, devAiSlowADCPadFlag, ("read_ai: %s: read routine with channel: %d has rval: %d gets val: %g\n", pai->name, paip->channel, pai->rval, pai->val)); /* ASLO and AOFF applied by EPICS */ return OK; }