简体   繁体   English

如何检查sc_buffer和sc_signal之间的区别?

[英]How can I check the difference between sc_buffer and sc_signal?

I would like to check the difference between using sc_buffer and sc_signal . 我想检查使用sc_buffersc_signal之间的区别。 I have coded a module which adds two random numbers and then I run two tests in parallel: one using sc_buffer and the other using sc_signal . 我编写了一个模块,它添加了两个随机数,然后我并行运行了两个测试:一个使用sc_buffer ,另一个使用sc_signal Nevertheless, when I check with gtkwave I see the same traces for both examples, so I think for this case there should not be any difference. 然而,当我用gtkwave检查时,我看到两个例子都有相同的痕迹,所以我认为对于这种情况应该没有任何区别。 How can I check the difference? 我该如何检查差异? or is it that these two different types of channel are intended for different applications? 或者这两种不同类型的通道是否适用于不同的应用?

sc_buffer is probably most useful when modeling at an abstract level. 在抽象级别进行建模时, sc_buffer可能最有用。

For example, consider modeling a serial communication channel. 例如,考虑建模串行通信信道。 The transmitter could send the same character twice in a row . 发射器可以连续两次发送相同的字符 If an sc_signal was used as the channel, the receiver wouldn't detect the second character, but with an sc_buffer , it would. 如果sc_signal被用作通道,接收器将不会检测到第二个字符,但是使用sc_buffer ,它会。

#include <systemc>
#include <iostream>

using namespace sc_core;
using namespace std;

struct Transmitter : public sc_module {

    sc_out<char> out;

    Transmitter(sc_module_name name) : sc_module(name) {
        SC_THREAD(transmit);
    }

    void transmit() {
        wait(1, SC_NS);
        out.write('x');

        wait(1, SC_NS);
        out.write('x');

        wait(1, SC_NS);
        out.write('y');
    };

    SC_HAS_PROCESS(Transmitter);
};

struct Receiver : public sc_module {

    sc_in<char> in;

    Receiver(sc_module_name name) : sc_module(name) {
        SC_METHOD(receive);
        sensitive << in;
        dont_initialize();
    }

    void receive() {
        cout << sc_time_stamp() << ": " << name() << " received "
             << in.read() << endl;
    }

    SC_HAS_PROCESS(Receiver);
};

int sc_main(int argc, char* argv[])
{
    sc_signal<char> signal;
    sc_buffer<char> buffer;

    Transmitter signal_transmitter("signal_transmitter");
    Receiver signal_receiver("signal_receiver");
    Transmitter buffer_transmitter("buffer_transmitter");
    Receiver buffer_receiver("buffer_receiver");

    signal_transmitter.out(signal);
    signal_receiver.in(signal);

    buffer_transmitter.out(buffer);
    buffer_receiver.in(buffer);

    sc_start();

    return 0;
}

The above example produces this output: 上面的例子产生了这个输出:

1 ns: signal_receiver received x
1 ns: buffer_receiver received x
2 ns: buffer_receiver received x
3 ns: signal_receiver received y
3 ns: buffer_receiver received y

Notice that signal_receiver didn't detect the character sent at 2 ns. 请注意, signal_receiver未检测到2 ns发送的字符。

You won't see any difference in a VCD trace, because the values stored in the sc_buffer and sc_signal channels are identical. 您将看不到VCD跟踪的任何差异,因为存储在sc_buffersc_signal通道中的值是相同的。 The difference is when the receiver is triggered. 不同之处在于接收器被触发时。

You can look at the answer below for the differences between sc_buffer and sc_signal . 您可以查看以下答案,了解sc_buffersc_signal之间的差异。

In SystemC, can the sc_signal_in/out type port be bound to the primary channel sc_buffer? 在SystemC中,sc_signal_in / out类型端口是否可以绑定到主通道sc_buffer?

sc_buffer is basically derived from sc_signal and it re-implements the write and update functions to generate notification for every change. sc_buffer基本上是从sc_signal派生的,它重新实现了writeupdate函数,以便为每个更改生成通知。 So if your generate new numbers which are same as the previous number written into the channel and you are dumping some output at each event notification you should see some difference. 因此,如果您生成的新数字与写入通道的前一个数字相同,并且您在每个事件通知中转储一些输出,您应该会看到一些差异。

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

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