URL
https://opencores.org/ocsvn/i2c/i2c/trunk
Subversion Repositories i2c
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 18 to Rev 19
- ↔ Reverse comparison
Rev 18 → Rev 19
/trunk/bench/verilog/tst_bench_top.v
1,6 → 1,52
///////////////////////////////////////////////////////////////////// |
//// //// |
//// WISHBONE rev.B2 compliant I2C Master controller Testbench //// |
//// //// |
//// //// |
//// Author: Richard Herveille //// |
//// richard@asics.ws //// |
//// www.asics.ws //// |
//// //// |
//// Downloaded from: http://www.opencores.org/projects/i2c/ //// |
//// //// |
///////////////////////////////////////////////////////////////////// |
//// //// |
//// Copyright (C) 2001 Richard Herveille //// |
//// richard@asics.ws //// |
//// //// |
//// This source file may be used and distributed without //// |
//// restriction provided that this copyright statement is not //// |
//// removed from the file and that any derivative work contains //// |
//// the original copyright notice and the associated disclaimer.//// |
//// //// |
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// |
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// |
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// |
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// |
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// |
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// |
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// |
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// |
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// |
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// |
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// |
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// |
//// POSSIBILITY OF SUCH DAMAGE. //// |
//// //// |
///////////////////////////////////////////////////////////////////// |
|
// CVS Log |
// |
// Testbench for wishbone i2c master module |
// $Id: tst_bench_top.v,v 1.2 2002-03-17 10:26:38 rherveille Exp $ |
// |
// $Date: 2002-03-17 10:26:38 $ |
// $Revision: 1.2 $ |
// $Author: rherveille $ |
// $Locker: $ |
// $State: Exp $ |
// |
// Change History: |
// $Log: not supported by cvs2svn $ |
|
`include "timescale.v" |
|
20,7 → 66,7
wire ack; |
wire inta; |
|
reg [7:0] q; |
reg [7:0] q, qq; |
|
wire scl, scl_o, scl_oen; |
wire sda, sda_o, sda_oen; |
44,7 → 90,7
always #5 clk = ~clk; |
|
// hookup wishbone master model |
wb_master_model u0 ( |
wb_master_model #(8, 32) u0 ( |
.clk(clk), |
.rst(rstn), |
.adr(adr), |
53,6 → 99,7
.cyc(cyc), |
.stb(stb), |
.we(we), |
.sel(), |
.ack(ack), |
.err(1'b0), |
.rty(1'b0) |
98,6 → 145,15
|
initial |
begin |
// force i2c_slave.debug = 1'b1; // enable i2c_slave debug information |
force i2c_slave.debug = 1'b0; // disable i2c_slave debug information |
|
$display("\nstatus: %t Testbench started\n\n", $time); |
|
$dumpfile("bench.vcd"); |
$dumpvars(1, tst_bench_top); |
$dumpvars(1, tst_bench_top.i2c_slave); |
|
// initially values |
clk = 0; |
|
107,6 → 163,8
rstn = 1'b0; // assert reset |
repeat(20) @(posedge clk); |
rstn = 1'b1; // negate reset |
|
$display("status: %t done reset", $time); |
|
@(posedge clk); |
|
115,11 → 173,21
// |
|
// program internal registers |
u0.wb_write(1, PRER_LO, 8'hfa); // load prescaler lo-byte |
// u0.wb_write(1, PRER_LO, 8'hfa); // load prescaler lo-byte |
u0.wb_write(1, PRER_LO, 8'h3e); // load prescaler lo-byte |
u0.wb_write(1, PRER_HI, 8'h00); // load prescaler hi-byte |
|
$display("status: %t programmed registers", $time); |
|
u0.wb_cmp(0, PRER_LO, 8'h3e); // verify prescaler lo-byte |
u0.wb_cmp(0, PRER_HI, 8'h00); // verify prescaler hi-byte |
|
$display("status: %t verified registers", $time); |
|
u0.wb_write(1, CTR, 8'h80); // enable core |
|
$display("status: %t enabled core", $time); |
|
// |
// access slave (write) |
// |
128,44 → 196,62
u0.wb_write(1, TXR, 8'ha0); // present slave address, set write-bit (== !read) |
u0.wb_write(0, CR, 8'h90); // set command (start, write) |
|
$display("status: %t generate 'start', write cmd a0 (slave address+write)", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(0, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// send memory address |
u0.wb_write(1, TXR, 8'h01); // present slave's memory address |
u0.wb_write(0, CR, 8'h10); // set command (write) |
|
$display("status: %t write slave memory address 01", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(0, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// send memory contents |
u0.wb_write(1, TXR, 8'ha5); // present data |
u0.wb_write(0, CR, 8'h10); // set command (stop, write) |
u0.wb_write(0, CR, 8'h10); // set command (write) |
|
$display("status: %t write data a5", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// send memory contents for next memory address (auto_inc) |
u0.wb_write(1, TXR, 8'h5a); // present data |
u0.wb_write(0, CR, 8'h50); // set command (stop, write) |
|
$display("status: %t write next data 5a, generate 'stop'", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
|
// |
// delay |
// |
#100000; // wait for 10us. |
#100000; // wait for 100us. |
|
$display("status: %t wait 100us", $time); |
|
// |
// access slave (read) |
// |
174,55 → 260,94
u0.wb_write(1, TXR, 8'ha0); // present slave address, set write-bit (== !read) |
u0.wb_write(0, CR, 8'h90); // set command (start, write) |
|
$display("status: %t generate 'start', write cmd a0 (slave address+write)", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// send memory address |
u0.wb_write(1, TXR, 8'h00); // present slave's memory address |
u0.wb_write(1, TXR, 8'h01); // present slave's memory address |
u0.wb_write(0, CR, 8'h10); // set command (write) |
|
$display("status: %t write slave address 01", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// drive slave address |
u0.wb_write(1, TXR, 8'ha1); // present slave's address, set read-bit |
u0.wb_write(0, CR, 8'h90); // set command (start, write) |
|
$display("status: %t generate 'repeated start', write cmd a1 (slave address+read)", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// read data from slave |
u0.wb_write(1, CR, 8'h20); // set command (read, ack_read) |
|
$display("status: %t read + ack", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// check data just received |
u0.wb_read(1, RXR, qq); |
if (qq !== 8'ha5) |
$display("\nERROR: Expected a5, received %x at time %t", qq, $time); |
|
// read data from slave |
u0.wb_write(1, CR, 8'h20); // set command (read, ack_read) |
|
$display("status: %t read + ack", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// check data just received |
u0.wb_read(1, RXR, qq); |
if (qq !== 8'h5a) |
$display("\nERROR: Expected 5a, received %x at time %t", qq, $time); |
|
// read data from slave |
u0.wb_write(1, CR, 8'h20); // set command (read, ack_read) |
|
$display("status: %t read + ack", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// check data just received |
u0.wb_read(1, RXR, qq); |
$display("status: %t received %x from 3rd read address", $time, qq); |
|
// read data from slave |
u0.wb_write(1, CR, 8'h28); // set command (read, nack_read) |
$display("status: %t read + nack", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
229,6 → 354,12
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// check data just received |
u0.wb_read(1, RXR, qq); |
$display("status: %t received %x from 4th read address", $time, qq); |
|
// |
// check invalid slave memory address |
// |
237,21 → 368,30
u0.wb_write(1, TXR, 8'ha0); // present slave address, set write-bit (== !read) |
u0.wb_write(0, CR, 8'h90); // set command (start, write) |
|
$display("status: %t generate 'start', write cmd a0 (slave address+write). Check invalid address", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// send memory address |
u0.wb_write(1, TXR, 8'h10); // present slave's memory address |
u0.wb_write(0, CR, 8'h10); // set command (write) |
|
$display("status: %t write slave memory address 10", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
// slave should have send NACK |
$display("status: %t Check for nack", $time); |
if (!q[7]) |
$display("\nERROR: Expected NACK, received ACK\n"); |
|
258,11 → 398,21
// read data from slave |
u0.wb_write(1, CR, 8'h40); // set command (stop) |
|
$display("status: %t generate 'stop'", $time); |
|
// check tip bit |
u0.wb_read(1, SR, q); |
while (q[1]) |
u0.wb_read(1, SR, q); // poll it until it is zero |
|
$display("status: %t tip==0", $time); |
|
|
#25000; // wait 25us |
|
$display("\n\nstatus: %t Testbench done", $time); |
|
$stop; |
end |
|
endmodule |
/trunk/bench/verilog/wb_master_model.v
1,29 → 1,81
/////////////////////////////////////////////////////////////////////// |
//// //// |
//// WISHBONE rev.B2 Wishbone Master model //// |
//// //// |
//// //// |
//// Author: Richard Herveille //// |
//// richard@asics.ws //// |
//// www.asics.ws //// |
//// //// |
//// Downloaded from: http://www.opencores.org/projects/mem_ctrl //// |
//// //// |
/////////////////////////////////////////////////////////////////////// |
//// //// |
//// Copyright (C) 2001 Richard Herveille //// |
//// richard@asics.ws //// |
//// //// |
//// This source file may be used and distributed without //// |
//// restriction provided that this copyright statement is not //// |
//// removed from the file and that any derivative work contains //// |
//// the original copyright notice and the associated disclaimer. //// |
//// //// |
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// |
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// |
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// |
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// |
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// |
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// |
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// |
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// |
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// |
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// |
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// |
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// |
//// POSSIBILITY OF SUCH DAMAGE. //// |
//// //// |
/////////////////////////////////////////////////////////////////////// |
|
// CVS Log |
// |
// Wishbone master model |
// $Id: wb_master_model.v,v 1.2 2002-03-17 10:26:38 rherveille Exp $ |
// |
|
// $Date: 2002-03-17 10:26:38 $ |
// $Revision: 1.2 $ |
// $Author: rherveille $ |
// $Locker: $ |
// $State: Exp $ |
// |
// Change History: |
// |
`include "timescale.v" |
|
module wb_master_model(clk, rst, adr, din, dout, cyc, stb, we, ack, err, rty); |
module wb_master_model(clk, rst, adr, din, dout, cyc, stb, we, sel, ack, err, rty); |
|
input clk, rst; |
output [31:0] adr; |
input [ 7:0] din; |
output [ 7:0] dout; |
output cyc, stb; |
output we; |
input ack, err, rty; |
parameter dwidth = 32; |
parameter awidth = 32; |
|
input clk, rst; |
output [awidth -1:0] adr; |
input [dwidth -1:0] din; |
output [dwidth -1:0] dout; |
output cyc, stb; |
output we; |
output [dwidth/8 -1:0] sel; |
input ack, err, rty; |
|
//////////////////////////////////////////////////////////////////// |
// |
// Local Wires |
// |
|
reg [31:0] adr; |
reg [ 7:0] dout; |
reg cyc, stb; |
reg we; |
reg [awidth -1:0] adr; |
reg [dwidth -1:0] dout; |
reg cyc, stb; |
reg we; |
reg [dwidth/8 -1:0] sel; |
|
reg [dwidth -1:0] q; |
|
//////////////////////////////////////////////////////////////////// |
// |
// Memory Logic |
33,11 → 85,12
begin |
//adr = 32'hxxxx_xxxx; |
//adr = 0; |
adr = 32'hxxxx_xxxx; |
dout = 8'hxx; |
adr = {awidth{1'bx}}; |
dout = {dwidth{1'bx}}; |
cyc = 1'b0; |
stb = 1'bx; |
we = 1'hx; |
sel = {dwidth/8{1'bx}}; |
#1; |
$display("\nINFO: WISHBONE MASTER MODEL INSTANTIATED (%m)\n"); |
end |
48,15 → 101,18
// |
|
task wb_write; |
input delay; |
input delay; |
integer delay; |
|
input [31:0] a; |
input [ 7:0] d; |
input [awidth -1:0] a; |
input [dwidth -1:0] d; |
|
begin |
|
// wait initial delay |
repeat(delay) @(posedge clk); |
|
// assert wishbone signal |
#1; |
adr = a; |
dout = d; |
63,15 → 119,20
cyc = 1'b1; |
stb = 1'b1; |
we = 1'b1; |
sel = {dwidth/8{1'b1}}; |
@(posedge clk); |
|
@(posedge clk); |
// wait for acknowledge from slave |
while(~ack) @(posedge clk); |
|
// negate wishbone signals |
#1; |
cyc = 1'b0; |
stb = 1'bx; |
adr = 32'hxxxx_xxxx; |
dout = 8'hxx; |
adr = {awidth{1'bx}}; |
dout = {dwidth{1'bx}}; |
we = 1'hx; |
sel = {dwidth/8{1'bx}}; |
|
end |
endtask |
82,33 → 143,63
// |
|
task wb_read; |
input delay; |
input delay; |
integer delay; |
|
input [31:0] a; |
output [ 7:0] d; |
input [awidth -1:0] a; |
output [dwidth -1:0] d; |
|
begin |
|
// wait initial delay |
repeat(delay) @(posedge clk); |
|
// assert wishbone signals |
#1; |
adr = a; |
dout = 8'hxx; |
dout = {dwidth{1'bx}}; |
cyc = 1'b1; |
stb = 1'b1; |
we = 1'b0; |
sel = {dwidth/8{1'b1}}; |
@(posedge clk); |
|
@(posedge clk); |
// wait for acknowledge from slave |
while(~ack) @(posedge clk); |
|
// negate wishbone signals |
#1; |
cyc = 1'b0; |
stb = 1'bx; |
adr = 32'hxxxx_xxxx; |
dout = 8'hxx; |
adr = {awidth{1'bx}}; |
dout = {dwidth{1'bx}}; |
we = 1'hx; |
sel = {dwidth/8{1'bx}}; |
d = din; |
|
end |
endtask |
|
//////////////////////////////////////////////////////////////////// |
// |
// Wishbone compare cycle (read data from location and compare with expected data) |
// |
|
task wb_cmp; |
input delay; |
integer delay; |
|
input [awidth -1:0] a; |
input [dwidth -1:0] d_exp; |
|
begin |
wb_read (delay, a, q); |
|
if (d_exp !== q) |
$display("Data compare error. Received %h, expected %h at time %t", q, d_exp, $time); |
end |
endtask |
|
endmodule |
|
|
/trunk/bench/verilog/i2c_slave_model.v
1,6 → 1,51
///////////////////////////////////////////////////////////////////// |
//// //// |
//// WISHBONE rev.B2 compliant synthesizable I2C Slave model //// |
//// //// |
//// //// |
//// Authors: Richard Herveille (richard@asics.ws) www.asics.ws //// |
//// John Sheahan (jrsheahan@optushome.com.au) //// |
//// //// |
//// Downloaded from: http://www.opencores.org/projects/i2c/ //// |
//// //// |
///////////////////////////////////////////////////////////////////// |
//// //// |
//// Copyright (C) 2001,2002 Richard Herveille //// |
//// richard@asics.ws //// |
//// //// |
//// This source file may be used and distributed without //// |
//// restriction provided that this copyright statement is not //// |
//// removed from the file and that any derivative work contains //// |
//// the original copyright notice and the associated disclaimer.//// |
//// //// |
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //// |
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //// |
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //// |
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //// |
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //// |
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //// |
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //// |
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //// |
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //// |
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //// |
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //// |
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //// |
//// POSSIBILITY OF SUCH DAMAGE. //// |
//// //// |
///////////////////////////////////////////////////////////////////// |
|
// CVS Log |
// |
// I2C slave model |
// $Id: i2c_slave_model.v,v 1.2 2002-03-17 10:26:38 rherveille Exp $ |
// |
// $Date: 2002-03-17 10:26:38 $ |
// $Revision: 1.2 $ |
// $Author: rherveille $ |
// $Locker: $ |
// $State: Exp $ |
// |
// Change History: |
// $Log: not supported by cvs2svn $ |
|
`include "timescale.v" |
|
20,6 → 65,8
// |
// Variable declaration |
// |
wire debug = 1'b1; |
|
reg [7:0] mem [3:0]; // initiate memory |
reg [7:0] mem_adr; // memory address |
reg [7:0] mem_do; // memory data output |
64,6 → 111,8
|
//detect my_address |
assign my_adr = (sr[7:1] == I2C_ADR); |
// FIXME: This should not be a generic assign, but rather |
// qualified on address transfer phase and probably reset by stop |
|
//generate bit-counter |
always@(posedge scl) |
78,7 → 127,12
//detect start condition |
always@(negedge sda) |
if (scl) |
begin |
sta <= #1 1'b1; |
|
if (debug) |
$display("DEBUG i2c_slave; start condition detected at %t", $time); |
end |
else |
sta <= #1 1'b0; |
|
88,7 → 142,12
// detect stop condition |
always@(posedge sda) |
if (scl) |
begin |
sto <= #1 1'b1; |
|
if (debug) |
$display("DEBUG i2c_slave; stop condition detected at %t", $time); |
end |
else |
sto <= #1 1'b0; |
|
113,20 → 172,37
case (state) // synopsys full_case parallel_case |
idle: // idle state |
if (acc_done && my_adr) |
begin |
state <= #1 slave_ack; |
rw <= #1 sr[0]; |
|
sda_o <= #1 1'b0; // generate i2c_ack |
|
#2; |
if (debug && rw) |
$display("DEBUG i2c_slave; command byte received (read) at %t", $time); |
if (debug && !rw) |
$display("DEBUG i2c_slave; command byte received (write) at %t", $time); |
|
if (rw) |
begin |
mem_do <= #1 mem[mem_adr]; |
|
if (debug) |
begin |
state <= #1 slave_ack; |
rw <= #1 sr[0]; |
|
sda_o <= #1 1'b0; // generate i2c_ack |
#2 $display("DEBUG i2c_slave; data block read %x from address %x (1)", mem_do, mem_adr); |
#2 $display("DEBUG i2c_slave; memcheck [0]=%x, [1]=%x, [2]=%x", mem[4'h0], mem[4'h1], mem[4'h2]); |
end |
end |
end |
|
slave_ack: |
begin |
if (rw) |
begin |
state <= #1 data; |
sda_o <= #1 mem_do[7]; |
end |
begin |
state <= #1 data; |
sda_o <= #1 mem_do[7]; |
end |
else |
state <= #1 get_mem_adr; |
|
135,13 → 211,16
|
get_mem_adr: // wait for memory address |
if (acc_done) |
begin |
state <= #1 gma_ack; |
mem_adr <= #1 sr; // store memory address |
begin |
state <= #1 gma_ack; |
mem_adr <= #1 sr; // store memory address |
|
sda_o <= #1 !(sr <= 15); // generate i2c_ack, for valid address |
end |
sda_o <= #1 !(sr <= 15); // generate i2c_ack, for valid address |
|
if (debug) |
#1 $display("DEBUG i2c_slave; address received. adr=%x, ack=%b", sr, sda_o); |
end |
|
gma_ack: |
begin |
state <= #1 data; |
154,16 → 233,29
sda_o <= #1 mem_do[7]; |
|
if (acc_done) |
begin |
state <= #1 data_ack; |
|
mem_adr <= #2 mem_adr + 8'h1; |
|
if (rw) |
begin |
state <= #1 data_ack; |
#3 mem_do <= mem[mem_adr]; |
|
mem_adr <= #1 mem_adr + 8'h1; |
if (debug) |
#5 $display("DEBUG i2c_slave; data block read %x from address %x (2)", mem_do, mem_adr); |
end |
|
if (!rw) |
mem[ mem_adr[3:0] ] <= #1 sr; // store data in memory |
|
sda_o <= #1 (rw && (mem_adr <= 15) ); // send ack on write, receive ack on read |
if (!rw) |
begin |
mem[ mem_adr[3:0] ] <= #1 sr; // store data in memory |
|
if (debug) |
#2 $display("DEBUG i2c_slave; data block write %x to address %x", sr, mem_adr); |
end |
|
sda_o <= #1 (rw && (mem_adr <= 15) ); // send ack on write, receive ack on read |
end |
end |
|
data_ack: |
193,9 → 285,7
|
// read data from memory |
always@(posedge scl) |
if (acc_done) |
mem_do <= #1 mem[mem_adr]; |
else |
if (!acc_done && rw) |
mem_do <= #1 {mem_do[6:0], 1'b1}; // insert 1'b1 for host ack generation |
|
// generate tri-states |
204,6 → 294,3
endmodule |
|
|
|
|
|