|
| 1 | +// Copyright 2024 ETH Zurich and University of Bologna. |
| 2 | +// Solderpad Hardware License, Version 0.51, see LICENSE for details. |
| 3 | +// SPDX-License-Identifier: SHL-0.51 |
| 4 | +// |
| 5 | +// Nicole Narr <narrn@student.ethz.ch> |
| 6 | +// Christopher Reinwardt <creinwar@student.ethz.ch> |
| 7 | +// Cyril Koenig <cykoenig@iis.ee.ethz.ch> |
| 8 | +// Yann Picod <ypicod@ethz.ch> |
| 9 | +// Paul Scheffler <paulsc@iis.ee.ethz.ch> |
| 10 | +// Philippe Sauter <phsauter@iis.ee.ethz.ch> |
| 11 | + |
| 12 | +`ifdef TARGET_GENESYS2 |
| 13 | + `define USE_RESETN |
| 14 | + `define USE_JTAG_TRSTN |
| 15 | + `define USE_STATUS |
| 16 | + `define USE_SWITCHES |
| 17 | + `define USE_LEDS |
| 18 | + `define USE_FAN |
| 19 | + `define USE_VIO |
| 20 | +`endif |
| 21 | + |
| 22 | +`define ila(__name, __signal) \ |
| 23 | + (* dont_touch = "yes" *) (* mark_debug = "true" *) logic [$bits(__signal)-1:0] __name; \ |
| 24 | + assign __name = __signal; |
| 25 | + |
| 26 | +module croc_xilinx import croc_pkg::*; #( |
| 27 | + localparam int unsigned GpioCount = 4 |
| 28 | +) ( |
| 29 | + input logic sys_clk_p, |
| 30 | + input logic sys_clk_n, |
| 31 | + |
| 32 | +`ifdef USE_RESET |
| 33 | + input logic sys_reset, |
| 34 | +`endif |
| 35 | +`ifdef USE_RESETN |
| 36 | + input logic sys_resetn, |
| 37 | +`endif |
| 38 | + |
| 39 | +`ifdef USE_SWITCHES |
| 40 | + input logic fetch_en_i, // switch 7 |
| 41 | + input logic [GpioCount-1:0] gpio_i, // switch 0-3 |
| 42 | +`endif |
| 43 | + |
| 44 | +`ifdef USE_LEDS |
| 45 | + output logic [GpioCount-1:0] gpio_o, |
| 46 | +`endif |
| 47 | + |
| 48 | +`ifdef USE_STATUS |
| 49 | + output logic status_o, |
| 50 | +`endif |
| 51 | + |
| 52 | + input logic jtag_tck_i, |
| 53 | + input logic jtag_tms_i, |
| 54 | + input logic jtag_tdi_i, |
| 55 | + output logic jtag_tdo_o, |
| 56 | +`ifdef USE_JTAG_TRSTN |
| 57 | + input logic jtag_trst_ni, |
| 58 | +`endif |
| 59 | +`ifdef USE_JTAG_VDDGND |
| 60 | + output logic jtag_vdd_o, |
| 61 | + output logic jtag_gnd_o, |
| 62 | +`endif |
| 63 | + |
| 64 | +`ifdef USE_FAN |
| 65 | + input logic [2:0] fan_sw, // switch 4-6 |
| 66 | + output logic fan_pwm, |
| 67 | +`endif |
| 68 | + |
| 69 | + output logic uart_tx_o, |
| 70 | + input logic uart_rx_i |
| 71 | +); |
| 72 | + |
| 73 | + //////////////////////// |
| 74 | + // Clock Generation // |
| 75 | + //////////////////////// |
| 76 | + |
| 77 | + wire sys_clk; |
| 78 | + wire soc_clk; |
| 79 | + |
| 80 | + IBUFDS #( |
| 81 | + .IBUF_LOW_PWR ("FALSE") |
| 82 | + ) i_bufds_sys_clk ( |
| 83 | + .I ( sys_clk_p ), |
| 84 | + .IB ( sys_clk_n ), |
| 85 | + .O ( sys_clk ) |
| 86 | + ); |
| 87 | + |
| 88 | + clkwiz i_clkwiz ( |
| 89 | + .clk_in1 ( sys_clk ), |
| 90 | + .reset ( '0 ), |
| 91 | + .locked ( ), |
| 92 | + .clk_20 ( soc_clk ) |
| 93 | + ); |
| 94 | + |
| 95 | + ///////////////////// |
| 96 | + // System Inputs // |
| 97 | + ///////////////////// |
| 98 | + |
| 99 | + // Select SoC reset |
| 100 | +`ifdef USE_RESET |
| 101 | + logic sys_resetn; |
| 102 | + assign sys_resetn = ~sys_reset; |
| 103 | +`elsif USE_RESETN |
| 104 | + logic sys_reset; |
| 105 | + assign sys_reset = ~sys_resetn; |
| 106 | +`endif |
| 107 | + |
| 108 | + // Tie off inputs of no switches |
| 109 | +`ifndef USE_SWITCHES |
| 110 | + logic fetch_en_i; |
| 111 | + logic [GpioCount-2:0] gpio_i; |
| 112 | + assign test_mode_i = '0; |
| 113 | + assign fetch_en_i = '0; |
| 114 | + assign gpio_i = '0; |
| 115 | +`endif |
| 116 | + |
| 117 | +`ifndef USE_STATUS |
| 118 | + logic status_o; |
| 119 | +`endif |
| 120 | + |
| 121 | +`ifndef USE_LEDS |
| 122 | + logic [GpioCount-1:0] gpio_o; |
| 123 | +`endif |
| 124 | + |
| 125 | + //////////// |
| 126 | + // VIOs // |
| 127 | + //////////// |
| 128 | + logic vio_reset, vio_fetch_en, vio_gpio; |
| 129 | + |
| 130 | +`ifdef USE_VIO |
| 131 | + vio i_vio ( |
| 132 | + .clk ( soc_clk ), |
| 133 | + .probe_out0 ( vio_reset ), |
| 134 | + .probe_out1 ( vio_fetch_en ), |
| 135 | + .probe_out2 ( vio_gpio ) |
| 136 | + ); |
| 137 | +`else |
| 138 | + assign vio_reset = '0; |
| 139 | + assign vio_fetch_en = '0; |
| 140 | + assign vio_gpio = '0; |
| 141 | +`endif |
| 142 | + |
| 143 | + |
| 144 | + ////////////// |
| 145 | + // SOC IO // |
| 146 | + ////////////// |
| 147 | + |
| 148 | + logic soc_fetch_en; |
| 149 | + logic soc_rst_n; |
| 150 | + |
| 151 | + assign soc_fetch_en = fetch_en_i | vio_fetch_en; |
| 152 | + assign soc_rst = ~sys_resetn | vio_reset; |
| 153 | + |
| 154 | + logic [GpioCount-1:0] soc_gpio_i; |
| 155 | + logic [GpioCount-1:0] soc_gpio_o; |
| 156 | + logic [GpioCount-1:0] soc_gpio_out_en_o; |
| 157 | + |
| 158 | + for(genvar idx=0; idx<GpioCount; idx++) begin |
| 159 | + assign gpio_o[idx] = soc_gpio_out_en_o[idx] ? soc_gpio_o[idx] : '0; |
| 160 | + |
| 161 | + if(idx == 0) begin |
| 162 | + assign soc_gpio_i[idx] = ~soc_gpio_out_en_o[idx] ? vio_gpio | gpio_i[0] : '0; |
| 163 | + end else begin |
| 164 | + assign soc_gpio_i[idx] = ~soc_gpio_out_en_o[idx] ? gpio_i[idx] : '0; |
| 165 | + end |
| 166 | + end |
| 167 | + |
| 168 | + |
| 169 | + ////////////////// |
| 170 | + // Reset Sync // |
| 171 | + ////////////////// |
| 172 | + |
| 173 | + wire rst_n; |
| 174 | + |
| 175 | + rstgen i_rstgen ( |
| 176 | + .clk_i ( soc_clk ), |
| 177 | + .rst_ni ( ~soc_rst ), |
| 178 | + .test_mode_i ( '0 ), |
| 179 | + .rst_no ( rst_n ), |
| 180 | + .init_no ( ) |
| 181 | + ); |
| 182 | + |
| 183 | + //////////// |
| 184 | + // JTAG // |
| 185 | + //////////// |
| 186 | + |
| 187 | +`ifdef USE_JTAG_VDDGND |
| 188 | + assign jtag_vdd_o = 1'b1; |
| 189 | + assign jtag_gnd_o = 1'b0; |
| 190 | +`endif |
| 191 | +`ifndef USE_JTAG_TRSTN |
| 192 | + logic jtag_trst_ni; |
| 193 | + assign jtag_trst_ni = 1'b1; |
| 194 | +`endif |
| 195 | + |
| 196 | + |
| 197 | + ///////////////////////// |
| 198 | + // "RTC" Clock Divider // |
| 199 | + ///////////////////////// |
| 200 | + |
| 201 | + logic rtc_clk_d, rtc_clk_q; |
| 202 | + logic [15:0] counter_d, counter_q; |
| 203 | + |
| 204 | + // Divide soc_clk (20 MHz) by 610 => ~32.768kHz RTC Clock |
| 205 | + // TODO: does genesys 2 have a 32.768kHz reference clock? |
| 206 | + always_comb begin |
| 207 | + counter_d = counter_q + 1; |
| 208 | + rtc_clk_d = rtc_clk_q; |
| 209 | + |
| 210 | + if(counter_q == 610) begin |
| 211 | + counter_d = '0; |
| 212 | + rtc_clk_d = ~rtc_clk_q; |
| 213 | + end |
| 214 | + end |
| 215 | + |
| 216 | + always_ff @(posedge soc_clk, negedge rst_n) begin |
| 217 | + if(~rst_n) begin |
| 218 | + counter_q <= '0; |
| 219 | + rtc_clk_q <= 0; |
| 220 | + end else begin |
| 221 | + counter_q <= counter_d; |
| 222 | + rtc_clk_q <= rtc_clk_d; |
| 223 | + end |
| 224 | + end |
| 225 | + |
| 226 | + ///////////////// |
| 227 | + // Fan Control // |
| 228 | + ///////////////// |
| 229 | + |
| 230 | +`ifdef USE_FAN |
| 231 | + fan_ctrl i_fan_ctrl ( |
| 232 | + .clk_i ( soc_clk ), |
| 233 | + .rst_ni ( rst_n ), |
| 234 | + .pwm_setting_i ( {'0, fan_sw} ), |
| 235 | + .fan_pwm_o ( fan_pwm ) |
| 236 | + ); |
| 237 | +`endif |
| 238 | + |
| 239 | + |
| 240 | + ////////////////// |
| 241 | + // Cheshire SoC // |
| 242 | + ////////////////// |
| 243 | + logic soc_testmode_i; |
| 244 | + assign soc_testmode_i = '0; |
| 245 | + |
| 246 | + croc_soc #( |
| 247 | + .GpioCount( GpioCount ) |
| 248 | + ) |
| 249 | + i_croc_soc ( |
| 250 | + .clk_i ( soc_clk ), |
| 251 | + .rst_ni ( rst_n ), |
| 252 | + .ref_clk_i ( rtc_clk_q ), |
| 253 | + .testmode_i ( soc_testmode_i ), |
| 254 | + .fetch_en_i ( soc_fetch_en ), |
| 255 | + .status_o ( status_o ), |
| 256 | + |
| 257 | + .jtag_tck_i ( jtag_tck_i ), |
| 258 | + .jtag_tdi_i ( jtag_tdi_i ), |
| 259 | + .jtag_tdo_o ( jtag_tdo_o ), |
| 260 | + .jtag_tms_i ( jtag_tms_i ), |
| 261 | + .jtag_trst_ni ( jtag_trst_ni ), |
| 262 | + |
| 263 | + .uart_rx_i ( uart_rx_i ), |
| 264 | + .uart_tx_o ( uart_tx_o ), |
| 265 | + |
| 266 | + .gpio_i ( soc_gpio_i ), |
| 267 | + .gpio_o ( soc_gpio_o ), |
| 268 | + .gpio_out_en_o ( soc_gpio_out_en_o ) |
| 269 | + ); |
| 270 | + |
| 271 | +endmodule |
0 commit comments