握手机制的verilog实现

保持寄存器+握手

“一种解决总线同步问题的方法是使用一个保持寄存器和握手信号”,这也就是“先异步暂存,后同步写入”的方法

分别编写了发送时钟域和接收时钟域的代码进行测试,用到两组MEM,以便于观察实验结果:
//发送端代码

//接收域应答信号ack采用两级寄存器同步,便于时序收敛

module woshou_tx(
 input rst_n,
 input t_clk,
 input ack,
 output [7:0] dout,
 output reg req
);

reg ack_reg1,ack_reg2;
reg [7:0] data_buf;
reg [2:0]tr_state;
reg [7:0] TR_MEM_Addr;
reg [7:0] TR_MEM [255:0];

parameter TR_IDLE=3'b000, SND_DATA_REQ=3'b001, CHK_ACK_ACTIVE=3'b010, CHK_COMM_END=3'b100;

always@(negedge rst_n or posedge t_clk)
begin
 if
  • 7
    点赞
  • 76
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是乒乓buffer双向握手Verilog实现: ```verilog module PingPongBuffer ( input clk, input reset, input tx_en, input rx_en, input [7:0] tx_data, output reg [7:0] rx_data ); reg [7:0] tx_reg; reg [1:0] state; parameter IDLE = 2'b00; parameter TX = 2'b01; parameter RX = 2'b10; always @(posedge clk) begin if (reset) begin state <= IDLE; tx_reg <= 8'h00; rx_data <= 8'h00; end else begin case (state) IDLE: begin if (tx_en) begin tx_reg <= tx_data; state <= TX; end else if (rx_en) begin state <= RX; end end TX: begin if (!tx_en) begin state <= IDLE; end else if (rx_en) begin state <= RX; end end RX: begin if (!rx_en) begin state <= IDLE; end else if (tx_en) begin tx_reg <= tx_data; state <= TX; end else begin rx_data <= tx_reg; state <= IDLE; end end endcase end end endmodule ``` 此模块有四个输入端口和一个输出端口: - `clk`是时钟信号 - `reset`是复位信号 - `tx_en`是发送使能信号 - `rx_en`是接收使能信号 - `tx_data`是发送数据 - `rx_data`是接收数据 在每个时钟周期中,状态机根据当前状态以及输入信号进行决策。在空闲状态下,如果收到发送使能信号,则将发送数据存储在缓冲寄存器中,并转换到发送状态。在发送状态下,如果收到发送使能信号,则更新缓冲寄存器中的数据。如果收到接收使能信号,则转换到接收状态。在接收状态下,如果收到发送使能信号,则将新的发送数据存储在缓冲寄存器中,并转换到发送状态。否则,将缓冲寄存器中的数据发送到接收数据端口,并转换回空闲状态。 这个模块可以用于实现双向通信,例如在一个串行通信接口中使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值