-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_array_heterogenous.cpp
82 lines (65 loc) · 1.61 KB
/
test_array_heterogenous.cpp
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
/******************************************************************************
* Copyright (c) 2020, Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
*
*****************************************************************************/
//
// Created by mmoiseev on 06/27/19s.
//
#include <systemc.h>
// Heterogenous array of module pointers, points to individual modules
template<typename T>
struct Target : public sc_module, sc_interface
{
sc_signal<bool> r;
explicit Target (sc_module_name name) :
sc_module(name)
{}
void f(T val) {
r = val;
}
};
template<typename T>
struct AhbSlave : public sc_module, sc_interface
{
sc_in_clk clk;
sc_in<bool> nrst;
Target<T>* slaves[2];
SC_CTOR(AhbSlave) {
SC_METHOD(methProc);
sensitive << clk.pos();
}
void methProc()
{
for (int i = 0; i < 2; ++i) {
slaves[i]->f(i);
}
}
};
struct Dut : public sc_module
{
sc_in_clk clk;
sc_signal<bool> nrst;
using T = sc_uint<4>;
sc_signal<T> s;
AhbSlave<T> slave{"slave"};
Target<T> tar1{"tar1"};
Target<T> tar2{"tar2"};
SC_HAS_PROCESS(Dut);
explicit Dut (sc_module_name name) : sc_module(name)
{
slave.clk(clk);
slave.nrst(nrst);
slave.slaves[0] = &tar1;
slave.slaves[1] = &tar2;
}
};
int sc_main(int argc, char **argv)
{
Dut dut{"dut"};
sc_clock clk("clk", 1, SC_NS);
dut.clk(clk);
sc_start();
return 0;
}