一: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语段起个名字

例子:

1、generate for 与always 语句结合使用
genvar i;
generate
for(i = 0; i <MCB_BYTE_WIDTH-1 ;i = i+1)
begin :data_shit
  always @( posedge wr_clk )
  begin
    if(i_h_sync )
    begin
      data_ram[i+1] <= data_ram[i];
    end
  end
end
endgenerate

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的更多相关文章

  1. 使用mvn archetype:generate生产maven工程,响应很慢

    经常到下列时就不往下走了. 解决方案: 1.不使用interactive mode方式,直接指定DarchetypeArtifactId 2.仍使用interactive mode方式,但增加参数 - ...

  2. [LeetCode] Generate Parentheses 生成括号

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  3. LeetCode 22. Generate Parentheses

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  4. 【leetcode】Generate Parentheses

    题目简述: Given n pairs of parentheses, write a function to generate all combinations of well-formed par ...

  5. 在cmd命令行使用Maven Archetype插件 generate命令创建简单的java web项目

    前提: 1.下载apache-maven:https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache ...

  6. No.022:Generate Parentheses

    问题: Given n pairs of parentheses, write a function to generate all combinations of well-formed paren ...

  7. iOS 苹果开发证书失效的解决方案(Failed to locate or generate matching signing assets)

    从2月14日开始,上传程序的同学可能会遇到提示上传失败的提示. 并且打开自己的钥匙串,发现所有的证书全部都显示此证书签发者无效. 出现以下情况: Failed to locate or generat ...

  8. How to generate UML Diagrams from Java code in Eclipse

    UML diagrams compliment inline documentation ( javadoc ) and allow to better explore / understand a ...

  9. maven archetype:generate 命令简化项目模板数量

    在maven里使用 mvn archetype:generate 来创建项目是十分方便的,但有时也不尽然.在网络不好时,从网络上加载 archetype-catalog.xml文件(http://re ...

  10. Generate Time Data(普通日期主数据)

    Note: While using this option you need to replicate the standard table into SAP HANA that is T005T, ...

随机推荐

  1. 常用HTTP状态码

    1.常用状态码介绍 在http响应协议中,我们通过HttpWatch抓包抓取到响应信息.其中响应首行中就包含一个状态码.状态码由三位数字组成,表示请求是否被理解或者被满足.HTTP响应状态码的第一个数 ...

  2. vue基础——vue实例

    创建一个vue实例 每个vue应用都是通过Vue函数创建一个新的Vue实例开始的 var vm = new Vue({ //选项 }) 一个Vue应用由一个通过new Vue创建的根Vue实例,以及可 ...

  3. Delphi 操作键盘按下和释放操作

    Unit Unit1; Interface Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ...

  4. urllib.parse.urldefrag(url)的解释

    引自https://www.cnblogs.com/ublue/articles/4471210.html 1.URL hash(片段标识符) 任一带#的URL称为片段URL(通常称为URL hash ...

  5. Spring Retry

    最近组内准备将项目中原有的重试功能抽取出来重构为一个重试平台,由于对重试的功能要求比较高,采用了不少中间件和框架(jimdb,jproxy, Elastic-Job ,JMQ,Hbase, Disru ...

  6. HTTP协议图示详解

    一.概念 协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则,超文本传输协议(HTTP)是一种通信协议,它允许将超文本标记语言(HTML)文档从Web服务器传送到客户端的浏览器. ...

  7. dreamwave基础

    WEBcs架构需要在客户段安装程序, 需要安装程序, 工作量会比较大, 需要安装和维护, 比如以后系统升级, 会很麻烦. 优点是一些业务逻辑可以在客户端, 可以减少服务器的一些压力, 客户端的界面操作 ...

  8. 第五章 二叉树(b)树的表示

  9. 第七章 二叉搜索树 (d3)AVL树:删除

  10. 取消svn add

    svn commit之前,add的东西都可以取消. 通过先执行svn cleanup,再执行svn revert --recursive example_folder.