1 |
14 |
leonardoar |
--! @file
|
2 |
|
|
--! @brief Register File unit http://en.wikipedia.org/wiki/Register_file
|
3 |
|
|
|
4 |
|
|
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
|
5 |
|
|
library IEEE;
|
6 |
|
|
use ieee.std_logic_1164.all;
|
7 |
|
|
use ieee.std_logic_unsigned.all;
|
8 |
|
|
use ieee.std_logic_arith.all;
|
9 |
|
|
|
10 |
|
|
--! Use CPU Definitions package
|
11 |
|
|
use work.pkgOpenCPU32.all;
|
12 |
|
|
|
13 |
|
|
--! A register file is an array of processor registers in a central processing unit (CPU).
|
14 |
|
|
|
15 |
|
|
--! A register file is an array of processor registers in a central processing unit (CPU).\n
|
16 |
|
|
--! Modern integrated circuit-based register files are usually implemented by way of fast static RAMs with multiple ports.\n
|
17 |
|
|
--! Such RAMs are distinguished by having dedicated read and write ports, whereas ordinary multiported SRAMs will usually read and write\n
|
18 |
|
|
--! through the same ports.
|
19 |
|
|
entity RegisterFile is
|
20 |
|
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the registers)
|
21 |
|
|
Port ( clk : in STD_LOGIC; --! Clock signal
|
22 |
|
|
writeEn : in STD_LOGIC; --! Write enable
|
23 |
|
|
writeAddr : in generalRegisters; --! Write Adress
|
24 |
|
|
input : in STD_LOGIC_VECTOR (n downto 0); --! Input
|
25 |
|
|
Read_A_En : in STD_LOGIC; --! Enable read A
|
26 |
|
|
Read_A_Addr : in generalRegisters; --! Read A adress
|
27 |
|
|
Read_B_En : in STD_LOGIC; --! Enable read A
|
28 |
|
|
Read_B_Addr : in generalRegisters; --! Read B adress
|
29 |
|
|
A_Out : out STD_LOGIC_VECTOR (n downto 0); --! Output A
|
30 |
|
|
B_Out : out STD_LOGIC_VECTOR (n downto 0)); --! Output B
|
31 |
|
|
end RegisterFile;
|
32 |
|
|
|
33 |
|
|
--! @brief This register file will have one input and two ouputs.
|
34 |
|
|
--! @details This will permit to read two registers on the same clock, but will need n clock cicles for n register assignments...
|
35 |
|
|
|
36 |
|
|
architecture Behavioral of RegisterFile is
|
37 |
|
|
subtype reg is STD_LOGIC_VECTOR (n downto 0); -- Define register type
|
38 |
|
|
type regArray is array (0 to (numGenRegs-1)) of reg; -- Define register type array
|
39 |
|
|
signal regFile : regArray; -- This signal will infer an FF array if assigned by a clock edge...
|
40 |
|
|
begin
|
41 |
|
|
|
42 |
|
|
-- Write some register value...
|
43 |
|
|
writeProcess: process (clk)
|
44 |
|
|
begin
|
45 |
|
|
if rising_edge(clk) then
|
46 |
|
|
if (writeEn = '1') then
|
47 |
|
|
regFile(CONV_INTEGER(reg2Num(writeAddr))) <= input;
|
48 |
|
|
end if;
|
49 |
|
|
end if;
|
50 |
|
|
end process;
|
51 |
|
|
|
52 |
|
|
-- Read some register in port A
|
53 |
|
|
readAProcess : process(Read_A_En,Read_A_Addr)
|
54 |
|
|
begin
|
55 |
|
|
if (Read_A_En = '1') then
|
56 |
15 |
leonardoar |
A_Out <= regFile(CONV_INTEGER(reg2Num(Read_A_Addr)));
|
57 |
14 |
leonardoar |
else
|
58 |
|
|
A_Out <= (others => 'Z');
|
59 |
|
|
end if;
|
60 |
|
|
end process;
|
61 |
|
|
|
62 |
|
|
-- Read some register in port B
|
63 |
|
|
readBProcess : process(Read_B_En,Read_B_Addr)
|
64 |
|
|
begin
|
65 |
|
|
if (Read_B_En = '1') then
|
66 |
15 |
leonardoar |
B_Out <= regFile(CONV_INTEGER(reg2Num(Read_B_Addr)));
|
67 |
14 |
leonardoar |
else
|
68 |
|
|
B_Out <= (others => 'Z');
|
69 |
|
|
end if;
|
70 |
|
|
end process;
|
71 |
|
|
|
72 |
|
|
end Behavioral;
|
73 |
|
|
|