Line 35... |
Line 35... |
//// ////
|
//// ////
|
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
|
|
// CVS Log
|
// CVS Log
|
//
|
//
|
// $Id: tst_bench_top.v,v 1.2 2002-03-17 10:26:38 rherveille Exp $
|
// $Id: tst_bench_top.v,v 1.3 2002-10-30 18:11:06 rherveille Exp $
|
//
|
//
|
// $Date: 2002-03-17 10:26:38 $
|
// $Date: 2002-10-30 18:11:06 $
|
// $Revision: 1.2 $
|
// $Revision: 1.3 $
|
// $Author: rherveille $
|
// $Author: rherveille $
|
// $Locker: $
|
// $Locker: $
|
// $State: Exp $
|
// $State: Exp $
|
//
|
//
|
// Change History:
|
// Change History:
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
// Revision 1.2 2002/03/17 10:26:38 rherveille
|
|
// Fixed some race conditions in the i2c-slave model.
|
|
// Added debug information.
|
|
// Added headers.
|
|
//
|
|
|
`include "timescale.v"
|
`include "timescale.v"
|
|
|
module tst_bench_top();
|
module tst_bench_top();
|
|
|
Line 143... |
Line 148... |
pullup p1(scl); // pullup scl line
|
pullup p1(scl); // pullup scl line
|
pullup p2(sda); // pullup sda line
|
pullup p2(sda); // pullup sda line
|
|
|
initial
|
initial
|
begin
|
begin
|
|
`ifdef WAVES
|
|
$shm_open("waves");
|
|
$shm_probe("AS",tst_bench_top,"AS");
|
|
$display("INFO: Signal dump enabled ...\n\n");
|
|
`endif
|
|
|
// force i2c_slave.debug = 1'b1; // enable i2c_slave debug information
|
// force i2c_slave.debug = 1'b1; // enable i2c_slave debug information
|
force i2c_slave.debug = 1'b0; // disable i2c_slave debug information
|
force i2c_slave.debug = 1'b0; // disable i2c_slave debug information
|
|
|
$display("\nstatus: %t Testbench started\n\n", $time);
|
$display("\nstatus: %t Testbench started\n\n", $time);
|
|
|
$dumpfile("bench.vcd");
|
// $dumpfile("bench.vcd");
|
$dumpvars(1, tst_bench_top);
|
// $dumpvars(1, tst_bench_top);
|
$dumpvars(1, tst_bench_top.i2c_slave);
|
// $dumpvars(1, tst_bench_top.i2c_slave);
|
|
|
// initially values
|
// initially values
|
clk = 0;
|
clk = 0;
|
|
|
// reset system
|
// reset system
|
Line 172... |
Line 183... |
// program core
|
// program core
|
//
|
//
|
|
|
// program internal registers
|
// 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_LO, 8'hc8); // load prescaler lo-byte
|
u0.wb_write(1, PRER_HI, 8'h00); // load prescaler hi-byte
|
u0.wb_write(1, PRER_HI, 8'h00); // load prescaler hi-byte
|
|
|
$display("status: %t programmed registers", $time);
|
$display("status: %t programmed registers", $time);
|
|
|
u0.wb_cmp(0, PRER_LO, 8'h3e); // verify prescaler lo-byte
|
u0.wb_cmp(0, PRER_LO, 8'hc8); // verify prescaler lo-byte
|
u0.wb_cmp(0, PRER_HI, 8'h00); // verify prescaler hi-byte
|
u0.wb_cmp(0, PRER_HI, 8'h00); // verify prescaler hi-byte
|
|
|
$display("status: %t verified registers", $time);
|
$display("status: %t verified registers", $time);
|
|
|
u0.wb_write(1, CTR, 8'h80); // enable core
|
u0.wb_write(1, CTR, 8'h80); // enable core
|
|
$display("status: %t core enabled", $time);
|
$display("status: %t enabled core", $time);
|
|
|
|
//
|
//
|
// access slave (write)
|
// access slave (write)
|
//
|
//
|
|
|
// drive slave address
|
// drive slave address
|
u0.wb_write(1, TXR, 8'ha0); // present slave address, set write-bit (== !read)
|
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)
|
u0.wb_write(0, CR, 8'h90); // set command (start, write)
|
|
|
$display("status: %t generate 'start', write cmd a0 (slave address+write)", $time);
|
$display("status: %t generate 'start', write cmd a0 (slave address+write)", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(0, SR, q); // poll it until it is zero
|
u0.wb_read(0, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// send memory address
|
// send memory address
|
u0.wb_write(1, TXR, 8'h01); // 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)
|
u0.wb_write(0, CR, 8'h10); // set command (write)
|
|
|
$display("status: %t write slave memory address 01", $time);
|
$display("status: %t write slave memory address 01", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(0, SR, q); // poll it until it is zero
|
u0.wb_read(0, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// send memory contents
|
// send memory contents
|
u0.wb_write(1, TXR, 8'ha5); // present data
|
u0.wb_write(1, TXR, 8'ha5); // present data
|
u0.wb_write(0, CR, 8'h10); // set command (write)
|
u0.wb_write(0, CR, 8'h10); // set command (write)
|
|
|
$display("status: %t write data a5", $time);
|
$display("status: %t write data a5", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// send memory contents for next memory address (auto_inc)
|
// send memory contents for next memory address (auto_inc)
|
u0.wb_write(1, TXR, 8'h5a); // present data
|
u0.wb_write(1, TXR, 8'h5a); // present data
|
u0.wb_write(0, CR, 8'h50); // set command (stop, write)
|
u0.wb_write(0, CR, 8'h50); // set command (stop, write)
|
|
|
$display("status: %t write next data 5a, generate 'stop'", $time);
|
$display("status: %t write next data 5a, generate 'stop'", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
|
|
//
|
//
|
// delay
|
// delay
|
//
|
//
|
#100000; // wait for 100us.
|
// #100000; // wait for 100us.
|
|
// $display("status: %t wait 100us", $time);
|
$display("status: %t wait 100us", $time);
|
|
|
|
//
|
//
|
// access slave (read)
|
// access slave (read)
|
//
|
//
|
|
|
// drive slave address
|
// drive slave address
|
u0.wb_write(1, TXR, 8'ha0); // present slave address, set write-bit (== !read)
|
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)
|
u0.wb_write(0, CR, 8'h90); // set command (start, write)
|
|
|
$display("status: %t generate 'start', write cmd a0 (slave address+write)", $time);
|
$display("status: %t generate 'start', write cmd a0 (slave address+write)", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// send memory address
|
// send memory address
|
u0.wb_write(1, TXR, 8'h01); // 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)
|
u0.wb_write(0, CR, 8'h10); // set command (write)
|
|
|
$display("status: %t write slave address 01", $time);
|
$display("status: %t write slave address 01", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// drive slave address
|
// drive slave address
|
u0.wb_write(1, TXR, 8'ha1); // present slave's address, set read-bit
|
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)
|
u0.wb_write(0, CR, 8'h90); // set command (start, write)
|
|
|
$display("status: %t generate 'repeated start', write cmd a1 (slave address+read)", $time);
|
$display("status: %t generate 'repeated start', write cmd a1 (slave address+read)", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// read data from slave
|
// read data from slave
|
u0.wb_write(1, CR, 8'h20); // set command (read, ack_read)
|
u0.wb_write(1, CR, 8'h20); // set command (read, ack_read)
|
|
|
$display("status: %t read + ack", $time);
|
$display("status: %t read + ack", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// check data just received
|
// check data just received
|
u0.wb_read(1, RXR, qq);
|
u0.wb_read(1, RXR, qq);
|
if (qq !== 8'ha5)
|
if (qq !== 8'ha5)
|
$display("\nERROR: Expected a5, received %x at time %t", qq, $time);
|
$display("\nERROR: Expected a5, received %x at time %t", qq, $time);
|
|
|
// read data from slave
|
// read data from slave
|
u0.wb_write(1, CR, 8'h20); // set command (read, ack_read)
|
u0.wb_write(1, CR, 8'h20); // set command (read, ack_read)
|
|
|
$display("status: %t read + ack", $time);
|
$display("status: %t read + ack", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// check data just received
|
// check data just received
|
u0.wb_read(1, RXR, qq);
|
u0.wb_read(1, RXR, qq);
|
if (qq !== 8'h5a)
|
if (qq !== 8'h5a)
|
$display("\nERROR: Expected 5a, received %x at time %t", qq, $time);
|
$display("\nERROR: Expected 5a, received %x at time %t", qq, $time);
|
|
|
// read data from slave
|
// read data from slave
|
u0.wb_write(1, CR, 8'h20); // set command (read, ack_read)
|
u0.wb_write(1, CR, 8'h20); // set command (read, ack_read)
|
|
|
$display("status: %t read + ack", $time);
|
$display("status: %t read + ack", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// check data just received
|
// check data just received
|
u0.wb_read(1, RXR, qq);
|
u0.wb_read(1, RXR, qq);
|
$display("status: %t received %x from 3rd read address", $time, qq);
|
$display("status: %t received %x from 3rd read address", $time, qq);
|
Line 351... |
Line 337... |
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// check data just received
|
// check data just received
|
u0.wb_read(1, RXR, qq);
|
u0.wb_read(1, RXR, qq);
|
$display("status: %t received %x from 4th read address", $time, qq);
|
$display("status: %t received %x from 4th read address", $time, qq);
|
Line 365... |
Line 350... |
//
|
//
|
|
|
// drive slave address
|
// drive slave address
|
u0.wb_write(1, TXR, 8'ha0); // present slave address, set write-bit (== !read)
|
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)
|
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);
|
$display("status: %t generate 'start', write cmd a0 (slave address+write). Check invalid address", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// send memory address
|
// send memory address
|
u0.wb_write(1, TXR, 8'h10); // present slave's memory address
|
u0.wb_write(1, TXR, 8'h10); // present slave's memory address
|
u0.wb_write(0, CR, 8'h10); // set command (write)
|
u0.wb_write(0, CR, 8'h10); // set command (write)
|
|
|
$display("status: %t write slave memory address 10", $time);
|
$display("status: %t write slave memory address 10", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
// slave should have send NACK
|
// slave should have send NACK
|
$display("status: %t Check for nack", $time);
|
$display("status: %t Check for nack", $time);
|
if (!q[7])
|
if (!q[7])
|
$display("\nERROR: Expected NACK, received ACK\n");
|
$display("\nERROR: Expected NACK, received ACK\n");
|
|
|
// read data from slave
|
// read data from slave
|
u0.wb_write(1, CR, 8'h40); // set command (stop)
|
u0.wb_write(1, CR, 8'h40); // set command (stop)
|
|
|
$display("status: %t generate 'stop'", $time);
|
$display("status: %t generate 'stop'", $time);
|
|
|
// check tip bit
|
// check tip bit
|
u0.wb_read(1, SR, q);
|
u0.wb_read(1, SR, q);
|
while (q[1])
|
while (q[1])
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
u0.wb_read(1, SR, q); // poll it until it is zero
|
|
|
$display("status: %t tip==0", $time);
|
$display("status: %t tip==0", $time);
|
|
|
|
|
#25000; // wait 25us
|
#25000; // wait 25us
|
|
|
$display("\n\nstatus: %t Testbench done", $time);
|
$display("\n\nstatus: %t Testbench done", $time);
|
|
$finish;
|
$stop;
|
|
end
|
end
|
|
|
endmodule
|
endmodule
|
|
|
|
|