Skip to content

Commit dc95d86

Browse files
committed
add a systemc subfolder and 1by2 binary to decimal decoder example, remove some unecessary files, edit readme
1 parent 028a5b8 commit dc95d86

12 files changed

+177
-7
lines changed

Makefile

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CXX = g++
22

3-
all:calc tempcalc clock
3+
all:calc tempcalc clock hello
44
clock:clock.cc
55
@echo 'Building file: $(@F)'
66
$(CXX) $< -o $@
@@ -10,11 +10,10 @@ calc:calc.cc
1010
tempcalc:tempcalc.cc
1111
@echo 'Building file: $(@F)'
1212
$(CXX) $< -o $@
13-
hello:hello.cc
14-
@echo 'building file: $(@F)'
15-
$(CXX) -I/usr/local/systemc-2.3.0/include -O0 -g3 -Wall -c hello.cc
16-
$(CXX) -L/usr/local/systemc-2.3.0/lib-linux64 -o "hello" hello.o -lsystemc
13+
systemc:
14+
cd systemc; $(MAKE)
1715
cleanclock:
1816
rm -f clock.o clock
1917
clean:
2018
rm -f *.out *.o calc tempcalc clock
19+
.PHONY: systemc

README

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
These are c++ examples I use while teaching basics of systemC
1+
These are c++ examples I use while teaching basics of systemC. they include use of classes, templates and features like inheritance. I have included a basic decoder example and some examples found in systemc books as a start. I intend to grow these into a set of systemc starting point examples showing how different features of the library may be used. Feel free to fork, add examples and contribute back.

module.h

Whitespace-only changes.

systemc/Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
all: hello decoder
3+
4+
hello:hello.cc
5+
@echo 'building file: $(@F)'
6+
$(CXX) -I/usr/local/systemc-2.3.0/include -O0 -g3 -Wall -c hello.cc
7+
$(CXX) -L/usr/local/systemc-2.3.0/lib-linux64 -o "hello" hello.o -lsystemc
8+
./hello
9+
decoder:decoder.cc
10+
@echo 'building file $(@F)'
11+
$(CXX) -I/usr/local/systemc-2.3.0/include -O0 -g3 -Wall -c decoder.cc
12+
$(CXX) -L/usr/local/systemc-2.3.0/lib-linux64 -o "decoder" decoder.o -lsystemc
13+
./decoder
14+
gtkwave timing_diagram.vcd
15+
.PHONY: decoder

systemc/decoder.cc

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include"decoder.h"
2+
#include"driver.h"
3+
#include"monitor.h"
4+
#include<systemc>
5+
6+
int sc_main(int argc, char *argv[]){
7+
//some signals for interconnections
8+
sc_signal<bool> in, out1, out2;
9+
//module instances
10+
decoder dec("decoder_instance");
11+
driver dr("driver");
12+
monitor mn("monitor");
13+
//interconnections b2in modules
14+
dr.d_a(in);
15+
dec.a(in);
16+
mn.m_a(in);
17+
18+
dec.b(out1);
19+
mn.m_b(out1);
20+
21+
dec.c(out2);
22+
mn.m_c(out2);
23+
24+
//create a trace file with nanosecond resolution
25+
sc_trace_file *tf;
26+
tf = sc_create_vcd_trace_file("timing_diagram");
27+
tf->set_time_unit(1, SC_NS);
28+
//trace the signals interconnecting modules
29+
sc_trace(tf, in, "binary_input"); // signals to be traced
30+
sc_trace(tf, out1, "input_is_zero");
31+
sc_trace(tf, out2, "input_is_one");
32+
33+
//run a simulation for 20 systemc nano-seconds
34+
if( !sc_pending_activity() )
35+
sc_start(25,SC_NS);
36+
//close the trace file
37+
sc_close_vcd_trace_file(tf);
38+
return 0;
39+
}

systemc/decoder.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include<systemc.h>
2+
3+
SC_MODULE(decoder){
4+
//input and output ports
5+
sc_in<bool> a;
6+
sc_out<bool> b,c;
7+
//constructor: where the processes are bound to simulation kernel
8+
SC_CTOR(decoder){
9+
SC_METHOD(decode);
10+
sensitive<<a;
11+
//dont_initialize();
12+
}
13+
14+
~decoder(){
15+
//delete stuff :P
16+
}
17+
18+
void decode(void){
19+
b=(a==0)?1:0;
20+
c=(a==1)?1:0;
21+
}
22+
};

systemc/driver.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef DRIVER_H_
2+
#define DRIVER_H_
3+
4+
#include<systemc>
5+
6+
SC_MODULE(driver){
7+
sc_out<bool> d_a;
8+
9+
SC_CTOR(driver){
10+
SC_THREAD(drive);
11+
}
12+
13+
void drive(void){
14+
while(1){
15+
d_a=0;
16+
wait(5,SC_NS);
17+
d_a=1;
18+
wait(5,SC_NS);
19+
}
20+
}
21+
};
22+
23+
#endif

hello.cc systemc/hello.cc

File renamed without changes.

hello.h systemc/hello.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SC_CTOR(test){
88
// sensitive<<a;
99
}
1010
void testing(void){
11-
SC_REPORT_INFO(SC_INFO,"Hello SystemC World!");
11+
SC_REPORT_INFO(1,"Hello SystemC World!");
1212
}
1313
~test(){
1414
//delete stuff

systemc/monitor.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef MONITOR_H_
2+
#define MONITOR_H_
3+
4+
#include<iostream>
5+
#include<systemc>
6+
7+
using namespace std;
8+
9+
SC_MODULE(monitor){
10+
sc_in<bool> m_a, m_b,m_c;
11+
12+
SC_CTOR(monitor){
13+
SC_METHOD(monita);
14+
sensitive<<m_b<<m_c;
15+
dont_initialize();
16+
}
17+
18+
void monita(void){
19+
cout<<"at "<<sc_time_stamp()<<" input is: "<<m_a<<" outputs are: "<<m_b<<" and "<<m_c<<endl;
20+
}
21+
};
22+
23+
#endif

systemc/timing_diagram.vcd

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
$date
2+
Nov 21, 2014 00:10:23
3+
$end
4+
5+
$version
6+
SystemC 2.3.0_pub_rev_20111121-OSCI --- Oct 29 2014 22:58:28
7+
$end
8+
9+
$timescale
10+
1 ns
11+
$end
12+
13+
$scope module SystemC $end
14+
$var wire 1 aaa binary_input $end
15+
$var wire 1 aab input_is_zero $end
16+
$var wire 1 aac input_is_one $end
17+
$upscope $end
18+
$enddefinitions $end
19+
20+
$comment
21+
All initial values are dumped below at time 0 sec = 0 timescale units.
22+
$end
23+
24+
$dumpvars
25+
0aaa
26+
1aab
27+
0aac
28+
$end
29+
30+
#5
31+
1aaa
32+
0aab
33+
1aac
34+
35+
#10
36+
0aaa
37+
1aab
38+
0aac
39+
40+
#15
41+
1aaa
42+
0aab
43+
1aac
44+
45+
#20
46+
0aaa
47+
1aab
48+
0aac
49+

systemc/traces.png

44.5 KB
Loading

0 commit comments

Comments
 (0)