ASIC/FPGA Design and Verification Out Source Services
A VHDL example implementing list (is access record).
-
This examples demonstrates how to create lists in VHDL. This may be useful in
implementing a FIFO quickly in a test-bench.
I used list style coding to read an unknown number of bytes, during
simulation at time 0, from a file. The data is to be later driven to a DUT.
read from file into a list.
-
The list item has two fields, data to be driven to DUT and a
next item pointer for list manipulation.
-
The simulation is ended using an assert error statement. The code has been tested
using ghdl. The code and compilation script is shown below:
#!/bin/bash
if [ -d "work" ] ; then
rm -fr work
fi
mkdir work
ghdl -i --std=93c --workdir=work tb_is_access.vhd
ghdl -m --work=work --workdir=work --ieee=synopsys tb_is_access
./tb_is_access --assert-level=error
- LIBRARY ieee;
- USE ieee.std_logic_1164.ALL;
- use STD.textio.all;
- use IEEE.std_logic_textio.all;
- use ieee.numeric_std.all;
- use ieee.STD_LOGIC_UNSIGNED.conv_integer;
- ENTITY tb_is_access IS
- END tb_is_access;
- ARCHITECTURE beha OF tb_is_access IS
- type fifo_item; -- the item
- type fifo_item_ptr is access fifo_item; -- pointer to item
- type fifo_item is record -- full definition of item
- data : std_logic_vector(7 downto 0);
- next_rec : fifo_item_ptr;
- end record;
- BEGIN
- --Read process
- process
- variable j : integer;
- variable v : std_logic_vector(7 downto 0);
- variable new_pkt : fifo_item_ptr;
- variable tmp_ptr : fifo_item_ptr;
- variable fifo_ptr: fifo_item_ptr := null;
- variable my_line : line;
- begin
- v := (others => '0');
- for j in 0 to 8 loop
- if(j = 0) then
- new_pkt := new fifo_item;
- new_pkt.data := v;
- new_pkt.next_rec := null;
- fifo_ptr := new_pkt;
- else
- new_pkt := new fifo_item;
- new_pkt.data := v;
- new_pkt.next_rec := null;
- tmp_ptr := fifo_ptr;
-
- --write(my_line, string'("dbg "));
- --hwrite(my_line, new_pkt.data);
- --writeline(output, my_line);
-
- while(tmp_ptr.next_rec /= null) loop --find last
- tmp_ptr := tmp_ptr.next_rec;
- end loop;
- tmp_ptr.next_rec := new_pkt;
- end if;
- v := std_logic_vector(unsigned(v) + "00000001");
- end loop;
- wait for 10 ns;
- tmp_ptr := fifo_ptr;
- while(tmp_ptr.next_rec /= null) loop
- write(my_line, string'("dbg "));
- hwrite(my_line, tmp_ptr.data);
- write(my_line, string'(" time "));
- write(my_line, now);
- writeline(output, my_line);
-
- tmp_ptr := tmp_ptr.next_rec;
- end loop;
-
- assert false report "end of test" severity error;
- end process;
- end beha;
|