NIOS2隨筆——自訂IP(DPRAM)

來源:互聯網
上載者:User

標籤:fpga ; nios2

  1. AVALON匯流排分類

在QSYS下,一個簡單的組件包含了許多介面,它們實現了不同的功能,大致有下面幾種:

Avalon-MM

Avalon-ST

Avalon Conduit

Avalon-TC

Avalon Interrupt

Avalon Clock.

這些標準是開源的,不需要license就可以開發使用。是一個匯流排應用的:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/86/15/wKioL1e0Gm3izts1AADLRaaI9b4776.jpg" title="AVALON_ARTH.jpg" width="600" height="606" border="0" hspace="0" vspace="0" style="width:600px;height:606px;" alt="wKioL1e0Gm3izts1AADLRaaI9b4776.jpg" />


2. AVALON MM匯流排

這裡以AVALON MM為例,設計一個使用者自訂的DPRAM組件,並用DMA方式將DPRAM PORTB中的資料搬移到記憶體SDRAM/DDR2中。下面介面定義是AVALON MM SLAVE匯流排的訊號,具體時序在Avalon Interface Specifications中有詳細描述。

//avalon MM slaveinput avs_clk,input avs_reset_n,input avs_chipselect_n,input [7:0] avs_address,input [3:0] avs_byteenable,input avs_write,input [31 :0] avs_writedata,input avs_read,output avs_readdatavalid,output [31 :0] avs_readdata


3. Qsys中添加自訂群組件

1) 新群組件

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/86/15/wKioL1e0HgKxVwZ9AAB_gS4gy2M556.jpg" title="AVALON_IP0.jpg" alt="wKioL1e0HgKxVwZ9AAB_gS4gy2M556.jpg" />

2)添加檔案

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/86/15/wKioL1e0HmrjMx98AACHdhdzvHY121.jpg" title="AVALON_IP1.jpg" width="600" height="311" border="0" hspace="0" vspace="0" style="width:600px;height:311px;" alt="wKioL1e0HmrjMx98AACHdhdzvHY121.jpg" />

3) 訊號設定

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/86/15/wKiom1e0Hu7iMPy7AAC72yJKk4w782.jpg" title="AVALON_IP2.jpg" width="600" height="282" border="0" hspace="0" vspace="0" style="width:600px;height:282px;" alt="wKiom1e0Hu7iMPy7AAC72yJKk4w782.jpg" />

4) 介面時序

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M02/86/15/wKioL1e0H2yzN8TvAACgJ_Ytcdw970.jpg" title="AVALON_IP3.jpg" width="600" height="448" border="0" hspace="0" vspace="0" style="width:600px;height:448px;" alt="wKioL1e0H2yzN8TvAACgJ_Ytcdw970.jpg" />


4. FPGA邏輯代碼

下面是使用者自訂的DPRAM的Verilog代碼:

//file name:vid_dpram.v//author:shugen.yin//date:2016.8.15//function:user dpram for Qsys//log:module vid_dpram(//user portinput inclock,input [7:0] data,input data_valid,input vid_vsync,//avalon MM slaveinput avs_clk,input avs_reset_n,input avs_chipselect_n,input [7:0] avs_address,input [3:0] avs_byteenable,input avs_write,input [31 :0] avs_writedata,input avs_read,output avs_readdatavalid,output [31 :0] avs_readdata);parameter VID_WIDTH = 640;reg avs_readdatavalid_r0;reg avs_readdatavalid_r1;reg [9:0] wraddress_0;reg [9:0] wraddress_1;reg rdaddress_high_bit;reg wraddress_high_bit;wire [10:0] wraddress;wire [8:0] rdaddress;assign rdaddress = (avs_chipselect_n==1‘b0)?{1‘b0,avs_address[7:0]}:0;wire rden;assign rden = avs_read & ~avs_chipselect_n;dpram_01dpram_01_inst (.data ( data ),.wrclock ( inclock ),.rdclock ( avs_clk ),.rden(rden),.rdaddress ( rdaddress ),//input[8:0]  rdaddress;.wraddress ( wraddress ),//input[10:0]  wraddress;.wren (1‘b0 ),.q ( avs_readdata ));endmodule

dpram的PORT B端用HEX檔案初始化(511~0迴圈遞減):

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M01/86/15/wKioL1e0I2qxQE2bAABXOWoPIyQ715.jpg" title="AVALON_HEX.jpg" alt="wKioL1e0I2qxQE2bAABXOWoPIyQ715.jpg" />


5. NIOS2 原始碼

#include <stdio.h>#include <sys/unistd.h>#include <string.h>#include <sys/alt_irq.h>#include "system.h"#include "alt_types.h"#include "altera_avalon_dma_regs.h"#include "sys/alt_dma.h"#include <sys/alt_cache.h>#define DAT_LEN 640unsigned int buffer0[DAT_LEN/4];unsigned int *point=VID_DPRAM_0_BASE;static void DMA_Init(void); //初始化DMAunsigned int dma_end_flag = 0;alt_dma_txchan tx;alt_dma_rxchan rx;void dma_done(){dma_end_flag++;}static void DMA_Init(void){tx = alt_dma_txchan_open("/dev/dma_0");if(tx != NULL){printf("DMA transition start\n");}alt_dma_txchan_ioctl(tx,ALT_DMA_SET_MODE_32,NULL);//point是源地址、傳輸資料區塊長度是DAT_LENalt_dma_txchan_send(tx, point, DAT_LEN, NULL, NULL);rx = alt_dma_rxchan_open("/dev/dma_0");alt_dma_rxchan_ioctl(rx,ALT_DMA_SET_MODE_32,NULL);//buffer0是目標地址、傳輸資料區塊長度是DAT_LEN、dma_done()是DMA完成後被調用的回呼函數alt_dma_rxchan_prepare(rx, buffer0 , DAT_LEN, dma_done, NULL);}int main(){int i;for(i=0;i<DAT_LEN/4;i++)buffer0[i] = 0;//alt_dcache_flush_all();//if the nios2 core uses the cacheDMA_Init();//等待中斷結束,說明傳輸完成while(dma_end_flag == 0);alt_dma_txchan_close(tx);alt_dma_rxchan_close(rx);printf("\n============start===========\n");//列印接收地址的資料for(i=0;i<DAT_LEN/4;i++){printf("buffer0[%d]=%d\t",i,buffer0[i]);}printf("\n=============end===========\n");return 0;}


6. 運行結果

650) this.width=650;" src="http://s2.51cto.com/wyfs02/M00/86/16/wKiom1e0JHHSssrhAADYzcNDodA880.jpg" title="AVALON_RESULT.jpg" alt="wKiom1e0JHHSssrhAADYzcNDodA880.jpg" />


本文出自 “shugenyin的部落格” 部落格,請務必保留此出處http://shugenyin.blog.51cto.com/4259554/1839613

NIOS2隨筆——自訂IP(DPRAM)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.