#ifndef CPSW_KLYSTRON_ASYN_DRIVER_H #define CPSW_KLYSTRON_ASYN_DRIVER_H #include #include #include #include #include #include #include #include #include #include #include #include #include "registerTimeStampSource.h" #define PULSEID(time) ((time).nsec & 0x0001ffff ) extern "C" { void KlystronDataProc_setPrevPCorr(double v, unsigned timeslot); void KlystronDataProc_setPrevACorr(double v, unsigned timeslot); } // hack to acess KlystronDataProc, need to clean it up class cpswKlystronAsynDriver:asynPortDriver { public: cpswKlystronAsynDriver(const char *portName); ~cpswKlystronAsynDriver(); asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); asynStatus writeInt32Array(asynUser *pasynUser, epicsInt32 *values, size_t nElements); asynStatus readFloat64(asynUser *pasynUser, epicsFloat64 *value); asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value); asynStatus writeFloat64Array(asynUser *pasynUser, epicsFloat64 *values, size_t nElements); void KlystronStreamTask(void *p); void KlystronInterlockTask(void *p); void KlystronMonitorTask(void *p); void initRtmWaveforms(void); void reportRtmWaveformBuffer(void); void clearRtmFaultHistory(void); void takeRtmFaultHistory(void); void postRtmFaultHistory(void); void getRtmWaveforms(void); void setRtmFwdcalRatio(double value); void setRtmRefcalRatio(double value); void setRtmDivrRatio(double value); void setRtmCurrRatio(double value); void getRtmThresholdReadout(void); void getTemperature(void); void takePllStatus(void); void forceRearm(void); void cpswKlystronReport(void); void cpswRtmReport(void); void TimeStampSourceProcess(adTimeStampSource_p pTss, epicsTimeStamp *pTime); private: epicsTimeStamp time; unsigned current_ts; unsigned pulseid; epicsEvent *pevent_interlock; int ts(unsigned timeslot); int paramSetup(void); int defaultSetup (void); const char * getDriverName(void); KlystronFw fw; int output_enable; int cw_enable; uint32_t ref_chn; uint32_t fdk_chn; std::vector strms; std::vector i_vec; std::vector q_vec; std::vector evCode[8]; uint32_t polarity[8]; uint32_t delay_ns[8]; uint32_t width_ns[8]; uint32_t accel_delay_ns; uint32_t stdby_delay_ns; uint32_t indv_delay_ns[4]; epicsMutex *pTimingCoreLock; epicsMutex *pRtmLock; int32_t phase_error_firmware; double applStart_ns; double applEnd_ns; double corrScale[6]; // support all 6 timeslots double corrAngle[6]; // support all 6 timeslots epicsMutex *pmutex; uint8_t *pdone_mask; uint8_t *pflush_mask; uint32_t *pdone_count; uint32_t *pflush_count; uint32_t *pinterval_reset; // Rtm Interlock uint32_t rtmFirmwareVersion; char rtmSystemId[32]; char rtmSubType[32]; char rtmFirmwareDate[32]; uint32_t rtmStatus; uint32_t rtmFaultOutStatus; uint32_t rtmAdcLockedStatus; uint32_t rtmRFOffStatus; double rtmFwdcalRatio; double rtmRefcalRatio; double rtmDivrRatio; double rtmCurrRatio; uint32_t rtmThresholdAdcInFwdPower_raw; uint32_t rtmThresholdAdcInRefPower_raw; uint32_t rtmThresholdAdcInBeamCurrent_raw; uint32_t rtmThresholdAdcInBeamVoltage_raw; double rtmThresholdAdcInFwdPower; double rtmThresholdAdcInRefPower; double rtmThresholdAdcInBeamCurrent; double rtmThresholdAdcInBeamVoltage; // PLL Loops int cnt_loPllUnlock; int cnt_clockPllUnlock; int cnt_adPllUnlock; int cnt_jesd[2][8]; int cntMode; void resetPllUnlockCounters(void); void resetJesdResyncCounters(void); protected: // // parameter section for asynPortDriver // int firstKlystronParam; #define FIRST_KLYSTRON_PARAM firstKlystronParam int p_LO_KP; /* asynInt32, rw */ int p_LO_KI; /* asynInt32, rw */ int p_CLK_KP; /* asynInt32, rw */ int p_CLK_KI; /* asynInt32, rw */ int p_ADPLL_KP; /* asynInt32, rw */ int p_ADPLL_KI; /* asynInt32, rw */ int p_loPllPhase; /* asynInt32, ro */ int p_loPllAmplitude; /* asynInt32, ro */ int p_loPllLocked; /* asynInt32, ro */ int p_clockPllPhase; /* asynInt32, ro */ int p_clockPllAmplitude; /* asynInt32, ro */ int p_clockPllLocked; /* asynInt32, ro */ int p_adPllPhase; /* asynInt32, ro */ int p_adPllAmplitude; /* asynInt32, ro */ int p_adPllLocked; /* asynInt32, ro */ int p_loPllPhaseDegree; /* asynFloat64 */ int p_clockPllPhaseDegree; /* asynFloat64 */ int p_adPllPhaseDegree; /* asynFloat64 */ int p_loPllLossSignal; /* asynInt32, ro */ int p_clockPllLossSignal; /* asynInt32, ro */ int p_adPllLossSignal; /* asynInt32, ro */ int p_loPllUnlockCounter; /* asynInt32, ro */ int p_clockPllUnlockCounter; /* asynInt32, ro */ int p_adPllUnlockCounter; /* asynInt32, ro */ int p_resetPllUnlockCounter; /* asynInt32, rw */ int p_loPllNormAmplitude; /* asynFloat64, ro */ int p_clockPllNormAmplitude; /* asynFloat64, ro */ int p_adPllNormAmplitude; /* asynFloat64, ro */ int p_resetJesdResyncCnt; /* asynInt32, rw */ int p_jesdResyncCnt[2][8]; /* asynInt32, ro */ int p_cntMode; /* asynInt32, rw */ int p_OutputEnable; /* asynInt32, rw */ // control RF output int p_CWEnable; /* asynInt32, rw */ // control CW mode and pulse mode int p_refChn; /* asynInt32, rw */ // reference channel int p_fdkChn; /* asynInt32, rw */ // feedback channel int p_trigMode; /* asynInt32 */ int p_evCodes[8]; /* asynInt32Array, rw */ // list of event codes int p_trigDelay[8]; /* asynInt32, rw */ // triger delay int p_trigWidth[8]; /* asynInt32, rw */ // triger width int p_trigPolarity[8]; /* asynInt32, rw */ int p_trigEnable[8]; /* asynInt32, rw */ int p_trigAccelDelay; /* asynInt32 */ int p_trigStdbyDelay; /* asynInt32 */ int p_trigIndvDelay[4]; /* asynInt32 */ int p_ISPTbl; /* asynFloat64Array, rw */ int p_QSPTbl; /* asynFloat64Array, rw */ int p_ApplWndStart; /* asynFloat64, rw */ int p_ApplWndEnd; /* asynFloat64, rw */ int p_corrScale[6]; /* asynFloat64, rw */ int p_corrAngle[6]; /* asynFloat64, rw */ int p_forceRearm; /* asynInt32, rw */ int p_debugStreamSelect[6]; /* asynInt32 */ int p_timeslotAware; /* asynInt32 */ int p_attenuator[12]; /* asynInt32 */ int p_temperature[8]; /* asynFloat64 */ int p_ckPhase; /* asynInt32 */ int p_refPhaseSP; /* asynFloat64 */ // diagnostics for stream readout int p_stream_done_cnt; /* asynInt32 */ int p_stream_flush_cnt; /* asynInt32 */ int p_stream_cycle_intv[8]; /* asynInt32 */ int p_stream_cycle_max[8]; /* asynInt32 */ int p_stream_cycle_min[8]; /* asynInt32 */ int p_stream_intv_reset; /* asynInt32 */ // rtm interlock module int p_rtmStatus; /* asynInt32 */ int p_rtmClearFault; /* asynInt32 */ int p_rtmFaultOutStatus; /* asynInt32 */ int p_rtmAdcLockedStatus; /* asynInt32 */ int p_rtmRFOffStatus; /* asynInt32 */ int p_rtmDesiredSled; /* asynInt32 */ int p_rtmThresholdAdcInFwdPower; /* asynFloat64 */ int p_rtmThresholdAdcInRefPower; /* asynFloat64 */ int p_rtmThresholdAdcInBeamCurrent; /* asynFloat64 */ int p_rtmThresholdAdcInBeamVoltage; /* asynFloat64 */ int p_rtmModThresholdFwdPower; /* asynFloat64 */ // modulator threshold A int p_rtmModThresholdRefPower; /* asynFloat64 */ // modulator threshold B int p_rtmKlyThresholdBeamCurrent; /* asynFloat64 */ // Klystron threshold A int p_rtmKlyThresholdBeamVoltage; /* asynFloat64 */ // Klystron threshold B int p_stroeNVThreadsholdFwdPower; /* asynInt32 */ int p_storeNVThreadsholdRefPower; /* asynInt32 */ int p_storeNVThreadSholdBeamCurrent; /* asynInt32 */ int p_storeNVThreadSholdVoltage; /* asynInt32 */ int p_rtmBeamCurrentWF; /* asynFloat64Array */ int p_rtmBeamVoltageWF; /* asynFloat64Array */ int p_rtmFwdPowerWF; /* asynFloat64Array */ int p_rtmRefPowerWF; /* asynFloat64Array */ int p_rtmBeamCurrentScaled; /* asynFloat64Array */ int p_rtmBeamVoltageScaled; /* asynFloat64Array */ int p_rtmFwdPowerScaled; /* asynFloat64Array */ int p_rtmRefPowerScaled; /* asynFloat64Array */ int p_pulseIdBeamCurrent; /* asynInt32 */ int p_pulseIdBeamVoltage; /* asynInt32 */ int p_pulseIdFwdPower; /* asynInt32 */ int p_pulseIdRefPower; /* asynInt32 */ int p_rtmSetFwdcalRatio; /* asynFloat64 */ int p_rtmSetRefcalRatio; /* asynFloat64 */ int p_rtmSetDivrRatio; /* asynFloat64 */ int p_rtmSetCurrRatio; /* asynFloat64 */ int p_rtmBeamCurrentHist[4]; /* asynFloat64Array */ int p_rtmBeamVoltageHist[4]; /* asynFloat64Array */ int p_rtmFwdPowerHist[4]; /* asynFloat64Arrray */ int p_rtmRefPowerHist[4]; /* asynFloat64Arrat */ int p_pulseIdBeamCurrentHist[4]; /* asynInt32 */ int p_pulseIdBeamVoltageHist[4]; /* asynInt32 */ int p_pulseIdFwdPowerHist[4]; /* asynInt32 */ int p_pulseIdRefPowerHist[4]; /* asynInt32 */ int p_rtmSetThresholdFwdPower; /* asynFloat64 */ int p_rtmSetThresholdRefPower; /* asynFloat64 */ int p_rtmSetThresholdBeamCurrent; /* asynFloat64 */ int p_rtmSetThresholdBeamVoltage; /* asynFloat64 */ int lastKlystronParam; #define LAST_KLYSTRON_PARAM lastKlystronParam }; #define NUM_KLYSTRON_DET_PARAMS ((int)(&LAST_KLYSTRON_PARAM - &FIRST_KLYSTRON_PARAM +1)) #define lo_kpString "lo_kp" #define lo_kiString "lo_ki" #define clk_kpString "clk_kp" #define clk_kiString "clk_ki" #define adpll_kpString "adpll_kp" #define adpll_kiString "adpll_ki" #define loPllPhaseString "loPllPhase" #define loPllAmplitudeString "loPllAmplitude" #define loPllLockedString "loPllLocked" #define clockPllPhaseString "clockPllPhase" #define clockPllAmplitudeString "clockPllAmplitude" #define clockPllLockedString "clockPllLocked" #define adPllPhaseString "adPllPhase" #define adPllAmplitudeString "adPllAmplitude" #define adPllLockedString "adPllLocked" #define loPllPhaseDegreeString "loPllPhaseDegree" #define clockPllPhaseDegreeString "clockPllPhaseDegree" #define adPllPhaseDegreeString "adPllPhaseDegree" #define loPllLossSignalString "loPllLossSignal" #define clockPllLossSignalString "clockPllLossSignal" #define adPllLossSignalString "adPllLossSignal" #define loPllUnlockCounterString "loPllUnlockCounter" #define clockPllUnlockCounterString "clockPllUnlockCounter" #define adPllUnlockCounterString "adPllUnlockCounter" #define resetPllUnlockCounterString "resetPllUnlockCounter" #define loPllNormAmplitudeString "loPllNormAmplitude" #define clockPllNormAmplitudeString "clockPllNormAmplitude" #define adPllNormAmplitudeString "adPllNormAmplitude" #define jesdResyncCntString "jesdResyncCnt%d%d" #define resetJesdResyncCntString "resetJesdResyncCnt" #define cntModeString "cntMode" #define outputEnableString "outputEnable" #define cwEnableString "cwEnable" #define refChnString "refChn" #define fdkChnString "fdkChn" #define trigModeString "trigMode" #define trigEnableString "%sEnable" #define trigEvCodesString "%sEvCodes" #define trigPolarityString "%sPolarity" #define trigDelayString "%sDelay" #define trigWidthString "%sWidth" #define trigAccelDelayString "accelDelay" #define trigStdbyDelayString "stdbyDelay" #define trigIndvDelayString "%sIndvDelay" #define ISPTblString "ISPTbl" #define QSPTblString "QSPTbl" #define applWndStartString "applWndStart" #define applWndEndString "applWndEnd" #define corrScaleTS4String "corrScaleT4" #define corrPhaseTS4String "corrPhaseT4" #define corrScaleTS1String "corrScaleT1" #define corrPhaseTS1String "corrPhaseT1" #define corrScaleTS2String "corrScaleT2" #define corrPhaseTS2String "corrPhaseT2" #define corrScaleTS3String "corrScaleT3" #define corrPhaseTS3String "corrPhaseT3" #define corrScaleTS5String "corrScaleT5" #define corrPhaseTS5String "corrPhaseT5" #define corrScaleTS6String "corrScaleT6" #define corrPhaseTS6String "corrPhaseT6" #define forceRearmString "forceRearm" #define debugStreamSelectString "debugStream%dSelect" #define timeslotAwareString "timeslotAware" #define attenuatorString "attenBay%dChn%d" #define temperatureString "bay%dTemp%d" #define ckPhaseString "ckPhase" #define refPhaseSPString "refPhaseSP" #define streamDoneCntString "streamDoneCnt" #define streamFlushCntString "streamFlushCnt" #define streamCycleIntvString "streamCycleIntv%d" #define streamCycleMaxIntvString "streamCycleMaxIntv%d" #define streamCycleMinIntvString "streamCycleMinIntv%d" #define streamCycleIntvResetString "streamCycleIntvReset" #define rtmStatusString "rtmStatus" #define rtmFaultOutStatusString "rtmFaultOut" #define rtmAdcLockedStatusString "rtmAdcLocked" #define rtmRFOffStatusString "rtmRFOff" #define rtmThresholdAdcInFwdPowerString "FwdPower_AdcIn" #define rtmThresholdAdcInRefPowerString "RefPower_AdcIn" #define rtmThresholdAdcInBeamCurrentString "BeamCurrent_AdcIn" #define rtmThresholdAdcInBeamVoltageString "BeamVoltage_AdcIn" #define rtmModThresholdFwdPowerString "modThresholdFwdPower" // modulator threshold A #define rtmModThresholdRefPowerString "modThresholdRefPower" // modulator threshold B #define rtmKlyThresholdBeamCurrentString "klyThresholdBeamCurrent" // Klystron threshold A #define rtmKlyThresholdBeamVoltageString "klyThresholdBeamVoltage" // Klystron threshold B #define rtmClearFaultString "rtmClearFault" #define rtmDesiredSledString "rtmDesiredSled" #define rtmBeamVoltageWFString "rtmBeamVoltageWF" #define rtmBeamVoltageScaledString "rtmBeamVoltageScaled" #define rtmBeamVoltageHistWFString "rtmBeamVoltageHist%d" #define rtmBeamCurrentWFString "rtmBeamCurrentWF" #define rtmBeamCurrentScaledString "rtmBeamCurrentScaled" #define rtmBeamCurrentHistWFString "rtmBeamCurrentHist%d" #define rtmFwdPowerWFString "rtmFwdPowerWF" #define rtmFwdPowerScaledString "rtmFwdPowerScaled" #define rtmFwdPowerHistWFString "rtmFwdPowerHist%d" #define rtmRefPowerWFString "rtmRefPowerWF" #define rtmRefPowerScaledString "rtmRefPowerScaled" #define rtmRefPowerHistWFString "rtmRefPowerHist%d" #define rtmSetFwdcalRatioString "rtmSetFwdcalRatio" #define rtmSetRefcalRatioString "rtmSetRefcalRatio" #define rtmSetDivrRatioString "rtmSetDivrRatio" #define rtmSetCurrRatioString "rtmSetCurrRatio" #define rtmPulseIdBeamCurrentString "pulseId_beamCurrent" #define rtmPulseIdBeamVoltageString "pulseId_beamVoltage" #define rtmPulseIdFwdPowerString "pulseId_fwdPower" #define rtmPulseIdRefPowerString "pulseId_refPower" #define rtmPulseIdBeamCurrentHistString "pulseId_beamCurrentHist%d" #define rtmPulseIdBeamVoltageHistString "pulseId_beamVoltageHist%d" #define rtmPulseIdFwdPowerHistString "pulseId_fwdPowerHist%d" #define rtmPulseIdRefPowerHistString "pulseId_refPowerHist%d" #define rtmSetThresholdFwdPowerString "rtmSetFwdPower" #define rtmSetThresholdRefPowerString "rtmSetRefPower" #define rtmSetThresholdBeamCurrentString "rtmSetBeamCurrent" #define rtmSetThresholdBeamVoltageString "rtmSetBeamVoltage" // RTM interlock #endif /* CPSW_KLYSTRON_ASYN_DRIVER_H */