/* * top.v * * vim: ts=4 sw=4 * * Copyright (C) 2019-2020 Sylvain Munaut * SPDX-License-Identifier: CERN-OHL-P-2.0 */ `default_nettype none `include "boards.vh" module top ( // Special features `ifdef MISC_SEL output wire [($bits(`MISC_SEL)/2)-1:0] misc, `endif // LED `ifdef HAS_1LED output wire led, `endif `ifdef HAS_RGB output wire [2:0] rgb, `endif // Debug UART `ifdef ENABLE_UART input wire uart_rx, output wire uart_tx, `endif // Clock `ifndef USE_HF_OSC input wire clk_in, `endif // Button input wire btn, // USB inout wire usb_dp, inout wire usb_dn, output wire usb_pu, // SPI inout wire spi_mosi, inout wire spi_miso, inout wire spi_clk, inout wire spi_cs_n ); localparam WB_N = 6; localparam WB_DW = 32; localparam WB_AW = 16; localparam WB_AI = 2; localparam SPRAM_AW = 14; /* 14 => 64k, 15 => 128k */ genvar i; // Signals // ------- // Memory bus wire mem_valid; wire mem_instr; wire mem_ready; wire [31:0] mem_addr; wire [31:0] mem_rdata; wire [31:0] mem_wdata; wire [ 3:0] mem_wstrb; // RAM // BRAM wire [ 7:0] bram_addr; wire [31:0] bram_rdata; wire [31:0] bram_wdata; wire [ 3:0] bram_wmsk; wire bram_we; // SPRAM wire [14:0] spram_addr; wire [31:0] spram_rdata; wire [31:0] spram_wdata; wire [ 3:0] spram_wmsk; wire spram_we; // Wishbone wire [ WB_AW -1:0] wb_addr; wire [ WB_DW-1 :0] wb_rdata [0:WB_N-1]; wire [ WB_DW -1:0] wb_wdata; wire [(WB_DW/8)-1:0] wb_wmsk; wire wb_we; wire [ WB_N -1:0] wb_cyc; wire [ WB_N -1:0] wb_ack; wire [(WB_DW*WB_N)-1:0] wb_rdata_flat; // USB Core // EP Buffer wire [ 8:0] ep_tx_addr_0; wire [31:0] ep_tx_data_0; wire ep_tx_we_0; wire [ 8:0] ep_rx_addr_0; wire [31:0] ep_rx_data_1; wire ep_rx_re_0; // Bus interface wire [11:0] ub_addr; wire [15:0] ub_wdata; wire [15:0] ub_rdata; wire ub_cyc; wire ub_we; wire ub_ack; // WarmBoot reg boot_now; reg [1:0] boot_sel; // Single led reg led_ena; reg [10:0] led_off; reg [10:0] led_on; wire led_i; // Clock / Reset logic wire clk_24m; wire clk_48m; wire rst; // SoC // --- // CPU picorv32 #( .PROGADDR_RESET(32'h 0000_0000), .STACKADDR(32'h 0000_0400), .BARREL_SHIFTER(0), .COMPRESSED_ISA(0), .ENABLE_COUNTERS(0), .ENABLE_MUL(0), .ENABLE_DIV(0), .ENABLE_IRQ(0), .ENABLE_IRQ_QREGS(0), .CATCH_MISALIGN(0), .CATCH_ILLINSN(0) ) cpu_I ( .clk (clk_24m), .resetn (~rst), .mem_valid (mem_valid), .mem_instr (mem_instr), .mem_ready (mem_ready), .mem_addr (mem_addr), .mem_wdata (mem_wdata), .mem_wstrb (mem_wstrb), .mem_rdata (mem_rdata) ); // Bus interface soc_picorv32_bridge #( .WB_N (WB_N), .WB_DW (WB_DW), .WB_AW (WB_AW), .WB_AI (WB_AI) ) pb_I ( .pb_addr (mem_addr), .pb_rdata (mem_rdata), .pb_wdata (mem_wdata), .pb_wstrb (mem_wstrb), .pb_valid (mem_valid), .pb_ready (mem_ready), .bram_addr (bram_addr), .bram_rdata (bram_rdata), .bram_wdata (bram_wdata), .bram_wmsk (bram_wmsk), .bram_we (bram_we), .spram_addr (spram_addr), .spram_rdata (spram_rdata), .spram_wdata (spram_wdata), .spram_wmsk (spram_wmsk), .spram_we (spram_we), .wb_addr (wb_addr), .wb_wdata (wb_wdata), .wb_wmsk (wb_wmsk), .wb_rdata (wb_rdata_flat), .wb_cyc (wb_cyc), .wb_we (wb_we), .wb_ack (wb_ack), .clk (clk_24m), .rst (rst) ); for (i=0; i