|
|
|
|
|
|
|
|
|
|
|
|
Example : scv_user_defined class
|
|
|
|
|
|
1 #include <scv.h>
2
3 class packet_t {
4 public :
5 sc_uint<8> addr;
6 sc_uint<12> data;
7 };
8
9 SCV_EXTENSIONS(packet_t) {
10 public:
11 scv_extensions< sc_uint<8> > addr;
12 scv_extensions< sc_uint<12> > data;
13 SCV_EXTENSIONS_CTOR(packet_t) {
14 SCV_FIELD(addr);
15 SCV_FIELD(data);
16 }
17 };
18
19 int sc_main (int argc, char* argv[]) {
20 packet_t pkt;
21 pkt.addr = rand();
22 pkt.data = rand();
23 int bitwidth = scv_get_extensions(pkt.addr).get_bitwidth();
24 cout << "Width of addr is "<< bitwidth << endl;
25 bitwidth = scv_get_extensions(pkt.data).get_bitwidth();
26 cout << "Width of data is "<< bitwidth << endl;
27 scv_get_extensions(pkt).print();
28 return 0;
29 }
You could download file scv_user_defined_class.cpp here
|
|
|
|
|
|
|
|
|
|
|
|
Simulation Output : scv_user_defined class
|
|
|
|
|
|
Width of addr is 8
Width of data is 12
{
addr:103
data:966
}
|
|
|
|
|
|
Example : scv_user_defined Enums
|
|
|
|
|
|
1 #include <scv.h>
2
3 //enum for one hot coding
4 enum onehot_t {
5 STATE_0 = 0, STATE_1 = 1, STATE_2 = 2, STATE_3 = 4,
6 STATE_4 = 8, STATE_5 = 16, STATE_6 = 32 };
7
8 struct data_t {
9 sc_uint<8> field;
10 unsigned payload[5];
11 onehot_t state;
12 };
13
14 template<>
15 class scv_extensions<onehot_t> : public scv_enum_base<onehot_t> {
16 public:
17 SCV_ENUM_CTOR(onehot_t) {
18 SCV_ENUM(STATE_0);
19 SCV_ENUM(STATE_1);
20 SCV_ENUM(STATE_2);
21 SCV_ENUM(STATE_3);
22 SCV_ENUM(STATE_4);
23 SCV_ENUM(STATE_5);
24 SCV_ENUM(STATE_6);
25 }
26 };
27
28 template<>
29 class scv_extensions<data_t> : public scv_extensions_base<data_t> {
30 public:
31 scv_extensions<sc_uint<8> > field;
32 scv_extensions<unsigned [5]> payload;
33 scv_extensions<onehot_t > state;
34 SCV_EXTENSIONS_CTOR(data_t) {
35 //must be in order
36 SCV_FIELD(field);
37 SCV_FIELD(payload);
38 SCV_FIELD(state);
39 }
40 };
41
42 int sc_main (int argc, char* argv[]) {
43 data_t data;
44 data.field = rand();
45 for (int i=0; i<5; i++) {
46 data.payload[i] = rand();
47 }
48 data.state = STATE_0;
49 scv_get_extensions(data).print();
50 return 0;
51 }
You could download file scv_user_defined_enum.cpp here
|
|
|
|
|
|
Simulation Output : scv_user_defined Enums
|
|
|
|
|
|
{
field:103
payload {
[0]:846930886
[1]:1681692777
[2]:1714636915
[3]:1957747793
[4]:424238335
}
state:STATE_0
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|