2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 use ieee.math_real.all;
10 use work.wishbone_types.all;
13 -- Memory map. *** Keep include/microwatt_soc.h updated on changes ***
16 -- 0x00000000: Block RAM (MEMORY_SIZE) or DRAM depending on syscon
17 -- 0x40000000: DRAM (when present)
18 -- 0x80000000: Block RAM (aliased & repeated)
23 -- 0xc0003000: UART1 (if any)
24 -- 0xc0004000: XICS ICP
25 -- 0xc0005000: XICS ICS
26 -- 0xc0006000: SPI Flash controller
27 -- 0xc0007000: GPIO controller
28 -- 0xc0008000: USB UART (valentyusb)
29 -- 0xc8nnnnnn: External IO bus
30 -- 0xf0000000: Flash "ROM" mapping
31 -- 0xff000000: DRAM init code (if any) or flash ROM (**)
34 -- 0xc8000000: LiteDRAM control (CSRs)
35 -- 0xc8020000: LiteEth CSRs (*)
36 -- 0xc8030000: LiteEth MMIO (*)
37 -- 0xc8040000: LiteSDCard CSRs
39 -- (*) LiteEth must be a single aligned 32KB block as the CSRs and MMIOs
40 -- are actually decoded as a single wishbone which LiteEth will
41 -- internally split based on bit 16.
43 -- (**) DRAM init code is currently special and goes to the external
44 -- IO bus, this will be fixed when it's moved out of litedram and
45 -- into the main SoC once we have a common "firmware".
58 MEMORY_SIZE : natural;
59 RAM_INIT_FILE : string;
62 HAS_FPU : boolean := true;
63 HAS_BTC : boolean := true;
64 HAS_SHORT_MULT : boolean := false;
65 DISABLE_FLATTEN_CORE : boolean := false;
66 HAS_DRAM : boolean := false;
67 DRAM_SIZE : integer := 0;
68 DRAM_INIT_SIZE : integer := 0;
69 HAS_SPI_FLASH : boolean := false;
70 SPI_FLASH_DLINES : positive := 1;
71 SPI_FLASH_OFFSET : integer := 0;
72 SPI_FLASH_DEF_CKDV : natural := 2;
73 SPI_FLASH_DEF_QUAD : boolean := false;
74 SPI_BOOT_CLOCKS : boolean := true;
75 LOG_LENGTH : natural := 512;
76 HAS_LITEETH : boolean := false;
77 UART0_IS_16550 : boolean := true;
78 HAS_UART1 : boolean := false;
79 HAS_UARTUSB : boolean := false;
80 ICACHE_NUM_LINES : natural := 64;
81 ICACHE_NUM_WAYS : natural := 2;
82 ICACHE_TLB_SIZE : natural := 64;
83 DCACHE_NUM_LINES : natural := 64;
84 DCACHE_NUM_WAYS : natural := 2;
85 DCACHE_TLB_SET_SIZE : natural := 64;
86 DCACHE_TLB_NUM_WAYS : natural := 2;
87 HAS_SD_CARD : boolean := false;
88 HAS_GPIO : boolean := false;
93 system_clk : in std_ulogic;
94 clk_48 : in std_ulogic := '0';
96 -- "Large" (64-bit) DRAM wishbone
97 wb_dram_in : out wishbone_master_out;
98 wb_dram_out : in wishbone_slave_out := wishbone_slave_out_init;
100 -- "Small" (32-bit) external IO wishbone
101 wb_ext_io_in : out wb_io_master_out;
102 wb_ext_io_out : in wb_io_slave_out := wb_io_slave_out_init;
103 wb_ext_is_dram_csr : out std_ulogic;
104 wb_ext_is_dram_init : out std_ulogic;
105 wb_ext_is_eth : out std_ulogic;
106 wb_ext_is_sdcard : out std_ulogic;
108 -- external DMA wishbone with 32-bit data/address
109 wishbone_dma_in : out wb_io_slave_out := wb_io_slave_out_init;
110 wishbone_dma_out : in wb_io_master_out := wb_io_master_out_init;
112 -- External interrupts
113 ext_irq_eth : in std_ulogic := '0';
114 ext_irq_sdcard : in std_ulogic := '0';
117 uart0_txd : out std_ulogic;
118 uart0_rxd : in std_ulogic := '0';
121 uart1_txd : out std_ulogic;
122 uart1_rxd : in std_ulogic := '0';
125 usb_d_p : in std_ulogic := '0';
126 usb_d_n : in std_ulogic := '0';
127 usb_pullup : out std_ulogic;
130 spi_flash_sck : out std_ulogic;
131 spi_flash_cs_n : out std_ulogic;
132 spi_flash_sdat_o : out std_ulogic_vector(SPI_FLASH_DLINES-1 downto 0);
133 spi_flash_sdat_oe : out std_ulogic_vector(SPI_FLASH_DLINES-1 downto 0);
134 spi_flash_sdat_i : in std_ulogic_vector(SPI_FLASH_DLINES-1 downto 0) := (others => '1');
137 gpio_out : out std_ulogic_vector(NGPIO - 1 downto 0);
138 gpio_dir : out std_ulogic_vector(NGPIO - 1 downto 0);
139 gpio_in : in std_ulogic_vector(NGPIO - 1 downto 0) := (others => '0');
141 -- DRAM controller signals
142 alt_reset : in std_ulogic := '0'
146 architecture behaviour of soc is
148 -- Wishbone master signals:
149 signal wishbone_dcore_in : wishbone_slave_out;
150 signal wishbone_dcore_out : wishbone_master_out;
151 signal wishbone_icore_in : wishbone_slave_out;
152 signal wishbone_icore_out : wishbone_master_out;
153 signal wishbone_debug_in : wishbone_slave_out;
154 signal wishbone_debug_out : wishbone_master_out;
156 -- Arbiter array (ghdl doesnt' support assigning the array
157 -- elements in the entity instantiation)
158 constant NUM_WB_MASTERS : positive := 4;
159 signal wb_masters_out : wishbone_master_out_vector(0 to NUM_WB_MASTERS-1);
160 signal wb_masters_in : wishbone_slave_out_vector(0 to NUM_WB_MASTERS-1);
162 -- Wishbone master (output of arbiter):
163 signal wb_master_in : wishbone_slave_out;
164 signal wb_master_out : wishbone_master_out;
165 signal wb_snoop : wishbone_master_out;
167 -- Main "IO" bus, from main slave decoder to the latch
168 signal wb_io_in : wishbone_master_out;
169 signal wb_io_out : wishbone_slave_out;
171 -- Secondary (smaller) IO bus after the IO bus latch
172 signal wb_sio_out : wb_io_master_out;
173 signal wb_sio_in : wb_io_slave_out;
176 signal dram_at_0 : std_ulogic;
177 signal do_core_reset : std_ulogic;
178 signal wb_syscon_in : wb_io_master_out;
179 signal wb_syscon_out : wb_io_slave_out;
182 signal wb_uart0_in : wb_io_master_out;
183 signal wb_uart0_out : wb_io_slave_out;
184 signal uart0_dat8 : std_ulogic_vector(7 downto 0);
185 signal uart0_irq : std_ulogic;
188 signal wb_uart1_in : wb_io_master_out;
189 signal wb_uart1_out : wb_io_slave_out;
190 signal uart1_dat8 : std_ulogic_vector(7 downto 0);
191 signal uart1_irq : std_ulogic;
194 signal wb_uartusb_in : wb_io_master_out;
195 signal wb_uartusb_out : wb_io_slave_out;
196 signal uartusb_irq : std_ulogic;
198 -- SPI Flash controller signals:
199 signal wb_spiflash_in : wb_io_master_out;
200 signal wb_spiflash_out : wb_io_slave_out;
201 signal wb_spiflash_is_reg : std_ulogic;
202 signal wb_spiflash_is_map : std_ulogic;
205 signal wb_xics_icp_in : wb_io_master_out;
206 signal wb_xics_icp_out : wb_io_slave_out;
207 signal wb_xics_ics_in : wb_io_master_out;
208 signal wb_xics_ics_out : wb_io_slave_out;
209 signal int_level_in : std_ulogic_vector(15 downto 0);
210 signal ics_to_icp : ics_to_icp_t;
211 signal core_ext_irq : std_ulogic;
214 signal wb_gpio_in : wb_io_master_out;
215 signal wb_gpio_out : wb_io_slave_out;
216 signal gpio_intr : std_ulogic := '0';
218 -- Main memory signals:
219 signal wb_bram_in : wishbone_master_out;
220 signal wb_bram_out : wishbone_slave_out;
222 -- DMI debug bus signals
223 signal dmi_addr : std_ulogic_vector(7 downto 0);
224 signal dmi_din : std_ulogic_vector(63 downto 0);
225 signal dmi_dout : std_ulogic_vector(63 downto 0);
226 signal dmi_req : std_ulogic;
227 signal dmi_wr : std_ulogic;
228 signal dmi_ack : std_ulogic;
230 -- Per slave DMI signals
231 signal dmi_wb_dout : std_ulogic_vector(63 downto 0);
232 signal dmi_wb_req : std_ulogic;
233 signal dmi_wb_ack : std_ulogic;
234 signal dmi_core_dout : std_ulogic_vector(63 downto 0);
235 signal dmi_core_req : std_ulogic;
236 signal dmi_core_ack : std_ulogic;
238 -- Delayed/latched resets and alt_reset
239 signal rst_core : std_ulogic := '1';
240 signal rst_uart : std_ulogic := '1';
241 signal rst_xics : std_ulogic := '1';
242 signal rst_spi : std_ulogic := '1';
243 signal rst_gpio : std_ulogic := '1';
244 signal rst_bram : std_ulogic := '1';
245 signal rst_dtm : std_ulogic := '1';
246 signal rst_wbar : std_ulogic := '1';
247 signal rst_wbdb : std_ulogic := '1';
248 signal alt_reset_d : std_ulogic;
251 type slave_io_type is (SLAVE_IO_SYSCON,
260 signal current_io_decode : slave_io_type;
262 signal io_cycle_none : std_ulogic;
263 signal io_cycle_syscon : std_ulogic;
264 signal io_cycle_uart : std_ulogic;
265 signal io_cycle_uart1 : std_ulogic;
266 signal io_cycle_uartusb : std_ulogic;
267 signal io_cycle_icp : std_ulogic;
268 signal io_cycle_ics : std_ulogic;
269 signal io_cycle_spi_flash : std_ulogic;
270 signal io_cycle_gpio : std_ulogic;
271 signal io_cycle_external : std_ulogic;
273 function wishbone_widen_data(wb : wb_io_master_out) return wishbone_master_out is
274 variable wwb : wishbone_master_out;
276 wwb.adr := wb.adr(wb.adr'left downto 1);
277 wwb.dat := wb.dat & wb.dat;
279 if wb.adr(0) = '0' then
280 wwb.sel(3 downto 0) := wb.sel;
282 wwb.sel(7 downto 4) := wb.sel;
290 function wishbone_narrow_data(wwbs : wishbone_slave_out; adr : std_ulogic_vector(29 downto 0))
291 return wb_io_slave_out is
292 variable wbs : wb_io_slave_out;
295 wbs.stall := wwbs.stall;
297 wbs.dat := wwbs.dat(31 downto 0);
299 wbs.dat := wwbs.dat(63 downto 32);
304 -- This is the component exported by the 16550 compatible
305 -- UART from FuseSoC.
307 component uart_top port (
308 wb_clk_i : in std_ulogic;
309 wb_rst_i : in std_ulogic;
310 wb_adr_i : in std_ulogic_vector(2 downto 0);
311 wb_dat_i : in std_ulogic_vector(7 downto 0);
312 wb_dat_o : out std_ulogic_vector(7 downto 0);
313 wb_we_i : in std_ulogic;
314 wb_stb_i : in std_ulogic;
315 wb_cyc_i : in std_ulogic;
316 wb_ack_o : out std_ulogic;
317 int_o : out std_ulogic;
318 stx_pad_o : out std_ulogic;
319 srx_pad_i : in std_ulogic;
320 rts_pad_o : out std_ulogic;
321 cts_pad_i : in std_ulogic;
322 dtr_pad_o : out std_ulogic;
323 dsr_pad_i : in std_ulogic;
324 ri_pad_i : in std_ulogic;
325 dcd_pad_i : in std_ulogic
329 constant UART0_IS_POTATO : boolean := not UART0_IS_16550;
332 resets: process(system_clk)
334 if rising_edge(system_clk) then
335 rst_core <= rst or do_core_reset;
344 alt_reset_d <= alt_reset;
349 processor: entity work.core
354 HAS_SHORT_MULT => HAS_SHORT_MULT,
355 DISABLE_FLATTEN => DISABLE_FLATTEN_CORE,
356 ALT_RESET_ADDRESS => (23 downto 0 => '0', others => '1'),
357 LOG_LENGTH => LOG_LENGTH,
358 ICACHE_NUM_LINES => ICACHE_NUM_LINES,
359 ICACHE_NUM_WAYS => ICACHE_NUM_WAYS,
360 ICACHE_TLB_SIZE => ICACHE_TLB_SIZE,
361 DCACHE_NUM_LINES => DCACHE_NUM_LINES,
362 DCACHE_NUM_WAYS => DCACHE_NUM_WAYS,
363 DCACHE_TLB_SET_SIZE => DCACHE_TLB_SET_SIZE,
364 DCACHE_TLB_NUM_WAYS => DCACHE_TLB_NUM_WAYS
369 alt_reset => alt_reset_d,
370 wishbone_insn_in => wishbone_icore_in,
371 wishbone_insn_out => wishbone_icore_out,
372 wishbone_data_in => wishbone_dcore_in,
373 wishbone_data_out => wishbone_dcore_out,
374 wb_snoop_in => wb_snoop,
375 dmi_addr => dmi_addr(3 downto 0),
376 dmi_dout => dmi_core_dout,
379 dmi_ack => dmi_core_ack,
380 dmi_req => dmi_core_req,
381 ext_irq => core_ext_irq
384 -- Wishbone bus master arbiter & mux
385 wb_masters_out <= (0 => wishbone_dcore_out,
386 1 => wishbone_icore_out,
387 2 => wishbone_widen_data(wishbone_dma_out),
388 3 => wishbone_debug_out);
389 wishbone_dcore_in <= wb_masters_in(0);
390 wishbone_icore_in <= wb_masters_in(1);
391 wishbone_dma_in <= wishbone_narrow_data(wb_masters_in(2), wishbone_dma_out.adr);
392 wishbone_debug_in <= wb_masters_in(3);
393 wishbone_arbiter_0: entity work.wishbone_arbiter
395 NUM_MASTERS => NUM_WB_MASTERS
400 wb_masters_in => wb_masters_out,
401 wb_masters_out => wb_masters_in,
402 wb_slave_out => wb_master_out,
403 wb_slave_in => wb_master_in
406 -- Snoop bus going to caches.
407 -- Gate stb with stall so the caches don't see the stalled strobes.
408 -- That way if the caches see a strobe when their wishbone is stalled,
409 -- they know it is an access by another master.
412 wb_snoop <= wb_master_out;
413 if wb_master_in.stall = '1' then
418 -- Top level Wishbone slaves address decoder & mux
420 -- From CPU to BRAM, DRAM, IO, selected on top 3 bits and dram_at_0
427 slave_top_intercon: process(wb_master_out, wb_bram_out, wb_dram_out, wb_io_out, dram_at_0)
428 type slave_top_type is (SLAVE_TOP_BRAM,
431 variable slave_top : slave_top_type;
432 variable top_decode : std_ulogic_vector(3 downto 0);
434 -- Top-level address decoder
435 top_decode := wb_master_out.adr(28 downto 26) & dram_at_0;
436 slave_top := SLAVE_TOP_BRAM;
437 if std_match(top_decode, "0000") then
438 slave_top := SLAVE_TOP_BRAM;
439 elsif std_match(top_decode, "0001") then
440 slave_top := SLAVE_TOP_DRAM;
441 elsif std_match(top_decode, "01--") then
442 slave_top := SLAVE_TOP_DRAM;
443 elsif std_match(top_decode, "10--") then
444 slave_top := SLAVE_TOP_BRAM;
445 elsif std_match(top_decode, "11--") then
446 slave_top := SLAVE_TOP_IO;
449 -- Top level wishbone muxing.
450 wb_bram_in <= wb_master_out;
451 wb_bram_in.cyc <= '0';
452 wb_dram_in <= wb_master_out;
453 wb_dram_in.cyc <= '0';
454 wb_io_in <= wb_master_out;
457 when SLAVE_TOP_BRAM =>
458 wb_bram_in.cyc <= wb_master_out.cyc;
459 wb_master_in <= wb_bram_out;
460 when SLAVE_TOP_DRAM =>
462 wb_dram_in.cyc <= wb_master_out.cyc;
463 wb_master_in <= wb_dram_out;
465 wb_master_in.ack <= wb_master_out.cyc and wb_master_out.stb;
466 wb_master_in.dat <= (others => '1');
467 wb_master_in.stall <= '0';
470 wb_io_in.cyc <= wb_master_out.cyc;
471 wb_master_in <= wb_io_out;
474 end process slave_top_intercon;
476 -- IO wishbone slave 64->32 bits converter
478 -- For timing reasons, this adds a one cycle latch on the way both
479 -- in and out. This relaxes timing and routing pressure on the "main"
480 -- memory bus by moving all simple IOs to a slower 32-bit bus.
482 -- This implementation is rather dumb at the moment, no stash buffer,
483 -- so we stall whenever that latch is busy. This can be improved.
485 slave_io_latch: process(system_clk)
487 type state_t is (IDLE, WAIT_ACK_BOT, WAIT_ACK_TOP);
488 variable state : state_t;
491 variable has_top : boolean;
492 variable has_bot : boolean;
493 variable do_cyc : std_ulogic;
494 variable end_cyc : std_ulogic;
495 variable slave_io : slave_io_type;
496 variable match : std_ulogic_vector(31 downto 12);
498 if rising_edge(system_clk) then
503 wb_io_out.ack <= '0';
504 wb_io_out.stall <= '0';
505 wb_sio_out.stb <= '0';
512 -- Clear ACK in case it was set
513 wb_io_out.ack <= '0';
515 -- Do we have a cycle ?
516 if wb_io_in.cyc = '1' and wb_io_in.stb = '1' then
517 -- Stall master until we are done, we are't (yet) pipelining
518 -- this, it's all slow IOs.
519 wb_io_out.stall <= '1';
521 -- Start cycle downstream
523 wb_sio_out.stb <= '1';
525 -- Copy write enable to IO out, copy address as well
526 wb_sio_out.we <= wb_io_in.we;
527 wb_sio_out.adr <= wb_io_in.adr(wb_sio_out.adr'left - 1 downto 0) & '0';
529 -- Do we have a top word and/or a bottom word ?
530 has_top := wb_io_in.sel(7 downto 4) /= "0000";
531 has_bot := wb_io_in.sel(3 downto 0) /= "0000";
533 -- If we have a bottom word, handle it first, otherwise
534 -- send the top word down. XXX Split the actual mux out
535 -- and only generate a control signal.
537 if wb_io_in.we = '1' then
538 wb_sio_out.dat <= wb_io_in.dat(31 downto 0);
540 wb_sio_out.sel <= wb_io_in.sel(3 downto 0);
543 state := WAIT_ACK_BOT;
545 if wb_io_in.we = '1' then
546 wb_sio_out.dat <= wb_io_in.dat(63 downto 32);
548 wb_sio_out.sel <= wb_io_in.sel(7 downto 4);
551 wb_sio_out.adr(0) <= '1';
554 state := WAIT_ACK_TOP;
558 -- If we aren't stalled by the device, clear stb
559 if wb_sio_in.stall = '0' then
560 wb_sio_out.stb <= '0';
564 if wb_sio_in.ack = '1' then
565 -- If it's a read, latch the data
566 if wb_sio_out.we = '0' then
567 wb_io_out.dat(31 downto 0) <= wb_sio_in.dat;
570 -- Do we have a "top" part as well ?
573 if wb_io_in.we = '1' then
574 wb_sio_out.dat <= wb_io_in.dat(63 downto 32);
576 wb_sio_out.sel <= wb_io_in.sel(7 downto 4);
578 -- Bump address and set STB
579 wb_sio_out.adr(0) <= '1';
580 wb_sio_out.stb <= '1';
583 state := WAIT_ACK_TOP;
585 -- We are done, ack up, clear cyc downstream
588 -- And ack & unstall upstream
589 wb_io_out.ack <= '1';
590 wb_io_out.stall <= '0';
597 -- If we aren't stalled by the device, clear stb
598 if wb_sio_in.stall = '0' then
599 wb_sio_out.stb <= '0';
603 if wb_sio_in.ack = '1' then
604 -- If it's a read, latch the data
605 if wb_sio_out.we = '0' then
606 wb_io_out.dat(63 downto 32) <= wb_sio_in.dat;
609 -- We are done, ack up, clear cyc downstram
612 -- And ack & unstall upstream
613 wb_io_out.ack <= '1';
614 wb_io_out.stall <= '0';
622 -- Create individual registered cycle signals for the wishbones
623 -- going to the various peripherals
624 if do_cyc = '1' or end_cyc = '1' then
625 io_cycle_none <= '0';
626 io_cycle_syscon <= '0';
627 io_cycle_uart <= '0';
628 io_cycle_uart1 <= '0';
629 io_cycle_uartusb <= '0';
632 io_cycle_spi_flash <= '0';
633 io_cycle_gpio <= '0';
634 io_cycle_external <= '0';
635 wb_sio_out.cyc <= '0';
636 wb_ext_is_dram_init <= '0';
637 wb_spiflash_is_map <= '0';
638 wb_spiflash_is_reg <= '0';
639 wb_ext_is_dram_csr <= '0';
640 wb_ext_is_eth <= '0';
641 wb_ext_is_sdcard <= '0';
644 -- Decode I/O address
645 -- This is real address bits 29 downto 12
646 match := "11" & wb_io_in.adr(26 downto 9);
647 slave_io := SLAVE_IO_SYSCON;
648 if std_match(match, x"FF---") and HAS_DRAM then
649 slave_io := SLAVE_IO_EXTERNAL;
650 io_cycle_external <= '1';
651 wb_ext_is_dram_init <= '1';
652 elsif std_match(match, x"F----") then
653 slave_io := SLAVE_IO_SPI_FLASH;
654 io_cycle_spi_flash <= '1';
655 wb_spiflash_is_map <= '1';
656 elsif std_match(match, x"C8---") then
657 -- Ext IO "chip selects"
658 if std_match(match, x"--00-") and HAS_DRAM then
659 slave_io := SLAVE_IO_EXTERNAL;
660 io_cycle_external <= '1';
661 wb_ext_is_dram_csr <= '1';
662 elsif (std_match(match, x"--02-") or std_match(match, x"--03-")) and
664 slave_io := SLAVE_IO_EXTERNAL;
665 io_cycle_external <= '1';
666 wb_ext_is_eth <= '1';
667 elsif std_match(match, x"--04-") and HAS_SD_CARD then
668 slave_io := SLAVE_IO_EXTERNAL;
669 io_cycle_external <= '1';
670 wb_ext_is_sdcard <= '1';
672 io_cycle_none <= '1';
674 elsif std_match(match, x"C0000") then
675 slave_io := SLAVE_IO_SYSCON;
676 io_cycle_syscon <= '1';
677 elsif std_match(match, x"C0002") then
678 slave_io := SLAVE_IO_UART;
679 io_cycle_uart <= '1';
680 elsif std_match(match, x"C0003") then
681 slave_io := SLAVE_IO_UART1;
682 io_cycle_uart1 <= '1';
683 elsif std_match(match, x"C0004") then
684 slave_io := SLAVE_IO_ICP;
686 elsif std_match(match, x"C0005") then
687 slave_io := SLAVE_IO_ICS;
689 elsif std_match(match, x"C0006") then
690 slave_io := SLAVE_IO_SPI_FLASH;
691 io_cycle_spi_flash <= '1';
692 wb_spiflash_is_reg <= '1';
693 elsif std_match(match, x"C0007") then
694 slave_io := SLAVE_IO_GPIO;
695 io_cycle_gpio <= '1';
696 elsif std_match(match, x"C0008") then
697 slave_io := SLAVE_IO_UARTUSB;
698 io_cycle_uartusb <= '1';
700 io_cycle_none <= '1';
702 current_io_decode <= slave_io;
703 wb_sio_out.cyc <= '1';
708 -- IO wishbone slave interconnect.
710 slave_io_intercon: process(all)
712 wb_uart0_in <= wb_sio_out;
713 wb_uart0_in.cyc <= io_cycle_uart;
714 wb_uart1_in <= wb_sio_out;
715 wb_uart1_in.cyc <= io_cycle_uart1;
717 wb_spiflash_in <= wb_sio_out;
718 wb_spiflash_in.cyc <= io_cycle_spi_flash;
719 -- Clear top bits so they don't make their way to the
721 wb_spiflash_in.adr(27 downto 26) <= "00";
723 wb_gpio_in <= wb_sio_out;
724 wb_gpio_in.cyc <= io_cycle_gpio;
726 wb_uartusb_in <= wb_sio_out;
727 wb_uartusb_in.cyc <= io_cycle_uartusb;
728 -- valentyusb was built at base 0x0, it only needs 5 low bits
729 wb_uartusb_in.adr <= (others => '0');
730 wb_uartusb_in.adr(4 downto 0) <= wb_sio_out.adr(4 downto 0);
732 -- Only give xics 8 bits of wb addr (for now...)
733 wb_xics_icp_in <= wb_sio_out;
734 wb_xics_icp_in.adr <= (others => '0');
735 wb_xics_icp_in.adr(5 downto 0) <= wb_sio_out.adr(5 downto 0);
736 wb_xics_icp_in.cyc <= io_cycle_icp;
737 wb_xics_ics_in <= wb_sio_out;
738 wb_xics_ics_in.adr <= (others => '0');
739 wb_xics_ics_in.adr(9 downto 0) <= wb_sio_out.adr(9 downto 0);
740 wb_xics_ics_in.cyc <= io_cycle_ics;
742 wb_ext_io_in <= wb_sio_out;
743 wb_ext_io_in.cyc <= io_cycle_external;
745 wb_syscon_in <= wb_sio_out;
746 wb_syscon_in.cyc <= io_cycle_syscon;
748 case current_io_decode is
749 when SLAVE_IO_EXTERNAL =>
750 wb_sio_in <= wb_ext_io_out;
751 when SLAVE_IO_SYSCON =>
752 wb_sio_in <= wb_syscon_out;
753 when SLAVE_IO_UART =>
754 wb_sio_in <= wb_uart0_out;
756 wb_sio_in <= wb_xics_icp_out;
758 wb_sio_in <= wb_xics_ics_out;
759 when SLAVE_IO_UART1 =>
760 wb_sio_in <= wb_uart1_out;
761 when SLAVE_IO_UARTUSB =>
762 wb_sio_in <= wb_uartusb_out;
763 when SLAVE_IO_SPI_FLASH =>
764 wb_sio_in <= wb_spiflash_out;
765 when SLAVE_IO_GPIO =>
766 wb_sio_in <= wb_gpio_out;
769 -- Default response, ack & return all 1's
770 if io_cycle_none = '1' then
771 wb_sio_in.dat <= (others => '1');
772 wb_sio_in.ack <= wb_sio_out.stb and wb_sio_out.cyc;
773 wb_sio_in.stall <= '0';
779 syscon0: entity work.syscon
782 HAS_DRAM => HAS_DRAM,
783 BRAM_SIZE => MEMORY_SIZE,
784 DRAM_SIZE => DRAM_SIZE,
785 DRAM_INIT_SIZE => DRAM_INIT_SIZE,
786 CLK_FREQ => CLK_FREQ,
787 HAS_SPI_FLASH => HAS_SPI_FLASH,
788 SPI_FLASH_OFFSET => SPI_FLASH_OFFSET,
789 HAS_LITEETH => HAS_LITEETH,
790 HAS_SD_CARD => HAS_SD_CARD,
791 UART0_IS_16550 => UART0_IS_16550,
792 HAS_UART1 => HAS_UART1,
793 HAS_UARTUSB => HAS_UARTUSB
798 wishbone_in => wb_syscon_in,
799 wishbone_out => wb_syscon_out,
800 dram_at_0 => dram_at_0,
801 core_reset => do_core_reset,
802 soc_reset => open -- XXX TODO
808 -- Either potato (legacy) or 16550
810 uart0_pp: if UART0_IS_POTATO generate
811 uart0: entity work.pp_soc_uart
821 wb_adr_in => wb_uart0_in.adr(9 downto 0) & "00",
822 wb_dat_in => wb_uart0_in.dat(7 downto 0),
823 wb_dat_out => uart0_dat8,
824 wb_cyc_in => wb_uart0_in.cyc,
825 wb_stb_in => wb_uart0_in.stb,
826 wb_we_in => wb_uart0_in.we,
827 wb_ack_out => wb_uart0_out.ack
830 wb_uart0_out.dat <= x"000000" & uart0_dat8;
831 wb_uart0_out.stall <= not wb_uart0_out.ack;
834 uart0_16550 : if UART0_IS_16550 generate
835 signal irq_l : std_ulogic;
839 wb_clk_i => system_clk,
840 wb_rst_i => rst_uart,
841 wb_adr_i => wb_uart0_in.adr(2 downto 0),
842 wb_dat_i => wb_uart0_in.dat(7 downto 0),
843 wb_dat_o => uart0_dat8,
844 wb_we_i => wb_uart0_in.we,
845 wb_stb_i => wb_uart0_in.stb,
846 wb_cyc_i => wb_uart0_in.cyc,
847 wb_ack_o => wb_uart0_out.ack,
849 stx_pad_o => uart0_txd,
850 srx_pad_i => uart0_rxd,
859 -- Add a register on the irq out, helps timing
860 uart0_irq_latch: process(system_clk)
862 if rising_edge(system_clk) then
867 wb_uart0_out.dat <= x"000000" & uart0_dat8;
868 wb_uart0_out.stall <= not wb_uart0_out.ack;
872 uart0_valentyusb : if HAS_UARTUSB generate
873 component valentyusb port (
874 clk_clksys : in std_ulogic;
875 clk_clk48 : in std_ulogic;
876 reset : in std_ulogic;
877 usb_d_p : in std_ulogic;
878 usb_d_n : in std_ulogic;
879 usb_pullup : out std_ulogic;
880 usb_tx_en : out std_ulogic;
881 interrupt : out std_ulogic;
882 wishbone_adr : in std_ulogic_vector(29 downto 0);
883 wishbone_dat_w : in std_ulogic_vector(31 downto 0);
884 wishbone_dat_r : out std_ulogic_vector(31 downto 0);
885 wishbone_sel : in std_ulogic_vector(3 downto 0);
886 wishbone_cyc : in std_ulogic;
887 wishbone_stb : in std_ulogic;
888 wishbone_ack : out std_ulogic;
889 wishbone_we : in std_ulogic;
890 wishbone_cti : in std_ulogic_vector(2 downto 0);
891 wishbone_bte : in std_ulogic_vector(1 downto 0);
892 wishbone_err : out std_ulogic
895 signal irq_l : std_ulogic;
899 clk_clksys => system_clk,
904 usb_pullup => usb_pullup,
907 wishbone_adr => "0000000000000000" & wb_uartusb_in.adr(13 downto 0),
908 wishbone_dat_r => wb_uartusb_out.dat,
909 wishbone_dat_w => wb_uartusb_in.dat,
910 wishbone_sel => wb_uartusb_in.sel,
911 wishbone_cyc => wb_uartusb_in.cyc,
912 wishbone_stb => wb_uartusb_in.stb,
913 wishbone_ack => wb_uartusb_out.ack,
914 wishbone_we => wb_uartusb_in.we,
916 -- XXX matt check this
917 wishbone_cti => "000",
918 -- XXX matt check this
919 wishbone_bte => "00",
923 wb_uartusb_out.stall <= not wb_uartusb_out.ack;
925 -- Add a register on the irq out, helps timing
926 uartusb_irq_latch: process(system_clk)
928 if rising_edge(system_clk) then
929 uartusb_irq <= irq_l;
937 -- Always 16550 if it exists
939 uart1: if HAS_UART1 generate
940 signal irq_l : std_ulogic;
944 wb_clk_i => system_clk,
945 wb_rst_i => rst_uart,
946 wb_adr_i => wb_uart1_in.adr(2 downto 0),
947 wb_dat_i => wb_uart1_in.dat(7 downto 0),
948 wb_dat_o => uart1_dat8,
949 wb_we_i => wb_uart1_in.we,
950 wb_stb_i => wb_uart1_in.stb,
951 wb_cyc_i => wb_uart1_in.cyc,
952 wb_ack_o => wb_uart1_out.ack,
954 stx_pad_o => uart1_txd,
955 srx_pad_i => uart1_rxd,
963 -- Add a register on the irq out, helps timing
964 uart0_irq_latch: process(system_clk)
966 if rising_edge(system_clk) then
970 wb_uart1_out.dat <= x"000000" & uart1_dat8;
971 wb_uart1_out.stall <= not wb_uart1_out.ack;
974 no_uart1 : if not HAS_UART1 generate
975 wb_uart1_out.dat <= x"00000000";
976 wb_uart1_out.ack <= wb_uart1_in.cyc and wb_uart1_in.stb;
977 wb_uart1_out.stall <= '0';
981 spiflash_gen: if HAS_SPI_FLASH generate
982 spiflash: entity work.spi_flash_ctrl
984 DATA_LINES => SPI_FLASH_DLINES,
985 DEF_CLK_DIV => SPI_FLASH_DEF_CKDV,
986 DEF_QUAD_READ => SPI_FLASH_DEF_QUAD,
987 BOOT_CLOCKS => SPI_BOOT_CLOCKS
992 wb_in => wb_spiflash_in,
993 wb_out => wb_spiflash_out,
994 wb_sel_reg => wb_spiflash_is_reg,
995 wb_sel_map => wb_spiflash_is_map,
996 sck => spi_flash_sck,
997 cs_n => spi_flash_cs_n,
998 sdat_o => spi_flash_sdat_o,
999 sdat_oe => spi_flash_sdat_oe,
1000 sdat_i => spi_flash_sdat_i
1004 no_spi0_gen: if not HAS_SPI_FLASH generate
1005 wb_spiflash_out.dat <= (others => '1');
1006 wb_spiflash_out.ack <= wb_spiflash_in.cyc and wb_spiflash_in.stb;
1007 wb_spiflash_out.stall <= wb_spiflash_in.cyc and not wb_spiflash_out.ack;
1010 xics_icp: entity work.xics_icp
1014 wb_in => wb_xics_icp_in,
1015 wb_out => wb_xics_icp_out,
1016 ics_in => ics_to_icp,
1017 core_irq_out => core_ext_irq
1020 xics_ics: entity work.xics_ics
1028 wb_in => wb_xics_ics_in,
1029 wb_out => wb_xics_ics_out,
1030 int_level_in => int_level_in,
1031 icp_out => ics_to_icp
1034 gpio0_gen: if HAS_GPIO generate
1035 gpio : entity work.gpio
1042 wb_in => wb_gpio_in,
1043 wb_out => wb_gpio_out,
1045 gpio_out => gpio_out,
1046 gpio_dir => gpio_dir,
1051 -- Assign external interrupts
1052 interrupts: process(all)
1054 int_level_in <= (others => '0');
1055 int_level_in(0) <= uart0_irq;
1056 int_level_in(1) <= ext_irq_eth;
1057 int_level_in(2) <= uart1_irq;
1058 int_level_in(3) <= ext_irq_sdcard;
1059 int_level_in(4) <= gpio_intr;
1060 int_level_in(5) <= uartusb_irq;
1063 -- BRAM Memory slave
1064 bram: if MEMORY_SIZE /= 0 generate
1065 bram0: entity work.wishbone_bram_wrapper
1067 MEMORY_SIZE => MEMORY_SIZE,
1068 RAM_INIT_FILE => RAM_INIT_FILE
1073 wishbone_in => wb_bram_in,
1074 wishbone_out => wb_bram_out
1078 no_bram: if MEMORY_SIZE = 0 generate
1079 wb_bram_out.ack <= wb_bram_in.cyc and wb_bram_in.stb;
1080 wb_bram_out.dat <= x"FFFFFFFFFFFFFFFF";
1081 wb_bram_out.stall <= not wb_bram_out.ack;
1084 -- DMI(debug bus) <-> JTAG bridge
1085 dtm: entity work.dmi_dtm
1091 sys_clk => system_clk,
1092 sys_reset => rst_dtm,
1093 dmi_addr => dmi_addr,
1095 dmi_dout => dmi_dout,
1102 dmi_intercon: process(dmi_addr, dmi_req,
1103 dmi_wb_ack, dmi_wb_dout,
1104 dmi_core_ack, dmi_core_dout)
1106 -- DMI address map (each address is a full 64-bit register)
1108 -- Offset: Size: Slave:
1112 type slave_type is (SLAVE_WB,
1115 variable slave : slave_type;
1117 -- Simple address decoder
1118 slave := SLAVE_NONE;
1119 if std_match(dmi_addr, "000000--") then
1121 elsif std_match(dmi_addr, "0001----") then
1122 slave := SLAVE_CORE;
1127 dmi_core_req <= '0';
1130 dmi_wb_req <= dmi_req;
1131 dmi_ack <= dmi_wb_ack;
1132 dmi_din <= dmi_wb_dout;
1134 dmi_core_req <= dmi_req;
1135 dmi_ack <= dmi_core_ack;
1136 dmi_din <= dmi_core_dout;
1139 dmi_din <= (others => '1');
1143 if SIM and dmi_req = '1' and dmi_addr = "11111111" and dmi_wr = '1' then
1148 -- Wishbone debug master (TODO: Add a DMI address decoder)
1149 wishbone_debug: entity work.wishbone_debug_master
1150 port map(clk => system_clk,
1152 dmi_addr => dmi_addr(1 downto 0),
1153 dmi_dout => dmi_wb_dout,
1154 dmi_din => dmi_dout,
1156 dmi_ack => dmi_wb_ack,
1157 dmi_req => dmi_wb_req,
1158 wb_in => wishbone_debug_in,
1159 wb_out => wishbone_debug_out);
1161 --pragma synthesis_off
1162 wb_x_state: process(system_clk)
1164 if rising_edge(system_clk) then
1167 assert not(is_x(wb_masters_out(0).cyc)) and not(is_x(wb_masters_out(0).stb)) severity failure;
1168 assert not(is_x(wb_masters_out(1).cyc)) and not(is_x(wb_masters_out(1).stb)) severity failure;
1169 assert not(is_x(wb_masters_out(2).cyc)) and not(is_x(wb_masters_out(2).stb)) severity failure;
1170 assert not(is_x(wb_masters_in(0).ack)) severity failure;
1171 assert not(is_x(wb_masters_in(1).ack)) severity failure;
1172 assert not(is_x(wb_masters_in(2).ack)) severity failure;
1174 -- Main memory wishbones
1175 assert not(is_x(wb_bram_in.cyc)) and not (is_x(wb_bram_in.stb)) severity failure;
1176 assert not(is_x(wb_dram_in.cyc)) and not (is_x(wb_dram_in.stb)) severity failure;
1177 assert not(is_x(wb_io_in.cyc)) and not (is_x(wb_io_in.stb)) severity failure;
1178 assert not(is_x(wb_bram_out.ack)) severity failure;
1179 assert not(is_x(wb_dram_out.ack)) severity failure;
1180 assert not(is_x(wb_io_out.ack)) severity failure;
1183 assert not(is_x(wb_uart0_in.cyc)) and not(is_x(wb_uart0_in.stb)) severity failure;
1184 assert not(is_x(wb_uart1_in.cyc)) and not(is_x(wb_uart1_in.stb)) severity failure;
1185 assert not(is_x(wb_spiflash_in.cyc)) and not(is_x(wb_spiflash_in.stb)) severity failure;
1186 assert not(is_x(wb_xics_icp_in.cyc)) and not(is_x(wb_xics_icp_in.stb)) severity failure;
1187 assert not(is_x(wb_xics_ics_in.cyc)) and not(is_x(wb_xics_ics_in.stb)) severity failure;
1188 assert not(is_x(wb_ext_io_in.cyc)) and not(is_x(wb_ext_io_in.stb)) severity failure;
1189 assert not(is_x(wb_syscon_in.cyc)) and not(is_x(wb_syscon_in.stb)) severity failure;
1190 assert not(is_x(wb_uart0_out.ack)) severity failure;
1191 assert not(is_x(wb_uart1_out.ack)) severity failure;
1192 assert not(is_x(wb_spiflash_out.ack)) severity failure;
1193 assert not(is_x(wb_xics_icp_out.ack)) severity failure;
1194 assert not(is_x(wb_xics_ics_out.ack)) severity failure;
1195 assert not(is_x(wb_ext_io_out.ack)) severity failure;
1196 assert not(is_x(wb_syscon_out.ack)) severity failure;
1200 --pragma synthesis_on
1202 end architecture behaviour;