R
Rick North
Guest
Hi all,
Has anybody felt the need to know how many fields
there are in a record? I have, at least for the second level.
The reason is that I want to be able to change the number of
events that each member of the record have and also to be
able to add new members. The code snippet below shows my
intentions (hopefully). The Different Systems has in one case
a fix number of Events tied to them and they are stored in a
constant. Fair enough, but I want to be able to change the
number of Events for each Systems. Therefore, a record is
created containing each Systems with its events.
Now, the code should loop through the Systems Event in the
record looking for an event that corresponds to one defined
in the PKG and set MyEvent high if MyEnable is high.
Can anybody give a pointer or an alternative approach?
Regards,
RN
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package pkg_test is
type Systems is (Mike_sys, Peter_sys, Austin_sys, Paul_sys);
constant Lenght_of_Sel : natural := 5;
type events is (Alice_event, Bob_event, John_event, Adam_event);
type event_def is array (events) of unsigned(Lenght_of_Sel downto 0);
type event_definition_type is array (Systems) of event_def;
constant Event_definition : event_definition_type := (
Mike_sys => (
Alice_event => "000001",
Bob_event => "000010",
John_event => "000100",
Adam_event => "001000"),
Peter_sys => (
Alice_event => "111110",
Bob_event => "111101",
John_event => "111011",
Adam_event => "110111"),
Austin_sys => (
Alice_event => "100000",
Bob_event => "010000",
John_event => "001000",
Adam_event => "000100"),
Paul_sys => (
Alice_event => "000001",
Bob_event => "000010",
John_event => "000011",
Adam_event => "000100")
);
type ch_event_type is array (events) of std_logic;
-- test for records where the members don't have all possible events
type Mike_sys_Rec_type is
record
Alice_event : unsigned(Lenght_of_Sel downto 0);
Bob_event : unsigned(Lenght_of_Sel downto 0);
John_event : unsigned(Lenght_of_Sel downto 0);
Adam_event : unsigned(Lenght_of_Sel downto 0);
end record Mike_sys_Rec_type;
type Peter_sys_Rec_type is
record
Alice_event : unsigned(Lenght_of_Sel downto 0);
John_event : unsigned(Lenght_of_Sel downto 0);
Adam_event : unsigned(Lenght_of_Sel downto 0);
end record Peter_sys_Rec_type;
type Austin_sys_Rec_type is
record
Alice_event : unsigned(Lenght_of_Sel downto 0);
Bob_event : unsigned(Lenght_of_Sel downto 0);
Adam_event : unsigned(Lenght_of_Sel downto 0);
end record Austin_sys_Rec_type;
type Paul_sys_Rec_type is
record
Alice_event : unsigned(Lenght_of_Sel downto 0);
Bob_event : unsigned(Lenght_of_Sel downto 0);
end record Paul_sys_Rec_type;
type Rec_sys_type is
record
Mike_sys : Mike_sys_Rec_type;
Peter_sys : Peter_sys_Rec_type;
Austin_sys : Austin_sys_Rec_type;
Paul_sys : Paul_sys_Rec_type;
end record Rec_sys_type;
constant Rec_sys_con : Rec_sys_type := (
Mike_sys => (
Alice_event => "100001",
Bob_event => "100010",
John_event => "100100",
Adam_event => "101000"),
Peter_sys => (
Alice_event => "010001",
John_event => "010100",
Adam_event => "011000"),
Austin_sys => (
Alice_event => "000011",
Bob_event => "000110",
Adam_event => "001100"),
Paul_sys => (
Alice_event => "001111",
Bob_event => "011111")
);
end package pkg_test;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.pkg_test.all;
entity Test is
generic (
System : Systems := Mike_sys);
port (
clk : in std_logic;
reset : in std_logic;
MyEnable : in std_logic;
EventOn : in ch_event_type;
SelEvent : in unsigned(Lenght_of_Sel downto 0);
MyEvent : out std_logic
);
end entity;
architecture beh of test is
begin
P_a : process (clk, reset) is
variable AtLeastOneTrue : boolean := false;
begin -- process P_a
if reset = '1' then -- asynchronous reset (active
high)
MyEvent <= '0';
AtLeastOneTrue := false;
elsif clk'event and clk = '1' then -- rising clock edge
-------------------------------------------------------------------------
-- Record atempt
-- Don't know howto use a generic in a record pointer nor howto
use it in
-- a loop
-- for n in (Rec_sys_con.(System)'low to
Rec_sys_con.(System)'high) loop
-- if Rec_sys_con.System. = SelEvent then
-- MyEvent <= EventOn and MyEnable;
-- AtLeastOneTrue := true;
-- end if;
-- end loop; -- n
-------------------------------------------------------------------------
-- constant array atempt
for k in events'low to events'high loop
if Event_Definition(Mike_sys)(k) = SelEvent then
MyEvent <= EventOn(k) and MyEnable;
AtLeastOneTrue := true;
end if;
end loop; -- k
-- This assertion might be done more effective somehow...
assert AtLeastOneTrue report "Event does not exist in
Event_definitions" severity error;
AtLeastOneTrue := false;
end if;
end process P_a;
end beh;
Has anybody felt the need to know how many fields
there are in a record? I have, at least for the second level.
The reason is that I want to be able to change the number of
events that each member of the record have and also to be
able to add new members. The code snippet below shows my
intentions (hopefully). The Different Systems has in one case
a fix number of Events tied to them and they are stored in a
constant. Fair enough, but I want to be able to change the
number of Events for each Systems. Therefore, a record is
created containing each Systems with its events.
Now, the code should loop through the Systems Event in the
record looking for an event that corresponds to one defined
in the PKG and set MyEvent high if MyEnable is high.
Can anybody give a pointer or an alternative approach?
Regards,
RN
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package pkg_test is
type Systems is (Mike_sys, Peter_sys, Austin_sys, Paul_sys);
constant Lenght_of_Sel : natural := 5;
type events is (Alice_event, Bob_event, John_event, Adam_event);
type event_def is array (events) of unsigned(Lenght_of_Sel downto 0);
type event_definition_type is array (Systems) of event_def;
constant Event_definition : event_definition_type := (
Mike_sys => (
Alice_event => "000001",
Bob_event => "000010",
John_event => "000100",
Adam_event => "001000"),
Peter_sys => (
Alice_event => "111110",
Bob_event => "111101",
John_event => "111011",
Adam_event => "110111"),
Austin_sys => (
Alice_event => "100000",
Bob_event => "010000",
John_event => "001000",
Adam_event => "000100"),
Paul_sys => (
Alice_event => "000001",
Bob_event => "000010",
John_event => "000011",
Adam_event => "000100")
);
type ch_event_type is array (events) of std_logic;
-- test for records where the members don't have all possible events
type Mike_sys_Rec_type is
record
Alice_event : unsigned(Lenght_of_Sel downto 0);
Bob_event : unsigned(Lenght_of_Sel downto 0);
John_event : unsigned(Lenght_of_Sel downto 0);
Adam_event : unsigned(Lenght_of_Sel downto 0);
end record Mike_sys_Rec_type;
type Peter_sys_Rec_type is
record
Alice_event : unsigned(Lenght_of_Sel downto 0);
John_event : unsigned(Lenght_of_Sel downto 0);
Adam_event : unsigned(Lenght_of_Sel downto 0);
end record Peter_sys_Rec_type;
type Austin_sys_Rec_type is
record
Alice_event : unsigned(Lenght_of_Sel downto 0);
Bob_event : unsigned(Lenght_of_Sel downto 0);
Adam_event : unsigned(Lenght_of_Sel downto 0);
end record Austin_sys_Rec_type;
type Paul_sys_Rec_type is
record
Alice_event : unsigned(Lenght_of_Sel downto 0);
Bob_event : unsigned(Lenght_of_Sel downto 0);
end record Paul_sys_Rec_type;
type Rec_sys_type is
record
Mike_sys : Mike_sys_Rec_type;
Peter_sys : Peter_sys_Rec_type;
Austin_sys : Austin_sys_Rec_type;
Paul_sys : Paul_sys_Rec_type;
end record Rec_sys_type;
constant Rec_sys_con : Rec_sys_type := (
Mike_sys => (
Alice_event => "100001",
Bob_event => "100010",
John_event => "100100",
Adam_event => "101000"),
Peter_sys => (
Alice_event => "010001",
John_event => "010100",
Adam_event => "011000"),
Austin_sys => (
Alice_event => "000011",
Bob_event => "000110",
Adam_event => "001100"),
Paul_sys => (
Alice_event => "001111",
Bob_event => "011111")
);
end package pkg_test;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.pkg_test.all;
entity Test is
generic (
System : Systems := Mike_sys);
port (
clk : in std_logic;
reset : in std_logic;
MyEnable : in std_logic;
EventOn : in ch_event_type;
SelEvent : in unsigned(Lenght_of_Sel downto 0);
MyEvent : out std_logic
);
end entity;
architecture beh of test is
begin
P_a : process (clk, reset) is
variable AtLeastOneTrue : boolean := false;
begin -- process P_a
if reset = '1' then -- asynchronous reset (active
high)
MyEvent <= '0';
AtLeastOneTrue := false;
elsif clk'event and clk = '1' then -- rising clock edge
-------------------------------------------------------------------------
-- Record atempt
-- Don't know howto use a generic in a record pointer nor howto
use it in
-- a loop
-- for n in (Rec_sys_con.(System)'low to
Rec_sys_con.(System)'high) loop
-- if Rec_sys_con.System. = SelEvent then
-- MyEvent <= EventOn and MyEnable;
-- AtLeastOneTrue := true;
-- end if;
-- end loop; -- n
-------------------------------------------------------------------------
-- constant array atempt
for k in events'low to events'high loop
if Event_Definition(Mike_sys)(k) = SelEvent then
MyEvent <= EventOn(k) and MyEnable;
AtLeastOneTrue := true;
end if;
end loop; -- k
-- This assertion might be done more effective somehow...
assert AtLeastOneTrue report "Event does not exist in
Event_definitions" severity error;
AtLeastOneTrue := false;
end if;
end process P_a;
end beh;