/*============================================================================= Name: devAoLlrf.c Abs: Device support for Ao Records Derived from $EPICS/base/src/rec/aoRecord.c * Auth: 18-jun-2008, Dayle Kotturi (dayle): Initial version for LLRF VME * Mod: Shantha Condamoor 16-Dec-2013 * Removed IQ-related l1x functions as l1x is now similar to tc0 ----------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include #include #include /* for SCAN_IO_EVENT */ #include /* for dbScanLock */ #include /* for DBADDR */ #include #include /* for aoRecord structure */ #include /* for epicsExportAddress */ #include /* for DEBUGPRINT */ #include "drvLlrf.h" /* for llrfSet* */ typedef struct aoLlrf_s { int routine; int station; int channel; } aoLlrf_t; typedef struct { long number; DEVSUPFUN dev_report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write_ao; DEVSUPFUN special_linconv; } AODSET; /* 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 devAoLlrfFlag = 0; #endif LOCAL long init_ao(); LOCAL long ao_ioinfo(); LOCAL long write_ao(); AODSET devAoLlrf = {6, NULL, NULL, init_ao, ao_ioinfo, write_ao, NULL}; epicsExportAddress(dset, devAoLlrf); /* extern int llrfSetPadOffset(int station, int channel, double ofst); extern int llrfSetPadSize(int station, int channel, double size); extern int llrfSetPadFrequency(int station, int channel, double frequency); */ LOCAL long init_ao(struct aoRecord *pao, int pass) { aoLlrf_t *paop; /* Allocate the memory for this records private data structure */ paop = (aoLlrf_t *) malloc(sizeof(aoLlrf_t)); if (paop == NULL) { return S_dev_noMemory; } /* Read the DBLINK "out" field to get the routine */ sscanf(pao->out.value.instio.string, "%d %d %d", &(paop->routine), &(paop->station), &(paop->channel)); /* Tell the record about its private data structure */ pao->dpvt = paop; /* From aoRecord.c */ pao->oval = pao->pval = pao->val; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAoLlrfFlag, ("init_ao: %s: has val: %g\n", pao->name, pao->val)); DEBUGPRINT(DP_INFO, devAoLlrfFlag, ("init_ao: %s: has parm: %s\n", pao->name, pao->out.value.instio.string)); DEBUGPRINT(DP_INFO, devAoLlrfFlag, ("init_ao: %s's dpvt has routine: %d, station: %d and channel %d\n", pao->name, (int) paop->routine, (int) paop->station, (int) paop->channel)); #endif return 2; /* don't convert */ } LOCAL long ao_ioinfo( int cmd, struct aoRecord *pao, IOSCANPVT *ppvt ) { return 0; } /* 6/18/8 These write to the global structures for each station. These values change infrequently and so by storing them in global they can be used in pulse by pulse calcs without wasting a subroutine INP field to pass them. What's missing is the first arg for all the Set routines: the station. */ LOCAL long write_ao(struct aoRecord *pao) { long rc; aoLlrf_t *paop; DBADDR *dolAddr; struct rset *prset; double *dol; double threshold; /* Set this to facilitate easy access to index field */ paop = (aoLlrf_t *)pao->dpvt; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devAoLlrfFlag, ("write_ao: %s: st %d ch %d val %d\n", pao->name, paop->station, paop->channel, (int) pao->val)); #endif switch (paop->routine) { case 0: rc = llrfSetPhaseOffsetCorrection(paop->station, paop->channel,(double)pao->val); if (rc == ERROR) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAoLlrfFlag, ("write_ao: %s: unable to set phase offset correction for st %d ch %d to: %d\n", pao->name, paop->station, paop->channel, (int) pao->val)); #endif /*pao->sevr = INVALID; or something */ } break; case 1: rc = llrfSetPowerScaleFactor(paop->station, paop->channel,(double)pao->val); if (rc == ERROR) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAoLlrfFlag, ("write_ao: %s: unable to set voltage scale factor for st %d ch %d to: %d\n", pao->name, paop->station, paop->channel, (int) pao->val)); #endif /*pao->sevr = INVALID; or something */ } break; case 2: rc = llrfSetVoltageScaleFactor(paop->station, paop->channel,(double)pao->val); if (rc == ERROR) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAoLlrfFlag, ("write_ao: %s: unable to set voltage scale factor for st %d ch %d to: %d\n", pao->name, paop->station, paop->channel, (int) pao->val)); #endif /*pao->sevr = INVALID; or something */ } break; case 3: rc = llrfSetPhaseWeightingFactor(paop->station, paop->channel,(double)pao->val); if (rc == ERROR) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAoLlrfFlag, ("write_ao: %s: unable to set phase weighting factor for st %d ch %d to: %d\n", pao->name, paop->station, paop->channel, (int) pao->val)); #endif } break; case 4: rc = llrfSetAmplWeightingFactor(paop->station, paop->channel,(double)pao->val); if (rc == ERROR) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAoLlrfFlag, ("write_ao: %s: unable to set ampl weighting factor for st %d ch %d to: %d\n", pao->name, paop->station, paop->channel, (int) pao->val)); #endif } break; case 5: rc = llrfSetDesiredPhase(paop->station, (double)pao->val); if (rc == ERROR) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAoLlrfFlag, ("write_ao: %s: unable to set desired phase for st %d to: %d\n", pao->name, paop->station, (int) pao->val)); #endif } break; case 7: rc = llrfSetDesiredXOffset(paop->station, paop->channel, (double)pao->val); if (rc == ERROR) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAoLlrfFlag, ("write_ao: %s: unable to set desired x offset for st %d ch %d to: %d\n", pao->name, paop->station, paop->channel, (int) pao->val)); #endif } break; case 8: rc = llrfSetDesiredPhase2856(paop->station, (double)pao->val); break; case 9: rc = llrfSetDesiredPhase2805(paop->station, (double)pao->val); break; case 10: #ifdef LLRF_LSR68_NG rc = llrfSetDesiredPhase68(paop->station, (double)pao->val); #elif LLRF_LSR119_NG rc = llrfSetDesiredPhase119(paop->station, (double)pao->val); #endif break; case 11: rc = llrfSetDesiredAmpl(paop->station, (double)pao->val); break; case 12: rc = llrfSetPhaseCorrectionMax(paop->station, (double)pao->val); break; case 13: rc = llrfSetPhaseCorrectionMin(paop->station, (double)pao->val); break; case 14: rc = llrfSetPhaseGain(paop->station, (double)pao->val); break; case 15: rc = llrfSetQScaleFactor(paop->station, (double)pao->val); break; case 16: rc = llrfSetIScaleFactor(paop->station, (double)pao->val); break; case 17: rc = llrfSetZeroingFactor(paop->station, (double)pao->val); break; case 18: rc = llrfSetPacIPositionMonitor(paop->station, (double)pao->val); break; case 19: rc = llrfSetPacQPositionMonitor(paop->station, (double)pao->val); break; case 20: /* * dol must be a DB link and must be the proper type. */ dolAddr = dbGetPdbAddrFromLink(&pao->dol); if (!dolAddr) { printf("NULL dolAddr\n"); /* 10/17/8 it goes here. don't know why */ return ERROR; } dbScanLock(dolAddr->precord); if ((dolAddr->field_type == DBF_DOUBLE) && ((prset = dbGetRset(dolAddr)))) { dol = (double *)dolAddr->pfield; } if (!dol) { rc = ERROR; dbScanUnlock(dolAddr->precord); /* do before any return */ } (*prset->get_value)(dol, &threshold); dbScanUnlock(dolAddr->precord); /* do before any return */ rc = llrfSetMinPowerThreshold(paop->station, threshold); break; /* case 21: rc = llrfSetPadOffset(paop->station, paop->channel,(double)pao->val); break; case 22: rc = llrfSetPadSize(paop->station, paop->channel,(double)pao->val); break; case 23: rc = llrfSetPadFrequency(paop->station, paop->channel,(double)pao->val); break; */ case 24: rc = llrfSetRefPhase(paop->station, (double)pao->val); break; default: rc = ERROR; #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devAoLlrfFlag, ("write_ao: %s: unrecognized value in routine: %d\n", pao->name, (int) paop->routine)); #endif /* pao->sevr = INVALID; or something */ } return rc; }