简体   繁体   English

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

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

I am still a novice for writing systemC-TLM.我还是写systemC-TLM的新手。 Now, I want to connect two modules by tlm_fifoFF.现在,我想通过 tlm_fifoFF 连接两个模块。 I am searching examples for a long time on net.我在网上搜索了很长时间的例子。 But no use.但是没有用。 Please help to give some ideas or examples how to achieve this.请帮助提供一些想法或示例如何实现这一点。

This is my architecture:这是我的架构:

在此处输入图片说明

and,this is my error information:而且,这是我的错误信息:

在此处输入图片说明


this is "main.cpp"这是“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;
} 

this is "merlin2.cpp"这是“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);
}

this is "merlin2.h"这是“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

this is "pe.cpp"这是“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);
}

this is "pe.h"这是“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

this is "test_PE.cpp"这是“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);
}

this is "test_PE.h"这是“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

You're mixing SystemC/TLM notions and especially ports and channels.您正在混合 SystemC/TLM 概念,尤其是端口和通道。

  • tlm_fifo is a channel. tlm_fifo是一个通道。 It can be used to connect two ports.它可用于连接两个端口。 It's the yellow part of your image.这是你图片的黄色部分。

However, you can't directly connect a channel to a module.但是,您不能将通道直接连接到模块。 Instead, you need to use ports in each module you want to connect the channel.相反,您需要在要连接通道的每个模块中使用端口。 A port is associated to an interface defining methods you can use.端口与定义您可以使用的方法的接口相关联。 In your case, you use nb_get(...) and nb_put(...) .在您的情况下,您使用nb_get(...)nb_put(...)

For tlm_fifo , you can use these ports:对于tlm_fifo ,您可以使用以下端口:

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

TLM-1.0 示例

Finally, you create instances of your modules in your Merlin2 constructor.最后,在Merlin2构造函数中创建模块的实例。 Objects are not persisted and deleted at the end of the constructor.对象不会在构造函数结束时持久化和删除。 They should be member of the class.他们应该是班级的成员。 Here is a complete working example of TLM-1.0 using tlm_fifo with non blocking interface.这是使用tlm_fifo和非阻塞接口的 TLM-​​1.0 的完整工作示例。

Note: You're mixing TLM-2.0 and TLM-1.0 headers.注意:您正在混合 TLM-​​2.0 和 TLM-​​1.0 标头。 I removed useless 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梅林2.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梅林2.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 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 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 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 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

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

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