當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]include "timescale.v"// synopsys translate_on`include "can_defines.v" module can_top( `ifdef CAN_WISHBONE_IF wb_clk_i, wb_rst_i, wb_dat_i, wb_dat_o, wb_cyc_i, wb_stb_i, wb_we_i,

include "timescale.v"

// synopsys translate_on

`include "can_defines.v"

 

module can_top

(

  `ifdef CAN_WISHBONE_IF

    wb_clk_i,

    wb_rst_i,

    wb_dat_i,

    wb_dat_o,

    wb_cyc_i,

    wb_stb_i,

    wb_we_i,

    wb_adr_i,

    wb_ack_o,

  `else

    rst_i,

    ale_i,

    rd_i,

    wr_i,

    port_0_io,

  `endif

  cs_can_i,

  clk_i,

  rx_i,

  tx_o,

  irq_on,

  clkout_o

);

 

parameter Tp = 1;

 

`ifdef CAN_WISHBONE_IF

  input        wb_clk_i;

  input        wb_rst_i;

  input  [7:0] wb_dat_i;

  output [7:0] wb_dat_o;

  input        wb_cyc_i;

  input        wb_stb_i;

  input        wb_we_i;

  input  [7:0] wb_adr_i;

  output       wb_ack_o;

 

  reg          wb_ack_o;

  reg          cs_sync1;

  reg          cs_sync2;

  reg          cs_sync3;

 

  reg          cs_ack1;

  reg          cs_ack2;

  reg          cs_ack3;

  reg          cs_sync_rst1;

  reg          cs_sync_rst2;

`else

  input        rst_i;

  input        ale_i;

  input        rd_i;

  input        wr_i;

  inout  [7:0] port_0_io;

 

  reg    [7:0] addr_latched;

  reg          wr_i_q;

  reg          rd_i_q;

`endif

 

input        cs_can_i;

input        clk_i;

input        rx_i;

output       tx_o;

output       irq_on;

output       clkout_o;

 

reg          data_out_fifo_selected;

 

 

wire         irq_o;

wire   [7:0] data_out_fifo;

wire   [7:0] data_out_regs;

 

 

/* Mode register */

wire         reset_mode;

wire         listen_only_mode;

wire         acceptance_filter_mode;

wire         self_test_mode;

 

/* Command register */

wire         release_buffer;

wire         tx_request;

wire         abort_tx;

wire         self_rx_request;

wire         single_shot_transmission;

 

/* Arbitration Lost Capture Register */

wire         read_arbitration_lost_capture_reg;

 

/* Error Code Capture Register */

wire         read_error_code_capture_reg;

wire   [7:0] error_capture_code;

 

/* Bus Timing 0 register */

wire   [5:0] baud_r_presc;

wire   [1:0] sync_jump_width;

 

/* Bus Timing 1 register */

wire   [3:0] time_segment1;

wire   [2:0] time_segment2;

wire         triple_sampling;

 

/* Error Warning Limit register */

wire   [7:0] error_warning_limit;

 

/* Rx Error Counter register */

wire         we_rx_err_cnt;

 

/* Tx Error Counter register */

wire         we_tx_err_cnt;

 

/* Clock Divider register */

wire         extended_mode;

 

/* This section is for BASIC and EXTENDED mode */

/* Acceptance code register */

wire   [7:0] acceptance_code_0;

 

/* Acceptance mask register */

wire   [7:0] acceptance_mask_0;

/* End: This section is for BASIC and EXTENDED mode */

 

 

/* This section is for EXTENDED mode */

/* Acceptance code register */

wire   [7:0] acceptance_code_1;

wire   [7:0] acceptance_code_2;

wire   [7:0] acceptance_code_3;

 

/* Acceptance mask register */

wire   [7:0] acceptance_mask_1;

wire   [7:0] acceptance_mask_2;

wire   [7:0] acceptance_mask_3;

/* End: This section is for EXTENDED mode */

 

/* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */

wire   [7:0] tx_data_0;

wire   [7:0] tx_data_1;

wire   [7:0] tx_data_2;

wire   [7:0] tx_data_3;

wire   [7:0] tx_data_4;

wire   [7:0] tx_data_5;

wire   [7:0] tx_data_6;

wire   [7:0] tx_data_7;

wire   [7:0] tx_data_8;

wire   [7:0] tx_data_9;

wire   [7:0] tx_data_10;

wire   [7:0] tx_data_11;

wire   [7:0] tx_data_12;

/* End: Tx data registers */
 

wire         cs;

 

/* Output signals from can_btl module */

wire         clk_en;

wire         sample_point;

wire         sampled_bit;

wire         sampled_bit_q;

wire         tx_point;

wire         hard_sync;

wire         resync;

 

 

/* output from can_bsp module */

wire         rx_idle;

wire         transmitting;

wire         last_bit_of_inter;

wire         set_reset_mode;

wire         node_bus_off;

wire         error_status;

wire   [7:0] rx_err_cnt;

wire   [7:0] tx_err_cnt;

wire         rx_err_cnt_dummy;  // The MSB is not displayed. It is just used for easier calculation (no counter overflow).

wire         tx_err_cnt_dummy;  // The MSB is not displayed. It is just used for easier calculation (no counter overflow).

wire         transmit_status;

wire         receive_status;

wire         tx_successful;

wire         need_to_tx;

wire         overrun;

wire         info_empty;

wire         set_bus_error_irq;

wire         set_arbitration_lost_irq;

wire   [4:0] arbitration_lost_capture;

wire         node_error_passive;

wire         node_error_active;

wire   [6:0] rx_message_counter;

wire         tx_out;

wire         tx_oen;

 

wire         rst;

wire         we;

wire   [7:0] addr;

wire   [7:0] data_in;

reg    [7:0] data_out;

 

 

/* Connecting can_registers module */

can_registers i_can_registers

(

  .clk(clk_i),

  .rst(rst),

  .cs(cs),

  .we(we),

  .addr(addr),

  .data_in(data_in),

  .data_out(data_out_regs),

  .irq(irq_o),

 

  .sample_point(sample_point),

  .transmitting(transmitting),

  .set_reset_mode(set_reset_mode),

  .node_bus_off(node_bus_off),

  .error_status(error_status),

  .rx_err_cnt(rx_err_cnt),

  .tx_err_cnt(tx_err_cnt),

  .transmit_status(transmit_status),

  .receive_status(receive_status),

  .tx_successful(tx_successful),

  .need_to_tx(need_to_tx),

  .overrun(overrun),

  .info_empty(info_empty),

  .set_bus_error_irq(set_bus_error_irq),

  .set_arbitration_lost_irq(set_arbitration_lost_irq),

  .arbitration_lost_capture(arbitration_lost_capture),

  .node_error_passive(node_error_passive),

  .node_error_active(node_error_active),

  .rx_message_counter(rx_message_counter),

 

 

  /* Mode register */

  .reset_mode(reset_mode),

  .listen_only_mode(listen_only_mode),

  .acceptance_filter_mode(acceptance_filter_mode),

  .self_test_mode(self_test_mode),

 

  /* Command register */

  .clear_data_overrun(),

  .release_buffer(release_buffer),

  .abort_tx(abort_tx),

  .tx_request(tx_request),

  .self_rx_request(self_rx_request),

  .single_shot_transmission(single_shot_transmission),

 

  /* Arbitration Lost Capture Register */

  .read_arbitration_lost_capture_reg(read_arbitration_lost_capture_reg),

 

  /* Error Code Capture Register */

  .read_error_code_capture_reg(read_error_code_capture_reg),

  .error_capture_code(error_capture_code),

 

  /* Bus Timing 0 register */

  .baud_r_presc(baud_r_presc),

  .sync_jump_width(sync_jump_width),

 

  /* Bus Timing 1 register */

  .time_segment1(time_segment1),

  .time_segment2(time_segment2),

  .triple_sampling(triple_sampling),

 

  /* Error Warning Limit register */

  .error_warning_limit(error_warning_limit),

 

  /* Rx Error Counter register */

  .we_rx_err_cnt(we_rx_err_cnt),

 

  /* Tx Error Counter register */

  .we_tx_err_cnt(we_tx_err_cnt),

 

  /* Clock Divider register */

  .extended_mode(extended_mode),

  .clkout(clkout_o),

 

  /* This section is for BASIC and EXTENDED mode */

  /* Acceptance code register */

  .acceptance_code_0(acceptance_code_0),

 

  /* Acceptance mask register */

  .acceptance_mask_0(acceptance_mask_0),

  /* End: This section is for BASIC and EXTENDED mode */

 

  /* This section is for EXTENDED mode */

  /* Acceptance code register */

  .acceptance_code_1(acceptance_code_1),

  .acceptance_code_2(acceptance_code_2),

  .acceptance_code_3(acceptance_code_3),

 

  /* Acceptance mask register */

  .acceptance_mask_1(acceptance_mask_1),

  .acceptance_mask_2(acceptance_mask_2),

  .acceptance_mask_3(acceptance_mask_3),

  /* End: This section is for EXTENDED mode */

 

  /* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */

  .tx_data_0(tx_data_0),

  .tx_data_1(tx_data_1),

  .tx_data_2(tx_data_2),

  .tx_data_3(tx_data_3),

  .tx_data_4(tx_data_4),

  .tx_data_5(tx_data_5),

  .tx_data_6(tx_data_6),

  .tx_data_7(tx_data_7),

  .tx_data_8(tx_data_8),

  .tx_data_9(tx_data_9),

  .tx_data_10(tx_data_10),

  .tx_data_11(tx_data_11),

  .tx_data_12(tx_data_12)

  /* End: Tx data registers */

);

 

 

assign irq_on = ~irq_o;

 

 

/* Connecting can_btl module */

can_btl i_can_btl

(

  .clk(clk_i),

  .rst(rst),

  .rx(rx_i),

 

  /* Mode register */

  .reset_mode(reset_mode),

 

  /* Bus Timing 0 register */

  .baud_r_presc(baud_r_presc),

  .sync_jump_width(sync_jump_width),

 

  /* Bus Timing 1 register */

  .time_segment1(time_segment1),

  .time_segment2(time_segment2),

  .triple_sampling(triple_sampling),

 

  /* Output signals from this module */

  .clk_en(clk_en),

  .sample_point(sample_point),

  .sampled_bit(sampled_bit),

  .sampled_bit_q(sampled_bit_q),

  .tx_point(tx_point),

  .hard_sync(hard_sync),

  .resync(resync),

 

 

  /* output from can_bsp module */

  .rx_idle(rx_idle),

  .transmitting(transmitting),

  .last_bit_of_inter(last_bit_of_inter)

 

 

 

);

 

 

 

can_bsp i_can_bsp

(

  .clk(clk_i),

  .rst(rst),

 

  /* From btl module */

  .sample_point(sample_point),

  .sampled_bit(sampled_bit),

  .sampled_bit_q(sampled_bit_q),

  .tx_point(tx_point),

  .hard_sync(hard_sync),

 

  .addr(addr),

  .data_in(data_in),

  .data_out(data_out_fifo),

  .fifo_selected(data_out_fifo_selected),
/* Mode register */

 

  .reset_mode(reset_mode),

  .listen_only_mode(listen_only_mode),

  .acceptance_filter_mode(acceptance_filter_mode),

  .self_test_mode(self_test_mode),

 

  /* Command register */

  .release_buffer(release_buffer),

  .tx_request(tx_request),

  .abort_tx(abort_tx),

  .self_rx_request(self_rx_request),

  .single_shot_transmission(single_shot_transmission),

 

  /* Arbitration Lost Capture Register */

  .read_arbitration_lost_capture_reg(read_arbitration_lost_capture_reg),

 

  /* Error Code Capture Register */

  .read_error_code_capture_reg(read_error_code_capture_reg),

  .error_capture_code(error_capture_code),

 

  /* Error Warning Limit register */

  .error_warning_limit(error_warning_limit),

 

  /* Rx Error Counter register */

  .we_rx_err_cnt(we_rx_err_cnt),

 

  /* Tx Error Counter register */

  .we_tx_err_cnt(we_tx_err_cnt),

 

  /* Clock Divider register */

  .extended_mode(extended_mode),

 

  /* output from can_bsp module */

  .rx_idle(rx_idle),

  .transmitting(transmitting),

  .last_bit_of_inter(last_bit_of_inter),

  .set_reset_mode(set_reset_mode),

  .node_bus_off(node_bus_off),

  .error_status(error_status),

  .rx_err_cnt({rx_err_cnt_dummy, rx_err_cnt[7:0]}),   // The MSB is not displayed. It is just used for easier calculation (no counter overflow).

  .tx_err_cnt({tx_err_cnt_dummy, tx_err_cnt[7:0]}),   // The MSB is not displayed. It is just used for easier calculation (no counter overflow).

  .transmit_status(transmit_status),

  .receive_status(receive_status),

  .tx_successful(tx_successful),

  .need_to_tx(need_to_tx),

  .overrun(overrun),

  .info_empty(info_empty),

  .set_bus_error_irq(set_bus_error_irq),

  .set_arbitration_lost_irq(set_arbitration_lost_irq),

  .arbitration_lost_capture(arbitration_lost_capture),

  .node_error_passive(node_error_passive),

  .node_error_active(node_error_active),

  .rx_message_counter(rx_message_counter),

 

  /* This section is for BASIC and EXTENDED mode */

  /* Acceptance code register */

  .acceptance_code_0(acceptance_code_0),

 

  /* Acceptance mask register */

  .acceptance_mask_0(acceptance_mask_0),

  /* End: This section is for BASIC and EXTENDED mode */

 

  /* This section is for EXTENDED mode */

  /* Acceptance code register */

  .acceptance_code_1(acceptance_code_1),

  .acceptance_code_2(acceptance_code_2),

  .acceptance_code_3(acceptance_code_3),

 

  /* Acceptance mask register */

  .acceptance_mask_1(acceptance_mask_1),

  .acceptance_mask_2(acceptance_mask_2),

  .acceptance_mask_3(acceptance_mask_3),

  /* End: This section is for EXTENDED mode */

 

  /* Tx data registers. Holding identifier (basic mode), tx frame information (extended mode) and data */

  .tx_data_0(tx_data_0),

  .tx_data_1(tx_data_1),

  .tx_data_2(tx_data_2),

  .tx_data_3(tx_data_3),

  .tx_data_4(tx_data_4),

  .tx_data_5(tx_data_5),

  .tx_data_6(tx_data_6),

  .tx_data_7(tx_data_7),

  .tx_data_8(tx_data_8),

  .tx_data_9(tx_data_9),

  .tx_data_10(tx_data_10),

  .tx_data_11(tx_data_11),

  .tx_data_12(tx_data_12),

  /* End: Tx data registers */

 

  /* Tx signal */

  .tx(tx_out),

  .tx_oen(tx_oen)

);

 

assign tx_o = tx_oen? 1'bz : tx_out;

 

 

// Multiplexing wb_dat_o from registers and rx fifo

always @ (extended_mode or addr or reset_mode)

begin

  if (extended_mode & (~reset_mode) & ((addr >= 8'd16) && (addr <= 8'd28)) | (~extended_mode) & ((addr >= 8'd20) && (addr <= 8'd29)))

    data_out_fifo_selected <= 1'b1;

  else

    data_out_fifo_selected <= 1'b0;

end

 

 

always @ (posedge clk_i)

begin

//  if (wb_cyc_i & (~wb_we_i))

  if (cs & (~we))

    begin

      if (data_out_fifo_selected)

        data_out <=#Tp data_out_fifo;

      else

        data_out <=#Tp data_out_regs;

    end

end

 

 

 

`ifdef CAN_WISHBONE_IF

  // Combining wb_cyc_i and wb_stb_i signals to cs signal. Than synchronizing to clk_i clock domain.

  always @ (posedge clk_i or posedge rst)

  begin

    if (rst)

      begin

        cs_sync1     <= 1'b0;

        cs_sync2     <= 1'b0;

        cs_sync3     <= 1'b0;

        cs_sync_rst1 <= 1'b0;

        cs_sync_rst2 <= 1'b0;

      end

    else

      begin

        cs_sync1     <=#Tp wb_cyc_i & wb_stb_i & (~cs_sync_rst2) & cs_can_i;

        cs_sync2     <=#Tp cs_sync1            & (~cs_sync_rst2);

        cs_sync3     <=#Tp cs_sync2            & (~cs_sync_rst2);

        cs_sync_rst1 <=#Tp cs_ack3;

        cs_sync_rst2 <=#Tp cs_sync_rst1;

      end

  end

 

 

  assign cs = cs_sync2 & (~cs_sync3);

 

 

  always @ (posedge wb_clk_i)

  begin

    cs_ack1 <=#Tp cs_sync3;

    cs_ack2 <=#Tp cs_ack1;

    cs_ack3 <=#Tp cs_ack2;

  end

 

 

 

  // Generating acknowledge signal

  always @ (posedge wb_clk_i)

  begin

    wb_ack_o <=#Tp (cs_ack2 & (~cs_ack3));

  end

 

 

  assign rst      = wb_rst_i;

  assign we       = wb_we_i;

  assign addr     = wb_adr_i;

  assign data_in  = wb_dat_i;

  assign wb_dat_o = data_out;

 

 

`else

 

  // Latching address

  always @ (negedge clk_i or posedge rst)

  begin

    if (rst)

      addr_latched <= 8'h0;

    else if (ale_i)

      addr_latched <=#Tp port_0_io;

  end

 

 

  // Generating delayed wr_i and rd_i signals

  always @ (posedge clk_i or posedge rst)

  begin

    if (rst)

      begin

        wr_i_q <= 1'b0;

        rd_i_q <= 1'b0;

      end

    else

      begin

        wr_i_q <=#Tp wr_i;

        rd_i_q <=#Tp rd_i;

      end

  end

 

 

  assign cs = ((wr_i & (~wr_i_q)) | (rd_i & (~rd_i_q))) & cs_can_i;

 

 

  assign rst       = rst_i;

  assign we        = wr_i;

  assign addr      = addr_latched;

  assign data_in   = port_0_io;

  assign port_0_io = (cs_can_i & rd_i)? data_out : 8'hz;

 

`endif

 

endmodule

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫?dú)角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉(zhuǎn)型技術(shù)解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關(guān)鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運(yùn)行,同時企業(yè)卻面臨越來越多業(yè)務(wù)中斷的風(fēng)險,如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報道,騰訊和網(wǎng)易近期正在縮減他們對日本游戲市場的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機(jī) 衛(wèi)星通信

要點(diǎn): 有效應(yīng)對環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實(shí)提質(zhì)增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競爭力 堅持高質(zhì)量發(fā)展策略,塑強(qiáng)核心競爭優(yōu)勢...

關(guān)鍵字: 通信 BSP 電信運(yùn)營商 數(shù)字經(jīng)濟(jì)

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術(shù)學(xué)會聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(shù)(集團(tuán))股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉