简体   繁体   English

SystemC端口转换

[英]SystemC Port Conversion

I am trying to convert one type of SystemC port into another: 我正在尝试将一种类型的SystemC端口转换为另一种类型:

from: 从:

sc_port<sc_fifo_out_if<Type> > 

to: 至:

sc_export<tlm::tlm_analysis_if<Type> > 

I used this class with a thread to convert between the types. 我使用带有线程的此类在类型之间进行转换。

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 解决方案图

Is there a simpler way to convert between these types of ports? 有没有在这些类型的端口之间转换的更简单方法?

Interfaces sc_fifo_out_if and tlm_analysis_if are not fully compatible. 接口sc_fifo_out_iftlm_analysis_if不完全兼容。 So here is probably the best you can get. 因此,这可能是您可以获得的最佳选择。 Simulation will stop with an error if someone will try to use incompatible method. 如果有人尝试使用不兼容的方法,则模拟将因错误而停止。

Update: I'm not sure if tlm_analysis_if guarantees non-blocking operation. 更新:我不确定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;
};

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

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