#include #include #include #include #include #include #include #include #include #include #include #include /* for SCAN_IO_EVENT */ #include #include /* for aiRecord structure */ #include /* for epicsExportAddress */ #include /* for DEBUGPRINT */ #include "drvMpsLinkNode.h" /* for mpsGet* routines */ typedef struct aiMps_s { int routine; int channel; int type; } aiMps_t; 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; #ifdef DEBUG_PRINT int devAiMpsFlag = 4; #endif LOCAL long init_ai(); LOCAL long ai_ioinfo(); LOCAL long read_ai(); AIDSET devAiMpsLinkNode = { 6, NULL, NULL, init_ai, ai_ioinfo, read_ai, NULL }; epicsExportAddress(dset, devAiMpsLinkNode); LOCAL long init_ai(struct aiRecord *pai) { aiMps_t *paip; switch(pai->inp.type) { case(INST_IO): /* Allocate the memory for this records private data structure */ paip = (aiMps_t *) malloc(sizeof(aiMps_t)); if (paip == NULL) { return S_dev_noMemory; } /* Tell the record about its private data structure */ pai->dpvt = paip; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiMpsFlag, ("init_ai: %s: has parm: %s\n", pai->name, pai->inp.value.instio.string)); #endif sscanf(pai->inp.value.instio.string, "%d %d %d", &(paip->routine), &(paip->channel), &(paip->type)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiMpsFlag, ("init_ai: %s's dpvt has routine: %d, channel: %d type: %d\n", pai->name, paip->routine, paip->channel, paip->type)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiMpsFlag, ("init_ai: %s: illegal INP field: %d", pai->name, (int) pai->inp.type)); #endif return ERROR; break; } return OK; } LOCAL long ai_ioinfo( int cmd, struct aiRecord *pai, IOSCANPVT *ppvt ) { return OK; } LOCAL long read_ai(struct aiRecord *pai) { aiMps_t *paip; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiMpsFlag, ("read_ai for %s\n", pai->name)); #endif /* Set this to facilitate easy access to index field */ paip = (aiMps_t *)pai->dpvt; /* 3/13/2008 rval is an uint32 so all my decimal places are lost!!! Do I have to use subroutine records???? */ switch(paip->routine) { case 0: pai->rval = mpsGetXilinxTempAnalog(); break; case 1: pai->rval = mpsGetP24V(); break; case 2: pai->rval = mpsGetP12V(); break; case 3: pai->rval = mpsGetP5V(); break; case 4: pai->rval = mpsGetP3d3V(); break; case 5: pai->rval = mpsGetBoardTempAnalog(); break; case 6: pai->rval = (long) mpsGetBLMHV(paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiMpsFlag, ("%s's rval is %d\n", pai->name, pai->rval)); #endif break; case 7: /* Invasive to FPGA. debug only */ pai->rval = mpsGetBYKThreshold(paip->type); break; case 8: pai->rval = mpsAssembleBeamDose(paip->channel, paip->type); break; case 9: pai->rval = mpsAssembleTestDose(paip->channel, paip->type); break; case 10: pai->rval = mpsGetADCDiagnostic(paip->type); break; case 11: pai->rval = mpsGetBLMHVThreshold(paip->channel, paip->type); break; default: pai->udf = 1; return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devAiMpsFlag, ("%s's rval is %d\n", pai->name, pai->rval)); #endif return OK; }