
Array Of Ports/Signals
SystemC allows to declare Array of ports and signals. This is very useful when we need to create array of similar ports and signals.
Below examples shows how to use of array of ports and signals.
Example : Array Of Ports/Signals
1 #include
2
3 SC_MODULE(ports_arrays) {
4 sc_in<sc_uint<2> > a[4];
5 sc_in<sc_uint<2> > b[4];
6 sc_out<sc_uint<3> > o[4];
7
8 void body () {
9 int i;
10 for (i=0; i < 4; i ++) {
11 o[i].write(a[i].read() + b[i].read());
12 }
13 }
14
15 SC_CTOR(ports_arrays) {
16 int j;
17 SC_METHOD(body);
18 for (j=0; j<4; j++) {
19 sensitive << a[j] << b[j];
20 }
21 }
22 };
23
24 // Testbench to generate test vectors
25 int sc_main (int argc, char* argv[]) {
26 sc_signal<sc_uint<2> > a[4];
27 sc_signal<sc_uint<2> > b[4];
28 sc_signal<sc_uint<3> > o[4];
29
30 int z;
31
32 ports_arrays prt_ar("PORT_ARRAY");
33 for (z=0; z<4; z++) {
34 prt_ar.a[z](a[z]);
35 prt_ar.b[z](b[z]);
36 prt_ar.o[z](o[z]);
37 }
38 sc_start(0);
39 // Open VCD file
40 sc_trace_file *wf = sc_create_vcd_trace_file("ports_arrays");
41 ((vcd_trace_file*)wf)->sc_set_vcd_time_unit(-5);
42 for (z=0; z<4; z++) {
43 char str[3];
44 sprintf(str, "(%0d)",z);
45 sc_trace(wf,a[z],"a" + string(str));
46 sc_trace(wf,b[z],"b" + string(str));
47 sc_trace(wf,o[z],"o" + string(str));
48 }
49 // Start the testing here
50 sc_start(1);
51 for (z=0; z<4; z++) {
52 a[z] = rand();
53 b[z] = rand();
54 sc_start(1);
55 cout << "@" << sc_time_stamp() <<" a : " << a[z]
56 << " ,b : " << b[z] << " ,o : " << o[z] << endl;
57 }
58 sc_start(2);
59
60 sc_close_vcd_trace_file(wf);
61 return 0;// Terminate simulation
62 }
Simulation Output : Array Of Ports/Signals
SystemC 2.0.1 --- Oct 6 2006 19:17:37
Copyright (c) 1996-2002 by all Contributors
ALL RIGHTS RESERVED
WARNING: Default time step is used for VCD tracing.
@2 ns a : 3 ,b : 2 ,o : 5
@3 ns a : 1 ,b : 3 ,o : 4
@4 ns a : 1 ,b : 3 ,o : 4
@5 ns a : 2 ,b : 0 ,o : 2
Bạn Có Đam Mê Với Vi Mạch hay Nhúng - Bạn Muốn Trau Dồi Thêm Kĩ Năng
Mong Muốn Có Thêm Cơ Hội Trong Công Việc
Và Trở Thành Một Người Có Giá Trị Hơn