作者zxvc (众生都是未来佛)
看板Electronics
标题[心得] SystemVerilog写pipeline registers
时间Fri Jun 25 08:00:41 2010
在写HDL时,有时modules要接起来线很多,很烦、易接错。
又如果modules间要加pipeline registers,
类似wire宣告又会多一卡车(夸饰)的分量。
code一多,要维护就很困难。
我最近就在想如何用SystemVerilog提供的语法化简这些工作。
我想到的方法是把IO port用packed structure包起来,
然後可以写一个parameterized D flip-flop
作pipeline registers。
以下是个例子(output其实是可以与input用不用同的structure。
这范例故意一样而已。):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
typedef struct packed {
logic [5:0] a;
logic [1:0] [1:0] b;
// ports要多少,有多少。
} TestIn;
module Test(
output TestIn out,
input TestIn in,
input reset,
input clock
);
// Pipeline registers.
Dff #($bits(in)) dffInst(out, in, reset, clock);
endmodule
module Dff(q, d, reset, clock);
parameter Len = 0;
output logic [Len-1:0] q;
input [Len-1:0] d;
input reset;
input clock;
always_ff@(posedge clock or negedge reset) begin
if(!reset) begin
q <= 0;
end
else begin
q <= d;
end
end
endmodule
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
以上code已用Design Compiler 2009.06合成过。
--
信佛的人要知道:佛绝不会说谎。但请把握时光。
法灭尽经:
http://www.cbeta.org/result/normal/T12/0396_001.htm
共勉之。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.115.221.79
1F:→ zxvc:code为什麽能重复利用较好?以上面的例子,如果想把Dff改成 06/25 08:06
2F:→ zxvc:synchronous reset只要改Dff就好。如果是用copy and paste 06/25 08:07
3F:→ zxvc:always_ff,copy几个就要改几个。copy 100个就要改100个。 06/25 08:09
4F:→ zxvc:所以一般reusable会比copy and paste的coding style来得 06/25 08:10
5F:→ zxvc:容易维护。 06/25 08:11
※ 编辑: zxvc 来自: 140.115.221.79 (06/25 08:14)
6F:→ zxvc:struct有一个限制:没有parameterized struct。除非把它包在 06/27 13:34
7F:→ zxvc:parameterized interface,然用後overwrite interface的 06/27 13:35
8F:→ zxvc:parameter,达到类似的效果,但用起来不是很方便。 06/27 13:36