2017-09-09 61 views
1

我仍然是編寫systemC-TLM的新手。現在,我想通過tlm_fifoFF連接兩個模塊。我在網上搜索很長一段時間的例子。但沒用。請幫助給出一些想法或例子如何實現這一點。如何通過systemC連接兩個模塊tlm_fifo <float>?

這是我的架構:

enter image description here

和,這是我的錯誤信息:

enter image description here


這是 「的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 

+0

提高您的格式和嵌入式圖像 –

回答

2

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

  • tlm_fifo是一個頻道。它可以用來連接兩個端口。這是你圖片的黃色部分。

但是,您不能直接將通道連接到模塊。相反,您需要使用每個模塊中要連接通道的端口。端口與定義您可以使用的方法的接口相關聯。在你的情況下,你使用nb_get(...)nb_put(...)

tlm_fifo,您可以使用這些端口:

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

TLM-1.0 example

最後,你在你的Merlin2構造函數創建模塊實例。對象不會在構造函數結束時被持久化和刪除。他們應該是班上的成員。這裏是使用tlm_fifo和非阻塞接口的TLM-1.0的完整工作示例。

注意:您正在混合TLM-2.0和TLM-1.0標頭。我刪除了無用的標題。


的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 
+0

紀堯姆,非常感謝!!!! !!!!我非常愛你!它可以在我的服務器上工作:),我得到了什麼錯誤。 順便說一下,有沒有一種方法使用TLM2.0(啓動套接字,目標套接字)來激發FIFO行爲,如我的merlin2圖片? JW –

+1

TLM-​​2.0在概念上有所不同。 TLM-1.0通信基於FIFO,而TLM-2.0通信則基於套接字和傳輸調用。您可以使用TLM-2.0在test_PE和PE之間添加一個FIFO模塊來模擬FIFO。你會有類似test_PE(發起者套接字)<--->(目標套接字)FIFO(發起者套接字)<---->(目標套接字)PE – Guillaume

+0

感謝您的詳細解釋!我明白了!祝你有美好的一天〜 –

相關問題