[22] | 1 | ---------------------------------------------------------------------------------- |
---|
| 2 | -- Company: |
---|
| 3 | -- Engineer: |
---|
| 4 | -- |
---|
| 5 | -- Create Date: 16:32:59 10/23/2012 |
---|
| 6 | -- Design Name: |
---|
| 7 | -- Module Name: FIFO_DP - Behavioral |
---|
| 8 | -- Project Name: |
---|
| 9 | -- Target Devices: |
---|
| 10 | -- Tool versions: |
---|
| 11 | -- Description: |
---|
| 12 | -- |
---|
| 13 | -- Dependencies: |
---|
| 14 | -- |
---|
| 15 | -- Revision: |
---|
| 16 | -- Revision 0.01 - File Created |
---|
| 17 | -- Additional Comments: |
---|
| 18 | -- |
---|
| 19 | ---------------------------------------------------------------------------------- |
---|
| 20 | |
---|
| 21 | library IEEE; |
---|
| 22 | use IEEE.STD_LOGIC_1164.ALL; |
---|
| 23 | use IEEE.STD_LOGIC_ARITH.ALL; |
---|
| 24 | use IEEE.STD_LOGIC_UNSIGNED.ALL; |
---|
| 25 | |
---|
| 26 | entity fifo_dp is |
---|
| 27 | GENERIC |
---|
| 28 | ( |
---|
| 29 | ADDRESS_WIDTH : integer:=8;---8 bit |
---|
| 30 | DATA_WIDTH : integer:=8 ---8 bit |
---|
| 31 | ); |
---|
| 32 | |
---|
| 33 | port ( clk : in std_logic; |
---|
| 34 | reset : in std_logic; |
---|
| 35 | enr : in std_logic; --enable read,should be '0' when not in use. |
---|
| 36 | enw : in std_logic; --enable write,should be '0' when not in use. |
---|
| 37 | dataout : out std_logic_vector(DATA_WIDTH-1 downto 0); --output data |
---|
| 38 | datain : in std_logic_vector (DATA_WIDTH-1 downto 0); --input data |
---|
| 39 | empty : out std_logic; --set as '1' when the queue is empty |
---|
| 40 | err : out std_logic; |
---|
| 41 | full : out std_logic --set as '1' when the queue is full |
---|
| 42 | ); |
---|
| 43 | end fifo; |
---|
| 44 | |
---|
| 45 | architecture Behavioral of fifo_dp is |
---|
| 46 | |
---|
| 47 | type memory_type is array (0 to ((2**ADDRESS_WIDTH)-1)) of std_logic_vector(DATA_WIDTH-1 downto 0); |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | -----distributed------- |
---|
| 51 | signal memory : memory_type ;-- :=(others => (others => '0')); --memory for queue.----- |
---|
| 52 | signal readptr,writeptr : std_logic_vector(ADDRESS_WIDTH-1 downto 0); --read and write pointers. |
---|
| 53 | signal full0 : std_logic; |
---|
| 54 | signal empty0 : std_logic; |
---|
| 55 | |
---|
| 56 | begin |
---|
| 57 | full <= full0; |
---|
| 58 | empty <= empty0; |
---|
| 59 | |
---|
| 60 | fifo0: process(clk,reset) |
---|
| 61 | begin |
---|
| 62 | if reset='1' then |
---|
| 63 | |
---|
| 64 | readptr <= (others => '0'); |
---|
| 65 | writeptr <= (others => '0'); |
---|
| 66 | empty0 <='1'; |
---|
| 67 | full0<='0'; |
---|
| 68 | err<='0'; |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | elsif rising_edge(clk) then |
---|
| 72 | |
---|
| 73 | if (writeptr + '1' = readptr) then |
---|
| 74 | full0<='1'; |
---|
| 75 | else |
---|
| 76 | full0<='0'; |
---|
| 77 | end if ; |
---|
| 78 | |
---|
| 79 | if (readptr = writeptr ) then |
---|
| 80 | empty0<='1'; |
---|
| 81 | else |
---|
| 82 | empty0<='0'; |
---|
| 83 | end if ; |
---|
| 84 | |
---|
| 85 | if (empty0='0' and enr='1') or (full0='0' and enw='1') then |
---|
| 86 | err<='1'; |
---|
| 87 | end if ; |
---|
| 88 | |
---|
| 89 | if enw='1' and full0='0' then |
---|
| 90 | memory (conv_integer(writeptr)) <= datain ; |
---|
| 91 | writeptr <= writeptr + '1' ; |
---|
| 92 | end if ; |
---|
| 93 | |
---|
| 94 | if enr='1' and empty0='0' then |
---|
| 95 | dataout <= memory (conv_integer(readptr)); |
---|
| 96 | readptr <= readptr + '1' ; |
---|
| 97 | end if ; |
---|
| 98 | |
---|
| 99 | end if; |
---|
| 100 | |
---|
| 101 | end process; |
---|
| 102 | end Behavioral; |
---|