pci_exp_usrapp_cfg.v 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 : pci_exp_usrapp_cfg.v
  52. // Version : 3.3
  53. //--
  54. //--------------------------------------------------------------------------------
  55. `include "board_common.vh"
  56. module pci_exp_usrapp_cfg (
  57. cfg_do,
  58. cfg_di,
  59. cfg_byte_en_n,
  60. cfg_dwaddr,
  61. cfg_wr_en_n,
  62. cfg_rd_en_n,
  63. cfg_rd_wr_done_n,
  64. cfg_err_cor_n,
  65. cfg_err_ur_n,
  66. cfg_err_ecrc_n,
  67. cfg_err_cpl_timeout_n,
  68. cfg_err_cpl_abort_n,
  69. cfg_err_cpl_unexpect_n,
  70. cfg_err_posted_n,
  71. cfg_err_tlp_cpl_header,
  72. cfg_interrupt_n,
  73. cfg_interrupt_rdy_n,
  74. cfg_turnoff_ok_n,
  75. cfg_to_turnoff_n,
  76. cfg_bus_number,
  77. cfg_device_number,
  78. cfg_function_number,
  79. cfg_status,
  80. cfg_command,
  81. cfg_dstatus,
  82. cfg_dcommand,
  83. cfg_lstatus,
  84. cfg_lcommand,
  85. cfg_pcie_link_state_n,
  86. cfg_trn_pending_n,
  87. cfg_pm_wake_n,
  88. trn_clk,
  89. trn_reset_n
  90. );
  91. input [(32 - 1):0] cfg_do;
  92. output [(32 - 1):0] cfg_di;
  93. output [(32/8 - 1):0] cfg_byte_en_n;
  94. output [(10 - 1):0] cfg_dwaddr;
  95. output cfg_wr_en_n;
  96. output cfg_rd_en_n;
  97. input cfg_rd_wr_done_n;
  98. output cfg_err_cor_n;
  99. output cfg_err_ur_n;
  100. output cfg_err_ecrc_n;
  101. output cfg_err_cpl_timeout_n;
  102. output cfg_err_cpl_abort_n;
  103. output cfg_err_cpl_unexpect_n;
  104. output cfg_err_posted_n;
  105. output [(48 - 1):0] cfg_err_tlp_cpl_header;
  106. output cfg_interrupt_n;
  107. input cfg_interrupt_rdy_n;
  108. output cfg_turnoff_ok_n;
  109. input cfg_to_turnoff_n;
  110. output cfg_pm_wake_n;
  111. input [(8 - 1):0] cfg_bus_number;
  112. input [(5 - 1):0] cfg_device_number;
  113. input [(3 - 1):0] cfg_function_number;
  114. input [(16 - 1):0] cfg_status;
  115. input [(16- 1):0] cfg_command;
  116. input [(16- 1):0] cfg_dstatus;
  117. input [(16 - 1):0] cfg_dcommand;
  118. input [(16 - 1):0] cfg_lstatus;
  119. input [(16 - 1):0] cfg_lcommand;
  120. input [(3 - 1):0] cfg_pcie_link_state_n;
  121. output cfg_trn_pending_n;
  122. input trn_clk;
  123. input trn_reset_n;
  124. parameter Tcq = 1;
  125. reg [(32 - 1):0] cfg_di;
  126. reg [(32/8 - 1):0] cfg_byte_en_n;
  127. reg [(10 - 1):0] cfg_dwaddr;
  128. reg cfg_wr_en_n;
  129. reg cfg_rd_en_n;
  130. reg cfg_err_cor_n;
  131. reg cfg_err_ecrc_n;
  132. reg cfg_err_ur_n;
  133. reg cfg_err_cpl_timeout_n;
  134. reg cfg_err_cpl_abort_n;
  135. reg cfg_err_cpl_unexpect_n;
  136. reg cfg_err_posted_n;
  137. reg [(48 - 1):0] cfg_err_tlp_cpl_header;
  138. reg cfg_interrupt_n;
  139. reg cfg_turnoff_ok_n;
  140. reg cfg_pm_wake_n;
  141. reg cfg_trn_pending_n;
  142. initial begin
  143. cfg_err_cor_n <= 1'b1;
  144. cfg_err_ur_n <= 1'b1;
  145. cfg_err_ecrc_n <= 1'b1;
  146. cfg_err_cpl_timeout_n <= 1'b1;
  147. cfg_err_cpl_abort_n <= 1'b1;
  148. cfg_err_cpl_unexpect_n <= 1'b1;
  149. cfg_err_posted_n <= 1'b0;
  150. cfg_interrupt_n <= 1'b1;
  151. cfg_turnoff_ok_n <= 1'b1;
  152. cfg_dwaddr <= 0;
  153. cfg_err_tlp_cpl_header <= 0;
  154. cfg_di <= 0;
  155. cfg_byte_en_n <= 4'hf;
  156. cfg_wr_en_n <= 1;
  157. cfg_rd_en_n <= 1;
  158. cfg_pm_wake_n <= 1;
  159. cfg_trn_pending_n <= 1'b0;
  160. end
  161. /************************************************************
  162. Task : TSK_READ_CFG_DW
  163. Description : Read Configuration Space DW
  164. *************************************************************/
  165. task TSK_READ_CFG_DW;
  166. input [31:0] addr_;
  167. begin
  168. if (!trn_reset_n) begin
  169. $display("[%t] : trn_reset_n is asserted", $realtime);
  170. $finish(1);
  171. end
  172. wait ( cfg_rd_wr_done_n == 1'b1)
  173. @(posedge trn_clk);
  174. cfg_dwaddr <= #(Tcq) addr_;
  175. cfg_wr_en_n <= #(Tcq) 1'b1;
  176. cfg_rd_en_n <= #(Tcq) 1'b0;
  177. $display("[%t] : Reading Cfg Addr [0x%h]", $realtime, addr_);
  178. $fdisplay(board.RP.com_usrapp.tx_file_ptr,
  179. "\n[%t] : Local Configuration Read Access :",
  180. $realtime);
  181. @(posedge trn_clk);
  182. #(Tcq);
  183. wait ( cfg_rd_wr_done_n == 1'b0)
  184. #(Tcq);
  185. $fdisplay(board.RP.com_usrapp.tx_file_ptr,
  186. "\t\t\tCfg Addr [0x%h] -> Data [0x%h]\n",
  187. {addr_,2'b00}, cfg_do);
  188. cfg_rd_en_n <= #(Tcq) 1'b1;
  189. end
  190. endtask // TSK_READ_CFG_DW;
  191. /************************************************************
  192. Task : TSK_WRITE_CFG_DW
  193. Description : Write Configuration Space DW
  194. *************************************************************/
  195. task TSK_WRITE_CFG_DW;
  196. input [31:0] addr_;
  197. input [31:0] data_;
  198. input [3:0] ben_;
  199. begin
  200. if (!trn_reset_n) begin
  201. $display("[%t] : trn_reset_n is asserted", $realtime);
  202. $finish(1);
  203. end
  204. wait ( cfg_rd_wr_done_n == 1'b1)
  205. @(posedge trn_clk);
  206. cfg_dwaddr <= #(Tcq) addr_;
  207. cfg_di <= #(Tcq) data_;
  208. cfg_byte_en_n <= #(Tcq) ben_;
  209. cfg_wr_en_n <= #(Tcq) 1'b0;
  210. cfg_rd_en_n <= #(Tcq) 1'b1;
  211. $display("[%t] : Writing Cfg Addr [0x%h]", $realtime, addr_);
  212. $fdisplay(board.RP.com_usrapp.tx_file_ptr,
  213. "\n[%t] : Local Configuration Write Access :",
  214. $realtime);
  215. @(posedge trn_clk);
  216. #(Tcq);
  217. wait ( cfg_rd_wr_done_n == 1'b0)
  218. #(Tcq);
  219. cfg_wr_en_n <= #(Tcq) 1'b1;
  220. end
  221. endtask // TSK_WRITE_CFG_DW;
  222. endmodule // pci_exp_usrapp_cfg