UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Adventurer
Adventurer
2,674 Views
Registered: ‎08-31-2009

what is the defference between function and procedure and a entity-inst

If I want to pack a specified functionality into a "code unit". what is the principle on choosing one form the three.

If possible, pls give me some examples to show that in such situation, we can only use one of them and other two can't meet requirement.

 

What's more, If I want two double-synchronize the input asynchronous signals, can I use function? procedure? Entity(tested available)? and which is more suitalbe? and Why?

 

That's a problem puzzle me for a long time, really need your help. Thanks a lot~

0 Kudos
2 Replies
Historian
Historian
2,663 Views
Registered: ‎02-25-2008

Re: what is the defference between function and procedure and a entity-inst


rohscomplaint wrote:

If I want to pack a specified functionality into a "code unit". what is the principle on choosing one form the three.

If possible, pls give me some examples to show that in such situation, we can only use one of them and other two can't meet requirement.


A function runs in zero (well, delta) time, and is always used as part of an expression. You can use a function to simplify complex expressions, especially those you use many times.A function returns a value. So if you need to determine the sine of an angle, you use a function.

 

A procedure encapsulates some sequential statements. It doesn't return any value. You use a procedure for its effects on the signals it drives.So for example if you have a pattern generator you can encapsulate its timing and signal outputs into a procedure that can be called at different times. VERY IMPORTANT:  a procedure may only be called from within a process. (It may be declared outside of a process, in the architecture body or in a package, but it can only be called from within a process.)

 

An entity is the structure which encapsulates the design. It can include both processes and simple assignments.

 


What's more, If I want two double-synchronize the input asynchronous signals, can I use function? procedure? Entity(tested available)? and which is more suitalbe? and Why?

 

That's a problem puzzle me for a long time, really need your help. Thanks a lot~


I find it easiest to just write a synchronous process. The other option is to create an entity but then you just have a lot more typing for no real benefit.

----------------------------Yes, I do this for a living.
0 Kudos
Explorer
Explorer
2,625 Views
Registered: ‎07-27-2009

Re: what is the defference between function and procedure and a entity-inst

package PCK_SYNCHRO

 

  type booleans is array(integer range <>) of boolean;

 

...

  procedure SHIFT_SYNCHRO(sync_regs: inout booleans; arg: in boolean) is
  begin
    sync_regs := sync_regs(sync_regs'high-1 downto 0) & arg;
  end procedure SHIFT_SYNCHRO;

 

end PCK_SYNCHRO ;

 

 

entityTEST

  port (

    -- Something to synchronize

   A_toggle: in boolean;

...

  );

end entity;

 

architecture RTL of TEST is

 

begin

 

  MAIN:process(CLK, RESET_N)
    variable A_S: booleans(1 downto 0);
   begin
    if RESET_N='0' then

...
       A_S     := (others => FALSE);
    elsif rising_edge(CLK) then

...
       -- Synchronizers
      SHIFT_SYNCHRO(A_S, A_TOGGLE);
    end if;
  end process;
 

 

 

 

 

0 Kudos