[4287] | 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: Sat Feb 23 21:53:35 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 | at_boot_clk_in, |
---|
| 58 | at_boot_clk_in_valid, |
---|
| 59 | at_boot_clkbuf_clocks_invalid, |
---|
| 60 | at_boot_config_sw, |
---|
| 61 | |
---|
[4294] | 62 | uart_tx, |
---|
| 63 | |
---|
| 64 | iic_eeprom_scl_I, |
---|
| 65 | iic_eeprom_scl_O, |
---|
| 66 | iic_eeprom_scl_T, |
---|
| 67 | |
---|
| 68 | iic_eeprom_sda_I, |
---|
| 69 | iic_eeprom_sda_O, |
---|
| 70 | iic_eeprom_sda_T, |
---|
| 71 | |
---|
[4287] | 72 | samp_spi_sclk, |
---|
| 73 | samp_spi_mosi, |
---|
| 74 | samp_spi_miso, |
---|
| 75 | samp_spi_cs_n, |
---|
| 76 | samp_func, |
---|
| 77 | |
---|
| 78 | rfref_spi_sclk, |
---|
| 79 | rfref_spi_mosi, |
---|
| 80 | rfref_spi_miso, |
---|
| 81 | rfref_spi_cs_n, |
---|
| 82 | rfref_func, |
---|
| 83 | |
---|
| 84 | cm_spi_sclk, |
---|
| 85 | cm_spi_mosi, |
---|
| 86 | cm_spi_miso, |
---|
| 87 | cm_spi_cs_n, |
---|
| 88 | cm_pll_status, |
---|
| 89 | |
---|
[4295] | 90 | pll_refclk, |
---|
[4287] | 91 | |
---|
| 92 | usr_reset0, |
---|
| 93 | usr_reset1, |
---|
| 94 | usr_reset2, |
---|
| 95 | usr_reset3, |
---|
| 96 | |
---|
| 97 | usr_status, |
---|
| 98 | // -- ADD USER PORTS ABOVE THIS LINE --------------- |
---|
| 99 | |
---|
| 100 | // -- DO NOT EDIT BELOW THIS LINE ------------------ |
---|
| 101 | // -- Bus protocol ports, do not add to or delete |
---|
| 102 | Bus2IP_Clk, // Bus to IP clock |
---|
| 103 | Bus2IP_Resetn, // Bus to IP reset |
---|
| 104 | Bus2IP_Data, // Bus to IP data bus |
---|
| 105 | Bus2IP_BE, // Bus to IP byte enables |
---|
| 106 | Bus2IP_RdCE, // Bus to IP read chip enable |
---|
| 107 | Bus2IP_WrCE, // Bus to IP write chip enable |
---|
| 108 | IP2Bus_Data, // IP to Bus data bus |
---|
| 109 | IP2Bus_RdAck, // IP to Bus read transfer acknowledgement |
---|
| 110 | IP2Bus_WrAck, // IP to Bus write transfer acknowledgement |
---|
| 111 | IP2Bus_Error // IP to Bus error response |
---|
| 112 | // -- DO NOT EDIT ABOVE THIS LINE ------------------ |
---|
| 113 | ); // user_logic |
---|
| 114 | |
---|
| 115 | // -- ADD USER PARAMETERS BELOW THIS LINE ------------ |
---|
| 116 | // --USER parameters added here |
---|
| 117 | // -- ADD USER PARAMETERS ABOVE THIS LINE ------------ |
---|
| 118 | |
---|
| 119 | // -- DO NOT EDIT BELOW THIS LINE -------------------- |
---|
| 120 | // -- Bus protocol parameters, do not add to or delete |
---|
| 121 | parameter C_NUM_REG = 8; |
---|
| 122 | parameter C_SLV_DWIDTH = 32; |
---|
| 123 | // -- DO NOT EDIT ABOVE THIS LINE -------------------- |
---|
| 124 | |
---|
| 125 | // -- ADD USER PORTS BELOW THIS LINE ----------------- |
---|
| 126 | |
---|
| 127 | input at_boot_clk_in; |
---|
| 128 | input at_boot_clk_in_valid; |
---|
| 129 | output at_boot_clkbuf_clocks_invalid; |
---|
| 130 | input [2:0] at_boot_config_sw; |
---|
| 131 | |
---|
[4294] | 132 | output uart_tx; |
---|
| 133 | |
---|
| 134 | input iic_eeprom_scl_I; |
---|
| 135 | output iic_eeprom_scl_O; |
---|
| 136 | output iic_eeprom_scl_T; |
---|
| 137 | |
---|
| 138 | input iic_eeprom_sda_I; |
---|
| 139 | output iic_eeprom_sda_O; |
---|
| 140 | output iic_eeprom_sda_T; |
---|
| 141 | |
---|
[4287] | 142 | output samp_spi_sclk; |
---|
| 143 | output samp_spi_mosi; |
---|
| 144 | input samp_spi_miso; |
---|
| 145 | output samp_spi_cs_n; |
---|
| 146 | output samp_func; |
---|
| 147 | |
---|
| 148 | output rfref_spi_sclk; |
---|
| 149 | output rfref_spi_mosi; |
---|
| 150 | input rfref_spi_miso; |
---|
| 151 | output rfref_spi_cs_n; |
---|
| 152 | output rfref_func; |
---|
| 153 | |
---|
| 154 | output cm_spi_sclk; |
---|
| 155 | output cm_spi_mosi; |
---|
| 156 | input cm_spi_miso; |
---|
| 157 | output cm_spi_cs_n; |
---|
| 158 | input cm_pll_status; |
---|
[4295] | 159 | input pll_refclk; |
---|
[4287] | 160 | |
---|
| 161 | output usr_reset0; |
---|
| 162 | output usr_reset1; |
---|
| 163 | output usr_reset2; |
---|
| 164 | output usr_reset3; |
---|
| 165 | |
---|
| 166 | input [31:0] usr_status; |
---|
| 167 | // -- ADD USER PORTS ABOVE THIS LINE ----------------- |
---|
| 168 | |
---|
| 169 | // -- DO NOT EDIT BELOW THIS LINE -------------------- |
---|
| 170 | // -- Bus protocol ports, do not add to or delete |
---|
| 171 | input Bus2IP_Clk; |
---|
| 172 | input Bus2IP_Resetn; |
---|
| 173 | input [C_SLV_DWIDTH-1 : 0] Bus2IP_Data; |
---|
| 174 | input [C_SLV_DWIDTH/8-1 : 0] Bus2IP_BE; |
---|
| 175 | input [C_NUM_REG-1 : 0] Bus2IP_RdCE; |
---|
| 176 | input [C_NUM_REG-1 : 0] Bus2IP_WrCE; |
---|
| 177 | output [C_SLV_DWIDTH-1 : 0] IP2Bus_Data; |
---|
| 178 | output IP2Bus_RdAck; |
---|
| 179 | output IP2Bus_WrAck; |
---|
| 180 | output IP2Bus_Error; |
---|
| 181 | // -- DO NOT EDIT ABOVE THIS LINE -------------------- |
---|
| 182 | |
---|
| 183 | //---------------------------------------------------------------------------- |
---|
| 184 | // Implementation |
---|
| 185 | //---------------------------------------------------------------------------- |
---|
| 186 | |
---|
| 187 | // --USER nets declarations added here, as needed for user logic |
---|
| 188 | |
---|
| 189 | // Nets for user logic slave model s/w accessible register example |
---|
| 190 | reg [C_SLV_DWIDTH-1 : 0] slv_reg0; |
---|
| 191 | reg [C_SLV_DWIDTH-1 : 0] slv_reg1; |
---|
| 192 | reg [C_SLV_DWIDTH-1 : 0] slv_reg2; |
---|
| 193 | reg [C_SLV_DWIDTH-1 : 0] slv_reg3; |
---|
| 194 | reg [C_SLV_DWIDTH-1 : 0] slv_reg4; |
---|
| 195 | reg [C_SLV_DWIDTH-1 : 0] slv_reg5; |
---|
| 196 | reg [C_SLV_DWIDTH-1 : 0] slv_reg6; |
---|
| 197 | reg [C_SLV_DWIDTH-1 : 0] slv_reg7; |
---|
| 198 | wire [7 : 0] slv_reg_write_sel; |
---|
| 199 | wire [7 : 0] slv_reg_read_sel; |
---|
| 200 | reg [C_SLV_DWIDTH-1 : 0] slv_ip2bus_data; |
---|
| 201 | wire slv_read_ack; |
---|
| 202 | wire slv_write_ack; |
---|
| 203 | integer byte_index, bit_index; |
---|
| 204 | |
---|
| 205 | // USER logic implementation added here |
---|
| 206 | |
---|
| 207 | // ------------------------------------------------------ |
---|
| 208 | // Example code to read/write user logic slave model s/w accessible registers |
---|
| 209 | // |
---|
| 210 | // Note: |
---|
| 211 | // The example code presented here is to show you one way of reading/writing |
---|
| 212 | // software accessible registers implemented in the user logic slave model. |
---|
| 213 | // Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to correspond |
---|
| 214 | // to one software accessible register by the top level template. For example, |
---|
| 215 | // if you have four 32 bit software accessible registers in the user logic, |
---|
| 216 | // you are basically operating on the following memory mapped registers: |
---|
| 217 | // |
---|
| 218 | // Bus2IP_WrCE/Bus2IP_RdCE Memory Mapped Register |
---|
| 219 | // "1000" C_BASEADDR + 0x0 |
---|
| 220 | // "0100" C_BASEADDR + 0x4 |
---|
| 221 | // "0010" C_BASEADDR + 0x8 |
---|
| 222 | // "0001" C_BASEADDR + 0xC |
---|
| 223 | // |
---|
| 224 | // ------------------------------------------------------ |
---|
| 225 | |
---|
| 226 | wire [7:0] samp_spi_rx_byte; |
---|
| 227 | wire [7:0] rfref_spi_rx_byte; |
---|
| 228 | wire [7:0] cm_spi_rx_byte; |
---|
| 229 | |
---|
| 230 | reg [31:0] usr_status_d, usr_status_d1, usr_status_d2; |
---|
| 231 | |
---|
| 232 | assign slv_reg_write_sel = Bus2IP_WrCE[7:0]; |
---|
| 233 | assign slv_reg_read_sel = Bus2IP_RdCE[7:0]; |
---|
| 234 | |
---|
| 235 | //Removed [6] from _ack list, so slv_reg1 ack can be delayed following write to SPI Tx register |
---|
| 236 | assign slv_write_ack = Bus2IP_WrCE[0] || Bus2IP_WrCE[1] || Bus2IP_WrCE[2] || Bus2IP_WrCE[3] || Bus2IP_WrCE[4] || Bus2IP_WrCE[5] || Bus2IP_WrCE[7]; |
---|
| 237 | 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]; |
---|
| 238 | |
---|
| 239 | // implement slave model register(s) |
---|
| 240 | always @( posedge Bus2IP_Clk ) |
---|
| 241 | begin |
---|
| 242 | |
---|
| 243 | if ( Bus2IP_Resetn == 1'b0 ) |
---|
| 244 | begin |
---|
| 245 | slv_reg0 <= 0; |
---|
| 246 | slv_reg1 <= 0; |
---|
| 247 | slv_reg2 <= 0; |
---|
| 248 | slv_reg3 <= 0; |
---|
| 249 | slv_reg4 <= 0; |
---|
| 250 | slv_reg5 <= 0; |
---|
| 251 | slv_reg6 <= 0; |
---|
| 252 | slv_reg7 <= 0; |
---|
| 253 | end |
---|
| 254 | else |
---|
| 255 | case ( slv_reg_write_sel ) |
---|
| 256 | 8'b10000000 : |
---|
| 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_reg0[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
| 260 | 8'b01000000 : |
---|
| 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_reg1[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
| 264 | 8'b00100000 : |
---|
| 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_reg2[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
| 268 | 8'b00010000 : |
---|
| 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_reg3[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
| 272 | 8'b00001000 : |
---|
| 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_reg4[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
| 276 | 8'b00000100 : |
---|
| 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_reg5[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
| 280 | 8'b00000010 : |
---|
| 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_reg6[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
| 284 | 8'b00000001 : |
---|
| 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_reg7[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8]; |
---|
| 288 | default : begin |
---|
| 289 | slv_reg0 <= slv_reg0; |
---|
| 290 | slv_reg1 <= slv_reg1; |
---|
| 291 | slv_reg2 <= slv_reg2; |
---|
| 292 | slv_reg3 <= slv_reg3; |
---|
| 293 | slv_reg4 <= slv_reg4; |
---|
| 294 | slv_reg5 <= slv_reg5; |
---|
| 295 | slv_reg6 <= slv_reg6; |
---|
| 296 | slv_reg7 <= slv_reg7; |
---|
| 297 | end |
---|
| 298 | endcase |
---|
| 299 | |
---|
| 300 | end // SLAVE_REG_WRITE_PROC |
---|
| 301 | |
---|
| 302 | // implement slave model register read mux |
---|
| 303 | always @* |
---|
| 304 | begin |
---|
| 305 | |
---|
| 306 | case ( slv_reg_read_sel ) |
---|
| 307 | 8'b10000000 : slv_ip2bus_data <= {cm_pll_status, at_boot_config_sw, 12'b0, slv_reg0[15:0]}; |
---|
| 308 | 8'b01000000 : slv_ip2bus_data <= slv_reg1; |
---|
| 309 | 8'b00100000 : slv_ip2bus_data <= {8'b0, cm_spi_rx_byte, rfref_spi_rx_byte, samp_spi_rx_byte}; |
---|
| 310 | 8'b00010000 : slv_ip2bus_data <= slv_reg3; |
---|
| 311 | 8'b00001000 : slv_ip2bus_data <= usr_status_d; |
---|
| 312 | 8'b00000100 : slv_ip2bus_data <= slv_reg5; |
---|
| 313 | 8'b00000010 : slv_ip2bus_data <= slv_reg6; |
---|
| 314 | 8'b00000001 : slv_ip2bus_data <= slv_reg7; |
---|
| 315 | default : slv_ip2bus_data <= 0; |
---|
| 316 | endcase |
---|
| 317 | |
---|
| 318 | end // SLAVE_REG_READ_PROC |
---|
| 319 | |
---|
| 320 | // ------------------------------------------------------------ |
---|
| 321 | // Example code to drive IP to Bus signals |
---|
| 322 | // ------------------------------------------------------------ |
---|
| 323 | |
---|
| 324 | assign IP2Bus_Data = (slv_read_ack == 1'b1) ? slv_ip2bus_data : 0 ; |
---|
| 325 | // assign IP2Bus_WrAck = slv_write_ack; //Overridden below |
---|
| 326 | assign IP2Bus_RdAck = slv_read_ack; |
---|
| 327 | assign IP2Bus_Error = 0; |
---|
| 328 | |
---|
| 329 | /* Address map: |
---|
| 330 | HDL is coded [MSB:LSB] = [31:0] |
---|
| 331 | regX[31] maps to 0x80000000 in C driver |
---|
| 332 | regX[0] maps to 0x00000001 in C driver |
---|
| 333 | |
---|
| 334 | 0: Config: |
---|
| 335 | [ 2: 0] Clock divider bit sel (00=0.5*busclk, 01=0.25*busclk, ...) 0x00000003 |
---|
| 336 | [ 3] Reserved |
---|
| 337 | [ 4] samp buf reset (active low) 0x00000010 |
---|
| 338 | [ 5] rf ref buf reset (active low) 0x00000020 |
---|
| 339 | [15: 6] Reserved 0x0000FFC0 |
---|
| 340 | [31:16] Clock module status 0xFFFF0000 |
---|
| 341 | |
---|
| 342 | 1: SPI Tx |
---|
| 343 | [ 7: 0] Tx data byte |
---|
| 344 | [14: 8] 7-bit register address (0x00 to 0xFF all valid) |
---|
| 345 | [20:15] 6'b0 (always zero) |
---|
| 346 | [22:21] Num bytes to Tx/Rx; must be 2'b0 for 1-byte Tx/Rx |
---|
| 347 | [ 23] RW# 1=Read, 0=Write |
---|
| 348 | [ 24] samp clock buffer chip select mask |
---|
| 349 | [ 25] rf ref clk buffer chip select mask |
---|
| 350 | [ 26] clock module clk buffer chip select mask |
---|
| 351 | [31:27] Reserved |
---|
| 352 | |
---|
| 353 | 2: SPI Rx: {samp_rxByte, rfref_rxByte, 16'b0} |
---|
| 354 | [ 7: 0] SPI Rx byte for samp buf 0x0000FF |
---|
| 355 | [15: 8] SPI Rx byte for rf ref buf 0x00FF00 |
---|
| 356 | [23:16] SPI Rx byte for clock module 0xFF0000 |
---|
| 357 | [31:24] Reserved 0xFF000000 |
---|
| 358 | |
---|
| 359 | 3: RW: User reset outputs |
---|
| 360 | [0] usr_reset0 |
---|
| 361 | [1] usr_reset1 |
---|
| 362 | [2] usr_reset2 |
---|
| 363 | [3] usr_reset3 |
---|
| 364 | [31:4] reserved |
---|
| 365 | |
---|
| 366 | 4: RO: User status inputs |
---|
| 367 | [31: 0] usr_status input |
---|
| 368 | |
---|
| 369 | 5-15: Reserved |
---|
| 370 | */ |
---|
| 371 | `define AD9512_SPI_XFER_LEN 5'd24 |
---|
| 372 | |
---|
| 373 | wire spi_mosi; |
---|
| 374 | wire spi_sclk; |
---|
| 375 | wire spi_cs; |
---|
| 376 | wire spi_rnw; |
---|
| 377 | wire spi_tx_reg_write; |
---|
| 378 | wire [2:0] clk_div_sel; |
---|
| 379 | wire spi_xfer_done; |
---|
| 380 | |
---|
| 381 | wire samp_spi_cs, rfref_spi_cs, cm_spi_cs; |
---|
| 382 | |
---|
| 383 | wire [31:0] samp_spi_rxData; |
---|
| 384 | wire [31:0] rfref_spi_rxData; |
---|
| 385 | wire [31:0] cm_spi_rxData; |
---|
| 386 | |
---|
| 387 | //Register the usr_status input here, to ease timing closure of potentially fast host PLBs |
---|
| 388 | always @(posedge Bus2IP_Clk) |
---|
| 389 | begin |
---|
| 390 | usr_status_d1 <= usr_status; |
---|
| 391 | usr_status_d2 <= usr_status_d1; |
---|
| 392 | usr_status_d <= usr_status_d2; |
---|
| 393 | end |
---|
| 394 | |
---|
| 395 | //Extract bits from IPIF slave registers and control signals |
---|
| 396 | |
---|
| 397 | //spi_io stores 32 bits for Tx/Rx |
---|
| 398 | // AD9512 only outputs 8-bit words during reads, always the last 8 bits of the transfer |
---|
| 399 | assign samp_spi_rx_byte = samp_spi_rxData[7:0]; |
---|
| 400 | assign rfref_spi_rx_byte = rfref_spi_rxData[7:0]; |
---|
| 401 | assign cm_spi_rx_byte = cm_spi_rxData[7:0]; |
---|
| 402 | |
---|
| 403 | //SPI clock divider selection |
---|
| 404 | assign clk_div_sel = slv_reg0[2:0]; //0x3 from driver |
---|
| 405 | |
---|
| 406 | //SPI device resets (active low) |
---|
| 407 | assign samp_func = 1'b1;//slv_reg0[4]; //0x10 from driver |
---|
| 408 | assign rfref_func = 1'b1;//slv_reg0[5]; //0x20 from driver |
---|
| 409 | |
---|
| 410 | //SPI device chip selects (active high; inverted before use below) |
---|
| 411 | assign samp_spi_cs = slv_reg1[24]; //0x01000000 from driver |
---|
| 412 | assign rfref_spi_cs = slv_reg1[25]; //0x02000000 from driver |
---|
| 413 | assign cm_spi_cs = slv_reg1[26]; //0x04000000 from driver |
---|
| 414 | |
---|
| 415 | //User reset outputs |
---|
| 416 | assign usr_reset0 = slv_reg3[0]; |
---|
| 417 | assign usr_reset1 = slv_reg3[1]; |
---|
| 418 | assign usr_reset2 = slv_reg3[2]; |
---|
| 419 | assign usr_reset3 = slv_reg3[3]; |
---|
| 420 | |
---|
| 421 | //Use the IPIC write-enable for the SPI Tx register as the SPI go |
---|
| 422 | // The bus will be paused until this core ACKs the write |
---|
| 423 | assign spi_tx_reg_write = Bus2IP_WrCE[6];//WrCE/RdCE busses are addressed CE[7:0]=slv_reg[0:7] |
---|
| 424 | |
---|
| 425 | //spi_tx_reg_write (Bus2IP_WrCE[6]) de-asserts as soon as transaction is ACK'd |
---|
| 426 | // so this mux switches back to the generic ACK as soon as the SPI xfer is done |
---|
| 427 | //Thus, the duration of assertion for spi_xfer_done doesn't really matter |
---|
| 428 | //A bit fast-n-loose, but works ok |
---|
| 429 | assign IP2Bus_WrAck = spi_tx_reg_write ? spi_xfer_done : slv_write_ack; |
---|
| 430 | |
---|
| 431 | //SPI device chip selects are active low |
---|
| 432 | //assign samp_spi_cs_n = ~(samp_spi_cs & spi_cs); //Overridden by at-boot logic |
---|
| 433 | //assign rfref_spi_cs_n = ~(rfref_spi_cs & spi_cs); |
---|
| 434 | //assign cm_spi_cs_n = ~(cm_spi_cs & spi_cs); |
---|
| 435 | |
---|
| 436 | //Mask each device's SPI clock output by its CS; no point toggling signals that will be ignored |
---|
| 437 | //assign samp_spi_sclk = (spi_sclk & samp_spi_cs); |
---|
| 438 | //assign rfref_spi_sclk = (spi_sclk & rfref_spi_cs); |
---|
| 439 | //assign cm_spi_sclk = (spi_sclk & cm_spi_cs); |
---|
| 440 | |
---|
| 441 | //All SPI devices driven by same serial data output; CS signals control who listens |
---|
| 442 | //assign samp_spi_mosi = samp_spi_cs ? spi_mosi : 1'b0; |
---|
| 443 | //assign rfref_spi_mosi = rfref_spi_cs ? spi_mosi : 1'b0; |
---|
| 444 | //assign cm_spi_mosi = cm_spi_cs ? spi_mosi : 1'b0; |
---|
| 445 | |
---|
| 446 | warp_spi_io #(.SPI_XFER_LEN(`AD9512_SPI_XFER_LEN)) spi_io |
---|
| 447 | ( |
---|
| 448 | .sys_clk(Bus2IP_Clk), |
---|
| 449 | .reset(~Bus2IP_Resetn), //warp_spi_io reset is active high |
---|
| 450 | .go(spi_tx_reg_write), |
---|
| 451 | .done(spi_xfer_done), |
---|
| 452 | .clkDiv(clk_div_sel), |
---|
| 453 | |
---|
| 454 | .currBitNum(), |
---|
| 455 | |
---|
| 456 | .txData(slv_reg1), |
---|
| 457 | |
---|
| 458 | .rxData1(samp_spi_rxData), |
---|
| 459 | .rxData2(rfref_spi_rxData), |
---|
| 460 | .rxData3(cm_spi_rxData), |
---|
| 461 | .rxData4(), |
---|
| 462 | |
---|
| 463 | .spi_cs(spi_cs), |
---|
| 464 | .spi_sclk(spi_sclk), |
---|
| 465 | |
---|
| 466 | .spi_mosi(spi_mosi), |
---|
| 467 | |
---|
| 468 | .spi_miso1(samp_spi_miso), |
---|
| 469 | .spi_miso2(rfref_spi_miso), |
---|
| 470 | .spi_miso3(cm_spi_miso), |
---|
| 471 | .spi_miso4(1'b0) |
---|
| 472 | ); |
---|
| 473 | |
---|
| 474 | /* At-boot Clock Config Logic |
---|
| 475 | This logic writes registers in the sampling clock AD9512 to: |
---|
| 476 | -Select the clock source (on-board oscillator or off-board via clock mod header) |
---|
| 477 | -Set the AD9512->FPGA divider to 1 (defaults to 2 on AD9512 reset) |
---|
| 478 | */ |
---|
| 479 | |
---|
| 480 | wire at_boot_clk_samp_spi_sclk; |
---|
| 481 | wire at_boot_clk_samp_spi_mosi; |
---|
| 482 | wire at_boot_clk_samp_spi_cs_n; |
---|
| 483 | |
---|
| 484 | wire at_boot_clk_rfref_spi_sclk; |
---|
| 485 | wire at_boot_clk_rfref_spi_mosi; |
---|
| 486 | wire at_boot_clk_rfref_spi_cs_n; |
---|
| 487 | |
---|
| 488 | wire at_boot_cm_spi_sclk; |
---|
| 489 | wire at_boot_cm_spi_mosi; |
---|
| 490 | wire at_boot_cm_spi_cs_n; |
---|
| 491 | |
---|
| 492 | wire clk_config_done; |
---|
| 493 | |
---|
| 494 | at_boot_clk_config boot_clk_config ( |
---|
| 495 | .clk(at_boot_clk_in), |
---|
[4288] | 496 | .clk_valid(at_boot_clk_in_valid), |
---|
[4287] | 497 | .pll_refclk(pll_refclk), |
---|
| 498 | |
---|
| 499 | .leds_red(), |
---|
| 500 | .leds_green(), |
---|
| 501 | |
---|
| 502 | .cm_switch(at_boot_config_sw), |
---|
| 503 | |
---|
[4294] | 504 | .uart_tx(uart_tx), |
---|
[4287] | 505 | |
---|
[4294] | 506 | .iic_eeprom_scl_I(iic_eeprom_scl_I), |
---|
| 507 | .iic_eeprom_scl_O(iic_eeprom_scl_O), |
---|
| 508 | .iic_eeprom_scl_T(iic_eeprom_scl_T), |
---|
| 509 | |
---|
| 510 | .iic_eeprom_sda_I(iic_eeprom_sda_I), |
---|
| 511 | .iic_eeprom_sda_O(iic_eeprom_sda_O), |
---|
| 512 | .iic_eeprom_sda_T(iic_eeprom_sda_T), |
---|
[4287] | 513 | |
---|
| 514 | .samp_spi_sclk(at_boot_clk_samp_spi_sclk), |
---|
| 515 | .samp_spi_mosi(at_boot_clk_samp_spi_mosi), |
---|
| 516 | .samp_spi_cs_n(at_boot_clk_samp_spi_cs_n), |
---|
| 517 | |
---|
| 518 | .rfref_spi_sclk(at_boot_clk_rfref_spi_sclk), |
---|
| 519 | .rfref_spi_mosi(at_boot_clk_rfref_spi_mosi), |
---|
| 520 | .rfref_spi_cs_n(at_boot_clk_rfref_spi_cs_n), |
---|
| 521 | |
---|
| 522 | .cm_spi_sclk(at_boot_cm_spi_sclk), |
---|
| 523 | .cm_spi_mosi(at_boot_cm_spi_mosi), |
---|
| 524 | .cm_spi_cs_n(at_boot_cm_spi_cs_n), |
---|
| 525 | |
---|
| 526 | .cm_pll_status(cm_pll_status), |
---|
| 527 | |
---|
| 528 | .clk_config_done(clk_config_done) |
---|
| 529 | ); |
---|
| 530 | |
---|
| 531 | //Mux all SPI outputs between at-boot logic and post-boot (software-controlled) SPI master |
---|
| 532 | assign samp_spi_sclk = clk_config_done ? (samp_spi_cs & spi_sclk) : at_boot_clk_samp_spi_sclk; |
---|
| 533 | assign samp_spi_mosi = clk_config_done ? (samp_spi_cs ? spi_mosi : 1'b0) : at_boot_clk_samp_spi_mosi; |
---|
| 534 | assign samp_spi_cs_n = clk_config_done ? (~(samp_spi_cs & spi_cs)) : at_boot_clk_samp_spi_cs_n; |
---|
| 535 | |
---|
| 536 | assign rfref_spi_sclk = clk_config_done ? (rfref_spi_cs & spi_sclk) : at_boot_clk_rfref_spi_sclk; |
---|
| 537 | assign rfref_spi_mosi = clk_config_done ? (rfref_spi_cs ? spi_mosi : 1'b0) : at_boot_clk_rfref_spi_mosi; |
---|
| 538 | assign rfref_spi_cs_n = clk_config_done ? (~(rfref_spi_cs & spi_cs)) : at_boot_clk_rfref_spi_cs_n; |
---|
| 539 | |
---|
| 540 | assign cm_spi_sclk = clk_config_done ? (cm_spi_cs & spi_sclk) : at_boot_cm_spi_sclk; |
---|
| 541 | assign cm_spi_mosi = clk_config_done ? (cm_spi_cs ? spi_mosi : 1'b0) : at_boot_cm_spi_mosi; |
---|
| 542 | assign cm_spi_cs_n = clk_config_done ? (~(cm_spi_cs & spi_cs)) : at_boot_cm_spi_cs_n; |
---|
| 543 | |
---|
| 544 | assign at_boot_clkbuf_clocks_invalid = ~clk_config_done; |
---|
| 545 | |
---|
| 546 | endmodule |
---|