标签:info ast lang ini emc exit transport art 基础上
了解TLM程序的基本过程。TLM的英文全称是Transaction Level Modeling,中文翻译为事务级建模。它是在SystemC基础上的一个扩展库。
模块A向模块B发送一个“Hello”字符串
systemc.h
#include "systemc.h"
class A : public sc_module { public: SC_HAS_PROCESS(A); A(sc_module_name name) : sc_module(name) { } }
class B : public sc_module { public: SC_HAS_PROCESS(B); B(sc_module_name name) : sc_module(name) { } }
#include "tlm.h" #include "tlm_utils/simple_initiator_socket.h"
public: tlm_utils::simple_initiator_socket<A> socket;
public: tlm_utils::simple_target_socket<B> socket;
int sc_main(int argc, char* argv[]) { A a("A"); // 实例化模块A B b("B"); // 实例化模块B a.socket(b.socket); // 连接模块A和B sc_start(10, SC_NS); // 仿真运行10纳秒 return 0; }
在类A
的构造方法中注册一个用来发送数据的方法hello
A(sc_module_name name) : sc_module(name) {
SC_THREAD(hello);
}
在类A
中创建发送数据的方法hello
void hello() { tlm::tlm_generic_payload *payload = new tlm::tlm_generic_payload(); assert(payload != nullptr); const char *data{"Hello"}; payload->set_data_ptr((unsigned char *) data); sc_time delay = SC_ZERO_TIME; socket->b_transport(*payload, delay); delete payload; }
在类B
的构造方法中注册一个用来接收数据的方法hello
B(sc_module_name name) : sc_module(name) { socket.register_b_transport(this, &B::hello); }
在类B
中创建接收数据的方法hello
void hello(tlm::tlm_generic_payload &payload, sc_core::sc_time &delay_time) { const char *data = reinterpret_cast<const char *>(payload.get_data_ptr()); std::cout << data << std::endl; }
SystemC 2.3.3-Accellera --- Sep 20 2019 16:02:02 Copyright (c) 1996-2018 by all Contributors, ALL RIGHTS RESERVED Hello Process finished with exit code 0
#include "systemc.h" #include "tlm.h" #include "tlm_utils/simple_initiator_socket.h" #include "tlm_utils/simple_target_socket.h" class A : public sc_module { public: SC_HAS_PROCESS(A); A(sc_module_name name) : sc_module(name) { SC_THREAD(hello); } public: tlm_utils::simple_initiator_socket<A> socket; private: void hello() { auto *payload = new tlm::tlm_generic_payload(); assert(payload != nullptr); const char *data{"Hello"}; payload->set_data_ptr((unsigned char *) data); sc_time delay = SC_ZERO_TIME; socket->b_transport(*payload, delay); delete payload; } }; class B : public sc_module { public: SC_HAS_PROCESS(B); B(sc_module_name name) : sc_module(name) { socket.register_b_transport(this, &B::hello); } public: tlm_utils::simple_target_socket<B> socket; private: void hello(tlm::tlm_generic_payload &payload, sc_core::sc_time &delay_time) { const char *data = reinterpret_cast<const char *>(payload.get_data_ptr()); std::cout << data << std::endl; } }; int sc_main(int argc, char* argv[]) { A a("A"); B b("B"); a.socket(b.socket); sc_start(10, SC_NS); return EXIT_SUCCESS; }
标签:info ast lang ini emc exit transport art 基础上
原文地址:https://www.cnblogs.com/cngpus/p/13175947.html