library IEEE; use IEEE.std_logic_1164.all; entity fifo is generic ( data_width : integer := 8;-- largeur de la donnée =>8 bits fifo_depth : integer := 4096 -- profondeur de la fifo =>4096 soit 4 KB ); port ( rst : in std_logic;--reset wr_en : in std_logic;--écriture autorisée wr_clk : in std_logic;-- horloge d'écriture wr_data : in std_logic_vector( 7 downto 0 );-- donnée d'entrée=>8 bits rd_en : in std_logic;-- lecture autorisée rd_clk : in std_logic;-- horloge d'écriture rd_data : out std_logic_vector( 7 downto 0 )-- donnée de sortie => 8bits ); end entity; architecture archfifo of fifo is type memory_type is array ( 11 downto 0 ) of std_logic_vector(7 downto 0); signal memory : memory_type; -- affectation au signal memory de signal memory_type signal wr_ptr : integer range memory'range(1); signal rd_ptr : integer range memory'range(1); begin process ( wr_clk, rst )-- ecriture dans la fifo begin if rising_edge(wr_clk) then-- déclenchement sur front montant du signal d'horloge ecriture if rst='1' then -- si reset vaut 1 alors wr_ptr <= 0;-- mise a zero du pointeur ecriture"wr" elsif wr_en='1' then --sinon si "wr_en = 1" memory(wr_ptr) <= wr_data;-- mise de data dans la memoire a l'adresse pointée par "wr-ptr" qui est au début 0 end if; wr_ptr <= (wr_ptr+1) mod fifo_depth;-- incrementation de la valeur du pointeur wr_ptr après l'écriture end if; --end if; --end if; end process; -- fin du process d'écriture process ( rd_clk, rst )-- lecture de la fifo begin if rising_edge(rd_clk) then -- déclenchement sur front montant de l'horloge de lecture if rst='1' then -- si reset vaut '1' alors rd_ptr <= 0;-- le pointeur de lecture vaut '0' elsif rd_en='1' then -- sinon, si rd_en est égale à '1' alors rd_ptr <= (rd_ptr+1) mod fifo_depth; -- incrementation de la valeur du pointeur rd_ptr end if; end if; --end if; end process; rd_data <= memory(rd_ptr);-- lecture de la valeur à l'adresse pointée par "rd_ptr" qui est égale à zéro lors de la première lecture end architecture;