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: 3.01.a |
---|
28 | // Description: User logic module. |
---|
29 | // Date: Tue Feb 26 12:57:13 2013 (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 | RFA_AD_spi_sclk, |
---|
58 | RFA_AD_spi_cs_n, |
---|
59 | RFA_AD_spi_sdio, |
---|
60 | RFA_AD_reset_n, |
---|
61 | |
---|
62 | RFB_AD_spi_sclk, |
---|
63 | RFB_AD_spi_cs_n, |
---|
64 | RFB_AD_spi_sdio, |
---|
65 | RFB_AD_reset_n, |
---|
66 | |
---|
67 | RFC_AD_spi_sclk, |
---|
68 | RFC_AD_spi_cs_n, |
---|
69 | RFC_AD_spi_sdio, |
---|
70 | RFC_AD_reset_n, |
---|
71 | |
---|
72 | RFD_AD_spi_sclk, |
---|
73 | RFD_AD_spi_cs_n, |
---|
74 | RFD_AD_spi_sdio, |
---|
75 | RFD_AD_reset_n, |
---|
76 | |
---|
77 | RF_AD_TXCLK_out_en, |
---|
78 | // -- ADD USER PORTS ABOVE THIS LINE --------------- |
---|
79 | |
---|
80 | // -- DO NOT EDIT BELOW THIS LINE ------------------ |
---|
81 | // -- Bus protocol ports, do not add to or delete |
---|
82 | Bus2IP_Clk, // Bus to IP clock |
---|
83 | Bus2IP_Resetn, // Bus to IP reset |
---|
84 | Bus2IP_Data, // Bus to IP data bus |
---|
85 | Bus2IP_BE, // Bus to IP byte enables |
---|
86 | Bus2IP_RdCE, // Bus to IP read chip enable |
---|
87 | Bus2IP_WrCE, // Bus to IP write chip enable |
---|
88 | IP2Bus_Data, // IP to Bus data bus |
---|
89 | IP2Bus_RdAck, // IP to Bus read transfer acknowledgement |
---|
90 | IP2Bus_WrAck, // IP to Bus write transfer acknowledgement |
---|
91 | IP2Bus_Error // IP to Bus error response |
---|
92 | // -- DO NOT EDIT ABOVE THIS LINE ------------------ |
---|
93 | ); // user_logic |
---|
94 | |
---|
95 | // -- ADD USER PARAMETERS BELOW THIS LINE ------------ |
---|
96 | // --USER parameters added here |
---|
97 | // -- ADD USER PARAMETERS ABOVE THIS LINE ------------ |
---|
98 | parameter INCLUDE_RFC_RFD_IO = 0; |
---|
99 | |
---|
100 | // -- DO NOT EDIT BELOW THIS LINE -------------------- |
---|
101 | // -- Bus protocol parameters, do not add to or delete |
---|
102 | parameter C_NUM_REG = 16; |
---|
103 | parameter C_SLV_DWIDTH = 32; |
---|
104 | // -- DO NOT EDIT ABOVE THIS LINE -------------------- |
---|
105 | |
---|
106 | // -- ADD USER PORTS BELOW THIS LINE ----------------- |
---|
107 | output RFA_AD_spi_sclk; |
---|
108 | output RFA_AD_spi_cs_n; |
---|
109 | inout RFA_AD_spi_sdio; |
---|
110 | output RFA_AD_reset_n; |
---|
111 | |
---|
112 | output RFB_AD_spi_sclk; |
---|
113 | output RFB_AD_spi_cs_n; |
---|
114 | inout RFB_AD_spi_sdio; |
---|
115 | output RFB_AD_reset_n; |
---|
116 | |
---|
117 | output RFC_AD_spi_sclk; |
---|
118 | output RFC_AD_spi_cs_n; |
---|
119 | inout RFC_AD_spi_sdio; |
---|
120 | output RFC_AD_reset_n; |
---|
121 | |
---|
122 | output RFD_AD_spi_sclk; |
---|
123 | output RFD_AD_spi_cs_n; |
---|
124 | inout RFD_AD_spi_sdio; |
---|
125 | output RFD_AD_reset_n; |
---|
126 | |
---|
127 | output RF_AD_TXCLK_out_en; |
---|
128 | // -- ADD USER PORTS ABOVE THIS LINE ----------------- |
---|
129 | |
---|
130 | // -- DO NOT EDIT BELOW THIS LINE -------------------- |
---|
131 | // -- Bus protocol ports, do not add to or delete |
---|
132 | input Bus2IP_Clk; |
---|
133 | input Bus2IP_Resetn; |
---|
134 | input [C_SLV_DWIDTH-1 : 0] Bus2IP_Data; |
---|
135 | input [C_SLV_DWIDTH/8-1 : 0] Bus2IP_BE; |
---|
136 | input [C_NUM_REG-1 : 0] Bus2IP_RdCE; |
---|
137 | input [C_NUM_REG-1 : 0] Bus2IP_WrCE; |
---|
138 | output [C_SLV_DWIDTH-1 : 0] IP2Bus_Data; |
---|
139 | output IP2Bus_RdAck; |
---|
140 | output IP2Bus_WrAck; |
---|
141 | output IP2Bus_Error; |
---|
142 | // -- DO NOT EDIT ABOVE THIS LINE -------------------- |
---|
143 | |
---|
144 | //---------------------------------------------------------------------------- |
---|
145 | // Implementation |
---|
146 | //---------------------------------------------------------------------------- |
---|
147 | |
---|
148 | // --USER nets declarations added here, as needed for user logic |
---|
149 | |
---|
150 | // Nets for user logic slave model s/w accessible register example |
---|
151 | reg [C_SLV_DWIDTH-1 : 0] slv_reg0; |
---|
152 | reg [C_SLV_DWIDTH-1 : 0] slv_reg1; |
---|
153 | reg [C_SLV_DWIDTH-1 : 0] slv_reg2; |
---|
154 | reg [C_SLV_DWIDTH-1 : 0] slv_reg3; |
---|
155 | reg [C_SLV_DWIDTH-1 : 0] slv_reg4; |
---|
156 | reg [C_SLV_DWIDTH-1 : 0] slv_reg5; |
---|
157 | reg [C_SLV_DWIDTH-1 : 0] slv_reg6; |
---|
158 | reg [C_SLV_DWIDTH-1 : 0] slv_reg7; |
---|
159 | reg [C_SLV_DWIDTH-1 : 0] slv_reg8; |
---|
160 | reg [C_SLV_DWIDTH-1 : 0] slv_reg9; |
---|
161 | reg [C_SLV_DWIDTH-1 : 0] slv_reg10; |
---|
162 | reg [C_SLV_DWIDTH-1 : 0] slv_reg11; |
---|
163 | reg [C_SLV_DWIDTH-1 : 0] slv_reg12; |
---|
164 | reg [C_SLV_DWIDTH-1 : 0] slv_reg13; |
---|
165 | reg [C_SLV_DWIDTH-1 : 0] slv_reg14; |
---|
166 | reg [C_SLV_DWIDTH-1 : 0] slv_reg15; |
---|
167 | wire [15 : 0] slv_reg_write_sel; |
---|
168 | wire [15 : 0] slv_reg_read_sel; |
---|
169 | reg [C_SLV_DWIDTH-1 : 0] slv_ip2bus_data; |
---|
170 | wire slv_read_ack; |
---|
171 | wire slv_write_ack; |
---|
172 | integer byte_index, bit_index; |
---|
173 | |
---|
174 | // USER logic implementation added here |
---|
175 | |
---|
176 | // ------------------------------------------------------ |
---|
177 | // Example code to read/write user logic slave model s/w accessible registers |
---|
178 | // |
---|
179 | // Note: |
---|
180 | // The example code presented here is to show you one way of reading/writing |
---|
181 | // software accessible registers implemented in the user logic slave model. |
---|
182 | // Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to correspond |
---|
183 | // to one software accessible register by the top level template. For example, |
---|
184 | // if you have four 32 bit software accessible registers in the user logic, |
---|
185 | // you are basically operating on the following memory mapped registers: |
---|
186 | // |
---|
187 | // Bus2IP_WrCE/Bus2IP_RdCE Memory Mapped Register |
---|
188 | // "1000" C_BASEADDR + 0x0 |
---|
189 | // "0100" C_BASEADDR + 0x4 |
---|
190 | // "0010" C_BASEADDR + 0x8 |
---|
191 | // "0001" C_BASEADDR + 0xC |
---|
192 | // |
---|
193 | // ------------------------------------------------------ |
---|
194 | |
---|
195 | assign slv_reg_write_sel = Bus2IP_WrCE[15:0]; |
---|
196 | assign slv_reg_read_sel = Bus2IP_RdCE[15:0]; |
---|
197 | |
---|
198 | //Removed [14] from write_ack, so ack can be delayed following write to SPI Tx register |
---|
199 | // WrCE/RdCE[15:0] map to slv_reg[0:15] |
---|
200 | assign 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] || Bus2IP_WrCE[12] || Bus2IP_WrCE[13] || Bus2IP_WrCE[15]; |
---|
201 | assign 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] || Bus2IP_RdCE[12] || Bus2IP_RdCE[13] || Bus2IP_RdCE[14] || Bus2IP_RdCE[15]; |
---|
202 | |
---|
203 | // implement slave model register(s) |
---|
204 | always @( posedge Bus2IP_Clk ) |
---|
205 | begin |
---|
206 | |
---|
207 | if ( Bus2IP_Resetn == 1'b0 ) |
---|
208 | begin |
---|
209 | slv_reg0 <= 0; |
---|
210 | slv_reg1 <= 0; |
---|
211 | slv_reg2 <= 0; |
---|
212 | slv_reg3 <= 0; |
---|
213 | slv_reg4 <= 0; |
---|
214 | slv_reg5 <= 0; |
---|
215 | slv_reg6 <= 0; |
---|
216 | slv_reg7 <= 0; |
---|
217 | slv_reg8 <= 0; |
---|
218 | slv_reg9 <= 0; |
---|
219 | slv_reg10 <= 0; |
---|
220 | slv_reg11 <= 0; |
---|
221 | slv_reg12 <= 0; |
---|
222 | slv_reg13 <= 0; |
---|
223 | slv_reg14 <= 0; |
---|
224 | slv_reg15 <= 0; |
---|
225 | end |
---|
226 | else |
---|
227 | case ( slv_reg_write_sel ) |
---|
228 | 16'b1000000000000000 : |
---|
229 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
230 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
231 | slv_reg0[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
232 | 16'b0100000000000000 : |
---|
233 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
234 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
235 | slv_reg1[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
236 | 16'b0010000000000000 : |
---|
237 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
238 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
239 | slv_reg2[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
240 | 16'b0001000000000000 : |
---|
241 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
242 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
243 | slv_reg3[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
244 | 16'b0000100000000000 : |
---|
245 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
246 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
247 | slv_reg4[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
248 | 16'b0000010000000000 : |
---|
249 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
250 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
251 | slv_reg5[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
252 | 16'b0000001000000000 : |
---|
253 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
254 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
255 | slv_reg6[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
256 | 16'b0000000100000000 : |
---|
257 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
258 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
259 | slv_reg7[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
260 | 16'b0000000010000000 : |
---|
261 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
262 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
263 | slv_reg8[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
264 | 16'b0000000001000000 : |
---|
265 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
266 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
267 | slv_reg9[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
268 | 16'b0000000000100000 : |
---|
269 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
270 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
271 | slv_reg10[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
272 | 16'b0000000000010000 : |
---|
273 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
274 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
275 | slv_reg11[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
276 | 16'b0000000000001000 : |
---|
277 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
278 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
279 | slv_reg12[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
280 | 16'b0000000000000100 : |
---|
281 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
282 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
283 | slv_reg13[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
284 | 16'b0000000000000010 : |
---|
285 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
286 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
287 | slv_reg14[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
288 | 16'b0000000000000001 : |
---|
289 | for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 ) |
---|
290 | if ( Bus2IP_BE[byte_index] == 1 ) |
---|
291 | slv_reg15[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
292 | default : begin |
---|
293 | slv_reg0 <= slv_reg0; |
---|
294 | slv_reg1 <= slv_reg1; |
---|
295 | slv_reg2 <= slv_reg2; |
---|
296 | slv_reg3 <= slv_reg3; |
---|
297 | slv_reg4 <= slv_reg4; |
---|
298 | slv_reg5 <= slv_reg5; |
---|
299 | slv_reg6 <= slv_reg6; |
---|
300 | slv_reg7 <= slv_reg7; |
---|
301 | slv_reg8 <= slv_reg8; |
---|
302 | slv_reg9 <= slv_reg9; |
---|
303 | slv_reg10 <= slv_reg10; |
---|
304 | slv_reg11 <= slv_reg11; |
---|
305 | slv_reg12 <= slv_reg12; |
---|
306 | slv_reg13 <= slv_reg13; |
---|
307 | slv_reg14 <= slv_reg14; |
---|
308 | slv_reg15 <= slv_reg15; |
---|
309 | end |
---|
310 | endcase |
---|
311 | |
---|
312 | end // SLAVE_REG_WRITE_PROC |
---|
313 | |
---|
314 | wire [7:0] RFA_AD_spi_rx_byte; |
---|
315 | wire [7:0] RFB_AD_spi_rx_byte; |
---|
316 | wire [7:0] RFC_AD_spi_rx_byte; |
---|
317 | wire [7:0] RFD_AD_spi_rx_byte; |
---|
318 | |
---|
319 | |
---|
320 | // implement slave model register read mux |
---|
321 | 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 or slv_reg12 or slv_reg13 or slv_reg14 or slv_reg15 ) |
---|
322 | begin |
---|
323 | |
---|
324 | case ( slv_reg_read_sel ) |
---|
325 | 16'b1000000000000000 : slv_ip2bus_data <= slv_reg0; |
---|
326 | 16'b0100000000000000 : slv_ip2bus_data <= slv_reg1; |
---|
327 | 16'b0010000000000000 : slv_ip2bus_data <= {RFD_AD_spi_rx_byte, RFC_AD_spi_rx_byte, RFB_AD_spi_rx_byte, RFA_AD_spi_rx_byte}; |
---|
328 | 16'b0001000000000000 : slv_ip2bus_data <= slv_reg3; |
---|
329 | 16'b0000100000000000 : slv_ip2bus_data <= slv_reg4; |
---|
330 | 16'b0000010000000000 : slv_ip2bus_data <= slv_reg5; |
---|
331 | 16'b0000001000000000 : slv_ip2bus_data <= slv_reg6; |
---|
332 | 16'b0000000100000000 : slv_ip2bus_data <= slv_reg7; |
---|
333 | 16'b0000000010000000 : slv_ip2bus_data <= slv_reg8; |
---|
334 | 16'b0000000001000000 : slv_ip2bus_data <= slv_reg9; |
---|
335 | 16'b0000000000100000 : slv_ip2bus_data <= slv_reg10; |
---|
336 | 16'b0000000000010000 : slv_ip2bus_data <= slv_reg11; |
---|
337 | 16'b0000000000001000 : slv_ip2bus_data <= slv_reg12; |
---|
338 | 16'b0000000000000100 : slv_ip2bus_data <= slv_reg13; |
---|
339 | 16'b0000000000000010 : slv_ip2bus_data <= slv_reg14; |
---|
340 | 16'b0000000000000001 : slv_ip2bus_data <= slv_reg15; |
---|
341 | default : slv_ip2bus_data <= 0; |
---|
342 | endcase |
---|
343 | |
---|
344 | end // SLAVE_REG_READ_PROC |
---|
345 | |
---|
346 | // ------------------------------------------------------------ |
---|
347 | // Example code to drive IP to Bus signals |
---|
348 | // ------------------------------------------------------------ |
---|
349 | |
---|
350 | assign IP2Bus_Data = (slv_read_ack == 1'b1) ? slv_ip2bus_data : 0 ; |
---|
351 | // assign IP2Bus_WrAck = slv_write_ack; //Overridden below |
---|
352 | assign IP2Bus_RdAck = slv_read_ack; |
---|
353 | assign IP2Bus_Error = 0; |
---|
354 | |
---|
355 | /* Address map: |
---|
356 | HDL is coded [MSB:LSB] = [31:0], per Xilinx's convention for AXI peripherals |
---|
357 | regX[31] maps to 0x80000000 in C driver |
---|
358 | regX[0] maps to 0x00000001 in C driver |
---|
359 | |
---|
360 | 0: Config: {clk_div_sel[2:0], 1'b0, RFA_AD_rst_n, RFB_AD_rst_n, RFC_AD_rst_n, RFD_AD_rst_n, 24'b0} |
---|
361 | [ 2: 0] Clock divider bit sel (00=0.5*busclk, 01=0.25*busclk, ...) 0x00000007 |
---|
362 | [ 3] Reserved |
---|
363 | [ 4] RFA_AD reset (active low) 0x00000010 |
---|
364 | [ 5] RFB_AD reset (active low) 0x00000020 |
---|
365 | [ 6] RFC_AD reset (active low) 0x00000040 |
---|
366 | [ 7] RFD_AD reset (active low) 0x00000080 |
---|
367 | [ 8] RF_AD_TXCLK_out_en (1 = enable TXCLK output from ad_bridge) |
---|
368 | [31: 9] Reserved |
---|
369 | |
---|
370 | 1: SPI Tx |
---|
371 | [ 7: 0] Tx data byte 0x00FF |
---|
372 | [15: 8] 8-bit register address (0x00 to 0xFF all valid) 0xFF00 |
---|
373 | [20:16] 5'b0 (always zero) |
---|
374 | [22:21] Num bytes to Tx/Rx; must be 2'b0 for 1-byte Tx/Rx |
---|
375 | [ 23] RW# 1=Read, 0=Write |
---|
376 | [ 24] RFA_AD chip select mask |
---|
377 | [ 25] RFB_AD chip select mask |
---|
378 | [ 26] RFC_AD chip select mask |
---|
379 | [ 27] RFD_AD chip select mask |
---|
380 | [31:28] Reserved |
---|
381 | |
---|
382 | 2: SPI Rx: {RFA_AD_rxByte, RFB_AD_rxByte, RFC_AD_rxByte, RFD_AD_rxByte} |
---|
383 | [ 7: 0] SPI Rx byte for RFA_AD 0x000000FF |
---|
384 | [15: 8] SPI Rx byte for RFB_AD 0x0000FF00 |
---|
385 | [23:16] SPI Rx byte for RFC_AD 0x00FF0000 |
---|
386 | [31:24] SPI Rx byte for RFD_AD 0xFF000000 |
---|
387 | |
---|
388 | 3-15: Reserved |
---|
389 | */ |
---|
390 | |
---|
391 | `define AD9963_SPI_XFER_LEN 24 //AD9963 |
---|
392 | `define AD9963_SPI_FIRST_RXBIT 5'd16 //AD9963 (16-bit instruction, 8-bit data) |
---|
393 | |
---|
394 | wire [4:0] spi_bitNum; |
---|
395 | wire spi_mosi; |
---|
396 | wire spi_sclk; |
---|
397 | wire spi_cs; |
---|
398 | wire spi_rnw; |
---|
399 | wire RFA_AD_spi_cs, RFB_AD_spi_cs, RFC_AD_spi_cs, RFD_AD_spi_cs; |
---|
400 | wire spi_tx_reg_write; |
---|
401 | wire [2:0] clk_div_sel; |
---|
402 | wire spi_xfer_done; |
---|
403 | |
---|
404 | wire [31:0] RFA_AD_spi_rxData; |
---|
405 | wire [31:0] RFB_AD_spi_rxData; |
---|
406 | wire [31:0] RFC_AD_spi_rxData; |
---|
407 | wire [31:0] RFD_AD_spi_rxData; |
---|
408 | |
---|
409 | wire RFA_AD_spi_mosi, RFA_AD_spi_miso; |
---|
410 | wire RFB_AD_spi_mosi, RFB_AD_spi_miso; |
---|
411 | wire RFC_AD_spi_mosi, RFC_AD_spi_miso; |
---|
412 | wire RFD_AD_spi_mosi, RFD_AD_spi_miso; |
---|
413 | |
---|
414 | //Extract bits from IPIF slave registers and control signals |
---|
415 | |
---|
416 | //spi_io stores 32 bits for Tx/Rx |
---|
417 | // AD9963 only outputs 8-bit words during reads, always the last 8 bits of the transfer |
---|
418 | assign RFA_AD_spi_rx_byte = RFA_AD_spi_rxData[7:0]; |
---|
419 | assign RFB_AD_spi_rx_byte = RFB_AD_spi_rxData[7:0]; |
---|
420 | assign RFC_AD_spi_rx_byte = RFC_AD_spi_rxData[7:0]; |
---|
421 | assign RFD_AD_spi_rx_byte = RFD_AD_spi_rxData[7:0]; |
---|
422 | |
---|
423 | //SPI clock divider selection |
---|
424 | assign clk_div_sel = slv_reg0[2:0]; //0x7 from driver |
---|
425 | |
---|
426 | //SPI device resets (active low) |
---|
427 | reg RFA_AD_reset_n_d, RFB_AD_reset_n_d, RFC_AD_reset_n_d, RFD_AD_reset_n_d; |
---|
428 | always @(posedge Bus2IP_Clk) |
---|
429 | begin |
---|
430 | //Pipeline regs (fewer bus -> pin routes is good) |
---|
431 | RFA_AD_reset_n_d <= slv_reg0[4]; |
---|
432 | RFB_AD_reset_n_d <= slv_reg0[5]; |
---|
433 | RFC_AD_reset_n_d <= slv_reg0[6]; |
---|
434 | RFD_AD_reset_n_d <= slv_reg0[7]; |
---|
435 | end |
---|
436 | |
---|
437 | assign RFA_AD_reset_n = RFA_AD_reset_n_d; //0x10 from driver |
---|
438 | assign RFB_AD_reset_n = RFB_AD_reset_n_d; //0x20 from driver |
---|
439 | assign RFC_AD_reset_n = RFC_AD_reset_n_d; //0x40 from driver |
---|
440 | assign RFD_AD_reset_n = RFD_AD_reset_n_d; //0x80 from driver |
---|
441 | |
---|
442 | //Output enable for ad_bridge TXCLK port (AD9963 TXCLK port is bidirectional, defaults to output from AD9963) |
---|
443 | reg RF_AD_TXCLK_out_en_d; |
---|
444 | always @(posedge Bus2IP_Clk) |
---|
445 | begin |
---|
446 | //Pipeline reg (fewer bus -> pin routes is good) |
---|
447 | RF_AD_TXCLK_out_en_d <= slv_reg0[8]; //0x100 from driver |
---|
448 | end |
---|
449 | assign RF_AD_TXCLK_out_en = RF_AD_TXCLK_out_en_d; |
---|
450 | |
---|
451 | //SPI device chip selects (active high; inverted before use below) |
---|
452 | assign RFA_AD_spi_cs = slv_reg1[24]; //0x01000000 from driver |
---|
453 | assign RFB_AD_spi_cs = slv_reg1[25]; //0x02000000 from driver |
---|
454 | assign RFC_AD_spi_cs = slv_reg1[26]; //0x04000000 from driver |
---|
455 | assign RFD_AD_spi_cs = slv_reg1[27]; //0x08000000 from driver |
---|
456 | |
---|
457 | //Internal signal for read vs. write transaction |
---|
458 | assign spi_rnw = slv_reg1[`AD9963_SPI_XFER_LEN-1]; //0x00800000 from driver |
---|
459 | |
---|
460 | //Use the IPIC write-enable for the SPI Tx register as the SPI go |
---|
461 | // The bus will be paused until this core ACKs the write |
---|
462 | assign spi_tx_reg_write = Bus2IP_WrCE[14]; //WrCE[15:0] maps to slv_reg[0:15] |
---|
463 | |
---|
464 | //spi_tx_reg_write (Bus2IP_WrCE[14]) de-asserts as soon as transaction is ACK'd |
---|
465 | // so this mux switches back to the generic ACK as soon as the SPI xfer is done |
---|
466 | //Thus, the duration of assertion for spi_xfer_done doesn't really matter |
---|
467 | //A bit fast-n-loose, but works ok |
---|
468 | assign IP2Bus_WrAck = spi_tx_reg_write ? spi_xfer_done : slv_write_ack; |
---|
469 | |
---|
470 | //SPI device chip selects are active low |
---|
471 | assign RFA_AD_spi_cs_n = ~(RFA_AD_spi_cs & spi_cs); |
---|
472 | assign RFB_AD_spi_cs_n = ~(RFB_AD_spi_cs & spi_cs); |
---|
473 | assign RFC_AD_spi_cs_n = ~(RFC_AD_spi_cs & spi_cs); |
---|
474 | assign RFD_AD_spi_cs_n = ~(RFD_AD_spi_cs & spi_cs); |
---|
475 | |
---|
476 | //Mask each device's SPI clock output by its CS; no point toggling signals that will be ignored |
---|
477 | assign RFA_AD_spi_sclk = (spi_sclk & RFA_AD_spi_cs); |
---|
478 | assign RFB_AD_spi_sclk = (spi_sclk & RFB_AD_spi_cs); |
---|
479 | assign RFC_AD_spi_sclk = (spi_sclk & RFC_AD_spi_cs); |
---|
480 | assign RFD_AD_spi_sclk = (spi_sclk & RFD_AD_spi_cs); |
---|
481 | |
---|
482 | //All SPI devices driven by same serial data output; CS signals control who listens |
---|
483 | assign RFA_AD_spi_mosi = RFA_AD_spi_cs ? spi_mosi : 1'b0; |
---|
484 | assign RFB_AD_spi_mosi = RFB_AD_spi_cs ? spi_mosi : 1'b0; |
---|
485 | assign RFC_AD_spi_mosi = RFC_AD_spi_cs ? spi_mosi : 1'b0; |
---|
486 | assign RFD_AD_spi_mosi = RFD_AD_spi_cs ? spi_mosi : 1'b0; |
---|
487 | |
---|
488 | //AD9963 SPI data is bi-directional; IOBUFs instantiated here to switch I vs. O mid-transfer |
---|
489 | //Set spi_sdio pins as inputs except when actively driving, to avoid accidental drive fights |
---|
490 | // FPGA drives the sdio pin when: |
---|
491 | // An SPI transaction is in progress AND |
---|
492 | // The transaction is a read AND the current bit is part of the instruction bytes |
---|
493 | // OR |
---|
494 | // The transaction is a write |
---|
495 | assign RFA_AD_spi_sdio_output_en = spi_cs & ( (spi_rnw & (spi_bitNum < `AD9963_SPI_FIRST_RXBIT)) | (~spi_rnw)); |
---|
496 | assign RFB_AD_spi_sdio_output_en = spi_cs & ( (spi_rnw & (spi_bitNum < `AD9963_SPI_FIRST_RXBIT)) | (~spi_rnw)); |
---|
497 | assign RFC_AD_spi_sdio_output_en = spi_cs & ( (spi_rnw & (spi_bitNum < `AD9963_SPI_FIRST_RXBIT)) | (~spi_rnw)); |
---|
498 | assign RFD_AD_spi_sdio_output_en = spi_cs & ( (spi_rnw & (spi_bitNum < `AD9963_SPI_FIRST_RXBIT)) | (~spi_rnw)); |
---|
499 | |
---|
500 | IOBUF IOBUF_RFA_AD_sdio ( |
---|
501 | .IO(RFA_AD_spi_sdio), //Connected to actual FPGA pin |
---|
502 | .I(RFA_AD_spi_mosi), //Logic-> Pad, input to OBUFT |
---|
503 | .O(RFA_AD_spi_miso), //Pad-> Logic, output of IBUF |
---|
504 | .T(~RFA_AD_spi_sdio_output_en) |
---|
505 | ); |
---|
506 | |
---|
507 | IOBUF IOBUF_RFB_AD_sdio ( |
---|
508 | .IO(RFB_AD_spi_sdio), //Connected to actual FPGA pin |
---|
509 | .I(RFB_AD_spi_mosi), //Logic-> Pad, input to OBUFT |
---|
510 | .O(RFB_AD_spi_miso), //Pad-> Logic, output of IBUF |
---|
511 | .T(~RFB_AD_spi_sdio_output_en) |
---|
512 | ); |
---|
513 | |
---|
514 | generate |
---|
515 | if(INCLUDE_RFC_RFD_IO==1) |
---|
516 | begin |
---|
517 | IOBUF IOBUF_RFC_AD_sdio ( |
---|
518 | .IO(RFC_AD_spi_sdio), //Connected to actual FPGA pin |
---|
519 | .I(RFC_AD_spi_mosi), //Logic-> Pad, input to OBUFT |
---|
520 | .O(RFC_AD_spi_miso), //Pad-> Logic, output of IBUF |
---|
521 | .T(~RFC_AD_spi_sdio_output_en) |
---|
522 | ); |
---|
523 | |
---|
524 | IOBUF IOBUF_RFD_AD_sdio ( |
---|
525 | .IO(RFD_AD_spi_sdio), //Connected to actual FPGA pin |
---|
526 | .I(RFD_AD_spi_mosi), //Logic-> Pad, input to OBUFT |
---|
527 | .O(RFD_AD_spi_miso), //Pad-> Logic, output of IBUF |
---|
528 | .T(~RFD_AD_spi_sdio_output_en) |
---|
529 | ); |
---|
530 | end |
---|
531 | else |
---|
532 | begin |
---|
533 | assign RFC_AD_spi_miso = 1'b0; |
---|
534 | assign RFD_AD_spi_miso = 1'b0; |
---|
535 | |
---|
536 | assign RFC_AD_spi_sdio = 1'b0; |
---|
537 | assign RFD_AD_spi_sdio = 1'b0; |
---|
538 | end |
---|
539 | endgenerate |
---|
540 | |
---|
541 | warp_spi_io #(.SPI_XFER_LEN(`AD9963_SPI_XFER_LEN)) spi_io |
---|
542 | ( |
---|
543 | .sys_clk(Bus2IP_Clk), |
---|
544 | .reset(~Bus2IP_Resetn),//warp_spi_io.reset is active high |
---|
545 | .go(spi_tx_reg_write), |
---|
546 | .done(spi_xfer_done), |
---|
547 | .clkDiv(clk_div_sel), |
---|
548 | |
---|
549 | .currBitNum(spi_bitNum), |
---|
550 | |
---|
551 | .txData(slv_reg1), |
---|
552 | |
---|
553 | .rxData1(RFA_AD_spi_rxData), |
---|
554 | .rxData2(RFB_AD_spi_rxData), |
---|
555 | .rxData3(RFC_AD_spi_rxData), |
---|
556 | .rxData4(RFD_AD_spi_rxData), |
---|
557 | |
---|
558 | .spi_cs(spi_cs), |
---|
559 | .spi_sclk(spi_sclk), |
---|
560 | |
---|
561 | .spi_mosi(spi_mosi), |
---|
562 | |
---|
563 | .spi_miso1(RFA_AD_spi_miso), |
---|
564 | .spi_miso2(RFB_AD_spi_miso), |
---|
565 | .spi_miso3(RFC_AD_spi_miso), |
---|
566 | .spi_miso4(RFD_AD_spi_miso) |
---|
567 | ); |
---|
568 | |
---|
569 | endmodule |
---|