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

Subversion Repositories attiny_atmega_xmega_core

[/] [attiny_atmega_xmega_core/] [trunk/] [rtl/] [sim_i2c.v] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 morgothcre
/*
2
 * This is the simulation file for TWI IP.
3
 *
4
 * Copyright (C) 2018  Iulian Gheorghiu
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
 */
20
 
21
`timescale 1ns / 1ps
22
`include "io_s_h.v"
23
 
24
module sim_i2c(
25
        output reg rst,
26
        output reg clk,
27
        output reg [15:0]addr,
28
        output reg wr,
29
        output reg rd,
30
        output [7:0]bus_in,
31
        output reg [7:0]bus_out,
32
        output int_tx_cmpl,
33
        output int_rx_cmpl,
34
        output int_tx_rst,
35
        output int_rx_rst,
36
 
37
        inout scl,
38
        inout sda
39
);
40
 
41
 
42
always  #(1)    clk     <=      ~clk;   //      clocking        device
43
 
44
initial
45
begin
46
        rst = 0;
47
        clk = 1;
48
        wr = 0;
49
        rd = 0;
50
        #2;
51
        rst = 1;
52
        #2;
53
        rst = 0;
54
        #4;
55
        addr = `TWI_MASTER_BAUD;
56
        bus_out = 'h1;
57
        wr = 1;
58
        #2;
59
        addr = `TWI_MASTER_CTRLA;
60
        bus_out = `TWI_MASTER_ENABLE_bm;
61
        #2;
62
        addr = `TWI_MASTER_DATA;
63
        bus_out = 8'h55;
64
        #2;
65
        wr = 0;
66
        bus_out = 'hz;
67
        rd = 1;
68
        addr = `TWI_MASTER_STATUS;
69
        #2;
70
        while(~bus_in[`TWI_MASTER_WIF_bp]) #2;
71
        rd = 0;
72
        #2;
73
        wr = 1;
74
        addr = `TWI_MASTER_DATA;
75
        bus_out = 8'hAA;
76
        #2;
77
        wr = 0;
78
        bus_out = 'hz;
79
        rd = 1;
80
        addr = `TWI_MASTER_STATUS;
81
        #2;
82
        while(~bus_in[`TWI_MASTER_WIF_bp]) #2;
83
        rd = 0;
84
        #2;
85
        addr = `TWI_MASTER_CTRLC;
86
        bus_out = `TWI_MASTER_CMD_REPSTART_gc;
87
        #2;
88
        wr = 1;
89
        addr = `TWI_MASTER_CTRLC;
90
        bus_out = `TWI_MASTER_CMD_RECVTRANS_gc;
91
        #2;
92
        wr = 0;
93
        bus_out = 'hz;
94
        rd = 1;
95
        addr = `TWI_MASTER_STATUS;
96
        #2;
97
        while(~bus_in[`TWI_MASTER_RIF_bp]) #2;
98
        addr = `TWI_MASTER_DATA;
99
        #2;
100
        rd = 0;
101
        #2;
102
        wr = 1;
103
        addr = `TWI_MASTER_CTRLC;
104
        bus_out = `TWI_MASTER_ACKACT_bm | `TWI_MASTER_CMD_RECVTRANS_gc;
105
        #2;
106
        wr = 0;
107
        bus_out = 'hz;
108
        rd = 1;
109
        addr = `TWI_MASTER_STATUS;
110
        #2;
111
        while(~bus_in[`TWI_MASTER_RIF_bp]) #2;
112
        addr = `TWI_MASTER_DATA;
113
        #2;
114
        rd = 0;
115
        #2;
116
        wr = 1;
117
        addr = `TWI_MASTER_CTRLC;
118
        bus_out = `TWI_MASTER_CMD_STOP_gc;
119
        #2;
120
        wr = 0;
121
        bus_out = 'hz;
122
        #10;
123
        $finish;
124
end
125
 
126
twi_s #(
127
        .DINAMIC_BAUDRATE("TRUE"),
128
        .BAUDRATE_DIVIDER(19200),
129
        .ADDRESS(0),
130
        .BUS_ADDR_DATA_LEN(16)
131
    )twi_inst(
132
        .rst(rst),
133
        .clk(clk),
134
        .addr(addr),
135
        .wr(wr),
136
        .rd(rd),
137
        .bus_in(bus_out),
138
        .bus_out(bus_in),
139
        .int_tx_cmpl(int_tx_cmpl),
140
        .int_rx_cmpl(int_rx_cmpl),
141
        .int_tx_rst(int_tx_rst),
142
        .int_rx_rst(int_rx_rst),
143
 
144
        .scl(scl),
145
        .sda(sda)
146
);
147
endmodule

powered by: WebSVN 2.1.0

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