Created
November 20, 2013 14:05
-
-
Save christiaanb/7563699 to your computer and use it in GitHub Desktop.
Type and Function generics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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