Skip to content

Instantly share code, notes, and snippets.

@christiaanb
Created November 20, 2013 14:05
Show Gist options
  • Save christiaanb/7563699 to your computer and use it in GitHub Desktop.
Save christiaanb/7563699 to your computer and use it in GitHub Desktop.
Type and Function generics
library ieee;
use ieee.std_logic_1164.all;
entity incrementer is
generic (type data_type;
function increment (x: data_type) return data_type);
port (I : in data_type;
O : out data_type;
inc : in std_logic);
end;
architecture RTL of incrementer is
begin
O <= increment(I) when inc = '1';
end;
library ieee;
use ieee.std_logic_1164.all;
entity typegenerics is
port (I : in unsigned(7 downto 0);
O : out unsigned(7 downto 0);
ena : in std_logic);
end;
architecture RTL of typegenerics is
function add_one (b : in unsigned(7 downto 0)) return unsigned(7 downto 0) is
begin
return (b + 1);
end;
begin
incr_inst : entity work.incrementer
generic map ( data_type => unsigned(7 downto 0),
increment => add_one )
port map ( I => I, O => O, inc => ena );
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment