1 | //---------------------------------------------------------------------------- |
---|
2 | // user_logic.v - module |
---|
3 | //---------------------------------------------------------------------------- |
---|
4 | // |
---|
5 | // *************************************************************************** |
---|
6 | // ** Copyright (c) 1995-2012 Xilinx, Inc. All rights reserved. ** |
---|
7 | // ** ** |
---|
8 | // ** Xilinx, Inc. ** |
---|
9 | // ** XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" ** |
---|
10 | // ** AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND ** |
---|
11 | // ** SOLUTIONS FOR XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE, ** |
---|
12 | // ** OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, ** |
---|
13 | // ** APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION ** |
---|
14 | // ** THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT, ** |
---|
15 | // ** AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE ** |
---|
16 | // ** FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY ** |
---|
17 | // ** WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE ** |
---|
18 | // ** IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR ** |
---|
19 | // ** REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF ** |
---|
20 | // ** INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ** |
---|
21 | // ** FOR A PARTICULAR PURPOSE. ** |
---|
22 | // ** ** |
---|
23 | // *************************************************************************** |
---|
24 | // |
---|
25 | //---------------------------------------------------------------------------- |
---|
26 | // Filename: user_logic.v |
---|
27 | // Version: 1.00.a |
---|
28 | // Description: User logic module. |
---|
29 | // Date: Fri Nov 09 20:37:15 2012 (by Create and Import Peripheral Wizard) |
---|
30 | // Verilog Standard: Verilog-2001 |
---|
31 | //---------------------------------------------------------------------------- |
---|
32 | // Naming Conventions: |
---|
33 | // active low signals: "*_n" |
---|
34 | // clock signals: "clk", "clk_div#", "clk_#x" |
---|
35 | // reset signals: "rst", "rst_n" |
---|
36 | // generics: "C_*" |
---|
37 | // user defined types: "*_TYPE" |
---|
38 | // state machine next state: "*_ns" |
---|
39 | // state machine current state: "*_cs" |
---|
40 | // combinatorial signals: "*_com" |
---|
41 | // pipelined or register delay signals: "*_d#" |
---|
42 | // counter signals: "*cnt*" |
---|
43 | // clock enable signals: "*_ce" |
---|
44 | // internal version of output port: "*_i" |
---|
45 | // device pins: "*_pin" |
---|
46 | // ports: "- Names begin with Uppercase" |
---|
47 | // processes: "*_PROCESS" |
---|
48 | // component instantiations: "<ENTITY_>I_<#|FUNC>" |
---|
49 | //---------------------------------------------------------------------------- |
---|
50 | |
---|
51 | `uselib lib=unisims_ver |
---|
52 | `uselib lib=proc_common_v3_00_a |
---|
53 | |
---|
54 | module user_logic |
---|
55 | ( |
---|
56 | // -- ADD USER PORTS BELOW THIS LINE --------------- |
---|
57 | hexdisp_left, |
---|
58 | hexdisp_left_dp, |
---|
59 | hexdisp_right, |
---|
60 | hexdisp_right_dp, |
---|
61 | leds_red, |
---|
62 | leds_green, |
---|
63 | rfa_led_red, |
---|
64 | rfa_led_green, |
---|
65 | rfb_led_red, |
---|
66 | rfb_led_green, |
---|
67 | dipsw, |
---|
68 | pb_u, |
---|
69 | pb_m, |
---|
70 | pb_d, |
---|
71 | usr_hexdisp_left, |
---|
72 | usr_hexdisp_left_dp, |
---|
73 | usr_hexdisp_right, |
---|
74 | usr_hexdisp_right_dp, |
---|
75 | usr_leds_red, |
---|
76 | usr_leds_green, |
---|
77 | usr_rfa_led_red, |
---|
78 | usr_rfa_led_green, |
---|
79 | usr_rfb_led_red, |
---|
80 | usr_rfb_led_green, |
---|
81 | usr_dipsw, |
---|
82 | usr_pb_u, |
---|
83 | usr_pb_m, |
---|
84 | usr_pb_d, |
---|
85 | DNA_Port_Clk, |
---|
86 | // -- ADD USER PORTS ABOVE THIS LINE --------------- |
---|
87 | |
---|
88 | // -- DO NOT EDIT BELOW THIS LINE ------------------ |
---|
89 | // -- Bus protocol ports, do not add to or delete |
---|
90 | Bus2IP_Clk, // Bus to IP clock |
---|
91 | Bus2IP_Resetn, // Bus to IP reset |
---|
92 | Bus2IP_Data, // Bus to IP data bus |
---|
93 | Bus2IP_BE, // Bus to IP byte enables |
---|
94 | Bus2IP_RdCE, // Bus to IP read chip enable |
---|
95 | Bus2IP_WrCE, // Bus to IP write chip enable |
---|
96 | IP2Bus_Data, // IP to Bus data bus |
---|
97 | IP2Bus_RdAck, // IP to Bus read transfer acknowledgement |
---|
98 | IP2Bus_WrAck, // IP to Bus write transfer acknowledgement |
---|
99 | IP2Bus_Error // IP to Bus error response |
---|
100 | // -- DO NOT EDIT ABOVE THIS LINE ------------------ |
---|
101 | ); // user_logic |
---|
102 | |
---|
103 | // -- ADD USER PARAMETERS BELOW THIS LINE ------------ |
---|
104 | parameter HEXDISP_ACTIVE_HIGH = 0; |
---|
105 | parameter INCLUDE_DNA_READ_LOGIC = 1; |
---|
106 | // -- ADD USER PARAMETERS ABOVE THIS LINE ------------ |
---|
107 | |
---|
108 | // -- DO NOT EDIT BELOW THIS LINE -------------------- |
---|
109 | // -- Bus protocol parameters, do not add to or delete |
---|
110 | parameter C_NUM_REG = 12; |
---|
111 | parameter C_SLV_DWIDTH = 32; |
---|
112 | // -- DO NOT EDIT ABOVE THIS LINE -------------------- |
---|
113 | |
---|
114 | // -- ADD USER PORTS BELOW THIS LINE ----------------- |
---|
115 | /******* |
---|
116 | I/O tied to top-level pins, connected to devices on board |
---|
117 | ********/ |
---|
118 | output [6:0] hexdisp_left; |
---|
119 | output hexdisp_left_dp; |
---|
120 | output [6:0] hexdisp_right; |
---|
121 | output hexdisp_right_dp; |
---|
122 | |
---|
123 | output [3:0] leds_red; |
---|
124 | output [3:0] leds_green; |
---|
125 | |
---|
126 | output rfa_led_red; |
---|
127 | output rfa_led_green; |
---|
128 | output rfb_led_red; |
---|
129 | output rfb_led_green; |
---|
130 | |
---|
131 | input [3:0] dipsw; |
---|
132 | input pb_u; |
---|
133 | input pb_m; |
---|
134 | input pb_d; |
---|
135 | |
---|
136 | /******* |
---|
137 | I/O optionally connected to internal signals for non-software access to user I/O |
---|
138 | ********/ |
---|
139 | input [6:0] usr_hexdisp_left; |
---|
140 | input usr_hexdisp_left_dp; |
---|
141 | input [6:0] usr_hexdisp_right; |
---|
142 | input usr_hexdisp_right_dp; |
---|
143 | |
---|
144 | input [3:0] usr_leds_red; |
---|
145 | input [3:0] usr_leds_green; |
---|
146 | |
---|
147 | input usr_rfa_led_red; |
---|
148 | input usr_rfa_led_green; |
---|
149 | input usr_rfb_led_red; |
---|
150 | input usr_rfb_led_green; |
---|
151 | |
---|
152 | output [3:0] usr_dipsw; |
---|
153 | output usr_pb_u; |
---|
154 | output usr_pb_m; |
---|
155 | output usr_pb_d; |
---|
156 | |
---|
157 | //Clock signal for DNA_PORT.CLK port (must be <100MHz) |
---|
158 | input DNA_Port_Clk; |
---|
159 | // -- ADD USER PORTS ABOVE THIS LINE ----------------- |
---|
160 | |
---|
161 | // -- DO NOT EDIT BELOW THIS LINE -------------------- |
---|
162 | // -- Bus protocol ports, do not add to or delete |
---|
163 | input Bus2IP_Clk; |
---|
164 | input Bus2IP_Resetn; |
---|
165 | input [C_SLV_DWIDTH-1 : 0] Bus2IP_Data; |
---|
166 | input [C_SLV_DWIDTH/8-1 : 0] Bus2IP_BE; |
---|
167 | input [C_NUM_REG-1 : 0] Bus2IP_RdCE; |
---|
168 | input [C_NUM_REG-1 : 0] Bus2IP_WrCE; |
---|
169 | output [C_SLV_DWIDTH-1 : 0] IP2Bus_Data; |
---|
170 | output IP2Bus_RdAck; |
---|
171 | output IP2Bus_WrAck; |
---|
172 | output IP2Bus_Error; |
---|
173 | // -- DO NOT EDIT ABOVE THIS LINE -------------------- |
---|
174 | |
---|
175 | //---------------------------------------------------------------------------- |
---|
176 | // Implementation |
---|
177 | //---------------------------------------------------------------------------- |
---|
178 | |
---|
179 | // --USER nets declarations added here, as needed for user logic |
---|
180 | |
---|
181 | // Nets for user logic slave model s/w accessible register example |
---|
182 | reg [C_SLV_DWIDTH-1 : 0] slv_reg0; |
---|
183 | reg [C_SLV_DWIDTH-1 : 0] slv_reg1; |
---|
184 | reg [C_SLV_DWIDTH-1 : 0] slv_reg2; |
---|
185 | reg [C_SLV_DWIDTH-1 : 0] slv_reg3; |
---|
186 | reg [C_SLV_DWIDTH-1 : 0] slv_reg4; |
---|
187 | reg [C_SLV_DWIDTH-1 : 0] slv_reg5; |
---|
188 | reg [C_SLV_DWIDTH-1 : 0] slv_reg6; |
---|
189 | reg [C_SLV_DWIDTH-1 : 0] slv_reg7; |
---|
190 | reg [C_SLV_DWIDTH-1 : 0] slv_reg8; |
---|
191 | reg [C_SLV_DWIDTH-1 : 0] slv_reg9; |
---|
192 | reg [C_SLV_DWIDTH-1 : 0] slv_reg10; |
---|
193 | reg [C_SLV_DWIDTH-1 : 0] slv_reg11; |
---|
194 | wire [11 : 0] slv_reg_write_sel; |
---|
195 | wire [11 : 0] slv_reg_read_sel; |
---|
196 | reg [C_SLV_DWIDTH-1 : 0] slv_ip2bus_data; |
---|
197 | wire slv_read_ack; |
---|
198 | wire slv_write_ack; |
---|
199 | integer byte_index, bit_index; |
---|
200 | |
---|
201 | // USER logic implementation added here |
---|
202 | |
---|
203 | // ------------------------------------------------------ |
---|
204 | // Example code to read/write user logic slave model s/w accessible registers |
---|
205 | // |
---|
206 | // Note: |
---|
207 | // The example code presented here is to show you one way of reading/writing |
---|
208 | // software accessible registers implemented in the user logic slave model. |
---|
209 | // Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to correspond |
---|
210 | // to one software accessible register by the top level template. For example, |
---|
211 | // if you have four 32 bit software accessible registers in the user logic, |
---|
212 | // you are basically operating on the following memory mapped registers: |
---|
213 | // |
---|
214 | // Bus2IP_WrCE/Bus2IP_RdCE Memory Mapped Register |
---|
215 | // "1000" C_BASEADDR + 0x0 |
---|
216 | // "0100" C_BASEADDR + 0x4 |
---|
217 | // "0010" C_BASEADDR + 0x8 |
---|
218 | // "0001" C_BASEADDR + 0xC |
---|
219 | // |
---|
220 | // ------------------------------------------------------ |
---|
221 | |
---|
222 | assign |
---|
223 | slv_reg_write_sel = Bus2IP_WrCE[11:0], |
---|
224 | slv_reg_read_sel = Bus2IP_RdCE[11:0], |
---|
225 | slv_write_ack = Bus2IP_WrCE[0] || Bus2IP_WrCE[1] || Bus2IP_WrCE[2] || Bus2IP_WrCE[3] || Bus2IP_WrCE[4] || Bus2IP_WrCE[5] || Bus2IP_WrCE[6] || Bus2IP_WrCE[7] || Bus2IP_WrCE[8] || Bus2IP_WrCE[9] || Bus2IP_WrCE[10] || Bus2IP_WrCE[11], |
---|
226 | slv_read_ack = Bus2IP_RdCE[0] || Bus2IP_RdCE[1] || Bus2IP_RdCE[2] || Bus2IP_RdCE[3] || Bus2IP_RdCE[4] || Bus2IP_RdCE[5] || Bus2IP_RdCE[6] || Bus2IP_RdCE[7] || Bus2IP_RdCE[8] || Bus2IP_RdCE[9] || Bus2IP_RdCE[10] || Bus2IP_RdCE[11]; |
---|
227 | |
---|
228 | // implement slave model register(s) |
---|
229 | always @( posedge Bus2IP_Clk ) |
---|
230 | begin |
---|
231 | |
---|
232 | if ( Bus2IP_Resetn == 1'b0 ) |
---|
233 | begin |
---|
234 | slv_reg0 <= 32'h3F000000; //Defaults: hex map mode on for both displays, RF LEDs controlled by usr_ ports |
---|
235 | slv_reg1 <= 0; |
---|
236 | slv_reg2 <= 0; |
---|
237 | slv_reg3 <= 0; |
---|
238 | slv_reg4 <= 0; |
---|
239 | slv_reg5 <= 0; |
---|
240 | slv_reg6 <= 0; |
---|
241 | slv_reg7 <= 0; |
---|
242 | slv_reg8 <= 0; |
---|
243 | slv_reg9 <= 0; |
---|
244 | slv_reg10 <= 0; |
---|
245 | slv_reg11 <= 0; |
---|
246 | end |
---|
247 | else |
---|
248 | case ( slv_reg_write_sel ) |
---|
249 | 12'b100000000000 : |
---|
250 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
251 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
252 | slv_reg0[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
253 | 12'b010000000000 : |
---|
254 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
255 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
256 | slv_reg1[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
257 | 12'b001000000000 : |
---|
258 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
259 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
260 | slv_reg2[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
261 | 12'b000100000000 : |
---|
262 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
263 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
264 | slv_reg3[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
265 | 12'b000010000000 : |
---|
266 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
267 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
268 | slv_reg4[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
269 | 12'b000001000000 : |
---|
270 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
271 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
272 | slv_reg5[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
273 | 12'b000000100000 : |
---|
274 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
275 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
276 | slv_reg6[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
277 | 12'b000000010000 : |
---|
278 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
279 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
280 | slv_reg7[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
281 | 12'b000000001000 : |
---|
282 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
283 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
284 | slv_reg8[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
285 | 12'b000000000100 : |
---|
286 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
287 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
288 | slv_reg9[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
289 | 12'b000000000010 : |
---|
290 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
291 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
292 | slv_reg10[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
293 | 12'b000000000001 : |
---|
294 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
295 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
296 | slv_reg11[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
297 | default : begin |
---|
298 | slv_reg0 <= slv_reg0; |
---|
299 | slv_reg1 <= slv_reg1; |
---|
300 | slv_reg2 <= slv_reg2; |
---|
301 | slv_reg3 <= slv_reg3; |
---|
302 | slv_reg4 <= slv_reg4; |
---|
303 | slv_reg5 <= slv_reg5; |
---|
304 | slv_reg6 <= slv_reg6; |
---|
305 | slv_reg7 <= slv_reg7; |
---|
306 | slv_reg8 <= slv_reg8; |
---|
307 | slv_reg9 <= slv_reg9; |
---|
308 | slv_reg10 <= slv_reg10; |
---|
309 | slv_reg11 <= slv_reg11; |
---|
310 | end |
---|
311 | endcase |
---|
312 | |
---|
313 | end // SLAVE_REG_WRITE_PROC |
---|
314 | |
---|
315 | wire pb_u_db; |
---|
316 | wire pb_m_db; |
---|
317 | wire pb_d_db; |
---|
318 | wire [3:0] dipsw_db; |
---|
319 | reg [56:0] fpga_dna_value = 57'b0; |
---|
320 | |
---|
321 | // implement slave model register read mux |
---|
322 | always @( slv_reg_read_sel or slv_reg0 or slv_reg1 or slv_reg2 or slv_reg3 or slv_reg4 or slv_reg5 or slv_reg6 or slv_reg7 or slv_reg8 or slv_reg9 or slv_reg10 or slv_reg11 ) |
---|
323 | begin |
---|
324 | |
---|
325 | case ( slv_reg_read_sel ) |
---|
326 | 12'b100000000000 : slv_ip2bus_data <= slv_reg0; |
---|
327 | 12'b010000000000 : slv_ip2bus_data <= slv_reg1; |
---|
328 | 12'b001000000000 : slv_ip2bus_data <= slv_reg2; |
---|
329 | 12'b000100000000 : slv_ip2bus_data <= slv_reg3; |
---|
330 | 12'b000010000000 : slv_ip2bus_data <= slv_reg4; |
---|
331 | 12'b000001000000 : slv_ip2bus_data <= slv_reg5; |
---|
332 | 12'b000000100000 : slv_ip2bus_data <= {25'b0, pb_u_db, pb_m_db, pb_d_db, dipsw_db}; |
---|
333 | 12'b000000010000 : slv_ip2bus_data <= slv_reg7; |
---|
334 | 12'b000000001000 : slv_ip2bus_data <= slv_reg8; |
---|
335 | 12'b000000000100 : slv_ip2bus_data <= slv_reg9; |
---|
336 | 12'b000000000010 : slv_ip2bus_data <= fpga_dna_value[56:25];//25:56]; //32 LSB |
---|
337 | 12'b000000000001 : slv_ip2bus_data <= {7'b0, fpga_dna_value[24:0]};//0:24]}; //25 MSB |
---|
338 | default : slv_ip2bus_data <= 0; |
---|
339 | endcase |
---|
340 | |
---|
341 | end // SLAVE_REG_READ_PROC |
---|
342 | |
---|
343 | // ------------------------------------------------------------ |
---|
344 | // Example code to drive IP to Bus signals |
---|
345 | // ------------------------------------------------------------ |
---|
346 | |
---|
347 | assign IP2Bus_Data = (slv_read_ack == 1'b1) ? slv_ip2bus_data : 0 ; |
---|
348 | assign IP2Bus_WrAck = slv_write_ack; |
---|
349 | assign IP2Bus_RdAck = slv_read_ack; |
---|
350 | assign IP2Bus_Error = 0; |
---|
351 | |
---|
352 | //User IO Implementation |
---|
353 | /* Address map: |
---|
354 | HDL is coded [31:0], adopting Xilinx's convention for AXI IPIF cores |
---|
355 | All registers are 32-bits |
---|
356 | regX[31] maps to 0x80000000 in C driver |
---|
357 | regX[0] maps to 0x00000001 in C driver |
---|
358 | |
---|
359 | 0: Control RW |
---|
360 | [31:30] = Reserved |
---|
361 | [ 29] = Left hex data mode (0=user supplies bit-per-segment; 1=user supplies 4-bit hex) 0x20000000 |
---|
362 | [ 28] = Right hex data mode (0=user supplies bit-per-segment; 1=user supplies 4-bit hex) 0x10000000 |
---|
363 | Control source for LEDs: 0=software controlled, 1=usr_ port controlled |
---|
364 | [27:24] = {rfb_red rfb_green rfa_red rfa_green} 0x0F000000 |
---|
365 | [23:16] = {leds_red leds_green} 0x00FF0000 |
---|
366 | [15: 8] = {hexdisp_left{a b c d e f g dp}} 0x0000FF00 |
---|
367 | [ 7: 0] = {hexdisp_right{a b c d e f g dp}} 0x000000FF |
---|
368 | 1: Left hex display RW |
---|
369 | [31: 9] = reserved |
---|
370 | [ 8] = DP (controlled directly; doesn't depend on data mode) 0x100 |
---|
371 | [ 6: 0] = Data value ([6:4] ignored when data mode = 1) 0x03F |
---|
372 | 2: Right hex display RW |
---|
373 | [31: 9] = reserved |
---|
374 | [ 8] = DP (controlled directly; doesn't depend on data mode) 0x100 |
---|
375 | [ 6: 0] = Data value ([6:4] ignored when data mode = 1) 0x03F |
---|
376 | 3: Red user LEDs RW |
---|
377 | [31: 4] = reserved |
---|
378 | [ 3: 0] = Data value (1=LED illuminated) 0xF, with 0x1 mapped to lowest LED |
---|
379 | 4: Green user LEDs RW |
---|
380 | [31: 4] = reserved |
---|
381 | [ 3: 0] = Data value (1=LED illuminated) 0xF, with 0x1 mapped to lowest LED |
---|
382 | 5: RF LEDs RW |
---|
383 | [31: 4] = reserved |
---|
384 | [ 3] = rfb_red 0x8 |
---|
385 | [ 2] = rfb_green 0x4 |
---|
386 | [ 1] = rfa_red 0x2 |
---|
387 | [ 0] = rfa_green 0x1 |
---|
388 | 6: Switch/button inputs RO |
---|
389 | [31: 7] = reserved |
---|
390 | [ 6] = pb_up 0x40 |
---|
391 | [ 5] = pb_mid 0x20 |
---|
392 | [ 4] = pb_down 0x10 |
---|
393 | [ 3: 0] = DIP switch 0x0F (with 0x1 mapped to right-most switch) |
---|
394 | |
---|
395 | */ |
---|
396 | integer ii; |
---|
397 | |
---|
398 | wire [27:0] all_outputs_ctrl_source; |
---|
399 | wire [27:0] all_outputs_sw_val; |
---|
400 | wire [27:0] all_outputs_hw_val; |
---|
401 | reg [27:0] all_outputs; |
---|
402 | |
---|
403 | wire [6:0] leftHex_mapped; |
---|
404 | wire [6:0] rightHex_mapped; |
---|
405 | |
---|
406 | wire [6:0] leftHex_sw_val; |
---|
407 | wire [6:0] rightHex_sw_val; |
---|
408 | |
---|
409 | reg [7:0] pb_u_d = 0; |
---|
410 | reg [7:0] pb_m_d = 0; |
---|
411 | reg [7:0] pb_d_d = 0; |
---|
412 | reg [7:0] dipsw_d0 = 0; |
---|
413 | reg [7:0] dipsw_d1 = 0; |
---|
414 | reg [7:0] dipsw_d2 = 0; |
---|
415 | reg [7:0] dipsw_d3 = 0; |
---|
416 | |
---|
417 | |
---|
418 | //Shift registers for debouncing mechanical inputs |
---|
419 | always @(posedge Bus2IP_Clk) |
---|
420 | begin |
---|
421 | pb_u_d[7:0] <= {pb_u_d[6:0], pb_u}; |
---|
422 | pb_m_d[7:0] <= {pb_m_d[6:0], pb_m}; |
---|
423 | pb_d_d[7:0] <= {pb_d_d[6:0], pb_d}; |
---|
424 | dipsw_d0[7:0] <= {dipsw_d0[6:0], dipsw[0]}; |
---|
425 | dipsw_d1[7:0] <= {dipsw_d1[6:0], dipsw[1]}; |
---|
426 | dipsw_d2[7:0] <= {dipsw_d2[6:0], dipsw[2]}; |
---|
427 | dipsw_d3[7:0] <= {dipsw_d3[6:0], dipsw[3]}; |
---|
428 | end |
---|
429 | |
---|
430 | //Assert debounced signals only if inputs are high 8 consecutive cycles |
---|
431 | assign pb_u_db = (pb_u_d == 8'hff); |
---|
432 | assign pb_m_db = (pb_m_d == 8'hff); |
---|
433 | assign pb_d_db = (pb_d_d == 8'hff); |
---|
434 | |
---|
435 | //Swap MSB:LSB here, to undo endian swaps relative to schematic labels |
---|
436 | assign dipsw_db = {(dipsw_d0==8'hff), (dipsw_d1==8'hff), (dipsw_d2==8'hff), (dipsw_d3==8'hff)}; |
---|
437 | |
---|
438 | //Logic to map 4-bit hex value to 7-bit value for hex display |
---|
439 | sevenSegmentMap leftHexMap (.data(slv_reg1[3:0]), .disp(leftHex_mapped)); |
---|
440 | sevenSegmentMap rightHexMap (.data(slv_reg2[3:0]), .disp(rightHex_mapped)); |
---|
441 | |
---|
442 | //Select which 7-bit value is used as the software-supplied value for hex displays |
---|
443 | // User either supplies 4-bit value to be interpretted as hex value |
---|
444 | // or raw 7-bit (bit-per-diode) value |
---|
445 | assign leftHex_sw_val = slv_reg0[29] ? leftHex_mapped : slv_reg1[6:0]; |
---|
446 | assign rightHex_sw_val = slv_reg0[28] ? rightHex_mapped : slv_reg2[6:0]; |
---|
447 | |
---|
448 | //Extract the mux control values from the software register |
---|
449 | assign all_outputs_ctrl_source = slv_reg0[27:0]; |
---|
450 | |
---|
451 | //Extract and concatenate the software-controlled output values |
---|
452 | assign all_outputs_sw_val[27:0] = { |
---|
453 | slv_reg5[3], //[27] rgb_red LED |
---|
454 | slv_reg5[2], //[26] rgb_green LED |
---|
455 | slv_reg5[1], //[25] rga_red LED |
---|
456 | slv_reg5[0], //[24] rga_green LED |
---|
457 | slv_reg4[3:0], //[23:20] green LEDs |
---|
458 | slv_reg3[3:0], //[19:16] red LEDs |
---|
459 | slv_reg2[8], //[15] right hex DP |
---|
460 | rightHex_sw_val[6:0], //[14:8] right hex mapped |
---|
461 | slv_reg1[8], //[7] left hex DP |
---|
462 | leftHex_sw_val[6:0] //[6:0] left hex mapped |
---|
463 | }; |
---|
464 | |
---|
465 | //Concatenate the top-level inputs for hardware-controlled output values |
---|
466 | assign all_outputs_hw_val[27:24] = {usr_rfb_led_red, usr_rfb_led_green, usr_rfa_led_red, usr_rfa_led_green}; |
---|
467 | assign all_outputs_hw_val[23:16] = {usr_leds_green, usr_leds_red}; |
---|
468 | assign all_outputs_hw_val[15:8] = {usr_hexdisp_right_dp, usr_hexdisp_right}; |
---|
469 | assign all_outputs_hw_val[7:0] = {usr_hexdisp_left_dp, usr_hexdisp_left}; |
---|
470 | |
---|
471 | //Mux between hardware and software control for each output |
---|
472 | // Source control = 0 -> Software register bit controls output |
---|
473 | // Source control = 1 -> Hardware port control output |
---|
474 | always @* |
---|
475 | begin |
---|
476 | for(ii=0; ii<28; ii=ii+1) |
---|
477 | all_outputs[ii] = all_outputs_ctrl_source[ii] ? all_outputs_hw_val[ii] : all_outputs_sw_val[ii]; |
---|
478 | end |
---|
479 | |
---|
480 | //Map the mux outputs to the top-level outputs |
---|
481 | assign {rfb_led_red, rfb_led_green, rfa_led_red, rfa_led_green} = all_outputs[27:24]; |
---|
482 | |
---|
483 | //Swap MSB:LSB here, to undo endian swaps relative to schematic labels |
---|
484 | assign leds_green[3:0] = all_outputs[23:20]; |
---|
485 | assign leds_red[3:0] = all_outputs[19:16]; |
---|
486 | |
---|
487 | //Hex displays can be active high or low, depending on which part is used in assembly |
---|
488 | // HDL parameter HEXDISP_ACTIVE_HIGH defines the type at build-time |
---|
489 | // User values are always interpreted as 1==illuminated |
---|
490 | assign hexdisp_left_dp = HEXDISP_ACTIVE_HIGH ? all_outputs[7] : ~all_outputs[7]; |
---|
491 | assign hexdisp_left[6:0] = HEXDISP_ACTIVE_HIGH ? all_outputs[6:0] : ~all_outputs[6:0]; |
---|
492 | |
---|
493 | assign hexdisp_right_dp = HEXDISP_ACTIVE_HIGH ? all_outputs[15] : ~all_outputs[15]; |
---|
494 | assign hexdisp_right[6:0] = HEXDISP_ACTIVE_HIGH ? all_outputs[14:8] : ~all_outputs[14:8]; |
---|
495 | |
---|
496 | //Assign the usr_ output ports to the de-bounced top-level inputs |
---|
497 | assign usr_dipsw[3:0] = dipsw_db[3:0]; |
---|
498 | assign usr_pb_u = pb_u_db; |
---|
499 | assign usr_pb_m = pb_m_db; |
---|
500 | assign usr_pb_d = pb_d_db; |
---|
501 | |
---|
502 | generate |
---|
503 | if(INCLUDE_DNA_READ_LOGIC) begin |
---|
504 | wire dna_port_read, dna_port_shift, dna_port_clk_gated, dna_port_dout; |
---|
505 | //Instantiate the DNA_PORT module, for reading the FPGA's unique ID |
---|
506 | // Two MSB are always [1 0]? Accordint to isim at least |
---|
507 | DNA_PORT #(.SIM_DNA_VALUE(57'h123456789abcdef)) dna_port_inst ( |
---|
508 | .DIN(1'b0), |
---|
509 | .READ(dna_port_read), |
---|
510 | .SHIFT(dna_port_shift), |
---|
511 | .CLK(dna_port_clk_gated), |
---|
512 | .DOUT(dna_port_dout) |
---|
513 | ); |
---|
514 | |
---|
515 | reg [6:0] dna_read_counter = 7'b0; |
---|
516 | |
---|
517 | //Only clock the DNA_PORT primitive while actively shifting data out |
---|
518 | assign dna_port_clk_gated = (DNA_Port_Clk & (dna_read_counter>7'd60) & (dna_read_counter<7'h7f)); |
---|
519 | |
---|
520 | //Count-limited counter, that starts at configuration and runs exactly once |
---|
521 | always @(posedge DNA_Port_Clk) |
---|
522 | begin |
---|
523 | if(dna_read_counter == 7'h7f) |
---|
524 | dna_read_counter <= 7'h7f; |
---|
525 | else |
---|
526 | dna_read_counter <= dna_read_counter + 1; |
---|
527 | end |
---|
528 | |
---|
529 | //dna read states, as function of dna_read_counter value: |
---|
530 | // 0-63: Do nothing (just in case things needs to settle before DNA_PORT is accessible) |
---|
531 | // 64: Toggle READ signal (loads DNA value into DNA_PORT 57-bit shift register) |
---|
532 | // 65: Read DNA[0] from shift register DOUT; assert SHIFT |
---|
533 | //66-121: Read DNA[1:56] from shif register DOUT; SHIFT stays asserted |
---|
534 | // 122: De-assert SHIFT and READ |
---|
535 | |
---|
536 | assign dna_port_read = (dna_read_counter == 7'd63); |
---|
537 | assign dna_port_shift = ((dna_read_counter>= 7'd65) && (dna_read_counter<=122)); |
---|
538 | |
---|
539 | //Capture the shift register output in a single big register |
---|
540 | wire dna_capt; |
---|
541 | assign dna_capt = ((dna_read_counter>= 7'd65) && (dna_read_counter<=121)); |
---|
542 | always @(posedge DNA_Port_Clk) |
---|
543 | begin |
---|
544 | if (dna_capt) |
---|
545 | fpga_dna_value[dna_read_counter-7'd65] = dna_port_dout; |
---|
546 | end |
---|
547 | end |
---|
548 | endgenerate |
---|
549 | |
---|
550 | endmodule |
---|
551 | |
---|
552 | |
---|
553 | module sevenSegmentMap |
---|
554 | ( |
---|
555 | input [3:0] data, |
---|
556 | output reg [6:0] disp |
---|
557 | ); |
---|
558 | |
---|
559 | always @(data[3:0]) |
---|
560 | case (data[3:0]) |
---|
561 | 4'b0000 : disp <= ~(7'b1000000); // 0 |
---|
562 | 4'b0001 : disp <= ~(7'b1111001); // 1 |
---|
563 | 4'b0010 : disp <= ~(7'b0100100); // 2 |
---|
564 | 4'b0011 : disp <= ~(7'b0110000); // 3 |
---|
565 | 4'b0100 : disp <= ~(7'b0011001); // 4 |
---|
566 | 4'b0101 : disp <= ~(7'b0010010); // 5 |
---|
567 | 4'b0110 : disp <= ~(7'b0000010); // 6 |
---|
568 | 4'b0111 : disp <= ~(7'b1111000); // 7 |
---|
569 | 4'b1000 : disp <= ~(7'b0000000); // 8 |
---|
570 | 4'b1001 : disp <= ~(7'b0010000); // 9 |
---|
571 | 4'b1010 : disp <= ~(7'b0001000); // A |
---|
572 | 4'b1011 : disp <= ~(7'b0000011); // b |
---|
573 | 4'b1100 : disp <= ~(7'b1000110); // C |
---|
574 | 4'b1101 : disp <= ~(7'b0100001); // d |
---|
575 | 4'b1110 : disp <= ~(7'b0000110); // E |
---|
576 | 4'b1111 : disp <= ~(7'b0001110); // F |
---|
577 | default : disp <= (7'b0000000); |
---|
578 | endcase |
---|
579 | |
---|
580 | endmodule |
---|