Verification Using SystemC Part V

In

Dynamic Extension

A dynamic extension is used when auxiliary data needs to be associated with the data object, such as a constraint or a callback function pointer. This is accomplished via the scv_smart_ptr template in the Verification Standard. 

For example, the following code generates a random value for an integer and register a callback.

The scv_shared_ptr template enables sharing of data objects among multiple C++ threads by performing automatic memory management. The scv_smart_ptr template combines scv_shared_ptr and scv_extensions to attach auxiliary data to a data object. The scv_smart_ptr subsumes the functionality in scv_shared_ptr, but scv_smart_ptr is more costly in both memory space and performance, so it should be used only when dynamic extensions are needed.
Example : scv_smart_ptr

  1 #include

  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 void do_something (scv_smart_ptr p) {

 20   cout << "address : " << p->addr << endl;

 21   cout << "data : " << p->data << endl;

 22   if (p->data == 0) {

 23     p-> data = rand();

 24   }

 25   if (p-> addr == 0) {

 26     p-> addr = rand();

 27   }

 28   cout << "The whole packet : " << endl;

 29   p->print();

 30 };

 31

 32 int sc_main (int argc, char* argv[]) {

 33   scv_smart_ptr pkt_p("packet");

 34   do_something(pkt_p);

 35   return 0;

 36 }

Simulation Output : scv_smart_ptr
 address : 0

 data : 0

 The whole packet :

 {

   addr:54

   data:502

 }

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

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

 

Lần cập nhật cuối ( Thứ ba, 29 Tháng 3 2022 00:43 )