OpenCores
URL https://opencores.org/ocsvn/iicmb/iicmb/trunk

Subversion Repositories iicmb

[/] [iicmb/] [trunk/] [src/] [iicmb_m.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sshuv2
 
2
--==============================================================================
3
--                                                                             |
4
--    Project: IIC Multiple Bus Controller (IICMB)                             |
5
--                                                                             |
6
--    Module:  I2C master controller with 'Generic Interface'.                 |
7
--    Version:                                                                 |
8
--             1.0,   April 29, 2016                                           |
9
--                                                                             |
10
--    Author:  Sergey Shuvalkin, (sshuv2@opencores.org)                        |
11
--                                                                             |
12
--==============================================================================
13
--==============================================================================
14
-- Copyright (c) 2016, Sergey Shuvalkin                                        |
15
-- All rights reserved.                                                        |
16
--                                                                             |
17
-- Redistribution and use in source and binary forms, with or without          |
18
-- modification, are permitted provided that the following conditions are met: |
19
--                                                                             |
20
-- 1. Redistributions of source code must retain the above copyright notice,   |
21
--    this list of conditions and the following disclaimer.                    |
22
-- 2. Redistributions in binary form must reproduce the above copyright        |
23
--    notice, this list of conditions and the following disclaimer in the      |
24
--    documentation and/or other materials provided with the distribution.     |
25
--                                                                             |
26
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
27
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE   |
28
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  |
29
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE    |
30
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR         |
31
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF        |
32
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS    |
33
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN     |
34
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)     |
35
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  |
36
-- POSSIBILITY OF SUCH DAMAGE.                                                 |
37
--==============================================================================
38
 
39
 
40
library ieee;
41
use ieee.std_logic_1164.all;
42
use ieee.numeric_std.all;
43
 
44
use work.iicmb_pkg.all;
45
use work.iicmb_int_pkg.all;
46
 
47
 
48
--==============================================================================
49
entity iicmb_m is
50
  generic
51
  (
52
    ------------------------------------
53
    g_bus_num   :       positive range 1 to 16 := 1;          -- Number of separate I2C buses
54
    g_f_clk     :       real                   := 100000.0;   -- Frequency of system clock 'clk' (in kHz)
55
    g_f_scl_0   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #0 (in kHz)
56
    g_f_scl_1   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #1 (in kHz)
57
    g_f_scl_2   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #2 (in kHz)
58
    g_f_scl_3   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #3 (in kHz)
59
    g_f_scl_4   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #4 (in kHz)
60
    g_f_scl_5   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #5 (in kHz)
61
    g_f_scl_6   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #6 (in kHz)
62
    g_f_scl_7   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #7 (in kHz)
63
    g_f_scl_8   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #8 (in kHz)
64
    g_f_scl_9   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #9 (in kHz)
65
    g_f_scl_a   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #10 (in kHz)
66
    g_f_scl_b   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #11 (in kHz)
67
    g_f_scl_c   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #12 (in kHz)
68
    g_f_scl_d   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #13 (in kHz)
69
    g_f_scl_e   :       real                   :=    100.0;   -- Frequency of 'SCL' clock of I2C bus #14 (in kHz)
70
    g_f_scl_f   :       real                   :=    100.0    -- Frequency of 'SCL' clock of I2C bus #15 (in kHz)
71
    ------------------------------------
72
  );
73
  port
74
  (
75
    ------------------------------------
76
    clk         : in    std_logic;                            -- Clock
77
    s_rst       : in    std_logic;                            -- Synchronous reset (active high)
78
    ------------------------------------
79
    ------------------------------------
80
    -- Status:
81
    busy        :   out std_logic;                            -- Bus busy status
82
    captured    :   out std_logic;                            -- Bus captured status
83
    bus_id      :   out std_logic_vector(3 downto 0);         -- ID of selected I2C bus
84
    bit_state   :   out std_logic_vector(3 downto 0);         -- State of bit level FSM
85
    byte_state  :   out std_logic_vector(3 downto 0);         -- State of byte level FSM
86
    ------------------------------------
87
    ------------------------------------
88
    -- 'Generic interface' signals:
89
    mcmd_wr     : in    std_logic;                            -- Byte command write (active high)
90
    mcmd_id     : in    std_logic_vector(2 downto 0);         -- Byte command ID
91
    mcmd_data   : in    std_logic_vector(7 downto 0);         -- Command data
92
    --
93
    mrsp_wr     :   out std_logic;                            -- Byte response write (active high)
94
    mrsp_id     :   out std_logic_vector(2 downto 0);         -- Byte response ID
95
    mrsp_data   :   out std_logic_vector(7 downto 0);         -- Byte Response data
96
    ------------------------------------
97
    ------------------------------------
98
    -- I2C buses:
99
    scl_i       : in    std_logic_vector(0 to g_bus_num - 1); -- I2C Clock inputs
100
    sda_i       : in    std_logic_vector(0 to g_bus_num - 1); -- I2C Data inputs
101
    scl_o       :   out std_logic_vector(0 to g_bus_num - 1); -- I2C Clock outputs
102
    sda_o       :   out std_logic_vector(0 to g_bus_num - 1)  -- I2C Data outputs
103
    ------------------------------------
104
  );
105
end entity iicmb_m;
106
--==============================================================================
107
 
108
--==============================================================================
109
architecture str of iicmb_m is
110
 
111
  ------------------------------------------------------------------------------
112
  component conditioner_mux is
113
    generic
114
    (
115
      g_bus_num :       positive range 1 to 16 := 1;
116
      g_f_clk   :       real                   := 100000.0;
117
      g_f_scl_0 :       real           :=    100.0;
118
      g_f_scl_1 :       real           :=    100.0;
119
      g_f_scl_2 :       real           :=    100.0;
120
      g_f_scl_3 :       real           :=    100.0;
121
      g_f_scl_4 :       real           :=    100.0;
122
      g_f_scl_5 :       real           :=    100.0;
123
      g_f_scl_6 :       real           :=    100.0;
124
      g_f_scl_7 :       real           :=    100.0;
125
      g_f_scl_8 :       real           :=    100.0;
126
      g_f_scl_9 :       real           :=    100.0;
127
      g_f_scl_a :       real           :=    100.0;
128
      g_f_scl_b :       real           :=    100.0;
129
      g_f_scl_c :       real           :=    100.0;
130
      g_f_scl_d :       real           :=    100.0;
131
      g_f_scl_e :       real           :=    100.0;
132
      g_f_scl_f :       real           :=    100.0
133
    );
134
    port
135
    (
136
      clk       : in    std_logic;
137
      s_rst     : in    std_logic;
138
      bus_id    : in    natural range 0 to g_bus_num - 1;
139
      busy      :   out std_logic := '0';
140
      scl_rx    :   out std_logic := '1';
141
      sda_rx    :   out std_logic := '1';
142
      scl_d_rx  :   out std_logic := '1';
143
      scl_tx    : in    std_logic;
144
      sda_tx    : in    std_logic;
145
      scl_i     : in    std_logic_vector(0 to g_bus_num - 1);
146
      sda_i     : in    std_logic_vector(0 to g_bus_num - 1);
147
      scl_o     :   out std_logic_vector(0 to g_bus_num - 1);
148
      sda_o     :   out std_logic_vector(0 to g_bus_num - 1)
149
    );
150
  end component conditioner_mux;
151
  ------------------------------------------------------------------------------
152
 
153
  ------------------------------------------------------------------------------
154
  component mbit is
155
    generic
156
    (
157
      g_bus_num :       positive range 1 to 16 := 1;
158
      g_f_clk   :       real           := 100000.0;
159
      g_f_scl_0 :       real           :=    100.0;
160
      g_f_scl_1 :       real           :=    100.0;
161
      g_f_scl_2 :       real           :=    100.0;
162
      g_f_scl_3 :       real           :=    100.0;
163
      g_f_scl_4 :       real           :=    100.0;
164
      g_f_scl_5 :       real           :=    100.0;
165
      g_f_scl_6 :       real           :=    100.0;
166
      g_f_scl_7 :       real           :=    100.0;
167
      g_f_scl_8 :       real           :=    100.0;
168
      g_f_scl_9 :       real           :=    100.0;
169
      g_f_scl_a :       real           :=    100.0;
170
      g_f_scl_b :       real           :=    100.0;
171
      g_f_scl_c :       real           :=    100.0;
172
      g_f_scl_d :       real           :=    100.0;
173
      g_f_scl_e :       real           :=    100.0;
174
      g_f_scl_f :       real           :=    100.0
175
    );
176
    port
177
    (
178
      clk       : in    std_logic;
179
      s_rst     : in    std_logic;
180
      fsm_state :   out std_logic_vector(3 downto 0);
181
      bus_id    : in    natural range 0 to g_bus_num - 1;
182
      mbc_wr    : in    std_logic;
183
      mbc       : in    mbc_type;
184
      mbr_wr    :   out std_logic      := '0';
185
      mbr       :   out mbr_type       := mbr_done;
186
      scl_i     : in    std_logic;
187
      sda_i     : in    std_logic;
188
      scl_i_d   : in    std_logic;
189
      scl_o     :   out std_logic      := '1';
190
      sda_o     :   out std_logic      := '1'
191
    );
192
  end component mbit;
193
  ------------------------------------------------------------------------------
194
 
195
  ------------------------------------------------------------------------------
196
  component mbyte is
197
    generic
198
    (
199
      g_bus_num   :       positive range 1 to 16 := 1;
200
      g_f_clk     :       real                   := 100000.0
201
    );
202
    port
203
    (
204
      clk         : in    std_logic;
205
      s_rst       : in    std_logic;
206
      captured    :   out std_logic;
207
      busy        : in    std_logic;
208
      bus_id      :   out natural range 0 to g_bus_num - 1 := 0;
209
      fsm_state   :   out std_logic_vector(3 downto 0);
210
      mcmd_wr     : in    std_logic;
211
      mcmd_id     : in    std_logic_vector(2 downto 0);
212
      mcmd_data   : in    std_logic_vector(7 downto 0);
213
      mrsp_wr     :   out std_logic                    := '0';
214
      mrsp_id     :   out std_logic_vector(2 downto 0) := mrsp_done;
215
      mrsp_data   :   out std_logic_vector(7 downto 0);
216
      mbc_wr      :   out std_logic                    := '0';
217
      mbc         :   out mbc_type                     := mbc_stop;
218
      mbr_wr      : in    std_logic;
219
      mbr         : in    mbr_type
220
    );
221
  end component mbyte;
222
  ------------------------------------------------------------------------------
223
 
224
  signal bus_id_y  : natural range 0 to g_bus_num - 1;
225
  signal busy_y    : std_logic;
226
  signal scl_rx    : std_logic;
227
  signal sda_rx    : std_logic;
228
  signal scl_d_rx  : std_logic;
229
  signal scl_tx    : std_logic;
230
  signal sda_tx    : std_logic;
231
 
232
  signal mbc_wr    : std_logic;
233
  signal mbc       : mbc_type;
234
  signal mbr_wr    : std_logic;
235
  signal mbr       : mbr_type;
236
 
237
begin
238
 
239
  busy   <= busy_y;
240
  bus_id <= std_logic_vector(to_unsigned(bus_id_y, 4));
241
 
242
  ------------------------------------------------------------------------------
243
  mbyte_inst0 : mbyte
244
    generic map
245
    (
246
      g_bus_num   => g_bus_num,
247
      g_f_clk     => g_f_clk
248
    )
249
    port map
250
    (
251
      clk         => clk,
252
      s_rst       => s_rst,
253
      captured    => captured,
254
      busy        => busy_y,
255
      bus_id      => bus_id_y,
256
      fsm_state   => byte_state,
257
      mcmd_wr     => mcmd_wr,
258
      mcmd_id     => mcmd_id,
259
      mcmd_data   => mcmd_data,
260
      mrsp_wr     => mrsp_wr,
261
      mrsp_id     => mrsp_id,
262
      mrsp_data   => mrsp_data,
263
      mbc_wr      => mbc_wr,
264
      mbc         => mbc,
265
      mbr_wr      => mbr_wr,
266
      mbr         => mbr
267
    );
268
  ------------------------------------------------------------------------------
269
 
270
  ------------------------------------------------------------------------------
271
  mbit_inst0 : mbit
272
    generic map
273
    (
274
      g_bus_num => g_bus_num,
275
      g_f_clk   => g_f_clk,
276
      g_f_scl_0 => g_f_scl_0,
277
      g_f_scl_1 => g_f_scl_1,
278
      g_f_scl_2 => g_f_scl_2,
279
      g_f_scl_3 => g_f_scl_3,
280
      g_f_scl_4 => g_f_scl_4,
281
      g_f_scl_5 => g_f_scl_5,
282
      g_f_scl_6 => g_f_scl_6,
283
      g_f_scl_7 => g_f_scl_7,
284
      g_f_scl_8 => g_f_scl_8,
285
      g_f_scl_9 => g_f_scl_9,
286
      g_f_scl_a => g_f_scl_a,
287
      g_f_scl_b => g_f_scl_b,
288
      g_f_scl_c => g_f_scl_c,
289
      g_f_scl_d => g_f_scl_d,
290
      g_f_scl_e => g_f_scl_e,
291
      g_f_scl_f => g_f_scl_f
292
    )
293
    port map
294
    (
295
      clk       => clk,
296
      s_rst     => s_rst,
297
      fsm_state => bit_state,
298
      bus_id    => bus_id_y,
299
      mbc_wr    => mbc_wr,
300
      mbc       => mbc,
301
      mbr_wr    => mbr_wr,
302
      mbr       => mbr,
303
      scl_i     => scl_rx,
304
      sda_i     => sda_rx,
305
      scl_i_d   => scl_d_rx,
306
      scl_o     => scl_tx,
307
      sda_o     => sda_tx
308
    );
309
  ------------------------------------------------------------------------------
310
 
311
  ------------------------------------------------------------------------------
312
  conditioner_mux_inst0 : conditioner_mux
313
    generic map
314
    (
315
      g_bus_num => g_bus_num,
316
      g_f_clk   => g_f_clk,
317
      g_f_scl_0 => g_f_scl_0,
318
      g_f_scl_1 => g_f_scl_1,
319
      g_f_scl_2 => g_f_scl_2,
320
      g_f_scl_3 => g_f_scl_3,
321
      g_f_scl_4 => g_f_scl_4,
322
      g_f_scl_5 => g_f_scl_5,
323
      g_f_scl_6 => g_f_scl_6,
324
      g_f_scl_7 => g_f_scl_7,
325
      g_f_scl_8 => g_f_scl_8,
326
      g_f_scl_9 => g_f_scl_9,
327
      g_f_scl_a => g_f_scl_a,
328
      g_f_scl_b => g_f_scl_b,
329
      g_f_scl_c => g_f_scl_c,
330
      g_f_scl_d => g_f_scl_d,
331
      g_f_scl_e => g_f_scl_e,
332
      g_f_scl_f => g_f_scl_f
333
    )
334
    port map
335
    (
336
      clk       => clk,
337
      s_rst     => s_rst,
338
      bus_id    => bus_id_y,
339
      busy      => busy_y,
340
      scl_rx    => scl_rx,
341
      sda_rx    => sda_rx,
342
      scl_d_rx  => scl_d_rx,
343
      scl_tx    => scl_tx,
344
      sda_tx    => sda_tx,
345
      scl_i     => scl_i,
346
      sda_i     => sda_i,
347
      scl_o     => scl_o,
348
      sda_o     => sda_o
349
    );
350
  ------------------------------------------------------------------------------
351
 
352
end architecture str;
353
--==============================================================================
354
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.