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

Subversion Repositories iicmb

[/] [iicmb/] [trunk/] [src/] [iicmb_pkg.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:  Main package.                                                   |
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
 
45
--==============================================================================
46
package iicmb_pkg is
47
 
48
  ------------------------------------------------------------------------------
49
  -- Byte level master mode commands' codes:
50
  ------------------------------------------------------------------------------
51
  -- Start                           --> Done | Arbitration Lost
52
  -- Byte Write                      --> Done | Write Not Acknowledged | Arbitration Lost | Error
53
  -- Byte Read                       --> Byte Received | Error
54
  -- Byte Read with Not-Acknowledge  --> Byte Received | Arbitration Lost | Error
55
  -- Stop                            --> Done
56
  -- Set Bus                         --> Done | Error
57
  -- Wait                            --> Done | Error
58
  constant mcmd_wait     : std_logic_vector(2 downto 0) := "000";
59
  constant mcmd_write    : std_logic_vector(2 downto 0) := "001";
60
  constant mcmd_read_ack : std_logic_vector(2 downto 0) := "010";
61
  constant mcmd_read_nak : std_logic_vector(2 downto 0) := "011";
62
  constant mcmd_start    : std_logic_vector(2 downto 0) := "100";
63
  constant mcmd_stop     : std_logic_vector(2 downto 0) := "101";
64
  constant mcmd_set_bus  : std_logic_vector(2 downto 0) := "110";
65
  ------------------------------------------------------------------------------
66
 
67
  ------------------------------------------------------------------------------
68
  -- Byte level master mode responses' codes:
69
  ------------------------------------------------------------------------------
70
  -- Done
71
  -- Byte received
72
  -- Write Not Acknowledged
73
  -- Arbitration lost
74
  -- Error
75
  constant mrsp_done     : std_logic_vector(2 downto 0) := "000";
76
  constant mrsp_nak      : std_logic_vector(2 downto 0) := "001";
77
  constant mrsp_arb_lost : std_logic_vector(2 downto 0) := "010";
78
  constant mrsp_error    : std_logic_vector(2 downto 0) := "011";
79
  constant mrsp_byte     : std_logic_vector(2 downto 0) := "100";
80
  ------------------------------------------------------------------------------
81
 
82
 
83
  ------------------------------------------------------------------------------
84
  -- Sequencer related stuff ---------------------------------------------------
85
  type seq_cmd_id is (seq_wait, seq_set_bus, seq_write_byte);
86
  type seq_cmd_type is record
87
    id    : seq_cmd_id;
88
    saddr : std_logic_vector(6 downto 0);
89
    daddr : std_logic_vector(7 downto 0);
90
    data  : std_logic_vector(7 downto 0);
91
  end record;
92
  constant c_seq_cmd_default : seq_cmd_type := (id => seq_wait, others => (others => '0'));
93
  type seq_cmd_type_array is array (natural range <>) of seq_cmd_type;
94
  constant c_empty_array : seq_cmd_type_array(0 to 0) := (others => c_seq_cmd_default); -- not really empty
95
 
96
  function scmd_wait(a : integer range 0 to 255) return seq_cmd_type;
97
  function scmd_set_bus(a : integer range 0 to 15) return seq_cmd_type;
98
  function scmd_write_byte(sa : std_logic_vector(6 downto 0);
99
                           da : std_logic_vector(7 downto 0);
100
                           d  : std_logic_vector(7 downto 0)) return seq_cmd_type;
101
  -- End of sequencer related stuff --------------------------------------------
102
  ------------------------------------------------------------------------------
103
 
104
end package iicmb_pkg;
105
--==============================================================================
106
 
107
--==============================================================================
108
package body iicmb_pkg is
109
 
110
  ------------------------------------------------------------------------------
111
  function scmd_wait(a : integer range 0 to 255) return seq_cmd_type is
112
    variable ret : seq_cmd_type;
113
  begin
114
    ret.id    := seq_wait;
115
    ret.saddr := (others => '0');
116
    ret.daddr := (others => '0');
117
    ret.data  := std_logic_vector(to_unsigned(a, 8));
118
    return ret;
119
  end function scmd_wait;
120
  ------------------------------------------------------------------------------
121
 
122
  ------------------------------------------------------------------------------
123
  function scmd_set_bus(a : integer range 0 to 15) return seq_cmd_type is
124
    variable ret : seq_cmd_type;
125
  begin
126
    ret.id    := seq_set_bus;
127
    ret.saddr := (others => '0');
128
    ret.daddr := (others => '0');
129
    ret.data  := std_logic_vector(to_unsigned(a, 8));
130
    return ret;
131
  end function scmd_set_bus;
132
  ------------------------------------------------------------------------------
133
 
134
  ------------------------------------------------------------------------------
135
  function scmd_write_byte(sa : std_logic_vector(6 downto 0);
136
                           da : std_logic_vector(7 downto 0);
137
                           d  : std_logic_vector(7 downto 0)) return seq_cmd_type is
138
    variable ret : seq_cmd_type;
139
  begin
140
    ret.id    := seq_write_byte;
141
    ret.saddr := sa;
142
    ret.daddr := da;
143
    ret.data  := d;
144
    return ret;
145
  end function scmd_write_byte;
146
  ------------------------------------------------------------------------------
147
 
148
end package body iicmb_pkg;
149
--==============================================================================
150
 

powered by: WebSVN 2.1.0

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