-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_cthread_mif.cpp
104 lines (85 loc) · 1.97 KB
/
test_cthread_mif.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/******************************************************************************
* Copyright (c) 2020, Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
*
*****************************************************************************/
//
// Created by htrampur on 07/19/19
//
#include <systemc.h>
// Tests for combinational variables in MIF threads
struct A: public sc_module, sc_interface
{
sc_in_clk clk;
sc_signal<bool> rst;
sc_signal<sc_uint<4>> s {"s"};
sc_signal<sc_uint<4>> ss {"ss"};
sc_uint<4> v;
sc_uint<4> vv;
SC_CTOR(A)
{
SC_CTHREAD(thread1, clk.pos());
async_reset_signal_is(rst, 1);
SC_CTHREAD(thread2, clk.pos());
async_reset_signal_is(rst, 1);
}
// Thread with combinational variable
sc_signal<int> t0;
void thread1()
{
s = 1;
v = 2;
wait();
while (true) {
v = 3;
s = 4;
auto a = v + s.read();
t0 = a;
wait();
}
}
sc_signal<int> t1;
void thread2()
{
wait();
while (true) {
auto a = ss.read();
t1 = a;
wait();
}
}
};
struct Dut : public sc_module
{
sc_in_clk clk;
sc_signal<bool> rst;
A* a2;
SC_CTOR(Dut)
{
a2 = new A("a2");
a2->clk(clk);
SC_CTHREAD(top_thread, clk.pos());
async_reset_signal_is(rst, 1);
}
void top_thread()
{
a2->ss = 1;
a2->vv = 2;
wait();
while (true) {
a2->ss = 3;
a2->vv = 4;
auto b = a2->vv + a2->ss.read();
wait();
}
}
};
int sc_main(int argc, char **argv)
{
Dut dut{"dut"};
sc_clock clk("clk", 1, SC_NS);
dut.clk(clk);
sc_start();
return 0;
}