简体   繁体   English

SystemVerilog可以表示具有异步设置和复位的触发器而无需添加不可合成的代码吗?

[英]Can SystemVerilog represent a flip-flop with asynchronous set and reset without adding unsynthesizable code?

I'm coming from a Verilog-95 background, and I'm trying to figure out what Verilog-95 hoops I don't have to jump through anymore. 我来自Verilog-95背景,我正在试图找出Verilog-95的箍,我不再需要跳过它。

The obvious way to write a flip flop with async set and reset in Verilog-95 is: 在Verilog-95中使用异步设置和重置编写触发器的明显方法是:

always @(posedge clk or negedge resetb or negedge setb) begin
  if (!resetb)      q <= 0;
  else if (!setb)   q <= 1;
  else              q <= d;
end

This works in synthesis. 这适用于综合。 But, this doesn't work in simulation if we ever assert both resetb and setb, and then de-assert resetb before de-asserting setb, since there's no posedge trigger for either of those signals. 但是,如果我们断言resetb和setb,然后在取消置位setb之前取消置位resetb,那么这在模拟中不起作用,因为这些信号中没有任何触发器。 We need to add the following (which varies depending on your synthesis tool), to get simulation to match synthesis: 我们需要添加以下内容(根据您的综合工具而有所不同),以获得匹配合成的模拟:

// synopsys translate_off
always @(resetb or setb)
  if (resetb && !setb) force q = 1;
  else               release q;
// synopsys translate_on

Is there a SystemVerilog construct that will let you do this without this extra junk? 是否有一个SystemVerilog构造可以让你在没有这个额外的垃圾的情况下做到这一点? Better yet, is there a straightforward way to do it in Verilog-95? 更好的是,在Verilog-95中有一种直接的方法吗?

Flip-flops with multiple asynchronous controls are best avoided. 最好避免使用具有多个异步控件的触发器。 The timing checks necessary to ensure they function properly are complex and easy to mess up. 确保它们正常运行所需的时序检查很复杂,容易搞砸。 If you really need to use them, then it's probably best to instantiate them by hand where needed. 如果你真的需要使用它们,那么最好在需要时手动实例化它们。 If you let your synthesis tool infer them, it may use them in places you don't intend, which increases the risk that the timing checks don't get done properly. 如果您让综合工具推断它们,它可能会在您不想要的地方使用它们,这会增加定时检查无法正确完成的风险。

One final aside, there is a similar simulation-synthesis mismatch issue with all asynchronous flops, if the active edge of reset is at time zero and is simulated before the flop is initialized to x, and the clock isn't running in reset. 最后一点,如果复位的有效边沿时间为0并且在触发器初始化为x之前模拟,并且时钟未在复位中运行,则所有异步触发器都存在类似的模拟 - 合成失配问题。 I believe some simulators have special cases to ensure the logic is not initialized in this order. 我相信一些模拟器有特殊情况可以确保逻辑没有按此顺序初始化。

That said, I had luck moving the priority logic outside the sequential always block. 也就是说,我很幸运将优先级逻辑移到了顺序always阻塞之外。 Note I'm using active-high signals for simplicity. 注意我使用高电平信号是为了简单起见。

assign s_int = s && !c;

always @(posedge clk or posedge s_int or posedge c) begin
        if (c)
                q <= 1'b0;
        else if (s_int)
                q <= 1'b1;
        else
                q <= d;
end

This is something I wish SystemVerilog had improved. 这是我希望SystemVerilog得到改进的东西。 If you want to allow both being low at the same time, then stick with the current method. 如果你想同时允许两者都低,那么坚持使用当前的方法。

The other option is to create a design rule stating the asynchronous signals can not be active at the same time and enforce the rule with an assertion. 另一种选择是创建一个设计规则,说明异步信号不能同时处于活动状态,并使用断言强制执行规则。 Assertions are suppose to be ignored by synthesizers, so translate_off/on should not be be necessary. 假设合成器会忽略断言,因此应该使用translate_off / on。

Here is an example using an inline assertion: 以下是使用内联断言的示例:

always_ff @(posedge clk, negedge resetb, negedge setb) begin : dff_asyncRbSb
  if (!resetb)      q <= 0;
  else if (!setb)   q <= 1;
  else              q <= d;
  asrt_setrst : assert(resetb||setb)
     else $error("resetb and setb can not be low at the same time.");
end : dff_asyncRbSb

I don't know any SV, so this isn't an answer, but the issue here is that Verilog (and, I think, SV) event expressions are basically broken. 我不知道任何SV,所以这不是一个答案,但这里的问题是Verilog(和我认为,SV)事件表达式基本上被打破了。 The problem is that, when you have multiple conditions in an event expression: 问题是,当事件表达式中有多个条件时:

event_expression ::=
  expression 
  | hierarchical_identifier
  | posedge expression
  | negedge expression
  | event_expression or event_expression
  | event_expression , event_expression

then there's no bullet-proof way to determine which expression caused the event, since the only thing you can do is to check the current state of the expression. 然后没有防弹的方法来确定哪个表达式导致了事件,因为你唯一能做的就是检查表达式的当前状态。 So, if you've got @(posedge clk, posedge rst) , for example, you look at the current levels of clk and rst and hope this is sufficient to do the job. 所以,如果你有@(posedge clk, posedge rst) ,例如,你看看clk和rst的当前水平,并希望这足以完成这项工作。 In general, it isn't, but your example is the only practical case (I think) that causes a problem. 一般情况下,它不是,但你的例子是导致问题的唯一实际案例(我认为)。

VHDL handles this by having signal attributes, which let you determine whether a signal has caused an event. VHDL通过具有信号属性来处理这一点,这可以让您确定信号是否导致了事件。 In VHDL, you get an event when any signal in your sensitivity list changes, and you then check their 'event attribute to determine whether they fired the process. 在VHDL中,当灵敏度列表中的任何信号发生变化时,您会收到一个事件,然后检查它们的'event属性”以确定它们是否触发了该过程。 No confusion, no posedge or negedge, and it all works. 没有混乱,没有构成或没有混乱,这一切都有效。

I've just had a quick look at the SV LRM, and SV attributes appear to be the same as Verilog attributes, so I think you're out of luck. 我刚刚看了一下SV LRM,SV属性看起来与Verilog属性相同,所以我觉得你运气不好。

with no edge defined, the assertion and de-assertion of reset and set signals should be able to trigger this code in simulation. 在没有定义边沿的情况下,复位和置位信号的断言和解除断言应该能够在仿真中触发该代码。

always_ff should be able to create a flop at synthesis.

Below code is compilation clean using synopsys VCS tool. 下面的代码是使用synopsys VCS工具进行编译清理。

always_ff @(posedge clk, resetb,  setb) begin 
  if (!resetb)      q <= 0;
  else if (!setb)   q <= 1;
  else              q <= d;
end

Try this: always_ff @(posedge clk or negedge resetb or negedge setb) 试试这个: always_ff @(posedge clk或negedge resetb或negedge setb)

systemverilog uses always_ff for clock triggered logic and always_comb for combo logic systemverilog使用always_ff作为时钟触发逻辑,使用always_comb作为组合逻辑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM