📄 bmd_ep_mem_access.v
字号:
//--------------------------------------------------------------------------------//--//-- This file is owned and controlled by Xilinx and must be used solely//-- for design, simulation, implementation and creation of design files//-- limited to Xilinx devices or technologies. Use with non-Xilinx//-- devices or technologies is expressly prohibited and immediately//-- terminates your license.//--//-- Xilinx products are not intended for use in life support//-- appliances, devices, or systems. Use in such applications is//-- expressly prohibited.//--//-- **************************************//-- ** Copyright (C) 2005, Xilinx, Inc. **//-- ** All Rights Reserved. **//-- **************************************//--//--------------------------------------------------------------------------------//-- Filename: BMD_EP_MEM_ACCESS.v//--//-- Description: Endpoint Memory Access Unit. This module provides access functions//-- to the Endpoint memory aperture.//--//-- Read Access: Module returns data for the specifed address and//-- byte enables selected. //-- //-- Write Access: Module accepts data, byte enables and updates//-- data when write enable is asserted. Modules signals write busy //-- when data write is in progress. //--//--------------------------------------------------------------------------------`timescale 1ns/1ns`define BMD_MEM_ACCESS_WR_RST 3'b000`define BMD_MEM_ACCESS_WR_WAIT 3'b001`define BMD_MEM_ACCESS_WR_READ 3'b010`define BMD_MEM_ACCESS_WR_WRITE 3'b100module BMD_EP_MEM_ACCESS ( clk, rst_n, // Misc. control ports cfg_max_rd_req_size, // I [2:0] cfg_max_payload_size, // I [2:0] // Read Access addr_i, // I [6:0] rd_be_i, // I [3:0] rd_data_o, // O [31:0] // Write Access wr_be_i, // I [7:0] wr_data_i, // I [31:0] wr_en_i, // I wr_busy_o, // O init_rst_o, // O mrd_start_o, // O mrd_done_o, // O mrd_addr_o, // O [31:0] mrd_len_o, // O [31:0] mrd_count_o, // O [31:0] mwr_start_o, // O mwr_done_i, // I mwr_addr_o, // O [31:0] mwr_len_o, // O [31:0] mwr_count_o, // O [31:0] mwr_data_o, cpl_ur_found_i, // I [7:0] cpl_ur_tag_i, // I [7:0] cpld_found_i, // I [31:0] cpld_data_size_i, // I [31:0] cpld_malformed_i, int_src_rd_i, // I int_src_wr_i, // I int_clear_o // O ); input clk; input rst_n; /* * Misc. control ports */ input [2:0] cfg_max_rd_req_size; input [2:0] cfg_max_payload_size; /* * Read Port */ input [6:0] addr_i; input [3:0] rd_be_i; output [31:0] rd_data_o; /* * Write Port */ input [7:0] wr_be_i; input [31:0] wr_data_i; input wr_en_i; output wr_busy_o; output init_rst_o; output mrd_start_o; output mrd_done_o; output [31:0] mrd_addr_o; output [31:0] mrd_len_o; output [31:0] mrd_count_o; output mwr_start_o; input mwr_done_i; output [31:0] mwr_addr_o; output [31:0] mwr_len_o; output [31:0] mwr_count_o; output [31:0] mwr_data_o; input [7:0] cpl_ur_found_i; input [7:0] cpl_ur_tag_i; input [31:0] cpld_found_i; input [31:0] cpld_data_size_i; input cpld_malformed_i; input int_src_rd_i; input int_src_wr_i; output int_clear_o; wire [31:0] mem_rd_data; wire [31:0] w_pre_wr_data; reg mem_write_en; reg [31:0] pre_wr_data; reg [31:0] mem_wr_data; reg [2:0] wr_mem_state; /* * Memory Write Controller */ wire [6:0] mem_addr = addr_i; /* * Extract current data bytes. These need to be swizzled * memory storage format : * data[31:0] = { byte[3], byte[2], byte[1], byte[0] (lowest addr) } */ wire [7:0] w_pre_wr_data_b3 = pre_wr_data[31:24]; wire [7:0] w_pre_wr_data_b2 = pre_wr_data[23:16]; wire [7:0] w_pre_wr_data_b1 = pre_wr_data[15:08]; wire [7:0] w_pre_wr_data_b0 = pre_wr_data[07:00]; /* * Extract new data bytes from payload * TLP Payload format : * data[31:0] = { byte[0] (lowest addr), byte[2], byte[1], byte[3] } */ wire [7:0] w_wr_data_b3 = wr_data_i[07:00]; wire [7:0] w_wr_data_b2 = wr_data_i[15:08]; wire [7:0] w_wr_data_b1 = wr_data_i[23:16]; wire [7:0] w_wr_data_b0 = wr_data_i[31:24]; always @(posedge clk or negedge rst_n) begin if ( !rst_n ) begin pre_wr_data <= 32'b0; mem_write_en <= 1'b0; mem_wr_data <= 32'b0; wr_mem_state <= `BMD_MEM_ACCESS_WR_RST; end else begin case ( wr_mem_state ) `BMD_MEM_ACCESS_WR_RST : begin mem_write_en <= 1'b0; if (wr_en_i) begin // read state wr_mem_state <= `BMD_MEM_ACCESS_WR_READ ; end else begin wr_mem_state <= `BMD_MEM_ACCESS_WR_RST; end end `BMD_MEM_ACCESS_WR_READ : begin mem_write_en <= 1'b0; pre_wr_data <= mem_rd_data; wr_mem_state <= `BMD_MEM_ACCESS_WR_WRITE; end `BMD_MEM_ACCESS_WR_WRITE : begin /* * Merge new enabled data and write target location */ mem_wr_data <= {{wr_be_i[3] ? w_wr_data_b3 : w_pre_wr_data_b3}, {wr_be_i[2] ? w_wr_data_b2 : w_pre_wr_data_b2}, {wr_be_i[1] ? w_wr_data_b1 : w_pre_wr_data_b1}, {wr_be_i[0] ? w_wr_data_b0 : w_pre_wr_data_b0}}; mem_write_en <= 1'b1; wr_mem_state <= `BMD_MEM_ACCESS_WR_RST; end endcase end end /* * Write controller busy */ assign wr_busy_o = wr_en_i | (wr_mem_state != `BMD_MEM_ACCESS_WR_RST); /* * Memory Read Controller */ /* Handle Read byte enables */ assign rd_data_o = {{rd_be_i[0] ? mem_rd_data[07:00] : 8'h0}, {rd_be_i[1] ? mem_rd_data[15:08] : 8'h0}, {rd_be_i[2] ? mem_rd_data[23:16] : 8'h0}, {rd_be_i[3] ? mem_rd_data[31:24] : 8'h0}}; BMD_EP_MEM EP_MEM ( .clk(clk), .rst_n(rst_n), .cfg_max_rd_req_size(cfg_max_rd_req_size), // I [2:0] .cfg_max_payload_size(cfg_max_payload_size), // I [2:0] .a_i(mem_addr[6:0]), // I [6:0] .wr_en_i(mem_write_en), // I .rd_d_o(mem_rd_data), // O [31:0] .wr_d_i(mem_wr_data), // I [31:0] .init_rst_o(init_rst_o), // O .mrd_start_o(mrd_start_o), // O .mrd_done_o(mrd_done_o), // O .mrd_addr_o(mrd_addr_o), // O [31:0] .mrd_len_o(mrd_len_o), // O [31:0] .mrd_count_o(mrd_count_o), // O [31:0] .mwr_start_o(mwr_start_o), // O .mwr_done_i(mwr_done_i), // I .mwr_addr_o(mwr_addr_o), // O [31:0] .mwr_len_o(mwr_len_o), // O [31:0] .mwr_count_o(mwr_count_o), // O [31:0] .mwr_data_o(mwr_data_o), // O [31:0] .cpl_ur_found_i(cpl_ur_found_i), // I .cpl_ur_tag_i(cpl_ur_tag_i), // I [7:0] .cpld_found_i(cpld_found_i), // I [31:0] .cpld_data_size_i(cpld_data_size_i), // I [31:0] .cpld_malformed_i(cpld_malformed_i), // I .int_src_rd_i(int_src_rd_i), // I .int_src_wr_i(int_src_wr_i), // I .int_clear_o(int_clear_o) // O );endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -