-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.cpp
More file actions
62 lines (51 loc) · 1.58 KB
/
Copy pathmemory.cpp
File metadata and controls
62 lines (51 loc) · 1.58 KB
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
#include <systemc.h>
#ifndef MEMORY
#define MEMORY
#define ADDR_WIDTH 4 // in bits
#define MEM_SIZE (1 << ADDR_WIDTH) // in words
#define WORD_WIDTH 4 // in bits
SC_MODULE(Memory)
{
sc_in_clk read_clock;
sc_in_clk write_clock;
sc_in<bool> reset;
sc_in<bool> write_enable;
sc_in<sc_uint<ADDR_WIDTH>> address_read;
sc_in<sc_uint<ADDR_WIDTH>> address_write;
sc_in<sc_uint<WORD_WIDTH>> data_in;
sc_out<sc_uint<WORD_WIDTH>> data_out;
sc_uint<WORD_WIDTH> data[MEM_SIZE];
void read()
{
if (reset.read() == 1)
{
cout << sc_time_stamp() << " | RESETTING MEMORY\n";
for (int i = 0; i < MEM_SIZE; i++)
{
data[i] = 0;
data_out.write(0);
}
}
else if (read_clock.read() == 1 && write_enable.read() == 0)
{
cout << sc_time_stamp() << " | READING FROM MEMORY value: " << data[address_read.read()] << " at location " << address_read.read() << endl;
data_out.write(data[address_read.read()]);
}
}
void write()
{
if (write_clock.read() == 1 && write_enable.read() == 1)
{
cout << sc_time_stamp() << " | WRITING TO MEMORY value: " << data_in.read() << " at location " << address_write.read() << endl;
data[address_write.read()] = data_in.read();
}
}
SC_CTOR(Memory)
{
SC_METHOD(read);
sensitive << reset.pos() << read_clock.pos();
SC_METHOD(write);
sensitive << write_clock.pos();
}
};
#endif