Added firmware support for adc_mux to handle swapping I/Q, etc.
[debian/gnuradio] / usrp2 / firmware / lib / memory_map.h
1 /* -*- c -*- */
2 /*
3  * Copyright 2007,2008 Free Software Foundation, Inc.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 /* Overall Memory Map
20  *   0000-7FFF  32K   RAM space (16K on 1500, 24K on 2000, 32K on DSP)
21  *   8000-BFFF  16K   Buffer Pool
22  *   C000-FFFF  16K   Peripherals
23  */
24
25
26 #ifndef INCLUDED_MEMORY_MAP_H
27 #define INCLUDED_MEMORY_MAP_H
28
29 #include <stdint.h>
30
31
32 #define MASTER_CLK_RATE        100000000                // 100 MHz
33
34
35 ////////////////////////////////////////////////////////////////
36 //
37 //         Memory map for embedded wishbone bus
38 //
39 ////////////////////////////////////////////////////////////////
40
41
42 ////////////////////////////////////////////////////////////////
43 // Main RAM, Slave 0
44
45 #define RAM_BASE 0x0000
46
47 ////////////////////////////////////////////////////////////////
48 // Buffer Pool RAM, Slave 1
49 //
50 // The buffers themselves are located in Slave 1, Buffer Pool RAM.
51 // The status registers are in Slave 5, Buffer Pool Status.
52 // The control register is in Slave 7, Settings Bus.
53
54 #define BUFFER_POOL_RAM_BASE 0x8000
55
56 #define NBUFFERS                8
57 #define BP_NLINES          0x0200       // number of 32-bit lines in a buffer
58 #define BP_LAST_LINE    (BP_NLINES - 1) // last line in a buffer
59
60 #define buffer_pool_ram \
61   ((uint32_t *) BUFFER_POOL_RAM_BASE)
62
63 #define buffer_ram(n) (&buffer_pool_ram[(n) * BP_NLINES])
64
65
66 /////////////////////////////////////////////////////
67 // SPI Core, Slave 2.  See core docs for more info
68 #define SPI_BASE 0xC000   // Base address (16-bit)
69
70 typedef struct {
71   volatile uint32_t     txrx0;
72   volatile uint32_t     txrx1;
73   volatile uint32_t     txrx2;
74   volatile uint32_t     txrx3;
75   volatile uint32_t     ctrl;
76   volatile uint32_t     div;
77   volatile uint32_t     ss;
78 } spi_regs_t;
79
80 #define spi_regs ((spi_regs_t *) SPI_BASE)
81
82
83 // Masks for controlling different peripherals
84 #define SPI_SS_AD9510    1
85 #define SPI_SS_AD9777    2
86 #define SPI_SS_RX_DAC    4
87 #define SPI_SS_RX_ADC    8
88 #define SPI_SS_RX_DB    16
89 #define SPI_SS_TX_DAC   32
90 #define SPI_SS_TX_ADC   64
91 #define SPI_SS_TX_DB   128
92
93 // Masks for different parts of CTRL reg
94 #define SPI_CTRL_ASS      (1<<13)
95 #define SPI_CTRL_IE       (1<<12)
96 #define SPI_CTRL_LSB      (1<<11)
97 #define SPI_CTRL_TXNEG    (1<<10)
98 #define SPI_CTRL_RXNEG    (1<< 9)
99 #define SPI_CTRL_GO_BSY   (1<< 8)
100 #define SPI_CTRL_CHAR_LEN_MASK 0x7F
101
102 ////////////////////////////////////////////////
103 // I2C, Slave 3
104 // See Wishbone I2C-Master Core Specification.
105
106 #define I2C_BASE 0xC400
107
108 typedef struct {
109   volatile uint32_t  prescaler_lo;      // r/w
110   volatile uint32_t  prescaler_hi;      // r/w
111   volatile uint32_t  ctrl;              // r/w
112   volatile uint32_t  data;              // wr = transmit reg; rd = receive reg
113   volatile uint32_t  cmd_status;        // wr = command reg;  rd = status reg
114 } i2c_regs_t;
115
116 #define i2c_regs ((i2c_regs_t *) I2C_BASE)
117
118 #define I2C_CTRL_EN     (1 << 7)        // core enable
119 #define I2C_CTRL_IE     (1 << 6)        // interrupt enable
120
121 //
122 // STA, STO, RD, WR, and IACK bits are cleared automatically
123 //
124 #define I2C_CMD_START   (1 << 7)        // generate (repeated) start condition
125 #define I2C_CMD_STOP    (1 << 6)        // generate stop condition
126 #define I2C_CMD_RD      (1 << 5)        // read from slave
127 #define I2C_CMD_WR      (1 << 4)        // write to slave
128 #define I2C_CMD_NACK    (1 << 3)        // when a rcvr, send ACK (ACK=0) or NACK (ACK=1)
129 #define I2C_CMD_RSVD_2  (1 << 2)        // reserved
130 #define I2C_CMD_RSVD_1  (1 << 1)        // reserved
131 #define I2C_CMD_IACK    (1 << 0)        // set to clear pending interrupt
132
133 #define I2C_ST_RXACK    (1 << 7)        // Received acknowledgement from slave (1 = NAK, 0 = ACK)
134 #define I2C_ST_BUSY     (1 << 6)        // 1 after START signal detected; 0 after STOP signal detected
135 #define I2C_ST_AL       (1 << 5)        // Arbitration lost.  1 when core lost arbitration
136 #define I2C_ST_RSVD_4   (1 << 4)        // reserved
137 #define I2C_ST_RSVD_3   (1 << 3)        // reserved
138 #define I2C_ST_RSVD_2   (1 << 2)        // reserved
139 #define I2C_ST_TIP      (1 << 1)        // Transfer-in-progress
140 #define I2C_ST_IP       (1 << 0)        // Interrupt pending
141
142
143 ////////////////////////////////////////////////
144 // GPIO, Slave 4
145 //
146 // These go to the daughterboard i/o pins
147
148 #define GPIO_BASE 0xC800
149
150 typedef struct {
151   volatile uint32_t     io;       // tx data in high 16, rx in low 16
152   volatile uint32_t     ddr;      // 32 bits, 1 means output. tx in high 16, rx in low 16
153   volatile uint32_t     tx_sel;   // 16 2-bit fields select which source goes to TX DB
154   volatile uint32_t     rx_sel;   // 16 2-bit fields select which source goes to RX DB
155 } gpio_regs_t;
156
157 // each 2-bit sel field is layed out this way
158 #define GPIO_SEL_SW        0 // if pin is an output, set by software in the io reg
159 #define GPIO_SEL_ATR       1 // if pin is an output, set by ATR logic
160 #define GPIO_SEL_DEBUG_0   2 // if pin is an output, debug lines from FPGA fabric
161 #define GPIO_SEL_DEBUG_1   3 // if pin is an output, debug lines from FPGA fabric
162
163 #define gpio_base ((gpio_regs_t *) GPIO_BASE)
164
165 ///////////////////////////////////////////////////
166 // Buffer Pool Status, Slave 5
167 //
168 // The buffers themselves are located in Slave 1, Buffer Pool RAM.
169 // The status registers are in Slave 5, Buffer Pool Status.
170 // The control register is in Slave 7, Settings Bus.
171
172 #define BUFFER_POOL_STATUS_BASE 0xCC00
173
174 typedef struct {
175   volatile uint32_t last_line[NBUFFERS]; // last line xfer'd in buffer
176   volatile uint32_t status;              // error and done flags
177   volatile uint32_t hw_config;           // see below
178 } buffer_pool_status_t;
179
180 #define buffer_pool_status ((buffer_pool_status_t *) BUFFER_POOL_STATUS_BASE)
181
182 /*
183  * Buffer n's xfer is done.
184  * Clear this bit by issuing bp_clear_buf(n)
185  */
186 #define BPS_DONE(n)     (0x00000001 << (n))
187 #define BPS_DONE_0      BPS_DONE(0)
188 #define BPS_DONE_1      BPS_DONE(1)
189 #define BPS_DONE_2      BPS_DONE(2)
190 #define BPS_DONE_3      BPS_DONE(3)
191 #define BPS_DONE_4      BPS_DONE(4)
192 #define BPS_DONE_5      BPS_DONE(5)
193 #define BPS_DONE_6      BPS_DONE(6)
194 #define BPS_DONE_7      BPS_DONE(7)
195
196 /*
197  * Buffer n's xfer had an error.
198  * Clear this bit by issuing bp_clear_buf(n)
199  */
200 #define BPS_ERROR(n)    (0x00000100 << (n))
201 #define BPS_ERROR_0     BPS_ERROR(0)
202 #define BPS_ERROR_1     BPS_ERROR(1)
203 #define BPS_ERROR_2     BPS_ERROR(2)
204 #define BPS_ERROR_3     BPS_ERROR(3)
205 #define BPS_ERROR_4     BPS_ERROR(4)
206 #define BPS_ERROR_5     BPS_ERROR(5)
207 #define BPS_ERROR_6     BPS_ERROR(6)
208 #define BPS_ERROR_7     BPS_ERROR(7)
209
210 /*
211  * Buffer n is idle.  A buffer is idle if it's not
212  * DONE, ERROR, or processing a transaction.  If it's
213  * IDLE, it's safe to start a new transaction.
214  *
215  * Clear this bit by starting a xfer with
216  * bp_send_from_buf or bp_receive_to_buf.
217  */
218 #define BPS_IDLE(n)     (0x00010000 << (n))
219 #define BPS_IDLE_0      BPS_IDLE(0)
220 #define BPS_IDLE_1      BPS_IDLE(1)
221 #define BPS_IDLE_2      BPS_IDLE(2)
222 #define BPS_IDLE_3      BPS_IDLE(3)
223 #define BPS_IDLE_4      BPS_IDLE(4)
224 #define BPS_IDLE_5      BPS_IDLE(5)
225 #define BPS_IDLE_6      BPS_IDLE(6)
226 #define BPS_IDLE_7      BPS_IDLE(7)
227
228 /*
229  * Buffer n has a "slow path" packet in it.
230  * This bit is orthogonal to the bits above and indicates that
231  * the FPGA ethernet rx protocol engine has identified this packet
232  * as one requiring firmware intervention.
233  */
234 #define BPS_SLOWPATH(n) (0x01000000 << (n))
235 #define BPS_SLOWPATH_0  BPS_SLOWPATH(0)
236 #define BPS_SLOWPATH_1  BPS_SLOWPATH(1)
237 #define BPS_SLOWPATH_2  BPS_SLOWPATH(2)
238 #define BPS_SLOWPATH_3  BPS_SLOWPATH(3)
239 #define BPS_SLOWPATH_4  BPS_SLOWPATH(4)
240 #define BPS_SLOWPATH_5  BPS_SLOWPATH(5)
241 #define BPS_SLOWPATH_6  BPS_SLOWPATH(6)
242 #define BPS_SLOWPATH_7  BPS_SLOWPATH(7)
243
244
245 #define BPS_DONE_ALL      0x000000ff    // mask of all dones
246 #define BPS_ERROR_ALL     0x0000ff00    // mask of all errors
247 #define BPS_IDLE_ALL      0x00ff0000    // mask of all idles
248 #define BPS_SLOWPATH_ALL  0xff000000    // mask of all slowpaths
249
250 // The hw_config register
251
252 #define HWC_SIMULATION          0x80000000
253 #define HWC_WB_CLK_DIV_MASK     0x0000000f
254
255 /*!
256  * \brief return non-zero if we're running under the simulator
257  */
258 inline static int
259 hwconfig_simulation_p(void)
260 {
261   return buffer_pool_status->hw_config & HWC_SIMULATION;
262 }
263
264 /*!
265  * \brief Return Wishbone Clock divisor.
266  * The processor runs at the Wishbone Clock rate which is MASTER_CLK_RATE / divisor.
267  */
268 inline static int
269 hwconfig_wishbone_divisor(void)
270 {
271   return buffer_pool_status->hw_config & HWC_WB_CLK_DIV_MASK;
272 }
273
274 ///////////////////////////////////////////////////
275 // Ethernet Core, Slave 6
276
277 #define ETH_BASE 0xD000
278
279 #include "eth_mac_regs.h"
280
281 #define eth_mac ((eth_mac_regs_t *) ETH_BASE)
282
283 ////////////////////////////////////////////////////
284 // Settings Bus, Slave #7, Not Byte Addressable!
285 //
286 // Output-only from processor point-of-view.
287 // 1KB of address space (== 256 32-bit write-only regs)
288
289
290 #define MISC_OUTPUT_BASE        0xD400
291 #define TX_PROTOCOL_ENGINE_BASE 0xD480
292 #define RX_PROTOCOL_ENGINE_BASE 0xD4C0
293 #define BUFFER_POOL_CTRL_BASE   0xD500
294 #define DSP_TX_BASE             0xD600
295 #define DSP_RX_BASE             0xD680
296
297 #define LAST_SETTING_REG        0xD7FC  // last valid setting register
298
299 // --- buffer pool control regs ---
300
301 typedef struct {
302   volatile uint32_t ctrl;
303 } buffer_pool_ctrl_t;
304
305 // buffer pool ports
306
307 #define PORT_SERDES     0       // serial/deserializer
308 #define PORT_DSP        1       // DSP tx or rx pipeline
309 #define PORT_ETH        2       // ethernet tx or rx
310 #define PORT_RAM        3       // RAM tx or rx
311
312 // the buffer pool ctrl register fields
313
314 #define BPC_BUFFER(n) (((n) & 0xf) << 28)
315 #define   BPC_BUFFER_MASK      BPC_BUFFER(~0)
316 #define   BPC_BUFFER_0         BPC_BUFFER(0)
317 #define   BPC_BUFFER_1         BPC_BUFFER(1)
318 #define   BPC_BUFFER_2         BPC_BUFFER(2)
319 #define   BPC_BUFFER_3         BPC_BUFFER(3)
320 #define   BPC_BUFFER_4         BPC_BUFFER(4)
321 #define   BPC_BUFFER_5         BPC_BUFFER(5)
322 #define   BPC_BUFFER_6         BPC_BUFFER(6)
323 #define   BPC_BUFFER_7         BPC_BUFFER(7)
324 #define   BPC_BUFFER_NIL       BPC_BUFFER(0x8)  // disable
325
326 #define BPC_PORT(n) (((n) & 0x7) << 25)
327 #define   BPC_PORT_MASK        BPC_PORT(~0)
328 #define   BPC_PORT_SERDES      BPC_PORT(PORT_SERDES)
329 #define   BPC_PORT_DSP         BPC_PORT(PORT_DSP)
330 #define   BPC_PORT_ETH         BPC_PORT(PORT_ETH)
331 #define   BPC_PORT_RAM         BPC_PORT(PORT_RAM)
332 #define   BPC_PORT_NIL         BPC_PORT(0x4)    // disable
333
334 #define BPC_CLR                (1 << 24)  // mutually excl commands
335 #define BPC_READ               (1 << 23)
336 #define BPC_WRITE              (1 << 22)
337
338 #define BPC_STEP(step) (((step) & 0xf) << 18)
339 #define   BPC_STEP_MASK        BPC_STEP(~0)
340 #define BPC_LAST_LINE(line) (((line) & 0x1ff) << 9)
341 #define   BPC_LAST_LINE_MASK   BPC_LAST_LINE(~0)
342 #define BPC_FIRST_LINE(line) (((line) & 0x1ff) << 0)
343 #define   BPC_FIRST_LINE_MASK  BPC_FIRST_LINE(~0)
344
345 #define buffer_pool_ctrl ((buffer_pool_ctrl_t *) BUFFER_POOL_CTRL_BASE)
346
347 // --- misc outputs ---
348
349 typedef struct {
350   volatile uint32_t     clk_ctrl;
351   volatile uint32_t     serdes_ctrl;
352   volatile uint32_t     adc_ctrl;
353   volatile uint32_t     leds;
354   volatile uint32_t     phy_ctrl;       // LSB is reset line to eth phy
355   volatile uint32_t     debug_mux_ctrl;
356   volatile uint32_t     ram_page;       // FIXME should go somewhere else...
357   volatile uint32_t     flush_icache;   // Flush the icache
358 } output_regs_t;
359
360 #define SERDES_ENABLE 8
361 #define SERDES_PRBSEN 4
362 #define SERDES_LOOPEN 2
363 #define SERDES_RXEN   1
364
365 #define ADC_CTRL_ON     0x0F
366 #define ADC_CTRL_OFF    0x00
367
368 #define output_regs ((output_regs_t *) MISC_OUTPUT_BASE)
369
370 // --- dsp tx regs ---
371
372 #define MIN_INTERP      1
373 #define MAX_INTERP    128
374
375 typedef struct {
376   volatile int32_t      freq;
377   volatile uint32_t     scale_iq;       // {scale_i,scale_q}
378   volatile uint32_t     interp_rate;
379   volatile uint32_t     clear_state;    // clears out state machine, fifos,
380                                         //   NOT freq, scale, interp
381   /*!
382    * \brief output mux configuration.
383    *
384    * <pre>
385    *     3                   2                   1                       
386    *   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
387    *  +-------------------------------+-------+-------+-------+-------+
388    *  |                                               | DAC1  |  DAC0 |
389    *  +-------------------------------+-------+-------+-------+-------+
390    * 
391    *  There are N DUCs (1 now) with complex inputs and outputs.
392    *  There are two DACs.
393    * 
394    *  Each 4-bit DACx field specifies the source for the DAC
395    *  Each subfield is coded like this: 
396    * 
397    *     3 2 1 0
398    *    +-------+
399    *    |   N   |
400    *    +-------+
401    * 
402    *  N specifies which DUC output is connected to this DAC.
403    * 
404    *   N   which interp output
405    *  ---  -------------------
406    *   0   DUC 0 I
407    *   1   DUC 0 Q
408    *   2   DUC 1 I
409    *   3   DUC 1 Q
410    *
411    * The default value is 0x10
412    * </pre>
413    */
414   //volatile uint32_t   tx_mux;         // FIXME this register is currently unimplemented
415
416 } dsp_tx_regs_t;
417   
418 #define dsp_tx_regs ((dsp_tx_regs_t *) DSP_TX_BASE)
419
420 // --- dsp rx regs ---
421
422 #define T_NOW (-1)
423
424 #define MIN_DECIM       1
425 #define MAX_DECIM     128
426
427 typedef struct {
428   volatile int32_t      freq;
429   volatile uint32_t     scale_iq;       // {scale_i,scale_q}
430   volatile uint32_t     decim_rate;
431   volatile uint32_t     rx_time;        // when to begin reception
432   volatile uint32_t     rx_command;     // {now, chain, num_lines(21), lines_per_frame(9)
433   volatile uint32_t     clear_state;    // clears out state machine, fifos,
434                                         //   cmd queue, NOT freq, scale, decim
435   volatile uint32_t     dcoffset_i;     // Bit 31 high sets fixed offset mode, using lower 14 bits,
436                                         // otherwise it is automatic 
437   volatile uint32_t     dcoffset_q;     // Bit 31 high sets fixed offset mode, using lower 14 bits
438
439   /*!
440    * \brief input mux configuration.
441    *
442    * This determines which ADC (or constant zero) is connected to 
443    * each DDC input.  There are N DDCs (1 now).  Each has two inputs.
444    *
445    * <pre>
446    * Mux value:
447    *
448    *    3                   2                   1                       
449    *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
450    * +-------+-------+-------+-------+-------+-------+-------+-------+
451    * |                                                       |Q0 |I0 |
452    * +-------+-------+-------+-------+-------+-------+-------+-------+
453    *
454    * Each 2-bit I field is either 00 (A/D A), 01 (A/D B) or 1X (const zero)
455    * Each 2-bit Q field is either 00 (A/D A), 01 (A/D B) or 1X (const zero)
456    *
457    * The default value is 0x4
458    * </pre>
459    */
460   volatile uint32_t     rx_mux;        // called adc_mux in dsp_core_rx.v
461
462 } dsp_rx_regs_t;
463   
464 #define dsp_rx_regs ((dsp_rx_regs_t *) DSP_RX_BASE)
465
466 #define MK_RX_CMD(num_lines, lines_per_frame, now, chain) \
467   (((num_lines) << 9) | ((lines_per_frame) & 0x1ff) \
468    | (((now) & 0x1) << 31) | (((chain) & 0x1) << 30))
469
470 /* 
471  * --- ethernet tx protocol engine regs (write only) ---
472  *
473  * These registers control the transmit portion of the ethernet
474  * protocol engine (out of USRP2).  The protocol engine handles fifo
475  * status and sequence number insertion in outgoing packets, and
476  * automagically generates status packets when required to inform the
477  * host of changes in fifo availability.
478  *
479  * All outgoing packets have their fifo_status field set to the number
480  * of 32-bit lines of fifo available in the ethernet Rx fifo (see
481  * usrp2_eth_packet.h).  Seqno's are set if FIXME, else 0.
482  *
483  * FIXME clean this up once we know how it's supposed to behave.
484  */
485
486 typedef struct {
487   volatile uint32_t  flags;          // not yet fully defined (channel?)
488   volatile uint32_t  mac_dst0123;    // 4 bytes of destination mac addr
489   volatile uint32_t  mac_dst45src01; // 2 bytes of dest mac addr; 2 bytes of src mac addr
490   volatile uint32_t  mac_src2345;    // 4 bytes of destination mac addr
491   volatile uint32_t  seqno;          // Write to init seqno.  It autoincs on match
492 } tx_proto_engine_regs_t;
493
494 #define tx_proto_engine ((tx_proto_engine_regs_t *) TX_PROTOCOL_ENGINE_BASE)
495
496 /*
497  * --- ethernet rx protocol engine regs (write only) ---
498  *
499  * These registers control the receive portion of the ethernet
500  * protocol engine (into USRP2).  The protocol engine offloads common
501  * packet inspection operations so that firmware has less to do on
502  * "fast path" packets.
503  *
504  * The registers define conditions which must be matched for a packet
505  * to be considered a "fast path" packet.  If a received packet
506  * matches the src and dst mac address, ethertype, flags field, and
507  * expected seqno number it is considered a "fast path" packet, and
508  * the expected seqno is updated.  If the packet fails to satisfy any
509  * of the above conditions it's a "slow path" packet, and the
510  * corresponding SLOWPATH flag will be set buffer_status register.
511  */
512
513 typedef struct {
514   volatile uint32_t  flags;          // not yet fully defined (channel?)
515   volatile uint32_t  mac_dst0123;    // 4 bytes of destination mac addr
516   volatile uint32_t  mac_dst45src01; // 2 bytes of dest mac addr; 2 bytes of src mac addr
517   volatile uint32_t  mac_src2345;    // 4 bytes of destination mac addr
518   volatile uint32_t  ethertype_pad;  // ethertype in high 16-bits
519 } rx_proto_engine_regs_t;
520
521 #define rx_proto_engine ((rx_proto_engine_regs_t *) RX_PROTOCOL_ENGINE_BASE)
522
523
524
525 ///////////////////////////////////////////////////
526 // Simple Programmable Interrupt Controller, Slave 8
527
528 #define PIC_BASE  0xD800
529
530 // Interrupt request lines
531 // Bit numbers (LSB == 0) that correpond to interrupts into PIC
532
533 #define IRQ_BUFFER      0       // buffer manager
534 #define IRQ_TIMER       1
535 #define IRQ_SPI         2
536 #define IRQ_I2C         3
537 #define IRQ_PHY         4       // ethernet PHY
538 #define IRQ_UNDERRUN    5
539 #define IRQ_OVERRUN     6
540 #define IRQ_PPS         7       // pulse per second
541 #define IRQ_UART_RX     8
542 #define IRQ_UART_TX     9
543 #define IRQ_SERDES      10
544 #define IRQ_CLKSTATUS   11
545
546 #define IRQ_TO_MASK(x) (1 << (x))
547
548 #define PIC_BUFFER_INT    IRQ_TO_MASK(IRQ_BUFFER)
549 #define PIC_TIMER_INT     IRQ_TO_MASK(IRQ_TIMER)
550 #define PIC_SPI_INT       IRQ_TO_MASK(IRQ_SPI)
551 #define PIC_I2C_INT       IRQ_TO_MASK(IRQ_I2C)
552 #define PIC_PHY_INT       IRQ_TO_MASK(IRQ_PHY)
553 #define PIC_UNDERRUN_INT  IRQ_TO_MASK(IRQ_UNDERRUN)
554 #define PIC_OVERRUN_INT   IRQ_TO_MASK(IRQ_OVERRUN)
555 #define PIC_PPS_INT       IRQ_TO_MASK(IRQ_PPS)
556 #define PIC_UART_RX_INT   IRQ_TO_MASK(IRQ_UART_RX)
557 #define PIC_UART_TX_INT   IRQ_TO_MASK(IRQ_UART_TX)
558 #define PIC_SERDES        IRQ_TO_MASK(IRQ_SERDES)
559 #define PIC_CLKSTATUS     IRQ_TO_MASK(IRQ_CLKSTATUS)
560
561 typedef struct {
562   volatile uint32_t edge_enable; // mask: 1 -> edge triggered, 0 -> level
563   volatile uint32_t polarity;    // mask: 1 -> rising edge
564   volatile uint32_t mask;        // mask: 1 -> disabled
565   volatile uint32_t pending;     // mask: 1 -> pending; write 1's to clear pending ints
566 } pic_regs_t;
567
568 #define pic_regs ((pic_regs_t *) PIC_BASE)
569
570 ///////////////////////////////////////////////////
571 // Timer, Slave 9
572
573 #define TIMER_BASE  0xDC00
574
575 typedef struct {
576   volatile uint32_t time;       // R: current, W: set time to interrupt
577 } timer_regs_t;
578
579 #define timer_regs ((timer_regs_t *) TIMER_BASE)
580
581 ///////////////////////////////////////////////////
582 // UART, Slave 10
583
584 #define UART_BASE  0xE000
585
586 typedef struct {
587   //  All elements are 8 bits except for clkdiv (16), but we use uint32 to make 
588   //    the hardware for decoding easier
589   volatile uint32_t clkdiv;  // Set to 50e6 divided by baud rate (no x16 factor)
590   volatile uint32_t txlevel; // Number of spaces in the FIFO for writes
591   volatile uint32_t rxlevel; // Number of available elements in the FIFO for reads
592   volatile uint32_t txchar;  // Write characters to be sent here
593   volatile uint32_t rxchar;  // Read received characters here
594 } uart_regs_t;
595
596 #define uart_regs ((uart_regs_t *) UART_BASE)
597
598 ///////////////////////////////////////////////////
599 // ATR Controller, Slave 11
600
601 #define ATR_BASE  0xE400
602
603 typedef struct {
604   volatile uint32_t     v[16];
605 } atr_regs_t;
606
607 #define ATR_IDLE        0x0     // indicies into v
608 #define ATR_TX          0x1
609 #define ATR_RX          0x2
610 #define ATR_FULL        0x3
611
612 #define atr_regs ((atr_regs_t *) ATR_BASE)
613
614 ///////////////////////////////////////////////////
615 // Time Sync Controller, Slave 12
616
617 #define TIMESYNC_BASE  0xE800
618
619 typedef struct {
620   volatile uint32_t tick_control;
621   volatile uint32_t tick_interval;
622   volatile uint32_t delta_time;
623 } timesync_regs_t;
624
625 #define timesync_regs ((timesync_regs_t *) TIMESYNC_BASE)
626
627 ///////////////////////////////////////////////////
628 // SD Card SPI interface, Slave 13
629 //   All regs are 8 bits wide, but are accessed as if they are 32 bits
630
631 #define SDSPI_BASE  0xEC00
632
633 typedef struct {
634   volatile uint32_t status;  // Write a 1 or 0 for controlling CS
635   volatile uint32_t clkdiv;
636   volatile uint32_t send_dat;
637   volatile uint32_t receive_dat;
638 } sdspi_regs_t;
639
640 #define sdspi_regs ((sdspi_regs_t *) SDSPI_BASE)
641
642 ///////////////////////////////////////////////////
643 // External RAM interface, Slave 14
644 //   Pages are 1K.  Page is 10 bits, set by a control register
645 //    output_regs->ram_page
646
647 #define EXTRAM_BASE 0xF000
648 #define extram ((volatile uint32_t *) EXTRAM_BASE)
649
650
651 ///////////////////////////////////////////////////
652
653 #endif
654