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

Last change on this file was 5058, checked in by welsh, 8 years ago

EEPROM core v 1.02.a: Added support for multi-cpu environment; Caching of WARP data (SN, FPGA DNA, MAC addresses) on init.

File size: 22.3 KB
Line 
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:           1.00.b
28// Description:       User logic module.
29// Date:              Sat Feb 23 20:58:52 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
54module user_logic
55(
56  // -- ADD USER PORTS BELOW THIS LINE ---------------
57  iic_sda_I,
58  iic_sda_O,
59  iic_sda_T,
60
61  iic_scl_I,
62  iic_scl_O,
63  iic_scl_T,
64  // -- ADD USER PORTS ABOVE THIS LINE ---------------
65
66  // -- DO NOT EDIT BELOW THIS LINE ------------------
67  // -- Bus protocol ports, do not add to or delete
68  Bus2IP_Clk,                     // Bus to IP clock
69  Bus2IP_Resetn,                  // Bus to IP reset
70  Bus2IP_Data,                    // Bus to IP data bus
71  Bus2IP_BE,                      // Bus to IP byte enables
72  Bus2IP_RdCE,                    // Bus to IP read chip enable
73  Bus2IP_WrCE,                    // Bus to IP write chip enable
74  IP2Bus_Data,                    // IP to Bus data bus
75  IP2Bus_RdAck,                   // IP to Bus read transfer acknowledgement
76  IP2Bus_WrAck,                   // IP to Bus write transfer acknowledgement
77  IP2Bus_Error                    // IP to Bus error response
78  // -- DO NOT EDIT ABOVE THIS LINE ------------------
79); // user_logic
80
81// -- ADD USER PARAMETERS BELOW THIS LINE ------------
82// --USER parameters added here
83// -- ADD USER PARAMETERS ABOVE THIS LINE ------------
84
85// -- DO NOT EDIT BELOW THIS LINE --------------------
86// -- Bus protocol parameters, do not add to or delete
87parameter C_NUM_REG                      = 16;
88parameter C_SLV_DWIDTH                   = 32;
89// -- DO NOT EDIT ABOVE THIS LINE --------------------
90
91// -- ADD USER PORTS BELOW THIS LINE -----------------
92input  iic_sda_I;
93output iic_sda_O;
94output iic_sda_T;
95
96input  iic_scl_I;
97output iic_scl_O;
98output iic_scl_T;
99// -- ADD USER PORTS ABOVE THIS LINE -----------------
100
101// -- DO NOT EDIT BELOW THIS LINE --------------------
102// -- Bus protocol ports, do not add to or delete
103input                                     Bus2IP_Clk;
104input                                     Bus2IP_Resetn;
105input      [C_SLV_DWIDTH-1 : 0]           Bus2IP_Data;
106input      [C_SLV_DWIDTH/8-1 : 0]         Bus2IP_BE;
107input      [C_NUM_REG-1 : 0]              Bus2IP_RdCE;
108input      [C_NUM_REG-1 : 0]              Bus2IP_WrCE;
109output     [C_SLV_DWIDTH-1 : 0]           IP2Bus_Data;
110output                                    IP2Bus_RdAck;
111output                                    IP2Bus_WrAck;
112output                                    IP2Bus_Error;
113// -- DO NOT EDIT ABOVE THIS LINE --------------------
114
115//----------------------------------------------------------------------------
116// Implementation
117//----------------------------------------------------------------------------
118
119  // --USER nets declarations added here, as needed for user logic
120
121  // Nets for user logic slave model s/w accessible register example
122  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg00;
123  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg01;
124  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg02;
125  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg03;
126  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg04;
127  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg05;
128  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg06;
129  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg07;
130  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg08;
131  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg09;
132  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg10;
133  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg11;
134  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg12;
135  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg13;
136  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg14;
137  reg        [C_SLV_DWIDTH-1 : 0]           slv_reg15;
138  wire       [15: 0]                        slv_reg_write_sel;
139  wire       [15: 0]                        slv_reg_read_sel;
140  reg        [C_SLV_DWIDTH-1 : 0]           slv_ip2bus_data;
141  wire                                      slv_read_ack;
142  wire                                      slv_write_ack;
143  integer                                   byte_index, bit_index;
144
145  // USER logic implementation added here
146
147  // ------------------------------------------------------
148  // Example code to read/write user logic slave model s/w accessible registers
149  //
150  // Note:
151  // The example code presented here is to show you one way of reading/writing
152  // software accessible registers implemented in the user logic slave model.
153  // Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to correspond
154  // to one software accessible register by the top level template. For example,
155  // if you have four 32 bit software accessible registers in the user logic,
156  // you are basically operating on the following memory mapped registers:
157  //
158  //    Bus2IP_WrCE/Bus2IP_RdCE   Memory Mapped Register
159  //                     "1000"   C_BASEADDR + 0x0
160  //                     "0100"   C_BASEADDR + 0x4
161  //                     "0010"   C_BASEADDR + 0x8
162  //                     "0001"   C_BASEADDR + 0xC
163  //
164  // ------------------------------------------------------
165
166  assign
167    slv_reg_write_sel = Bus2IP_WrCE[15:0],
168    slv_reg_read_sel  = Bus2IP_RdCE[15:0],
169    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[14] || Bus2IP_WrCE[15],
170    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];
171
172  // implement slave model register(s)
173  always @( posedge Bus2IP_Clk )
174    begin
175
176      if ( Bus2IP_Resetn == 1'b0 )
177        begin
178          slv_reg00 <= 0;
179          slv_reg01 <= 0;
180          slv_reg02 <= 0;
181          slv_reg03 <= 0;
182          slv_reg04 <= 0;
183          slv_reg05 <= 0;
184          slv_reg06 <= 0;
185          slv_reg07 <= 0;
186          slv_reg08 <= 0;
187          slv_reg09 <= 0;
188          slv_reg10 <= 0;
189          slv_reg11 <= 0;
190          slv_reg12 <= 0;
191          slv_reg13 <= 0;
192          slv_reg14 <= 0;
193          slv_reg15 <= 0;
194        end
195      else
196        case ( slv_reg_write_sel )
197          16'b1000000000000000 :
198            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
199              if ( Bus2IP_BE[byte_index] == 1 )
200                slv_reg00[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
201          16'b0100000000000000 :
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                slv_reg01[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
205          16'b0010000000000000 :
206            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
207              if ( Bus2IP_BE[byte_index] == 1 )
208                slv_reg02[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
209          16'b0001000000000000 :
210            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
211              if ( Bus2IP_BE[byte_index] == 1 )
212                slv_reg03[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
213         
214          // Mutex register
215          //     - [31] is a "lock" bit and is always writeable
216          //     - [30:0] are writeable only if [31] is zero
217          //
218          // NOTE:  Both Bus2IP_BE and Bus2IP_Data are accessed with magic numbers vs the parameterized
219          //     values.  If the data width of the slave interface is changed, then this must be updated.
220          //
221          16'b0000100000000000 :
222            if ( slv_reg04[31] == 0 )                                                                   // Check lock bit
223              begin                                                                                     // Update all bytes that are enabled (includes lock bit)
224                for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
225                  if ( Bus2IP_BE[byte_index] == 1 )
226                    slv_reg04[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];           
227              end
228            else
229              begin                                                                                     // Update only lock bit
230                if ( Bus2IP_BE[3] == 1 )
231                  slv_reg04[31] <= Bus2IP_Data[31];
232              end
233         
234          16'b0000010000000000 :
235            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
236              if ( Bus2IP_BE[byte_index] == 1 )
237                slv_reg05[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
238          16'b0000001000000000 :
239            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
240              if ( Bus2IP_BE[byte_index] == 1 )
241                slv_reg06[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
242          16'b0000000100000000 :
243            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
244              if ( Bus2IP_BE[byte_index] == 1 )
245                slv_reg07[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
246          16'b0000000010000000 :
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                slv_reg08[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
250          16'b0000000001000000 :
251            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
252              if ( Bus2IP_BE[byte_index] == 1 )
253                slv_reg09[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
254          16'b0000000000100000 :
255            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
256              if ( Bus2IP_BE[byte_index] == 1 )
257                slv_reg10[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
258          16'b0000000000010000 :
259            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
260              if ( Bus2IP_BE[byte_index] == 1 )
261                slv_reg11[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
262          16'b0000000000001000 :
263            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
264              if ( Bus2IP_BE[byte_index] == 1 )
265                slv_reg12[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
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                slv_reg13[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
270          16'b0000000000000010 :
271            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
272              if ( Bus2IP_BE[byte_index] == 1 )
273                slv_reg14[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
274          16'b0000000000000001 :
275            for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index+1 )
276              if ( Bus2IP_BE[byte_index] == 1 )
277                slv_reg15[(byte_index*8) +: 8] <= Bus2IP_Data[(byte_index*8) +: 8];
278               
279          default : begin
280            slv_reg00 <= slv_reg00;
281            slv_reg01 <= slv_reg01;
282            slv_reg02 <= slv_reg02;
283            slv_reg03 <= slv_reg03;
284            slv_reg04 <= slv_reg04;
285            slv_reg05 <= slv_reg05;
286            slv_reg06 <= slv_reg06;
287            slv_reg07 <= slv_reg07;
288            slv_reg08 <= slv_reg08;
289            slv_reg09 <= slv_reg09;
290            slv_reg10 <= slv_reg10;
291            slv_reg11 <= slv_reg11;
292            slv_reg12 <= slv_reg12;
293            slv_reg13 <= slv_reg13;
294            slv_reg14 <= slv_reg14;
295            slv_reg15 <= slv_reg15;
296          end
297        endcase
298
299    end // SLAVE_REG_WRITE_PROC
300
301  // implement slave model register read mux
302  always @*
303    begin 
304      case ( slv_reg_read_sel )
305        16'b1000000000000000 : slv_ip2bus_data <= slv_reg00_rd;
306        16'b0100000000000000 : slv_ip2bus_data <= slv_reg01;
307        16'b0010000000000000 : slv_ip2bus_data <= slv_reg02;
308        16'b0001000000000000 : slv_ip2bus_data <= slv_reg03_rd;
309        16'b0000100000000000 : slv_ip2bus_data <= slv_reg04;
310        16'b0000010000000000 : slv_ip2bus_data <= slv_reg05;
311        16'b0000001000000000 : slv_ip2bus_data <= slv_reg06;
312        16'b0000000100000000 : slv_ip2bus_data <= slv_reg07;
313        16'b0000000010000000 : slv_ip2bus_data <= slv_reg08;
314        16'b0000000001000000 : slv_ip2bus_data <= slv_reg09;
315        16'b0000000000100000 : slv_ip2bus_data <= slv_reg10;
316        16'b0000000000010000 : slv_ip2bus_data <= slv_reg11;
317        16'b0000000000001000 : slv_ip2bus_data <= slv_reg12;
318        16'b0000000000000100 : slv_ip2bus_data <= slv_reg13;
319        16'b0000000000000010 : slv_ip2bus_data <= slv_reg14;
320        16'b0000000000000001 : slv_ip2bus_data <= slv_reg15;
321        default : slv_ip2bus_data <= 0;
322      endcase
323
324    end // SLAVE_REG_READ_PROC
325
326  // ------------------------------------------------------------
327  // Example code to drive IP to Bus signals
328  // ------------------------------------------------------------
329  assign IP2Bus_Data  = (slv_read_ack == 1'b1) ? slv_ip2bus_data :  0 ;
330  assign IP2Bus_WrAck = slv_write_ack;
331  assign IP2Bus_RdAck = slv_read_ack;
332  assign IP2Bus_Error = 0;
333
334    /* Address map:
335           HDL is coded [MSB:LSB] = [31:0]
336               regX[31] maps to 0x80000000 in C driver
337               regX[0]  maps to 0x00000001 in C driver
338
339    00: Config/Status[31: 0]: RW
340        [ 7: 0]: clk divider (see comments below for interpretation)           RW 0x000000FF
341            [8]: core enable (1=enabled, 0=disabled)                           RW 0x00000100
342        [15: 9]: Reserved (always zero)                                        RO 0x0000FE00
343           [16]: RxACK: received ACK from slave (1=received ACK)               RO 0x00010000
344           [17]: Busy: IIC bus busy (1 between Start and Stop events)          RO 0x00020000
345           [18]: AL: Arbitration lost (1 when Stop detected but not requested) RO 0x00040000
346           [19]: TIP: Transfer in progress (1 during transfer)                 RO 0x00080000
347        [31:20]: Reserved                                                      RW 0xFFF00000
348       
349    01: Command[31: 0]: RW, self-clearing, uses local reg, not normal slv_reg1
350            [0]: Start:  generate IIC start                 0x01
351            [1]: Stop:   generate IIC stop                  0x02
352            [2]: Read:   execute IIC read                   0x04
353            [3]: Write:  execute IIC write                  0x08
354            [4]: ACK:    send ACK for current transaction   0x10
355        [31: 5]: Reserved
356   
357    02: Transmit[31: 0]: {24'b0, txByte[7:0]} RW
358        [ 7: 0]: Tx Byte ([31]=RNW during control word writes)
359        [31: 8]: Reserved
360
361    03: Receive[31: 0]: {24'b0, rxByte[7:0]} RO
362        [ 7: 0]: Rx Byte
363        [31: 8]: Reserved
364   
365    04: Mutex[31: 0]: RW (with lock bit)
366        [30: 0]: User bits
367        [31]   : Lock
368   
369    05: Serial Number [31:0]: RW
370        [31: 0]: Serial Number
371   
372    06: Ethernet A MAC address 0[31: 0]: RW
373        [31: 0]: Ethernet A MAC address [31: 0]
374   
375    07: Ethernet A MAC address 1[31: 0]: RW
376        [15: 0]: Ethernet A MAC address [47:32]
377        [31:16]: Reserved
378   
379    08: Ethernet B MAC address 0[31: 0]: RW
380        [31: 0]: Ethernet B MAC address [31: 0]
381   
382    09: Ethernet B MAC address 1[31: 0]: RW
383        [15: 0]: Ethernet B MAC address [47:32]
384        [31:16]: Reserved
385   
386    10: FPGA DNA 0[31: 0]: RW
387        [31: 0]: FPGA DNA [31: 0]
388       
389    11: FPGA DNA 1[31: 0]: RW
390        [31: 0]: FPGA DNA [63:32]
391   
392    12: Reserved
393    13: Reserved
394    14: Reserved
395    15: Reserved
396   
397    */
398
399    reg [4:0] cmd_reg;
400    wire core_en;
401    wire [15:0] clk_div;
402    wire cmd_start, cmd_stop, cmd_read, cmd_write, cmd_ack;
403
404    wire [7:0] iic_tx_byte;
405    wire [7:0] iic_rx_byte;
406
407    wire iic_rx_ack;
408    wire iic_bus_busy;
409    wire iic_al;
410    wire iic_done;
411    wire iic_tip;
412   
413    wire slv_reg01_WE;
414   
415    assign slv_reg01_WE = Bus2IP_WrCE[14];       // WrCE/RdCE[15:0] map to slv_reg[0:15]
416
417    // Custom command register logic, implements self-clearing bits
418    always @( posedge Bus2IP_Clk )
419    begin
420        if ( Bus2IP_Resetn == 1'b0 )
421            cmd_reg <= 5'b0;
422        else if(slv_reg01_WE == 1'b1)
423            cmd_reg[4:0] <= Bus2IP_Data[4:0];
424        else if(iic_done | iic_al)
425        begin
426            // Clear start, stop, read, write bits on transfer completion or arbitration loss
427            cmd_reg[3:0] <= 4'b0;
428            cmd_reg[4]   <= cmd_reg[4];
429        end
430        else
431            cmd_reg[4:0] <= cmd_reg[4:0];
432    end
433   
434    assign cmd_start = cmd_reg[0]; // 0x01 from driver
435    assign cmd_stop  = cmd_reg[1]; // 0x02
436    assign cmd_read  = cmd_reg[2]; // 0x04
437    assign cmd_write = cmd_reg[3]; // 0x08
438    assign cmd_ack   = cmd_reg[4]; // 0x10
439
440    assign iic_tip = (cmd_read | cmd_write); // Register bits self-clear on transfer completion
441
442   
443    // Construct 32-bit vectors for read access to mixed RW/RO registers
444    wire [31:0] slv_reg00_rd;
445    wire [31:0] slv_reg03_rd;
446    assign slv_reg00_rd = {slv_reg00[31:20], iic_tip, iic_al, iic_bus_busy, iic_rx_ack, 7'b0, slv_reg00[8], slv_reg00[7:0]};
447    assign slv_reg03_rd = {24'b0, iic_rx_byte[7:0]};
448   
449
450    // IIC master divides down master clock to generate SCL
451    //     SCL rate is (sys_clk / (5*clk_div[0:15]))
452    //     For 200MHz sys_clk and 100kHz SCL, clk_div = 400 = 0x190
453    //     Interpret user-provided clock divider as bits[6:13] of clk_div
454    assign clk_div[15:0] = {6'b0, slv_reg00[7:0], 2'b0};
455    assign core_en       = slv_reg00[8];
456
457    assign iic_tx_byte   = slv_reg02[7:0];
458
459    wire sda_pad_i, sda_pad_o, sda_pad_oe;
460    wire scl_pad_i, scl_pad_o, scl_pad_oe;
461
462    i2c_master_byte_ctrl byte_controller (
463        .clk      ( Bus2IP_Clk ),      // master clock
464        .rst      ( ~Bus2IP_Resetn ),  // synchronous reset, active high
465        .nReset   ( 1'b1 ),            // asynchronous reset, active low
466        .ena      ( core_en ),         // core enable, active high
467        .clk_cnt  ( clk_div ),         // master-to-iic clock divider
468        .start    ( cmd_start ),       // send iic start
469        .stop     ( cmd_stop ),        // send iic stop
470        .read     ( cmd_read ),        // perform iic read
471        .write    ( cmd_write ),       // perform iic write
472        .ack_in   ( cmd_ack ),         // send iic ack
473        .din      ( iic_tx_byte ),     // byte to send
474        .cmd_ack  ( iic_done ),        // xfer is done
475        .ack_out  ( iic_rx_ack ),      // ack from slave
476        .dout     ( iic_rx_byte ),     // byte read from slave
477        .i2c_busy ( iic_bus_busy ),
478        .i2c_al   ( iic_al ),          // arbitration lost output
479        .scl_i    ( iic_scl_I ),       // iic scl input (pad -> logic)
480        .scl_o    ( iic_scl_O ),       // iic scl output (logic -> pad)
481        .scl_oen  ( iic_scl_T ),       // iic scl output enable (0=scl is logic-driven output)
482        .sda_i    ( iic_sda_I ),       // iic sda input (pad -> logic)
483        .sda_o    ( iic_sda_O ),       // iic sda output (logic -> pad)
484        .sda_oen  ( iic_sda_T )        // iic sda output enable (0=sda is logic-driven output)
485    );
486   
487endmodule
Note: See TracBrowser for help on using the repository browser.