Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolution function issues #516

Closed
avelure opened this issue Aug 16, 2022 · 1 comment
Closed

Resolution function issues #516

avelure opened this issue Aug 16, 2022 · 1 comment

Comments

@avelure
Copy link

avelure commented Aug 16, 2022

I'm using the following code to communicate over a bus within a test hierarchy, but it does not seem to simulate correctly in NVC, while it does in ghdl and modelsim.

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity test is
end entity test;
architecture beh of test is
  type t_event_ctrl_unresolved is record
    val : std_logic;
    ack : std_logic;
  end record;
  type t_event_ctrl_drivers is array (natural range <> ) of t_event_ctrl_unresolved;
  function resolved_event_ctrl(input_vector : t_event_ctrl_drivers) return t_event_ctrl_unresolved;
  subtype t_event_ctrl is resolved_event_ctrl t_event_ctrl_unresolved;

  type t_events_unresolved is record
    flag1   : t_event_ctrl;
    flag2   : t_event_ctrl;
  end record;
  type t_events_drivers is array (natural range <> ) of t_events_unresolved;
  function resolved_events(input_vector : t_events_drivers) return t_events_unresolved;
  subtype t_events is resolved_events t_events_unresolved;
  function resolved_event_ctrl(
    input_vector : t_event_ctrl_drivers
  ) return t_event_ctrl_unresolved
  is
    variable ret : t_event_ctrl_unresolved := (others => '0');
  begin
    if input_vector'length = 0 THEN
      return ret;
    else
      for i in input_vector'range loop
        if input_vector(i).val = '1' then
          ret.val := '1';
        end if;
        if input_vector(i).ack = '1' then
          ret.ack := '1';
        end if;
      end loop;
      return ret;
    end if;
  end function resolved_event_ctrl;

  function resolved_events(
    input_vector : t_events_drivers
  ) return t_events_unresolved
  is
    variable ret : t_events_unresolved := (others => (others => '0'));
  begin
    if input_vector'length = 0 THEN
      return ret;
    else
      for i in input_vector'range loop
        ret.flag1  := resolved_event_ctrl(t_event_ctrl_drivers'(ret.flag1, input_vector(i).flag2));
        ret.flag2   := resolved_event_ctrl(t_event_ctrl_drivers'(ret.flag2, input_vector(i).flag2));
      end loop;
      return ret;
    end if;
  end function resolved_events;
  signal events : t_events;
begin
  p_events : process
  begin
    events <= (others => (others => '0'));
    loop
      wait on events.flag2.val;
      report "Got val" severity note;
      if rising_edge(events.flag2.val) then
        report "Sending ack" severity note;
        events.flag2.ack           <= '1' after 1 us, '0' after 1.1 us;
      end if;
      if falling_edge(events.flag2.val) then
        report "Resetting ack" severity note;
        events.flag2.ack           <= '1', '0' after 1 ns;
      end if;
    end loop;
  end process p_events;

  process
    procedure com2(signal flag : inout t_event_ctrl) is
    begin
      events.flag2.val <= '1';
      report "Send val 1" severity note;
      wait until events.flag2.ack = '1';
      report "Got ack" severity note;
      report "Send val 0" severity note;
      events.flag2.val <= '1';
      wait until events.flag2.ack = '0';
      report "Got ack 0" severity note;
    end procedure;
    procedure com(signal flag_event : inout t_events) is
    begin
      com2(flag_event.flag2);
    end procedure;
  begin
    wait for 1 us;
    report "Running" severity note;
    com(events);
    wait;
  end process;

end architecture beh;
nvc --std=08 -a test_resolution.vhd -e test-beh -r
** Note: 1us+0: Report Note: Running
         test_resolution.vhd:97
** Note: 1us+0: Report Note: Send val 1
         test_resolution.vhd:83

Expected output

ghdl --elab-run --std=08 work.test beh
test_resolution.vhd:97:5:@1us:(report note): Running
test_resolution.vhd:83:7:@1us:(report note): Send val 1
test_resolution.vhd:67:7:@1us:(report note): Got val
test_resolution.vhd:69:9:@1us:(report note): Sending ack
test_resolution.vhd:85:7:@2us:(report note): Got ack
test_resolution.vhd:86:7:@2us:(report note): Send val 0
test_resolution.vhd:89:7:@2100ns:(report note): Got ack 0
@nickg
Copy link
Owner

nickg commented Aug 20, 2022

Thanks for the minimal reproducer, would have been very difficult to debug otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants