My Project
evgRegMap.h
1 /*************************************************************************\
2 * Copyright (c) 2010 Brookhaven Science Associates, as Operator of
3 * Brookhaven National Laboratory.
4 * Copyright (c) 2015 Paul Scherrer Institute (PSI), Villigen, Switzerland
5 * mrfioc2 is distributed subject to a Software License Agreement found
6 * in file LICENSE that is included with this distribution.
7 \*************************************************************************/
8 #ifndef EVGREGMAP_H
9 #define EVGREGMAP_H
10 
11 #include "epicsTypes.h"
12 
13 /*
14  * Series 2xx Event Generator Modular Register Map
15  *
16  * For firmware version #8
17  * as documented in EVR-MRM-008.doc
18  * Jukka Pietarinen
19  * 07 Dec 2015
20  *
21  * Important note about data width
22  *
23  * All registers can be accessed with 8, 16, or 32 width
24  * however, to support transparent operation for both
25  * VME and PCI bus it is necessary to use only 32 bit
26  * access assuming MSB ordering.
27  *
28  * Bus bridge chips will transparently change the byte order.
29  * VME bridges do this for any data width. The PLX and lattice bridges
30  * do this assuming 32-bit data width.
31  */
32 
33 //=====================
34 // Status Registers
35 //
36 #define U32_Status 0x0000 // Status Register (full)
37 #define U8_DBusRxValue 0x0000 // Distributed Data Bus Received Values
38 #define U8_DBusTxValue 0x0001 // Distributed Data Bus Transmitted Values
39 
40 //=====================
41 // General Control Register
42 //
43 #define U32_Control 0x0004 // Control Register
44 
45 //=====================
46 // Interrupt Control Registers
47 //
48 #define U32_IrqFlag 0x0008 // Interrupt Flag Register
49 #define U32_IrqEnable 0x000C // Interrupt Enable Register
50 
51 #define EVG_IRQ_ENABLE 0x80000000 // Master Interrupt Enable Bit
52 #define EVG_IRQ_PCIIE 0x40000000
53 #define EVG_IRQ_STOP_RAM_BASE 0x00001000 // Sequence RAM Stop Interrupt Bit
54 #define EVG_IRQ_STOP_RAM(N) (EVG_IRQ_STOP_RAM_BASE<<N)
55 #define EVG_IRQ_START_RAM_BASE 0x00000100 // Sequence RAM Start Interrupt Bit
56 #define EVG_IRQ_START_RAM(N) (EVG_IRQ_START_RAM_BASE<<N)
57 #define EVG_IRQ_EXT_INP 0x00000040 // External Input Interrupt Bit
58 #define EVG_IRQ_DBUFF 0x00000020 // Data Buffer Interrupt Bit
59 #define EVG_IRQ_FIFO 0x00000002 // Event FIFO Full Interrupt Bit
60 #define EVG_IRQ_RXVIO 0x00000001 // Receiver Violation Bit
61 
62 // With Linux this bit should used by the kernel driver exclusively
63 #define U32_PCI_MIE 0x001C
64 #define EVG_MIE_ENABLE 0x40000000
65 
66 //=====================
67 // AC Trigger Control Registers
68 //
69 #define U32_AcTrigControl 0x0010
70 
71 #define AcTrigControl_Sync_MASK 0x000d0000
72 #define AcTrigControl_Sync_SHIFT 16
73 #define AcTrigControl_Bypass 0x00020000
74 #define AcTrigControl_Divider_MASK 0x0000ff00
75 #define AcTrigControl_Divider_SHIFT 8
76 #define AcTrigControl_Phase_MASK 0x000000ff
77 #define AcTrigControl_Phase_SHIFT 0
78 
79 #define U32_AcTrigMap 0x0014
80 
81 #define AcTrigMap_EvtMASK 0x000000ff
82 #define AcTrigMap_EvtSHIFT 0
83 
84 //=====================
85 // Software Event Control Registers
86 //
87 #define U32_SwEvent 0x0018
88 
89 #define SwEvent_Ena 0x00000100
90 #define SwEvent_Pend 0x00000200
91 #define SwEvent_Code_MASK 0x000000ff
92 #define SwEvent_Code_SHIFT 0
93 
94 //=====================
95 // Data Buffer and Distributed Data Bus Control
96 //
97 #define U32_DataBufferControl 0x0020 // Data Buffer Control Register
98 #define U32_DBusSrc 0x0024 // Distributed Data Bus Mapping Register
99 #define U32_DBusTSEvt 0x0028 // Timestamp events configure for the distributed Data BusD
100 
101 #define TSDBusEvt_MASK 0x000000E0
102 #define TSDBusEvt_SHIFT 5
103 
104 //=====================
105 // FPGA Firmware Version
106 //
107 #define U32_FPGAVersion 0x002C // FPGA Firmware Version
108 
109 #define FPGAVersion_TYPE_MASK 0xF0000000
110 #define FPGAVersion_FORM_MASK 0x0F000000
111 #define FPGAVersion_FORM_SHIFT 24
112 #define FPGAVersion_TYPE_SHIFT 28
113 #define FPGAVersion_VER_MASK 0x000000FF
114 
115 //=====================
116 // Timestamp Control
117 //
118 #define U32_TSControl 0x0034 // TS Control register
119 #define TSGenerator_ena_MASK 0x01
120 #define TSGenerator_ena_SHIFT 0
121 #define TSValuse_load_MASK 0x02
122 #define TSValuse_load_SHIFT 1
123 #define U32_TSValue 0x0038 // TS Value to transmit
124 
125 //=====================
126 // Event Clock Control
127 //
128 #define U32_uSecDiv 0x004C // Event Clock Freq Rounded to Nearest 1 MHz
129 
130 #define U32_ClockControl 0x0050
131 
132 #define ClockControl_plllock 0x80000000
133 #define ClockControl_Sel_MASK 0x07000000
134 #define ClockControl_Sel_SHIFT 24
135 #define ClockControl_pllbw 0x70000000
136 #define ClockControl_pllbw_SHIFT 28
137 #define ClockControl_Div_MASK 0x003f0000
138 #define ClockControl_Div_SHIFT 16
139 #define ClockControl_EXTRF 0x01000000 // External/Internal reference clock select
140 #define ClockControl_cglock 0x00000200
141 
142 #define PLLBandwidth_MAX 4
143 
144 #define U8_ClockSource 0x0050 // Event Clock Source(Internal or RF Input)
145 #define U8_RfDiv 0x0051 // RF Input Divider
146 #define U16_ClockStatus 0x0052 // Event Clock Status
147 
148 //=====================
149 // Event Analyzer Registers
150 //
151 #define U32_EvAnControl 0x0060 // Event Analyser Control/Status Register
152 #define U16_EvAnEvent 0x0066 // Event Code & Data Buffer Byte
153 #define U32_EvAnTimeHigh 0x0068 // High-Order 32 Bits of Time Stamp Counter
154 #define U32_EvAnTimeLow 0x006C // Low-Order 32 Bits of Time Stamp Counter
155 
156 //=====================
157 // Sequence RAM Control Registers
158 //
159 #define U32_SeqControl_base 0x0070 // Sequencer Control Register Array Base
160 #define U32_SeqControl(n) (U32_SeqControl_base + (4*n))
161 
162 #define SeqControl_TrigSrc_MASK 0x000000ff
163 #define SeqControl_TrigSrc_SHIFT 0
164 
165 //=====================
166 // Fractional Synthesizer Control Word
167 //
168 #define U32_FracSynthWord 0x0080 // RF Reference Clock Pattern (Micrel SY87739L)
169 
170 //=====================
171 // RF Recovery
172 //
173 #define U32_RxInitPS 0x0088 // Initial Value For RF Recovery DCM Phase
174 
175 // SPI device access (eg. FPGA configuration eeprom)
176 #define U32_SPIDData 0x0A0
177 #define U32_SPIDCtrl 0x0A4
178 
179 //=====================
180 // Trigger Event Control Registers
181 //
182 #define U32_TrigEventCtrl_base 0x0100 // Trigger Event Control Register Array Base
183 #define U32_TrigEventCtrl(n) (U32_TrigEventCtrl_base + (4*(n)))
184 
185 #define TrigEventCtrl_Ena 0x00000100
186 #define TrigEventCtrl_Code_MASK 0x000000ff
187 #define TrigEventCtrl_Code_SHIFT 0
188 
189 #define U8_TrigEventCode(n) (U32_TrigEventCtrl(n) + 3)
190 
191 #define EVG_TRIG_EVT_ENA 0x00000100
192 
193 //=====================
194 // Multiplexed Counter Control Register Arrays
195 //
196 #define U32_MuxControl_base 0x0180 // Mux Counter Control Register Base Offset
197 #define U32_MuxPrescaler_base 0x0184 // Mux Counter Prescaler Register Base Offset
198 
199 #define U32_MuxControl(n) (U32_MuxControl_base + (8*(n)))
200 
201 #define MuxControl_Pol 0x40000000
202 #define MuxControl_Sts 0x80000000
203 #define MuxControl_TrigMap_MASK 0x000000ff
204 #define MuxControl_TrigMap_SHIFT 0
205 
206 #define U32_MuxPrescaler(n) (U32_MuxPrescaler_base + (8*(n)))
207 
208 //=====================
209 // Front Panel Output Mapping Register Array
210 //
211 #define U16_FrontOutMap_base 0x0400 // Front Output Port Mapping Register Offset
212 #define U16_FrontOutMap(n) (U16_FrontOutMap_base + (2*(n)))
213 
214 //=====================
215 // Front Panel Universal Output Mapping Register Array
216 //
217 #define U16_UnivOutMap_base 0x0440 // Front Univ Output Mapping Register
218 #define U16_UnivOutMap(n) (U16_UnivOutMap_base + (2*(n)))
219 
220 //=====================
221 // Front Panel Input Mapping Registers
222 //
223 #define U32_FrontInMap_base 0x0500 // Front Input Port Mapping Register
224 #define U32_FrontInMap(n) (U32_FrontInMap_base + (4*(n)))
225 
226 //=====================
227 // Front Panel Universal Input Mapping Registers
228 //
229 #define U32_UnivInMap_base 0x0540 // Front Univ Input Port Mapping Register
230 #define U32_UnivInMap(n) (U32_UnivInMap_base + (4*(n)))
231 
232 
233 //=====================
234 // Rear Universal Input Mapping Registers
235 //
236 #define U32_RearInMap_base 0x0600 // Rear Univ Input Port Mapping Register
237 #define U32_RearInMap(n) (U32_RearInMap_base + (4*(n)))
238 
239 //=====================
240 // Data Buffer Area
241 //
242 #define U8_DataBuffer_base 0x0800 // Data Buffer Array Base Offset
243 #define U8_DataBuffer(n) (U8_DataBuffer_base + n)
244 
245 //=====================
246 // Sequence RAMs
247 //
248 #define U32_SeqRamTS_base 0x8000 // Sequence Ram Timestamp Array Base Offset
249 #define U32_SeqRamTS(n,m) (U32_SeqRamTS_base + (0x4000*(n)) + (8*(m)))
250 
251 #define U32_SeqRamEvent_base 0x8004 // Sequence Ram Event Code Array Base Offset
252 #define U32_SeqRamEvent(n,m) (U32_SeqRamEvent_base + (0x4000*(n)) + (8*(m)))
253 
254 // Number of entrys in each ram
255 #define SeqRam_Length (0x4000/8)
256 
257 //=====================
258 // Size of Event Generator Register Space
259 //
260 #define EVG_REGMAP_SIZE 0x10000 // Register map size is 64K
261 
262 
263 /**************************************************************************************************/
264 /* Sequence RAM Control Register (0x0070, 0x0074) Bit Assignments */
265 /**************************************************************************************************/
266 
267 #define EVG_SEQ_RAM_RUNNING 0x02000000 // Sequence RAM is Running (read only)
268 #define EVG_SEQ_RAM_ENABLED 0x01000000 // Sequence RAM is Enabled (read only)
269 
270 #define EVG_SEQ_RAM_SW_TRIG 0x00200000 // Sequence RAM Software Trigger Bit
271 #define EVG_SEQ_RAM_RESET 0x00040000 // Sequence RAM Reset
272 #define EVG_SEQ_RAM_DISABLE 0x00020000 // Sequence RAM Disable
273 #define EVG_SEQ_RAM_ARM 0x00010000 // Sequence RAM Enable/Arm
274 
275 #define EVG_SEQ_RAM_REPEAT_MASK 0x00180000 // Sequence RAM Repeat Mode Mask
276 #define EVG_SEQ_RAM_NORMAL 0x00000000 // Normal Mode: Repeat every trigger
277 #define EVG_SEQ_RAM_SINGLE 0x00100000 // Single-Shot Mode: Disable on completion
278 #define EVG_SEQ_RAM_RECYCLE 0x00080000 // Continuous Mode: Repeat on completion
279 
280 //Mask registers
281 #define EVG_SEQ_RAM_SWMASK 0x0000F000 // Sequence RAM Software mask
282 #define EVG_SEQ_RAM_SWMASK_shift 12
283 #define EVG_SEQ_RAM_SWENABLE 0x00000F00 // Sequence RAM Software enable
284 #define EVG_SEQ_RAM_SWENABLE_shift 8
285 
286 /**************************************************************************************************/
287 /* Control Register flags */
288 /**************************************************************************************************/
289 
290 #define EVG_MASTER_ENA 0x80000000
291 #define EVG_DIS_EVT_REC 0x40000000
292 #define EVG_REV_PWD_DOWN 0x20000000
293 #define EVG_MXC_RESET 0x01000000
294 #define EVG_BCGEN 0x00800000
295 #define EVG_DCMST 0x00400000
296 
297 /**************************************************************************************************/
298 /* Input */
299 /**************************************************************************************************/
300 
301 #define EVG_EXT_INP_IRQ_ENA 0x01000000
302 #define EVG_INP_FP_ENA 0x0F000000
303 #define EVG_INP_FP_ENA_shift 24
304 #define EVG_INP_FP_MASK 0xF0000000
305 #define EVG_INP_FP_MASK_shift 28
306 #define EVG_INP_MXCR_ENA 0x00008000
307 #define EVG_INP_MXCR_ENA_shift 15
308 
309 #ifndef EVG_CONSTANTS
310 #define EVG_CONSTANTS
311 
312 #define evgNumMxc 8
313 #define evgNumEvtTrig 8
314 #define evgNumDbusBit 8
315 #define evgNumFrontOut 6
316 #define evgNumUnivOut 4
317 #define evgNumSeqRam 2
318 #define evgAllowedTsGitter 0.5f
319 #define evgEndOfSeqBuf 5
320 
321 #endif
322 
323 #endif /* EVGREGMAP_H */