簡體   English   中英

是否可以將子模塊的 output 綁定到兩個不同的 output 端口?

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

我正在嘗試制作一個計算加法進位的電路。

在這段代碼中,我想將子模塊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]);
    }
};

但是,我收到錯誤(E109) complete binding failed: 2 binds exceeds maximum of 1 allowed: port 'Carries.PG.port_5' (sc_out) 我還嘗試了一個信號,無論有沒有作者策略SC_MANY_WRITER ,正如論壇上有人建議的那樣,但它也不起作用。

我是 SystemC 的新手,雖然我理解錯誤,但我真的不明白為什么這不起作用以及如何以不同的方式做。 那么,有沒有辦法將一個子模塊的 output 綁定到父模塊的多個sc_out上,如何?

SystemC 中的端口不是電線,而是智能指針。 與常規的 C++ 指針不同,SystemC 端口是安全的並支持分層綁定。 與常規指針類似,默認情況下,您不能將端口同時連接到 2 個通道。

雖然這對於低級建模可能不方便,但這允許將端口與任何類型的高級通道一起使用,例如 FIFO 或 TLM 通道。

看起來您需要廣播端口之類的東西:當您寫入此類端口時,應將消息寫入所有連接的通道。

要創建可以綁定到多個通道的端口,請使用 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

讓我們測試一下:

#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;
}

這並不是我們想要的:每次我們需要向廣播端口寫入內容時,我們都需要遍歷所有連接的通道。

讓我們創建一個派生的 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_);
    }
  }
};

下面是我們如何在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM