2017-01-30 49 views
0

我想要一個類型的SystemC端口轉換成另:SystemC的端口變換

來自:

sc_port<sc_fifo_out_if<Type> > 

到:

sc_export<tlm::tlm_analysis_if<Type> > 

我用這個類線程轉換類型之間。

class port_converter : public sc_core::sc_module{ 
public: 
    sc_port<sc_fifo_in_if<Type> > in_converter; 
    sc_port<tlm::tlm_analysis_if<Type> > out_converter; 

    // c'tor 
    SC_HAS_PROCESS(port_converter); 
    port_converter(sc_module_name nm) : 
     sc_module(nm), in_converter("in"), out_converter("out") { 
     SC_THREAD(main_action); 
    } 

    // main action 
    void main_action() { 
     while (1){ 
      out_converter->write(in_converter->read()); 
     } 
    } 
}; 

The solution diagram

有沒有更簡單到這些類型的端口之間進行轉換的方式?

回答

0

接口sc_fifo_out_if和tlm_analysis_if不完全兼容。所以這裏可能是你能得到的最好的。如果有人嘗試使用不兼容的方法,模擬將停止並顯示錯誤。

更新:我不確定tlm_analysis_if是否保證非阻塞操作。

template <typename T> 
struct my_converter : sc_fifo_out_if<T>, sc_core::sc_module { 

    sc_export<sc_fifo_out_if<T>>   in{"in"}; 
    sc_port<tlm::tlm_analysis_if<T>>  out{"out"}; 

    my_converter(sc_core::sc_module_name){ 
     in.bind(*this); 
    } 

    bool nb_write(const T &t) override { 
     out->write(t); 
    } 

    const sc_event &data_read_event() const override { 
     SC_REPORT_ERROR("my_converter", "data_read_event not supported!!"); 
     return m_data_read_event; 
    } 

    void write(const T &t) override { 
     nb_write(t); 
    } 

    int num_free() const override { 
     SC_REPORT_ERROR("my_converter", "num_free not supported!!"); 
     return 1; 
    } 

private: 
    sc_event m_data_read_event; // this even will never happen; 
};