/*============================================================================= Name: devAiLlrf.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 -----------------------------------------------------------------------------*/ #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 "drvLlrf.h" /* for llrf* */ typedef struct aiLlrf_s { int routine; int station; int channel; int sample; } aiLlrf_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 devAiLlrf = { 6, NULL, NULL, init_record, NULL, read_ai, NULL }; epicsExportAddress(dset,devAiLlrf); /* 11/21/8 Writing errors (level 2) has become too invasive to the processor w.r.t. processing the incoming data streams. Set this to 0 */ #ifdef DEBUG_PRINT int devAiLlrfFlag = 0; #endif LOCAL long init_record(aiRecord *pai) { aiLlrf_t *paip; /* Allocate the memory for this records private data structure */ paip = (aiLlrf_t *) malloc(sizeof(aiLlrf_t)); if (paip == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiLlrfFlag, ("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 %d", &(paip->routine), &(paip->station), &(paip->channel), &(paip->sample)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("init_ai: %s: init routine with routine %d station %d channel: %d and sample: %d\n", pai->name, paip->routine, paip->station, paip->channel, paip->sample)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiLlrfFlag, ("init_ai: %s: unrecognized link type\n", pai->name)); #endif return ERROR; } return OK; } LOCAL long read_ai(aiRecord *pai) { aiLlrf_t *paip; /* Set this to facilitate easy access to channel field */ if (pai->dpvt == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiLlrfFlag, ("read_ai: %s: dpvt is NULL\n", pai->name)); #endif return ERROR; } paip = (aiLlrf_t *)pai->dpvt; switch (paip->routine) { case 0: pai->val = llrfGetPavg(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: stn: %d avg phase is %g\n", pai->name, paip->station, pai->val)); #endif break; case 1: pai->val = llrfGetAavg(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: avg ampl is %g\n", pai->name, pai->val)); #endif break; case 2: pai->val = llrfGetTotalPhaseWeighting(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: tot phas wt is %g\n", pai->name, pai->val)); #endif break; case 3: pai->val = llrfGetTotalAmplWeighting(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: tot ampl wt is %g\n", pai->name, pai->val)); #endif break; case 4: pai->val = llrfGetPhase(paip->station, paip->channel, paip->sample); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: phase is %g\n", pai->name, pai->val)); #endif break; case 5: pai->val = llrfGetAmpl(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: ampl is %g\n", pai->name, pai->val)); #endif break; case 6: pai->val = llrfGetPower(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: pwr is %g\n", pai->name, pai->val)); #endif break; case 7: pai->val = llrfGetTotalIQWeighting(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: tot iq weighting is %g\n", pai->name, pai->val)); #endif break; case 8: pai->val = llrfGetQprim(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: qprim is %g\n", pai->name, pai->val)); #endif break; case 9: pai->val = llrfGetIprim(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: iprim is %g\n", pai->name, pai->val)); #endif break; case 10: pai->val = llrfGetQ_avg(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: q_avg is %g\n", pai->name, pai->val)); #endif break; case 11: pai->val = llrfGetI_avg(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: i_avg is %g\n", pai->name, pai->val)); #endif break; case 12: pai->val = llrfGetPhaseprim(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: phaseprim is %g\n", pai->name, pai->val)); #endif break; case 13: pai->val = llrfGetS(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: S is %g\n", pai->name, pai->val)); #endif break; case 14: pai->val = llrfGetPhaseWeightingFactor(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: pwt is %g\n", pai->name, pai->val)); #endif break; case 15: pai->val = llrfGetIQWeightingFactor(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: IQwt is %g\n", pai->name, pai->val)); #endif break; case 16: pai->val = llrfGetMidpoint(paip->station, paip->channel, paip->sample); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: midpoint is %g\n", pai->name, pai->val)); #endif break; case 17: pai->val = llrfGetLinearPhase(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: linear phase is %g\n", pai->name, pai->val)); #endif break; case 18: pai->val = llrfGetSlope(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: slope is %g\n", pai->name, pai->val)); #endif break; case 19: pai->val = llrfGetIntercept(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: intercept is %g\n", pai->name, pai->val)); #endif break; case 20: pai->val = llrfGetNonRotatedPhase(paip->station, paip->channel ); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: non-rotated phase is %g\n", pai->name, pai->val)); #endif break; case 21: pai->val = (double) llrfGetVarQ(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: Q variance is %g\n", pai->name, pai->val)); #endif break; case 22: pai->val = (double) llrfGetVarI(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: I variance is %g\n", pai->name, pai->val)); #endif break; case 23: pai->val = llrfGetSigmaQ(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: Q std dev is %g\n", pai->name, pai->val)); #endif break; case 24: pai->val = llrfGetSigmaI(paip->station, paip->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: I std dev is %g\n", pai->name, pai->val)); #endif break; case 25: pai->val = llrfGetPreviousPhaseSetpt(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: prev phase setpt is %g\n", pai->name, pai->val)); #endif break; case 26: pai->val = llrfGetPhaseSetpt(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: phase setpt is %g\n", pai->name, pai->val)); #endif break; case 27: pai->val = llrfGetISetpt(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: i setpt is %g\n", pai->name, pai->val)); #endif break; case 28: pai->val = llrfGetQSetpt(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: q setpt is %g\n", pai->name, pai->val)); #endif break; case 29: pai->val = llrfGetPACPhaseSetpt(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: PAC phase setpt is %g\n", pai->name, pai->val)); #endif break; case 30: pai->val = llrfGetDesiredPhase(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: desired phase is %g\n", pai->name, pai->val)); #endif break; case 31: pai->val = llrfGetZeroingFactor(paip->station); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("read_ai: %s: zeroing factor is %g\n", pai->name, pai->val)); #endif break; default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAiLlrfFlag, ("read_ai: %s: unrecognized routine: %d", pai->name, paip->routine)); #endif return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAiLlrfFlag, ("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 */ }