1 /* ****************************************************************************
\r
2 -- Source file: mesa_core.v
\r
3 -- Date: October 4, 2015
\r
5 -- Description: Wrapper around a bunch of Mesa Bus Modules. This takes in the
\r
6 -- binary nibble stream from mesa_phy and takes care of slot
\r
7 -- enumeration and subslot bus decoding to local-bus.
\r
8 -- SubSlot-0 is 32bit user localbus.
\r
9 -- SubSlot-E is 32bit SPI PROM Interface localbus.
\r
10 -- SubSlot-F is power management,etc.
\r
11 -- Language: Verilog-2001 and VHDL-1993
\r
12 -- Simulation: Mentor-Modelsim
\r
13 -- Synthesis: Xilinst-XST
\r
14 -- License: This project is licensed with the CERN Open Hardware Licence
\r
15 -- v1.2. You may redistribute and modify this project under the
\r
16 -- terms of the CERN OHL v.1.2. (http://ohwr.org/cernohl).
\r
17 -- This project is distributed WITHOUT ANY EXPRESS OR IMPLIED
\r
18 -- WARRANTY, INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY
\r
19 -- AND FITNESS FOR A PARTICULAR PURPOSE. Please see the CERN OHL
\r
20 -- v.1.2 for applicable Conditions.
\r
22 -- Revision History:
\r
23 -- Ver# When Who What
\r
24 -- ---- -------- -------- ---------------------------------------------------
\r
25 -- 0.1 10.04.15 khubbard Creation
\r
26 -- ***************************************************************************/
\r
27 `default_nettype none // Strictly enforce all nets to be declared
\r
31 parameter spi_prom_en = 1
\r
38 output wire [31:0] lb_addr,
\r
39 output wire [31:0] lb_wr_d,
\r
40 input wire [31:0] lb_rd_d,
\r
41 input wire lb_rd_rdy,
\r
43 output wire spi_sck,
\r
44 output wire spi_cs_l,
\r
45 output wire spi_mosi,
\r
46 input wire spi_miso,
\r
47 input wire [3:0] rx_in_d,
\r
48 input wire rx_in_rdy,
\r
49 output reg [7:0] tx_byte_d,
\r
50 output reg tx_byte_rdy,
\r
53 output wire [7:0] tx_wo_byte,
\r
54 output wire tx_wo_rdy,
\r
56 input wire oob_done,
\r
58 output wire [8:0] subslot_ctrl,
\r
59 output wire reconfig_req,
\r
60 output wire [31:0] reconfig_addr,
\r
61 output wire bist_req
\r
62 );// module mesa_core
\r
67 wire [7:0] rx_loc_d;
\r
69 wire [7:0] tx_spi_byte_d;
\r
70 wire tx_spi_byte_rdy;
\r
72 wire [7:0] tx_lb_byte_d;
\r
73 wire tx_lb_byte_rdy;
\r
76 reg [3:0] tx_busy_sr;
\r
80 wire [31:0] prom_addr;
\r
81 wire [31:0] prom_wr_d;
\r
82 wire [31:0] prom_rd_d;
\r
87 wire [31:0] slot_size;
\r
88 wire [31:0] time_stamp_d;
\r
91 //-----------------------------------------------------------------------------
\r
92 // Decode the 2 PROM Addresses at 0x20 and 0x24 using combo logic
\r
93 //-----------------------------------------------------------------------------
\r
94 always @ ( * ) begin : proc_prom_decode
\r
96 if ( prom_addr[15:0] == 16'h0020 ) begin
\r
97 prom_cs_c <= prom_wr | prom_rd;
\r
101 if ( prom_addr[15:0] == 16'h0024 ) begin
\r
102 prom_cs_d <= prom_wr | prom_rd;
\r
107 end // proc_prom_decode
\r
110 // ----------------------------------------------------------------------------
\r
111 // Ro Mux : Mux between multiple byte sources for Ro readback path.
\r
112 // Note: There is no arbitration - 1st come 1st service requires that only
\r
113 // one device will send readback data ( polled requests ).
\r
114 // ----------------------------------------------------------------------------
\r
115 always @ ( posedge clk ) begin : proc_tx
\r
116 tx_busy_sr[0] <= tx_lb_byte_rdy | tx_spi_byte_rdy | tx_busy;
\r
117 tx_busy_sr[3:1] <= tx_busy_sr[2:0];
\r
118 tx_byte_rdy <= tx_lb_byte_rdy | tx_spi_byte_rdy;
\r
119 tx_done <= tx_lb_done | tx_spi_done | oob_done;// Sends LF
\r
121 if ( tx_lb_byte_rdy == 1 ) begin
\r
122 tx_byte_d <= tx_lb_byte_d[7:0];
\r
124 tx_byte_d <= tx_spi_byte_d[7:0];
\r
127 // Support pipeling Ro byte path by asserting busy for 4 clocks after a byte
\r
128 assign tx_busy_loc = ( tx_busy_sr != 4'b0000 ) ? 1 : 0;
\r
131 //-----------------------------------------------------------------------------
\r
132 // Decode Slot Addresses : Take in the Wi path as nibbles and generate the Wo
\r
133 // paths for both internal and external devices.
\r
134 //-----------------------------------------------------------------------------
\r
135 mesa_decode u_mesa_decode
\r
139 .rx_in_d ( rx_in_d[3:0] ),
\r
140 .rx_in_rdy ( rx_in_rdy ),
\r
141 .rx_out_d ( tx_wo_byte[7:0] ),
\r
142 .rx_out_rdy ( tx_wo_rdy ),
\r
143 .rx_loc_d ( rx_loc_d[7:0] ),
\r
144 .rx_loc_rdy ( rx_loc_rdy ),
\r
145 .rx_loc_start ( rx_loc_start ),
\r
146 .rx_loc_stop ( rx_loc_stop )
\r
150 //-----------------------------------------------------------------------------
\r
151 // Convert Subslots 0x0 and 0xE to 32bit local bus for user logic and prom
\r
152 //-----------------------------------------------------------------------------
\r
157 .rx_byte_d ( rx_loc_d[7:0] ),
\r
158 .rx_byte_rdy ( rx_loc_rdy ),
\r
159 .rx_byte_start ( rx_loc_start ),
\r
160 .rx_byte_stop ( rx_loc_stop ),
\r
161 .tx_byte_d ( tx_lb_byte_d[7:0] ),
\r
162 .tx_byte_rdy ( tx_lb_byte_rdy ),
\r
163 .tx_done ( tx_lb_done ),
\r
164 .tx_busy ( tx_busy_loc ),
\r
167 .lb_wr_d ( lb_wr_d[31:0] ),
\r
168 .lb_addr ( lb_addr[31:0] ),
\r
169 .lb_rd_d ( lb_rd_d[31:0] ),
\r
170 .lb_rd_rdy ( lb_rd_rdy ),
\r
171 .oob_en ( oob_en ),
\r
172 .oob_rd_d ( lb_rd_d[31:0] ),
\r
173 .oob_rd_rdy ( lb_rd_rdy ),
\r
174 .prom_wr ( prom_wr ),
\r
175 .prom_rd ( prom_rd ),
\r
176 .prom_wr_d ( prom_wr_d[31:0] ),
\r
177 .prom_addr ( prom_addr[31:0] ),
\r
178 .prom_rd_d ( prom_rd_d[31:0] ),
\r
179 .prom_rd_rdy ( prom_rd_rdy )
\r
183 //-----------------------------------------------------------------------------
\r
184 // Convert Subslots 0x1 to SPI
\r
185 // Use spi_ck_div of 0x7 for div-8 of 24 MHz to 3 MHz for SPI of 1.5 MHz.
\r
186 //-----------------------------------------------------------------------------
\r
187 //mesa2spi u_mesa2spi
\r
190 // .reset ( reset ),
\r
191 // .subslot ( 4'd1 ),
\r
192 // .spi_ck_div ( 4'd7 ),
\r
193 // .rx_byte_d ( rx_loc_d[7:0] ),
\r
194 // .rx_byte_rdy ( rx_loc_rdy ),
\r
195 // .rx_byte_start ( rx_loc_start ),
\r
196 // .rx_byte_stop ( rx_loc_stop ),
\r
198 // .tx_byte_d ( tx_spi_byte_d[7:0] ),
\r
199 // .tx_byte_rdy ( tx_spi_byte_rdy ),
\r
200 // .tx_done ( tx_spi_done ),
\r
201 // .tx_busy ( tx_busy_loc ),
\r
207 assign tx_spi_byte_d[7:0] = 8'd0;
\r
208 assign tx_spi_byte_rdy = 1'b0;
\r
209 assign tx_spi_done = 1'b0;
\r
212 //-----------------------------------------------------------------------------
\r
213 // Decode Subslot Nibble Controls
\r
214 //-----------------------------------------------------------------------------
\r
215 mesa2ctrl u_mesa2ctrl
\r
219 .rx_byte_d ( rx_loc_d[7:0] ),
\r
220 .rx_byte_rdy ( rx_loc_rdy ),
\r
221 .rx_byte_start ( rx_loc_start ),
\r
222 .rx_byte_stop ( rx_loc_stop ),
\r
223 .subslot_ctrl ( subslot_ctrl[8:0] )
\r
227 //-----------------------------------------------------------------------------
\r
228 // 32bit UNIX TimeStamp of when the design was synthesized
\r
229 //-----------------------------------------------------------------------------
\r
230 time_stamp u_time_stamp
\r
232 .time_dout ( time_stamp_d )
\r
236 //-----------------------------------------------------------------------------
\r
237 // Interface to SPI PROM : Allow LB to program SPI PROM, request reconfig
\r
238 // ck_divisor 10 is for ( 80M / 10 ) for 2x SPI Clock Rate of 4 MHz
\r
239 // ck_divisor 3 is for ( 24M / 3 ) for 2x SPI Clock Rate of 4 MHz
\r
241 // slot_size 0x00020000 is 1Mbit Slot for ICE5LP4K
\r
242 // slot_size 0x00040000 is 2Mbit Slot for XC3S200A (Compressed, no BRAM ROMs)
\r
243 // slot_size 0x00080000 is 4Mbit Slot for XC6SLX9 (Compressed, no BRAM ROMs)
\r
244 //-----------------------------------------------------------------------------
\r
246 if ( spi_prom_en == 1 ) begin
\r
247 spi_prom u_spi_prom
\r
250 .prom_is_32b ( 1'b0 ),
\r
251 .ck_divisor ( 8'd3 ),
\r
252 .slot_size ( slot_size[31:0] ),
\r
253 .protect_1st_slot ( 1'b1 ),
\r
256 .lb_cs_prom_c ( prom_cs_c ),
\r
257 .lb_cs_prom_d ( prom_cs_d ),
\r
258 .lb_wr ( prom_wr ),
\r
259 .lb_rd ( prom_rd ),
\r
260 .lb_wr_d ( prom_wr_d[31:0] ),
\r
261 .lb_rd_d ( prom_rd_d[31:0] ),
\r
262 .lb_rd_rdy ( prom_rd_rdy ),
\r
264 .spi_ctrl ( 4'b0000 ),
\r
265 .spi_sck ( spi_sck ),
\r
266 .spi_cs_l ( spi_cs_l ),
\r
267 .spi_mosi ( spi_mosi ),
\r
268 .spi_miso ( spi_miso ),
\r
271 .bist_req ( bist_req ),
\r
272 .reconfig_2nd_slot ( 1'b0 ),
\r
273 .reconfig_req ( reconfig_req ),
\r
274 .reconfig_addr ( reconfig_addr[31:0] )
\r
277 assign spi_sck = 1;
\r
278 assign spi_cs_l = 1;
\r
279 assign spi_mosi = 1;
\r
280 assign bist_req = 0;
\r
281 assign reconfig_req = 0;
\r
282 assign reconfig_addr = 32'd0;
\r
283 assign prom_rd_d = 32'd0;
\r
284 assign prom_rd_rdy = 0;
\r
287 assign slot_size = 32'h00020000;
\r
290 endmodule // mesa_core
\r