Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Can a function be synchronous?

Reply
Thread Tools

Can a function be synchronous?

 
 
cruzin
Guest
Posts: n/a
 
      11-21-2003
Is it possible to make a function synchronous to the clock?

I have written an arbitrary-size mux using a recursive function:

function mux( ... )
begin
...
return ( mux(top_half), mux(bottom_half) );
end mux;

To improve synthesized performance, I want to register each level of
the mux. Something like:

function mux( clk, ... )
begin
...
wait until clk='1';
return ( mux(top_half), mux(bottom_half) );
end mux;

I realize I can not use wait in a function.

Are functions always meant to complete in zero-time? Is my only
recourse to write the synchronous mux using a recursive component
model?
 
Reply With Quote
 
 
 
 
Jim Lewis
Guest
Posts: n/a
 
      11-21-2003
You are correct you cannot use wait in a function.

If you want to create a register in either a function
or procedure, I recommend using rising_edge:

architecture RTL of Shift4x1 is -- 4 Stage Shift Reg
procedure FF(
signal Clk : in Std_Logic ;
nReset : in Std_Logic ;
D : in Std_Logic ;
signal Q : out Std_Logic
) is
begin
if nReset='0' then
Q <= '0';
elsif Rising_Edge(Clk) then
Q <= D;
end if;
end FF;
-- Clk, nReset, D, Q are ports of std_logic
signal Reg1, Reg2, Reg3 ;
begin
FF(Clk, nReset, D, Reg1);
FF(Clk, nReset, Reg1, Reg2);
FF(Clk, nReset, Reg3, Q);
end RTL ;


Currently this may not be synthesizable in all
tools, but it should be in the future as it is
called for in 1076.6-200X.


Obviously this does not solve your recursion problem.
I cannot see a way to handle it with a procedure as
you would need to be able to create a signal to hold
intermediate values. As a result, I think your
only alternative is to have some fun with an entity
with a generic and generate.


This is not the way I would solve your problem though.
First to give the synthesis tool good control of
a multiplexer chain, I prefer to use and-or logic.
And-Or at the first level, and then it becomes OR
at the upper levels.

Next, if I have a timing problem, I would plan on
using the pipeline retiming capability of the
synthesis tool. Basically code N registers in
sequence after the multiplexer and allow the synthesis
tool to move them around as it sees fit.

This will also allow you to tune the number of
registers you need based on your timing, rather than
having a register following each multiplexer stage.

Cheers,
Jim
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
Jim Lewis
Director of Training (E-Mail Removed)
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

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


cruzin wrote:
> Is it possible to make a function synchronous to the clock?
>
> I have written an arbitrary-size mux using a recursive function:
>
> function mux( ... )
> begin
> ...
> return ( mux(top_half), mux(bottom_half) );
> end mux;
>
> To improve synthesized performance, I want to register each level of
> the mux. Something like:
>
> function mux( clk, ... )
> begin
> ...
> wait until clk='1';
> return ( mux(top_half), mux(bottom_half) );
> end mux;
>
> I realize I can not use wait in a function.
>
> Are functions always meant to complete in zero-time? Is my only
> recourse to write the synchronous mux using a recursive component
> model?


 
Reply With Quote
 
 
 
 
Mike Treseler
Guest
Posts: n/a
 
      11-21-2003
cruzin wrote:
> Is it possible to make a function synchronous to the clock?


No. A function is a value calculation.
It is wires and gates, not flops.

> To improve synthesized performance, I want to register each level of
> the mux. Something like:
>
> function mux( clk, ... )
> begin
> ...
> wait until clk='1';
> return ( mux(top_half), mux(bottom_half) );
> end mux;
>
> I realize I can not use wait in a function.



The only wait you really need for
synthesis is

elsif rising_edge(clk) then

Consider calling a procedure from inside
a clocked process. Use a process variable
to keep track of the mux state.

-- Mike Treseler

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function versus pointer to function, in context of std::function,huh? Alf P. Steinbach C++ 10 07-27-2011 05:51 AM
Function pointer to void function and int function Giannis Papadopoulos C Programming 5 09-05-2005 09:06 PM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Passing a C++ object's member function to a C function expecing a function pointer! James Vanns C++ 7 01-21-2004 02:39 AM



Advertisments