O
o pere o
Guest
I am trying to write some helper tools to generate testbench signals.
For instance, I have written this data_stream generator:
procedure data_stream(
signal y : out std_logic; -- Output signal
constant data : std_logic_vector; -- Data, e.g. "11110101"
constant bit_period : time; -- Duration of each bit
constant start_time : time := 0 ns; -- Initial time offset
constant def_out : std_logic := 'U') is
begin
y <= def_out;
wait for start_time;
for ix in data'left to data'right loop (*)
y<=data(ix);
wait for bit_period;
end loop;
y <= def_out;
(*) actually I look if data'left < data'right and iterate "to" or
"downto" otherwise. (Could probably be improved)
Using this procedure, in the test bench I can build:
data_stream(slv(1),"0011",1 us, 0 us,'Z');
data_stream(slv(0),"1101",1 us, 5 us,'Z');
Now, I would like to merge each signal onto one. Thanks to the default
value of 'Z' this is simple. For instance, in the test bench, this code
works fine:
join: for i in slv'range generate
tot <= slv(i);
end generate;
y <='U' when tot='Z' else tot;
where the 'U' could be changed to whatever makes sense. Now, I would
like to have the last lines in a _function_ or _procedure_.
Unfortunately, I only have been able to bring this together, which works
but looks ugly compared to the 4 lines before:
procedure signal_join(
signal y : out std_logic;
constant slv : std_logic_vector;
constant def_out : std_logic := 'U') is
variable tot: std_logic;
begin
tot := 'Z';
join: for i in slv'range loop
if slv(i)/='Z' then
tot := slv(i);
end if;
end loop;
if tot='Z' then
y<=def_out;
else
y<=tot;
end if;
end;
I would appreciate any suggestion on this. Especially, if I am making
big mistakes! Furthermore, I have been unable to find functions that
ease the generation of test signals, say to simulate some bursts of an
SPI master or whatever, which is why I am writing this stuff. Any
pointers on this?
Pere
For instance, I have written this data_stream generator:
procedure data_stream(
signal y : out std_logic; -- Output signal
constant data : std_logic_vector; -- Data, e.g. "11110101"
constant bit_period : time; -- Duration of each bit
constant start_time : time := 0 ns; -- Initial time offset
constant def_out : std_logic := 'U') is
begin
y <= def_out;
wait for start_time;
for ix in data'left to data'right loop (*)
y<=data(ix);
wait for bit_period;
end loop;
y <= def_out;
(*) actually I look if data'left < data'right and iterate "to" or
"downto" otherwise. (Could probably be improved)
Using this procedure, in the test bench I can build:
data_stream(slv(1),"0011",1 us, 0 us,'Z');
data_stream(slv(0),"1101",1 us, 5 us,'Z');
Now, I would like to merge each signal onto one. Thanks to the default
value of 'Z' this is simple. For instance, in the test bench, this code
works fine:
join: for i in slv'range generate
tot <= slv(i);
end generate;
y <='U' when tot='Z' else tot;
where the 'U' could be changed to whatever makes sense. Now, I would
like to have the last lines in a _function_ or _procedure_.
Unfortunately, I only have been able to bring this together, which works
but looks ugly compared to the 4 lines before:
procedure signal_join(
signal y : out std_logic;
constant slv : std_logic_vector;
constant def_out : std_logic := 'U') is
variable tot: std_logic;
begin
tot := 'Z';
join: for i in slv'range loop
if slv(i)/='Z' then
tot := slv(i);
end if;
end loop;
if tot='Z' then
y<=def_out;
else
y<=tot;
end if;
end;
I would appreciate any suggestion on this. Especially, if I am making
big mistakes! Furthermore, I have been unable to find functions that
ease the generation of test signals, say to simulate some bursts of an
SPI master or whatever, which is why I am writing this stuff. Any
pointers on this?
Pere