前言:因为目前研究的是如何使用CAN_IP,而CAN_CONTROLLER第一步就是对各个寄存器进行初始化。因此在此先看tb中是如何进行初始化的。并且对各个重要的task进行解读。
task send_bit;//rx线的测试task,单位输入 input bit; integer cnt; begin #1 rx=bit; //延迟一个时间单位 进行赋值 repeat ((`CAN_TIMING1_TSEG1 + `CAN_TIMING1_TSEG2 + 3)*BRP) @ (posedge clk);// 等待((`CAN_TIMING1_TSEG1 + `CAN_TIMING1_TSEG2 + 3)*BRP) 多个时钟上升沿 end endtask /**************************************************************************************** task write_register;//对can1 的寄存器进行操作的task input [7:0] reg_addr; input [7:0] reg_data; `ifdef CAN_WISHBONE_IF //一种总线,在can中使用的是这个结构 begin wait (wb_free); wb_free = 0; @ (posedge wb_clk_i); #1; cs_can = 1; wb_adr_i = reg_addr; wb_dat_i = reg_data; wb_cyc_i = 1; wb_stb_i = 1; wb_we_i = 1; wait (wb_ack_o); @ (posedge wb_clk_i); #1; wb_adr_i = 'hz; wb_dat_i = 'hz; wb_cyc_i = 0; wb_stb_i = 0; wb_we_i = 'hz; cs_can = 0; wb_free = 1; end `else begin $display("(%0t) Writing register [%0d] with 0x%0x", $time, reg_addr, reg_data); wait (port_free); port_free = 0; @ (posedge clk); #1; cs_can = 1; @ (negedge clk); #1; ale_i = 1; port_0_en = 1; port_0_o = reg_addr; @ (negedge clk); #1; ale_i = 0; #90; // 73 - 103 ns port_0_o = reg_data; wr_i = 1; #158; wr_i = 0; port_0_en = 0; cs_can = 0; port_free = 1; end `endif endtask