我是靠谱客的博主 干净戒指,最近开发中收集的这篇文章主要介绍can口通信的软件测试,CAN通信控制程序的仿真与测试,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

//连接 can_top 模块

can_top i_can_top

(

.cs_can_i(cs_can),

.clk_i(clk),

.rx_i(rx_and_tx),

.tx_o(tx),

.irq_on(irq),

.clkout_o(clkout)

);

//产生 24 MHz 时钟

initial

begin

clk=0;

forever #21 clk = ~clk;

end

//初始化

initial

begin

start_tb = 0;

cs_can = 0;

rx = 1;

extended_mode = 0;

tx_bypassed = 0;

rst_i = 1'b0;

ale_i = 1'b0;

rd_i = 1'b0;

wr_i = 1'b0;

port_0_o = 8'h0;

port_0_en = 0;

port_free = 1;

rst_i = 1;

#200 rst_i = 0;

#200 start_tb = 1;

end

//产生延迟的 tx 信号(CAN 发送器延迟)

always

begin

wait (tx);

repeat (4*BRP) @ (posedge clk); // 4 time quants delay

#1 delayed_tx = tx;

wait (~tx);

repeat (4*BRP) @ (posedge clk); // 4 time quants delay

#1 delayed_tx = tx;

end

assign rx_and_tx = rx & (delayed_tx | tx_bypassed); // When this signal is on, tx is notlooped back to the rx.

//主程序

initial

begin

wait(start_tb);

//设置总线时序寄存器

write_register(8'd6, {`CAN_TIMING0_SJW, `CAN_TIMING0_BRP});

write_register(8'd7, {`CAN_TIMING1_SAM, `CAN_TIMING1_TSEG2, `CAN_TIMING1_TSEG1});

// 设置时钟分频寄存器

extended_mode = 1'b0;

write_register(8'd31, {extended_mode, 3'h0, 1'b0, 3'h0}); // Setting the normal mode (notextended)

//设置接收代码和接收寄存器

write_register(8'd16, 8'ha6); // acceptance code 0

write_register(8'd17, 8'hb0); // acceptance code 1

write_register(8'd18, 8'h12); // acceptance code 2

write_register(8'd19, 8'h30); // acceptance code 3

write_register(8'd20, 8'h0); // acceptance mask 0

write_register(8'd21, 8'h0); // acceptance mask 1

write_register(8'd22, 8'h00); // acceptance mask 2

write_register(8'd23, 8'h00); // acceptance mask 3

write_register(8'd4, 8'he8); // acceptance code

write_register(8'd5, 8'h0f); // acceptance mask

#10;

repeat (1000) @ (posedge clk);

//开关复位模式

write_register(8'd0, {7'h0, ~(`CAN_MODE_RESET)});

repeat (BRP) @ (posedge clk);

// 在复位后设置总线空闲

repeat (11) send_bit(1);

test_full_fIFo; // test currently switched on

send_frame; // test currently switched off

bus_off_test; // test currently switched off

forced_bus_off; // test currently switched off

send_frame_basic; // test currently switched off

send_frame_extended; // test currently switched off

self_reception_request; // test currently switched off

manual_frame_basic; // test currently switched off

manual_frame_ext; // test currently switched off

$display("CAN Testbench finished !");

$stop;

end

最后

以上就是干净戒指为你收集整理的can口通信的软件测试,CAN通信控制程序的仿真与测试的全部内容,希望文章能够帮你解决can口通信的软件测试,CAN通信控制程序的仿真与测试所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部