Do you want to pass a file into a function, or a filename? they are two different things, and both possible. But if you want to drive a bus, you'll probably want a procedure instead
VHDL has a FILE_OPEN procedure you can call in the function, or procedure, but if you're passing in a filename then theres no need.
Below is an example:
Code VHDL - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| procedure send_packet(constant fname : in string;
-- interface to drive
signal clk : in std_logic;
signal drive : out std_logic_vector(31 downto 0) ) is
file pkt_file : text open read_mode is fname
variable l : line;
variable d : std_logic_vector(drive'range);
begin
while not ENDFILE(pkt_file) loop
readline(pkt_file, l);
read(l, d);
drive <= d;
wait until rising_edge(clk);
end loop;
end procedure send_packet; |
Of course, this can get much, much more complicated.
The above code requires you use VHDL 2008 for standard libraries, otherwise you'll need to include the non-standard ieee.std_logic_textio (included with all simulators afaik) if you're running VHDL '93.
so in your testbench, you just write:
Code VHDL - [expand] |
1
2
3
4
5
6
7
8
9
| process
begin
send_packet("packet1.txt", clk, d);
wait for 10 us;
send_packet("packet2.txt", clk, d);
wait for 10 us;
send_packet("packet3.txt", clk, d);
wait;
end process; |