#ifndef CPSW_LLRF_ASYN_DRIVER_H #define CPSW_LLRF_ASYN_DRIVER_H #include #include #include #include #include #include #include #include #include #include #include #include #include "registerTimeStampSource.h" #define PULSEID(time) ((time).nsec & 0x0001ffff ) int rtm_rand(void); void rtm_srand(unsigned seed); extern "C" { void mrLlrfDataProc_setPrevPCorr(double v, unsigned timeslot); void mrLlrfDataProc_setPrevACorr(double v, unsigned timeslot); } // hack to acess mrLlrfDataProc, need to clean it up class cpswLlrfAsynDriver:asynPortDriver { public: cpswLlrfAsynDriver(const char *portName, const char *useYaml, const char *cfgYaml, const char *ipAddr); ~cpswLlrfAsynDriver(); 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 llrfStreamTask(void *p); void llrfInterlockTask(void *p); void initRtmWaveforms(void); void reportRtmWaveformBuffer(void); void clearRtmFaultHistory(void); void takeRtmFaultHistory(void); void postRtmFaultHistory(void); void getRtmWaveforms(void); void getRtmThresholdReadout(void); void setRtmThresholdFwdPower(double value); void setRtmThresholdRefPower(double value); void setRtmThresholdBeamCurrent(double value); void setRtmThresholdBeamVoltage(double value); void forceRearm(void); void cpswLlrfReport(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); LlrfMrFw 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; uint32_t rtmThresholdAdcInFwdPower_raw; uint32_t rtmThresholdAdcInRefPower_raw; uint32_t rtmThresholdAdcInBeamCurrent_raw; uint32_t rtmThresholdAdcInBeamVoltage_raw; double rtmThresholdAdcInFwdPower; double rtmThresholdAdcInRefPower; double rtmThresholdAdcInBeamCurrent; double rtmThresholdAdcInBeamVoltage; int rtmRandKey; int rtmUsrRandKey; protected: // // parameter section for asynPortDriver // int firstLlrfParam; #define FIRST_LLRF_PARAM firstLlrfParam 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_pulseIdBeamCurrent; /* asynInt32 */ int p_pulseIdBeamVoltage; /* asynInt32 */ int p_pulseIdFwdPower; /* asynInt32 */ int p_pulseIdRefPower; /* asynInt32 */ 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_rtmRandKey; /* asynInt32 */ int p_rtmSetRandKey; /* asynInt32 */ int p_rtmSetThresholdFwdPower; /* asynFloat64 */ int p_rtmSetThresholdRefPower; /* asynFloat64 */ int p_rtmSetThresholdBeamCurrent; /* asynFloat64 */ int p_rtmSetThresholdBeamVoltage; /* asynFloat64 */ int p_rtmStThresholdFwdPower; /* asynInt32 */ int p_rtmStThresholdRefPower; /* asynInt32 */ int p_rtmStThresholdBeamCurrent; /* asynInt32 */ int p_rtmStThresholdBeamVoltage; /* asynInt32 */ int lastLlrfParam; #define LAST_LLRF_PARAM lastLlrfParam }; #define NUM_LLRF_DET_PARAMS ((int)(&LAST_LLRF_PARAM - &FIRST_LLRF_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 threadhol A #define rtmModThresholdRefPowerString "modThresholdRefPower" // modulator threshold B #define rtmKlyThresholdBeamCurrentString "klyThresholdBeamCurrent" // klystorn threshold A #define rtmKlyThresholdBeamVoltageString "klyThresholdBeamVoltage" // klystron threshold B #define rtmClearFaultString "rtmClearFault" #define rtmBeamVoltageWFString "rtmBeamVoltageWF" #define rtmBeamVoltageHistWFString "rtmBeamVoltageHist%d" #define rtmBeamCurrentWFString "rtmBeamCurrentWF" #define rtmBeamCurrentHistWFString "rtmBeamCurrentHist%d" #define rtmFwdPowerWFString "rtmFwdPowerWF" #define rtmFwdPowerHistWFString "rtmFwdPowerHist%d" #define rtmRefPowerWFString "rtmRefPowerWF" #define rtmRefPowerHistWFString "rtmRefPowerHist%d" #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 rtmRandKeyString "rtmRandKey" #define rtmSetRandKeyString "rtmSetRandKey" #define rtmSetThresholdFwdPowerString "rtmSetFwdPower" #define rtmSetThresholdRefPowerString "rtmSetRefPower" #define rtmSetThresholdBeamCurrentString "rtmSetBeamCurrent" #define rtmSetThresholdBeamVoltageString "rtmSetBeamVoltage" #define rtmStThresholdFwdPowerString "rtmStFwdPower" #define rtmStThresholdRefPowerString "rtmStRefPower" #define rtmStThresholdBeamCurrentString "rtmStBeamCurrent" #define rtmStThresholdBeamVoltageString "rtmStBeamVoltage" // RTM interlock #endif /* CPSW_LLRF_ASYN_DRIVER_H */