-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsimplex_AMBA3.cpp
136 lines (94 loc) · 2.59 KB
/
simplex_AMBA3.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
#include "systemc.h"
#include "iostream"
#define CLOCK_PULSE 2 //In nano Seconds
using namespace std;
class HCLK:public sc_module{
private:
int w;
public:
sc_signal<sc_bit> clk;
SC_HAS_PROCESS(HCLK);
HCLK(sc_module_name name,int v):sc_module(name),w(v){
clk=sc_bit('1');
SC_THREAD(start_clk);
}
void start_clk(){
for(int i=0;i<10;i++){
cout<<" # "<<sc_time_stamp()<<" Clock Pulse: "<<false<<endl;
clk=sc_bit('0');
wait(w,SC_NS);
clk=sc_bit('1');
cout<<" # "<<sc_time_stamp()<<" Clock Pulse: "<<true<<endl;
wait(w,SC_NS);
}
}
};
HCLK t("C",CLOCK_PULSE);
class master:public sc_module{
public:
sc_port<sc_fifo_out_if<sc_uint<32> > > send_list;
sc_signal<sc_bit> hwrite; //high -- write to slave; //low -- read from slave
int r_val; //random value to be written
SC_HAS_PROCESS(master);
master(sc_module_name name):sc_module(name){
SC_THREAD(writer_function);
}
void writer_function(){
wait(CLOCK_PULSE,SC_NS);
for(int i=0;i<5;i++){
if(t.clk==sc_bit('0'))
{
cout<<" # Random value written at: "<<sc_time_stamp()<<endl;
cout<<" # Value: "<<r_val<<"\n\n";
r_val=rand()%1024;
send_list->write(r_val);
wait(CLOCK_PULSE,SC_NS);
}
}
}
};
class slave:public sc_module{
public:
sc_port<sc_fifo_in_if<sc_uint<32> > > reciever_list;
int r_val;
SC_HAS_PROCESS(slave);
slave(sc_module_name name):sc_module(name){
SC_THREAD(reader_function);
}
void reader_function()
{
wait(CLOCK_PULSE,SC_NS);
for(int i=0;i<5;i++){
if(t.clk==sc_bit('0'))
{
wait(CLOCK_PULSE,SC_NS);
int temp=reciever_list->read();
cout<<" @ Value Read From Master at: "<<sc_time_stamp()<<endl;
cout<<" @ Value: "<<temp<<endl<<endl;
}
}
}
};
class top : public sc_module
{
public:
sc_fifo <sc_uint<32> > *fifo_inst;
master *m;
slave *s;
top(sc_module_name name) : sc_module(name)
{
fifo_inst = new sc_fifo<sc_uint<32> >(100);
m = new master("Master");
m->send_list(*fifo_inst);
s = new slave("Slave1");
s->reciever_list(*fifo_inst);
}
};
int sc_main (int argc , char *argv[])
{
//sc_clock clock ("my_clock",10,0.5);
//setting clock frequency to 10 Ns.
top t1("Main");
sc_start(); //starting the functions
return 0; //terminate code
}