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