generate
一:generate
Verilog-2001添加了generate循环,允许产生module和primitive的多个实例化,同时也可以产生多个variable,net,task,function,continous assignment,initial和always。在generate语句中可以引入if-else和case语句,根据条件不同产生不同的实例化。
用法:
1. generate语法有generate for, genreate if和generate case三种
2. generate for语句必须有genvar关键字定义for的变量
3. for 的内容必须加begin和end
4. 必须给for语段起个名字
例子:
2、gnerate for实现复制
genvar bufds_num;
generate
for ( bufds_num = 0; bufds_num < DATA_WIDTH ; bufds_num = bufds_num + 1)
begin :ibufds_inst
IBUFDS #(.DIFF_TERM("FALSE"),.IBUF_LOW_PWR("TRUE"), .IOSTANDARD("LVDS_25")
) IBUFDS_inst00 (.O(dout[bufds_num]), .I(din_p[bufds_num]), .IB(din_n[bufds_num]));
end
endgenerate
2、 generate if 用法
parameter TRANS_FLAG = 1'b1;
generate
if(TRANS_FLAG == 1'b1 )
begin:trans_f
always @( posedge rd_clk )
begin
if( rd_cnt >= cfg_rd_cnt-1 )
rd_cnt <=4'd0;
else
rd_cnt <= rd_cnt + 1'b1;
end
always @( posedge rd_clk )
begin
if((empty == 1'b0)&&(rd_cnt == 0))
rd_en <= 1'b1;
else
rd_en <= 1'b0;
end
end
else
begin
always @( posedge rd_clk )
begin
if(empty == 1'b0)//(rd_cnt == 0)//&& )
rd_en <= 1'b1;
else
rd_en <= 1'b0;
end
always @( posedge rd_clk )
begin
if(num == (cfg_len-1)&&out_valid) //( )&&(rd_cnt == cfg_rd_cnt ) )
begin
num <= 5'd0;
end
else if(out_valid)//( rd_cnt == cfg_rd_cnt )
begin
num <= num + 1'b1;
end
else
begin
num <= num;
end
end
always @( posedge rd_clk )
begin
if((num == 5'd0)&& out_valid )
begin
nt_dout <= rd_en;
end
else
begin
nt_dout <= 1'b0;
end
end
always @( posedge rd_clk )
begin
nd_dout <= out_valid;
end
end
endgenerate
二、参数传递
类似VHDL的Generic语句,Verilog也可以在例化时传递参数
传递的参数是子模块中定义的parameter。
传递的方法:
1、module_name #( parameter1, parameter2) inst_name( port_map);
2、module_name #( .parameter_name(para_value), .parameter_name(para_value)) inst_name (port map);
用#方法和port map的写法差不多
module multiplier (a, b, product);
parameter a_width = 8, b_width = 8;
localparam product_width = a_width+b_width;
input [a_width-1:0] a;
input [b_width-1:0] b;
output[product_width-1:0]product;
generate
if((a_width < 8) || (b_width < 8))
CLA_multiplier #(a_width, b_width) u1 (a, b, product);
else
WALLACE_multiplier #(a_width, b_width) u1 (a, b, product);
endgenerate
endmodule
generate的更多相关文章
- 使用mvn archetype:generate生产maven工程,响应很慢
经常到下列时就不往下走了. 解决方案: 1.不使用interactive mode方式,直接指定DarchetypeArtifactId 2.仍使用interactive mode方式,但增加参数 - ...
- [LeetCode] Generate Parentheses 生成括号
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- LeetCode 22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- 【leetcode】Generate Parentheses
题目简述: Given n pairs of parentheses, write a function to generate all combinations of well-formed par ...
- 在cmd命令行使用Maven Archetype插件 generate命令创建简单的java web项目
前提: 1.下载apache-maven:https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache ...
- No.022:Generate Parentheses
问题: Given n pairs of parentheses, write a function to generate all combinations of well-formed paren ...
- iOS 苹果开发证书失效的解决方案(Failed to locate or generate matching signing assets)
从2月14日开始,上传程序的同学可能会遇到提示上传失败的提示. 并且打开自己的钥匙串,发现所有的证书全部都显示此证书签发者无效. 出现以下情况: Failed to locate or generat ...
- How to generate UML Diagrams from Java code in Eclipse
UML diagrams compliment inline documentation ( javadoc ) and allow to better explore / understand a ...
- maven archetype:generate 命令简化项目模板数量
在maven里使用 mvn archetype:generate 来创建项目是十分方便的,但有时也不尽然.在网络不好时,从网络上加载 archetype-catalog.xml文件(http://re ...
- Generate Time Data(普通日期主数据)
Note: While using this option you need to replicate the standard table into SAP HANA that is T005T, ...
随机推荐
- 9 random模块
1.ramdom模块主要方法 random.random()函数是这个模块中最常用的方法了,它会生成一个随机的浮点数,范围是在0.0~1.0之间. random.uniform()正好弥补了上面函数的 ...
- Quartz+TopShelf实现Windows服务作业调度
Quartz:首先我贴出来了两段代码(下方),可以看出,首先会根据配置文件(quartz.config),包装出一个Quartz.Core.QuartzScheduler instance,这是一个调 ...
- Delphi 动态数组合并
TIntArray = array of Integer; function MergeArray(const ArrayA, ArrayB: TIntArray): TIntArray; var i ...
- spring AOP 注解配置
applicationContext-resource.xml: <?xml version="1.0" encoding="UTF-8"?>< ...
- Mysql InnoDB 数据更新 锁表
一.数据表结构 1 2 3 4 5 6 7 8 9 10 CREATE TABLE `jx_attach` ( `attach_id` int(11) NOT NULL AUTO_INCREMEN ...
- new operator
[new operator] When the code new Foo(...) is executed, the following things happen: A new object is ...
- <a>, <input>, <button>的区分与何时使用
像 button 的原始目的就是一个通用的按钮,点击后应该触发 JavaScript, 没有其它附带的隐含的附加效果,<a> 标签的隐含附带效果就是跳转页面到其它地方,而提交表单时应该有一 ...
- Educational Codeforces Round 58
D. GCD Counting 题意: 给出n个点的树,每个点有一个权值,找出一条最长的路径使得路径上所有的点的gcd>1 题解: gcd>1的一定不会有很多.所以暴力搞一下就行,不需要点 ...
- Partition List双色问题链表版
[抄题]: Given a linked list and a value x, partition it such that all nodes less than x come before no ...
- thinkphp下多语言
这里指定2种语言 ,zh-cn 和 zh-tw 1.在配置文件中写入 'LANG_SWITCH_ON' => true, // 开启语言包功能 'LANG_AUTO_DETECT' => ...