--! @file
|
--! @file
|
--! @brief DataPath http://en.wikipedia.org/wiki/Datapath
|
--! @brief DataPath http://en.wikipedia.org/wiki/Datapath
|
|
|
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
|
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
|
library IEEE;
|
library IEEE;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_arith.all;
|
use ieee.std_logic_arith.all;
|
|
|
--! Use CPU Definitions package
|
--! Use CPU Definitions package
|
use work.pkgOpenCPU32.all;
|
use work.pkgOpenCPU32.all;
|
|
|
--! A datapath is a collection of functional units, such as arithmetic logic units or multipliers, that perform data processing operations.\n
|
--! A datapath is a collection of functional units, such as arithmetic logic units or multipliers, that perform data processing operations.\n
|
--! Most central processing units consist of a datapath and a control unit, with a large part of the control unit dedicated to
|
--! Most central processing units consist of a datapath and a control unit, with a large part of the control unit dedicated to
|
--! regulating the interaction between the datapath and main memory.
|
--! regulating the interaction between the datapath and main memory.
|
|
|
--! The purpose of datapaths is to provide routes for data to travel between functional units.
|
--! The purpose of datapaths is to provide routes for data to travel between functional units.
|
entity DataPath is
|
entity DataPath is
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
Port ( inputMm : in STD_LOGIC_VECTOR (n downto 0); --! Input of Datapath from main memory
|
Port ( inputMm : in STD_LOGIC_VECTOR (n downto 0); --! Input of Datapath from main memory
|
inputImm : in STD_LOGIC_VECTOR (n downto 0); --! Input of Datapath from imediate value (instructions...)
|
inputImm : in STD_LOGIC_VECTOR (n downto 0); --! Input of Datapath from imediate value (instructions...)
|
clk : in STD_LOGIC; --! Clock signal
|
clk : in STD_LOGIC; --! Clock signal
|
outEn : in typeEnDis; --! Enable/Disable datapath output
|
outEn : in typeEnDis; --! Enable/Disable datapath output
|
aluOp : in aluOps; --! Alu operations
|
aluOp : in aluOps; --! Alu operations
|
muxSel : in dpMuxInputs; --! Select inputs from dataPath(Memory,Imediate,RegisterFile,Alu)
|
muxSel : in dpMuxInputs; --! Select inputs from dataPath(Memory,Imediate,RegisterFile,Alu)
|
muxRegFile : in STD_LOGIC_VECTOR(1 downto 0); --! Select Alu InputA (Memory,Imediate,RegFileA)
|
muxRegFile : in dpMuxAluIn; --! Select Alu InputA (Memory,Imediate,RegFileA)
|
regFileWriteAddr : in generalRegisters; --! General register write address
|
regFileWriteAddr : in generalRegisters; --! General register write address
|
regFileWriteEn : in STD_LOGIC; --! RegisterFile write enable signal
|
regFileWriteEn : in STD_LOGIC; --! RegisterFile write enable signal
|
regFileReadAddrA : in generalRegisters; --! General register read address (PortA)
|
regFileReadAddrA : in generalRegisters; --! General register read address (PortA)
|
regFileReadAddrB : in generalRegisters; --! General register read address (PortB)
|
regFileReadAddrB : in generalRegisters; --! General register read address (PortB)
|
regFileEnA : in STD_LOGIC; --! Enable RegisterFile PortA
|
regFileEnA : in STD_LOGIC; --! Enable RegisterFile PortA
|
regFileEnB : in STD_LOGIC; --! Enable RegisterFile PortB
|
regFileEnB : in STD_LOGIC; --! Enable RegisterFile PortB
|
outputDp : out STD_LOGIC_VECTOR (n downto 0); --! DataPath Output
|
outputDp : out STD_LOGIC_VECTOR (n downto 0); --! DataPath Output
|
dpFlags : out STD_LOGIC_VECTOR (2 downto 0)); --! Alu Flags
|
dpFlags : out STD_LOGIC_VECTOR (2 downto 0)); --! Alu Flags
|
end DataPath;
|
end DataPath;
|
|
|
--! @brief DataPath http://en.wikipedia.org/wiki/Datapath
|
--! @brief DataPath http://en.wikipedia.org/wiki/Datapath
|
--! @details This description will also show how to instantiate components(Alu, RegisterFile, Multiplexer) on your design
|
--! @details This description will also show how to instantiate components(Alu, RegisterFile, Multiplexer) on your design
|
architecture Behavioral of DataPath is
|
architecture Behavioral of DataPath is
|
|
|
--! Component declaration to instantiate the Multiplexer circuit
|
--! Component declaration to instantiate the Multiplexer circuit
|
COMPONENT Multiplexer4_1
|
COMPONENT Multiplexer4_1
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
Port ( A : in STD_LOGIC_VECTOR (n downto 0); --! First Input
|
Port ( A : in STD_LOGIC_VECTOR (n downto 0); --! First Input
|
B : in STD_LOGIC_VECTOR (n downto 0); --! Second Input
|
B : in STD_LOGIC_VECTOR (n downto 0); --! Second Input
|
C : in STD_LOGIC_VECTOR (n downto 0); --! Third Input
|
C : in STD_LOGIC_VECTOR (n downto 0); --! Third Input
|
D : in STD_LOGIC_VECTOR (n downto 0); --! Forth Input
|
D : in STD_LOGIC_VECTOR (n downto 0); --! Forth Input
|
E : in STD_LOGIC_VECTOR (n downto 0); --! Fifth Input
|
E : in STD_LOGIC_VECTOR (n downto 0); --! Fifth Input
|
sel : in dpMuxInputs; --! Select inputs (1, 2, 3, 4, 5)
|
sel : in dpMuxInputs; --! Select inputs (1, 2, 3, 4, 5)
|
S : out STD_LOGIC_VECTOR (n downto 0)); --! Mux Output
|
S : out STD_LOGIC_VECTOR (n downto 0)); --! Mux Output
|
END COMPONENT;
|
END COMPONENT;
|
|
|
--! Component declaration to instantiate the Multiplexer3_1 circuit
|
--! Component declaration to instantiate the Multiplexer3_1 circuit
|
COMPONENT Multiplexer3_1 is
|
COMPONENT Multiplexer3_1 is
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
Port ( A : in STD_LOGIC_VECTOR (n downto 0); --! First Input
|
Port ( A : in STD_LOGIC_VECTOR (n downto 0); --! First Input
|
B : in STD_LOGIC_VECTOR (n downto 0); --! Second Input
|
B : in STD_LOGIC_VECTOR (n downto 0); --! Second Input
|
C : in STD_LOGIC_VECTOR (n downto 0); --! Third Input
|
C : in STD_LOGIC_VECTOR (n downto 0); --! Third Input
|
sel : in STD_LOGIC_VECTOR(1 downto 0); --! Select inputs (1, 2, 3)
|
sel : in dpMuxAluIn; --! Select inputs (fromMemory, fromImediate, fromRegFileA)
|
S : out STD_LOGIC_VECTOR (n downto 0)); --! Mux Output
|
S : out STD_LOGIC_VECTOR (n downto 0)); --! Mux Output
|
end COMPONENT;
|
end COMPONENT;
|
|
|
--! Component declaration to instantiate the Alu circuit
|
--! Component declaration to instantiate the Alu circuit
|
COMPONENT Alu
|
COMPONENT Alu
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
Port ( A : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 1
|
Port ( A : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 1
|
B : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 2
|
B : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 2
|
S : out STD_LOGIC_VECTOR (n downto 0); --! Alu Output
|
S : out STD_LOGIC_VECTOR (n downto 0); --! Alu Output
|
flagsOut : out STD_LOGIC_VECTOR(2 downto 0); --! Flags from current operation
|
flagsOut : out STD_LOGIC_VECTOR(2 downto 0); --! Flags from current operation
|
sel : in aluOps); --! Select operation
|
sel : in aluOps); --! Select operation
|
END COMPONENT;
|
END COMPONENT;
|
|
|
--! Component declaration to instantiate the testRegisterFile circuit
|
--! Component declaration to instantiate the testRegisterFile circuit
|
COMPONENT RegisterFile
|
COMPONENT RegisterFile
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the registers)
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the registers)
|
Port ( clk : in STD_LOGIC; --! Clock signal
|
Port ( clk : in STD_LOGIC; --! Clock signal
|
writeEn : in STD_LOGIC; --! Write enable
|
writeEn : in STD_LOGIC; --! Write enable
|
writeAddr : in generalRegisters; --! Write Adress
|
writeAddr : in generalRegisters; --! Write Adress
|
input : in STD_LOGIC_VECTOR (n downto 0); --! Input
|
input : in STD_LOGIC_VECTOR (n downto 0); --! Input
|
Read_A_En : in STD_LOGIC; --! Enable read A
|
Read_A_En : in STD_LOGIC; --! Enable read A
|
Read_A_Addr : in generalRegisters; --! Read A adress
|
Read_A_Addr : in generalRegisters; --! Read A adress
|
Read_B_En : in STD_LOGIC; --! Enable read A
|
Read_B_En : in STD_LOGIC; --! Enable read A
|
Read_B_Addr : in generalRegisters; --! Read B adress
|
Read_B_Addr : in generalRegisters; --! Read B adress
|
A_Out : out STD_LOGIC_VECTOR (n downto 0); --! Output A
|
A_Out : out STD_LOGIC_VECTOR (n downto 0); --! Output A
|
B_Out : out STD_LOGIC_VECTOR (n downto 0)); --! Output B
|
B_Out : out STD_LOGIC_VECTOR (n downto 0)); --! Output B
|
END COMPONENT;
|
END COMPONENT;
|
|
|
COMPONENT TriStateBuffer
|
COMPONENT TriStateBuffer
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
PORT(
|
PORT(
|
A : IN std_logic_vector(n downto 0); --! Buffer Input
|
A : IN std_logic_vector(n downto 0); --! Buffer Input
|
sel : IN typeEnDis; --! Enable or Disable the output
|
sel : IN typeEnDis; --! Enable or Disable the output
|
S : OUT std_logic_vector(n downto 0) --! Enable or Disable the output
|
S : OUT std_logic_vector(n downto 0) --! Enable or Disable the output
|
);
|
);
|
END COMPONENT;
|
END COMPONENT;
|
|
|
-- Signals that will connect the various components from the DataPath
|
-- Signals that will connect the various components from the DataPath
|
signal regFilePortA : STD_LOGIC_VECTOR (n downto 0);
|
signal regFilePortA : STD_LOGIC_VECTOR (n downto 0);
|
signal regFilePortB : STD_LOGIC_VECTOR (n downto 0);
|
signal regFilePortB : STD_LOGIC_VECTOR (n downto 0);
|
signal aluOut : STD_LOGIC_VECTOR (n downto 0);
|
signal aluOut : STD_LOGIC_VECTOR (n downto 0);
|
signal muxOut : STD_LOGIC_VECTOR (n downto 0);
|
signal muxOut : STD_LOGIC_VECTOR (n downto 0);
|
signal muxOutReg : STD_LOGIC_VECTOR (n downto 0);
|
signal muxOutReg : STD_LOGIC_VECTOR (n downto 0);
|
begin
|
begin
|
--! Instantiate Multiplexer 5:1
|
--! Instantiate Multiplexer 5:1
|
uMux: Multiplexer4_1 PORT MAP (
|
uMux: Multiplexer4_1 PORT MAP (
|
A => inputMm,
|
A => inputMm,
|
B => inputImm,
|
B => inputImm,
|
C => regFilePortA,
|
C => regFilePortA,
|
D => regFilePortB,
|
D => regFilePortB,
|
E => aluOut,
|
E => aluOut,
|
sel => muxSel,
|
sel => muxSel,
|
S => muxOut
|
S => muxOut
|
);
|
);
|
|
|
--! Instantiate Multiplexer 5:1
|
--! Instantiate Multiplexer 5:1
|
uMux2: Multiplexer3_1 PORT MAP (
|
uMux2: Multiplexer3_1 PORT MAP (
|
A => inputMm,
|
A => inputMm,
|
B => inputImm,
|
B => inputImm,
|
C => regFilePortA,
|
C => regFilePortA,
|
sel => muxRegFile,
|
sel => muxRegFile,
|
S => muxOutReg
|
S => muxOutReg
|
);
|
);
|
|
|
--! Instantiate the Unit Under Test (Alu) (Doxygen bug if it's not commented!)
|
--! Instantiate the Unit Under Test (Alu) (Doxygen bug if it's not commented!)
|
uAlu: Alu PORT MAP (
|
uAlu: Alu PORT MAP (
|
A => muxOutReg,
|
A => muxOutReg,
|
B => regFilePortB,
|
B => regFilePortB,
|
S => aluOut,
|
S => aluOut,
|
flagsOut => dpFlags,
|
flagsOut => dpFlags,
|
sel => aluOp
|
sel => aluOp
|
);
|
);
|
|
|
--! Instantiate the Unit Under Test (RegisterFile) (Doxygen bug if it's not commented!)
|
--! Instantiate the Unit Under Test (RegisterFile) (Doxygen bug if it's not commented!)
|
uRegisterFile: RegisterFile PORT MAP (
|
uRegisterFile: RegisterFile PORT MAP (
|
clk => clk,
|
clk => clk,
|
writeEn => regFileWriteEn,
|
writeEn => regFileWriteEn,
|
writeAddr => regFileWriteAddr,
|
writeAddr => regFileWriteAddr,
|
input => muxOut,
|
input => muxOut,
|
Read_A_En => regFileEnA,
|
Read_A_En => regFileEnA,
|
Read_A_Addr => regFileReadAddrA,
|
Read_A_Addr => regFileReadAddrA,
|
Read_B_En => regFileEnB,
|
Read_B_En => regFileEnB,
|
Read_B_Addr => regFileReadAddrB,
|
Read_B_Addr => regFileReadAddrB,
|
A_Out => regFilePortA,
|
A_Out => regFilePortA,
|
B_Out => regFilePortB
|
B_Out => regFilePortB
|
);
|
);
|
|
|
--!Instantiate the Unit Under Test (Multiplexer2_1) (Doxygen bug if it's not commented!)
|
--!Instantiate the Unit Under Test (Multiplexer2_1) (Doxygen bug if it's not commented!)
|
uTriState: TriStateBuffer PORT MAP (
|
uTriState: TriStateBuffer PORT MAP (
|
A => muxOut,
|
A => muxOut,
|
sel => outEn,
|
sel => outEn,
|
S => outputDp
|
S => outputDp
|
);
|
);
|
|
|
end Behavioral;
|
end Behavioral;
|
|
|
|
|