1 |
2 |
sshuv2 |
|
2 |
|
|
--==============================================================================
|
3 |
|
|
-- |
|
4 |
|
|
-- Project: IIC Multiple Bus Controller (IICMB) |
|
5 |
|
|
-- |
|
6 |
|
|
-- Module: Top level of IICMB controller with Avalon-MM 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 |
|
|
|
43 |
|
|
|
44 |
|
|
--==============================================================================
|
45 |
|
|
entity iicmb_m_av is
|
46 |
|
|
generic
|
47 |
|
|
(
|
48 |
|
|
------------------------------------
|
49 |
|
|
g_bus_num : positive range 1 to 16 := 1; -- Number of separate I2C buses
|
50 |
|
|
g_f_clk : real := 100000.0; -- Frequency of system clock 'clk' (in kHz)
|
51 |
|
|
g_f_scl_0 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #0 (in kHz)
|
52 |
|
|
g_f_scl_1 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #1 (in kHz)
|
53 |
|
|
g_f_scl_2 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #2 (in kHz)
|
54 |
|
|
g_f_scl_3 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #3 (in kHz)
|
55 |
|
|
g_f_scl_4 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #4 (in kHz)
|
56 |
|
|
g_f_scl_5 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #5 (in kHz)
|
57 |
|
|
g_f_scl_6 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #6 (in kHz)
|
58 |
|
|
g_f_scl_7 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #7 (in kHz)
|
59 |
|
|
g_f_scl_8 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #8 (in kHz)
|
60 |
|
|
g_f_scl_9 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #9 (in kHz)
|
61 |
|
|
g_f_scl_a : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #10 (in kHz)
|
62 |
|
|
g_f_scl_b : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #11 (in kHz)
|
63 |
|
|
g_f_scl_c : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #12 (in kHz)
|
64 |
|
|
g_f_scl_d : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #13 (in kHz)
|
65 |
|
|
g_f_scl_e : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #14 (in kHz)
|
66 |
|
|
g_f_scl_f : real := 100.0 -- Frequency of 'SCL' clock of I2C bus #15 (in kHz)
|
67 |
|
|
------------------------------------
|
68 |
|
|
);
|
69 |
|
|
port
|
70 |
|
|
(
|
71 |
|
|
------------------------------------
|
72 |
|
|
-- Avalon-MM signals:
|
73 |
|
|
clk : in std_logic; -- Clock
|
74 |
|
|
s_rst : in std_logic; -- Synchronous reset (active high)
|
75 |
|
|
-------------
|
76 |
|
|
waitrequest : out std_logic;
|
77 |
|
|
readdata : out std_logic_vector(31 downto 0);
|
78 |
|
|
readdatavalid : out std_logic;
|
79 |
|
|
writedata : in std_logic_vector(31 downto 0);
|
80 |
|
|
write : in std_logic;
|
81 |
|
|
read : in std_logic;
|
82 |
|
|
byteenable : in std_logic_vector( 3 downto 0);
|
83 |
|
|
------------------------------------
|
84 |
|
|
------------------------------------
|
85 |
|
|
-- Interrupt request:
|
86 |
|
|
irq : out std_logic; -- Interrupt request
|
87 |
|
|
------------------------------------
|
88 |
|
|
------------------------------------
|
89 |
|
|
-- I2C interfaces:
|
90 |
|
|
scl_i : in std_logic_vector(0 to g_bus_num - 1); -- I2C Clock inputs
|
91 |
|
|
sda_i : in std_logic_vector(0 to g_bus_num - 1); -- I2C Data inputs
|
92 |
|
|
scl_o : out std_logic_vector(0 to g_bus_num - 1); -- I2C Clock outputs
|
93 |
|
|
sda_o : out std_logic_vector(0 to g_bus_num - 1) -- I2C Data outputs
|
94 |
|
|
------------------------------------
|
95 |
|
|
);
|
96 |
|
|
end entity iicmb_m_av;
|
97 |
|
|
--==============================================================================
|
98 |
|
|
|
99 |
|
|
--==============================================================================
|
100 |
|
|
architecture str of iicmb_m_av is
|
101 |
|
|
|
102 |
|
|
------------------------------------------------------------------------------
|
103 |
|
|
component avalon_mm is
|
104 |
|
|
port
|
105 |
|
|
(
|
106 |
|
|
clk : in std_logic;
|
107 |
|
|
s_rst : in std_logic;
|
108 |
|
|
waitrequest : out std_logic;
|
109 |
|
|
readdata : out std_logic_vector(31 downto 0);
|
110 |
|
|
readdatavalid : out std_logic;
|
111 |
|
|
writedata : in std_logic_vector(31 downto 0);
|
112 |
|
|
write : in std_logic;
|
113 |
|
|
read : in std_logic;
|
114 |
|
|
byteenable : in std_logic_vector( 3 downto 0);
|
115 |
|
|
wr : out std_logic_vector( 3 downto 0);
|
116 |
|
|
rd : out std_logic_vector( 3 downto 0);
|
117 |
|
|
idata : out std_logic_vector(31 downto 0);
|
118 |
|
|
odata : in std_logic_vector(31 downto 0)
|
119 |
|
|
);
|
120 |
|
|
end component avalon_mm;
|
121 |
|
|
------------------------------------------------------------------------------
|
122 |
|
|
|
123 |
|
|
------------------------------------------------------------------------------
|
124 |
|
|
component regblock is
|
125 |
|
|
port
|
126 |
|
|
(
|
127 |
|
|
clk : in std_logic;
|
128 |
|
|
s_rst : in std_logic;
|
129 |
|
|
wr : in std_logic_vector( 3 downto 0);
|
130 |
|
|
rd : in std_logic_vector( 3 downto 0);
|
131 |
|
|
idata : in std_logic_vector(31 downto 0);
|
132 |
|
|
odata : out std_logic_vector(31 downto 0);
|
133 |
|
|
irq : out std_logic;
|
134 |
|
|
busy : in std_logic;
|
135 |
|
|
captured : in std_logic;
|
136 |
|
|
bus_id : in std_logic_vector( 3 downto 0);
|
137 |
|
|
bit_state : in std_logic_vector( 3 downto 0);
|
138 |
|
|
byte_state : in std_logic_vector( 3 downto 0);
|
139 |
|
|
disable : out std_logic;
|
140 |
|
|
mcmd_wr : out std_logic;
|
141 |
|
|
mcmd_id : out std_logic_vector( 2 downto 0);
|
142 |
|
|
mcmd_data : out std_logic_vector( 7 downto 0);
|
143 |
|
|
mrsp_wr : in std_logic;
|
144 |
|
|
mrsp_id : in std_logic_vector( 2 downto 0);
|
145 |
|
|
mrsp_data : in std_logic_vector( 7 downto 0)
|
146 |
|
|
);
|
147 |
|
|
end component regblock;
|
148 |
|
|
------------------------------------------------------------------------------
|
149 |
|
|
|
150 |
|
|
------------------------------------------------------------------------------
|
151 |
|
|
component iicmb_m is
|
152 |
|
|
generic
|
153 |
|
|
(
|
154 |
|
|
g_bus_num : positive range 1 to 16 := 1;
|
155 |
|
|
g_f_clk : real := 100000.0;
|
156 |
|
|
g_f_scl_0 : real := 100.0;
|
157 |
|
|
g_f_scl_1 : real := 100.0;
|
158 |
|
|
g_f_scl_2 : real := 100.0;
|
159 |
|
|
g_f_scl_3 : real := 100.0;
|
160 |
|
|
g_f_scl_4 : real := 100.0;
|
161 |
|
|
g_f_scl_5 : real := 100.0;
|
162 |
|
|
g_f_scl_6 : real := 100.0;
|
163 |
|
|
g_f_scl_7 : real := 100.0;
|
164 |
|
|
g_f_scl_8 : real := 100.0;
|
165 |
|
|
g_f_scl_9 : real := 100.0;
|
166 |
|
|
g_f_scl_a : real := 100.0;
|
167 |
|
|
g_f_scl_b : real := 100.0;
|
168 |
|
|
g_f_scl_c : real := 100.0;
|
169 |
|
|
g_f_scl_d : real := 100.0;
|
170 |
|
|
g_f_scl_e : real := 100.0;
|
171 |
|
|
g_f_scl_f : real := 100.0
|
172 |
|
|
);
|
173 |
|
|
port
|
174 |
|
|
(
|
175 |
|
|
clk : in std_logic;
|
176 |
|
|
s_rst : in std_logic;
|
177 |
|
|
busy : out std_logic;
|
178 |
|
|
captured : out std_logic;
|
179 |
|
|
bus_id : out std_logic_vector(3 downto 0);
|
180 |
|
|
bit_state : out std_logic_vector(3 downto 0);
|
181 |
|
|
byte_state : out std_logic_vector(3 downto 0);
|
182 |
|
|
mcmd_wr : in std_logic;
|
183 |
|
|
mcmd_id : in std_logic_vector(2 downto 0);
|
184 |
|
|
mcmd_data : in std_logic_vector(7 downto 0);
|
185 |
|
|
mrsp_wr : out std_logic;
|
186 |
|
|
mrsp_id : out std_logic_vector(2 downto 0);
|
187 |
|
|
mrsp_data : out std_logic_vector(7 downto 0);
|
188 |
|
|
scl_i : in std_logic_vector(0 to g_bus_num - 1);
|
189 |
|
|
sda_i : in std_logic_vector(0 to g_bus_num - 1);
|
190 |
|
|
scl_o : out std_logic_vector(0 to g_bus_num - 1);
|
191 |
|
|
sda_o : out std_logic_vector(0 to g_bus_num - 1)
|
192 |
|
|
);
|
193 |
|
|
end component iicmb_m;
|
194 |
|
|
------------------------------------------------------------------------------
|
195 |
|
|
|
196 |
|
|
signal wr : std_logic_vector( 3 downto 0);
|
197 |
|
|
signal rd : std_logic_vector( 3 downto 0);
|
198 |
|
|
signal idata : std_logic_vector(31 downto 0);
|
199 |
|
|
signal odata : std_logic_vector(31 downto 0);
|
200 |
|
|
|
201 |
|
|
signal busy : std_logic;
|
202 |
|
|
signal captured : std_logic;
|
203 |
|
|
signal bus_id : std_logic_vector( 3 downto 0);
|
204 |
|
|
signal bit_state : std_logic_vector( 3 downto 0);
|
205 |
|
|
signal byte_state : std_logic_vector( 3 downto 0);
|
206 |
|
|
signal disable : std_logic; -- used as synchronous reset for 'iicmb_m'
|
207 |
|
|
|
208 |
|
|
-- Signals of 'Generic Interface':
|
209 |
|
|
-- Command:
|
210 |
|
|
signal mcmd_wr : std_logic;
|
211 |
|
|
signal mcmd_id : std_logic_vector( 2 downto 0);
|
212 |
|
|
signal mcmd_data : std_logic_vector( 7 downto 0);
|
213 |
|
|
-- Response:
|
214 |
|
|
signal mrsp_wr : std_logic;
|
215 |
|
|
signal mrsp_id : std_logic_vector( 2 downto 0);
|
216 |
|
|
signal mrsp_data : std_logic_vector( 7 downto 0);
|
217 |
|
|
|
218 |
|
|
begin
|
219 |
|
|
|
220 |
|
|
------------------------------------------------------------------------------
|
221 |
|
|
avalon_mm_inst0 : avalon_mm
|
222 |
|
|
port map
|
223 |
|
|
(
|
224 |
|
|
clk => clk,
|
225 |
|
|
s_rst => s_rst,
|
226 |
|
|
waitrequest => waitrequest,
|
227 |
|
|
readdata => readdata,
|
228 |
|
|
readdatavalid => readdatavalid,
|
229 |
|
|
writedata => writedata,
|
230 |
|
|
write => write,
|
231 |
|
|
read => read,
|
232 |
|
|
byteenable => byteenable,
|
233 |
|
|
wr => wr,
|
234 |
|
|
rd => rd,
|
235 |
|
|
idata => idata,
|
236 |
|
|
odata => odata
|
237 |
|
|
);
|
238 |
|
|
------------------------------------------------------------------------------
|
239 |
|
|
|
240 |
|
|
------------------------------------------------------------------------------
|
241 |
|
|
regblock_inst9 : regblock
|
242 |
|
|
port map
|
243 |
|
|
(
|
244 |
|
|
clk => clk,
|
245 |
|
|
s_rst => s_rst,
|
246 |
|
|
wr => wr,
|
247 |
|
|
rd => rd,
|
248 |
|
|
idata => idata,
|
249 |
|
|
odata => odata,
|
250 |
|
|
irq => irq,
|
251 |
|
|
busy => busy,
|
252 |
|
|
captured => captured,
|
253 |
|
|
bus_id => bus_id,
|
254 |
|
|
bit_state => bit_state,
|
255 |
|
|
byte_state => byte_state,
|
256 |
|
|
disable => disable,
|
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 |
|
|
);
|
264 |
|
|
------------------------------------------------------------------------------
|
265 |
|
|
|
266 |
|
|
------------------------------------------------------------------------------
|
267 |
|
|
iicmb_m_inst0 : iicmb_m
|
268 |
|
|
generic map
|
269 |
|
|
(
|
270 |
|
|
g_bus_num => g_bus_num,
|
271 |
|
|
g_f_clk => g_f_clk,
|
272 |
|
|
g_f_scl_0 => g_f_scl_0,
|
273 |
|
|
g_f_scl_1 => g_f_scl_1,
|
274 |
|
|
g_f_scl_2 => g_f_scl_2,
|
275 |
|
|
g_f_scl_3 => g_f_scl_3,
|
276 |
|
|
g_f_scl_4 => g_f_scl_4,
|
277 |
|
|
g_f_scl_5 => g_f_scl_5,
|
278 |
|
|
g_f_scl_6 => g_f_scl_6,
|
279 |
|
|
g_f_scl_7 => g_f_scl_7,
|
280 |
|
|
g_f_scl_8 => g_f_scl_8,
|
281 |
|
|
g_f_scl_9 => g_f_scl_9,
|
282 |
|
|
g_f_scl_a => g_f_scl_a,
|
283 |
|
|
g_f_scl_b => g_f_scl_b,
|
284 |
|
|
g_f_scl_c => g_f_scl_c,
|
285 |
|
|
g_f_scl_d => g_f_scl_d,
|
286 |
|
|
g_f_scl_e => g_f_scl_e,
|
287 |
|
|
g_f_scl_f => g_f_scl_f
|
288 |
|
|
)
|
289 |
|
|
port map
|
290 |
|
|
(
|
291 |
|
|
clk => clk,
|
292 |
|
|
s_rst => disable,
|
293 |
|
|
busy => busy,
|
294 |
|
|
captured => captured,
|
295 |
|
|
bus_id => bus_id,
|
296 |
|
|
bit_state => bit_state,
|
297 |
|
|
byte_state => byte_state,
|
298 |
|
|
mcmd_wr => mcmd_wr,
|
299 |
|
|
mcmd_id => mcmd_id,
|
300 |
|
|
mcmd_data => mcmd_data,
|
301 |
|
|
mrsp_wr => mrsp_wr,
|
302 |
|
|
mrsp_id => mrsp_id,
|
303 |
|
|
mrsp_data => mrsp_data,
|
304 |
|
|
scl_i => scl_i,
|
305 |
|
|
sda_i => sda_i,
|
306 |
|
|
scl_o => scl_o,
|
307 |
|
|
sda_o => sda_o
|
308 |
|
|
);
|
309 |
|
|
------------------------------------------------------------------------------
|
310 |
|
|
|
311 |
|
|
end architecture str;
|
312 |
|
|
--==============================================================================
|
313 |
|
|
|