add new readback entries to memory map. Has irqs, priority encoded buffer status...
[debian/gnuradio] / usrp2 / firmware / lib / memory_map.h
1 /* -*- c -*- */
2 /*
3  * Copyright 2007,2008,2009 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   volatile uint32_t dummy[3];
179   volatile uint32_t irqs;
180   volatile uint32_t pri_enc_bp_status;
181   volatile uint32_t cycle_count;
182 } buffer_pool_status_t;
183
184 #define buffer_pool_status ((buffer_pool_status_t *) BUFFER_POOL_STATUS_BASE)
185
186 /*
187  * Buffer n's xfer is done.
188  * Clear this bit by issuing bp_clear_buf(n)
189  */
190 #define BPS_DONE(n)     (0x00000001 << (n))
191 #define BPS_DONE_0      BPS_DONE(0)
192 #define BPS_DONE_1      BPS_DONE(1)
193 #define BPS_DONE_2      BPS_DONE(2)
194 #define BPS_DONE_3      BPS_DONE(3)
195 #define BPS_DONE_4      BPS_DONE(4)
196 #define BPS_DONE_5      BPS_DONE(5)
197 #define BPS_DONE_6      BPS_DONE(6)
198 #define BPS_DONE_7      BPS_DONE(7)
199
200 /*
201  * Buffer n's xfer had an error.
202  * Clear this bit by issuing bp_clear_buf(n)
203  */
204 #define BPS_ERROR(n)    (0x00000100 << (n))
205 #define BPS_ERROR_0     BPS_ERROR(0)
206 #define BPS_ERROR_1     BPS_ERROR(1)
207 #define BPS_ERROR_2     BPS_ERROR(2)
208 #define BPS_ERROR_3     BPS_ERROR(3)
209 #define BPS_ERROR_4     BPS_ERROR(4)
210 #define BPS_ERROR_5     BPS_ERROR(5)
211 #define BPS_ERROR_6     BPS_ERROR(6)
212 #define BPS_ERROR_7     BPS_ERROR(7)
213
214 /*
215  * Buffer n is idle.  A buffer is idle if it's not
216  * DONE, ERROR, or processing a transaction.  If it's
217  * IDLE, it's safe to start a new transaction.
218  *
219  * Clear this bit by starting a xfer with
220  * bp_send_from_buf or bp_receive_to_buf.
221  */
222 #define BPS_IDLE(n)     (0x00010000 << (n))
223 #define BPS_IDLE_0      BPS_IDLE(0)
224 #define BPS_IDLE_1      BPS_IDLE(1)
225 #define BPS_IDLE_2      BPS_IDLE(2)
226 #define BPS_IDLE_3      BPS_IDLE(3)
227 #define BPS_IDLE_4      BPS_IDLE(4)
228 #define BPS_IDLE_5      BPS_IDLE(5)
229 #define BPS_IDLE_6      BPS_IDLE(6)
230 #define BPS_IDLE_7      BPS_IDLE(7)
231
232 /*
233  * Buffer n has a "slow path" packet in it.
234  * This bit is orthogonal to the bits above and indicates that
235  * the FPGA ethernet rx protocol engine has identified this packet
236  * as one requiring firmware intervention.
237  */
238 #define BPS_SLOWPATH(n) (0x01000000 << (n))
239 #define BPS_SLOWPATH_0  BPS_SLOWPATH(0)
240 #define BPS_SLOWPATH_1  BPS_SLOWPATH(1)
241 #define BPS_SLOWPATH_2  BPS_SLOWPATH(2)
242 #define BPS_SLOWPATH_3  BPS_SLOWPATH(3)
243 #define BPS_SLOWPATH_4  BPS_SLOWPATH(4)
244 #define BPS_SLOWPATH_5  BPS_SLOWPATH(5)
245 #define BPS_SLOWPATH_6  BPS_SLOWPATH(6)
246 #define BPS_SLOWPATH_7  BPS_SLOWPATH(7)
247
248
249 #define BPS_DONE_ALL      0x000000ff    // mask of all dones
250 #define BPS_ERROR_ALL     0x0000ff00    // mask of all errors
251 #define BPS_IDLE_ALL      0x00ff0000    // mask of all idles
252 #define BPS_SLOWPATH_ALL  0xff000000    // mask of all slowpaths
253
254 // The hw_config register
255
256 #define HWC_SIMULATION          0x80000000
257 #define HWC_WB_CLK_DIV_MASK     0x0000000f
258
259 /*!
260  * \brief return non-zero if we're running under the simulator
261  */
262 inline static int
263 hwconfig_simulation_p(void)
264 {
265   return buffer_pool_status->hw_config & HWC_SIMULATION;
266 }
267
268 /*!
269  * \brief Return Wishbone Clock divisor.
270  * The processor runs at the Wishbone Clock rate which is MASTER_CLK_RATE / divisor.
271  */
272 inline static int
273 hwconfig_wishbone_divisor(void)
274 {
275   return buffer_pool_status->hw_config & HWC_WB_CLK_DIV_MASK;
276 }
277
278 ///////////////////////////////////////////////////
279 // Ethernet Core, Slave 6
280
281 #define ETH_BASE 0xD000
282
283 #include "eth_mac_regs.h"
284
285 #define eth_mac ((eth_mac_regs_t *) ETH_BASE)
286
287 ////////////////////////////////////////////////////
288 // Settings Bus, Slave #7, Not Byte Addressable!
289 //
290 // Output-only from processor point-of-view.
291 // 1KB of address space (== 256 32-bit write-only regs)
292
293
294 #define MISC_OUTPUT_BASE        0xD400
295 #define TX_PROTOCOL_ENGINE_BASE 0xD480
296 #define RX_PROTOCOL_ENGINE_BASE 0xD4C0
297 #define BUFFER_POOL_CTRL_BASE   0xD500
298 #define DSP_TX_BASE             0xD600
299 #define DSP_RX_BASE             0xD680
300
301 #define LAST_SETTING_REG        0xD7FC  // last valid setting register
302
303 // --- buffer pool control regs ---
304
305 typedef struct {
306   volatile uint32_t ctrl;
307 } buffer_pool_ctrl_t;
308
309 // buffer pool ports
310
311 #define PORT_SERDES     0       // serial/deserializer
312 #define PORT_DSP        1       // DSP tx or rx pipeline
313 #define PORT_ETH        2       // ethernet tx or rx
314 #define PORT_RAM        3       // RAM tx or rx
315
316 // the buffer pool ctrl register fields
317
318 #define BPC_BUFFER(n) (((n) & 0xf) << 28)
319 #define   BPC_BUFFER_MASK      BPC_BUFFER(~0)
320 #define   BPC_BUFFER_0         BPC_BUFFER(0)
321 #define   BPC_BUFFER_1         BPC_BUFFER(1)
322 #define   BPC_BUFFER_2         BPC_BUFFER(2)
323 #define   BPC_BUFFER_3         BPC_BUFFER(3)
324 #define   BPC_BUFFER_4         BPC_BUFFER(4)
325 #define   BPC_BUFFER_5         BPC_BUFFER(5)
326 #define   BPC_BUFFER_6         BPC_BUFFER(6)
327 #define   BPC_BUFFER_7         BPC_BUFFER(7)
328 #define   BPC_BUFFER_NIL       BPC_BUFFER(0x8)  // disable
329
330 #define BPC_PORT(n) (((n) & 0x7) << 25)
331 #define   BPC_PORT_MASK        BPC_PORT(~0)
332 #define   BPC_PORT_SERDES      BPC_PORT(PORT_SERDES)
333 #define   BPC_PORT_DSP         BPC_PORT(PORT_DSP)
334 #define   BPC_PORT_ETH         BPC_PORT(PORT_ETH)
335 #define   BPC_PORT_RAM         BPC_PORT(PORT_RAM)
336 #define   BPC_PORT_NIL         BPC_PORT(0x4)    // disable
337
338 #define BPC_CLR                (1 << 24)  // mutually excl commands
339 #define BPC_READ               (1 << 23)
340 #define BPC_WRITE              (1 << 22)
341
342 #define BPC_STEP(step) (((step) & 0xf) << 18)
343 #define   BPC_STEP_MASK        BPC_STEP(~0)
344 #define BPC_LAST_LINE(line) (((line) & 0x1ff) << 9)
345 #define   BPC_LAST_LINE_MASK   BPC_LAST_LINE(~0)
346 #define BPC_FIRST_LINE(line) (((line) & 0x1ff) << 0)
347 #define   BPC_FIRST_LINE_MASK  BPC_FIRST_LINE(~0)
348
349 #define buffer_pool_ctrl ((buffer_pool_ctrl_t *) BUFFER_POOL_CTRL_BASE)
350
351 // --- misc outputs ---
352
353 typedef struct {
354   volatile uint32_t     clk_ctrl;
355   volatile uint32_t     serdes_ctrl;
356   volatile uint32_t     adc_ctrl;
357   volatile uint32_t     leds;
358   volatile uint32_t     phy_ctrl;       // LSB is reset line to eth phy
359   volatile uint32_t     debug_mux_ctrl;
360   volatile uint32_t     ram_page;       // FIXME should go somewhere else...
361   volatile uint32_t     flush_icache;   // Flush the icache
362   volatile uint32_t     led_src;        // HW or SW control for LEDs
363 } output_regs_t;
364
365 #define SERDES_ENABLE 8
366 #define SERDES_PRBSEN 4
367 #define SERDES_LOOPEN 2
368 #define SERDES_RXEN   1
369
370 #define ADC_CTRL_ON     0x0F
371 #define ADC_CTRL_OFF    0x00
372
373 // crazy order that matches the labels on the case
374
375 #define LED_A           (1 << 4)
376 #define LED_B           (1 << 1)
377 #define LED_C           (1 << 3)
378 #define LED_D           (1 << 0)
379 #define LED_E           (1 << 2)
380 //      LED_F           // controlled by CPLD
381 #define LED_RJ45        (1 << 5)
382
383 #define output_regs ((output_regs_t *) MISC_OUTPUT_BASE)
384
385 // --- dsp tx regs ---
386
387 #define MIN_CIC_INTERP  1
388 #define MAX_CIC_INTERP  128
389
390 typedef struct {
391   volatile int32_t      freq;
392   volatile uint32_t     scale_iq;       // {scale_i,scale_q}
393   volatile uint32_t     interp_rate;
394   volatile uint32_t     clear_state;    // clears out state machine, fifos,
395                                         //   NOT freq, scale, interp
396   /*!
397    * \brief output mux configuration.
398    *
399    * <pre>
400    *     3                   2                   1                       
401    *   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
402    *  +-------------------------------+-------+-------+-------+-------+
403    *  |                                               | DAC1  |  DAC0 |
404    *  +-------------------------------+-------+-------+-------+-------+
405    * 
406    *  There are N DUCs (1 now) with complex inputs and outputs.
407    *  There are two DACs.
408    * 
409    *  Each 4-bit DACx field specifies the source for the DAC
410    *  Each subfield is coded like this: 
411    * 
412    *     3 2 1 0
413    *    +-------+
414    *    |   N   |
415    *    +-------+
416    * 
417    *  N specifies which DUC output is connected to this DAC.
418    * 
419    *   N   which interp output
420    *  ---  -------------------
421    *   0   DUC 0 I
422    *   1   DUC 0 Q
423    *   2   DUC 1 I
424    *   3   DUC 1 Q
425    *   F   All Zeros
426    *   
427    * The default value is 0x10
428    * </pre>
429    */
430   volatile uint32_t     tx_mux;
431
432 } dsp_tx_regs_t;
433   
434 #define dsp_tx_regs ((dsp_tx_regs_t *) DSP_TX_BASE)
435
436 // --- dsp rx regs ---
437
438 #define T_NOW (-1)
439
440 #define MIN_CIC_DECIM   1
441 #define MAX_CIC_DECIM   128
442
443 typedef struct {
444   volatile int32_t      freq;
445   volatile uint32_t     scale_iq;       // {scale_i,scale_q}
446   volatile uint32_t     decim_rate;
447   volatile uint32_t     rx_time;        // when to begin reception
448   volatile uint32_t     rx_command;     // {now, chain, num_lines(21), lines_per_frame(9)
449   volatile uint32_t     clear_state;    // clears out state machine, fifos,
450                                         //   cmd queue, NOT freq, scale, decim
451   volatile uint32_t     dcoffset_i;     // Bit 31 high sets fixed offset mode, using lower 14 bits,
452                                         // otherwise it is automatic 
453   volatile uint32_t     dcoffset_q;     // Bit 31 high sets fixed offset mode, using lower 14 bits
454
455   /*!
456    * \brief input mux configuration.
457    *
458    * This determines which ADC (or constant zero) is connected to 
459    * each DDC input.  There are N DDCs (1 now).  Each has two inputs.
460    *
461    * <pre>
462    * Mux value:
463    *
464    *    3                   2                   1                       
465    *  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
466    * +-------+-------+-------+-------+-------+-------+-------+-------+
467    * |                                                       |Q0 |I0 |
468    * +-------+-------+-------+-------+-------+-------+-------+-------+
469    *
470    * Each 2-bit I field is either 00 (A/D A), 01 (A/D B) or 1X (const zero)
471    * Each 2-bit Q field is either 00 (A/D A), 01 (A/D B) or 1X (const zero)
472    *
473    * The default value is 0x4
474    * </pre>
475    */
476   volatile uint32_t     rx_mux;        // called adc_mux in dsp_core_rx.v
477
478   /*!
479    * \brief Streaming GPIO configuration
480    *
481    * This determines whether the LSBs of I and Q samples come from the DSP
482    * pipeline or from the io_rx GPIO pins.  To stream GPIO, one must first
483    * set the GPIO data direction register to have io_rx[15] and/or io_rx[14]
484    * configured as inputs.  The GPIO pins will be sampled at the time the
485    * remainder of the DSP sample is strobed into the RX sample FIFO.  There
486    * will be a decimation-dependent fixed time offset between the GPIO
487    * sample stream and the associated RF samples.
488    *
489    *    3                   2                   1                       
490    *  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
491    * +-------+-------+-------+-------+-------+-------+-------+-------+
492    * |                           MBZ                             |Q|I|
493    * +-------+-------+-------+-------+-------+-------+-------+-------+
494    *
495    * I         0=LSB comes from DSP pipeline (default)
496    *           1=LSB comes from io_rx[15]
497    * 
498    * Q         0=LSB comes from DSP pipeline (default)
499    *           1=LSB comes from io_rx[14]
500    */
501   volatile uint32_t gpio_stream_enable;
502
503 } dsp_rx_regs_t;
504   
505 #define dsp_rx_regs ((dsp_rx_regs_t *) DSP_RX_BASE)
506
507 #define MK_RX_CMD(num_lines, lines_per_frame, now, chain) \
508   (((num_lines) << 9) | ((lines_per_frame) & 0x1ff) \
509    | (((now) & 0x1) << 31) | (((chain) & 0x1) << 30))
510
511 /* 
512  * --- ethernet tx protocol engine regs (write only) ---
513  *
514  * These registers control the transmit portion of the ethernet
515  * protocol engine (out of USRP2).  The protocol engine handles fifo
516  * status and sequence number insertion in outgoing packets, and
517  * automagically generates status packets when required to inform the
518  * host of changes in fifo availability.
519  *
520  * All outgoing packets have their fifo_status field set to the number
521  * of 32-bit lines of fifo available in the ethernet Rx fifo (see
522  * usrp2_eth_packet.h).  Seqno's are set if FIXME, else 0.
523  *
524  * FIXME clean this up once we know how it's supposed to behave.
525  */
526
527 typedef struct {
528   volatile uint32_t  flags;          // not yet fully defined (channel?)
529   volatile uint32_t  mac_dst0123;    // 4 bytes of destination mac addr
530   volatile uint32_t  mac_dst45src01; // 2 bytes of dest mac addr; 2 bytes of src mac addr
531   volatile uint32_t  mac_src2345;    // 4 bytes of destination mac addr
532   volatile uint32_t  seqno;          // Write to init seqno.  It autoincs on match
533 } tx_proto_engine_regs_t;
534
535 #define tx_proto_engine ((tx_proto_engine_regs_t *) TX_PROTOCOL_ENGINE_BASE)
536
537 /*
538  * --- ethernet rx protocol engine regs (write only) ---
539  *
540  * These registers control the receive portion of the ethernet
541  * protocol engine (into USRP2).  The protocol engine offloads common
542  * packet inspection operations so that firmware has less to do on
543  * "fast path" packets.
544  *
545  * The registers define conditions which must be matched for a packet
546  * to be considered a "fast path" packet.  If a received packet
547  * matches the src and dst mac address, ethertype, flags field, and
548  * expected seqno number it is considered a "fast path" packet, and
549  * the expected seqno is updated.  If the packet fails to satisfy any
550  * of the above conditions it's a "slow path" packet, and the
551  * corresponding SLOWPATH flag will be set buffer_status register.
552  */
553
554 typedef struct {
555   volatile uint32_t  flags;          // not yet fully defined (channel?)
556   volatile uint32_t  mac_dst0123;    // 4 bytes of destination mac addr
557   volatile uint32_t  mac_dst45src01; // 2 bytes of dest mac addr; 2 bytes of src mac addr
558   volatile uint32_t  mac_src2345;    // 4 bytes of destination mac addr
559   volatile uint32_t  ethertype_pad;  // ethertype in high 16-bits
560 } rx_proto_engine_regs_t;
561
562 #define rx_proto_engine ((rx_proto_engine_regs_t *) RX_PROTOCOL_ENGINE_BASE)
563
564
565
566 ///////////////////////////////////////////////////
567 // Simple Programmable Interrupt Controller, Slave 8
568
569 #define PIC_BASE  0xD800
570
571 // Interrupt request lines
572 // Bit numbers (LSB == 0) that correpond to interrupts into PIC
573
574 #define IRQ_BUFFER      0       // buffer manager
575 #define IRQ_TIMER       1
576 #define IRQ_SPI         2
577 #define IRQ_I2C         3
578 #define IRQ_PHY         4       // ethernet PHY
579 #define IRQ_UNDERRUN    5
580 #define IRQ_OVERRUN     6
581 #define IRQ_PPS         7       // pulse per second
582 #define IRQ_UART_RX     8
583 #define IRQ_UART_TX     9
584 #define IRQ_SERDES      10
585 #define IRQ_CLKSTATUS   11
586
587 #define IRQ_TO_MASK(x) (1 << (x))
588
589 #define PIC_BUFFER_INT    IRQ_TO_MASK(IRQ_BUFFER)
590 #define PIC_TIMER_INT     IRQ_TO_MASK(IRQ_TIMER)
591 #define PIC_SPI_INT       IRQ_TO_MASK(IRQ_SPI)
592 #define PIC_I2C_INT       IRQ_TO_MASK(IRQ_I2C)
593 #define PIC_PHY_INT       IRQ_TO_MASK(IRQ_PHY)
594 #define PIC_UNDERRUN_INT  IRQ_TO_MASK(IRQ_UNDERRUN)
595 #define PIC_OVERRUN_INT   IRQ_TO_MASK(IRQ_OVERRUN)
596 #define PIC_PPS_INT       IRQ_TO_MASK(IRQ_PPS)
597 #define PIC_UART_RX_INT   IRQ_TO_MASK(IRQ_UART_RX)
598 #define PIC_UART_TX_INT   IRQ_TO_MASK(IRQ_UART_TX)
599 #define PIC_SERDES        IRQ_TO_MASK(IRQ_SERDES)
600 #define PIC_CLKSTATUS     IRQ_TO_MASK(IRQ_CLKSTATUS)
601
602 typedef struct {
603   volatile uint32_t edge_enable; // mask: 1 -> edge triggered, 0 -> level
604   volatile uint32_t polarity;    // mask: 1 -> rising edge
605   volatile uint32_t mask;        // mask: 1 -> disabled
606   volatile uint32_t pending;     // mask: 1 -> pending; write 1's to clear pending ints
607 } pic_regs_t;
608
609 #define pic_regs ((pic_regs_t *) PIC_BASE)
610
611 ///////////////////////////////////////////////////
612 // Timer, Slave 9
613
614 #define TIMER_BASE  0xDC00
615
616 typedef struct {
617   volatile uint32_t time;       // R: current, W: set time to interrupt
618 } timer_regs_t;
619
620 #define timer_regs ((timer_regs_t *) TIMER_BASE)
621
622 ///////////////////////////////////////////////////
623 // UART, Slave 10
624
625 #define UART_BASE  0xE000
626
627 typedef struct {
628   //  All elements are 8 bits except for clkdiv (16), but we use uint32 to make 
629   //    the hardware for decoding easier
630   volatile uint32_t clkdiv;  // Set to 50e6 divided by baud rate (no x16 factor)
631   volatile uint32_t txlevel; // Number of spaces in the FIFO for writes
632   volatile uint32_t rxlevel; // Number of available elements in the FIFO for reads
633   volatile uint32_t txchar;  // Write characters to be sent here
634   volatile uint32_t rxchar;  // Read received characters here
635 } uart_regs_t;
636
637 #define uart_regs ((uart_regs_t *) UART_BASE)
638
639 ///////////////////////////////////////////////////
640 // ATR Controller, Slave 11
641
642 #define ATR_BASE  0xE400
643
644 typedef struct {
645   volatile uint32_t     v[16];
646 } atr_regs_t;
647
648 #define ATR_IDLE        0x0     // indicies into v
649 #define ATR_TX          0x1
650 #define ATR_RX          0x2
651 #define ATR_FULL        0x3
652
653 #define atr_regs ((atr_regs_t *) ATR_BASE)
654
655 ///////////////////////////////////////////////////
656 // Time Sync Controller, Slave 12
657 #define TIMESYNC_BASE  0xE800
658
659 typedef struct {
660   /*!
661    * \brief Time sync configuration.
662    *
663    * <pre>
664    *
665    *    3                   2                   1                       
666    *  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
667    * +-----------------------------------------------------+-+-+-+-+-+
668    * |                                                     |T|G|X|I|S|
669    * +-----------------------------------------------------+-+-+-+-+-+
670    *
671    * S - Tick source (0 = free run, 1 = pps, default=0)
672    * I - Tick interrupt enable (not implemented)
673    * X - Use external sync source (default=1)
674    * G - PPS edge selection (0=negedge, 1=posedge, default=0)
675    * T - Trigger sync every pps edge (default=0)
676    *
677    * </pre>
678    */
679   volatile uint32_t tick_control;
680   volatile uint32_t tick_interval;
681   volatile uint32_t delta_time;
682   volatile uint32_t sync_on_next_pps;
683 } timesync_regs_t;
684
685 #define timesync_regs ((timesync_regs_t *) TIMESYNC_BASE)
686
687 #define TSC_SOURCE_PPS        (1 << 0)
688 //#define TSC_SOURCE_FREE_RUN (0 << 0)
689 #define TSC_IENABLE           (1 << 1)
690 #define TSC_EXTSYNC           (1 << 2)
691 #define TSC_PPSEDGE_POS       (1 << 3)
692 //#define TSC_PPSEDGE_NEG     (0 << 3)
693 #define TSC_TRIGGER_EVERYPPS  (1 << 4)
694 //#define TSC_TRIGGER_ONCE    (0 << 4)
695
696 ///////////////////////////////////////////////////
697 // SD Card SPI interface, Slave 13
698 //   All regs are 8 bits wide, but are accessed as if they are 32 bits
699
700 #define SDSPI_BASE  0xEC00
701
702 typedef struct {
703   volatile uint32_t status;  // Write a 1 or 0 for controlling CS
704   volatile uint32_t clkdiv;
705   volatile uint32_t send_dat;
706   volatile uint32_t receive_dat;
707 } sdspi_regs_t;
708
709 #define sdspi_regs ((sdspi_regs_t *) SDSPI_BASE)
710
711 ///////////////////////////////////////////////////
712 // External RAM interface, Slave 14
713 //   Pages are 1K.  Page is 10 bits, set by a control register
714 //    output_regs->ram_page
715
716 #define EXTRAM_BASE 0xF000
717 #define extram ((volatile uint32_t *) EXTRAM_BASE)
718
719
720 ///////////////////////////////////////////////////
721
722 #endif
723