|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
for-generate在和外部信号相连时,感觉很奇怪,因为generate中用一个循环就可以很方便生成很多个类似的模块,但是这些端口信号和外部信号相连却要全部逐个赋值。。。。。。有经验的大神请讲解一下呗,谢谢
- `timescale 1ns/1ps
- `define TWO
- module top(
- clk
- ,rst_n
- ,din0
- ,din1
- ,din2
- ,din3
- ,dout0
- ,dout1
- ,dout2
- ,dout3
- );
- parameter N=4;
- input clk;
- input rst_n;
- input [3:0] din0;
- input [3:0] din1;
- input [3:0] din2;
- input [3:0] din3;
- output [3:0] dout0;
- output [3:0] dout1;
- output [3:0] dout2;
- output [3:0] dout3;
- `ifdef ONE
- generate
- genvar j;
-
- for(j=0;j<N;j=j+1) begin: fuck
-
- wire [3:0] din;
- wire [3:0] dout;
-
- gen gen(
- .clk (clk )
- ,.rst_n (rst_n)
- ,.din (din )
- ,.dout (dout )
- );
- end
- endgenerate
- assign fuck[0].din = din0;
- assign fuck[1].din = din1;
- assign fuck[2].din = din2;
- assign fuck[3].din = din3;
- assign dout0 = fuck[0].dout;
- assign dout1 = fuck[1].dout;
- assign dout2 = fuck[2].dout;
- assign dout3 = fuck[3].dout;
- `elsif TWO
- wire [4*N-1:0] din_w;
- wire [4*N-1:0] dout_w;
- generate
- genvar j;
-
- for(j=0;j<N;j=j+1) begin: fuck
- gen gen(
- .clk (clk )
- ,.rst_n (rst_n )
- ,.din (din_w[(j+1)*4-1 : j*4] )
- ,.dout (dout_w[(j+1)*4-1 : j*4])
- );
- end
- endgenerate
- assign din_w[3:0] = din0;
- assign din_w[7:4] = din1;
- assign din_w[11:8] = din2;
- assign din_w[15:12] = din3;
- assign dout0 = dout_w[3:0] ;
- assign dout1 = dout_w[7:4] ;
- assign dout2 = dout_w[11:8] ;
- assign dout3 = dout_w[15:12];
- `endif
- endmodule
复制代码
module gen(
clk
,rst_n
,din
,dout
);
//---------------------------------
// parameter
//---------------------------------
parameter PAR = 4'd1;
//---------------------------------
// Input and Output
//---------------------------------
input clk;
input rst_n;
input [3:0] din;
output [3:0] dout;
reg [3:0] dout;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
always @(posedge clk,negedge rst_n) begin
if(!rst_n)
dout <= 4'd0;
else
dout <= din + PAR;
end
endmodule
[/code] |
|