VHDL Programming

(C. Jardin) #1

Data Types 89


ARCHITECTURE basic OF rom IS
CONSTANT z_state : data_out := (‘Z’, ‘Z’, ‘Z’, ‘Z’);
CONSTANT x_state : data_out := (‘X’, ‘X’, ‘X’, ‘X’);
CONSTANT rom_data : mem_data :=
( ( ‘ 0 ’, ‘ 0 ’, ‘ 0 ’, ‘ 0 ’),
( ( ‘ 0 ’, ‘ 0 ’, ‘ 0 ’, ‘ 1 ’),
( ( ‘ 0 ’, ‘ 0 ’, ‘ 1 ’, ‘ 0 ’),
( ( ‘ 0 ’, ‘ 0 ’, ‘ 1 ’, ‘ 1 ’),
( ( ‘ 0 ’, ‘ 1 ’, ‘ 0 ’, ‘ 0 ’),
( ( ‘ 0 ’, ‘ 1 ’, ‘ 0 ’, ‘ 1 ’),
( ( ‘ 0 ’, ‘ 1 ’, ‘ 1 ’, ‘ 0 ’),
( ( ‘ 0 ’, ‘ 1 ’, ‘ 1 ’, ‘ 1 ’) );
BEGIN
ASSERT addr <= memsize
REPORT “addr out of range”
SEVERITY ERROR;

data <= rom_data(addr) AFTER 10 ns WHEN cs = ‘ 1 ’ ELSE
data <= z_state AFTER 20 ns WHEN cs = ‘ 0 ’ ELSE
data <= x_state AFTER 10 ns;
END basic;

Package memory uses two constants to define two data types that form
the data structures for entity rom. By changing the constant width and
recompiling, we can change the output width of the memory. The initializa-
tion data for the ROM would also have to change to reflect the new width.
The data types from package memory are also used to define the data
types of the ports of the entity. In particular, the data port is defined to
be of type data_out.
The architecture defines three constants used to determine the output
value. The first defines the output value when the csinput is a ‘ 0 ’. The
value output is consistent with the rombeing unselected. The second con-
stant defines the output value when romhas an unknown value on the cs
input. The value output by romis unknown as well. The last constant de-
fines the data stored by rom. (This is a very efficient method to model the
ROM, but if the ROM data changes, the model needs to be recompiled.)
Depending on the address to rom, an appropriate entry from this third
constant is output. This happens when the csinput is a ‘ 1 ’value.
The romdata type in this example is organized as eight rows (0 to 7)
and four columns (0 to 3). It is a two-dimensional structure, as shown in
Figure 4-2.
To initialize the constant for the romdata type, an aggregate initial-
ization is required. The table after the rom_dataconstant declaration
is an aggregate used to initialize the constant. The aggregate value is
constructed as a table for readability; it could have been all on one line.
Free download pdf