简体   繁体   English

从sc_signal驱动sc_out

[英]Driving an sc_out from an sc_signal

Consider the following example, where one module's output ( inner::out ) is supposed to drive two outputs ( outer::out and outer::out2 ) of the upper hierarchy level: 考虑下面的示例,其中一个模块的输出( inner::out )应该驱动较高层次结构的两个输出( outer::out2 outer::outouter::out2 ):

#include <systemc.h>

SC_MODULE(inner) {
    sc_out<bool> out;

    SC_CTOR(inner) : out("out") {
        SC_THREAD(doit);
    };

    void doit() {
        for (int i=0; i<10; ++i) {
            out != out;
            wait(10, SC_NS);
        }
    }
};


SC_MODULE(outer) {
    sc_out<bool> out, out2;

    SC_CTOR(outer) : out("out"), out2("out2"), i("inner"), out_s("out_s") {
        i.out(out_s);

        out(out_s);
        out2(out_s);
    }

    inner i;

    sc_signal<bool> out_s;
};


int sc_main(int argc, char **argv) {
    outer o("outer");

    sc_start(1, SC_MS);

    return 0;
}

https://www.edaplayground.com/x/5s2C# https://www.edaplayground.com/x/5s2C#

Running this results in the following error: 运行此命令将导致以下错误:

Error: (E115) sc_signal<T> cannot have more than one driver: 
 signal `outer.out_s' (sc_signal)
 first driver `outer.inner.out'  (sc_out)
 second driver `outer.out2' (sc_out)
In file: ../../../../src/sysc/communication/sc_signal.cpp:73

It seems that outer::out2 is considered to drive out_s instead of being driven by it. 似乎out_s outer::out2被认为是驱动 out_s而不是由它驱动 Is there something obvious that I'm overlooking? 有什么明显的我可以忽略的吗? Is there a way to make this work without using an explicit SC_METHOD sensitive to inner::out inside outer ? 有没有一种方法,使这项工作,而无需使用一个明确的SC_METHOD敏感inner::outouter

Your design describes a signal driven by three different output ports -- not what you want. 您的设计描述了由三个不同输出端口驱动的信号-而不是您想要的。

You may want to use port-to-port binding . 您可能要使用端口到端口绑定 If you're not familiar with the concept, section 4.1.3 "Port binding and export binding" in the SystemC LRM describes it like this: 如果您不熟悉此概念,SystemC LRM中的第4.1.3节“端口绑定和导出绑定”将对此进行描述:

When port A is bound to port B, and port B is bound to channel C, the effect shall be the same as if port A were bound directly to channel C. Wherever this standard refers to port A being bound to channel C, it shall be assumed this means that port A is bound either directly to channel C or to another port that is itself bound to channel C according to this very same rule. 当端口A绑定到端口B,并且端口B绑定到通道C时,其效果应与将端口A直接绑定到通道C相同。无论该标准是指端口A绑定到通道C上,还是应该这样做。假设这意味着端口A根据此非常相同的规则直接绑定到通道C或绑定到本身绑定到通道C的另一个端口。 This same rule shall apply when binding exports. 约束出口时,应适用同一规则。

With port-to-port binding, you can bind inner::out directly to both outer::out and outer::out2 , without a signal in between. 使用端口到端口绑定,您可以将inner::out直接绑定到outer::out2 outer::outouter::out2两者之间,而无需两者之间的信号。 For example: 例如:

#include <systemc.h>

SC_MODULE(inner) {
    sc_port<sc_signal_inout_if<bool>, 2> out;

    SC_CTOR(inner) : out("out") {
        SC_THREAD(doit);
    };

    void doit() {
        for (int i=0; i<10; ++i) {
            out[0]->write(!out[0]->read());
            out[1]->write(!out[1]->read());
            wait(10, SC_NS);
        }
    }
};


SC_MODULE(outer) {
    sc_out<bool> out, out2;

    SC_CTOR(outer) : out("out"), out2("out2"), i("inner") {
        i.out(out);
        i.out(out2);
    }

    inner i;
};


int sc_main(int argc, char **argv) {
    outer o("outer");
    sc_signal<bool> out_s;
    sc_signal<bool> out2_s;

    o.out(out_s);
    o.out2(out2_s);

    sc_trace_file *tf = sc_create_vcd_trace_file("trace");
    sc_trace(tf, out_s, "out_s");
    sc_trace(tf, out2_s, "out2_s");

    sc_start(1, SC_MS);

    sc_core::sc_close_vcd_trace_file(tf);

    return 0;
}

There are a couple of things to note in the above code: 上面的代码中有两点需要注意:

  • inner::out is declared as a sc_port<sc_signal_inout_if<bool>, 2> , which is basically the same as an sc_out but allows the port to be bound to two channels. inner::out声明为sc_port<sc_signal_inout_if<bool>, 2> ,基本上与sc_out相同,但允许将端口绑定到两个通道。 sc_out can only be bound to a single channel. sc_out只能绑定到单个通道。
  • When writing to inner::out , you have to specify the bound channel you are driving. 写入inner::out ,必须指定要驱动的绑定通道。 This is done with the [] operator -- see inner::doit() above where both bound channels are driven. 这是通过[]运算符完成的-请参见上面的inner::doit() ,其中驱动了两个绑定通道。

When run, the above code produces a trace.vcd file that shows the levels on the two signals, out_s and out2_s , toggling. 运行时,上面的代码将生成一个trace.vcd文件,该文件显示两个信号out_sout2_s的电平切换。

Having explained all that, I'm not sure that it's really what you want. 在解释了所有这些之后,我不确定这是否真的是您想要的。 Having an output port fan out like that is pretty unusual. 像这样将输出端口扇出是很不正常的。 Do you really need two output ports on outer ? 您是否真的需要outer两个输出端口?

Error: (E115) sc_signal cannot have more than one driver: 错误:(E115)sc_signal不能有多个驱动程序:

Can be solved by using SC_MANY_WRITERS. 可以通过使用SC_MANY_WRITERS来解决。

for example: 例如:

sc_signal < bool, SC_MANY_WRITERS > reset_sig;

and then for a module called initializer we can bind this signal as such: 然后对于称为初始化器的模块,我们可以这样绑定该信号:

initializer<int, 16> init("init");

init.reset(reset_sig);

now for the other module, producer module, which is using the same signal: 现在,对于另一个模块,生产者模块,它使用相同的信号:

producer<int, 16> prc("prc");

prc.resetIn(reset_sig);
prc.resetOut(reset_sig);

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

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