微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 SystemC 中使用 next_trigger() 模拟输出延迟?

如何解决如何在 SystemC 中使用 next_trigger() 模拟输出延迟?

我一直在阅读 Stack Overflow 上的这个被点赞的答案:https://stackoverflow.com/a/26129960/12311164

它表示将 SC_THREAD 中的 wait(delay,units); 替换为 SC_METHOD 中的 next_trigger(delay,units) 有效。

但是当我尝试时,它不起作用。我正在尝试构建具有 2 ns 输出延迟的加法器模块。加法器输出不是 2 ns 的输出延迟,而是每 2 ns 更新一次。

设计:

#include "systemc.h"

#define WIDTH  4

SC_MODULE(adder) {
  sc_in<sc_uint<WIDTH> > A,B;  
  sc_out<sc_uint<WIDTH> > OUT;
 
  void add(){
    sc_time t1 = sc_time_stamp();
    int current_time  = t1.value();
    int intermediate = A.read() + B.read();
    next_trigger(2,SC_NS);
    OUT.write(intermediate);
    cout << " SC_METHOD add triggered at "<<sc_time_stamp() <<endl; 
  }
  
  
  SC_CTOR(adder){
    SC_METHOD(add);
    sensitive << A << B;  
  }
};

我知道如何使用 2 种技术模拟延迟:sc_eventSC_METHOD 以及 wait 中的 SC_THREAD 语句,但我想使用 next_trigger( )。我已经阅读了语言参考手册,但不知道如何去做。

此处在 EDA Playground 上模拟:https://edaplayground.com/x/dFzc

我想我需要在输入改变后触发 2 个 NS,怎么做?

解决方法

您必须手动跟踪状态:

sc_uint<WIDTH> intermediate;

void add(){
    if (A->event() || B->event() || sc_delta_count() == 0) {
        intermediate = A.read() + B.read();
        next_trigger(2,SC_NS);
    } else {
        OUT->write(intermediate);
    }
}

问题是使用 next_trigger 并不能神奇地将您的 SC_METHOD 转换为 SC_THREAD。总的来说,我发现 next_trigger 的任何使用都不方便,而且使用 sc_event 有更好的方法来做到这一点。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。