-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSystem.cpp
273 lines (219 loc) · 6.8 KB
/
System.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* @ASCK
*/
#include <systemc.h>
/*
** GLOBAL EVENT FOR MICRO-ACC
*/
//////////////////////////
sc_event micro_acc_ev;///
////////////////////////
/*
** GLOBAL EVENT FOR ACC-MEMORY -> READ MODE
*/
//////////////////////////
sc_event acc_mem_read_ev;///
////////////////////////
/*
** GLOBAL EVENT FOR ACC-MEMORY -> WRITE MODE
*/
//////////////////////////
sc_event acc_mem_write_ev;///
////////////////////////
/*
** variable for checking if IF/ID/EXE/WB should have been stopped after call=1 on memory-access stage or not!
*/
bool now_is_call = false;
#include <./Micro.cpp>
#include <./Bus.cpp>
#include <./Memory.cpp>
#include <./Acc.cpp>
SC_MODULE(System)
{
sc_in_clk clk;
sc_in_clk clk_bus;
// testing wires
sc_out<sc_uint<14>> pc;
sc_out<sc_uint<5>> test_aluop;
sc_out<sc_int<8>> reg_dump[8];
/*
** module global variables
*/
//
// SIGNALS
//
// MICRO
sc_signal<sc_int<8>> micro_data_in; // input
sc_signal<bool> micro_read, micro_write, micro_call;
sc_signal<sc_uint<13>> micro_addr;
sc_signal<sc_int<8>> micro_data_out; // output
// BUS
sc_signal<bool> req;
sc_signal<bool> read_in;
sc_signal<bool> write_in;
sc_signal<bool> call_in;
sc_signal<sc_uint<13>> addr_in; // for both Mem. and Acc.
sc_signal<sc_int<8>> data_in;
//// INPUTS -up- / -down- OUTPUTS
sc_signal<bool> ack;
sc_signal<bool> read_out;
sc_signal<bool> write_out;
sc_signal<bool> call_out;
sc_signal<sc_uint<13>> addr_out; // for both Mem. and Acc.
sc_signal<sc_int<8>> data_out;
// MEMORY
sc_signal<sc_int<8>> mem_data_in, mem_data_out;
sc_signal<sc_uint<13>> mem_addr;
sc_signal<bool> r_nw;
// ACC1
sc_signal <bool> acc_call_in, acc_read, acc_write;
sc_signal <sc_uint<13>> acc_addr_out;
sc_signal <sc_int<8>> acc_data_in, acc_data_out;
//TESTING SIGNALS
sc_signal<sc_uint<5>> test_aluOp;
sc_signal<sc_uint<14>> test_pc;
sc_signal<sc_uint<20>> test_inst;
/*
** CREATE POINTER TO COMPONENTS
*/
Micro *micro;
Bus *bus;
Memory *memory;
Acc *acc;
SC_CTOR(System)
{
SC_METHOD(process);
sensitive << clk_bus.pos();
micro = new Micro("Micro");
bus = new Bus("Bus");
memory = new Memory("MEMORY");
acc = new Acc("Acc1");
micro->clk(clk);
micro->mem_data(micro_data_in);
micro->read(micro_read);
micro->write(micro_write);
micro->call(micro_call);
micro->addr(micro_addr);
micro->data(micro_data_out);
micro->test_aluOp(test_aluOp);
micro->test_pc(test_pc);
micro->test_inst(test_inst);
for (int i = 0; i < 8; i++)
{
micro->reg_dump[i](reg_dump[i]);
}
req = 1;
bus->clk(clk_bus);
bus->req(req);
bus->read(read_in);
bus->write(write_in);
bus->call(micro_call);
bus->addr(addr_in);
bus->data(data_in);
bus->ack(ack);
bus->read_out(read_out);
bus->write_out(write_out);
bus->call_out(call_out);
bus->addr_out(addr_out);
bus->data_out(data_out);
r_nw = 1;
memory->r_nw(r_nw);
memory->addr(mem_addr);
memory->data(mem_data_in);
memory->out(mem_data_out);
acc->mem_data(acc_data_in);
acc->call(acc_call_in);
acc->read(acc_read);
acc->write(acc_write);
acc->addr(acc_addr_out);
acc->data(acc_data_out);
}
int c = 0; //clk counter for printing
/*
** FLAG: if the **acc_read** of accelerator is enabled then we know that after 2 clks
** we will have the memory data on the bus data_out!
**
** BRIEF: this flag acknowledge us whether we have to notify the acc_mem_read_ev or not!
*/
int notify_flag_read = 0;
int notify_flag_write = 0;
void process()
{
// testing wires
test_aluop.write(test_aluOp.read());
pc.write(test_pc.read());
cout << "-----------------------------------------------" << endl;
cout << "\t-___ " << "bus_clk: 0X" <<c++ << " ___-" << endl << endl;
/*
** Micro - MEMORY - ACC
*/
mem_addr = addr_out.read();
mem_data_in = data_out.read();
micro_data_in = data_out.read();
acc_data_in = data_out.read();
acc_call_in = call_out.read();
if (read_out.read() || write_out.read() || call_out.read()){
if (read_out.read()){
r_nw = read_out.read();
data_in = mem_data_out.read();
}
else if (write_out.read()){
r_nw = !(write_out.read());
}
}
////////////////////////HANDLE ACC READ/WRITE////////////////////////
if (notify_flag_write !=0 && notify_flag_write < 3){
// increment the flag to get to the intended clk count
notify_flag_write++;
return;
}
else if (notify_flag_write == 3){
// the write operation should have been done
notify_flag_write = 0;
acc_mem_write_ev.notify();
return;
}
if (notify_flag_read !=0 && notify_flag_read < 4){
// increment the flag to get to the intended clk count
notify_flag_read++;
return;
}
else if (notify_flag_read == 4){
// should we notify accelerator event? (two clocks have passed)
notify_flag_read = 0;
acc_mem_read_ev.notify();
return;
}
///////////////////////////////////////////////////////////////////MICRO
if (micro_read.read() || micro_write.read() || micro_call.read())
{
read_in = micro_read.read();
write_in = micro_write.read();
call_in = micro_call.read();
if (micro_read.read()){
addr_in = micro_addr.read();
}
else if (micro_write.read()){
data_in = micro_data_out.read();
addr_in = micro_addr.read();
}
}
///////////////////////////////////////////////////////////////////ACC
if (acc_read.read() || acc_write.read())
{
read_in = acc_read.read();
write_in = acc_write.read();
if (acc_read.read()){
// increment accelerator notify_flag_read
notify_flag_read++;
addr_in = acc_addr_out.read();
}
else if (acc_write.read()){
// increment accelerator notify_flag_write
notify_flag_write++;
data_in = acc_data_out.read();
addr_in = acc_addr_out.read();
}
}
}
};