# How to create a VHDL function/procedure that can return true or false based on value of signals outside it?

Here is the function I am trying to write:

procedure ASCERTAIN_CALL_VALIDITY is
begin
end procedure;


I want to return the value from logic processing and store inside a signal or variable outside it. Now the problem is that, functions can't access signals outside of them. Procedures can't return a value. So what do I do now?

• Functions can access signals (in scope at the point of the fn declaration) ; it just makes them impure. So, impure function ASCERTAIN return BOOLEAN is ... Aug 8, 2021 at 13:20

Either return a value from the procedure call (which is a statement) or use an impure function:


entity q231 is
end entity;

architecture foo of q231 is
signal SESSION_CHECK_ACTIVATION_MSG_IN: boolean;
signal SESSION_CHECK_ACTIVATION_ACKNOWLEDGE_MSG_IN: boolean;
signal SESSION_CHECK_START_SESSION_MSG_IN: boolean;
signal SESSION_CHECK_STARTUP_CONFIGURATION_MSG_IN: boolean;
signal SESSION_CHECK_TURN_OFF_MSG_IN: boolean;

procedure ASCERTAIN_CALL_VALIDITY (result: out boolean) is  -- ADDED out parameter
begin
end procedure;

impure function call_validity return boolean is
begin
end function;
begin
process
variable result:    boolean;
begin
wait for 10 ns;
ASCERTAIN_CALL_VALIDITY(result);
if not result then
report "result is not TRUE";
end if;
if not call_validity then
report "call_validity is FALSE";
end if;
wait;
end process;

end architecture;

• I thought that impure functions can't be synthesized at all? Aug 8, 2021 at 1:37
• Perhaps you could constrain your question further. There are no prohibitions against synthesizing impure functions found in IEEE Std 1076.6-2004 (RTL Synthesis, withdrawn). Any such prohibition would be dependent on a particular synthesis vendor. A lot of places impure functions are used are otherwise ineligible for synthesis (e.g. methods of protected types). Aug 8, 2021 at 2:23
• what tools have you used impure functions in, have you used them with Intel/Altera, Xilinx and Microsemi synthesis tools? Aug 8, 2021 at 2:27
• Xilinx synthesis for example has no problem with impure functions of this sort. A reference for an assertion to the contrary might be enlightening. The requirement to label impure functions is meant to be informative to the reader. Aug 8, 2021 at 4:26
• (additionally impure can be read by the compiler as don't perform certain sorts of optimisations on this function) Aug 8, 2021 at 13:22