source: PlatformSupport/CustomPeripherals/pcores/w3_ad_controller_v3_00_b/hdl/verilog/user_logic.v

Last change on this file was 1766, checked in by murphpo, 12 years ago
File size: 21.1 KB
Line 
1//----------------------------------------------------------------------------
2// user_logic.v
3//----------------------------------------------------------------------------
4//
5// ***************************************************************************
6// ** Copyright (c) 1995-2011 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// Modifications from base template Copyright (c) 2012 Mango Communications
27// Distributed under the terms of the WARP open-source license
28//   http://warp.rice.edu/license
29//----------------------------------------------------------------------------
30// Naming Conventions:
31//   active low signals:                    "*_n"
32//   clock signals:                         "clk", "clk_div#", "clk_#x"
33//   reset signals:                         "rst", "rst_n"
34//   generics:                              "C_*"
35//   user defined types:                    "*_TYPE"
36//   state machine next state:              "*_ns"
37//   state machine current state:           "*_cs"
38//   combinatorial signals:                 "*_com"
39//   pipelined or register delay signals:   "*_d#"
40//   counter signals:                       "*cnt*"
41//   clock enable signals:                  "*_ce"
42//   internal version of output port:       "*_i"
43//   device pins:                           "*_pin"
44//   ports:                                 "- Names begin with Uppercase"
45//   processes:                             "*_PROCESS"
46//   component instantiations:              "<ENTITY_>I_<#|FUNC>"
47//----------------------------------------------------------------------------
48
49module user_logic
50(
51    // -- ADD USER PORTS BELOW THIS LINE ---------------
52    RFA_AD_spi_sclk,
53    RFA_AD_spi_cs_n,
54    RFA_AD_spi_sdio,
55    RFA_AD_reset_n,
56
57    RFB_AD_spi_sclk,
58    RFB_AD_spi_cs_n,
59    RFB_AD_spi_sdio,
60    RFB_AD_reset_n,
61   
62    // -- ADD USER PORTS ABOVE THIS LINE ---------------
63
64    // -- DO NOT EDIT BELOW THIS LINE ------------------
65    // -- Bus protocol ports, do not add to or delete
66    Bus2IP_Clk,                     // Bus to IP clock
67    Bus2IP_Reset,                   // Bus to IP reset
68    Bus2IP_Addr,                    // Bus to IP address bus
69    Bus2IP_Data,                    // Bus to IP data bus
70    Bus2IP_BE,                      // Bus to IP byte enables
71    Bus2IP_RdCE,                    // Bus to IP read chip enable
72    Bus2IP_WrCE,                    // Bus to IP write chip enable
73    IP2Bus_Data,                    // IP to Bus data bus
74    IP2Bus_RdAck,                   // IP to Bus read transfer acknowledgement
75    IP2Bus_WrAck,                   // IP to Bus write transfer acknowledgement
76    IP2Bus_Error                    // IP to Bus error response
77    // -- DO NOT EDIT ABOVE THIS LINE ------------------
78); // user_logic
79
80// -- ADD USER PARAMETERS BELOW THIS LINE ------------
81
82// -- ADD USER PARAMETERS ABOVE THIS LINE ------------
83
84// -- DO NOT EDIT BELOW THIS LINE --------------------
85// -- Bus protocol parameters, do not add to or delete
86parameter C_SLV_DWIDTH                   = 32;
87parameter C_NUM_REG                      = 16;
88// -- DO NOT EDIT ABOVE THIS LINE --------------------
89
90// -- ADD USER PORTS BELOW THIS LINE -----------------
91    output RFA_AD_spi_sclk;
92    output RFA_AD_spi_cs_n;
93    inout RFA_AD_spi_sdio;
94    output RFA_AD_reset_n;
95
96   
97    output RFB_AD_spi_sclk;
98    output RFB_AD_spi_cs_n;
99    inout RFB_AD_spi_sdio;
100    output RFB_AD_reset_n;
101// -- ADD USER PORTS ABOVE THIS LINE -----------------
102
103// -- DO NOT EDIT BELOW THIS LINE --------------------
104// -- Bus protocol ports, do not add to or delete
105input                                     Bus2IP_Clk;
106input                                     Bus2IP_Reset;
107input      [0 : 31]                       Bus2IP_Addr;
108input      [0 : C_SLV_DWIDTH-1]           Bus2IP_Data;
109input      [0 : C_SLV_DWIDTH/8-1]         Bus2IP_BE;
110input      [0 : C_NUM_REG-1]              Bus2IP_RdCE;
111input      [0 : C_NUM_REG-1]              Bus2IP_WrCE;
112output     [0 : C_SLV_DWIDTH-1]           IP2Bus_Data;
113output                                    IP2Bus_RdAck;
114output                                    IP2Bus_WrAck;
115output                                    IP2Bus_Error;
116// -- DO NOT EDIT ABOVE THIS LINE --------------------
117
118//----------------------------------------------------------------------------
119// Implementation
120//----------------------------------------------------------------------------
121
122    // --USER nets declarations added here, as needed for user logic
123
124    // Nets for user logic slave model s/w accessible register example
125    reg        [0 : C_SLV_DWIDTH-1]           slv_reg0;
126    reg        [0 : C_SLV_DWIDTH-1]           slv_reg1;
127    reg        [0 : C_SLV_DWIDTH-1]           slv_reg2;
128    reg        [0 : C_SLV_DWIDTH-1]           slv_reg3;
129    reg        [0 : C_SLV_DWIDTH-1]           slv_reg4;
130    reg        [0 : C_SLV_DWIDTH-1]           slv_reg5;
131    reg        [0 : C_SLV_DWIDTH-1]           slv_reg6;
132    reg        [0 : C_SLV_DWIDTH-1]           slv_reg7;
133    reg        [0 : C_SLV_DWIDTH-1]           slv_reg8;
134    reg        [0 : C_SLV_DWIDTH-1]           slv_reg9;
135    reg        [0 : C_SLV_DWIDTH-1]           slv_reg10;
136    reg        [0 : C_SLV_DWIDTH-1]           slv_reg11;
137    reg        [0 : C_SLV_DWIDTH-1]           slv_reg12;
138    reg        [0 : C_SLV_DWIDTH-1]           slv_reg13;
139    reg        [0 : C_SLV_DWIDTH-1]           slv_reg14;
140    reg        [0 : C_SLV_DWIDTH-1]           slv_reg15;
141    wire       [0 : 15]                       slv_reg_write_sel;
142    wire       [0 : 15]                       slv_reg_read_sel;
143    reg        [0 : C_SLV_DWIDTH-1]           slv_ip2bus_data;
144    wire                                      slv_read_ack;
145    wire                                      slv_write_ack;
146    integer                                   byte_index, bit_index;
147
148    // --USER logic implementation added here
149
150    // ------------------------------------------------------
151    // Example code to read/write user logic slave model s/w accessible registers
152    //
153    // Note:
154    // The example code presented here is to show you one way of reading/writing
155    // software accessible registers implemented in the user logic slave model.
156    // Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to correspond
157    // to one software accessible register by the top level template. For example,
158    // if you have four 32 bit software accessible registers in the user logic,
159    // you are basically operating on the following memory mapped registers:
160    //
161    //    Bus2IP_WrCE/Bus2IP_RdCE   Memory Mapped Register
162    //                     "1000"   C_BASEADDR + 0x0
163    //                     "0100"   C_BASEADDR + 0x4
164    //                     "0010"   C_BASEADDR + 0x8
165    //                     "0001"   C_BASEADDR + 0xC
166    //
167    // ------------------------------------------------------
168
169    assign slv_reg_write_sel = Bus2IP_WrCE[0:15];
170    assign slv_reg_read_sel  = Bus2IP_RdCE[0:15];
171       
172    //Removed [1] from _ack list, so ack can be delayed following write to SPI Tx register
173    assign slv_write_ack = Bus2IP_WrCE[0] || 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[14] || Bus2IP_WrCE[15];
174    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];
175
176    // implement slave model register(s)
177    always @( posedge Bus2IP_Clk )
178        begin: SLAVE_REG_WRITE_PROC
179
180            if ( Bus2IP_Reset == 1 )
181                begin
182                    slv_reg0 <= 0;
183                    slv_reg1 <= 0;
184                    slv_reg2 <= 0;
185                    slv_reg3 <= 0;
186                    slv_reg4 <= 0;
187                    slv_reg5 <= 0;
188                    slv_reg6 <= 0;
189                    slv_reg7 <= 0;
190                    slv_reg8 <= 0;
191                    slv_reg9 <= 0;
192                    slv_reg10 <= 0;
193                    slv_reg11 <= 0;
194                    slv_reg12 <= 0;
195                    slv_reg13 <= 0;
196                    slv_reg14 <= 0;
197                    slv_reg15 <= 0;
198                end
199            else
200                case ( slv_reg_write_sel )
201                    16'b1000000000000000 :
202                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
203                            if ( Bus2IP_BE[byte_index] == 1 )
204                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
205                                    slv_reg0[bit_index] <= Bus2IP_Data[bit_index];
206                    16'b0100000000000000 :
207                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
208                            if ( Bus2IP_BE[byte_index] == 1 )
209                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
210                                    slv_reg1[bit_index] <= Bus2IP_Data[bit_index];
211                    16'b0010000000000000 :
212                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
213                            if ( Bus2IP_BE[byte_index] == 1 )
214                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
215                                    slv_reg2[bit_index] <= Bus2IP_Data[bit_index];
216                    16'b0001000000000000 :
217                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
218                            if ( Bus2IP_BE[byte_index] == 1 )
219                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
220                                    slv_reg3[bit_index] <= Bus2IP_Data[bit_index];
221                    16'b0000100000000000 :
222                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
223                            if ( Bus2IP_BE[byte_index] == 1 )
224                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
225                                    slv_reg4[bit_index] <= Bus2IP_Data[bit_index];
226                    16'b0000010000000000 :
227                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
228                            if ( Bus2IP_BE[byte_index] == 1 )
229                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
230                                    slv_reg5[bit_index] <= Bus2IP_Data[bit_index];
231                    16'b0000001000000000 :
232                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
233                            if ( Bus2IP_BE[byte_index] == 1 )
234                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
235                                    slv_reg6[bit_index] <= Bus2IP_Data[bit_index];
236                    16'b0000000100000000 :
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                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
240                                    slv_reg7[bit_index] <= Bus2IP_Data[bit_index];
241                    16'b0000000010000000 :
242                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
243                            if ( Bus2IP_BE[byte_index] == 1 )
244                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
245                                    slv_reg8[bit_index] <= Bus2IP_Data[bit_index];
246                    16'b0000000001000000 :
247                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
248                            if ( Bus2IP_BE[byte_index] == 1 )
249                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
250                                    slv_reg9[bit_index] <= Bus2IP_Data[bit_index];
251                    16'b0000000000100000 :
252                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
253                            if ( Bus2IP_BE[byte_index] == 1 )
254                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
255                                    slv_reg10[bit_index] <= Bus2IP_Data[bit_index];
256                    16'b0000000000010000 :
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                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
260                                    slv_reg11[bit_index] <= Bus2IP_Data[bit_index];
261                    16'b0000000000001000 :
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                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
265                                    slv_reg12[bit_index] <= Bus2IP_Data[bit_index];
266                    16'b0000000000000100 :
267                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
268                            if ( Bus2IP_BE[byte_index] == 1 )
269                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
270                                    slv_reg13[bit_index] <= Bus2IP_Data[bit_index];
271                    16'b0000000000000010 :
272                        for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
273                            if ( Bus2IP_BE[byte_index] == 1 )
274                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
275                                    slv_reg14[bit_index] <= Bus2IP_Data[bit_index];
276                    16'b0000000000000001 :
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                                for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1 )
280                                    slv_reg15[bit_index] <= Bus2IP_Data[bit_index];
281                    default : ;
282                endcase
283
284        end // SLAVE_REG_WRITE_PROC
285
286    wire [0:7] RFA_AD_spi_rx_byte;
287    wire [0:7] RFB_AD_spi_rx_byte;
288   
289    // implement slave model register read mux
290    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 )
291        begin: SLAVE_REG_READ_PROC
292
293            case ( slv_reg_read_sel )
294                16'b1000000000000000 : slv_ip2bus_data <= slv_reg0;
295                16'b0100000000000000 : slv_ip2bus_data <= slv_reg1;
296                16'b0010000000000000 : slv_ip2bus_data <= {16'b0, RFB_AD_spi_rx_byte, RFA_AD_spi_rx_byte};
297                16'b0001000000000000 : slv_ip2bus_data <= slv_reg3;
298                16'b0000100000000000 : slv_ip2bus_data <= slv_reg4;
299                16'b0000010000000000 : slv_ip2bus_data <= slv_reg5;
300                16'b0000001000000000 : slv_ip2bus_data <= slv_reg6;
301                16'b0000000100000000 : slv_ip2bus_data <= slv_reg7;
302                16'b0000000010000000 : slv_ip2bus_data <= slv_reg8;
303                16'b0000000001000000 : slv_ip2bus_data <= slv_reg9;
304                16'b0000000000100000 : slv_ip2bus_data <= slv_reg10;
305                16'b0000000000010000 : slv_ip2bus_data <= slv_reg11;
306                16'b0000000000001000 : slv_ip2bus_data <= slv_reg12;
307                16'b0000000000000100 : slv_ip2bus_data <= slv_reg13;
308                16'b0000000000000010 : slv_ip2bus_data <= slv_reg14;
309                16'b0000000000000001 : slv_ip2bus_data <= slv_reg15;
310                default : slv_ip2bus_data <= 0;
311            endcase
312
313        end // SLAVE_REG_READ_PROC
314
315
316    assign IP2Bus_Data    = slv_ip2bus_data;
317
318    //Reads occur immediately; acknowledge in same cycle as access
319    assign IP2Bus_RdAck   = slv_read_ack;
320    //assign IP2Bus_WrAck   = slv_write_ack; //Overridden below
321    assign IP2Bus_Error   = 0;
322
323    /* Address map:
324        HDL is coded [MSB:LSB] = [0:31]
325        regX[0]  maps to 0x80000000 in C driver
326        regX[31] maps to 0x00000001 in C driver
327
328    0: Config: {clk_div_sel[2:0], 1'b0, RFA_AD_rst_n, RFB_AD_rst_n, 26'b0}
329        [29:31] Clock divider bit sel (00=0.5*busclk, 01=0.25*busclk, ...) 0x00000003
330        [28   ] Reserved
331        [   27] RFA_AD reset (active low) 0x00000010
332        [   26] RFB_AD reset (active low) 0x00000020
333        [0 :25] Reserved
334
335    1: SPI Tx
336        [24:31] Tx data byte
337        [16:23] 8-bit register address (0x00 to 0xFF all valid)
338        [11:15] 5'b0 (always zero)
339        [ 9:10] Num bytes to Tx/Rx; must be 2'b0 for 1-byte Tx/Rx
340        [    8] RW# 1=Read, 0=Write
341        [    7] RFA_AD chip select mask
342        [    6] RFB_AD chip select mask
343        [ 0: 5] Reserved
344   
345    2: SPI Rx: {RFA_AD_rxByte, RFB_AD_rxByte, 16'b0}
346        [24:31] SPI Rx byte for RFA_AD 0x00FF
347        [16:23] SPI Rx byte for RFB_AD 0xFF00
348        [ 0:15] Reserved 0xFFFF0000
349       
350    3-15: Reserved
351    */
352
353
354//  `define AD9963_SPI_XFER_LEN 5'd16 //AD9777 testing
355    `define AD9963_SPI_XFER_LEN 24 //AD9963
356
357//  `define AD9963_SPI_FIRST_RXBIT 5'd8 //AD9777 testing (8-bit instruction, 8-bit data)
358    `define AD9963_SPI_FIRST_RXBIT 5'd16 //AD9963 (16-bit instruction, 8-bit data)
359   
360   
361    wire [0:4] spi_bitNum;
362    wire spi_mosi;
363    wire spi_sclk;
364    wire spi_cs;
365    wire spi_rnw;
366    wire RFA_AD_spi_cs, RFB_AD_spi_cs;
367    wire spi_tx_reg_write;
368    wire [0:2] clk_div_sel;
369    wire spi_xfer_done;
370   
371    wire [0:31] RFA_AD_spi_rxData;
372    wire [0:31] RFB_AD_spi_rxData;
373   
374    wire RFA_AD_spi_mosi, RFA_AD_spi_miso;
375    wire RFB_AD_spi_mosi, RFB_AD_spi_miso;
376   
377    //Extract bits from IPIF slave registers and control signals
378
379    //spi_io stores 32 bits for Tx/Rx
380    // AD9963 only outputs 8-bit words during reads, always the last 8 bits of the transfer
381    assign RFA_AD_spi_rx_byte = RFA_AD_spi_rxData[24:31];
382    assign RFB_AD_spi_rx_byte = RFB_AD_spi_rxData[24:31];
383   
384    //SPI clock divider selection
385    assign clk_div_sel = slv_reg0[29:31]; //0x7 from driver
386
387    //SPI device resets (active low)
388    assign RFA_AD_reset_n = slv_reg0[27]; //0x10 from driver
389    assign RFB_AD_reset_n = slv_reg0[26]; //0x20 from driver
390
391    //SPI device chip selects (active high; inverted before use below)
392    assign RFA_AD_spi_cs = slv_reg1[7]; //0x01000000 from driver
393    assign RFB_AD_spi_cs = slv_reg1[6]; //0x02000000 from driver
394
395    //Internal signal for read vs. write transaction
396    assign spi_rnw = slv_reg1[32-`AD9963_SPI_XFER_LEN]; //0x00800000 from driver
397   
398    //Use the IPIC write-enable for the SPI Tx register as the SPI go
399    // The bus will be paused until this core ACKs the write
400    assign spi_tx_reg_write = Bus2IP_WrCE[1];
401
402    //spi_tx_reg_write (Bus2IP_WrCE[1]) de-asserts as soon as transaction is ACK'd
403    // so this mux switches back to the generic ACK as soon as the SPI xfer is done
404    //Thus, the duration of assertion for spi_xfer_done doesn't really matter
405    //A bit fast-n-loose, but works ok
406    assign IP2Bus_WrAck = spi_tx_reg_write ? spi_xfer_done : slv_write_ack;
407
408    //SPI device chip selects are active low
409    assign RFA_AD_spi_cs_n = ~(RFA_AD_spi_cs & spi_cs);
410    assign RFB_AD_spi_cs_n = ~(RFB_AD_spi_cs & spi_cs);
411   
412    //Mask each device's SPI clock output by its CS; no point toggling signals that will be ignored
413    assign RFA_AD_spi_sclk = (spi_sclk & RFA_AD_spi_cs);
414    assign RFB_AD_spi_sclk = (spi_sclk & RFB_AD_spi_cs);
415
416    //All SPI devices driven by same serial data output; CS signals control who listens
417    assign RFA_AD_spi_mosi = RFA_AD_spi_cs ? spi_mosi : 1'b0;
418    assign RFB_AD_spi_mosi = RFB_AD_spi_cs ? spi_mosi : 1'b0;
419   
420    //AD9963 SPI data is bi-directional; IOBUFs instantiated here to switch I vs. O mid-transfer
421    //Set spi_sdio pins as inputs except when actively driving, to avoid accidental drive fights
422    // FPGA drives the sdio pin when:
423    //   An SPI transaction is in progress AND
424    //     The transaction is a read AND the current bit is part of the instruction bytes
425    //      OR
426    //     The transaction is a write
427    assign RFA_AD_spi_sdio_output_en = spi_cs & ( (spi_rnw & (spi_bitNum < `AD9963_SPI_FIRST_RXBIT)) | (~spi_rnw));
428    assign RFB_AD_spi_sdio_output_en = spi_cs & ( (spi_rnw & (spi_bitNum < `AD9963_SPI_FIRST_RXBIT)) | (~spi_rnw));
429
430    IOBUF IOBUF_RFA_AD_sdio (
431        .IO(RFA_AD_spi_sdio), //Connected to actual FPGA pin
432        .I(RFA_AD_spi_mosi), //Logic-> Pad, input to OBUFT
433        .O(RFA_AD_spi_miso), //Pad-> Logic, output of IBUF
434        .T(~RFA_AD_spi_sdio_output_en)
435    );
436
437    IOBUF IOBUF_RFB_AD_sdio (
438        .IO(RFB_AD_spi_sdio), //Connected to actual FPGA pin
439        .I(RFB_AD_spi_mosi), //Logic-> Pad, input to OBUFT
440        .O(RFB_AD_spi_miso), //Pad-> Logic, output of IBUF
441        .T(~RFB_AD_spi_sdio_output_en)
442    );
443
444    warp_spi_io #(.SPI_XFER_LEN(`AD9963_SPI_XFER_LEN)) spi_io
445    (
446        .sys_clk(Bus2IP_Clk),
447        .reset(Bus2IP_Reset),
448        .go(spi_tx_reg_write),
449        .done(spi_xfer_done),
450        .clkDiv(clk_div_sel),
451
452        .currBitNum(spi_bitNum),
453
454        .txData(slv_reg1),
455
456        .rxData1(RFA_AD_spi_rxData),
457        .rxData2(RFB_AD_spi_rxData),
458        .rxData3(),
459        .rxData4(),
460       
461        .spi_cs(spi_cs),
462        .spi_sclk(spi_sclk),
463
464        .spi_mosi(spi_mosi),
465       
466        .spi_miso1(RFA_AD_spi_miso),
467        .spi_miso2(RFB_AD_spi_miso),
468        .spi_miso3(1'b0),
469        .spi_miso4(1'b0)
470    );
471   
472endmodule
Note: See TracBrowser for help on using the repository browser.