简体   繁体   English

是否可以将子模块的 output 绑定到两个不同的 output 端口?

[英]Is it possible to bind the output of a submodule to two different output ports?

I am trying to make a circuit which computes the carries for an addition.我正在尝试制作一个计算加法进位的电路。

In this piece of code, I would like to connect the output port rOut of the submodule pg to two output ports ( rOut and carries[0] ) of the parent module, so both get the same value.在这段代码中,我想将子模块pg的 output 端口rOut连接到父模块的两个 output 端口( rOut和 carry carries[0] ),因此两者都得到相同的值。

template<>
struct Carries<1> : ::sc_core::sc_module {
    sc_vector<sc_in<bool>> a, b;
    sc_in<bool> rIn;
    sc_out<bool> p, g, rOut;
    sc_vector<sc_out<bool>> carries;

    CarryPropGen pg {"PG"};

    SC_CTOR(Carries)
        :   a {"vectA", 1}, b {"vectB", 1},
            rIn {"rIn"},
            p {"p"}, g {"g"}, rOut {"rOut"},
            carries {"vectCarries", 1} {
        pg.a(a[0]);
        pg.b(b[0]);
        pg.r(rIn);

        pg.p(p);
        pg.g(g);
        pg.rOut(rOut);
        pg.rOut(carries[0]);
    }
};

However, I get the error (E109) complete binding failed: 2 binds exceeds maximum of 1 allowed: port 'Carries.PG.port_5' (sc_out) .但是,我收到错误(E109) complete binding failed: 2 binds exceeds maximum of 1 allowed: port 'Carries.PG.port_5' (sc_out) I also tried with a signal, with and without the writer policy SC_MANY_WRITER , as it was suggested by someone on a forum, but it didn't work either.我还尝试了一个信号,无论有没有作者策略SC_MANY_WRITER ,正如论坛上有人建议的那样,但它也不起作用。

I am new to SystemC and while I understand the error, I don't really understand why this can't work and how to do it differently.我是 SystemC 的新手,虽然我理解错误,但我真的不明白为什么这不起作用以及如何以不同的方式做。 So, is there a way to bind one submodule's output to multiple sc_out of the parent module, and how?那么,有没有办法将一个子模块的 output 绑定到父模块的多个sc_out上,如何?

Ports in SystemC are not wires, but smart pointers. SystemC 中的端口不是电线,而是智能指针。 Unlike regular C++ pointers, SystemC ports are safe and support hierarchical binding.与常规的 C++ 指针不同,SystemC 端口是安全的并支持分层绑定。 Similarly to a regular pointers, by default, you can't connect port to 2 channels simultaneously.与常规指针类似,默认情况下,您不能将端口同时连接到 2 个通道。

While this may be inconvenient for low-level modeling, this allows to use ports with any kind of high-level channels, like FIFOs or TLM channels.虽然这对于低级建模可能不方便,但这允许将端口与任何类型的高级通道一起使用,例如 FIFO 或 TLM 通道。

Looks like you need something like broadcast port: when you write to such a port message should be written to all connected channels.看起来您需要广播端口之类的东西:当您写入此类端口时,应将消息写入所有连接的通道。

To create a port that can be binded to a multiple channels, use second template parameter N of sc_port:要创建可以绑定到多个通道的端口,请使用 sc_port 的第二个模板参数N

// ----------------------------------------------------------------------------
//  CLASS : sc_port
//
//  Generic port class and base class for other port classes.
//  N is the maximum number of channels (with interface IF) that can be bound
//  to this port. N <= 0 means no maximum.
// ----------------------------------------------------------------------------
template <class IF, int N = 1, sc_port_policy P=SC_ONE_OR_MORE_BOUND>
class sc_port

Lets test it:让我们测试一下:

#include <systemc.h>

SC_MODULE(test) {
  // Create broadcast_port that allows any number of binded channels
  sc_port<sc_signal_inout_if<int>, 0> SC_NAMED(broadcast_port);

  // create some signals
  sc_signal<int> SC_NAMED(a);
  sc_signal<int> SC_NAMED(b);
  sc_signal<int> SC_NAMED(c);

  SC_CTOR(test) {
    // bind port to signals
    broadcast_port(a);
    broadcast_port(b);
    broadcast_port(c);

    SC_THREAD(test_thread);
  }

  void test_thread() {
    // write 42 to all connected signals
    for (size_t ii = 0; ii < broadcast_port.size(); ++ii) {
      broadcast_port[ii]->write(42);
    }

    wait(SC_ZERO_TIME);
    // print results
    std::cout << a << "\n";
    std::cout << b << "\n";
    std::cout << c << "\n";
  }
};

int sc_main(int, char *[]) {
  test SC_NAMED(test_top);
  sc_start();
  return 0;
}

This is not exactly what we wanted: here we need to iterate over all connected channels each time we need to write something into broadcast port.这并不是我们想要的:每次我们需要向广播端口写入内容时,我们都需要遍历所有连接的通道。

Let's create a derived class that will do this automatically:让我们创建一个派生的 class 自动执行此操作:

template <typename T>
class sc_out_broadcast : public sc_port<sc_signal_inout_if<int>, 0>
{
public:
  explicit sc_out_broadcast(const char *name_) : sc_port(name_) {}

  // write the new value to all connected signals
  void write( const T& value_ )
  {
    for (size_t ii = 0; ii < this->size(); ++ii) {
      (*this)[ii]->write(value_);
    }
  }
};

Here is how we use it in test_thread:下面是我们如何在 test_thread 中使用它:

  void test_thread() {

    broadcast_port.write(42);

    wait(SC_ZERO_TIME);

    std::cout << a << "\n";
    std::cout << b << "\n";
    std::cout << c << "\n";
  }

暂无
暂无

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

相关问题 位向量输出分配延迟 - Delay in bitvector Output assignment 错误:输出文件./.noxim_explorer.tmp损坏,noxim工具 - Error: Output file ./.noxim_explorer.tmp corrupted, noxim tool 如何使用 sc_method 模拟 output 延迟但不在 SystemC 中使用 next_trigger()? - How to simulate output delay using sc_method but without using next_trigger() in SystemC? 如果线程对SystemC中的多个端口敏感,如何确定哪个端口调用了sc_thread? - How to determine which port has invoked an sc_thread if the thread is sensitive to multiple ports in SystemC? 错误:(E107)绑定接口到端口失败:模块“simple_instance.data_in_reg”的端口4上的类型不匹配 - Error: (E107) bind interface to port failed: type mismatch on port 4 of module `simple_instance.data_in_reg' 是否可以获取已传递给函数的sc_fix的属性? - Is it possible to get the attributes of an sc_fix thats been passed into a function? 运行Boost单元测试不同的进程 - Running Boost unit tests on different processes 错误:(E107)将接口绑定到端口失败:接口已绑定到端口:端口&#39;MC8051_ALU()。AM.port_27&#39;(sc_in) - Error: (E107) bind interface to port failed: interface already bound to port: port 'MC8051_ALU().AM.port_27' (sc_in) 是否可以在 C++ 中使用系统 C 数据类型而不使用整个系统 C kernel? - Is it possible to use System C data types in C++ without the entire System C kernel? 如何通过systemC tlm_fifo连接两个模块<float> ? - How to connect two modules by systemC tlm_fifo<float>?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM