1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#include "models/lt_bus.h"
#include "utils/log.h"
#include <tlm_utils/simple_initiator_socket.h>
#include <tlm_utils/simple_target_socket.h>
// -- TARGET -------------------------------------------------------------------
struct target : public sc_core::sc_module {
explicit target(sc_core::sc_module_name nm) : sc_module(std::move(nm)) {
p_sock.register_b_transport(this, &target::b_transport);
}
tlm_utils::simple_target_socket<target> p_sock{"sock"};
private:
void b_transport(tlm::tlm_generic_payload& tx, sc_core::sc_time& t) {
LOGM("transport 0x%llx w: %d r: %d", tx.get_address(), tx.is_write(),
tx.is_read());
tx.set_response_status(tlm::TLM_OK_RESPONSE);
}
};
// -- INITIATOR ----------------------------------------------------------------
struct initiator : public sc_core::sc_module {
SC_HAS_PROCESS(initiator);
explicit initiator(sc_core::sc_module_name nm) : sc_module(std::move(nm)) {
SC_THREAD(run);
}
tlm_utils::simple_initiator_socket<initiator> p_sock{"sock"};
private:
void send_tx(tlm::tlm_command cmd, std::uint64_t addr) {
unsigned char data[4];
tlm::tlm_generic_payload tx;
tx.set_command(cmd);
tx.set_address(addr);
tx.set_data_ptr(data);
tx.set_data_length(sizeof(data));
tx.set_byte_enable_ptr(nullptr);
tx.set_byte_enable_length(0);
tx.set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
tx.set_dmi_allowed(false);
sc_core::sc_time t;
p_sock->b_transport(tx, t);
LOGM("ACCESS @%lx ok: %d (%s)", addr, tx.is_response_ok(),
tx.get_response_string().c_str());
}
void run() {
send_tx(tlm::TLM_WRITE_COMMAND, 0x1000);
send_tx(tlm::TLM_WRITE_COMMAND, 0x3000);
send_tx(tlm::TLM_WRITE_COMMAND, 0x4000);
send_tx(tlm::TLM_WRITE_COMMAND, 0x9000);
send_tx(tlm::TLM_WRITE_COMMAND, 0x80fc);
send_tx(tlm::TLM_WRITE_COMMAND, 0x80fd);
}
};
// -- SC_MAIN ------------------------------------------------------------------
extern "C" int sc_main(int, char*[]) {
lt_bus bus{"bus"};
target target1{"target1"};
target target2{"target2"};
target target3{"target3"};
initiator init1{"init1"};
bus.attach_target(target2.p_sock, 0x4000, 0x4fff);
bus.attach_target(target1.p_sock, 0x0000, 0x3fff);
bus.attach_target(target3.p_sock, 0x8000, 0x80ff);
bus.attach_initiator(init1.p_sock);
sc_core::sc_start();
return 0;
}
|