Trung tâm đào tạo thiết kế vi mạch Semicon


  • ĐĂNG KÝ TÀI KHOẢN ĐỂ TRUY CẬP NHIỀU TÀI LIỆU HƠN!
  • Đăng ký
    *
    *
    *
    *
    *
    Fields marked with an asterisk (*) are required.
semicon_lab.jpg

Structs And Units Part-I

Email In PDF.
Introduction to Structs

The basic organization of an e program is a tree of structs. A struct is a compound type that contains data fields, procedural methods, and other members.

It is the e equivalent of a class in other object-oriented languages. A base struct type can be extended by adding members. Subtypes can be created from a base struct type which inherit the base type s members, and contain additional members.

Structs are used to define data elements and behavior of components of a test environment. A struct can hold all types of data and methods.
For reusability of e code, you can add struct members or change the behavior of a previously defined struct with .extend. This is very important feature of e language.

There are two ways to implement object-oriented inheritance in e: like inheritance or when inheritance :

  • Like inheritance is the classical, single inheritance familiar to users of all object-oriented languages and is specified with the like clause in new struct definitions.
    • For God Shake please don't use this nonsense.
  • When inheritance is a concept unique to e and is specified by defining subtypes with when struct members. When inheritance provides the following advantages compared to like inheritance:
    • Ability to have explicit reference to the when fields
    • Ability to have multiple, orthogonal subtypes
    • Ability to extend the struct later

Struct
Structs are the basis building blocks for any e language based testbenches. This are similar to class in C++ and thus are used for constructing compound data structures. Like in C++ and C, we can use this compound data structures in all the places like -

  • Can be used as regular data types in any context where a type is required
    • The default value for a struct is NULL
  • Passing to/from methods (functions in C).
  • Can be used in another stuct as normal data type
  • You can also define a variable using a struct type inside a method.
    Syntax
    :struct struct-type: struct-descriptor [like base-struct-type: struct-descriptor] { [member: struct-member; &]}

Parameter

Description

base-struct-type

The type of the struct from which the new struct inherits its members.

struct-member...

The contents of the struct. The following are types of struct members

 -data fields for storing data

-methods for procedures

-events for defining temporal triggers

-coverage groups for defining coverage points

-when, for specifying inheritance subtypes

-declarative constraints for describing relations between data fields

-on, for specifying actions to perform upon event occurrences

-expect, for specifying temporal behavior rules

Example

1 <'

 2 struct structs_units1 {

 3   addr : byte;

 4   data : byte;

 5   rd_wr: bool;

 6 };

 7 '>

In the above example, the struct_units1 is the name of struct, and it contains fields addr,data,rd_wr.
Struct Subtypes

When a struct field has a Boolean type or an enumerated type, you can define a struct subtype for one or more of the possible values for that field. What I mean by defining subtype is, defining new variables for that particular type. What this means is, variables defined for one subtype will not exist for other subtype after generation. Lets see the example below.
Example

  1 <'

  2 struct structs_units2 {

  3   addr : byte;

  4   // True it is write

  5   rd_wr: bool;

  6   // Write data is present only during

  7   // write operation

  8   when TRUE structs_units1 {

  9     data : byte;

 10   };

 11 };

 12 '>
 In the above example, data exists only when the rd_wr is TRUE i.e when it is write access.

Referring subtype

To refer to an enumerated struct subtype in a struct where no values are shared between the enumerated types, you can use this syntax:
value_name struct_type

In structs where more than one enumerated field can have the same value, you must use the following syntax to refer to the struct subtype:
value'field_name struct_type

Example

  1 <'

  2 struct structs_units3 {

  3   addr : byte;

  4   // True it is write

  5   rd_wr: bool;

  6   // Write data is present only during write operation

  7   when TRUE'rd_wr structs_units3 {

  8     data : byte;

  9   };

 10 };

 11

 12 extend sys {

 13   obj : structs_units3;

 14   // This method shows a sub type can accessed

 15   print_obj () is {

 16     if (obj.rd_wr == TRUE) {

 17       out ("Access Type    is : Write");

 18       outf("Access Address is : %x\n",obj.addr);

 19       // To access subtype object is bit complicated, as it does not exit

 20       // in nomal struct

 21       outf("Access Data    is : %x\n",obj.as_a(TRUE'rd_wr structs_units3).data);

 22     } else {

 23       out ("Access Type    is : Read");

 24       outf("Access Address is : %x\n",obj.addr);

 25       // Below code if you uncomment it will compile, but will give run time

 26       // error, as data does not exist when rd_wr is false

 27       //outf("Access Data    is : %x\n",obj.as_a(TRUE'rd_wr structs_units3).data);

 28     };

 29   };

 30   // Just generate the obj and print it

 31   run() is also {

 32     for {var i : int = 0; i < 4; i = i + 1} do {

 33       gen obj;

 34       print_obj();

 35     };

 36   };

 37 };

 38 '>

Access Type    is : Read

Access Address is : 74

Access Type    is : Write

Access Address is : e6

Access Data    is : 2b

Access Type    is : Write

Access Address is : 96

Access Data    is : 35

Access Type    is : Write

Access Address is : 1d

Access Data    is : d1

  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ứ tư, 01 Tháng 6 2022 17:56 )  
Chat Zalo