日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

自定义IP原来如此简单

發(fā)布時(shí)間:2025/4/16 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 自定义IP原来如此简单 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

首先用Verilog語(yǔ)言或者VHDL編寫(xiě)、或者用原理圖來(lái)畫(huà)硬件驅(qū)動(dòng),以數(shù)碼管驅(qū)動(dòng)為例子,編寫(xiě)Verilog如下:

1 module sg7IP(
2
3 ?input reset,
4 ?input clk,
5 ?input avs_s1_write,
6 ?input [31:0]avs_s1_writedata,
7 ?input avs_s1_address,
8 ?output wire [7:0] oSEG7
9 );
10
11 ?reg [7:0] sg7_r;
12 ?always @(posedge clk or posedge reset)
13 begin
14 if(reset)
15 sg7_r<=8'hf;
16 else if(avs_s1_write&&avs_s1_address==0)
17 sg7_r[7:0]<=avs_s1_writedata[7:0];
18
19 end
20 assign oSEG7=~sg7_r;
21 endmodule
22

?

?

然后編寫(xiě)一個(gè)頂層文件來(lái)調(diào)用sg7IP.v來(lái)測(cè)試驗(yàn)證上面的驅(qū)動(dòng)是正常的。我這里編寫(xiě)了sg7top.v來(lái)作為頂層文件。

?

1 module seg7top(
2 input iCLK_50,
3 input [0:0]iKEY,
4 output wire [6:0] oHEX0_D,
5 output wire oHEX0_DP
6 );
7
8
9 sg7IP sg7ipu0(
10 .reset(!iKEY[0]),
11 .clk(iCLK_50),
12 .avs_s1_write(1'b1),
13 .avs_s1_writedata(32'd113),
14 .avs_s1_address(1'b0),
15 .oSEG7({oHEX0_DP,oHEX0_D[6:0]})
16

17 endmodule
18

分配管教,編譯后下載到DE2-70的開(kāi)發(fā)板中,數(shù)碼管HEX0顯示為F則表示硬件驅(qū)動(dòng)正常。

?

?

然后打開(kāi)SOPCBuilder,新建一個(gè)component。過(guò)程如下圖。

?

?

?

添加sg7IP、onchipmemory、cpu、jtag uart組件,點(diǎn)擊“生成”

?

?

完了后在QUARTUS II中修改sg7top.v

?

?

?

1 module seg7top(
2 input iCLK_50,
3 input [0:0]iKEY,
4 output wire [6:0] oHEX0_D,
5 output wire oHEX0_DP
6 );
7
8
9 nios_cpu nios_cpu_inst
10 (
11 .clk_0 (iCLK_50),
12 .oSEG7_from_the_sg7IP_0 ({oHEX0_DP,oHEX0_D[6:0]}),
13 .reset_n (iKEY[0])
14 );
15
16 endmodule
17

?

?

重新編譯,下載。

打開(kāi)NISO IDE。

新建空工程。

建立sg7.h

?

?

1 #ifndef SEG7_H_
2 #define SEG7_H_
3
4 void SEG7_NUM(alt_u8 num);
5
6
7 #endif /*SEG7_H_*/
8

?

?

建立sg7.c

?

?

1 #include "io.h"
2 #include "alt_types.h"
3
4 #include "system.h"
5
6 #include "SEG7.h"
7
8 #define SEG7_SET(seg_mask) IOWR(SG7IP_0_BASE,0,seg_mask)
9
10 static unsigned char szMap[] = {
11 63, 6, 91, 79, 102, 109, 125, 7,
12 127, 111, 119, 124, 57, 94, 121, 113
13 }; // 0,1,2,....9, a, b, c, d, e, f
14
15
16 void SEG7_NUM(alt_u8 num)
17 {
18 SEG7_SET(szMap[num]);
19 }
20

?

建立main.c

?

1 #include <stdio.h>
2 #include "system.h"
3 #include "unistd.h"
4 #include "alt_types.h"
5 #include "SEG7.h"
6
7 int main(void) {
8 alt_u8 i=0;
9 printf("My first IP");
10 while(1){
11 for(i = 0; i <10; i++) {
12 SEG7_NUM(i);
13 printf("Now print:%d\n",i);
14 usleep(1 * 1000 * 1000);
15 }
16 }
17 return 0;
18 }
19

CTRL+B編譯。

run as? NIOS II? hardware。

開(kāi)發(fā)板中的數(shù)碼管從0到9不斷變化。IP編寫(xiě)測(cè)試完畢。

轉(zhuǎn)載于:https://www.cnblogs.com/nios_ii/archive/2010/10/05/1844432.html

《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的自定义IP原来如此简单的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。