OpenCores
URL https://opencores.org/ocsvn/opencpu32/opencpu32/trunk

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [ControlUnit.vhd] - Diff between revs 27 and 28

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 27 Rev 28
Line 17... Line 17...
 
 
--! 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 ControlUnit is
entity ControlUnit 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 ( reset : in  STD_LOGIC;
         Port ( reset : in  STD_LOGIC;
           clk : in  STD_LOGIC;
           clk : in  STD_LOGIC;                                                                                         --! Main system clock
           FlagsDp : in  STD_LOGIC_VECTOR (n downto 0);
           FlagsDp : in  STD_LOGIC_VECTOR (n downto 0);                          --! Flags comming from the Datapath
           DataDp : in  STD_LOGIC_VECTOR (n downto 0);
           DataDp : in  STD_LOGIC_VECTOR (n downto 0);                           --! Data comming from the Datapath
           MuxDp : out  STD_LOGIC_VECTOR (2 downto 0);
           MuxDp : out  STD_LOGIC_VECTOR (2 downto 0);                           --! Select on datapath data from (Memory, Imediate, RegFileA, RegFileB, AluOut)
                          MuxRegDp : out STD_LOGIC_VECTOR(1 downto 0);                           --! Select Alu InputA (Memory,Imediate,RegFileA)
                          MuxRegDp : out STD_LOGIC_VECTOR(1 downto 0);                           --! Select Alu InputA (Memory,Imediate,RegFileA)
           ImmDp : out  STD_LOGIC_VECTOR (n downto 0);
           ImmDp : out  STD_LOGIC_VECTOR (n downto 0);                           --! Imediate value passed to the Datapath
           DpAluOp : out  aluOps;                                                                                       --! Alu operations
           DpAluOp : out  aluOps;                                                                                       --! Alu operations
                          DpRegFileWriteAddr : out  generalRegisters;
                          DpRegFileWriteAddr : out  generalRegisters;                           --! General register address to write
           DpRegFileWriteEn : out  STD_LOGIC;
           DpRegFileWriteEn : out  STD_LOGIC;                                                   --! Enable register write
           DpRegFileReadAddrA : out  generalRegisters;
           DpRegFileReadAddrA : out  generalRegisters;                          --! General register address to read
           DpRegFileReadAddrB : out  generalRegisters;
           DpRegFileReadAddrB : out  generalRegisters;                          --! General register address to read
           DpRegFileReadEnA : out  STD_LOGIC;
           DpRegFileReadEnA : out  STD_LOGIC;                                                   --! Enable register read (PortA)
           DpRegFileReadEnB : out  STD_LOGIC;
           DpRegFileReadEnB : out  STD_LOGIC;                                                   --! Enable register read (PortB)
           MemoryDataRead   : out std_logic;
           MemoryDataReadEn : out std_logic;                                                            --! Enable Main memory read
                          MemoryDataWrite  : out std_logic;
                          MemoryDataWriteEn: out std_logic;                                                             --! Enable Main memory write
                          MemoryDataInput : in  STD_LOGIC_VECTOR (n downto 0);
                          MemoryDataInput : in  STD_LOGIC_VECTOR (n downto 0);   --! Incoming data from main memory
           MemoryDataAddr : out  STD_LOGIC_VECTOR (n downto 0);
           MemoryDataAddr : out  STD_LOGIC_VECTOR (n downto 0);  --! Main memory write address
           MemoryDataOut : out  STD_LOGIC_VECTOR (n downto 0));
           MemoryDataOut : out  STD_LOGIC_VECTOR (n downto 0));  --! Data to write on main memory
end ControlUnit;
end ControlUnit;
 
 
--! @brief ControlUnit http://en.wikipedia.org/wiki/Control_unit
--! @brief ControlUnit http://en.wikipedia.org/wiki/Control_unit
--! @details The control unit receives external instructions or commands which it converts into a sequence of control signals that the control \n
--! @details The control unit receives external instructions or commands which it converts into a sequence of control signals that the control \n
--! unit applies to data path to implement a sequence of register-transfer level operations.
--! unit applies to data path to implement a sequence of register-transfer level operations.
Line 86... Line 86...
                        when initial =>
                        when initial =>
                                cyclesExecute := 0;
                                cyclesExecute := 0;
                                PC <= (others => '0');
                                PC <= (others => '0');
                                IR <= (others => '0');
                                IR <= (others => '0');
                                MemoryDataAddr <= (others => '0');
                                MemoryDataAddr <= (others => '0');
                                MemoryDataRead <= '0';
                                MemoryDataReadEn <= '0';
                                MemoryDataWrite <= '0';
                                MemoryDataWriteEn <= '0';
                                MemoryDataAddr <= (others => '0');
                                MemoryDataAddr <= (others => '0');
                                nextCpuState <= fetch;
                                nextCpuState <= fetch;
 
 
                        -- Fetch state (Go to memory and get a instruction)
                        -- Fetch state (Go to memory and get a instruction)
                        when fetch =>
                        when fetch =>
                                -- Increment program counter (Remember that PC will be update only on the next cycle...
                                -- Increment program counter (Remember that PC will be update only on the next cycle...
                                PC <= PC + conv_std_logic_vector(1, nBits);
                                PC <= PC + conv_std_logic_vector(1, nBits);
                                MemoryDataAddr <= PC;   -- Warning PC is not 1 yet...
                                MemoryDataAddr <= PC;   -- Warning PC is not 1 yet...
                                IR <= MemoryDataInput;
                                IR <= MemoryDataInput;
                                MemoryDataRead <= '1';
                                MemoryDataReadEn <= '1';
                                nextCpuState <= decode;
                                nextCpuState <= decode;
 
 
                        -- Detect with instruction came from memory, set the number of cycles to execute...
                        -- Detect with instruction came from memory, set the number of cycles to execute...
                        when decode =>
                        when decode =>
                                MemoryDataRead <= '0';
                                MemoryDataReadEn <= '0';
                                MemoryDataWrite <= '0';
                                MemoryDataWriteEn <= '0';
 
 
                                -- The high attribute points to the highes bit position
                                -- The high attribute points to the highes bit position
                                case opcodeIR is
                                case opcodeIR is
                                        when mov_reg | mov_val | add_reg | sub_reg | and_reg | or_reg | xor_reg =>
                                        when mov_reg | mov_val | add_reg | sub_reg | and_reg | or_reg | xor_reg =>
                                                        nextCpuState <= execute;
                                                        nextCpuState <= execute;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.