如何通过systemCtlm_fifo<float>连接两个模块?

How to connect two modules by systemC tlm_fifo<float>?

对于systemC-TLM的编写,我还是个新手。现在,我想通过 tlm_fifoFF 连接两个模块。我在网上搜索了很长时间的示例。但是没有用。请帮助提供一些想法或示例如何实现这一目标。

这是我的架构:

还有,这是我的错误信息:


这是"main.cpp"

#include <systemc.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h> 
#include "merlin2.h"

#include "tlm.h"
#include <tlm_utils/simple_target_socket.h>
#include <tlm_utils/simple_initiator_socket.h>
#include <tlm_utils/multi_passthrough_initiator_socket.h>
#include <tlm_utils/multi_passthrough_target_socket.h>
#include <tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo.h>
#include <tlm_core/tlm_1/tlm_req_rsp/tlm_1_interfaces/tlm_fifo_ifs.h>
using namespace sc_core;
using namespace tlm;
using namespace tlm_utils;
using namespace std;

int sc_main(int argc, char** argv){

    Merlin2 merlin_test("merlin2_JW");

    sc_start();
    cout << "end" << endl;
    return 0;
} 

这是"merlin2.cpp"

#include "merlin2.h"
Merlin2::Merlin2(const sc_module_name& name)
{
    ProcessEngine PE_TEST("test_PE");
    test_PE TP("PE_test");
    tlm::tlm_fifo <float> FF ("fifo");

    TP.out(FF);
    PE_TEST.in(FF);
}

这是"merlin2.h"

#ifndef __MERLIN2_H__
#define __MERLIN2_H__
#include <fstream>
#include <string>
#include <systemc.h>

#include "pe.h"
#include "test_PE.h"

class Merlin2: public sc_module 
{
    public:

        SC_HAS_PROCESS(Merlin2);
        Merlin2(const sc_module_name& name);

};

#endif

这是"pe.cpp"

#include <systemc.h>
#include <iostream>
#include "pe.h"

using namespace std;
ProcessEngine::ProcessEngine(const sc_module_name& name):in("in")
{ 
    cout << "before SC_THREAD(run)" << endl;
    SC_THREAD(run);
    cout << "after SC_THREAD(run)" << endl;
}

void ProcessEngine::run()
{   
    int N = in.nb_get();
    cout <<  " N=" << N << endl;

    wait(1,SC_NS);
}

这是"pe.h"

#ifndef __PE_H__
#define __PE_H__

#include <iostream>
#include <bitset>
#include "tlm.h"
#include <tlm_utils/simple_target_socket.h>
#include <tlm_utils/simple_initiator_socket.h>
#include <tlm_utils/multi_passthrough_initiator_socket.h>
#include <tlm_utils/multi_passthrough_target_socket.h>
#include <tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo.h>
#include <tlm_core/tlm_1/tlm_req_rsp/tlm_1_interfaces/tlm_fifo_ifs.h>
using namespace sc_core;
using namespace tlm;
using namespace tlm_utils;
using namespace std;


class ProcessEngine: public sc_module
{
    public:

        tlm::tlm_fifo<float>  in;
        void run();

        ProcessEngine(const sc_module_name& name);
        SC_HAS_PROCESS(ProcessEngine);


};

#endif

这是"test_PE.cpp"

#include <systemc.h>
#include <iostream>
#include "test_PE.h"
using namespace std;

test_PE::test_PE(const sc_module_name& name):out("out")
{ 
    cout << "before start_test " << endl;
    SC_THREAD(start_test);
    cout << "After start_test " << endl;
}

void test_PE::start_test()
{
    float A=5;
    in.nb_put(A);
    cout << "A=" << A << endl;
    wait(1,SC_NS);
}

这是"test_PE.h"

#ifndef __TESTPE_H__
#define __TESTPE_H__
#include <fstream>
#include <string>
#include <systemc.h>

#include "tlm.h"
#include <tlm_utils/simple_target_socket.h>
#include <tlm_utils/simple_initiator_socket.h>
#include <tlm_utils/multi_passthrough_initiator_socket.h>
#include <tlm_utils/multi_passthrough_target_socket.h>
#include <tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo.h>
#include <tlm_core/tlm_1/tlm_req_rsp/tlm_1_interfaces/tlm_fifo_ifs.h>

using namespace sc_core;
using namespace tlm;
using namespace tlm_utils;
using namespace std;

class test_PE:public sc_module
{
    public:
        tlm::tlm_fifo<float>  out;  
        test_PE(const sc_module_name& name);
        SC_HAS_PROCESS(test_PE);
        void start_test();
    private:
        float A;
};
#endif

您正在混合 SystemC/TLM 概念,尤其是端口和通道。

  • tlm_fifo 是一个频道。它可用于连接两个端口。这是你图片的黄色部分。

但是,您不能直接将通道连接到模块。相反,您需要在每个要连接通道的模块中使用端口。端口与您可以使用的定义方法的接口相关联。在您的情况下,您使用 nb_get(...)nb_put(...).

对于 tlm_fifo,您可以使用这些端口:

  • sc_port< tlm_nonblocking_put_if<float> >
  • sc_port< tlm_nonblocking_get_if<float> >

最后,您在 Merlin2 构造函数中创建模块的实例。 Objects 不会在构造函数结束时保留和删除。他们应该是 class 的成员。这是使用 tlm_fifo 和非阻塞接口的 TLM-​​1.0 的完整工作示例。

注意:您正在混合使用 TLM-​​2.0 和 TLM-​​1.0 headers。我删除了无用的 headers.


main.cpp

#include <systemc>
#include "merlin2.h"

using namespace sc_core;
using namespace std;

int sc_main(int argc, char** argv) {
    Merlin2 merlin_test("merlin2_JW");
    sc_start();
    cout << "end" << endl;
    return 0;
}

merlin2.h

#ifndef __MERLIN2_H__
#define __MERLIN2_H__
#include <fstream>
#include <string>
#include <systemc>

#include "pe.h"
#include "test_PE.h"

class Merlin2: public sc_module
{
public:
    Merlin2(const sc_module_name& name);
    tlm::tlm_fifo <float> FF;
    ProcessEngine PE_TEST;
    test_PE TP;
};
#endif

merlin2.cpp

#include "merlin2.h"

Merlin2::Merlin2(const sc_module_name& name):
        PE_TEST("test_PE"),
        TP("PE_test"),
        FF("fifo")
{
    TP.out(FF);
    PE_TEST.in(FF);
}

pe.h

#ifndef __PE_H__
#define __PE_H__

#include <fstream>
#include <string>
#include <systemc>
#include <tlm>

using namespace sc_core;
using namespace tlm;
using namespace std;

class ProcessEngine: public sc_module
{
public:
    sc_port< tlm_nonblocking_get_if<float> >  in;
    void run();
    ProcessEngine(const sc_module_name& name);
    SC_HAS_PROCESS(ProcessEngine);
};

#endif

pe.cpp

#include <systemc.h>
#include "pe.h"

using namespace std;

ProcessEngine::ProcessEngine(const sc_module_name& name):
        in("in")
{
    SC_THREAD(run);
}

void ProcessEngine::run()
{
    sc_core::wait(1, SC_NS);
    float N = 0;
    bool r = in->nb_get(N);
    cout <<  " N=" << N << endl;
}

test_PE.cpp

#include <systemc>
#include "test_PE.h"

using namespace std;

test_PE::test_PE(const sc_module_name& name):
        out("out")
{
    SC_THREAD(start_test);
}

void test_PE::start_test()
{
    float A=5;
    out->nb_put(A);
    cout << "A=" << A << endl;
    sc_core::wait(1, SC_NS);
}

test_PE.h

#ifndef __TESTPE_H__
#define __TESTPE_H__

#include <fstream>
#include <string>
#include <systemc>
#include <tlm>

using namespace sc_core;
using namespace tlm;
using namespace std;

class test_PE:public sc_module
{
public:
    sc_port< tlm_nonblocking_put_if<float> >  out;
    test_PE(const sc_module_name& name);
    SC_HAS_PROCESS(test_PE);
    void start_test();
private:
    float A;
};
#endif