FPGA的自适应与条件编译

8 篇文章 0 订阅
1 篇文章 0 订阅

条件编译和参数化数字系统设计

首先思考这样一个问题,百兆网口和千兆网口的时序肯定不一样,那么网口只有一个,程序只有一个,怎么做到同一个程序中可以满足两种接口的自适应呢?
下面介绍在FPGA中如何实现自适应的格式。
要实现自适应,就是在主程序中添加预编译代码,然后在外创建一个预编译文档,程序运行到主程序的预编译代码时,判断是否采用,从而实现自适应功能。

//这段程序相当于括号,告诉软件这里用不用预编译文件
`ifdef...`endif	
`ifdef...`elsif...`elsif...`endif

条件编译程序的格式

//条件编译
`include "docname.v"	//预编译的文件名
module test_gg(
	input			clk,
	input			rst_n,
	input			key,	//模块的按键输入
//条件编译
`ifdef USE_KEY_Board	//如果使用了按键模块
	input	[3:0]	Row_i,//增加键盘行输入
	output	[3:0]	Col_o,//增加键盘列输出
`endif
`ifdef USE_IR			//如果使用了红外遥控模块
	input			iIR,	//增加iIR输入
`endif	
	output			dout	//模块的输出
);
......//省略

//信号的两种模式
`ifdef USE_KEY_Board
	wire	key_flag;
	wire	[3:0]key_value;
`elsif USE_IR
	wire	ir_Get_Flag;
	assign	ir_success = ~ir_Get_Flag;
`endif

`ifdef USE_KEY_Board
	assign key_value = 4'd1101;
`endif 

`ifdef USE_IR
	assign iraddr = 1;
`endif

//模块的条件例化
sys_crtl sys_crtl(
	.clk(clk),
	.rst_n(rst_n),
`ifdef USE_KEY_Board
	.key_flag(key_flag),
	.key_value(key_value),
`endif
`ifdef USE_IR
	.ir_Get_Flag(ir_Get_Flag),
`endif
	.freq_sel(freq_sel)
);


`ifdef USE_KEY_Board
	key_board key_board(
		.....
	);
`endif

//参数化数字设计
	always @(*)
		if(en=` Key_word0)
			...
		else if(en=` Key_word1)
			....
//在这里,如果我们使用了多个键盘的自适应程序。Key_word1的值不同,位数不同时,可以采用参数化的自适应设计。在预编译中定义使用各个键盘的Key_word值,然后在这里用`Key_word的形式表现出来。详情见下

参数化数字设计(预编译文件)

//docname 预编译文件
`define USE_KEY_Board 1				//当我们不采用这个模块的时候 屏蔽掉,那么主程序就不会编译这个了
//`define USE_KEY_Detect 1
//`define USE_IR 1
`define user_ir_addr 16'hff00

//参数化定义
`ifdef USE_KEY_Board
	`define Key_word0 4'd0
	`define Key_word1 4'd1
	`define Key_word2 4'd2
    `define Key_word3 4'd3
	`define Key_word4 4'd4
    `define Key_word5 4'd5
    `define Key_word6 4'd6
    `define Key_word7 4'd7
`elsif USE_IR
	`define Key_word0 8'h5
    `define Key_word1 8'h4
    `define Key_word2 8'h3
    `define Key_word3 8'h2
    `define Key_word4 8'h1
    `define Key_word5 8'h0
    `define Key_word6 8'ha
    `define Key_word7 8'hc0
`endif
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值