axi代码
时间: 2023-07-02 17:23:55 浏览: 47
AXI (Advanced eXtensible Interface) 是一种用于片上总线的标准协议。下面是一个 AXI4-Lite 总线的简单读写示例:
```verilog
module axi_lite_example (
input clk,
input rst,
input [31:0] addr,
input [31:0] write_data,
input write_en,
output [31:0] read_data,
input read_en
);
// AXI4-Lite Slave 接口
reg [31:0] reg_data;
always @(posedge clk) begin
if (rst) begin
reg_data <= 32'h0;
end else if (write_en) begin
reg_data <= write_data;
end
end
assign read_data = read_en ? reg_data : 32'h0;
endmodule
```
这个模块有一个 AXI4-Lite Slave 接口,可以通过 `addr`、`write_data`、`write_en`、`read_en` 来访问它。当 `write_en` 为 1 时,将 `write_data` 写入到 `addr` 所表示的寄存器中;当 `read_en` 为 1 时,从 `addr` 所表示的寄存器中读取数据,并将其输出到 `read_data` 中。