0
\$\begingroup\$

Here is the function I am trying to write:

procedure ASCERTAIN_CALL_VALIDITY is
begin
  (SESSION_CHECK_ACTIVATION_MSG_IN and ACTIVATION_MSG_RECEIVED_INT) or
  (SESSION_CHECK_ACTIVATION_ACKNOWLEDGE_MSG_IN and ACTIVATION_ACKNOWLEDGE_MSG_RECEIVED_INT) or
  (SESSION_CHECK_START_SESSION_MSG_IN and START_SESSION_MSG_RECEIVED_INT) or
  (SESSION_CHECK_STARTUP_CONFIGURATION_MSG_IN and STARTUP_CONFIGURATION_MSG_RECEIVED_INT) or
  (SESSION_CHECK_TURN_OFF_MSG_IN and TURN_OFF_MSG_RECEIVED_INT)
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?

\$\endgroup\$
1
  • \$\begingroup\$ 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 ... \$\endgroup\$ Aug 8, 2021 at 13:20

1 Answer 1

3
\$\begingroup\$

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 ACTIVATION_MSG_RECEIVED_INT: boolean;
    signal SESSION_CHECK_ACTIVATION_ACKNOWLEDGE_MSG_IN: boolean;
    signal ACTIVATION_ACKNOWLEDGE_MSG_RECEIVED_INT: boolean;
    signal SESSION_CHECK_START_SESSION_MSG_IN: boolean;
    signal START_SESSION_MSG_RECEIVED_INT: boolean;
    signal SESSION_CHECK_STARTUP_CONFIGURATION_MSG_IN: boolean;
    signal STARTUP_CONFIGURATION_MSG_RECEIVED_INT: boolean;
    signal SESSION_CHECK_TURN_OFF_MSG_IN: boolean;
    signal TURN_OFF_MSG_RECEIVED_INT: boolean;
    
    procedure ASCERTAIN_CALL_VALIDITY (result: out boolean) is  -- ADDED out parameter
    begin
        result :=   -- ADDED
      (SESSION_CHECK_ACTIVATION_MSG_IN and ACTIVATION_MSG_RECEIVED_INT) or
      (SESSION_CHECK_ACTIVATION_ACKNOWLEDGE_MSG_IN and ACTIVATION_ACKNOWLEDGE_MSG_RECEIVED_INT) or
      (SESSION_CHECK_START_SESSION_MSG_IN and START_SESSION_MSG_RECEIVED_INT) or
      (SESSION_CHECK_STARTUP_CONFIGURATION_MSG_IN and STARTUP_CONFIGURATION_MSG_RECEIVED_INT) or
      (SESSION_CHECK_TURN_OFF_MSG_IN and TURN_OFF_MSG_RECEIVED_INT) ; -- ADDED ;
    end procedure;
    
    impure function call_validity return boolean is
    begin
        return (SESSION_CHECK_ACTIVATION_MSG_IN and ACTIVATION_MSG_RECEIVED_INT) or
      (SESSION_CHECK_ACTIVATION_ACKNOWLEDGE_MSG_IN and ACTIVATION_ACKNOWLEDGE_MSG_RECEIVED_INT) or
      (SESSION_CHECK_START_SESSION_MSG_IN and START_SESSION_MSG_RECEIVED_INT) or
      (SESSION_CHECK_STARTUP_CONFIGURATION_MSG_IN and STARTUP_CONFIGURATION_MSG_RECEIVED_INT) or
      (SESSION_CHECK_TURN_OFF_MSG_IN and TURN_OFF_MSG_RECEIVED_INT) ;
    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;
\$\endgroup\$
5
  • 1
    \$\begingroup\$ I thought that impure functions can't be synthesized at all? \$\endgroup\$
    – quantum231
    Aug 8, 2021 at 1:37
  • 3
    \$\begingroup\$ 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). \$\endgroup\$ Aug 8, 2021 at 2:23
  • \$\begingroup\$ what tools have you used impure functions in, have you used them with Intel/Altera, Xilinx and Microsemi synthesis tools? \$\endgroup\$
    – quantum231
    Aug 8, 2021 at 2:27
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Aug 8, 2021 at 4:26
  • \$\begingroup\$ (additionally impure can be read by the compiler as don't perform certain sorts of optimisations on this function) \$\endgroup\$ Aug 8, 2021 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.