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

Subversion Repositories smbus_controller

[/] [smbus_controller/] [trunk/] [hw/] [simulations/] [Testbench_SMBusController.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ldalmasso
------------------------------------------------------------------------
2
-- Engineer:    Dalmasso Loic
3
-- Create Date: 18/11/2024
4
-- Module Name: SMBusController
5
-- Description:
6
--      System Management Bus (SMBus) Controller, compatible with all 15 commands (from SMBus Speficiation 3.3.1)
7
--              Features:
8
--          - Controller-Transmitter with Read/Write Operations
9
--                      - Controller-Receiver Auto-Dectection (act as Slave/Target)
10
--                      - Command Byte activation/deactivation
11
--                      - PEC (Packet Error Code) activation/deactivation
12
--                      - Configurable Read/Write Data length
13
--          - Bus Busy Detection
14
--          - Bus Timeout Detection
15
--                      - Clock Stretching Detection
16
--                      - Multimaster (arbitration)
17
--
18
-- WARNING: /!\ Require Pull-Up on SMBCLK and SMBDAT pins /!\
19
--
20
-- Usage:
21
--      ...
22
--
23
-- Generics
24
--              INPUT_CLOCK_FREQ: Module Input Clock Frequency
25
--              SMBUS_CLOCK_FREQ: SMBus Serial Clock Frequency
26
--              SMBUS_CLASS: SMBus Class (100kHz, 400kHz, 1MHz)
27
--              MAX_BUS_LENGTH: Maximum Length of the SMBus Address/Data in bits
28
--              CONTROLLER_ADDR: Address of this SMBus Controller-Receiver
29
--
30
-- Ports
31
--              Input   -       i_clock: Module Input Clock
32
--              Input   -       i_reset: Reset ('0': No Reset, '1': Reset)
33
--              Input   -       i_start: Start SMBus Transmission ('0': No Start, '1': Start)
34
--              Input   -       i_mode: Operation Mode ("00": Write-Only, "11": Read-Only, "01": Write-then-Read)
35
--              Input   -       i_slave_addr: Slave Address (7 bits)
36
--              Input   -       i_cmd_enable: Command Byte Enable ('0': Disable, '1': Enable)
37
--              Input   -       i_pec_enable: Packet Error Code Enable ('0': Disable, '1': Enable)
38
--              Input   -       i_data_write_length: Data Length to Write in bytes
39
--              Input   -       i_data_read_length: Data Length to Read in bytes
40
--              Input   -       i_cmd: Command Value to Write
41
--              Input   -       i_data_write: Data Value to Write
42
--              Output  -       o_data_read: Read Data Value
43
--              Output  -       o_data_read_valid: Validity of the Read Data Value ('0': Not Valid, '1': Valid)
44
--              Output  -       o_ready: Ready State of SMBus Controller ('0': Not Ready, '1': Ready)
45
--              Output  -       o_error: Error State of SMBus Controller ('0': No Error, '1': Error)
46
--              Output  -       o_busy: Busy State of SMBus Controller ('0': Not Busy, '1': Busy)
47
--              In/Out  -       io_smbclk: SMBus Serial Clock ('0'-'Z'(as '1') values, working with Pull-Up)
48
--              In/Out  -       io_smbdat: SMBus Serial Data ('0'-'Z'(as '1') values, working with Pull-Up)
49
------------------------------------------------------------------------
50
 
51
LIBRARY IEEE;
52
USE IEEE.STD_LOGIC_1164.ALL;
53
USE IEEE.NUMERIC_STD.ALL;
54
 
55
entity Testbench_SMBusController is
56
end Testbench_SMBusController;
57
 
58
architecture Behavioral of Testbench_SMBusController is
59
 
60
COMPONENT SMBusController is
61
 
62
GENERIC(
63
        INPUT_CLOCK_FREQ: INTEGER := 12_000_000;
64
        SMBUS_CLOCK_FREQ: INTEGER := 100_000;
65
        SMBUS_CLASS: INTEGER := 100_000;
66
        MAX_DATA_BIT_LENGTH: INTEGER := 8
67
);
68
 
69
PORT(
70
        i_clock: IN STD_LOGIC;
71
    i_reset: IN STD_LOGIC;
72
        i_start: IN STD_LOGIC;
73
        i_mode: IN STD_LOGIC_VECTOR(1 downto 0);
74
        i_slave_addr: IN STD_LOGIC_VECTOR(6 downto 0);
75
        i_cmd_enable: IN STD_LOGIC;
76
        i_pec_enable: IN STD_LOGIC;
77
        i_data_write_byte_number: IN INTEGER range 0 to MAX_DATA_BIT_LENGTH/8;
78
        i_data_read_byte_number: IN INTEGER range 0 to MAX_DATA_BIT_LENGTH/8;
79
        i_cmd: IN STD_LOGIC_VECTOR(7 downto 0);
80
        i_data_write: IN STD_LOGIC_VECTOR(MAX_DATA_BIT_LENGTH-1 downto 0);
81
        o_data_read: OUT STD_LOGIC_VECTOR(MAX_DATA_BIT_LENGTH-1 downto 0);
82
        o_data_read_valid: OUT STD_LOGIC;
83
        o_ready: OUT STD_LOGIC;
84
        o_error: OUT STD_LOGIC;
85
        o_busy: OUT STD_LOGIC;
86
        io_smbclk: INOUT STD_LOGIC;
87
        io_smbdat: INOUT STD_LOGIC
88
);
89
 
90
END COMPONENT;
91
 
92
signal clock_12M: STD_LOGIC := '1';
93
signal reset: STD_LOGIC := '0';
94
signal start: STD_LOGIC := '0';
95
signal mode: STD_LOGIC_VECTOR(1 downto 0) := (others => '0');
96
signal slave_addr: STD_LOGIC_VECTOR(6 downto 0) := (others => '0');
97
signal cmd_enable: STD_LOGIC := '0';
98
signal pec_enable: STD_LOGIC := '0';
99
signal cmd: STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
100
signal data_read: STD_LOGIC_VECTOR(8-1 downto 0) := (others => '0');
101
signal data_read_valid: STD_LOGIC := '0';
102
signal ready: STD_LOGIC := '0';
103
signal error: STD_LOGIC := '0';
104
signal busy: STD_LOGIC := '0';
105
signal smbclk: STD_LOGIC := '0';
106
signal smbdat: STD_LOGIC := '0';
107
 
108
 
109
begin
110
 
111
-- Clock 12 MHz
112
clock_12M <= not(clock_12M) after 41.6667 ns;
113
 
114
-- Reset
115
reset <= '1', '0' after 250 ns;
116
 
117
-- Mode
118
mode <= "00", "11" after 601 us, "01" after 1201 us;
119
 
120
-- Start
121
start <= '0', '1' after 1 us, '0' after 12 us, '1' after 600 us, '0' after 602 us, '1' after 1200 us, '0' after 1202 us;
122
 
123
-- SMBCLK
124
smbclk <= 'Z';
125
 
126
-- SMBDAT
127
smbdat <=
128
        -- Write Mode
129
        'Z',
130
        -- Write Slave Addr W ACK
131
        '0' after 100.250802 us,
132
        'Z' after 110.250882 us,
133
        -- Write CMD ACK
134
        '0' after 190.251522 us,
135
        'Z' after 200.251602 us,
136
        -- Write Reg ACK
137
        '0' after 280.252242 us,
138
        'Z' after 290.252322 us,
139
         -- Write PEC ACK
140
        '0' after 370.252962 us,
141
        'Z' after 380.253042 us,
142
 
143
        -- Read Mode
144
        -- Write Slave Addr R ACK
145
        '0' after 690.255522 us,
146
        -- Read Reg Value
147
        '0' after 700.255602 us,
148
        '0' after 710.255682 us,
149
        '1' after 720.255762 us,
150
        '1' after 730.255842 us,
151
        '0' after 740.255922 us,
152
        '0' after 750.256002 us,
153
        '1' after 760.256082 us,
154
        '0' after 770.256162 us,
155
        'Z' after 780.256242 us,
156
        -- Read PEC Value
157
        '0' after 790.256322 us,
158
        '0' after 800.256402 us,
159
        '0' after 810.256482 us,
160
        '1' after 820.256562 us,
161
        '1' after 830.256642 us,
162
        '0' after 840.256722 us,
163
        '1' after 850.256802 us,
164
        '1' after 860.256882 us,
165
        'Z' after 870.256962 us,
166
 
167
        -- Write-then-Read Mode
168
        -- Write Slave Addr W ACK
169
        '0' after 1290.260322 us,
170
        'Z' after 1300.260402 us,
171
        -- Write CMD ACK
172
        '0' after 1380.261042 us,
173
        'Z' after 1390.261122 us,
174
        -- Write Reg ACK
175
        '0' after 1470.261762 us,
176
        'Z' after 1480.261842 us,
177
         -- Write Slave Addr R ACK
178
        '0' after 1570.262562 us,
179
         -- Read Reg Value
180
        '1' after 1580.262642 us,
181
        '1' after 1590.262722 us,
182
        '0' after 1600.262802 us,
183
        '1' after 1610.262882 us,
184
        '0' after 1620.262962 us,
185
        '1' after 1630.263042 us,
186
        '1' after 1640.263122 us,
187
        '0' after 1650.263202 us,
188
        'Z' after 1660.263282 us,
189
        -- Read PEC Value
190
        '1' after 1670.263362 us,
191
        '1' after 1680.263442 us,
192
        '1' after 1690.263522 us,
193
        '0' after 1700.263602 us,
194
        '1' after 1710.263682 us,
195
        '1' after 1720.263762 us,
196
        '0' after 1730.263842 us,
197
        '1' after 1740.263922 us,
198
        'Z' after 1750.264002 us;
199
 
200
 
201
uut: SMBusController
202
 
203
    PORT map(
204
        i_clock => clock_12M,
205
    i_reset => reset,
206
        i_start => start,
207
        i_mode => mode,
208
        i_slave_addr => "1101001",
209
        i_cmd_enable => '1',
210
        i_pec_enable => '1',
211
        i_data_write_byte_number => 1,
212
        i_data_read_byte_number => 1,
213
        i_cmd => X"FF",
214
        i_data_write => "10110010",
215
        o_data_read => data_read,
216
        o_data_read_valid => data_read_valid,
217
        o_ready => ready,
218
        o_error => error,
219
        o_busy => busy,
220
        io_smbclk => smbclk,
221
        io_smbdat => smbdat);
222
 
223
end Behavioral;

powered by: WebSVN 2.1.0

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