PIO_EP_MEM_ACCESS.v 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. //-----------------------------------------------------------------------------
  2. //
  3. // (c) Copyright 2010-2011 Xilinx, Inc. All rights reserved.
  4. //
  5. // This file contains confidential and proprietary information
  6. // of Xilinx, Inc. and is protected under U.S. and
  7. // international copyright and other intellectual property
  8. // laws.
  9. //
  10. // DISCLAIMER
  11. // This disclaimer is not a license and does not grant any
  12. // rights to the materials distributed herewith. Except as
  13. // otherwise provided in a valid license issued to you by
  14. // Xilinx, and to the maximum extent permitted by applicable
  15. // law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
  16. // WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
  17. // AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
  18. // BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
  19. // INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
  20. // (2) Xilinx shall not be liable (whether in contract or tort,
  21. // including negligence, or under any other theory of
  22. // liability) for any loss or damage of any kind or nature
  23. // related to, arising under or in connection with these
  24. // materials, including for any direct, or any indirect,
  25. // special, incidental, or consequential loss or damage
  26. // (including loss of data, profits, goodwill, or any type of
  27. // loss or damage suffered as a result of any action brought
  28. // by a third party) even if such damage or loss was
  29. // reasonably foreseeable or Xilinx had been advised of the
  30. // possibility of the same.
  31. //
  32. // CRITICAL APPLICATIONS
  33. // Xilinx products are not designed or intended to be fail-
  34. // safe, or for use in any application requiring fail-safe
  35. // performance, such as life-support or safety devices or
  36. // systems, Class III medical devices, nuclear facilities,
  37. // applications related to the deployment of airbags, or any
  38. // other applications that could lead to death, personal
  39. // injury, or severe property or environmental damage
  40. // (individually and collectively, "Critical
  41. // Applications"). Customer assumes the sole risk and
  42. // liability of any use of Xilinx products in Critical
  43. // Applications, subject only to applicable laws and
  44. // regulations governing limitations on product liability.
  45. //
  46. // THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
  47. // PART OF THIS FILE AT ALL TIMES.
  48. //
  49. //-----------------------------------------------------------------------------
  50. // Project : Series-7 Integrated Block for PCI Express
  51. // File : PIO_EP_MEM_ACCESS.v
  52. // Version : 3.3
  53. //--
  54. //-- Description: Endpoint Memory Access Unit. This module provides access functions
  55. //-- to the Endpoint memory aperture.
  56. //--
  57. //-- Read Access: Module returns data for the specifed address and
  58. //-- byte enables selected.
  59. //--
  60. //-- Write Access: Module accepts data, byte enables and updates
  61. //-- data when write enable is asserted. Modules signals write busy
  62. //-- when data write is in progress.
  63. //--
  64. //--------------------------------------------------------------------------------
  65. `timescale 1ps/1ps
  66. (* DowngradeIPIdentifiedWarnings = "yes" *)
  67. module PIO_EP_MEM_ACCESS #(
  68. parameter TCQ = 1
  69. ) (
  70. clk,
  71. rst_n,
  72. // Read Access
  73. rd_addr, // I [10:0] Read Address
  74. rd_be, // I [3:0] Read Byte Enable
  75. rd_data, // O [31:0] Read Data
  76. // Write Access
  77. wr_addr, // I [10:0] Write Address
  78. wr_be, // I [7:0] Write Byte Enable
  79. wr_data, // I [31:0] Write Data
  80. wr_en, // I Write Enable
  81. wr_busy // O Write Controller Busy
  82. );
  83. input clk;
  84. input rst_n;
  85. // Read Port
  86. input [10:0] rd_addr;
  87. input [3:0] rd_be;
  88. output [31:0] rd_data;
  89. // Write Port
  90. input [10:0] wr_addr;
  91. input [7:0] wr_be;
  92. input [31:0] wr_data;
  93. input wr_en;
  94. output wr_busy;
  95. localparam PIO_MEM_ACCESS_WR_RST = 3'b000;
  96. localparam PIO_MEM_ACCESS_WR_WAIT = 3'b001;
  97. localparam PIO_MEM_ACCESS_WR_READ = 3'b010;
  98. localparam PIO_MEM_ACCESS_WR_WRITE = 3'b100;
  99. wire [31:0] rd_data;
  100. reg [31:0] rd_data_raw_o;
  101. wire [31:0] rd_data0_o, rd_data1_o, rd_data2_o, rd_data3_o;
  102. wire rd_data0_en, rd_data1_en, rd_data2_en, rd_data3_en;
  103. wire wr_busy;
  104. reg write_en;
  105. reg [31:0] post_wr_data;
  106. reg [31:0] w_pre_wr_data;
  107. reg [2:0] wr_mem_state;
  108. reg [31:0] pre_wr_data;
  109. wire [31:0] w_pre_wr_data0;
  110. wire [31:0] w_pre_wr_data1;
  111. wire [31:0] w_pre_wr_data2;
  112. wire [31:0] w_pre_wr_data3;
  113. wire [7:0] w_pre_wr_data_b0;
  114. wire [7:0] w_pre_wr_data_b1;
  115. wire [7:0] w_pre_wr_data_b2;
  116. wire [7:0] w_pre_wr_data_b3;
  117. wire [7:0] w_wr_data_b0;
  118. wire [7:0] w_wr_data_b1;
  119. wire [7:0] w_wr_data_b2;
  120. wire [7:0] w_wr_data_b3;
  121. // Memory Write Process
  122. // Extract current data bytes. These need to be swizzled
  123. // BRAM storage format :
  124. // data[31:0] = { byte[3], byte[2], byte[1], byte[0] (lowest addr) }
  125. assign w_pre_wr_data_b3 = pre_wr_data[31:24];
  126. assign w_pre_wr_data_b2 = pre_wr_data[23:16];
  127. assign w_pre_wr_data_b1 = pre_wr_data[15:08];
  128. assign w_pre_wr_data_b0 = pre_wr_data[07:00];
  129. // Extract new data bytes from payload
  130. // TLP Payload format :
  131. // data[31:0] = { byte[0] (lowest addr), byte[2], byte[1], byte[3] }
  132. assign w_wr_data_b3 = wr_data[07:00];
  133. assign w_wr_data_b2 = wr_data[15:08];
  134. assign w_wr_data_b1 = wr_data[23:16];
  135. assign w_wr_data_b0 = wr_data[31:24];
  136. always @(posedge clk) begin
  137. if ( !rst_n )
  138. begin
  139. pre_wr_data <= #TCQ 32'b0;
  140. post_wr_data <= #TCQ 32'b0;
  141. pre_wr_data <= #TCQ 32'b0;
  142. write_en <= #TCQ 1'b0;
  143. wr_mem_state <= #TCQ PIO_MEM_ACCESS_WR_RST;
  144. end // if !rst_n
  145. else
  146. begin
  147. case ( wr_mem_state )
  148. PIO_MEM_ACCESS_WR_RST : begin
  149. if (wr_en)
  150. begin // read state
  151. wr_mem_state <= #TCQ PIO_MEM_ACCESS_WR_WAIT; //Pipelining happens in RAM's internal output reg.
  152. end
  153. else
  154. begin
  155. write_en <= #TCQ 1'b0;
  156. wr_mem_state <= #TCQ PIO_MEM_ACCESS_WR_RST;
  157. end
  158. end // PIO_MEM_ACCESS_WR_RST
  159. PIO_MEM_ACCESS_WR_WAIT : begin
  160. write_en <= #TCQ 1'b0;
  161. wr_mem_state <= #TCQ PIO_MEM_ACCESS_WR_READ ;
  162. end // PIO_MEM_ACCESS_WR_WAIT
  163. PIO_MEM_ACCESS_WR_READ : begin
  164. // Now save the selected BRAM B port data out
  165. pre_wr_data <= #TCQ w_pre_wr_data;
  166. write_en <= #TCQ 1'b0;
  167. wr_mem_state <= #TCQ PIO_MEM_ACCESS_WR_WRITE;
  168. end // PIO_MEM_ACCESS_WR_READ
  169. PIO_MEM_ACCESS_WR_WRITE : begin
  170. //Merge new enabled data and write target BlockRAM location
  171. post_wr_data <= #TCQ {{wr_be[3] ? w_wr_data_b3 : w_pre_wr_data_b3},
  172. {wr_be[2] ? w_wr_data_b2 : w_pre_wr_data_b2},
  173. {wr_be[1] ? w_wr_data_b1 : w_pre_wr_data_b1},
  174. {wr_be[0] ? w_wr_data_b0 : w_pre_wr_data_b0}};
  175. write_en <= #TCQ 1'b1;
  176. wr_mem_state <= #TCQ PIO_MEM_ACCESS_WR_RST;
  177. end // PIO_MEM_ACCESS_WR_WRITE
  178. default : begin
  179. // default case stmt
  180. wr_mem_state <= #TCQ PIO_MEM_ACCESS_WR_RST;
  181. end // default
  182. endcase // case (wr_mem_state)
  183. end // if rst_n
  184. end
  185. // Write controller busy
  186. assign wr_busy = wr_en | (wr_mem_state != PIO_MEM_ACCESS_WR_RST);
  187. // Select BlockRAM output based on higher 2 address bits
  188. always @*
  189. begin
  190. case ({wr_addr[10:9]}) // synthesis parallel_case full_case
  191. 2'b00 : w_pre_wr_data = w_pre_wr_data0;
  192. 2'b01 : w_pre_wr_data = w_pre_wr_data1;
  193. 2'b10 : w_pre_wr_data = w_pre_wr_data2;
  194. 2'b11 : w_pre_wr_data = w_pre_wr_data3;
  195. endcase
  196. end
  197. // Memory Read Controller
  198. assign rd_data0_en = {rd_addr[10:9] == 2'b00};
  199. assign rd_data1_en = {rd_addr[10:9] == 2'b01};
  200. assign rd_data2_en = {rd_addr[10:9] == 2'b10};
  201. assign rd_data3_en = {rd_addr[10:9] == 2'b11};
  202. always @(rd_addr or rd_data0_o or rd_data1_o or rd_data2_o or rd_data3_o)
  203. begin
  204. case ({rd_addr[10:9]}) // synthesis parallel_case full_case
  205. 2'b00 : rd_data_raw_o = rd_data0_o;
  206. 2'b01 : rd_data_raw_o = rd_data1_o;
  207. 2'b10 : rd_data_raw_o = rd_data2_o;
  208. 2'b11 : rd_data_raw_o = rd_data3_o;
  209. endcase
  210. end
  211. // Handle Read byte enables
  212. assign rd_data = {{rd_be[0] ? rd_data_raw_o[07:00] : 8'h0},
  213. {rd_be[1] ? rd_data_raw_o[15:08] : 8'h0},
  214. {rd_be[2] ? rd_data_raw_o[23:16] : 8'h0},
  215. {rd_be[3] ? rd_data_raw_o[31:24] : 8'h0}};
  216. EP_MEM EP_MEM_inst (
  217. .clk_i(clk),
  218. .a_rd_a_i_0(rd_addr[8:0]), // I [8:0]
  219. .a_rd_en_i_0(rd_data0_en), // I [1:0]
  220. .a_rd_d_o_0(rd_data0_o), // O [31:0]
  221. .b_wr_a_i_0(wr_addr[8:0]), // I [8:0]
  222. .b_wr_d_i_0(post_wr_data), // I [31:0]
  223. .b_wr_en_i_0({write_en & (wr_addr[10:9] == 2'b00)}), // I
  224. .b_rd_d_o_0(w_pre_wr_data0[31:0]), // O [31:0]
  225. .b_rd_en_i_0({wr_addr[10:9] == 2'b00}), // I
  226. .a_rd_a_i_1(rd_addr[8:0]), // I [8:0]
  227. .a_rd_en_i_1(rd_data1_en), // I [1:0]
  228. .a_rd_d_o_1(rd_data1_o), // O [31:0]
  229. .b_wr_a_i_1(wr_addr[8:0]), // [8:0]
  230. .b_wr_d_i_1(post_wr_data), // [31:0]
  231. .b_wr_en_i_1({write_en & (wr_addr[10:9] == 2'b01)}), // I
  232. .b_rd_d_o_1(w_pre_wr_data1[31:0]), // [31:0]
  233. .b_rd_en_i_1({wr_addr[10:9] == 2'b01}), // I
  234. .a_rd_a_i_2(rd_addr[8:0]), // I [8:0]
  235. .a_rd_en_i_2(rd_data2_en), // I [1:0]
  236. .a_rd_d_o_2(rd_data2_o), // O [31:0]
  237. .b_wr_a_i_2(wr_addr[8:0]), // I [8:0]
  238. .b_wr_d_i_2(post_wr_data), // I [31:0]
  239. .b_wr_en_i_2({write_en & (wr_addr[10:9] == 2'b10)}), // I
  240. .b_rd_d_o_2(w_pre_wr_data2[31:0]), // I [31:0]
  241. .b_rd_en_i_2({wr_addr[10:9] == 2'b10}), // I
  242. .a_rd_a_i_3(rd_addr[8:0]), // [8:0]
  243. .a_rd_en_i_3(rd_data3_en), // [1:0]
  244. .a_rd_d_o_3(rd_data3_o), // O [31:0]
  245. .b_wr_a_i_3(wr_addr[8:0]), // I [8:0]
  246. .b_wr_d_i_3(post_wr_data), // I [31:0]
  247. .b_wr_en_i_3({write_en & (wr_addr[10:9] == 2'b11)}), // I
  248. .b_rd_d_o_3(w_pre_wr_data3[31:0]), // I [31:0]
  249. .b_rd_en_i_3({wr_addr[10:9] == 2'b11}) // I
  250. );
  251. // synthesis translate_off
  252. reg [8*20:1] state_ascii;
  253. always @(wr_mem_state)
  254. begin
  255. case (wr_mem_state)
  256. PIO_MEM_ACCESS_WR_RST : state_ascii <= #TCQ "PIO_MEM_WR_RST";
  257. PIO_MEM_ACCESS_WR_WAIT : state_ascii <= #TCQ "PIO_MEM_WR_WAIT";
  258. PIO_MEM_ACCESS_WR_READ : state_ascii <= #TCQ "PIO_MEM_WR_READ";
  259. PIO_MEM_ACCESS_WR_WRITE : state_ascii <= #TCQ "PIO_MEM_WR_WRITE";
  260. default : state_ascii <= #TCQ "PIO MEM STATE ERR";
  261. endcase
  262. end
  263. // synthesis translate_on
  264. endmodule