/* $Id: devAoLlrfPad.c,v 1.11 2014/03/20 19:34:49 scondam Exp $ */ /*============================================================================= Name: devAoLlrfPad.c Abs: Raw Pad Device support for ao records. Auth: Shantha Condamoor (scondam) Rev: Oct 10 2011 - Initial Release Mar 12 2014 - drvLlrf.c functions are not defined or used for Klystron Diagnostics stations. These stations include the definition "LLRF_KLY_PAD" in their drvLlrfPadRF*.c files. Exclude these functions using compiler directives for Kly PAD stations. Directly include this file, devAoLlrfPad.c drvLlrfPadRF*.c files for these stations. Sept 16 2014 Converted LCLS Coherent Laser 1 Feedback station to Diagnostics station per H.Loos/J.Frisch. Now exclude drvLlrf.c function calls. Use LLRF_LSRDIAG_PAD compiler directive to check if it is LCLS Non-Feedback Laser Controls or ASTA Feedback Laser controls. Both use station number 1. -----------------------------------------------------------------------------*/ #if 0 #include "copyright_SLAC.h" /* SLAC copyright comments */ #endif /*----------------------------------------------------------------------------- Mod: (see CVS log) =============================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "drvLlrfPad.h" #define AODPADSET "devAoLlrfPad" #ifndef LLRF_KLY_PAD #ifndef LLRF_KLY_PAD2 #ifndef LLRF_LSRDIAG_PAD extern int llrfSetPhaseOffsetCorrection(int station, int channel, double phase_offset_corr); extern int llrfSetVoltageScaleFactor(int station, int channel, double voltage_scal_fac); extern int llrfSetPowerScaleFactor(int station, int channel, double power_scal_fac); #endif #endif #endif typedef struct LlrfPadAoDpvtRec_ { int routine,station,channel; /* interrupt-lock ofst/size when accessing -- * these fields are shared by the record scanning * tasks and the driver task */ int ofst, size, freq, sample; double poc, avc, apc; double mon_desired_phase, iadj, qadj, mon_poc; } LlrfPadAoDpvtRec, *LlrfPadAoDpvt; static long report_ao(int interest) { errlogPrintf(AODPADSET": Window Parameters device support for analog out\n"); return 0; } static long window_init_ao(aoRecord *ao_p) { LlrfStation sta_p; LlrfPadAoDpvt dpvt; int chnl; if ( ao_p->out.type != INST_IO ) { errlogPrintf("%s: invalid INP field -- must be INST_IO\n", ao_p->name); ao_p->pact = TRUE; return S_dev_badInpType; } dpvt = mallocMustSucceed( sizeof(*dpvt), "devAoLlrfPad: -- no memory for DPVT" ); sscanf(ao_p->out.value.instio.string, "%d %d %d", &(dpvt->routine), &(dpvt->station), &(dpvt->channel)); if ( ! (sta_p = llrfGetStation( dpvt->station ) ) ) { errlogPrintf("devAoLlrfPad: %s: invalid INP field -- bad 'card' value: %i\n", ao_p->name, dpvt->station); ao_p->pact = TRUE; return S_dev_badCard; } chnl = dpvt->channel; dpvt->channel = dpvt->channel % PAD_NUM_CHANNELS_ON_BOARD; ao_p->dpvt = dpvt; ao_p->oval = ao_p->pval = ao_p->val; dpvt->sample=0; epicsMutexMustLock( sta_p->mutex ); switch (dpvt->routine) { case OFST: switch (dpvt->station) { case LLRF_PCAV1: /* Station LLRF_PH1 PAD (station 9) ch0 and ch1 are for PCAV1 and ch2 and ch3 are for PCAV2 */ case LLRF_PCAV2: /* Channel 0,1,2,3 are for sample 0 and channel 4,5,6,7 are for sample 1 */ case LLRF_PCAV3: case LLRF_PCAV4: if (chnl >= PAD_NUM_CHANNELS_ON_BOARD) { sta_p->chnls[dpvt->channel].Samples->ofst = dpvt->ofst = (int) ao_p->val; dpvt->sample=1; break; } default: sta_p->chnls[dpvt->channel].ofst = dpvt->ofst = (int) ao_p->val; break; } break; case SIZE: switch (dpvt->station) { case LLRF_PCAV1: /* Station LLRF_PH1 PAD (station 9) ch0 and ch1 are for PCAV1 and ch2 and ch3 are for PCAV2 */ case LLRF_PCAV2: /* Channel 0,1,2,3 are for sample 0 and channel 4,5,6,7 are for sample 1 */ case LLRF_PCAV3: case LLRF_PCAV4: if (chnl >= PAD_NUM_CHANNELS_ON_BOARD) { sta_p->chnls[dpvt->channel].Samples->size = dpvt->size = (int) ao_p->val; dpvt->sample=1; break; } default: sta_p->chnls[dpvt->channel].size = dpvt->size = (int) ao_p->val; break; } break; case FREQ: sta_p->chnls[dpvt->channel].freq = dpvt->freq = (int) ao_p->val; break; case POC: sta_p->chnls[dpvt->channel].poc = dpvt->poc = (double) ao_p->val; #ifndef LLRF_KLY_PAD #ifndef LLRF_KLY_PAD2 #ifndef LLRF_LSRDIAG_PAD /* LCLS Cohr Laser 1 and 2 are now Non-Feedback Diag PADs. ASTA Laser remains feedback controls. */ switch (dpvt->station) { case LLRF_L0A: /* Station LLRF_L0 PAD (station 3) ch0 and ch1 are for L0A and ch2 and ch3 are for L0B */ case LLRF_L0B: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetPhaseOffsetCorrection(LLRF_L0B, dpvt->channel,(double)ao_p->val); } else { llrfSetPhaseOffsetCorrection(LLRF_L0A, dpvt->channel,(double)ao_p->val); } break; case LLRF_PCAV1: /* Station LLRF_PH1 PAD (station 9) ch0 and ch1 are for PCAV1 and ch2 and ch3 are for PCAV2 */ case LLRF_PCAV2: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetPhaseOffsetCorrection(LLRF_PCAV2, dpvt->channel,(double)ao_p->val); } else { llrfSetPhaseOffsetCorrection(LLRF_PCAV1, dpvt->channel,(double)ao_p->val); } break; case LLRF_LSR: /* same as LLRF_XTCAVA */ case LLRF_GUN: case LLRF_TCAV0: case LLRF_L1S: case LLRF_L1X: case LLRF_TCAV3: case LLRF_PCAV3: case LLRF_PCAV4: llrfSetPhaseOffsetCorrection(dpvt->station, dpvt->channel,(double)ao_p->val); default: break; } #endif #endif #endif break; case AVC: sta_p->chnls[dpvt->channel].avc = dpvt->avc = (double) ao_p->val; #ifndef LLRF_KLY_PAD #ifndef LLRF_KLY_PAD2 #ifndef LLRF_LSRDIAG_PAD /* LCLS Cohr Laser 1 and 2 are now Non-Feedback Diag PADs. ASTA Laser remains feedback controls. */ switch (dpvt->station) { case LLRF_L0A: /* Station LLRF_L0 PAD (station 3) ch0 and ch1 are for L0A and ch2 and ch3 are for L0B */ case LLRF_L0B: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetVoltageScaleFactor(LLRF_L0B, dpvt->channel,(double)ao_p->val); } else { llrfSetVoltageScaleFactor(LLRF_L0A, dpvt->channel,(double)ao_p->val); } break; case LLRF_PCAV1: /* Station LLRF_PH1 PAD (station 9) ch0 and ch1 are for PCAV1 and ch2 and ch3 are for PCAV2 */ case LLRF_PCAV2: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetVoltageScaleFactor(LLRF_PCAV2, dpvt->channel,(double)ao_p->val); } else { llrfSetVoltageScaleFactor(LLRF_PCAV1, dpvt->channel,(double)ao_p->val); } break; case LLRF_LSR: /* same as LLRF_XTCAVA */ case LLRF_GUN: case LLRF_TCAV0: case LLRF_L1S: case LLRF_L1X: case LLRF_TCAV3: case LLRF_PCAV3: case LLRF_PCAV4: llrfSetVoltageScaleFactor(dpvt->station, dpvt->channel,(double)ao_p->val); default: break; } #endif #endif #endif break; case APC: sta_p->chnls[dpvt->channel].apc = dpvt->apc = (double) ao_p->val; #ifndef LLRF_KLY_PAD #ifndef LLRF_KLY_PAD2 #ifndef LLRF_LSRDIAG_PAD /* LCLS Cohr Laser 1 and 2 are now Non-Feedback Diag PADs. ASTA Laser remains feedback controls. */ switch (dpvt->station) { case LLRF_L0A: /* Station LLRF_L0 PAD (station 3) ch0 and ch1 are for L0A and ch2 and ch3 are for L0B */ case LLRF_L0B: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetPowerScaleFactor(LLRF_L0B, dpvt->channel,(double)ao_p->val); } else { llrfSetPowerScaleFactor(LLRF_L0A, dpvt->channel,(double)ao_p->val); } break; case LLRF_PCAV1: /* Station LLRF_PH1 PAD (station 9) ch0 and ch1 are for PCAV1 and ch2 and ch3 are for PCAV2 */ case LLRF_PCAV2: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetPowerScaleFactor(LLRF_PCAV2, dpvt->channel,(double)ao_p->val); } else { llrfSetPowerScaleFactor(LLRF_PCAV1, dpvt->channel,(double)ao_p->val); } break; case LLRF_LSR: /* same as LLRF_XTCAVA */ case LLRF_GUN: case LLRF_TCAV0: case LLRF_L1S: case LLRF_L1X: case LLRF_TCAV3: case LLRF_PCAV3: case LLRF_PCAV4: llrfSetPowerScaleFactor(dpvt->station, dpvt->channel,(double)ao_p->val); default: break; } #endif #endif #endif break; case MON_PDES: sta_p->mon_desired_phase = dpvt->mon_desired_phase = (int) ao_p->val; lsrDiagSetDesiredPhase(dpvt->station, sta_p->mon_desired_phase); break; case MON_IADJ: sta_p->mon_iadjust = dpvt->iadj = (int) ao_p->val; break; case MON_QADJ: sta_p->mon_qadjust = dpvt->qadj = (int) ao_p->val; break; case MON_POC: sta_p->mon_poc = dpvt->mon_poc = (int) ao_p->val; lsrDiagSetDesiredPhaseOffset(dpvt->station, sta_p->mon_poc); break; default: break; } epicsMutexUnlock( sta_p->mutex ); return 0; } static long window_write_ao(aoRecord *ao_p) { LlrfPadAoDpvt dpvt = ao_p->dpvt; LlrfStation sta_p; int chnl; if ( ! (sta_p = llrfGetStation( dpvt->station ) ) ) { errlogPrintf("devAoLlrfPad: %s: invalid INP field -- bad 'card' value: %i\n", ao_p->name, dpvt->station); ao_p->pact = TRUE; return S_dev_badCard; } dpvt->channel = dpvt->channel % PAD_NUM_CHANNELS_ON_BOARD; epicsMutexMustLock( sta_p->mutex ); switch (dpvt->routine) { case OFST: switch (dpvt->station) { case LLRF_PCAV1: /* Station LLRF_PH1 PAD (station 9) ch0 and ch1 are for PCAV1 and ch2 and ch3 are for PCAV2 */ case LLRF_PCAV2: /* Channel 0,1,2,3 are for sample 0 and channel 4,5,6,7 are for sample 1 */ case LLRF_PCAV3: case LLRF_PCAV4: if (dpvt->sample) { sta_p->chnls[dpvt->channel].Samples->ofst = dpvt->ofst = (int) ao_p->val; break; } default: sta_p->chnls[dpvt->channel].ofst = dpvt->ofst = (int) ao_p->val; break; } break; case SIZE: switch (dpvt->station) { case LLRF_PCAV1: /* Station LLRF_PH1 PAD (station 9) ch0 and ch1 are for PCAV1 and ch2 and ch3 are for PCAV2 */ case LLRF_PCAV2: /* Channel 0,1,2,3 are for sample 0 and channel 4,5,6,7 are for sample 1 */ case LLRF_PCAV3: case LLRF_PCAV4: if (dpvt->sample) { sta_p->chnls[dpvt->channel].Samples->size = dpvt->size = (int) ao_p->val; break; } default: sta_p->chnls[dpvt->channel].size = dpvt->size = (int) ao_p->val; break; } break; case FREQ: sta_p->chnls[dpvt->channel].freq = dpvt->freq = (int) ao_p->val; break; case POC: sta_p->chnls[dpvt->channel].poc = dpvt->poc = (double) ao_p->val; #ifndef LLRF_KLY_PAD #ifndef LLRF_KLY_PAD2 #ifndef LLRF_LSRDIAG_PAD /* LCLS Cohr Laser 1 and 2 are now Non-Feedback Diag PADs. ASTA Laser remains feedback controls. */ switch (dpvt->station) { case LLRF_L0A: /* Station LLRF_L0 PAD (station 3) ch0 and ch1 are for L0A and ch2 and ch3 are for L0B */ case LLRF_L0B: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetPhaseOffsetCorrection(LLRF_L0B, dpvt->channel,(double)ao_p->val); } else { llrfSetPhaseOffsetCorrection(LLRF_L0A, dpvt->channel,(double)ao_p->val); } break; case LLRF_PCAV1: /* Station LLRF_PH1 PAD (station 9) ch0 and ch1 are for PCAV1 and ch2 and ch3 are for PCAV2 */ case LLRF_PCAV2: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetPhaseOffsetCorrection(LLRF_PCAV2, dpvt->channel,(double)ao_p->val); } else { llrfSetPhaseOffsetCorrection(LLRF_PCAV1, dpvt->channel,(double)ao_p->val); } break; case LLRF_LSR: /* same as LLRF_XTCAVA */ case LLRF_GUN: case LLRF_TCAV0: case LLRF_L1S: case LLRF_L1X: case LLRF_TCAV3: case LLRF_PCAV3: case LLRF_PCAV4: llrfSetPhaseOffsetCorrection(dpvt->station, dpvt->channel,(double)ao_p->val); default: break; } #endif #endif #endif break; case AVC: sta_p->chnls[dpvt->channel].avc = dpvt->avc = (double) ao_p->val; #ifndef LLRF_KLY_PAD #ifndef LLRF_KLY_PAD2 #ifndef LLRF_LSRDIAG_PAD /* LCLS Cohr Laser 1 and 2 are now Non-Feedback Diag PADs. ASTA Laser remains feedback controls. */ switch (dpvt->station) { case LLRF_L0A: /* Station LLRF_L0 PAD (station 3) ch0 and ch1 are for L0A and ch2 and ch3 are for L0B */ case LLRF_L0B: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetVoltageScaleFactor(LLRF_L0B, dpvt->channel,(double)ao_p->val); } else { llrfSetVoltageScaleFactor(LLRF_L0A, dpvt->channel,(double)ao_p->val); } break; case LLRF_PCAV1: /* Station LLRF_PH1 PAD (station 9) ch0 and ch1 are for PCAV1 and ch2 and ch3 are for PCAV2 */ case LLRF_PCAV2: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetVoltageScaleFactor(LLRF_PCAV2, dpvt->channel,(double)ao_p->val); } else { llrfSetVoltageScaleFactor(LLRF_PCAV1, dpvt->channel,(double)ao_p->val); } break; case LLRF_LSR: /* same as LLRF_XTCAVA */ case LLRF_GUN: case LLRF_TCAV0: case LLRF_L1S: case LLRF_L1X: case LLRF_TCAV3: case LLRF_PCAV3: case LLRF_PCAV4: llrfSetVoltageScaleFactor(dpvt->station, dpvt->channel,(double)ao_p->val); default: break; } #endif #endif #endif break; case APC: sta_p->chnls[dpvt->channel].apc = dpvt->apc = (double) ao_p->val; #ifndef LLRF_KLY_PAD #ifndef LLRF_KLY_PAD2 #ifndef LLRF_LSRDIAG_PAD /* LCLS Cohr Laser 1 and 2 are now Non-Feedback Diag PADs. ASTA Laser remains feedback controls. */ switch (dpvt->station) { case LLRF_L0A: /* Station LLRF_L0 PAD (station 3) ch0 and ch1 are for L0A and ch2 and ch3 are for L0B */ case LLRF_L0B: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetPowerScaleFactor(LLRF_L0B, dpvt->channel,(double)ao_p->val); } else { llrfSetPowerScaleFactor(LLRF_L0A, dpvt->channel,(double)ao_p->val); } break; case LLRF_PCAV1: /* Station LLRF_PH1 PAD (station 9) ch0 and ch1 are for PCAV1 and ch2 and ch3 are for PCAV2 */ case LLRF_PCAV2: if ((dpvt->channel == 2) || (dpvt->channel == 3)) { llrfSetPowerScaleFactor(LLRF_PCAV2, dpvt->channel,(double)ao_p->val); } else { llrfSetPowerScaleFactor(LLRF_PCAV1, dpvt->channel,(double)ao_p->val); } break; case LLRF_LSR: /* same as LLRF_XTCAVA */ case LLRF_TCAV0: case LLRF_L1S: case LLRF_L1X: case LLRF_TCAV3: case LLRF_PCAV3: case LLRF_PCAV4: llrfSetPowerScaleFactor(dpvt->station, dpvt->channel,(double)ao_p->val); default: break; } #endif #endif #endif break; case MON_PDES: sta_p->mon_desired_phase = dpvt->mon_desired_phase = (int) ao_p->val; lsrDiagSetDesiredPhase(dpvt->station, sta_p->mon_desired_phase); break; case MON_IADJ: sta_p->mon_iadjust = dpvt->iadj = (int) ao_p->val; break; case MON_QADJ: sta_p->mon_qadjust = dpvt->qadj = (int) ao_p->val; break; case MON_POC: sta_p->mon_poc = dpvt->mon_poc = (int) ao_p->val; lsrDiagSetDesiredPhaseOffset(dpvt->station, sta_p->mon_poc); break; default: break; } epicsMutexUnlock( sta_p->mutex ); /* Nothing to do. They access the original waveform data */ return 0; } struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write_ao; DEVSUPFUN special_linconv; }devAoLlrfPad={ 6, report_ao, 0, window_init_ao, 0, window_write_ao, 0}; epicsExportAddress(dset,devAoLlrfPad);