My Project
evrRegMap.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 * Copyright (c) 2022 Cosylab d.d.
6 * mrfioc2 is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 /*
10  * Author: Michael Davidsaver <mdavidsaver@gmail.com>
11  */
12 
13 #ifndef EVRREGMAP_H
14 #define EVRREGMAP_H
15 
16 #include <mrfBitOps.h>
17 #include <shareLib.h> /* for INLINE (C only) */
18 
19 #ifdef __cplusplus
20 # ifndef INLINE
21 # define INLINE static inline
22 # endif
23 #endif
24 
25 /*
26  * Registers for Modular Register Map version of EVR
27  *
28  * For firmware version #4
29  * as documented in EVR-MRM-004.doc
30  * Jukka Pietarinen
31  * 07 Apr 2011
32  *
33  * Important note about data width
34  *
35  * All registers can be accessed with 8, 16, or 32 width
36  * however, to support transparent operation for both
37  * VME and PCI bus it is necessary to use only 32 bit
38  * access.
39  *
40  * Bus bridge chips will transparently change the byte order.
41  * VME bridges do this for any data width. The PLX and lattice bridges
42  * do this assuming 32-bit data width.
43  */
44 
45 #define evrNumDbusBit 8
46 
47 #define U32_Status 0x000
48 # define Status_dbus_mask 0xff000000
49 # define Status_dbus_shift 24
50 # define Status_legvio 0x00010000
51 # define Status_sfpmod 0x00000080
52 # define Status_linksts 0x00000040
53 # define Status_fifostop 0x00000020
54 
55 #define U32_Control 0x004
56 # define Control_enable 0x80000000
57 
58 # define Control_evtfwd 0x40000000
59 
60 /* 0 - normal, 1 loop back in logic */
61 # define Control_txloop 0x20000000
62 /* 0 - normal, 1 loop back in SFP */
63 # define Control_rxloop 0x10000000
64 
65 # define Control_outena 0x08000000 /* cPCI-EVRTG-300 only */
66 
67 # define Control_sreset 0x04000000 /* soft FPGA reset */
68 
69 # define Control_endian 0x02000000 /* 0 - MSB, 1 - LSB, 300 PCI devices only */
70 
71 # define Control_GTXio 0x01000000 /* GTX use external inhibit */
72 
73 # define Control_DCEna 0x00400000
74 
75 # define Control_pspol 0x00008000 /* prescaler polarity */
76 
77 /* Timestamp clock on DBUS #4 */
78 # define Control_tsdbus 0x00004000
79 # define Control_tsrst 0x00002000
80 # define Control_tsltch 0x00000400
81 
82 # define Control_mapena 0x00000200
83 # define Control_mapsel 0x00000100
84 
85 # define Control_logrst 0x00000080
86 # define Control_logena 0x00000040
87 # define Control_logdis 0x00000020
88 /* Stop Event Enable */
89 # define Control_logsea 0x00000010
90 # define Control_fiforst 0x00000008
91 
92 #define U32_IRQFlag 0x008
93 # define IRQ_EoS 0x1000
94 # define IRQ_SoS 0x0100
95 # define IRQ_LinkChg 0x40
96 # define IRQ_BufFull 0x20
97 # define IRQ_HWMapped 0x10
98 # define IRQ_Event 0x08
99 # define IRQ_Heartbeat 0x04
100 # define IRQ_FIFOFull 0x02
101 # define IRQ_RXErr 0x01
102 
103 #define U32_IRQEnable 0x00c
104 /* Same bits as IRQFlag plus */
105 # define IRQ_Enable 0x80000000
106 # define IRQ_PCIee 0x40000000
107 
108 #define U32_IRQPulseMap 0x010
109 
110 //=====================
111 // Software Event Control Registers
112 //
113 #define U32_SwEvent 0x0018
114 
115 #define SwEvent_Ena 0x00000100
116 #define SwEvent_Pend 0x00000200
117 #define SwEvent_Code_MASK 0x000000ff
118 #define SwEvent_Code_SHIFT 0
119 
120 // With Linux this bit should used by the kernel driver exclusively
121 #define U32_PCI_MIE 0x001C
122 #define EVG_MIE_ENABLE 0x40000000
123 
124 #define U32_DataBufCtrl 0x020
125 /* Write 1 to start, read for run status */
126 # define DataBufCtrl_rx 0x8000
127 /* Write 1 to stop, read for complete status */
128 # define DataBufCtrl_stop 0x4000
129 # define DataBufCtrl_sumerr 0x2000
130 # define DataBufCtrl_mode 0x1000
131 # define DataBufCtrl_len_mask 0x0fff
132 
133 #define U32_DataTxCtrl 0x024
134 # define DataTxCtrl_done 0x100000
135 # define DataTxCtrl_run 0x080000
136 # define DataTxCtrl_trig 0x040000
137 # define DataTxCtrl_ena 0x020000
138 # define DataTxCtrl_mode 0x010000
139 # define DataTxCtrl_len_mask 0x0007fc
140 
141 #define U32_FWVersion 0x02c
142 # define FWVersion_type_mask 0xf0000000
143 # define FWVersion_type_shift 28
144 # define FWVersion_form_mask 0x0f000000
145 # define FWVersion_form_shift 24
146 # define FWVersion_ver_mask 0x0000ffff
147 # define FWVersion_ver_shift 0
148 
149 #define U32_CounterPS 0x040 /* Timestamp event counter prescaler */
150 
151 #define U32_USecDiv 0x04C
152 
153 #define U32_ClkCtrl 0x050
154 # define ClkCtrl_plllock 0x80000000
155 # define ClkCtrl_pllbw 0x70000000
156 # define ClkCtrl_pllbw_SHIFT 28
157 # define ClkCtrl_clkmd_MASK 0x06000000
158 # define ClkCtrl_clkmd_SHIFT 25
159 # define ClkCtrl_cglock 0x00000200
160 # define PLLBandwidth_MAX 4
161 
162 #define U32_SRSec 0x05C
163 
164 #define U32_TSSec 0x060
165 #define U32_TSEvt 0x064
166 #define U32_TSSecLatch 0x068
167 #define U32_TSEvtLatch 0x06c
168 
169 #define U32_EvtFIFOSec 0x070
170 #define U32_EvtFIFOEvt 0x074
171 #define U32_EvtFIFOCode 0x078
172 
173 #define U32_LogStatus 0x07C
174 
175 #define U32_FracDiv 0x080
176 
177 #define U32_RFInitPhas 0x088
178 
179 #define U32_GPIODir 0x090
180 #define U32_GPIOIn 0x094
181 #define U32_GPIOOut 0x098
182 
183 // SPI device access (eg. FPGA configuration eeprom)
184 #define U32_SPIDData 0x0A0
185 #define U32_SPIDCtrl 0x0A4
186 
187 #define U32_DCTarget 0x0b0
188 #define U32_DCRxVal 0x0b4
189 #define U32_DCIntVal 0x0b8
190 #define U32_DCStatus 0x0bc
191 #define U32_TOPID 0x0c0
192 
193 #define U32_SeqControl_base 0x00e0
194 #define U32_SeqControl(n) (U32_SeqControl_base + (4*n))
195 
196 
197 #define U32_ScalerN 0x100
198 # define ScalerMax 8
199 /* 0 <= N <= 7 */
200 #define U32_Scaler(N) (U32_ScalerN + (4*(N)))
201 # define ScalerPhasOffs_offset 0x20
202 #define U32_ScalerPulsTrig(N) (U32_ScalerN + 0x40 + (4*(N)))
203 
204 #define U32_DBusTrigN 0x180
205 #define U32_DBusPulsTrig(N) (U32_DBusTrigN + (4*(N)))
206 
207 #define U32_PulserNCtrl 0x200
208 #define U32_PulserNScal 0x204
209 #define U32_PulserNDely 0x208
210 #define U32_PulserNWdth 0x20c
211 # define PulserMax 24
212 
213 /* 0 <= N <= 15 */
214 #define U32_PulserCtrl(N) (U32_PulserNCtrl + (16*(N)))
215 # define PulserCtrl_masks 0xf0000000
216 # define PulserCtrl_masks_shift 28
217 # define PulserCtrl_enables 0x00f00000
218 # define PulserCtrl_enables_shift 20
219 # define PulserCtrl_ena 0x01
220 # define PulserCtrl_mtrg 0x02
221 # define PulserCtrl_mset 0x04
222 # define PulserCtrl_mrst 0x08
223 # define PulserCtrl_pol 0x10
224 # define PulserCtrl_srst 0x20
225 # define PulserCtrl_sset 0x40
226 # define PulserCtrl_rbv 0x80
227 
228 #define U32_PulserScal(N) (U32_PulserNScal + (16*(N)))
229 #define U32_PulserDely(N) (U32_PulserNDely + (16*(N)))
230 #define U32_PulserWdth(N) (U32_PulserNWdth + (16*(N)))
231 
232 /* 2x 16-bit registers are treated as one to take advantage
233  * of VME/PCI invariance. Unfortunatly this only works for
234  * 32-bit operations...
235  *
236  * Even numbered outputs are the high word,
237  * odd outputs are the low word
238  */
239 
240 #define Output_mask(N) ( ((N)&1) ? 0x0000ffff : 0xffff0000 )
241 #define Output_shift(N) ( ((N)&1) ? 0 : 16)
242 
243 /* Front panel outputs */
244 #define U32_OutputMapFPN 0x400
245 # define OutputMapFPMax 8
246 
247 /* 0 <= N <= 7 */
248 #define U32_OutputMapFP(N) (U32_OutputMapFPN + (2*( (N) & (~0x1) )))
249 
250 /* Front panel universal outputs */
251 #define U32_OutputMapFPUnivN 0x440
252 # define OutputMapFPUnivMax 10
253 
254 /* 0 <= N <= 9 */
255 #define U32_OutputMapFPUniv(N) (U32_OutputMapFPUnivN + (2*( (N) & (~0x1) )))
256 
257 /* Transition board outputs */
258 #define U32_OutputMapRBN 0x480
259 # define OutputMapRBMax 32
260 
261 /* 0 <= N <= 31 */
262 #define U32_OutputMapRB(N) (U32_OutputMapRBN + (2*( (N) & (~0x1) )))
263 
264 /* Backplane line outputs */
265 #define U32_OutputMapBackplaneN 0x4C0
266 # define OutputMapBackplaneMax 8
267 
268 /* 0 <= N <= 7 */
269 #define U32_OutputMapBackplane(N) (U32_OutputMapBackplaneN + (2*( (N) & (~0x1) )))
270 
271 /* Front panel inputs */
272 #define U32_InputMapFPN 0x500
273 # define InputMapFP_state 0x80000000
274 # define InputMapFP_lvl 0x20000000
275 # define InputMapFP_blvl 0x10000000
276 # define InputMapFP_elvl 0x08000000
277 # define InputMapFP_edge 0x04000000
278 # define InputMapFP_bedg 0x02000000
279 # define InputMapFP_eedg 0x01000000
280 # define InputMapFP_dbus_mask 0x00ff0000
281 # define InputMapFP_dbus_shft 16
282 # define InputMapFP_back_mask 0x0000ff00
283 # define InputMapFP_back_shft 8
284 # define InputMapFP_ext_mask 0x000000ff
285 # define InputMapFP_ext_shft 0
286 # define InputMapFPMax 32
287 
294 #define U32_InputMapFP(N) (U32_InputMapFPN + (4*(N)))
295 
296 /* GTX delay */
297 #define U32_GTXDelayN 0x580
298 #define U32_GTXDelay(N) (U32_GTXDelayN + (4*(N)))
299 
300 /* Current mode logic (CML) and GTX outputs */
301 #define U32_OutputCMLNLow 0x600
302 #define U32_OutputCMLNRise 0x604
303 #define U32_OutputCMLNFall 0x608
304 #define U32_OutputCMLNHigh 0x60c
305 #define U32_OutputCMLNEna 0x610
306 # define OutputCMLEna_ftrig_mask 0xffff0000
307 # define OutputCMLEna_ftrig_shft 16
308 # define OutputCMLEna_type_mask 0x0c00
309 # define OutputCMLEna_type_300 0x0800
310 # define OutputCMLEna_type_203 0x0400
311 # define OutputCMLEna_type_cml 0x0000
312 # define OutputCMLEna_pha_mask 0x0300
313 # define OutputCMLEna_pha_shift 8
314 # define OutputCMLEna_cycl 0x80
315 # define OutputCMLEna_ftrg 0x40
316 # define OutputCMLEna_mode_mask 0x30
317 # define OutputCMLEna_mode_orig 0x00
318 # define OutputCMLEna_mode_freq 0x10
319 # define OutputCMLEna_mode_patt 0x20
320 # define OutputCMLEna_rst 0x04
321 # define OutputCMLEna_pow 0x02
322 # define OutputCMLEna_ena 0x01
323 #define U32_OutputCMLNCount 0x0614
324 # define OutputCMLCount_mask 0xffff
325 # define OutputCMLCount_high_shft 16
326 # define OutputCMLCount_low_shft 0
327 #define U32_OutputCMLNPatLength 0x0618
328 # define OutputCMLPatLengthMax 2047
329 
330 #define U32_OutputCMLNPat_base 0x20000
331 #define U32_OutputCMLPat(i,N) (U32_OutputCMLNPat_base + 0x4000*(i) + 4*(N))
332 
333 # define OutputCMLMax 4
334 # define OutputGTXMax 8
335 
336 /* 0 <= N <= 2 */
337 #define U32_OutputCMLLow(N) (U32_OutputCMLNLow +(0x20*(N)))
338 #define U32_OutputCMLRise(N) (U32_OutputCMLNRise +(0x20*(N)))
339 #define U32_OutputCMLFall(N) (U32_OutputCMLNFall +(0x20*(N)))
340 #define U32_OutputCMLHigh(N) (U32_OutputCMLNHigh +(0x20*(N)))
341 #define U32_OutputCMLEna(N) (U32_OutputCMLNEna +(0x20*(N)))
342 /* The Count is offset by 1. 0 sends 1 word, 1 sends 2 words, ... */
343 #define U32_OutputCMLCount(N) (U32_OutputCMLNCount +(0x20*(N)))
344 #define U32_OutputCMLPatLength(N) (U32_OutputCMLNPatLength +(0x20*(N)))
345 
346 #define U32_DataRx_base 0x0800
347 #define U32_DataTx_base 0x1800
348 #define U32_EventLog_base 0x2000
349 
350 /* 0 <= N <= 0x7ff */
351 #define U32_DataRx(N) (U32_DataRx_base + (N))
352 #define U32_DataTx(N) (U32_DataTx_base + (N))
353 
354 /* 0 <= N <= 0xfff */
355 #define U32_EventLog(N) (U32_EventLog_base + (N))
356 
357 /* 0 <= M <= 1 ram select
358  * 0 <= E <= 255 event code number
359  * 0 <= N <= 15 Byte
360  *
361  * Internal, Trigger, Set, or Reset - Block select
362  */
363 #define U32_MappingRam_base 0x4000
364 
365 #define MappingRamBlockInternal 0x0
366 #define MappingRamBlockTrigger 0x4
367 #define MappingRamBlockSet 0x8
368 #define MappingRamBlockReset 0xc
369 
370 #define U32__MappingRam(M,E,N) (U32_MappingRam_base + (0x1000*(M)) + (0x10*(E)) + (N))
371 #define U32_MappingRam(M,E,N) U32__MappingRam(M,E, MappingRamBlock##N)
372 
373 // MappingRam actions
374 #define ActionFIFOSave 127
375 #define ActionTSLatch 126
376 #define ActionLEDBlink 125
377 #define ActionEvtFwd 124
378 #define ActionLogStop 123
379 #define ActionLogSave 122
380 #define ActionHeartBeat 101
381 #define ActionPSRst 100
382 
383 // Sequence Ram Timestamp Array Base Offset
384 #define U32_SeqRamTS_base 0xc000
385 #define U32_SeqRamTS(n,m) (U32_SeqRamTS_base + (0x4000*(n)) + (8*(m)))
386 
387 #define U32_SFPEEPROM_base 0x8200
388 #define U32_SFPEEPROM(N) (U32_SFPEEPROM_base + (N))
389 #define U32_SFPDIAG_base 0x8300
390 #define U32_SFPDIAG(N) (U32_SFPDIAG_base + (N))
391 
392 #define EVR_REGMAP_SIZE 0x40000 // Total register map size = 256K
393 
394 #endif /* EVRREGMAP_H */