Advertisement
Guest User

Untitled

a guest
Apr 13th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 11.29 KB | None | 0 0
  1. //`include "orpsoc-defines.v"
  2. module orpsoc_top #(
  3. parameter   rom0_aw = 6,
  4. parameter   uart0_aw = 3
  5. )(
  6. input   sys_clk_pad_i,
  7. input   rst_n_pad_i,
  8.  
  9. // Cell Ram
  10. inout [15:0]    cellram_data_io,
  11. output [22:0]    cellram_adr_o,
  12. output      cellram_adv_n_o,
  13. output      cellram_ce_n_o,
  14. output      cellram_clk_o,
  15. output      cellram_oe_n_o,
  16. input       cellram_wait_i,
  17. output      cellram_we_n_o,
  18. output      cellram_cre_o,
  19. output           cellram_ub_n_o,
  20. output           cellram_lb_n_o,
  21.  
  22. // UART
  23. input   uart0_srx_pad_i,
  24. output  uart0_stx_pad_o,
  25.  
  26. // GPIO
  27. inout   [7:0]   gpio0_io
  28.  
  29. );
  30.  
  31. parameter   IDCODE_VALUE=32'h13631093;
  32.  
  33. localparam wb_aw = 32;
  34. localparam wb_dw = 32;
  35.  
  36. localparam MEM_SIZE_BITS = 12;
  37.  
  38. ////////////////////////////////////////////////////////////////////////
  39. //
  40. // Clock and reset generation module
  41. //
  42. ////////////////////////////////////////////////////////////////////////
  43.  
  44. //
  45. // Wires
  46. //
  47. wire wb_clk, wb_rst;
  48. wire dbg_tck;
  49. wire reset_invert;
  50.  
  51. assign reset_invert = ~rst_n_pad_i;
  52.  
  53. clkgen clkgen0
  54.  (
  55.     .sys_clk_in (sys_clk_pad_i),
  56.  
  57.     .wb_clk_o (wb_clk),
  58.     .wb_rst_o (wb_rst),
  59.  
  60.     // Asynchronous active low reset
  61.     .rst_i (reset_invert)
  62.  );
  63. ////////////////////////////////////////////////////////////////////////
  64. //
  65. // Modules interconnections
  66. //
  67. ////////////////////////////////////////////////////////////////////////
  68. `include "wb_intercon.vh"
  69.  
  70. ////////////////////////////////////////////////////////////////////////
  71. //
  72. // ARTIX7 JTAG TAP
  73. //
  74. ////////////////////////////////////////////////////////////////////////
  75.  
  76. wire dbg_capture_o;
  77. wire dbg_drck_o;
  78. wire dbg_reset_o;
  79. wire dbg_runtest_o;
  80. wire dbg_sel_o;
  81. wire dbg_shift_o;
  82. wire dbg_tck_o;
  83. wire dbg_tdi_o;
  84. wire dbg_tms_o;
  85. wire dbg_update_o;
  86. wire dbg_tdo_i;
  87.  
  88. wire dbg_pause_o;
  89. assign dbg_pause_o = 1'b0;
  90.  
  91.  
  92. BSCANE2 #(
  93.    .JTAG_CHAIN(1)  // Value for USER command. Possible values: 1-4.
  94. )
  95. BSCANE2_inst (
  96.    .CAPTURE(dbg_capture_o), // 1-bit output: CAPTURE output from TAP controller.
  97.    .DRCK(dbg_drck_o),       // 1-bit output: Gated TCK output. When SEL is asserted, DRCK toggles when CAPTURE or
  98.                       // SHIFT are asserted.
  99.  
  100.    .RESET(dbg_reset_o),     // 1-bit output: Reset output for TAP controller.
  101.    .RUNTEST(dbg_runtest_o), // 1-bit output: Output asserted when TAP controller is in Run Test/Idle state.
  102.    .SEL(dbg_sel_o),         // 1-bit output: USER instruction active output.
  103.    .SHIFT(dbg_shift_o),     // 1-bit output: SHIFT output from TAP controller.
  104.    .TCK(dbg_tck_o),         // 1-bit output: Test Clock output. Fabric connection to TAP Clock pin.
  105.    .TDI(dbg_tdi_o),         // 1-bit output: Test Data Input (TDI) output from TAP controller.
  106.    .TMS(dbg_tms_o),         // 1-bit output: Test Mode Select output. Fabric connection to TAP.
  107.    .UPDATE(dbg_update_o),   // 1-bit output: UPDATE output from TAP controller
  108.    .TDO(dbg_tdo_i)          // 1-bit input: Test Data Output (TDO) input for USER function.
  109. );
  110. /*
  111. minsoc_xilinx_internal_jtag tap_top(
  112.     .tck_o( dbg_tck_o ),
  113.     .debug_tdo_i( dbg_tdo_i ),
  114.     .tdi_o( debug_tdi_o ),
  115.  
  116.     .test_logic_reset_o( dbg_reset_o ),
  117.     .run_test_idle_o( dbg_runtest_o ),
  118.  
  119.     .shift_dr_o( dbg_shift_o ),
  120.     .capture_dr_o( dbg_capture_o ),
  121.     .pause_dr_o( dbg_pause_o ),
  122.     .update_dr_o( dbg_update_o ),
  123.     .debug_select_o( dbg_sel_o )
  124. );
  125. */
  126. ////////////////////////////////////////////////////////////////////////
  127. //
  128. // OR1K CPU
  129. //
  130. ////////////////////////////////////////////////////////////////////////
  131.  
  132. wire    [31:0]  or1k_irq;
  133. wire    or1k_rst;
  134.  
  135. wire    [31:0]  or1k_dbg_adr_i;
  136. wire    [31:0]  or1k_dbg_dat_i;
  137. wire        or1k_dbg_stb_i;
  138. wire        or1k_dbg_we_i;
  139. wire    [31:0]  or1k_dbg_dat_o;
  140. wire        or1k_dbg_ack_o;
  141. wire        or1k_dbg_stall_i;
  142. wire        or1k_dbg_bp_o;
  143.  
  144. mor1kx #(
  145.     .FEATURE_DEBUGUNIT("ENABLED"),
  146.     .FEATURE_CMOV("ENABLED"),
  147.     .FEATURE_INSTRUCTIONCACHE("ENABLED"),
  148.     .OPTION_ICACHE_BLOCK_WIDTH(5),
  149.     .OPTION_ICACHE_SET_WIDTH(8),
  150.     .OPTION_ICACHE_WAYS(2),
  151.     .OPTION_ICACHE_LIMIT_WIDTH(32),
  152.     .FEATURE_IMMU("ENABLED"),
  153.     .FEATURE_DATACACHE("ENABLED"),
  154.     .OPTION_DCACHE_BLOCK_WIDTH(5),
  155.     .OPTION_DCACHE_SET_WIDTH(8),
  156.     .OPTION_DCACHE_WAYS(2),
  157.     .OPTION_DCACHE_LIMIT_WIDTH(31),
  158.     .FEATURE_DMMU("ENABLED"),
  159.     .OPTION_PIC_TRIGGER("LATCHED_LEVEL"),
  160.  
  161.     .IBUS_WB_TYPE("B3_REGISTERED_FEEDBACK"),
  162.     .DBUS_WB_TYPE("B3_REGISTERED_FEEDBACK"),
  163.     .OPTION_CPU0("CAPPUCCINO"),
  164.     .OPTION_RESET_PC(32'hf0000100)
  165. ) mor1kx0 (
  166.     .iwbm_adr_o(wb_m2s_or1k_i_adr),
  167.     .iwbm_stb_o(wb_m2s_or1k_i_stb),
  168.     .iwbm_cyc_o(wb_m2s_or1k_i_cyc),
  169.     .iwbm_sel_o(wb_m2s_or1k_i_sel),
  170.     .iwbm_we_o (wb_m2s_or1k_i_we),
  171.     .iwbm_cti_o(wb_m2s_or1k_i_cti),
  172.     .iwbm_bte_o(wb_m2s_or1k_i_bte),
  173.     .iwbm_dat_o(wb_m2s_or1k_i_dat),
  174.  
  175.     .dwbm_adr_o(wb_m2s_or1k_d_adr),
  176.     .dwbm_stb_o(wb_m2s_or1k_d_stb),
  177.     .dwbm_cyc_o(wb_m2s_or1k_d_cyc),
  178.     .dwbm_sel_o(wb_m2s_or1k_d_sel),
  179.     .dwbm_we_o (wb_m2s_or1k_d_we ),
  180.     .dwbm_cti_o(wb_m2s_or1k_d_cti),
  181.     .dwbm_bte_o(wb_m2s_or1k_d_bte),
  182.     .dwbm_dat_o(wb_m2s_or1k_d_dat),
  183.  
  184.     .clk(wb_clk),
  185.     .rst(wb_rst),
  186.  
  187.     .iwbm_err_i(wb_s2m_or1k_i_err),
  188.     .iwbm_ack_i(wb_s2m_or1k_i_ack),
  189.     .iwbm_dat_i(wb_s2m_or1k_i_dat),
  190.     .iwbm_rty_i(wb_s2m_or1k_i_rty),
  191.  
  192.     .dwbm_err_i(wb_s2m_or1k_d_err),
  193.     .dwbm_ack_i(wb_s2m_or1k_d_ack),
  194.     .dwbm_dat_i(wb_s2m_or1k_d_dat),
  195.     .dwbm_rty_i(wb_s2m_or1k_d_rty),
  196.  
  197.     .irq_i(or1k_irq),
  198.  
  199.     .du_addr_i(or1k_dbg_adr_i[15:0]),
  200.     .du_stb_i(or1k_dbg_stb_i),
  201.     .du_dat_i(or1k_dbg_dat_i),
  202.     .du_we_i(or1k_dbg_we_i),
  203.     .du_dat_o(or1k_dbg_dat_o),
  204.     .du_ack_o(or1k_dbg_ack_o),
  205.     .du_stall_i(or1k_dbg_stall_i),
  206.     .du_stall_o(or1k_dbg_bp_o)
  207. );
  208.  
  209. ////////////////////////////////////////////////////////////////////////
  210. //
  211. // Debug Interface
  212. //
  213. ////////////////////////////////////////////////////////////////////////
  214.  
  215. adbg_top dbg_if0 (
  216.     // OR1K interface
  217.     .cpu0_clk_i (wb_clk),
  218.     .cpu0_rst_o (or1k_rst),
  219.     .cpu0_addr_o    (or1k_dbg_adr_i),
  220.     .cpu0_data_o    (or1k_dbg_dat_i),
  221.     .cpu0_stb_o (or1k_dbg_stb_i),
  222.     .cpu0_we_o  (or1k_dbg_we_i),
  223.     .cpu0_data_i    (or1k_dbg_dat_o),
  224.     .cpu0_ack_i (or1k_dbg_ack_o),
  225.     .cpu0_stall_o   (or1k_dbg_stall_i),
  226.     .cpu0_bp_i  (or1k_dbg_bp_o),
  227.  
  228.     // TAP interface
  229.     .tck_i      (dbg_tck_o),
  230.     .tdi_i      (dbg_tdi_o),
  231.     .tdo_o      (dbg_tdo_i),
  232.     .rst_i      (wb_rst),
  233.     .capture_dr_i   (dbg_capture_o),
  234.     .shift_dr_i (dbg_shift_o),
  235.     .pause_dr_i (dbg_pause_o),
  236.     .update_dr_i    (dbg_update_o),
  237.     .debug_select_i (dbg_sel_o),
  238.  
  239.     // Wishbone debug master
  240.     .wb_rst_i   (wb_rst),
  241.     .wb_clk_i   (wb_clk),
  242.     .wb_dat_i   (wb_s2m_dbg_dat),
  243.     .wb_ack_i   (wb_s2m_dbg_ack),
  244.     .wb_err_i   (wb_s2m_dbg_err),
  245.  
  246.     .wb_adr_o   (wb_m2s_dbg_adr),
  247.     .wb_dat_o   (wb_m2s_dbg_dat),
  248.     .wb_cyc_o   (wb_m2s_dbg_cyc),
  249.     .wb_stb_o   (wb_m2s_dbg_stb),
  250.     .wb_sel_o   (wb_m2s_dbg_sel),
  251.     .wb_we_o    (wb_m2s_dbg_we),
  252.     .wb_cti_o   (wb_m2s_dbg_cti),
  253.     .wb_bte_o   (wb_m2s_dbg_bte)
  254. );
  255.  
  256.  
  257. ////////////////////////////////////////////////////////////////////////
  258. //
  259. // ram_wb0
  260. //
  261. ////////////////////////////////////////////////////////////////////////
  262.  
  263. /* Lighweight arbiter between instruction and data busses going
  264.     into the cellram controller */
  265. reg [9:0] cellram_arb_timeout;
  266. wire cellram_arb_reset;
  267.  
  268. always @(posedge wb_clk)
  269.  if (wb_rst)
  270.    cellram_arb_timeout <= 0;
  271.  else if (wb_s2m_mem_ack)
  272.    cellram_arb_timeout <= 0;
  273.  else if (wb_m2s_mem_stb & wb_m2s_mem_cyc)
  274.    cellram_arb_timeout <= cellram_arb_timeout + 1;
  275.  
  276. reg [3:0] cellram_rst_counter;
  277. always @(posedge wb_clk or posedge wb_rst)
  278.  if (wb_rst)
  279.    cellram_rst_counter <= 4'hf;
  280.  else if (|cellram_rst_counter)
  281.    cellram_rst_counter <= cellram_rst_counter - 1;
  282.  
  283. assign cellram_arb_reset = (&cellram_arb_timeout);
  284.  
  285. cellram_ctrl
  286.  /* Use the simple flash interface */
  287.  #(
  288.    .cellram_read_cycles(7), // 70ns in cycles, at 100MHz = 7 (70 ns)
  289.    .cellram_write_cycles(7)) // 70ns in cycles, at 100Mhz = 7 (70 ns)
  290.  cellram_ctrl0
  291.  (
  292.   .wb_clk_i(wb_clk),
  293.   .wb_rst_i(wb_rst | cellram_arb_reset),
  294.  
  295.   .wb_adr_i(wb_m2s_mem_adr),
  296.   .wb_dat_i(wb_m2s_mem_dat),
  297.   .wb_stb_i(wb_m2s_mem_stb & !(|cellram_rst_counter)),
  298.   .wb_cyc_i(wb_m2s_mem_cyc),
  299.   .wb_we_i (wb_m2s_mem_we ),
  300.   .wb_sel_i(wb_m2s_mem_sel),
  301.   .wb_dat_o(wb_s2m_mem_dat),
  302.   .wb_ack_o(wb_s2m_mem_ack),
  303.   .wb_err_o(wb_s2m_mem_err & cellram_arb_reset),
  304.   .wb_rty_o(wb_s2m_mem_rty),
  305.  
  306.   .cellram_dq_io(cellram_data_io),
  307.   .cellram_adr_o(cellram_adr_o),
  308.   .cellram_adv_n_o(cellram_adv_n_o),
  309.   .cellram_ce_n_o(cellram_ce_n_o),
  310.   .cellram_clk_o(cellram_clk_o),
  311.   .cellram_oe_n_o(cellram_oe_n_o),
  312.   .cellram_rst_n_o(),
  313.   .cellram_wait_i(cellram_wait_i),
  314.   .cellram_we_n_o(cellram_we_n_o),
  315.   .cellram_wp_n_o(),
  316.   .cellram_lb_n_o(cellram_lb_n_o),
  317.   .cellram_ub_n_o(cellram_ub_n_o),
  318.   .cellram_cre_o(cellram_cre_o)
  319.   );
  320.  
  321. ////////////////////////////////////////////////////////////////////////
  322. //
  323. // UART0
  324. //
  325. ////////////////////////////////////////////////////////////////////////
  326.  
  327. wire    uart0_irq;
  328.  
  329. uart_top uart16550_0 (
  330. // Wishbone slave interface
  331. .wb_clk_i   (wb_clk),
  332. .wb_rst_i   (wb_rst),
  333. .wb_adr_i   (wb_m2s_uart0_adr[uart0_aw-1:0]),
  334. .wb_dat_i   (wb_m2s_uart0_dat),
  335. .wb_we_i    (wb_m2s_uart0_we),
  336. .wb_stb_i   (wb_m2s_uart0_stb),
  337. .wb_cyc_i   (wb_m2s_uart0_cyc),
  338. .wb_sel_i   (4'b0), // Not used in 8-bit mode
  339. .wb_dat_o   (wb_s2m_uart0_dat),
  340. .wb_ack_o   (wb_s2m_uart0_ack),
  341.  
  342. // Outputs
  343. .int_o  (uart0_irq),
  344. .stx_pad_o  (uart0_stx_pad_o),
  345. .rts_pad_o  (),
  346. .dtr_pad_o  (),
  347.  
  348. // Inputs
  349. .srx_pad_i  (uart0_srx_pad_i),
  350. .cts_pad_i  (1'b0),
  351. .dsr_pad_i  (1'b0),
  352. .ri_pad_i   (1'b0),
  353. .dcd_pad_i  (1'b0)
  354. );
  355.  
  356. ////////////////////////////////////////////////////////////////////////
  357. //
  358. // GPIO 0
  359. //
  360. ////////////////////////////////////////////////////////////////////////
  361.  
  362. wire [7:0]  gpio0_in;
  363. wire [7:0]  gpio0_out;
  364. wire [7:0]  gpio0_dir;
  365.  
  366. // Tristate logic for IO
  367. // 0 = input, 1 = output
  368. genvar i;
  369. generate
  370. for (i = 0; i < 8; i = i+1) begin: gpio0_tris
  371. assign gpio0_io[i] = gpio0_dir[i] ? gpio0_out[i] : 1'bz;
  372. assign gpio0_in[i] = gpio0_dir[i] ? gpio0_out[i] : gpio0_io[i];
  373. end
  374. endgenerate
  375.  
  376. gpio gpio0 (
  377. // GPIO bus
  378. .gpio_i (gpio0_in),
  379. .gpio_o (gpio0_out),
  380. .gpio_dir_o (gpio0_dir),
  381. // Wishbone slave interface
  382. .wb_adr_i   (wb_m2s_gpio0_adr[0]),
  383. .wb_dat_i   (wb_m2s_gpio0_dat),
  384. .wb_we_i    (wb_m2s_gpio0_we),
  385. .wb_cyc_i   (wb_m2s_gpio0_cyc),
  386. .wb_stb_i   (wb_m2s_gpio0_stb),
  387. .wb_cti_i   (wb_m2s_gpio0_cti),
  388. .wb_bte_i   (wb_m2s_gpio0_bte),
  389. .wb_dat_o   (wb_s2m_gpio0_dat),
  390. .wb_ack_o   (wb_s2m_gpio0_ack),
  391. .wb_err_o   (wb_s2m_gpio0_err),
  392. .wb_rty_o   (wb_s2m_gpio0_rty),
  393.  
  394. .wb_clk (wb_clk),
  395. .wb_rst (wb_rst)
  396. );
  397.  
  398. ////////////////////////////////////////////////////////////////////////
  399. //
  400. // Interrupt assignment
  401. //
  402. ////////////////////////////////////////////////////////////////////////
  403.  
  404. assign or1k_irq[0] = 0; // Non-maskable inside OR1K
  405. assign or1k_irq[1] = 0; // Non-maskable inside OR1K
  406. assign or1k_irq[2] = uart0_irq;
  407. assign or1k_irq[3] = 0;
  408. assign or1k_irq[4] = 0;
  409. assign or1k_irq[5] = 0;
  410. assign or1k_irq[6] = 0;
  411. assign or1k_irq[7] = 0;
  412. assign or1k_irq[8] = 0;
  413. assign or1k_irq[9] = 0;
  414. assign or1k_irq[10] = 0;
  415. assign or1k_irq[11] = 0;
  416. assign or1k_irq[12] = 0;
  417. assign or1k_irq[13] = 0;
  418. assign or1k_irq[14] = 0;
  419. assign or1k_irq[15] = 0;
  420. assign or1k_irq[16] = 0;
  421. assign or1k_irq[17] = 0;
  422. assign or1k_irq[18] = 0;
  423. assign or1k_irq[19] = 0;
  424. assign or1k_irq[20] = 0;
  425. assign or1k_irq[21] = 0;
  426. assign or1k_irq[22] = 0;
  427. assign or1k_irq[23] = 0;
  428. assign or1k_irq[24] = 0;
  429. assign or1k_irq[25] = 0;
  430. assign or1k_irq[26] = 0;
  431. assign or1k_irq[27] = 0;
  432. assign or1k_irq[28] = 0;
  433. assign or1k_irq[29] = 0;
  434. assign or1k_irq[30] = 0;
  435. assign or1k_irq[31] = 0;
  436.  
  437. endmodule // orpsoc_top
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement