1 |
2 |
sshuv2 |
|
2 |
|
|
--==============================================================================
|
3 |
|
|
-- |
|
4 |
|
|
-- Project: IIC Multiple Bus Controller (IICMB) |
|
5 |
|
|
-- |
|
6 |
|
|
-- Module: Top level of IICMB controller with sequencer. |
|
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 |
|
|
use work.iicmb_pkg.all;
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
--==============================================================================
|
47 |
|
|
entity iicmb_m_sq is
|
48 |
|
|
generic
|
49 |
|
|
(
|
50 |
|
|
------------------------------------
|
51 |
|
|
g_bus_num : positive range 1 to 16 := 1; -- Number of separate I2C buses
|
52 |
|
|
g_f_clk : real := 100000.0; -- Frequency of system clock 'clk' (in kHz)
|
53 |
|
|
g_f_scl_0 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #0 (in kHz)
|
54 |
|
|
g_f_scl_1 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #1 (in kHz)
|
55 |
|
|
g_f_scl_2 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #2 (in kHz)
|
56 |
|
|
g_f_scl_3 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #3 (in kHz)
|
57 |
|
|
g_f_scl_4 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #4 (in kHz)
|
58 |
|
|
g_f_scl_5 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #5 (in kHz)
|
59 |
|
|
g_f_scl_6 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #6 (in kHz)
|
60 |
|
|
g_f_scl_7 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #7 (in kHz)
|
61 |
|
|
g_f_scl_8 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #8 (in kHz)
|
62 |
|
|
g_f_scl_9 : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #9 (in kHz)
|
63 |
|
|
g_f_scl_a : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #10 (in kHz)
|
64 |
|
|
g_f_scl_b : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #11 (in kHz)
|
65 |
|
|
g_f_scl_c : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #12 (in kHz)
|
66 |
|
|
g_f_scl_d : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #13 (in kHz)
|
67 |
|
|
g_f_scl_e : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #14 (in kHz)
|
68 |
|
|
g_f_scl_f : real := 100.0; -- Frequency of 'SCL' clock of I2C bus #15 (in kHz)
|
69 |
|
|
g_cmd : seq_cmd_type_array := c_empty_array -- Sequence of commands (supported: WAIT, SET_BUS and WRITE_BYTE)
|
70 |
|
|
------------------------------------
|
71 |
|
|
);
|
72 |
|
|
port
|
73 |
|
|
(
|
74 |
|
|
------------------------------------
|
75 |
|
|
clk : in std_logic; -- Clock
|
76 |
|
|
s_rst : in std_logic; -- Synchronous reset (active high)
|
77 |
|
|
------------------------------------
|
78 |
|
|
------------------------------------
|
79 |
|
|
cs_start : in std_logic; -- Start executing command sequence
|
80 |
|
|
cs_busy : out std_logic; -- Command sequence is being executed
|
81 |
|
|
cs_status : out std_logic_vector(2 downto 0); -- Execution status
|
82 |
|
|
------------------------------------
|
83 |
|
|
------------------------------------
|
84 |
|
|
-- I2C interfaces:
|
85 |
|
|
scl_i : in std_logic_vector(0 to g_bus_num - 1); -- I2C Clock inputs
|
86 |
|
|
sda_i : in std_logic_vector(0 to g_bus_num - 1); -- I2C Data inputs
|
87 |
|
|
scl_o : out std_logic_vector(0 to g_bus_num - 1); -- I2C Clock outputs
|
88 |
|
|
sda_o : out std_logic_vector(0 to g_bus_num - 1) -- I2C Data outputs
|
89 |
|
|
------------------------------------
|
90 |
|
|
);
|
91 |
|
|
end entity iicmb_m_sq;
|
92 |
|
|
--==============================================================================
|
93 |
|
|
|
94 |
|
|
--==============================================================================
|
95 |
|
|
architecture str of iicmb_m_sq is
|
96 |
|
|
|
97 |
|
|
------------------------------------------------------------------------------
|
98 |
|
|
component sequencer is
|
99 |
|
|
generic
|
100 |
|
|
(
|
101 |
|
|
g_cmd : seq_cmd_type_array := c_empty_array
|
102 |
|
|
);
|
103 |
|
|
port
|
104 |
|
|
(
|
105 |
|
|
clk : in std_logic;
|
106 |
|
|
s_rst : in std_logic;
|
107 |
|
|
cs_start : in std_logic;
|
108 |
|
|
cs_busy : out std_logic;
|
109 |
|
|
cs_status : out std_logic_vector(2 downto 0);
|
110 |
|
|
busy : in std_logic;
|
111 |
|
|
captured : in std_logic;
|
112 |
|
|
bus_id : in std_logic_vector(3 downto 0);
|
113 |
|
|
bit_state : in std_logic_vector(3 downto 0);
|
114 |
|
|
byte_state : in std_logic_vector(3 downto 0);
|
115 |
|
|
mcmd_wr : out std_logic;
|
116 |
|
|
mcmd_id : out std_logic_vector(2 downto 0);
|
117 |
|
|
mcmd_data : out std_logic_vector(7 downto 0);
|
118 |
|
|
mrsp_wr : in std_logic;
|
119 |
|
|
mrsp_id : in std_logic_vector(2 downto 0);
|
120 |
|
|
mrsp_data : in std_logic_vector(7 downto 0)
|
121 |
|
|
);
|
122 |
|
|
end component sequencer;
|
123 |
|
|
------------------------------------------------------------------------------
|
124 |
|
|
|
125 |
|
|
------------------------------------------------------------------------------
|
126 |
|
|
component iicmb_m is
|
127 |
|
|
generic
|
128 |
|
|
(
|
129 |
|
|
g_bus_num : positive range 1 to 16 := 1;
|
130 |
|
|
g_f_clk : real := 100000.0;
|
131 |
|
|
g_f_scl_0 : real := 100.0;
|
132 |
|
|
g_f_scl_1 : real := 100.0;
|
133 |
|
|
g_f_scl_2 : real := 100.0;
|
134 |
|
|
g_f_scl_3 : real := 100.0;
|
135 |
|
|
g_f_scl_4 : real := 100.0;
|
136 |
|
|
g_f_scl_5 : real := 100.0;
|
137 |
|
|
g_f_scl_6 : real := 100.0;
|
138 |
|
|
g_f_scl_7 : real := 100.0;
|
139 |
|
|
g_f_scl_8 : real := 100.0;
|
140 |
|
|
g_f_scl_9 : real := 100.0;
|
141 |
|
|
g_f_scl_a : real := 100.0;
|
142 |
|
|
g_f_scl_b : real := 100.0;
|
143 |
|
|
g_f_scl_c : real := 100.0;
|
144 |
|
|
g_f_scl_d : real := 100.0;
|
145 |
|
|
g_f_scl_e : real := 100.0;
|
146 |
|
|
g_f_scl_f : real := 100.0
|
147 |
|
|
);
|
148 |
|
|
port
|
149 |
|
|
(
|
150 |
|
|
clk : in std_logic;
|
151 |
|
|
s_rst : in std_logic;
|
152 |
|
|
busy : out std_logic;
|
153 |
|
|
captured : out std_logic;
|
154 |
|
|
bus_id : out std_logic_vector(3 downto 0);
|
155 |
|
|
bit_state : out std_logic_vector(3 downto 0);
|
156 |
|
|
byte_state : out std_logic_vector(3 downto 0);
|
157 |
|
|
mcmd_wr : in std_logic;
|
158 |
|
|
mcmd_id : in std_logic_vector(2 downto 0);
|
159 |
|
|
mcmd_data : in std_logic_vector(7 downto 0);
|
160 |
|
|
mrsp_wr : out std_logic;
|
161 |
|
|
mrsp_id : out std_logic_vector(2 downto 0);
|
162 |
|
|
mrsp_data : out std_logic_vector(7 downto 0);
|
163 |
|
|
scl_i : in std_logic_vector(0 to g_bus_num - 1);
|
164 |
|
|
sda_i : in std_logic_vector(0 to g_bus_num - 1);
|
165 |
|
|
scl_o : out std_logic_vector(0 to g_bus_num - 1);
|
166 |
|
|
sda_o : out std_logic_vector(0 to g_bus_num - 1)
|
167 |
|
|
);
|
168 |
|
|
end component iicmb_m;
|
169 |
|
|
------------------------------------------------------------------------------
|
170 |
|
|
|
171 |
|
|
signal busy : std_logic;
|
172 |
|
|
signal captured : std_logic;
|
173 |
|
|
signal bus_id : std_logic_vector( 3 downto 0);
|
174 |
|
|
signal bit_state : std_logic_vector( 3 downto 0);
|
175 |
|
|
signal byte_state : std_logic_vector( 3 downto 0);
|
176 |
|
|
|
177 |
|
|
-- Signals of 'Generic Interface':
|
178 |
|
|
-- Command:
|
179 |
|
|
signal mcmd_wr : std_logic;
|
180 |
|
|
signal mcmd_id : std_logic_vector( 2 downto 0);
|
181 |
|
|
signal mcmd_data : std_logic_vector( 7 downto 0);
|
182 |
|
|
-- Response:
|
183 |
|
|
signal mrsp_wr : std_logic;
|
184 |
|
|
signal mrsp_id : std_logic_vector( 2 downto 0);
|
185 |
|
|
signal mrsp_data : std_logic_vector( 7 downto 0);
|
186 |
|
|
|
187 |
|
|
begin
|
188 |
|
|
|
189 |
|
|
------------------------------------------------------------------------------
|
190 |
|
|
sequencer_inst0 : sequencer
|
191 |
|
|
generic map
|
192 |
|
|
(
|
193 |
|
|
g_cmd => g_cmd
|
194 |
|
|
)
|
195 |
|
|
port map
|
196 |
|
|
(
|
197 |
|
|
clk => clk,
|
198 |
|
|
s_rst => s_rst,
|
199 |
|
|
cs_start => cs_start,
|
200 |
|
|
cs_busy => cs_busy,
|
201 |
|
|
cs_status => cs_status,
|
202 |
|
|
busy => busy,
|
203 |
|
|
captured => captured,
|
204 |
|
|
bus_id => bus_id,
|
205 |
|
|
bit_state => bit_state,
|
206 |
|
|
byte_state => byte_state,
|
207 |
|
|
mcmd_wr => mcmd_wr,
|
208 |
|
|
mcmd_id => mcmd_id,
|
209 |
|
|
mcmd_data => mcmd_data,
|
210 |
|
|
mrsp_wr => mrsp_wr,
|
211 |
|
|
mrsp_id => mrsp_id,
|
212 |
|
|
mrsp_data => mrsp_data
|
213 |
|
|
);
|
214 |
|
|
------------------------------------------------------------------------------
|
215 |
|
|
|
216 |
|
|
------------------------------------------------------------------------------
|
217 |
|
|
iicmb_m_inst0 : iicmb_m
|
218 |
|
|
generic map
|
219 |
|
|
(
|
220 |
|
|
g_bus_num => g_bus_num,
|
221 |
|
|
g_f_clk => g_f_clk,
|
222 |
|
|
g_f_scl_0 => g_f_scl_0,
|
223 |
|
|
g_f_scl_1 => g_f_scl_1,
|
224 |
|
|
g_f_scl_2 => g_f_scl_2,
|
225 |
|
|
g_f_scl_3 => g_f_scl_3,
|
226 |
|
|
g_f_scl_4 => g_f_scl_4,
|
227 |
|
|
g_f_scl_5 => g_f_scl_5,
|
228 |
|
|
g_f_scl_6 => g_f_scl_6,
|
229 |
|
|
g_f_scl_7 => g_f_scl_7,
|
230 |
|
|
g_f_scl_8 => g_f_scl_8,
|
231 |
|
|
g_f_scl_9 => g_f_scl_9,
|
232 |
|
|
g_f_scl_a => g_f_scl_a,
|
233 |
|
|
g_f_scl_b => g_f_scl_b,
|
234 |
|
|
g_f_scl_c => g_f_scl_c,
|
235 |
|
|
g_f_scl_d => g_f_scl_d,
|
236 |
|
|
g_f_scl_e => g_f_scl_e,
|
237 |
|
|
g_f_scl_f => g_f_scl_f
|
238 |
|
|
)
|
239 |
|
|
port map
|
240 |
|
|
(
|
241 |
|
|
clk => clk,
|
242 |
|
|
s_rst => s_rst,
|
243 |
|
|
busy => busy,
|
244 |
|
|
captured => captured,
|
245 |
|
|
bus_id => bus_id,
|
246 |
|
|
bit_state => bit_state,
|
247 |
|
|
byte_state => byte_state,
|
248 |
|
|
mcmd_wr => mcmd_wr,
|
249 |
|
|
mcmd_id => mcmd_id,
|
250 |
|
|
mcmd_data => mcmd_data,
|
251 |
|
|
mrsp_wr => mrsp_wr,
|
252 |
|
|
mrsp_id => mrsp_id,
|
253 |
|
|
mrsp_data => mrsp_data,
|
254 |
|
|
scl_i => scl_i,
|
255 |
|
|
sda_i => sda_i,
|
256 |
|
|
scl_o => scl_o,
|
257 |
|
|
sda_o => sda_o
|
258 |
|
|
);
|
259 |
|
|
------------------------------------------------------------------------------
|
260 |
|
|
|
261 |
|
|
end architecture str;
|
262 |
|
|
--==============================================================================
|
263 |
|
|
|