blob: 472c1ff258b5fca936da338a2c2921df79db042a [file] [log] [blame]
Sylvain Munautbd83e532020-09-15 22:11:29 +02001/*
2 * top.v
3 *
4 * vim: ts=4 sw=4
5 *
6 * Top-level for the icE1usb production boards
7 *
8 * Copyright (C) 2019-2020 Sylvain Munaut <tnt@246tNt.com>
9 * SPDX-License-Identifier: CERN-OHL-S-2.0
10 */
11
12`default_nettype none
13
Sylvain Munautd420ffc2020-10-09 13:25:51 +020014// `define WITH_SINGLE_CHANNEL
Sylvain Munaut0685edd2022-05-03 13:55:32 +020015// `define WITH_SB_I2C
16`define WITH_CUSTOM_I2C
Sylvain Munaut58531972020-10-03 20:52:43 +020017
Sylvain Munautbd83e532020-09-15 22:11:29 +020018module top (
19 // E1 PHY
20 input wire e1A_rx_hi_p,
21// input wire e1A_rx_hi_n,
22 input wire e1A_rx_lo_p,
23// input wire e1A_rx_lo_n,
24 output wire e1A_tx_hi,
25 output wire e1A_tx_lo,
26
27 input wire e1B_rx_hi_p,
28// input wire e1B_rx_hi_n,
29 input wire e1B_rx_lo_p,
30// input wire e1B_rx_lo_n,
31 output wire e1B_tx_hi,
32 output wire e1B_tx_lo,
33
34 output wire [1:0] e1_rx_bias,
35
36 // USB
37 inout wire usb_dp,
38 inout wire usb_dn,
39 output wire usb_pu,
40
41 // Flash
42 inout wire flash_mosi,
43 inout wire flash_miso,
44 inout wire flash_clk,
45 inout wire flash_cs_n,
46
47 // LED Shift register + Button input
48 inout wire e1_led_rclk,
49
50 // GPS
51 output wire gps_reset_n,
52 input wire gps_rx,
53 output wire gps_tx,
54 input wire gps_pps,
55
56 // I2C
57 inout wire i2c_sda,
58 inout wire i2c_scl,
59
60 // GPIOs
61 inout wire [2:0] gpio,
62
63 // Clock (30.72 MHz)
64 input wire clk_in,
65 output wire clk_tune_hi,
66 output wire clk_tune_lo,
67
68 // Debug UART
69 input wire dbg_rx,
70 output wire dbg_tx,
71
72 // RGB LEDs
73 output wire [2:0] rgb
74);
75
76 localparam integer WB_N = 3;
77
78 genvar i;
79
80
81 // Signals
82 // -------
83
84 // Flash SPI internal signals
85 wire flash_mosi_i, flash_miso_i, flash_clk_i;
86 wire flash_mosi_o, flash_miso_o, flash_clk_o;
87 wire flash_mosi_oe, flash_miso_oe, flash_clk_oe;
88 wire flash_csn_o;
89
90 // Peripheral wishbone
91 wire [15:0] wb_addr;
92 wire [31:0] wb_rdata [0:WB_N-1];
93 wire [31:0] wb_wdata;
94 wire [ 3:0] wb_wmsk;
95 wire wb_we;
96 wire [WB_N-1:0] wb_cyc;
97 wire [WB_N-1:0] wb_ack;
98
99 wire [(WB_N*32)-1:0] wb_rdata_flat;
100
101 // Ticks
Sylvain Munaut60f664f2024-04-29 16:14:54 +0200102 wire [7:0] tick_e1;
Sylvain Munautbd83e532020-09-15 22:11:29 +0200103 wire tick_usb_sof;
104
105 // I2C
106 wire i2c_scl_oe;
Sylvain Munaut921f4772022-05-03 13:38:51 +0200107 wire i2c_scl_i;
Sylvain Munautbd83e532020-09-15 22:11:29 +0200108 wire i2c_sda_oe;
109 wire i2c_sda_i;
110
111 // Led & Button
112 wire [7:0] e1_led_state;
113 wire e1_led_run;
114 wire e1_led_active;
115
116 wire spi_req;
117 wire spi_gnt;
118
119 wire [7:0] sr_val;
120 wire sr_go;
121 wire sr_rdy;
122
123 wire btn_val;
124 wire btn_stb;
125
126 // Clocks / Reset
127 wire rst_req;
128
129 wire clk_sys;
130 wire rst_sys;
131 wire clk_48m;
132 wire rst_48m;
133
134
135 // SoC base
136 // --------
137
138 // Instance
139 soc_base #(
140 .WB_N(WB_N),
141 .E1_N(2),
Sylvain Munautd420ffc2020-10-09 13:25:51 +0200142`ifdef WITH_SINGLE_CHANNEL
Sylvain Munautbd83e532020-09-15 22:11:29 +0200143 .E1_UNIT_HAS_RX(2'b01),
144 .E1_UNIT_HAS_TX(2'b01),
Sylvain Munautd420ffc2020-10-09 13:25:51 +0200145`else
146 .E1_UNIT_HAS_RX(2'b11),
147 .E1_UNIT_HAS_TX(2'b11),
148`endif
Sylvain Munautbd83e532020-09-15 22:11:29 +0200149 .E1_LIU(0)
150 ) soc_I (
151 .e1_rx_hi_p ({e1B_rx_hi_p, e1A_rx_hi_p}),
152// .e1_rx_hi_n ({e1B_rx_hi_n, e1A_rx_hi_n}),
153 .e1_rx_lo_p ({e1B_rx_lo_p, e1A_rx_lo_p}),
154// .e1_rx_lo_n ({e1B_rx_lo_n, e1A_rx_lo_n}),
155 .e1_tx_hi ({e1B_tx_hi, e1A_tx_hi }),
156 .e1_tx_lo ({e1B_tx_lo, e1A_tx_lo }),
157 .e1_rx_data (),
158 .e1_rx_clk (),
159 .e1_tx_data (),
160 .e1_tx_clk (),
161 .usb_dp (usb_dp),
162 .usb_dn (usb_dn),
163 .usb_pu (usb_pu),
164 .flash_mosi_i (flash_mosi_i),
165 .flash_mosi_o (flash_mosi_o),
166 .flash_mosi_oe(flash_mosi_oe),
167 .flash_miso_i (flash_miso_i),
168 .flash_miso_o (flash_miso_o),
169 .flash_miso_oe(flash_miso_oe),
170 .flash_clk_i (flash_clk_i),
171 .flash_clk_o (flash_clk_o),
172 .flash_clk_oe (flash_clk_oe),
173 .flash_csn_o (flash_csn_o),
174 .dbg_rx (dbg_rx),
175 .dbg_tx (dbg_tx),
176 .rgb (rgb),
177 .wb_m_addr (wb_addr),
178 .wb_m_rdata (wb_rdata_flat),
179 .wb_m_wdata (wb_wdata),
180 .wb_m_wmsk (wb_wmsk),
181 .wb_m_we (wb_we),
182 .wb_m_cyc (wb_cyc),
183 .wb_m_ack (wb_ack),
Sylvain Munaut60f664f2024-04-29 16:14:54 +0200184 .tick_e1 (tick_e1),
Sylvain Munautbd83e532020-09-15 22:11:29 +0200185 .tick_usb_sof (tick_usb_sof),
186 .clk_sys (clk_sys),
187 .rst_sys (rst_sys),
188 .clk_48m (clk_48m),
189 .rst_48m (rst_48m)
190 );
191
192 // WB read data flattening
193 for (i=0; i<WB_N; i=i+1)
194 assign wb_rdata_flat[i*32+:32] = wb_rdata[i];
195
196
197 // Dummy channel
198 // -------------
199
Sylvain Munautd420ffc2020-10-09 13:25:51 +0200200`ifdef WITH_SINGLE_CHANNEL
Sylvain Munautbd83e532020-09-15 22:11:29 +0200201 wire [1:0] e1_dummy;
202
203 SB_IO #(
204 .PIN_TYPE(6'b000000),
205 .PULLUP(1'b0),
206 .NEG_TRIGGER(1'b0),
207 .IO_STANDARD("SB_LVDS_INPUT")
208 ) e1_dummy_rx_I[1:0] (
209 .PACKAGE_PIN({e1B_rx_hi_p, e1B_rx_lo_p}),
210 .LATCH_INPUT_VALUE(1'b0),
211 .CLOCK_ENABLE(1'b1),
212 .INPUT_CLK(clk_sys),
213 .OUTPUT_CLK(1'b0),
214 .OUTPUT_ENABLE(1'b0),
215 .D_OUT_0(1'b0),
216 .D_OUT_1(1'b0),
217 .D_IN_0(e1_dummy),
218 .D_IN_1()
219 );
220
221 SB_IO #(
222 .PIN_TYPE(6'b010100),
223 .PULLUP(1'b0),
224 .NEG_TRIGGER(1'b0),
225 .IO_STANDARD("SB_LVCMOS")
226 ) e1_dummy_tx_I[1:0] (
227 .PACKAGE_PIN({e1B_tx_hi, e1B_tx_lo}),
228 .LATCH_INPUT_VALUE(1'b0),
229 .CLOCK_ENABLE(1'b1),
230 .INPUT_CLK(1'b0),
231 .OUTPUT_CLK(clk_sys),
232 .OUTPUT_ENABLE(1'b0),
233 .D_OUT_0(e1_dummy),
234 .D_OUT_1(1'b0),
235 .D_IN_0(),
236 .D_IN_1()
237 );
Sylvain Munautd420ffc2020-10-09 13:25:51 +0200238`endif
Sylvain Munautbd83e532020-09-15 22:11:29 +0200239
240
241 // Misc [0]
242 // ----
243
244 misc misc_I (
245 .e1_rx_bias (e1_rx_bias),
246 .clk_tune_hi (clk_tune_hi),
247 .clk_tune_lo (clk_tune_lo),
248 .gps_reset_n (gps_reset_n),
249 .gps_pps (gps_pps),
250 .gpio (gpio),
251 .e1_led_state (e1_led_state),
252 .e1_led_run (e1_led_run),
253 .e1_led_active (e1_led_active),
254 .btn_val (btn_val),
255 .btn_stb (btn_stb),
Sylvain Munaut60f664f2024-04-29 16:14:54 +0200256 .tick_e1 (tick_e1),
Sylvain Munautbd83e532020-09-15 22:11:29 +0200257 .tick_usb_sof (tick_usb_sof),
258 .rst_req (rst_req),
259 .wb_addr (wb_addr[7:0]),
260 .wb_rdata (wb_rdata[0]),
261 .wb_wdata (wb_wdata),
262 .wb_we (wb_we),
263 .wb_cyc (wb_cyc[0]),
264 .wb_ack (wb_ack[0]),
265 .clk (clk_sys),
266 .rst (rst_sys)
267 );
268
269
270 // GPS UART [1]
271 // --------
272
273 uart_wb #(
274 .DIV_WIDTH(12),
275 .DW(32)
276 ) gps_uart_I (
277 .uart_tx (gps_tx),
278 .uart_rx (gps_rx),
279 .wb_addr (wb_addr[1:0]),
280 .wb_rdata (wb_rdata[1]),
281 .wb_wdata (wb_wdata),
282 .wb_we (wb_we),
283 .wb_cyc (wb_cyc[1]),
284 .wb_ack (wb_ack[1]),
285 .clk (clk_sys),
286 .rst (rst_sys)
287 );
288
289
290 // I2C [2]
291 // ---
292
Sylvain Munaut58531972020-10-03 20:52:43 +0200293`ifdef WITH_SB_I2C
294
295 // Hard-IP
296 ice40_i2c_wb #(
297 .WITH_IOB(1),
298 .UNIT(0)
299 ) i2c_I (
300 .i2c_scl (i2c_scl),
301 .i2c_sda (i2c_sda),
302 .wb_addr (wb_addr[3:0]),
303 .wb_rdata (wb_rdata[2]),
304 .wb_wdata (wb_wdata),
305 .wb_we (wb_we),
306 .wb_cyc (wb_cyc[2]),
307 .wb_ack (wb_ack[2]),
308 .clk (clk_sys),
309 .rst (rst_sys)
310 );
311
312`elsif WITH_CUSTOM_I2C
313
Sylvain Munautbd83e532020-09-15 22:11:29 +0200314 // Controller
315 i2c_master_wb #(
Sylvain Munaut0c1684e2022-05-03 13:53:29 +0200316 .DW(4),
Sylvain Munautbd83e532020-09-15 22:11:29 +0200317 .FIFO_DEPTH(0)
318 ) i2c_I (
319 .scl_oe (i2c_scl_oe),
Sylvain Munaut921f4772022-05-03 13:38:51 +0200320 .scl_i (i2c_scl_i),
Sylvain Munautbd83e532020-09-15 22:11:29 +0200321 .sda_oe (i2c_sda_oe),
322 .sda_i (i2c_sda_i),
323 .wb_rdata(wb_rdata[2]),
324 .wb_wdata(wb_wdata),
325 .wb_we (wb_we),
326 .wb_cyc (wb_cyc[2]),
327 .wb_ack (wb_ack[2]),
Sylvain Munautbd83e532020-09-15 22:11:29 +0200328 .clk (clk_sys),
329 .rst (rst_sys)
330 );
331
332 // IOBs
333 SB_IO #(
Sylvain Munautbd83e532020-09-15 22:11:29 +0200334 .PIN_TYPE(6'b110100),
335 .PULLUP(1'b1),
336 .IO_STANDARD("SB_LVCMOS")
Sylvain Munaut921f4772022-05-03 13:38:51 +0200337 ) i2c_iob_I[1:0] (
338 .PACKAGE_PIN ({i2c_scl, i2c_sda}),
Sylvain Munautbd83e532020-09-15 22:11:29 +0200339 .INPUT_CLK (clk_sys),
340 .OUTPUT_CLK (clk_sys),
Sylvain Munaut921f4772022-05-03 13:38:51 +0200341 .OUTPUT_ENABLE({i2c_scl_oe, i2c_sda_oe}),
Sylvain Munautbd83e532020-09-15 22:11:29 +0200342 .D_OUT_0 (1'b0),
Sylvain Munaut921f4772022-05-03 13:38:51 +0200343 .D_IN_0 ({i2c_scl_i, i2c_sda_i})
Sylvain Munautbd83e532020-09-15 22:11:29 +0200344 );
345
Sylvain Munaut58531972020-10-03 20:52:43 +0200346`else
347
348 // Dummy
349 assign wb_ack[2] = wb_cyc[2];
350 assign wb_rdata[2] = 32'h00000000;
351
352`endif
353
Sylvain Munautbd83e532020-09-15 22:11:29 +0200354
355 // E1 LEDs & Button
356 // ----------------
357
358 // Blink pattern generator
359 led_blinker blinker_I (
360 .led_state(e1_led_state),
361 .sr_val (sr_val),
362 .sr_go (sr_go),
363 .sr_rdy (sr_rdy),
364 .clk (clk_sys),
365 .rst (rst_sys)
366 );
367
368 // Interface
369 sr_btn_if #(
370 .TICK_LOG2_DIV(3)
371 ) spi_mux_I (
372 .flash_mosi (flash_mosi),
373 .flash_miso (flash_miso),
374 .flash_clk (flash_clk),
375 .flash_cs_n (flash_cs_n),
376 .e1_led_rclk (e1_led_rclk),
377 .spi_mosi_i (flash_mosi_i),
378 .spi_mosi_o (flash_mosi_o),
379 .spi_mosi_oe (flash_mosi_oe),
380 .spi_miso_i (flash_miso_i),
381 .spi_miso_o (flash_miso_o),
382 .spi_miso_oe (flash_miso_oe),
383 .spi_clk_i (flash_clk_i),
384 .spi_clk_o (flash_clk_o),
385 .spi_clk_oe (flash_clk_oe),
386 .spi_csn_o (flash_csn_o),
387 .spi_csn_oe (1'b1),
388 .spi_req (spi_req),
389 .spi_gnt (spi_gnt),
390 .sr_val (sr_val),
391 .sr_go (sr_go),
392 .sr_rdy (sr_rdy),
393 .btn_val (btn_val),
394 .btn_stb (btn_stb),
395 .clk (clk_sys),
396 .rst (rst_sys)
397 );
398
399 assign spi_req = ~e1_led_run;
400 assign e1_led_active = ~spi_gnt;
401
402
403 // Clock / Reset
404 // -------------
405
406 sysmgr sys_mgr_I (
407 .clk_in (clk_in),
408 .rst_in (rst_req),
409 .clk_sys(clk_sys),
410 .rst_sys(rst_sys),
411 .clk_48m(clk_48m),
412 .rst_48m(rst_48m)
413 );
414
415endmodule // top