1 | //---------------------------------------------------------------------------- |
---|
2 | // user_logic.vhd - module |
---|
3 | //---------------------------------------------------------------------------- |
---|
4 | // |
---|
5 | // *************************************************************************** |
---|
6 | // ** Copyright (c) 1995-2009 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.vhd |
---|
27 | // Version: 1.00.a |
---|
28 | // Description: User logic module. |
---|
29 | // Date: Mon Oct 5 10:19:40 2009 (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 | // Ideal layout |
---|
52 | // |
---|
53 | // 5 |
---|
54 | // --- |
---|
55 | // 0 | | 4 |
---|
56 | // | 6 | |
---|
57 | // --- |
---|
58 | // 1 | | 3 |
---|
59 | // | 2 | |
---|
60 | // --- o 7 |
---|
61 | // |
---|
62 | // |
---|
63 | |
---|
64 | module user_logic |
---|
65 | ( |
---|
66 | leds, |
---|
67 | hex_sda, |
---|
68 | hex_scl, |
---|
69 | pushbuttons, |
---|
70 | dipsw, |
---|
71 | Bus2IP_Clk, // Bus to IP clock |
---|
72 | Bus2IP_Reset, // Bus to IP reset |
---|
73 | Bus2IP_Data, // Bus to IP data bus |
---|
74 | Bus2IP_BE, // Bus to IP byte enables |
---|
75 | Bus2IP_RdCE, // Bus to IP read chip enable |
---|
76 | Bus2IP_WrCE, // Bus to IP write chip enable |
---|
77 | IP2Bus_Data, // IP to Bus data bus |
---|
78 | IP2Bus_RdAck, // IP to Bus read transfer acknowledgement |
---|
79 | IP2Bus_WrAck, // IP to Bus write transfer acknowledgement |
---|
80 | IP2Bus_Error // IP to Bus error response |
---|
81 | ); // user_logic |
---|
82 | |
---|
83 | parameter C_ADDRESS_0 = 8'h40; |
---|
84 | parameter C_ADDRESS_1 = 8'h50; |
---|
85 | parameter C_I2C_DIVIDER = 8'h40; |
---|
86 | parameter C_SLV_DWIDTH = 32; |
---|
87 | parameter C_NUM_REG = 5; |
---|
88 | |
---|
89 | output [0:7] leds; |
---|
90 | output hex_sda; |
---|
91 | output hex_scl; |
---|
92 | input [0:3] pushbuttons; |
---|
93 | input [0:3] dipsw; |
---|
94 | |
---|
95 | // -- Bus protocol ports, do not add to or delete |
---|
96 | input Bus2IP_Clk; |
---|
97 | input Bus2IP_Reset; |
---|
98 | input [0 : C_SLV_DWIDTH-1] Bus2IP_Data; |
---|
99 | input [0 : C_SLV_DWIDTH/8-1] Bus2IP_BE; |
---|
100 | input [0 : C_NUM_REG-1] Bus2IP_RdCE; |
---|
101 | input [0 : C_NUM_REG-1] Bus2IP_WrCE; |
---|
102 | output [0 : C_SLV_DWIDTH-1] IP2Bus_Data; |
---|
103 | output IP2Bus_RdAck; |
---|
104 | output IP2Bus_WrAck; |
---|
105 | output IP2Bus_Error; |
---|
106 | |
---|
107 | //---------------------------------------------------------------------------- |
---|
108 | // Implementation |
---|
109 | //---------------------------------------------------------------------------- |
---|
110 | |
---|
111 | wire [0:7] addr0; |
---|
112 | wire [0:7] addr1; |
---|
113 | wire [0:7] divider; |
---|
114 | assign addr0 = C_ADDRESS_0; |
---|
115 | assign addr1 = C_ADDRESS_1; |
---|
116 | assign divider = C_I2C_DIVIDER; |
---|
117 | |
---|
118 | // Nets for user logic slave model s/w accessible register example |
---|
119 | reg [0 : C_SLV_DWIDTH-1] slv_reg0; |
---|
120 | reg [0 : C_SLV_DWIDTH-1] slv_reg1; |
---|
121 | reg [0 : C_SLV_DWIDTH-1] slv_reg2; |
---|
122 | reg [0 : C_SLV_DWIDTH-1] slv_reg3; |
---|
123 | reg [0 : C_SLV_DWIDTH-1] slv_reg4; |
---|
124 | wire [0 : 4] slv_reg_write_sel; |
---|
125 | wire [0 : 4] slv_reg_read_sel; |
---|
126 | reg [0 : C_SLV_DWIDTH-1] slv_ip2bus_data; |
---|
127 | wire slv_read_ack; |
---|
128 | wire slv_write_ack; |
---|
129 | integer byte_index, bit_index; |
---|
130 | |
---|
131 | |
---|
132 | // All IO except io expander assignment. Debouncing pushbuttons |
---|
133 | |
---|
134 | reg [0:3] push_de0; |
---|
135 | reg [0:3] push_de1; |
---|
136 | reg [0:3] push_de2; |
---|
137 | reg [0:3] push_de3; |
---|
138 | reg [0:3] dip_de0; |
---|
139 | reg [0:3] dip_de1; |
---|
140 | reg [0:3] dip_de2; |
---|
141 | reg [0:3] dip_de3; |
---|
142 | |
---|
143 | reg [0:7] hex_l_local; |
---|
144 | wire [0:7] hex_l_hw; |
---|
145 | reg [0:7] hex_m_local; |
---|
146 | wire [0:7] hex_m_hw; |
---|
147 | reg [0:7] hex_r_local; |
---|
148 | wire [0:7] hex_r_hw; |
---|
149 | wire [0:7] hex_led; |
---|
150 | |
---|
151 | assign leds = slv_reg0[24:31]; |
---|
152 | |
---|
153 | always @( posedge Bus2IP_Clk ) |
---|
154 | begin |
---|
155 | push_de0 <= (push_de0 << 1) | {3'b0, pushbuttons[0]}; |
---|
156 | push_de1 <= (push_de1 << 1) | {3'b0, pushbuttons[1]}; |
---|
157 | push_de2 <= (push_de2 << 1) | {3'b0, pushbuttons[2]}; |
---|
158 | push_de3 <= (push_de3 << 1) | {3'b0, pushbuttons[3]}; |
---|
159 | |
---|
160 | slv_reg1[28] <= &push_de0; |
---|
161 | slv_reg1[29] <= &push_de1; |
---|
162 | slv_reg1[30] <= &push_de2; |
---|
163 | slv_reg1[31] <= &push_de3; |
---|
164 | |
---|
165 | dip_de0 <= (dip_de0 << 1) | {3'b0, dipsw[0]}; |
---|
166 | dip_de1 <= (dip_de1 << 1) | {3'b0, dipsw[1]}; |
---|
167 | dip_de2 <= (dip_de2 << 1) | {3'b0, dipsw[2]}; |
---|
168 | dip_de3 <= (dip_de3 << 1) | {3'b0, dipsw[3]}; |
---|
169 | |
---|
170 | slv_reg1[24] <= &dip_de0; |
---|
171 | slv_reg1[25] <= &dip_de1; |
---|
172 | slv_reg1[26] <= &dip_de2; |
---|
173 | slv_reg1[27] <= &dip_de3; |
---|
174 | |
---|
175 | if (slv_reg4[31] == 1'b1) |
---|
176 | begin |
---|
177 | // hex_right |
---|
178 | case ({slv_reg2[26], slv_reg2[28:31]}) |
---|
179 | 5'b00000: |
---|
180 | hex_r_local <= 8'b11111100; |
---|
181 | 5'b00001: |
---|
182 | hex_r_local <= 8'b00011000; |
---|
183 | 5'b00010: |
---|
184 | hex_r_local <= 8'b01101110; |
---|
185 | 5'b00011: |
---|
186 | hex_r_local <= 8'b00111110; |
---|
187 | 5'b00100: |
---|
188 | hex_r_local <= 8'b10011010; |
---|
189 | 5'b00101: |
---|
190 | hex_r_local <= 8'b10110110; |
---|
191 | 5'b00110: |
---|
192 | hex_r_local <= 8'b11110110; |
---|
193 | 5'b00111: |
---|
194 | hex_r_local <= 8'b00011100; |
---|
195 | 5'b01000: |
---|
196 | hex_r_local <= 8'b11111110; |
---|
197 | 5'b01001: |
---|
198 | hex_r_local <= 8'b10111110; |
---|
199 | 5'b01010: |
---|
200 | hex_r_local <= 8'b11011110; |
---|
201 | 5'b01011: |
---|
202 | hex_r_local <= 8'b11111110; |
---|
203 | 5'b01100: |
---|
204 | hex_r_local <= 8'b11100100; |
---|
205 | 5'b01101: |
---|
206 | hex_r_local <= 8'b11111100; |
---|
207 | 5'b01110: |
---|
208 | hex_r_local <= 8'b11100110; |
---|
209 | 5'b01111: |
---|
210 | hex_r_local <= 8'b11000110; |
---|
211 | default: |
---|
212 | hex_r_local <= 8'b00000000; |
---|
213 | endcase |
---|
214 | hex_r_local[7] <= slv_reg2[27]; |
---|
215 | end |
---|
216 | else |
---|
217 | begin |
---|
218 | // if not in number mode, map slv_reg3 bits directly to hex_local |
---|
219 | hex_r_local <= slv_reg3[16:23]; |
---|
220 | end |
---|
221 | |
---|
222 | if (slv_reg4[30] == 1'b1) |
---|
223 | begin |
---|
224 | // hex_mid |
---|
225 | case ({slv_reg2[18], slv_reg2[20:23]}) |
---|
226 | 5'b00000: |
---|
227 | hex_m_local <= 8'b11111100; |
---|
228 | 5'b00001: |
---|
229 | hex_m_local <= 8'b00011000; |
---|
230 | 5'b00010: |
---|
231 | hex_m_local <= 8'b01101110; |
---|
232 | 5'b00011: |
---|
233 | hex_m_local <= 8'b00111110; |
---|
234 | 5'b00100: |
---|
235 | hex_m_local <= 8'b10011010; |
---|
236 | 5'b00101: |
---|
237 | hex_m_local <= 8'b10110110; |
---|
238 | 5'b00110: |
---|
239 | hex_m_local <= 8'b11110110; |
---|
240 | 5'b00111: |
---|
241 | hex_m_local <= 8'b00011100; |
---|
242 | 5'b01000: |
---|
243 | hex_m_local <= 8'b11111110; |
---|
244 | 5'b01001: |
---|
245 | hex_m_local <= 8'b10111110; |
---|
246 | 5'b01010: |
---|
247 | hex_m_local <= 8'b11011110; |
---|
248 | 5'b01011: |
---|
249 | hex_m_local <= 8'b11111110; |
---|
250 | 5'b01100: |
---|
251 | hex_m_local <= 8'b11100100; |
---|
252 | 5'b01101: |
---|
253 | hex_m_local <= 8'b11111100; |
---|
254 | 5'b01110: |
---|
255 | hex_m_local <= 8'b11100110; |
---|
256 | 5'b01111: |
---|
257 | hex_m_local <= 8'b11000110; |
---|
258 | default: |
---|
259 | hex_m_local <= 8'b00000000; |
---|
260 | endcase |
---|
261 | hex_m_local[7] <= slv_reg2[19]; |
---|
262 | end |
---|
263 | else |
---|
264 | begin |
---|
265 | // if not in number mode, map slv_reg3 bits directly to hex_local |
---|
266 | hex_m_local <= slv_reg3[8:15]; |
---|
267 | end |
---|
268 | |
---|
269 | if (slv_reg4[29] == 1'b1) |
---|
270 | begin |
---|
271 | // hex_left |
---|
272 | case ({slv_reg2[10], slv_reg2[12:15]}) |
---|
273 | 5'b00000: |
---|
274 | hex_l_local <= 8'b11111100; |
---|
275 | 5'b00001: |
---|
276 | hex_l_local <= 8'b00011000; |
---|
277 | 5'b00010: |
---|
278 | hex_l_local <= 8'b01101110; |
---|
279 | 5'b00011: |
---|
280 | hex_l_local <= 8'b00111110; |
---|
281 | 5'b00100: |
---|
282 | hex_l_local <= 8'b10011010; |
---|
283 | 5'b00101: |
---|
284 | hex_l_local <= 8'b10110110; |
---|
285 | 5'b00110: |
---|
286 | hex_l_local <= 8'b11110110; |
---|
287 | 5'b00111: |
---|
288 | hex_l_local <= 8'b00011100; |
---|
289 | 5'b01000: |
---|
290 | hex_l_local <= 8'b11111110; |
---|
291 | 5'b01001: |
---|
292 | hex_l_local <= 8'b10111110; |
---|
293 | 5'b01010: |
---|
294 | hex_l_local <= 8'b11011110; |
---|
295 | 5'b01011: |
---|
296 | hex_l_local <= 8'b11111110; |
---|
297 | 5'b01100: |
---|
298 | hex_l_local <= 8'b11100100; |
---|
299 | 5'b01101: |
---|
300 | hex_l_local <= 8'b11111100; |
---|
301 | 5'b01110: |
---|
302 | hex_l_local <= 8'b11100110; |
---|
303 | 5'b01111: |
---|
304 | hex_l_local <= 8'b11000110; |
---|
305 | default: |
---|
306 | hex_l_local <= 8'b00000000; |
---|
307 | endcase |
---|
308 | hex_l_local[7] <= slv_reg2[11]; |
---|
309 | end |
---|
310 | else |
---|
311 | begin |
---|
312 | // if not in number mode, map slv_reg3 bits directly to hex_local |
---|
313 | hex_l_local <= slv_reg3[0:7]; |
---|
314 | end |
---|
315 | end |
---|
316 | |
---|
317 | // perform crazy mapping of ideal layout of bits to actual hardware bits |
---|
318 | assign hex_r_hw = {hex_r_local[0], hex_r_local[6], hex_r_local[1], hex_r_local[2], hex_r_local[7], hex_r_local[3], hex_r_local[4], hex_r_local[5]}; |
---|
319 | assign hex_m_hw = {hex_m_local[0], hex_m_local[6], hex_m_local[1], hex_m_local[2], hex_m_local[7], hex_m_local[3], hex_m_local[4], hex_m_local[5]}; |
---|
320 | assign hex_l_hw = {hex_l_local[5], hex_l_local[4], hex_l_local[3], hex_l_local[7], hex_l_local[2], hex_l_local[1], hex_l_local[6], hex_l_local[0]}; |
---|
321 | assign hex_led = slv_reg3[24:31]; |
---|
322 | |
---|
323 | assign |
---|
324 | slv_reg_write_sel = Bus2IP_WrCE[0:4], |
---|
325 | slv_reg_read_sel = Bus2IP_RdCE[0:4], |
---|
326 | slv_write_ack = Bus2IP_WrCE[0] || Bus2IP_WrCE[1] || Bus2IP_WrCE[2] || Bus2IP_WrCE[3] || Bus2IP_WrCE[4], |
---|
327 | slv_read_ack = Bus2IP_RdCE[0] || Bus2IP_RdCE[1] || Bus2IP_RdCE[2] || Bus2IP_RdCE[3] || Bus2IP_RdCE[4]; |
---|
328 | |
---|
329 | // implement slave model register(s) |
---|
330 | always @( posedge Bus2IP_Clk ) |
---|
331 | begin: SLAVE_REG_WRITE_PROC |
---|
332 | |
---|
333 | if ( Bus2IP_Reset == 1 ) |
---|
334 | begin |
---|
335 | slv_reg0 <= 0; |
---|
336 | //slv_reg1 <= 0; |
---|
337 | slv_reg2 <= 0; |
---|
338 | slv_reg3 <= 0; |
---|
339 | slv_reg4 <= 0; |
---|
340 | end |
---|
341 | else |
---|
342 | case (slv_reg_write_sel) |
---|
343 | 5'b10000 : |
---|
344 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
345 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
346 | for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 ) |
---|
347 | slv_reg0[bit_index] <= Bus2IP_Data[bit_index]; |
---|
348 | //5'b01000 : |
---|
349 | // for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
350 | // if ( Bus2IP_BE[byte_index] == 1 ) |
---|
351 | // for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 ) |
---|
352 | // slv_reg1[bit_index] <= Bus2IP_Data[bit_index]; |
---|
353 | 5'b00100 : |
---|
354 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
355 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
356 | for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 ) |
---|
357 | slv_reg2[bit_index] <= Bus2IP_Data[bit_index]; |
---|
358 | 5'b00010 : |
---|
359 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
360 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
361 | for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 ) |
---|
362 | slv_reg3[bit_index] <= Bus2IP_Data[bit_index]; |
---|
363 | 5'b00001 : |
---|
364 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
365 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
366 | for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 ) |
---|
367 | slv_reg4[bit_index] <= Bus2IP_Data[bit_index]; |
---|
368 | default : ; |
---|
369 | endcase |
---|
370 | |
---|
371 | end // SLAVE_REG_WRITE_PROC |
---|
372 | |
---|
373 | // implement slave model register read mux |
---|
374 | always @( slv_reg_read_sel or slv_reg0 or slv_reg1 or slv_reg2 or slv_reg3 or slv_reg4 ) |
---|
375 | begin: SLAVE_REG_READ_PROC |
---|
376 | |
---|
377 | case ( slv_reg_read_sel ) |
---|
378 | 5'b10000 : slv_ip2bus_data <= slv_reg0; |
---|
379 | 5'b01000 : slv_ip2bus_data <= slv_reg1; |
---|
380 | 5'b00100 : slv_ip2bus_data <= slv_reg2; |
---|
381 | 5'b00010 : slv_ip2bus_data <= {hex_l_local, hex_m_local, hex_r_local, hex_led}; |
---|
382 | 5'b00001 : slv_ip2bus_data <= slv_reg4; |
---|
383 | default : slv_ip2bus_data <= 0; |
---|
384 | endcase |
---|
385 | end // SLAVE_REG_READ_PROC |
---|
386 | |
---|
387 | // ------------------------------------------------------------ |
---|
388 | // Example code to drive IP to Bus signals |
---|
389 | // ------------------------------------------------------------ |
---|
390 | |
---|
391 | assign IP2Bus_Data = slv_ip2bus_data; |
---|
392 | assign IP2Bus_WrAck = slv_write_ack; |
---|
393 | assign IP2Bus_RdAck = slv_read_ack; |
---|
394 | assign IP2Bus_Error = 0; |
---|
395 | |
---|
396 | hex_out_cw hex_io ( |
---|
397 | .clk(Bus2IP_Clk), |
---|
398 | .ce(1'b1), |
---|
399 | .address0(addr0), |
---|
400 | .address1(addr1), |
---|
401 | .divider(divider), |
---|
402 | .hex_l(hex_m_hw), // naming error in sysgen. port corresponds to bits 0-7 of addr0 expander which is middle display |
---|
403 | .hex_m(hex_l_hw), // naming error in sysgen. port corresponds to bits 8-15 of addr0 expander which is left display |
---|
404 | .hex_r(hex_r_hw), |
---|
405 | .led8(hex_led), |
---|
406 | .reset(Bus2IP_Reset), |
---|
407 | .scl(hex_scl), |
---|
408 | .sda(hex_sda) |
---|
409 | ); |
---|
410 | |
---|
411 | endmodule |
---|