The Sparta Modeling Framework
Loading...
Searching...
No Matches
SpartaSystemCSimulator.cpp
1
4#include "sparta/simulation/ResourceTreeNode.hpp"
5#include "sparta/simulation/ResourceFactory.hpp"
6
7#include "SpartaSystemCSimulator.hpp"
8#include "sparta-target/SpartaMemory.hpp"
9#include "sparta-target/SpartaTLMTargetGasket.hpp"
10
11namespace sparta_sim
12{
14 sparta::app::Simulation("SpartaSystemCSimulator", sched),
15 sysc_sched_runner_(sched),
16 systemc_example_top_("top")
17 {
24 }
25
26 SpartaSystemCSimulator::~SpartaSystemCSimulator() {
28 }
29
39 void SpartaSystemCSimulator::buildTree_()
40 {
41 auto rtn = getRoot(); // gets the sparta "top" node
42
43 // Create a sys node for the heck of it.
44 sparta::TreeNode * sys = nullptr;
45 tns_to_delete_.emplace_back(sys = new sparta::TreeNode(rtn,
46 "sys",
49 "Dummy System"));
50
51
52
53 const auto total_targets = 2;
54 for(uint32_t i = 0; i < total_targets; ++i) {
55 // Create the Memory on the dummy system node
56 sparta::TreeNode * mem = nullptr;
57 tns_to_delete_.emplace_back
58 (mem = new sparta::ResourceTreeNode(sys,
59 sparta_target::SpartaMemory::name + std::to_string(i),
60 sparta_target::SpartaMemory::name, i,
61 "Dummy Memory",
63 getResourceFactory(sparta_target::SpartaMemory::name)));
64 // Put the gasket on the memory tree node (can really go anywhere)
65 tns_to_delete_.emplace_back(new sparta::ResourceTreeNode(mem,
66 sparta_target::SpartaTLMTargetGasket::name + std::to_string(i),
67 sparta_target::SpartaTLMTargetGasket::name, i,
68 "TLM gasket",
70 getResourceFactory(sparta_target::SpartaTLMTargetGasket::name)));
71 }
72 }
73
74 // Nothing for now...
75 void SpartaSystemCSimulator::configureTree_() {}
76
81 void SpartaSystemCSimulator::bindTree_()
82 {
83 auto root_node = getRoot();
84 sparta::bind(root_node->getChildAs<sparta::Port>("sys.memory0.ports.in_memory_request"),
85 root_node->getChildAs<sparta::Port>("sys.memory0.mem_tlm_gasket0.ports.out_memory_request"));
86 sparta::bind(root_node->getChildAs<sparta::Port>("sys.memory0.ports.out_memory_response"),
87 root_node->getChildAs<sparta::Port>("sys.memory0.mem_tlm_gasket0.ports.in_memory_response"));
88
89 sparta::bind(root_node->getChildAs<sparta::Port>("sys.memory1.ports.in_memory_request"),
90 root_node->getChildAs<sparta::Port>("sys.memory1.mem_tlm_gasket1.ports.out_memory_request"));
91 sparta::bind(root_node->getChildAs<sparta::Port>("sys.memory1.ports.out_memory_response"),
92 root_node->getChildAs<sparta::Port>("sys.memory1.mem_tlm_gasket1.ports.in_memory_response"));
93
94 auto sparta_tlm_gasket0 =
95 root_node->getChild("sys.memory0.mem_tlm_gasket0")->getResourceAs<sparta_target::SpartaTLMTargetGasket>();
96 auto sparta_tlm_gasket1 =
97 root_node->getChild("sys.memory1.mem_tlm_gasket1")->getResourceAs<sparta_target::SpartaTLMTargetGasket>();
98
99 // SysC binding
100 systemc_example_top_.m_bus.initiator_socket[0](sparta_tlm_gasket0->getMemorySocket());
101 systemc_example_top_.m_bus.initiator_socket[1](sparta_tlm_gasket1->getMemorySocket());
102 }
103}
A simple time-based, event precedence based scheduler.
Basic Node framework in sparta device tree composite pattern.
The port interface used to bind port types together and defines a port behavior.
Definition Port.hpp:59
Templated ResourceFactoryBase implementation which can be used to trivially define Resource Factories...
TreeNode subclass representing a node in the device tree which contains a single ResourceFactory and ...
void enterTeardown()
Places this tree into TREE_TEARDOWN phase so that nodes may be deleted without errors.
A class that lets you schedule events now and in the future.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
static const group_idx_type GROUP_IDX_NONE
GroupIndex indicating that a node has no group index because it belongs to no group.
Definition TreeNode.hpp:303
static constexpr char GROUP_NAME_NONE[]
Group name indicating that a node belongs to no group.
Definition TreeNode.hpp:314
const ConstT getChildAs(const std::string &name, bool must_exist=true) const
Retrieves a child that is castable to T with the given dotted path.
sparta::RootTreeNode * getRoot() noexcept
Returns the tree root.
sparta::ResourceSet * getResourceSet() noexcept
Returns the resource set for this Simulation.
SpartaSystemCSimulator(sparta::Scheduler *sched)
Construction of the SpartaSystemCSimulator.
Macros for handling exponential backoff.
void bind(Bus *p1, Bus *p2)
Bind two buses together.
Definition Bus.hpp:333