作者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