#ifndef DRV_LLRF_H #define DRV_LLRF_H #include "llrfMacros.h" typedef struct rf_lsr_station_s { double phase_offset_correction[PAD_NUM_CHANNELS_ON_BOARD]; double power_scale_factor[PAD_NUM_CHANNELS_ON_BOARD]; double voltage_scale_factor[PAD_NUM_CHANNELS_ON_BOARD]; short Q[PAD_NUM_CHANNELS_ON_BOARD]; short I[PAD_NUM_CHANNELS_ON_BOARD]; double rotatedQ[PAD_NUM_CHANNELS_ON_BOARD]; /* rotated by either desired_phase2856 or desired_phase119, depending on the channel */ double rotatedI[PAD_NUM_CHANNELS_ON_BOARD]; short varQ[PAD_NUM_CHANNELS_ON_BOARD]; short varI[PAD_NUM_CHANNELS_ON_BOARD]; double phase[PAD_NUM_CHANNELS_ON_BOARD]; /* rotated by ... */ double nonRotatedPhase[PAD_NUM_CHANNELS_ON_BOARD]; double sumsq[PAD_NUM_CHANNELS_ON_BOARD]; double sigmaQ[PAD_NUM_CHANNELS_ON_BOARD]; double sigmaI[PAD_NUM_CHANNELS_ON_BOARD]; double ampl[PAD_NUM_CHANNELS_ON_BOARD]; double power[PAD_NUM_CHANNELS_ON_BOARD]; int input_source; /* 10/13/8: new */ int prev_input_source;/* 10/16/8: new */ double actual_phase; /* units are deg 476 */ double actual_ampl; double desired_phase2856; /* exception: LSR needs this in calc */ double desired_phase119; /* exception: LSR needs this in calc */ double desired_phase2805; /* exception: LSR needs this in calc */ double desired_phase; /* units are deg 476 */ double desired_ampl; int feedback_on; double corrected_phase; double corrected_phase_upper_limit; double corrected_phase_lower_limit; double phase_smoothing_factor; double ampl_minimum_threshold; double previous_phase_setpt; /* units are deg 476 */ double phase_setpt; /* units are deg 476 */ double pac_phase_setpt; double q_scale_factor; double i_scale_factor; double phase_zeroing_angle; double q_setpt; double i_setpt; /* 10/15/8 In case other software (eg Matlab) bypasses the correct interface (the VME), instead setting I and Q adjust values directly on the PAC. Since the VME has no knowledge of this, it must learn where the PAC is and incorporate this reality BEFORE starting feedback, in order that no jump occur. Note that if the other software does not take these same precautions, jumps could still be induced by it. These next two variables hold the known PAD setpoints. They are updated whenever the binary output record that toggles the on/off of the feedback is processed. So yes, they are updated both when feedback is turned on and when it is turned off. When feedback is turned off, no absorption is done, however. */ double q_adjust_from_PAC; double i_adjust_from_PAC; int debug_flag; } rf_lsr_station_t; typedef struct rf_fdbk_station_s { double phase_offset_correction[PAD_NUM_CHANNELS_ON_BOARD]; double power_scale_factor[PAD_NUM_CHANNELS_ON_BOARD]; double voltage_scale_factor[PAD_NUM_CHANNELS_ON_BOARD]; short Q[PAD_NUM_CHANNELS_ON_BOARD]; short I[PAD_NUM_CHANNELS_ON_BOARD]; double phase[PAD_NUM_CHANNELS_ON_BOARD]; double sumsq[PAD_NUM_CHANNELS_ON_BOARD]; double ampl[PAD_NUM_CHANNELS_ON_BOARD]; double power[PAD_NUM_CHANNELS_ON_BOARD]; double phase_weighting_factor[PAD_NUM_CHANNELS_ON_BOARD]; double ampl_weighting_factor[PAD_NUM_CHANNELS_ON_BOARD]; double total_phase_weighting; double total_ampl_weighting; double avg_phase; double avg_ampl; int debug_flag; } rf_fdbk_station_t; typedef struct rf_2ch_fdbk_station_s { double phase_offset_correction[PAD_NUM_CHANNELS_ON_BOARD]; double power_scale_factor[PAD_NUM_CHANNELS_ON_BOARD]; double voltage_scale_factor[PAD_NUM_CHANNELS_ON_BOARD]; short Q[PAD_NUM_CHANNELS_ON_BOARD]; short I[PAD_NUM_CHANNELS_ON_BOARD]; double phase[PAD_NUM_CHANNELS_ON_BOARD]; double sumsq[PAD_NUM_CHANNELS_ON_BOARD]; /* could live without this */ double ampl[PAD_NUM_CHANNELS_ON_BOARD]; double power[PAD_NUM_CHANNELS_ON_BOARD]; double phase_weighting_factor[2]; double ampl_weighting_factor[2]; double total_phase_weighting; double total_ampl_weighting; double avg_phase; double avg_ampl; int debug_flag; } rf_2ch_fdbk_station_t; typedef struct rf_l1x_station_s { /* channel 2 is straight signal, no combined I&Q, but it is messy, so allocate 4 elem arrays */ double phase_offset_correction[PAD_NUM_CHANNELS_ON_BOARD]; double power_scale_factor[PAD_NUM_CHANNELS_ON_BOARD]; double voltage_scale_factor[PAD_NUM_CHANNELS_ON_BOARD]; short Q[PAD_NUM_CHANNELS_ON_BOARD]; short I[PAD_NUM_CHANNELS_ON_BOARD]; short S; double phase[PAD_NUM_CHANNELS_ON_BOARD]; double sumsq[PAD_NUM_CHANNELS_ON_BOARD]; double ampl[PAD_NUM_CHANNELS_ON_BOARD]; double power[PAD_NUM_CHANNELS_ON_BOARD]; double IQ_weighting_factor[PAD_NUM_CHANNELS_L1X_FB]; double ampl_weighting_factor[PAD_NUM_CHANNELS_L1X_FB]; double total_IQ_weighting; double total_ampl_weighting; double avg_I; double avg_Q; double avg_phase; double avg_Iprim; double avg_Qprim; double avg_phaseprim; double avg_ampl; int debug_flag; double Iprim[PAD_NUM_CHANNELS_L1X_FB]; double Qprim[PAD_NUM_CHANNELS_L1X_FB]; double desired_phase; /* exception: L1X needs this in calc */ } rf_l1x_station_t; typedef struct rf_2ch_pcav_station_s { double phase_offset_correction[2]; double power_scale_factor[2]; double voltage_scale_factor[2]; short Q[2]; /* the first sample for each of channel 0 and 1 */ short I[2]; /* the first sample for each of channel 0 and 1 */ short S1_Q[2]; /* the second sample for each of channel 0 and 1 */ short S1_I[2]; /* the second sample for each of channel 0 and 1 */ short X[2]; /* the midpoint of the first sample for each of channel 0 and 1 */ short S1_X[2]; /* the midpoint of the second sample for each of channel 0 and 1 */ double phase[2]; /* the phase of the first sample for each of channel 0 and 1 */ double S1_phase[2]; /* the phase of the second sample for each of channel 0 and 1 */ double linear_phase[2]; /* the phase as determined by eqn to line of two samples for each of channel 0 and 1 */ double desired_X[2]; /* X value of desired phase */ double slope[2]; /* the slope of the lines for each of channel 0 and 1 */ double b[2]; /* the y-intercepts of the lines for each of channel 0 and 1 */ double ampl[2]; /* the ampl of the first sample for each of channel 0 and 1 */ double power[2]; /* the power of the first sample for each of channel 0 and 1 */ double phase_weighting_factor[2]; double ampl_weighting_factor[2]; double total_phase_weighting; double total_ampl_weighting; double avg_phase; /* weighted average phase from channel 0 and 1 */ double avg_ampl; /* weighted average ampl from channel 0 and 1 */ int debug_flag; } rf_2ch_pcav_station_t; typedef struct rf_pcav_station_s { double phase_offset_correction[4]; double power_scale_factor[4]; double voltage_scale_factor[4]; short Q[4]; /* the first sample for each of the channels */ short I[4]; /* the first sample for each of the channels */ short S1_Q[4]; /* the second sample for each of the channels */ short S1_I[4]; /* the second sample for each of the channels */ short X[4]; /* the midpoint of the first sample for each of the channels */ short S1_X[4]; /* the midpoint of the second sample for each of the channels */ double phase[4]; /* the phase of the first sample for each of the channels */ double S1_phase[4]; /* the phase of the second sample for each of the channels */ double linear_phase[4]; /* the phase as determined by eqn to line of two samples for each of the channels */ double desired_X[4]; /* X value of desired phase */ double slope[4]; /* the slope of the lines for each of the channels */ double b[4]; /* the y-intercepts of the lines for each of the channels */ double ampl[4]; /* the ampl of the first sample for each of the channels */ double power[4]; /* the power of the first sample for each of the channels */ double phase_weighting_factor[4]; double ampl_weighting_factor[4]; double total_phase_weighting; double total_ampl_weighting; double avg_phase; /* weighted average phase from the channels */ double avg_ampl; /* weighted average ampl from the channels */ int debug_flag; } rf_pcav_station_t; /* 6/18/8: no surprise here. each station does not fit this struct. need special versions */ #ifdef LLRF_LSR_NG rf_lsr_station_t lsr; #endif #ifdef LLRF_GUN_NG rf_fdbk_station_t gun; #endif #ifdef LLRF_L0A_NG rf_2ch_fdbk_station_t l0a; #endif #ifdef LLRF_L0B_NG /* EXCEPTION: IT IS A 2 CH FEEDBACK, BUT CHANNELS ARE 2 & 3 */ rf_fdbk_station_t l0b; #endif #ifdef LLRF_PCAV1_NG rf_2ch_pcav_station_t pc1; #endif #ifdef LLRF_TCAV0_NG rf_2ch_fdbk_station_t tc0; #endif #ifdef LLRF_L1S_NG rf_fdbk_station_t l1s; #endif #ifdef LLRF_L1X_NG rf_l1x_station_t l1x; #endif #ifdef LLRF_PCAV2_NG rf_pcav_station_t pc2; #endif #ifdef LLRF_TCAV3_NG rf_2ch_fdbk_station_t tc3; #endif #ifdef LLRF_PCAV3_NG rf_pcav_station_t pc3; #endif #ifdef LLRF_PCAV4_NG rf_pcav_station_t pc4; #endif /* Called via ai records */ double llrfGetPhaseOffsetCorrection(int station, int channel); double llrfGetPowerScaleFactor(int station, int channel); double llrfGetVoltageScaleFactor(int station, int channel); double llrfGetPhaseWeightingFactor(int station, int channel); double llrfGetAmplWeightingFactor(int station, int channel); double llrfGetTotalPhaseWeighting(int station); double llrfGetTotalAmplWeighting(int station); double llrfGetPavg(int station); double llrfGetAavg(int station); double llrfGetPhase(int station, int channel, int sample); double llrfGetNonRotatedPhase(int station, int channel); double llrfGetAmpl(int station, int channel); double llrfGetPower(int station, int channel); double llrfGetDesiredPhase(int station); /* implemented for LASER only */ double llrfGetS(int station, int channel); double llrfGetTotalIQWeighting(int station); double llrfGetIprim(int station, int channel); double llrfGetQprim(int station, int channel); double llrfGetI_avg(int station); double llrfGetQ_avg(int station); double llrfGetPhaseprim(int station); double llrfGetPhaseWeightingFactor(int station, int channel); /* as of 7/15/8 no PV calls this */ double llrfGetIQWeightingFactor(int station, int channel); /* as of 7/15/8 no PV calls this */ double llrfGetLinearPhase(int station, int channel); double llrfGetSlope(int station, int channel); double llrfGetIntercept(int station, int channel); double llrfGetMidpoint(int station, int channel, int sample); double llrfGetVarQ(int station, int channel); double llrfGetVarI(int station, int channel); double llrfGetSigmaQ(int station, int channel); double llrfGetSigmaI(int station, int channel); double llrfGetPreviousPhaseSetpt(int station); double llrfGetPhaseSetpt(int station); double llrfGetISetpt(int station); double llrfGetQSetpt(int station); double llrfGetPACPhaseSetpt(int station); double llrfGetZeroingFactor(int station); /* Called via ao records */ int llrfSetPhaseOffsetCorrection(int station, int channel, double phase_offset_corr); int llrfSetPowerScaleFactor(int station, int channel, double power_scal_fac); int llrfSetVoltageScaleFactor(int station, int channel, double voltage_scal_fac); int llrfSetPhaseWeightingFactor(int station, int channel, double phase_weighting); int llrfSetAmplWeightingFactor(int station, int channel, double ampl_weighting_factor); int llrfSetDesiredPhase(int station, double desired_phase); /* implemented for L1X and LASER only */ int llrfSetIQWeightingFactor(int station, int channel, double IQ_weighting_factor); /* as of 7/15/8 no PV calls this */ int llrfSetDesiredXOffset(int station, int channel, double desired_X); int llrfSetInputSource(int station, int source); int llrfGetInputSource(int station); int llrfSetDesiredPhase2856(int station, double phase); int llrfSetDesiredPhase119(int station, double phase); int llrfSetDesiredPhase2805(int station, double phase); int llrfSetPhaseCorrectionMax(int station, double correction); int llrfSetPhaseCorrectionMin(int station, double correction); int llrfSetPhaseGain(int station, double gain); int llrfSetDesiredAmpl(int station, double ampl); int llrfSetQScaleFactor(int station, double scale_factor); int llrfSetIScaleFactor(int station, double scale_factor); int llrfSetZeroingFactor(int station, double zeroing_angle); int llrfSetPhaseFeedbackControl(int station, int val); int llrfSetPacIPositionMonitor(int station, double position); int llrfSetPacQPositionMonitor(int station, double position); int llrfSetDebugLevel(int station, int level); int llrfSetMinPowerThreshold(int station, double threshold); void* llrfGetFeedbackStation(int station); int llrfCalculations(int station); #endif