/* ****************************************************************************** * Modification history * Mod: Shantha Condamoor 11-Nov-2013 * Changed LLRF_KLY21_1 to LLRF_LSRDIAG as this slot (20) is now used * for Coherent 2 Laser Diagnostics PAD * Added LLRF_LSRDIAG related variables to structures * Added lsrDiagSetDesiredPhase() and lsrDiagSetInputSource() * Mod: Shantha Condamoor 18-Mar-2014 - Changes from code review done on 17-Mar-2014: * Added macro LLRF_PROCESSED_DATA **************************************************************************** */ #ifndef DRV_LLRF_PAD_H #define DRV_LLRF_PAD_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include "llrfMacros.h" #ifdef LLRF_KLY_PAD #elif defined LLRF_KLY_PAD2 #define NON_FEEDBACK_PAD #endif #ifdef DATAPROC_BLOB #include "drvPadDataProc.h" #endif /* PAD ai - LLRFAI Fast high-priority input attributes */ #define IAVG 0 /* I for Interlaced waveforms */ #define SAVG 0 /* Average for Simple waveforms */ #define QAVG 1 /* Q for Interlaced waveforms */ #define PHASE 2 /* Phase for Interlaced waveforms */ #define AMPLITUDE 3 /* Amplitude for Interlaced waveforms */ #define SAMPLITUDE 3 /* Amplitude for Simple waveforms */ #define POWER 4 /* Power for Interlaced waveforms */ #define SPOWER 4 /* Power for Simple waveforms */ /* PAD ai - LLRFAI Slow low-priority input attributes */ #define OVRFLOW 5 /* Channel Overflow for CWs */ #define SOVRFLOW 5 /* Channel Overflow for simple wfs */ #define ALIGN_START 6 #define ALIGN_END 7 #define ROTATEDI 8 /* var: rotatedI PV: IROT */ #define ROTATEDQ 9 /* var: rotatedQ PV: QROT */ #define ROTPHASE 10 /* var: rotatedPhase PV: PACT */ #define NONROTPHASE 11 /* var: nonRotatedPhase PV: NRPA */ #define PACT 12 /* var: actual_phase PV: FB_PACT */ #define AACT 13 /* var: actual_ampl PV: FB_AACT */ #define PDES 14 /* var: desired_phase PV: PDES */ /* 476 MHz */ #define PDES2856 15 /* var: desired_phase2856 PV: PDES2856 */ /* 2856 MHz */ #define PDES68 16 /* var: desired_phase68 PV: PDES68 */ /* 68 MHz */ /* #define PDES119 16 */ /* var: desired_phase119 PV: PDES119 */ /* 119 MHz */ #define MIDPOINT 17 #define LAST_AI 18 /* PAD ao - LLRFA0 output attributes */ #define OFST 0 #define SIZE 1 #define FREQ 2 #define POC 3 #define AVC 4 #define SF 4 #define APC 5 #define MON_PDES 6 /* var: mon_desired_phase PV: MON_PDES */ #define MON_IADJ 7 /* var: mon_iadjust PV: MON_IADJ */ #define MON_QADJ 8 /* var: mon_qadjust PV: MON_QADJ */ #define MON_POC 9 /* var: mon_poc PV: MON_POC */ #define LAST_AO 10 /* PAD mbbo - LLRFMBBO output attributes */ #define SOURCE 0 #define LAST_MBBO 1 /* I/Q/P/A etc. can be calculated for different samples within the raw waveforms */ /* For example: Beam Phase cavity waveforms contain two distinct samples withing the same waveform that must be processed separately */ #ifdef LLRF_PCAV1_NG #elif defined LLRF_PCAV2_NG #elif defined LLRF_PCAV3_NG #elif defined LLRF_PCAV4_NG #define LLRF_WF_SAMPLES 2 #else #define LLRF_WF_SAMPLES 1 #endif /* Waveforms are sampled at 0,60,120,180,240,300 degrees for 119 MHz signals */ /* Waveforms are sampled at 0,120,240 degrees for 68 MHz signals */ /* Waveforms are sampled at 0,90,180,270 degrees for 2856 MHz signals that are downmixed to 25.5 Mhz */ #define LLRF_PHASE_ANGLES 6 /* Number of shorts that are added to the drvPadDataProc message queue */ #define LLRF_PROCESSED_DATA 24 typedef epicsTimeStamp TimeStamp; typedef epicsInt16 LlrfInNumber; #define DRVLLRF_INP_FTVL menuFtypeSHORT typedef epicsInt32 LlrfOutNumber; #define DRVLLRF_OUT_FTVL menuFtypeLONG /* for waveforms that contain more than one sample - like PCAV */ typedef struct LlrfChannelSampleRec_ { LlrfOutNumber sum_acc[6]; LlrfOutNumber num_acc[6]; LlrfOutNumber sum[6]; LlrfOutNumber num[6]; LlrfInNumber I; /* same as S for simple waveforms */ LlrfInNumber Q; double Phase; double Amplitude; double Power; LlrfOutNumber ofst; LlrfOutNumber size; LlrfInNumber aligned_start; LlrfInNumber aligned_end; LlrfInNumber x; /* midpoint */ } LlrfChannelSampleRec, *LlrfChannelSample; typedef struct LlrfChannelRec_ { unsigned frags; LlrfOutNumber sum_acc[6]; LlrfOutNumber num_acc[6]; LlrfOutNumber sum[6]; LlrfOutNumber num[6]; LlrfOutNumber Overflow; /* PAD channel Overflow counts */ LlrfInNumber I; /* same as S for simple waveforms */ LlrfInNumber Q; double Phase; double Amplitude; double Power; LlrfInNumber vec[LLRF_NUM_SAMPLES]; LlrfOutNumber ofst; LlrfOutNumber size; double poc; double avc; double apc; LlrfOutNumber freq; /* freq of incoming channel in MHz. 0 means simple averaging */ int number; /*Channel number 0,1,2,3 */ LlrfInNumber aligned_start; LlrfInNumber aligned_end; double rotatedQ; /* rotated by either desired_phase2856 or desired_phase (68 or 119), depending on the channel */ double rotatedI; double rotatedPhase; /* rotated by ... */ double nonRotatedPhase; LlrfInNumber x; /* midpoint */ int stn; /* station number same for all 4 channels */ LlrfChannelSample Samples; /* Pointer Samples= LlrfChannelSampleRec for PCAV channels else Samples = NULL */ } LlrfChannelRec, *LlrfChannel; typedef struct LlrfStationRec_ { LlrfChannelRec chnls[PAD_NUM_CHANNELS_ON_BOARD]; epicsEventId rawDataReady; epicsTimeStamp tsSum; epicsThreadId fcomProcessThread; float fcomPavg; float fcomAavg; uint32_t xid; unsigned chnlsDone; /* timedout is a bitmask. The 4 LSB represent the four Isums (ch0..ch3) * the next 4 bits the Phases (ch0..ch3). A clear bit indicates OK data. * The 'timedout' bit reflect the status of the udpComm link. If the * drvPadUdpComm watchdog fires (no udpComm traffic seen for a while) * then 'timedout' is set to all ones. Bits are cleared as new * Isums/Phases are computed. */ #define LLRF_TIMEDOUT(channel) (1<<(channel)) #define LLRF_TIMEDOUT_ANY_RAW 0x0f #define LLRF_TIMEDOUT_ANY_IMAX 0xf0 #define LLRF_TIMEDOUT_ALL (-1) unsigned timedout; int epics_event_no; epicsMutexId mutex; int index; #ifdef DATAPROC_BLOB genericPadData_p padData_p; #endif LlrfOutNumber input_source; double actual_phase; /* units are deg 476 */ double actual_ampl; double mon_desired_phase; /* monitor des phase set in laser subystem PV - units are deg 2856 */ double mon_iadjust; /* monitor IADJUST changes from Laser PAC */ double mon_qadjust; /* monitor QADJUST changes from Laser PAC */ double desired_phase; /* units are deg 476 */ double desired_phase2856; /* LSR needs this in calc */ double desired_phase68; /* LSR needs this in calc */ /* double desired_phase119; */ /* LSR needs this in calc */ double mon_poc; /* monitor phase offset set in laser subystem PV - units are deg 2856 */ } LlrfStationRec, *LlrfStation; int llrfPadInitialise(void); /* station is 1-based, channel is 0-based */ LlrfStation llrfGetStation(int station); double llrfGetPadDoubleValue(unsigned station, unsigned channel, unsigned sample, epicsTimeStamp *ts_p, unsigned attr); LlrfOutNumber llrfGetPadIntegerValue(unsigned station, unsigned channel, unsigned sample, epicsTimeStamp *ts_p, unsigned attr); int llrfSetPadValue(int station, int channel, unsigned sample, double val, unsigned attr); int lsrDiagSetDesiredPhase(int station, double phase); int lsrDiagSetDesiredPhaseOffset(int station, double phase); int lsrDiagSetInputSource(int station, LlrfOutNumber source); #ifdef FCOM_BLOB void llrfFcomTaskResumeAll(void); #endif typedef long (*DrvLlrf_read_raw_ai_cb)(aiRecord *pai, TimeStamp *pts, unsigned r, unsigned c, unsigned s); long drvLlrf_read_raw_ai_helper(aiRecord *pai, DrvLlrf_read_raw_ai_cb cb); long drvLlrf_read_raw_ai(aiRecord *pai); typedef long (*DrvLlrf_init_raw_ai_cb)(aiRecord *pai, unsigned r, unsigned c, unsigned s); long drvLlrf_init_raw_ai_helper(aiRecord *pai, DrvLlrf_init_raw_ai_cb cb); /* NULL callback doing nothing */ long drvLlrf_init_raw_ai_generic(void *precord); long drvLlrf_init_raw_ai(aiRecord *pai); double sysClkPeriodGet(); #endif