Subprograms

M

Matt North

Guest
The while loop below is used in a subprogram

while i<=something loop
dosomething
i:=i+1;
exit when i=something+1;
end loop;

is it possible to use the values of i in another process which calls this
subroutine while i is changing.
i.e. use the value of i to strobe the address of ram.

When i simulate i just get the final value of i. NOT USEFULL.
 
Matt North wrote:
The while loop below is used in a subprogram

while i<=something loop
dosomething
i:=i+1;
exit when i=something+1;
end loop;

is it possible to use the values of i in another process which calls this
subroutine while i is changing.
Variables local to the procedure
go out of scope at the exit.

The calling process has to have
the variable or signal already
declared and in scope to pass it as an
inout parameter to the procedure.

Another process could not have access
to the same variable. You could have
two processes share a signal as long
and one is the driver and the other
just reads it.

-- Mike Treseler
 
You can add a signal out to your procedure and then
strobe it at the appropriate time.

One way to do this (testbench style):
Drive Strobe such that each time it gets the opposite
value that it previously had (requires Strobe to be initialized
somewhere - I suggest initializing the signal):
Strobe <= not Strobe ; -- strobe must be class INOUT
Alternately: Strobe <= i ; -- if strobe is an integer

Wake up when strobe changes:
wait on Strobe ;

Alternately (closer to real hardware behavior):
Drive nAds so it is a clock cycle wide (like 386):
nAds <= '0' after tpd, '1' after tpd + tperiod_clk ;

Wake up when nAds is high on the rising edge of Clk:
wait on Clk until nAds = '1' and Clk = '1' ;


Cheers,
Jim
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jim Lewis
Director of Training mailto:Jim@SynthWorks.com
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Matt North wrote:
The while loop below is used in a subprogram

while i<=something loop
dosomething
i:=i+1;
exit when i=something+1;
end loop;

is it possible to use the values of i in another process which calls this
subroutine while i is changing.
i.e. use the value of i to strobe the address of ram.

When i simulate i just get the final value of i. NOT USEFULL.
 
Jim,

Alternately (closer to real hardware behavior):
Drive nAds so it is a clock cycle wide (like 386):
nAds <= '0' after tpd, '1' after tpd + tperiod_clk ;
My procedure is called in a process;

process(rst, clk)
variable ptr: int_r;
begin
rising_edge(clk) then
wr<='1';
proc1(ram, ptr, "jksdf kjsdfjk");
end if;
addr_int<=ptr;
end process;

The contents of the procedure;

procedure proc1(signal data: out bit_vector(7 downto 0);
variable ptr: out int_r;
info: string) is

variable i: int_r:=0;

begin

while i<=info'HIGH loop
if i=0 then
data<=prel;
i:=i+1;
elsif i<=info'LENGTH then
data<=func_call(info(i));
i:=i+1;
else
data<=(others=>'0');
end if;
end if;
ptr:=i;
exit when i=info'HIGH+1;
end loop;

end ChWriteMM;

I would like to be able to get all the values of the variable i as it
increments and use them to strobe a ram address.
I dont think this is possible as the procedure is being called in one clk
cycle.
The variable i is incrementing but at what period i do not know.
When i simulate the code the value of ptr is the final value of i
(info'HIGH), this is no good i need to pass all the
values of i as it reaches info'HIGH.

Thanks,
Matt


"Jim Lewis" <Jim@SynthWorks.com> wrote in message
news:vqd238li9n7qe6@corp.supernews.com...
You can add a signal out to your procedure and then
strobe it at the appropriate time.

One way to do this (testbench style):
Drive Strobe such that each time it gets the opposite
value that it previously had (requires Strobe to be initialized
somewhere - I suggest initializing the signal):
Strobe <= not Strobe ; -- strobe must be class INOUT
Alternately: Strobe <= i ; -- if strobe is an integer

Wake up when strobe changes:
wait on Strobe ;

Alternately (closer to real hardware behavior):
Drive nAds so it is a clock cycle wide (like 386):
nAds <= '0' after tpd, '1' after tpd + tperiod_clk ;

Wake up when nAds is high on the rising edge of Clk:
wait on Clk until nAds = '1' and Clk = '1' ;


Cheers,
Jim
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jim Lewis
Director of Training mailto:Jim@SynthWorks.com
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Matt North wrote:
The while loop below is used in a subprogram

while i<=something loop
dosomething
i:=i+1;
exit when i=something+1;
end loop;

is it possible to use the values of i in another process which calls
this
subroutine while i is changing.
i.e. use the value of i to strobe the address of ram.

When i simulate i just get the final value of i. NOT USEFULL.
 
Matt,
I recommend that you simulate this before
you go further. Your while loop in the
procedure proc1 executes in 0 time. Since
no time passes between iterations (assigments
to data), when a value of data is scheduled it will
replace (meaning delete from ever happening) the
previous value. So the only value on data
is the last value.

Time needs to pass when apply run your sequence on
data. Note procedures (unlike functions) are permitted
to have wait statements in them. If you are waiting on
a data object, that object will need to have the class
of signal.

You might want to reconsider your problem.
You want your procedures to do an action on an
interface. This means that if you are driving things
to a RAM interface, then you will want the procedure
to drive data, address, and the control signals.

Cheers,
Jim

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jim Lewis
Director of Training mailto:Jim@SynthWorks.com
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Matt North wrote:

Jim,


Alternately (closer to real hardware behavior):
Drive nAds so it is a clock cycle wide (like 386):
nAds <= '0' after tpd, '1' after tpd + tperiod_clk ;


My procedure is called in a process;

process(rst, clk)
variable ptr: int_r;
begin
rising_edge(clk) then
wr<='1';
proc1(ram, ptr, "jksdf kjsdfjk");
end if;
addr_int<=ptr;
end process;

The contents of the procedure;

procedure proc1(signal data: out bit_vector(7 downto 0);
variable ptr: out int_r;
info: string) is

variable i: int_r:=0;

begin

while i<=info'HIGH loop
if i=0 then
data<=prel;
i:=i+1;
elsif i<=info'LENGTH then
data<=func_call(info(i));
i:=i+1;
else
data<=(others=>'0');
end if;
end if;
ptr:=i;
exit when i=info'HIGH+1;
end loop;

end ChWriteMM;

I would like to be able to get all the values of the variable i as it
increments and use them to strobe a ram address.
I dont think this is possible as the procedure is being called in one clk
cycle.
The variable i is incrementing but at what period i do not know.
When i simulate the code the value of ptr is the final value of i
(info'HIGH), this is no good i need to pass all the
values of i as it reaches info'HIGH.

Thanks,
Matt


"Jim Lewis" <Jim@SynthWorks.com> wrote in message
news:vqd238li9n7qe6@corp.supernews.com...

You can add a signal out to your procedure and then
strobe it at the appropriate time.

One way to do this (testbench style):
Drive Strobe such that each time it gets the opposite
value that it previously had (requires Strobe to be initialized
somewhere - I suggest initializing the signal):
Strobe <= not Strobe ; -- strobe must be class INOUT
Alternately: Strobe <= i ; -- if strobe is an integer

Wake up when strobe changes:
wait on Strobe ;

Alternately (closer to real hardware behavior):
Drive nAds so it is a clock cycle wide (like 386):
nAds <= '0' after tpd, '1' after tpd + tperiod_clk ;

Wake up when nAds is high on the rising edge of Clk:
wait on Clk until nAds = '1' and Clk = '1' ;


Cheers,
Jim
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jim Lewis
Director of Training mailto:Jim@SynthWorks.com
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Matt North wrote:

The while loop below is used in a subprogram

while i<=something loop
dosomething
i:=i+1;
exit when i=something+1;
end loop;

is it possible to use the values of i in another process which calls

this

subroutine while i is changing.
i.e. use the value of i to strobe the address of ram.

When i simulate i just get the final value of i. NOT USEFULL.
--
 

Welcome to EDABoard.com

Sponsor

Back
Top