以下資料的整理主要是做備忘錄,避免以後忘了,順便留給需要的人。

==========================================

本文主要是參考友晶科技的DE2i-150光碟裡面的PCie_Fundmental範例,再重新打造一個新的範例程式。

  1. // ============================================================================
  2. // Copyright (c) 2012 by Terasic Technologies Inc.
  3. // Copyright (c) 2013 by TKU ICLAB.
  4. // ============================================================================
  5. //
  6. //
  7. // ============================================================================
  8. //Date: Wed Jun 27 19:19:53 2012
  9. // ============================================================================
  10. //
  11. // Revision History :
  12. // --------------------------------------------------------------------
  13. // Ver :| Author :| Mod. Date :| Changes Made:
  14. // V1.0 :| Shih-An Li :| 10/10/2013 :| Initial Revision, add SW14
  15. // to control 7-seg lights
  16. // --------------------------------------------------------------------
  17.  
  18. `define ENABLE_PCIE
  19. module de2i_pci_top(
  20.  
  21. ///////////CLOCK2/////////////
  22. iCLOCK2_50,
  23.  
  24. /////////CLOCK3/////////
  25. iCLOCK3_50,
  26.  
  27. /////////CLOCK/////////
  28. iCLOCK_50,
  29.  
  30. /////////DRAM/////////
  31. oDRAM_ADDR,
  32. oDRAM_BA,
  33. oDRAM_CAS_N,
  34. oDRAM_CKE,
  35. oDRAM_CLK,
  36. oDRAM_CS_N,
  37. DRAM_DQ,
  38. oDRAM_DQM,
  39. oDRAM_RAS_N,
  40. oDRAM_WE_N,
  41.  
  42. /////////EEP/////////
  43. oEEP_I2C_SCLK,
  44. EEP_I2C_SDAT,
  45.  
  46. /////////ENET/////////
  47. oENET_GTX_CLK,
  48. iENET_INT_N,
  49. iENET_LINK100,
  50. oENET_MDC,
  51. ENET_MDIO,
  52. oENET_RST_N,
  53. iENET_RX_CLK,
  54. iENET_RX_COL,
  55. iENET_RX_CRS,
  56. iENET_RX_DATA,
  57. iENET_RX_DV,
  58. iENET_RX_ER,
  59. iENET_TX_CLK,
  60. oENET_TX_DATA,
  61. oENET_TX_EN,
  62. oENET_TX_ER,
  63.  
  64. /////////FAN/////////
  65. FAN_CTRL,
  66.  
  67. /////////FL/////////
  68. oFL_CE_N,
  69. oFL_OE_N,
  70. iFL_RY,
  71. oFL_WE_N,
  72. oFL_WP_N,
  73. oFL_RESET_N,
  74. /////////FS/////////
  75. FS_DQ,
  76. oFS_ADDR,
  77. /////////GPIO/////////
  78. GPIO,
  79.  
  80. /////////G/////////
  81. iG_SENSOR_INT1,
  82. oG_SENSOR_SCLK,
  83. G_SENSOR_SDAT,
  84.  
  85. /////////HEX/////////
  86. oHEX0,
  87. oHEX1,
  88. oHEX2,
  89. oHEX3,
  90. oHEX4,
  91. oHEX5,
  92. oHEX6,
  93. oHEX7,
  94.  
  95. /////////HSMC/////////
  96. iHSMC_CLKIN0,
  97. iHSMC_CLKIN_N1,
  98. iHSMC_CLKIN_N2,
  99. iHSMC_CLKIN_P1,
  100. iHSMC_CLKIN_P2,
  101. oHSMC_CLKOUT0,
  102. HSMC_CLKOUT_N1,
  103. HSMC_CLKOUT_N2,
  104. HSMC_CLKOUT_P1,
  105. HSMC_CLKOUT_P2,
  106. HSMC_D,
  107. oHSMC_I2C_SCLK,
  108. HSMC_I2C_SDAT,
  109. HSMC_RX_D_N,
  110. HSMC_RX_D_P,
  111. HSMC_TX_D_N,
  112. HSMC_TX_D_P,
  113.  
  114. /////////I2C/////////
  115. oI2C_SCLK,
  116. I2C_SDAT,
  117.  
  118. /////////IRDA/////////
  119. iIRDA_RXD,
  120.  
  121. /////////KEY/////////
  122. iKEY,
  123.  
  124. /////////LCD/////////
  125. LCD_DATA,
  126. oLCD_EN,
  127. oLCD_ON,
  128. oLCD_RS,
  129. oLCD_RW,
  130.  
  131. /////////LEDG/////////
  132. oLEDG,
  133.  
  134. /////////LEDR/////////
  135. oLEDR,
  136.  
  137. /////////PCIE/////////
  138. `ifdef ENABLE_PCIE
  139.  
  140. iPCIE_PERST_N,
  141. iPCIE_REFCLK_P,
  142. iPCIE_RX_P,
  143. oPCIE_TX_P,
  144. oPCIE_WAKE_N,
  145. `endif
  146. /////////SD/////////
  147. oSD_CLK,
  148. SD_CMD,
  149. SD_DAT,
  150. iSD_WP_N,
  151.  
  152. /////////SMA/////////
  153. iSMA_CLKIN,
  154. oSMA_CLKOUT,
  155.  
  156. /////////SSRAM/////////
  157. oSSRAM_ADSC_N,
  158. oSSRAM_ADSP_N,
  159. oSSRAM_ADV_N,
  160. oSSRAM_BE,
  161. oSSRAM_CLK,
  162. oSSRAM_GW_N,
  163. oSSRAM_OE_N,
  164. oSSRAM_WE_N,
  165. oSSRAM0_CE_N,
  166. oSSRAM1_CE_N,
  167. /////////SW/////////
  168. iSW,
  169.  
  170. /////////TD/////////
  171. iTD_CLK27,
  172. iTD_DATA,
  173. iTD_HS,
  174. oTD_RESET_N,
  175. iTD_VS,
  176.  
  177. /////////UART/////////
  178. iUART_CTS,
  179. oUART_RTS,
  180. iUART_RXD,
  181. oUART_TXD,
  182.  
  183. /////////VGA/////////
  184. oVGA_B,
  185. oVGA_BLANK_N,
  186. oVGA_CLK,
  187. oVGA_G,
  188. oVGA_HS,
  189. oVGA_R,
  190. oVGA_SYNC_N,
  191. oVGA_VS,
  192. );
  193.  
  194. //=======================================================
  195. // PORT declarations
  196. //=======================================================
  197.  
  198. ///////////CLOCK2/////////////
  199.  
  200. input iCLOCK2_50;
  201.  
  202. ///////// CLOCK3 /////////
  203. input iCLOCK3_50;
  204.  
  205. ///////// CLOCK /////////
  206. input iCLOCK_50;
  207.  
  208. ///////// DRAM /////////
  209. output [:] oDRAM_ADDR;
  210. output [:] oDRAM_BA;
  211. output oDRAM_CAS_N;
  212. output oDRAM_CKE;
  213. output oDRAM_CLK;
  214. output oDRAM_CS_N;
  215. inout [:] DRAM_DQ;
  216. output [:] oDRAM_DQM;
  217. output oDRAM_RAS_N;
  218. output oDRAM_WE_N;
  219.  
  220. ///////// EEP /////////
  221. output oEEP_I2C_SCLK;
  222. inout EEP_I2C_SDAT;
  223.  
  224. ///////// ENET /////////
  225. output oENET_GTX_CLK;
  226. input iENET_INT_N;
  227. input iENET_LINK100;
  228. output oENET_MDC;
  229. inout ENET_MDIO;
  230. output oENET_RST_N;
  231. input iENET_RX_CLK;
  232. input iENET_RX_COL;
  233. input iENET_RX_CRS;
  234. input [:] iENET_RX_DATA;
  235. input iENET_RX_DV;
  236. input iENET_RX_ER;
  237. input iENET_TX_CLK;
  238. output [:] oENET_TX_DATA;
  239. output oENET_TX_EN;
  240. output oENET_TX_ER;
  241.  
  242. ///////// FAN /////////
  243. inout FAN_CTRL;
  244.  
  245. ///////// FL /////////
  246. output oFL_CE_N;
  247. output oFL_OE_N;
  248. input iFL_RY;
  249. output oFL_WE_N;
  250. output oFL_WP_N;
  251. output oFL_RESET_N;
  252. ///////// FS /////////
  253. inout [:] FS_DQ;
  254. output [:] oFS_ADDR;
  255. ///////// GPIO /////////
  256. inout [:] GPIO;
  257.  
  258. ///////// G /////////
  259. input iG_SENSOR_INT1;
  260. output oG_SENSOR_SCLK;
  261. inout G_SENSOR_SDAT;
  262.  
  263. ///////// HEX /////////
  264. output [:] oHEX0;
  265. output [:] oHEX1;
  266. output [:] oHEX2;
  267. output [:] oHEX3;
  268. output [:] oHEX4;
  269. output [:] oHEX5;
  270. output [:] oHEX6;
  271. output [:] oHEX7;
  272.  
  273. ///////// HSMC /////////
  274. input iHSMC_CLKIN0;
  275. input iHSMC_CLKIN_N1;
  276. input iHSMC_CLKIN_N2;
  277. input iHSMC_CLKIN_P1;
  278. input iHSMC_CLKIN_P2;
  279. output oHSMC_CLKOUT0;
  280. inout HSMC_CLKOUT_N1;
  281. inout HSMC_CLKOUT_N2;
  282. inout HSMC_CLKOUT_P1;
  283. inout HSMC_CLKOUT_P2;
  284. inout [:] HSMC_D;
  285. output oHSMC_I2C_SCLK;
  286. inout HSMC_I2C_SDAT;
  287. inout [:] HSMC_RX_D_N;
  288. inout [:] HSMC_RX_D_P;
  289. inout [:] HSMC_TX_D_N;
  290. inout [:] HSMC_TX_D_P;
  291.  
  292. ///////// I2C /////////
  293. output oI2C_SCLK;
  294. inout I2C_SDAT;
  295.  
  296. ///////// IRDA /////////
  297. input iIRDA_RXD;
  298.  
  299. ///////// KEY /////////
  300. input [:] iKEY;
  301.  
  302. ///////// LCD /////////
  303. inout [:] LCD_DATA;
  304. output oLCD_EN;
  305. output oLCD_ON;
  306. output oLCD_RS;
  307. output oLCD_RW;
  308.  
  309. ///////// LEDG /////////
  310. output [:] oLEDG;
  311.  
  312. ///////// LEDR /////////
  313. output [:] oLEDR;
  314.  
  315. ///////// PCIE /////////
  316. `ifdef ENABLE_PCIE
  317. input iPCIE_PERST_N;
  318. input iPCIE_REFCLK_P;
  319. input [:] iPCIE_RX_P;
  320. output [:] oPCIE_TX_P;
  321. output oPCIE_WAKE_N;
  322. `endif
  323. ///////// SD /////////
  324. output oSD_CLK;
  325. inout SD_CMD;
  326. inout [:] SD_DAT;
  327. input iSD_WP_N;
  328.  
  329. ///////// SMA /////////
  330. input iSMA_CLKIN;
  331. output oSMA_CLKOUT;
  332.  
  333. ///////// SSRAM /////////
  334. output oSSRAM_ADSC_N;
  335. output oSSRAM_ADSP_N;
  336. output oSSRAM_ADV_N;
  337. output [:] oSSRAM_BE;
  338. output oSSRAM_CLK;
  339. output oSSRAM_GW_N;
  340. output oSSRAM_OE_N;
  341. output oSSRAM_WE_N;
  342. output oSSRAM0_CE_N;
  343. output oSSRAM1_CE_N;
  344.  
  345. ///////// SW /////////
  346. input [:] iSW;
  347.  
  348. ///////// TD /////////
  349. input iTD_CLK27;
  350. input [:] iTD_DATA;
  351. input iTD_HS;
  352. output oTD_RESET_N;
  353. input iTD_VS;
  354.  
  355. ///////// UART /////////
  356. input iUART_CTS;
  357. output oUART_RTS;
  358. input iUART_RXD;
  359. output oUART_TXD;
  360.  
  361. ///////// VGA /////////
  362. output [:] oVGA_B;
  363. output oVGA_BLANK_N;
  364. output oVGA_CLK;
  365. output [:] oVGA_G;
  366. output oVGA_HS;
  367. output [:] oVGA_R;
  368. output oVGA_SYNC_N;
  369. output oVGA_VS;
  370.  
  371. //=======================================================
  372. // REG/WIRE declarations
  373. //=======================================================
  374.  
  375. wire [:] hexbus;
  376. wire [:] inbus;
  377.  
  378. //=======================================================
  379. // Structural coding
  380. //=======================================================
  381.  
  382. pcihellocore u0 (
  383. .clk_clk(iCLOCK_50),
  384. .reset_reset_n(iKEY[]),
  385. .pcie_ip_rx_in_rx_datain_0 (iPCIE_RX_P[]), // pcie_hard_ip_0_rx_in.rx_datain_0
  386. .pcie_ip_rx_in_rx_datain_1 (iPCIE_RX_P[]),
  387. .pcie_ip_tx_out_tx_dataout_0 (oPCIE_TX_P[]), // pcie_hard_ip_0_tx_out.tx_dataout_0
  388. .pcie_ip_tx_out_tx_dataout_1 (oPCIE_TX_P[]),
  389. // .pcie_hard_ip_0_powerdown_pll_powerdown (oPCIE_WAKE_N), // pcie_hard_ip_0_powerdown.pll_powerdown
  390. // .pcie_hard_ip_0_powerdown_gxb_powerdown (oPCIE_WAKE_N), // .gxb_powerdown
  391. .pcie_ip_refclk_export (iPCIE_REFCLK_P), // pcie_hard_ip_0_refclk.export
  392. .pcie_ip_pcie_rstn_export (iPCIE_PERST_N),
  393. // .hexport_external_connection_export (hexbus), // hexport_external_connection.export
  394. // .inport_external_connection_export (inbus), // inport_external_connection.export
  395. .led_external_connection_export(oLEDG),
  396. .button_external_connection_export(iKEY)
  397. );
  398.  
  399. assign oPCIE_WAKE_N = 'b1; // for ubuntu poweroff instruction using, if set to 0, the poweroff cant be used
  400.  
  401. //////////// FAN Control //////////
  402. //assign FAN_CTRL = 1'b1; // turn on FAN
  403. //iSW close the 7-segment led, add by 2013/10/10
  404. assign oHEX0 = (iSW[])? hexbus[ : ] : 'h7f;
  405. assign oHEX1 = (iSW[])? hexbus[: ] : 'h7f;
  406. assign oHEX2 = (iSW[])? hexbus[:] : 'h7f;
  407. assign oHEX3 = (iSW[])? hexbus[:] : 'h7f;
  408. assign oHEX4 = (iSW[])? hexbus[ : ] : 'h7f;
  409. assign oHEX5 = (iSW[])? hexbus[: ] : 'h7f;
  410. assign oHEX6 = (iSW[])? hexbus[:] : 'h7f;
  411. assign oHEX7 = (iSW[])? hexbus[:] : 'h7f;
  412.  
  413. assign inbus = iSW[:];
  414.  
  415. // Fan Control,
  416. wire [:] wDuty;
  417. assign wDuty = (iSW[:]=='b000) ? 8'd0 :
  418. (iSW[:]=='b001) ? 8'd10 :
  419. (iSW[:]=='b010) ? 8'd20 :
  420. (iSW[:]=='b011) ? 8'd30 :
  421. (iSW[:]=='b100) ? 8'd40 :
  422. (iSW[:]=='b101) ? 8'd50 :
  423. (iSW[:]=='b110) ? 8'd60 : 'd100 ;
  424. pwmgen pwm(
  425. .iClk50M(iCLOCK_50), // 50Mhz clock
  426. .iRst_n('b1), // reset, low active
  427. .iDuty(wDuty), // Range is 0~100
  428. .oPWM(FAN_CTRL),
  429. // .oSampClk,
  430. // .oErrorValue
  431. );
  432.  
  433. wire hb_50;
  434. heart_beat heart_beat_clk50(
  435. .clk(iCLOCK_50),
  436. .led(oLEDR[])
  437. );
  438.  
  439. endmodule

程式碼說明:

Line 384~399是Qsys模組的腳位連接。因為是選用PCIe Gen1 x2所以會用到兩個PCIe訊號。

Line 428~435是風扇控制程式,由於風扇太吵了,所以寫了一個PWM程式用SW[17:15]來控制風扇轉速。

=================================================================

以下來介紹Qsys系統的設定。

Fig.1 Qsys系統圖

其中pcie_ip模組的設定如Fig.2所示。

Fig.2 PCIe_ip模組設定

SGDMA模組設定如下:

Fig.3 SGDMA設定

接下來是Nios設定

Fig.4 Nios設定

LED模組設定

Fig.5 LED模組

Button模組設定:

Fig. 6 Button模組設定

FIFO_memory模組設定:

Fig.7 FIFO_memory模組設定

Onchip_memory模組設定:

Fig. 8 On_Chip Memory模組設定

設定完成後就可以按下generate產生Qsys系統。

Fig.9 Generate Qsys

經由以上設定後,Quartus硬體也都設定完成。

接下來就可以用Quartus 編譯 de2i_pci_top專案了。

等編譯完成後,按照下面步驟執行。

Step 1: 下載 de2i_pci_top.sof 檔至DE2i-150 的FPGA晶片內。

Step 2: 安裝PCIe_DriverInstall目錄下的驅動程式。(如果之前有裝過,就可以跳過)

Step 3: windwos重新開機,讓作業系統重新抓PCIe的新硬體。

Step 4: 執行專案目錄下的\windows_app_bcb6\output\app.exe

就可以按[0]控制LED,[1]讀取按鈕。

但是按[2]和[3]就會出現錯誤,這是由於FIFO跟onchip_memory內沒有資料,因此需要事先把FIFO與onchip_memory的初始檔放到

.\pcihellocore\synthesis\submodules 目錄下,本人已經把檔案放在附件的code中,有需要的人就去下載吧。

再重新編譯Qsys和Quartus專案後,執行步驟Step1~step4後就可以順利執行[2]和[3]功能了。

==================================================================================

以上是整個PCIe_Fundmental範例硬體檔的設定部分,下次再來研究講解VC程式部分,PC如何跟FPGA用PCIe做溝通。


附件下載URL: http://files.cnblogs.com/files/lishyhan/PCIe_Fundmental.zip

[DE2i-150] 重建PCIe_Fundmental範例說明的更多相关文章

  1. 什麼是 N-key 與按鍵衝突?原理說明、改善技術、選購注意完全解析

    不管是文書處理或遊戲中,我們都經常會使用到組合鍵,也就是多顆按鍵一起按下,執行某些特定的功能.有時候你可能會發現,明明只按下2顆鍵,再按下第3顆鍵時訊號卻沒有輸出.要是打報告到一半遇到這種狀況還好,如 ...

  2. NUC970 U-Boot 使用說明

    U-Boot 使用說明U-Boot 是一個主要用於嵌入式系統的開機載入程式, 可以支援多種不同的計算機系統結構, 包括ARM.MIPS.x86與 68K. 這也是一套在GNU通用公共許可證之下發布的自 ...

  3. Pseudo-elements ::before, ::after 範例

    xhtml <strong class="amount">700</strong> css .amount::before {content:"$ ...

  4. Python 基礎 - 淺copy補充說明

    在 import copy 這個模塊裡 基於第一個列表來做淺copy,實際上第二個列表裡的元素,是第一個列表的 引用. 接下來介紹 淺copy有三種方式可以使用 #!/usr/bin/env pyth ...

  5. JavaFX結合 JDBC, Servlet, Swing, Google Map及動態產生比例圖 (2):JavaFX建立及程式碼說明 (转帖)

    說明:就如同標題一樣,前端會用到JavaFX.Swing.Java Web Start.Google Map 的技術, 後端就是JDBC.Servlet的技術,以及我們會簽署認證jar檔案,這樣才可存 ...

  6. man page分類與說明

    轉載自http://itzone.hk/article/article.php?aid=200407152225014657 (如有侵權,請留言或來信告知) 前言 Man page是每位程式設計員及U ...

  7. 開賣!下集 -- ASP.NET 4.5 專題實務(II)-範例應用與 4.5新功能【VB/C# 雙語法】

    開賣!下集 -- ASP.NET 4.5 專題實務(II)-範例應用與 4.5新功能[VB/C# 雙語法] 我.....作者都沒拿到書呢! 全台灣最專業的電腦書店 -- 天瓏書局 已經開賣了! 感謝天 ...

  8. open和opener使用說明

    父網頁:window.open("article.html")子網頁:var dialoginfo=$('#dialogdata',window.opener.document); ...

  9. vi 常用命令使用說明

    vi是一種文字模式全螢幕文字編輯軟體(Text Editor).對初學者來說,vi是個很難用的工具,一般需要2個星期的時間才能得心應手.之所以介紹vi,其理由如下: vi是Unix上的標準文字編輯軟體 ...

随机推荐

  1. nib文件的注册及加载

    1,注册 [(UIView *)view registerNib:[UINib nibWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle ...

  2. win7共享文件夹给局域网

    1.设置共享   2.关闭"需要密码访问"          

  3. android network develop(3)----Xml Parser

    Normally, there are three type parser in android. Xmlpullparser, DOM & SAX. Google recomand Xmlp ...

  4. Linux 基础知识----shell

    1.file title: #!/bin/bash 2.input: echo $1 echo $2 3.if # ifif [ "$1" = "N" ]the ...

  5. Effective Java 33 Use EnumMap instead of ordinal indexing

    Wrong practice: Putting sets into an array indexed by the type's ordinal /** * Added demo for the &q ...

  6. 使用MiniProfiler调试ASP.NET MVC网站性能

    MiniProfiler 以前开发Webform的时候可以开启trace来跟踪页面事件,这对于诊断程序的性能是有很大的帮助的,起到事半功倍的作用,今天我就来谈用mvc开 发项目的调试和性能监控.EF框 ...

  7. window10系统安装oracle11g时遇到INS-13001环境不满足最低要求

    机器安装了window10系统,之前有次安装oracle11g是成功了.但是机器后来固态硬盘坏了,又坏了个后,还是win10系统安装oracle11g时,出现INS-13001环境不满足最低要求,郁闷 ...

  8. POJ 3687 Labeling Balls()

    Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9641 Accepted: 2636 Descri ...

  9. web.xml文件报错:The processing instruction target matching "[xX][mM][lL]" is not allowed.

    昨晚把我的项目上传到了gitlab,然后今天在公司从gitlab下载下来, 发现web.xml报错.

  10. 详解apache的allow和deny

    今天看了一篇关于apache allow,deny的文章收获匪浅,防止被删,我直接摘过来了,原文地址!!! !http://www.cnblogs.com/top5/archive/2009/09/2 ...