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

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [ControlUnit.vhd] - Blame information for rev 24

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 leonardoar
--! @file
2
--! @brief ControlUnit http://en.wikipedia.org/wiki/Control_unit
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
--! The control unit coordinates the input and output devices of a computer system. It fetches the code of all of the instructions \n
14
--! in the microprograms. It directs the operation of the other units by providing timing and control signals. \n
15
--! all computer resources are managed by the Control Unit.It directs the flow of data between the cpu and the other devices.\n
16
--! The outputs of the control unit control the activity of the rest of the device. A control unit can be thought of as a finite-state machine.
17
 
18
--! The purpose of datapaths is to provide routes for data to travel between functional units.
19
entity ControlUnit is
20 24 leonardoar
    generic (n : integer := nBits - 1);                                                                 --! Generic value (Used to easily change the size of the Alu on the package)
21
         Port ( reset : in  STD_LOGIC;
22 22 leonardoar
           clk : in  STD_LOGIC;
23 24 leonardoar
           FlagsDp : in  STD_LOGIC_VECTOR (n downto 0);
24
           DataDp : in  STD_LOGIC_VECTOR (n downto 0);
25 22 leonardoar
           MuxDp : out  STD_LOGIC_VECTOR (2 downto 0);
26 24 leonardoar
           ImmDp : out  STD_LOGIC_VECTOR (n downto 0);
27 22 leonardoar
           DpRegFileWriteAddr : out  STD_LOGIC;
28
           DpRegFileWriteEn : out  STD_LOGIC;
29
           DpRegFileReadAddrA : out  STD_LOGIC;
30
           DpRegFileReadAddrB : out  STD_LOGIC;
31
           DpRegFileReadEnA : out  STD_LOGIC;
32
           DpRegFileReadEnB : out  STD_LOGIC;
33 24 leonardoar
           MemoryDataRead   : out std_logic;
34
                          MemoryDataWrite  : out std_logic;
35
                          MemoryDataInput : in  STD_LOGIC_VECTOR (n downto 0);
36
           MemoryDataAddr : out  STD_LOGIC_VECTOR (n downto 0);
37
           MemoryDataOut : out  STD_LOGIC_VECTOR (n downto 0));
38 22 leonardoar
end ControlUnit;
39
 
40
--! @brief ControlUnit http://en.wikipedia.org/wiki/Control_unit
41
--! @details The control unit receives external instructions or commands which it converts into a sequence of control signals that the control \n
42
--! unit applies to data path to implement a sequence of register-transfer level operations.
43
architecture Behavioral of ControlUnit is
44 24 leonardoar
signal currentCpuState : controlUnitStates;
45
signal nextCpuState    : controlUnitStates;
46
signal PC              : std_logic_vector(n downto 0);
47
signal IR              : std_logic_vector(n downto 0);
48 22 leonardoar
begin
49 24 leonardoar
 
50
        -- Next state logic
51
        process (clk, reset)
52
        begin
53
                if (reset = '1') then
54
                        currentCpuState <= initial;
55
                        MemoryDataAddr <= (others => '0');
56
                elsif rising_edge(clk) then
57
                        currentCpuState <= nextCpuState;
58
                end if;
59
        end process;
60
 
61
        -- assd
62
        process (currentCpuState)
63
        begin
64
                case currentCpuState is
65
                        -- Initial state left from reset ...
66
                        when initial =>
67
                                PC <= (others => '0');
68
                                MemoryDataRead <= (others => '0');
69
                                MemoryDataWrite <= (others => '0');
70
                                MemoryDataAddr <= (others => '0');
71
                                nextCpuState <= fetch;
72
 
73
                        -- Fetch state (Go to memory and get a instruction)
74
                        when fetch =>
75
                                -- Increment program counter (Remember that PC will be update only on the next cycle...
76
                                PC <= PC + conv_std_logic_vector(1, nBits);
77
                                MemoryDataAddr <= PC;   -- Warning PC is not 1 yet...
78
                                IR <= MemoryDataInput;
79
                                MemoryDataRead <= '1';
80
                                nextCpuState <= decode;
81
 
82
                        -- Detect with instruction came from memory...
83
                        when decode =>
84
                                MemoryDataRead <= '0';
85
 
86
                        when others =>
87
                                null;
88
                end case;
89
        end process;
90 22 leonardoar
 
91
end Behavioral;
92
 

powered by: WebSVN 2.1.0

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