#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 module; 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 = 2; int devAiMpsAssemblePICDoseFlag = 0; #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 %d", &(paip->routine), &(paip->module), &(paip->channel), &(paip->type)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiMpsFlag, ("init_ai: %s's dpvt has routine: %d module: %d channel: %d type: %d\n", pai->name, paip->routine, paip->module, 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: /* 4/10/9 module is new. fix BLM templates to have it */ pai->rval = mpsAssembleBeamDose(paip->module, paip->channel, paip->type); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiMpsAssemblePICDoseFlag, ("%s has module:%d chan:%d time:%d\n", pai->name, paip->module, paip->channel, paip->type)); #endif break; case 9: pai->rval = mpsAssembleTestDose(paip->channel, paip->type); break; case 10: /* 4/10/9 module is new. fix BLM templates to have it */ pai->rval = mpsGetADCDiagnostic(paip->module, paip->type); break; case 11: pai->rval = mpsGetBLMHVThreshold(paip->channel, paip->type); break; case 12: /* 4/15/9 new. Read PIC QADC doses from memory now pai->rval = mpsGetBeamDoseFromMem(paip->module, paip->channel, paip->type); 7/1/10 memory map reworked. Back to using mpsAssembleBeamDose, which calls mpsGetQADCBeamDose. Use routine 8 instead of this */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiMpsFlag, ("%s should not be called with routine #12\n", pai->name)); #endif break; case 13: /* 7/8/9 new. Use to debug register combining from diff locations */ pai->rval = mpsGetQADCBaseThresholdUpperRegister(paip->module, paip->channel, paip->type); break; case 14: /* 7/8/9 new. Use to debug register combining from diff locations */ pai->rval = mpsGetQADCBaseThresholdLowerRegister(paip->module, paip->channel, paip->type); break; case 15: /* 7/8/9 new. Use to debug register combining from diff locations */ pai->rval = mpsGetQADCTestThresholdUpperRegister(paip->module, paip->channel, paip->type); break; case 16: /* 7/8/9 new. Use to debug register combining from diff locations */ pai->rval = mpsGetQADCTestThresholdLowerRegister(paip->module, paip->channel, paip->type); break; case 17: /* 7/8/9 new. Use to debug register combining from diff locations */ pai->rval = mpsGetQADCBeamThresholdUpperRegister(paip->module, paip->channel, paip->type); break; case 18: /* 7/8/9 new. Use to debug register combining from diff locations */ pai->rval = mpsGetQADCBeamThresholdLowerRegister(paip->module, paip->channel, paip->type); break; case 19: pai->rval = mpsGetAcquisitionCounter(paip->module); break; case 20: pai->rval = mpsGetBeamPedestal(paip->channel); break; case 21: pai->rval = mpsGetBeamPed3d3(); break; case 22: pai->rval = mpsGetBeamPed2d5(); break; case 23: pai->rval = mpsGetBeamPed1d2(); break; case 24: pai->rval = mpsGetBeamPedGnd(); break; /* 2/25/10 removed the mpsGetTest* routines */ case 30: pai->rval = mpsGetEventCounter(); break; case 31: pai->rval = mpsGetAbortCounter(); break; case 32: pai->rval = mpsGetStandbyCounter(); break; case 33: pai->rval = mpsGetEVGAbortCounter(); 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; }