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