#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 writeFloat64(asynUser *pasynUser, epicsFloat64 value); asynStatus writeFloat64Array(asynUser *pasynUser, epicsFloat64 *values, size_t nElements); void KlystronStreamTask(void *p); void KlystronInterlockTask(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 setRtmThresholdFwdPower(double value); void setRtmThresholdRefPower(double value); void setRtmThresholdBeamCurrent(double value); void setRtmThresholdBeamVoltage(double value); 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[2]; double corrAngle[2]; epicsMutex *pmutex; uint8_t *pdone_mask; // 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; protected: // // parameter section for asynPortDriver // int firstKlystronParam; #define FIRST_KLYSTRON_PARAM firstKlystronParam 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[2]; /* asynFloat64, rw */ int p_corrAngle[2]; /* asynFloat64, rw */ int p_forceRearm; /* asynInt32, rw */ int p_debugStreamSelect[6]; /* asynInt32 */ int p_timeslotAware; /* asynInt32 */ int p_attenuator[12]; /* asynInt32 */ int p_ckPhase; /* asynInt32 */ int p_refPhaseSP; /* asynFloat64 */ // 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_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 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 forceRearmString "forceRearm" #define debugStreamSelectString "debugStream%dSelect" #define timeslotAwareString "timeslotAware" #define attenuatorString "attenBay%dChn%d" #define ckPhaseString "ckPhase" #define refPhaseSPString "refPhaseSP" #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 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 */