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

Subversion Repositories iicmb

[/] [iicmb/] [trunk/] [src/] [regblock.vhd] - Blame information for rev 3

Go to most recent revision | 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:  Register block.                                                 |
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
--------------------------------------------------------------------------------
41
-- Implemented registers:
42
-- 
43
--   Control/Status register:
44
--            7     6     5     4     3     2     1     0
45
--         +-----+-----+-----+-----+-----+-----+-----+-----+
46
--   0x00  |  E  | IE  |  BB |  BC |        Bus ID         |
47
--         +-----+-----+-----+-----+-----+-----+-----+-----+
48
--           R/W   R/W   RO    RO             RO
49
--           '0'   '0'   '0'   '0'          "0000"
50
--
51
--            E      - Enable
52
--            IE     - Interrupt Enable
53
--            BB     - Bus Busy
54
--            RC     - Bus Captured
55
--
56
--
57
--   Data register:
58
--            7     6     5     4     3     2     1     0
59
--         +-----+-----+-----+-----+-----+-----+-----+-----+
60
--   0x01  |                     Data                      |
61
--         +-----+-----+-----+-----+-----+-----+-----+-----+
62
--                                R/W
63
--                            "00000000"
64
--
65
--   Command register:
66
--            7     6     5     4     3     2     1     0
67
--         +-----+-----+-----+-----+-----+-----+-----+-----+
68
--   0x02  | DON | NAK | AL  | ERR | '0' |  Command Code   |
69
--         +-----+-----+-----+-----+-----+-----+-----+-----+
70
--           RO    RO    RO    RO                R/W
71
--           '1'   '0'   '0'   '0'              "000"
72
--
73
--            DON - Command Done
74
--            NAK - Data write was not acknowledged
75
--            AL  - Arbitration Lost
76
--            ERR - Error
77
--
78
--
79
--   Status register of FSM states:
80
--            7     6     5     4     3     2     1     0
81
--         +-----+-----+-----+-----+-----+-----+-----+-----+
82
--   0x03  |       Byte State      |       Bit State       |
83
--         +-----+-----+-----+-----+-----+-----+-----+-----+
84
--                    RO                      RO 
85
--                  "0000"                  "0000"
86
--------------------------------------------------------------------------------
87
 
88
 
89
library ieee;
90
use ieee.std_logic_1164.all;
91
 
92
use work.iicmb_pkg.all;
93
 
94
 
95
--==============================================================================
96
entity regblock is
97
  port
98
  (
99
    ------------------------------------
100
    clk         : in    std_logic;                                -- Clock input
101
    s_rst       : in    std_logic;                                -- Synchronous reset (active high)
102
    ------------------------------------
103
    ------------------------------------
104
    wr          : in    std_logic_vector( 3 downto 0);            -- Write (active high)
105
    rd          : in    std_logic_vector( 3 downto 0);            -- Read (active high)
106
    idata       : in    std_logic_vector(31 downto 0);            -- Data from System Bus
107
    odata       :   out std_logic_vector(31 downto 0);            -- Data to System Bus
108
    ------------------------------------
109
    ------------------------------------
110
    irq         :   out std_logic;                                -- Interrupt request
111
    ------------------------------------
112
 
113
    ------------------------------------
114
    busy        : in    std_logic;                                -- 'Bus is busy' indication (busy = high)
115
    captured    : in    std_logic;                                -- 'Bus is captured' indication (captured = high)
116
    bus_id      : in    std_logic_vector( 3 downto 0);            -- ID of selected I2C bus
117
    bit_state   : in    std_logic_vector( 3 downto 0);            -- State of bit level FSM
118
    byte_state  : in    std_logic_vector( 3 downto 0);            -- State of byte level FSM
119
    disable     :   out std_logic;                                -- Disable controller (used as synchronous reset)
120
    ------------------------------------
121
    ------------------------------------
122
    -- 'Generic Interface' signals:
123
    -- Byte command interface:
124
    mcmd_wr     :   out std_logic;                                -- Byte command write (active high)
125
    mcmd_id     :   out std_logic_vector( 2 downto 0);            -- Byte command ID
126
    mcmd_data   :   out std_logic_vector( 7 downto 0);            -- Byte command data
127
    -------------
128
    -- Byte response interface:
129
    mrsp_wr     : in    std_logic;                                -- Byte response write (active high)
130
    mrsp_id     : in    std_logic_vector( 2 downto 0);            -- Byte response ID
131
    mrsp_data   : in    std_logic_vector( 7 downto 0)             -- Byte response data
132
    ------------------------------------
133
  );
134
end entity regblock;
135
--==============================================================================
136
 
137
--==============================================================================
138
architecture rtl of regblock is
139
 
140
  signal irq_y             : std_logic                    := '0';
141
  signal mcmd_wr_y         : std_logic                    := '0';
142
  signal mcmd_id_y         : std_logic_vector(2 downto 0) := mcmd_set_bus;
143
  signal e_reg             : std_logic                    := '0';
144
  signal ie_reg            : std_logic                    := '0';
145
  signal tx_data_reg       : std_logic_vector(7 downto 0) := "00000000";
146
  signal rx_data_reg       : std_logic_vector(7 downto 0) := "00000000";
147
  signal don_reg           : std_logic                    := '1';
148
  signal nak_reg           : std_logic                    := '0';
149
  signal al_reg            : std_logic                    := '0';
150
  signal err_reg           : std_logic                    := '0';
151
  signal cmd_code_reg      : std_logic_vector(2 downto 0) := "000";
152
  signal command_completed : std_logic;
153
 
154
begin
155
 
156
  disable             <= not(e_reg);
157
 
158
  odata(31 downto 28) <= byte_state;
159
  odata(27 downto 24) <= bit_state;
160
  --
161
  odata(23)           <= don_reg;
162
  odata(22)           <= nak_reg;
163
  odata(21)           <= al_reg;
164
  odata(20)           <= err_reg;
165
  odata(19)           <= '0';
166
  odata(18 downto 16) <= cmd_code_reg;
167
  --
168
  odata(15 downto  8) <= rx_data_reg;
169
  --
170
  odata( 7)           <= e_reg;
171
  odata( 6)           <= ie_reg;
172
  odata( 5)           <= busy;
173
  odata( 4)           <= captured;
174
  odata( 3 downto  0) <= bus_id;
175
 
176
  ------------------------------------------------------------------------------
177
  process(clk)
178
  begin
179
    if rising_edge(clk) then
180
      if (s_rst = '1') then
181
        e_reg        <= '0';
182
        ie_reg       <= '0';
183
      else
184
        if (wr(0) = '1') then
185
          e_reg  <= idata(7);
186
          ie_reg <= idata(6);
187
        end if;
188
      end if;
189
    end if;
190
  end process;
191
  ------------------------------------------------------------------------------
192
 
193
  ------------------------------------------------------------------------------
194
  process(clk)
195
  begin
196
    if rising_edge(clk) then
197
      if (s_rst = '1') then
198
        tx_data_reg  <= "00000000";
199
      else
200
        if (wr(1) = '1') then
201
          tx_data_reg <= idata(15 downto 8);
202
        end if;
203
      end if;
204
    end if;
205
  end process;
206
  ------------------------------------------------------------------------------
207
 
208
  command_completed <= don_reg or nak_reg or al_reg or err_reg;
209
 
210
  ------------------------------------------------------------------------------
211
  process(clk)
212
  begin
213
    if rising_edge(clk) then
214
      if (s_rst = '1')or(e_reg = '0') then
215
        cmd_code_reg <= "000";
216
      else
217
        if (wr(2) = '1') then
218
          if (command_completed = '1') then
219
            cmd_code_reg <= idata(18 downto 16);
220
          end if;
221
        end if;
222
      end if;
223
    end if;
224
  end process;
225
  ------------------------------------------------------------------------------
226
 
227
  ------------------------------------------------------------------------------
228
  -- Command status registers
229
  process(clk)
230
  begin
231
    if rising_edge(clk) then
232
      if (s_rst = '1')or(e_reg = '0') then
233
        don_reg     <= '1';
234
        nak_reg     <= '0';
235
        al_reg      <= '0';
236
        err_reg     <= '0';
237
        rx_data_reg <= "00000000";
238
      else
239
        if (wr(2) = '1') then
240
          don_reg <= '0';
241
          nak_reg <= '0';
242
          al_reg  <= '0';
243
          err_reg <= '0';
244
        end if;
245
        if (mrsp_wr = '1') then
246
          case (mrsp_id) is
247
            when mrsp_done     => don_reg <= '1';
248
            when mrsp_byte     =>
249
              don_reg     <= '1';
250
              rx_data_reg <= mrsp_data;
251
            when mrsp_nak      => nak_reg <= '1';
252
            when mrsp_arb_lost => al_reg  <= '1';
253
            when others        => err_reg <= '1';
254
          end case;
255
        end if;
256
      end if;
257
    end if;
258
  end process;
259
  ------------------------------------------------------------------------------
260
 
261
  ------------------------------------------------------------------------------
262
  -- Interrupt request
263
  process(clk)
264
  begin
265
    if rising_edge(clk) then
266
      if (s_rst = '1')or(e_reg = '0') then
267
        irq_y <= '0';
268
      else
269
        if (rd(2) = '1') then
270
          irq_y <= '0';
271
        end if;
272
        if (mrsp_wr = '1') then
273
          irq_y <= '1';
274
        end if;
275
        if (ie_reg = '0') then
276
          irq_y <= '0';
277
        end if;
278
      end if;
279
    end if;
280
  end process;
281
  ------------------------------------------------------------------------------
282
 
283
  irq <= irq_y;
284
 
285
  ------------------------------------------------------------------------------
286
  -- Generating a byte command
287
  mcmd_proc:
288
  process(clk)
289
  begin
290
    if rising_edge(clk) then
291
      if (s_rst = '1')or(e_reg = '0') then
292
        mcmd_wr_y <= '0';
293
        mcmd_id_y <= mcmd_wait;
294
      else
295
        if (wr(2) = '1')and(command_completed = '1') then
296
          mcmd_wr_y <= '1';
297
          mcmd_id_y <= idata(18 downto 16);
298
        else
299
          mcmd_wr_y <= '0';
300
        end if;
301
      end if;
302
    end if;
303
  end process mcmd_proc;
304
  ------------------------------------------------------------------------------
305
 
306
  mcmd_wr   <= mcmd_wr_y;
307
  mcmd_id   <= mcmd_id_y;
308
  mcmd_data <= tx_data_reg;
309
 
310
end architecture rtl;
311
--==============================================================================
312
 

powered by: WebSVN 2.1.0

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