Line 43... |
Line 43... |
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
// CVS Revision History
|
// CVS Revision History
|
//
|
//
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
// Revision 1.8 2003/01/08 02:09:43 mohor
|
|
// Acceptance filter added.
|
|
//
|
// Revision 1.7 2002/12/28 04:13:53 mohor
|
// Revision 1.7 2002/12/28 04:13:53 mohor
|
// Backup version.
|
// Backup version.
|
//
|
//
|
// Revision 1.6 2002/12/27 00:12:48 mohor
|
// Revision 1.6 2002/12/27 00:12:48 mohor
|
// Header changed, testbench improved to send a frame (crc still missing).
|
// Header changed, testbench improved to send a frame (crc still missing).
|
Line 90... |
Line 93... |
wire [7:0] data_out;
|
wire [7:0] data_out;
|
reg cs, rw;
|
reg cs, rw;
|
reg [7:0] addr;
|
reg [7:0] addr;
|
reg rx;
|
reg rx;
|
integer start_tb;
|
integer start_tb;
|
|
reg [7:0] tmp_data;
|
|
|
// Instantiate can_top module
|
// Instantiate can_top module
|
can_top i_can_top
|
can_top i_can_top
|
(
|
(
|
.clk(clk),
|
.clk(clk),
|
Line 137... |
Line 141... |
write_register(8'h6, {`CAN_TIMING0_SJW, `CAN_TIMING0_BRP});
|
write_register(8'h6, {`CAN_TIMING0_SJW, `CAN_TIMING0_BRP});
|
|
|
// Set bus timing register 1
|
// Set bus timing register 1
|
write_register(8'h7, {`CAN_TIMING1_SAM, `CAN_TIMING1_TSEG2, `CAN_TIMING1_TSEG1});
|
write_register(8'h7, {`CAN_TIMING1_SAM, `CAN_TIMING1_TSEG2, `CAN_TIMING1_TSEG1});
|
|
|
|
|
|
|
// Set Clock Divider register
|
// Set Clock Divider register
|
write_register(8'h31, {`CAN_CLOCK_DIVIDER_MODE, 7'h0}); // Setting the normal mode (not extended)
|
write_register(8'h31, {`CAN_CLOCK_DIVIDER_MODE, 7'h0}); // Setting the normal mode (not extended)
|
|
|
// Set Acceptance Code and Acceptance Mask registers (their address differs for basic and extended mode
|
// Set Acceptance Code and Acceptance Mask registers (their address differs for basic and extended mode
|
if(`CAN_CLOCK_DIVIDER_MODE) // Extended mode
|
if(`CAN_CLOCK_DIVIDER_MODE) // Extended mode
|
Line 186... |
Line 192... |
send_frame(0, 1, {26'h00000a6, 3'h5}, 2, 15'h2a11); // mode, rtr, id, length, crc
|
send_frame(0, 1, {26'h00000a6, 3'h5}, 2, 15'h2a11); // mode, rtr, id, length, crc
|
end
|
end
|
|
|
|
|
repeat (50000) @ (posedge clk);
|
repeat (50000) @ (posedge clk);
|
|
|
|
read_register(8'h4);
|
|
read_register(8'h20);
|
|
read_register(8'h21);
|
|
read_register(8'h22);
|
|
read_register(8'h23);
|
|
read_register(8'h24);
|
|
read_register(8'h25);
|
|
|
|
|
$display("CAN Testbench finished.");
|
$display("CAN Testbench finished.");
|
$stop;
|
$stop;
|
end
|
end
|
|
|
|
|
|
|
|
|
|
task read_register;
|
|
input [7:0] reg_addr;
|
|
|
|
begin
|
|
@ (posedge clk);
|
|
#1;
|
|
addr = reg_addr;
|
|
cs = 1;
|
|
rw = 1;
|
|
@ (posedge clk);
|
|
$display("(%0t) Reading register [0x%0x] = 0x%0x", $time, addr, data_out);
|
|
#1;
|
|
addr = 'hz;
|
|
cs = 0;
|
|
rw = 'hz;
|
|
end
|
|
endtask
|
|
|
|
|
task write_register;
|
task write_register;
|
input [7:0] reg_addr;
|
input [7:0] reg_addr;
|
input [7:0] reg_data;
|
input [7:0] reg_data;
|
|
|
begin
|
begin
|