/*============================================================================= Name: devAiBlm.c Abs: Device support for Derived from $EPICS/base/src/rec/aiRecord.c Auth: 18-jun-2008, Dayle Kotturi (dayle): Initial version for LLRF VME -----------------------------------------------------------------------------*/ #if 0 #include "copyright_SLAC.h" /* SLAC copyright comments */ #endif /*----------------------------------------------------------------------------- Mod: (newest to oldest) xx-xxx-2008, 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 "drvBlm.h" /* for blm* */ typedef struct aiBlm_s { int routine; int station; int channel; } aiBlm_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 devAiBlm = { 6, NULL, NULL, init_record, NULL, read_ai, NULL }; epicsExportAddress(dset,devAiBlm); #ifdef DEBUG_PRINT int devAiBlmFlag = 2; #endif LOCAL long init_record(aiRecord *pai) { aiBlm_t *paip; /* Allocate the memory for this records private data structure */ paip = (aiBlm_t *) malloc(sizeof(aiBlm_t)); if (paip == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiBlmFlag, ("init_ai: %s: out of memory\n", pai->name)); #endif return S_dev_noMemory; } /* 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 %d %d", &(paip->routine), &(paip->station), &(paip->channel)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiBlmFlag, ("init_ai: %s: init routine with routine %d station %d channel: %d\n", pai->name, paip->routine, paip->station, paip->channel)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiBlmFlag, ("init_ai: %s: unrecognized link type\n", pai->name)); #endif return ERROR; } return OK; } LOCAL long read_ai(aiRecord *pai) { aiBlm_t *paip; /* Set this to facilitate easy access to channel field */ if (pai->dpvt == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiBlmFlag, ("read_ai: %s: dpvt is NULL\n", pai->name)); #endif return ERROR; } paip = (aiBlm_t *)pai->dpvt; switch (paip->routine) { case 0: pai->val = blmGetSum(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiBlmFlag, ("read_ai: %s: stn: %d avg phase is %g\n", pai->name, paip->station, pai->val)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiBlmFlag, ("read_ai: %s: unrecognized routine: %d", pai->name, paip->routine)); #endif return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiBlmFlag, ("read_ai: %s: ch: %d has rval: %d gets val: %g\n", pai->name, paip->channel, pai->rval, pai->val)); #endif pai->udf = FALSE; return 2; /* DON'T CONVERT */ }