96 Chapter Four
packet.data(10)(4) := ‘ 1 ’; --error line 4
packet.data(10)(0) := ‘ 1 ’; --Ok line 5
END PROCESS;
This example shows how complex record types are accessed. In line 1,
a record field of a record is accessed. Field keyis a record field of record
addr_type, which is a field of record data_packet. This line assigns the
value 5 to that field. Line 2 assigns an aggregate to the whole field called
addrin record data_packet.
In line 3, the data field is assigned an aggregate for the 0th element
of the array. Line 4 tries to assign to only one bit of the eleventh ele-
ment of the data array field in record data_packet, but the second index
value is out of range. Finally, line 5 shows how to assign to a single bit
of the array correctly.
Composite types are very powerful tools for modeling complex and
abstract data types. By using the right combination of records and arrays,
you can make models easy to understand and efficient.
ACCESS TYPES Most hardware design engineers using VHDL
probably never use access types directly (a hardware designer may use
the TextIO package, which uses access types, thereby an indirect use of
access types), but access types provide very powerful programming lan-
guage type operations. An access type in VHDL is very similar to a
pointer in a language like Pascal or C. It is an address, or a handle, to
a specific object.
Access types allow the designer to model objects of a dynamic nature. For
instance, dynamic queues, fifos, and so on can be modeled easily using
access types. Probably the most common operation using an access type
is creating and maintaining a linked list.
Only variables can be declared as access types. By the nature of access
types, they can only be used in sequential processing. Access types are
currently not synthesizable because they are usually used to model the
behavior of dynamically sized structures such as a linked list.
When an object is declared to be of an access type, two predefined functions
are automatically available to manipulate the object. These functions are
named NEWand DEALLOCATE. Function NEWallocates memory of the size of
the object in bytes and returns the access value. Function DEALLOCATEtakes
in the access value and returns the memory back to the system. Following
is an example that shows how this all works: