/*============================================================================= Name: devAiPac.c Abs: Device support for Derived from $EPICS/base/src/rec/aiRecord.c Auth: 29-sep-2008, Dayle Kotturi (dayle): Initial version for PAC -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- 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 "drvPac.h" /* for pac* */ typedef struct aiPac_s { int routine; int num; } aiPac_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 devAiPac = { 6, NULL, NULL, init_record, NULL, read_ai, NULL }; epicsExportAddress(dset,devAiPac); #ifdef DEBUG_PRINT int devAiPacFlag = 2; #endif LOCAL long init_record(aiRecord *pai) { aiPac_t *paip; /* Allocate the memory for this records private data structure */ paip = (aiPac_t *) malloc(sizeof(aiPac_t)); if (paip == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiPacFlag, ("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", &(paip->routine), &(paip->num)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiPacFlag, ("init_ai: %s: init routine with routine %d num %d\n", pai->name, paip->routine, paip->num)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiPacFlag, ("init_ai: %s: unrecognized link type\n", pai->name)); #endif return ERROR; } return OK; } LOCAL long read_ai(aiRecord *pai) { aiPac_t *paip; /* Set this to facilitate easy access to channel field */ if (pai->dpvt == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiPacFlag, ("read_ai: %s: dpvt is NULL\n", pai->name)); #endif return ERROR; } paip = (aiPac_t *)pai->dpvt; switch (paip->routine) { case 0: pai->rval = (long) pacGetADC(paip->num); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiPacFlag, ("read_ai: %s: adc[%d]: %ld\n", pai->name, paip->num, pai->rval)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiPacFlag, ("read_ai: %s: unrecognized routine: %d", pai->name, paip->routine)); #endif return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiPacFlag, ("read_ai: %s: num: %d has rval: %ld\n", pai->name, paip->num, pai->rval)); #endif return OK; }