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

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [DataPath.vhd] - Blame information for rev 27

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

Line No. Rev Author Line
1 17 leonardoar
--! @file
2
--! @brief DataPath http://en.wikipedia.org/wiki/Datapath
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 datapath is a collection of functional units, such as arithmetic logic units or multipliers, that perform data processing operations.\n
14
--! Most central processing units consist of a datapath and a control unit, with a large part of the control unit dedicated to 
15
--! regulating the interaction between the datapath and main memory.
16
 
17
--! The purpose of datapaths is to provide routes for data to travel between functional units.
18
entity DataPath is
19
    generic (n : integer := nBits - 1);                                                                 --! Generic value (Used to easily change the size of the Alu on the package)
20
         Port ( inputMm : in  STD_LOGIC_VECTOR (n downto 0);                     --! Input of Datapath from main memory       
21
                          inputImm : in  STD_LOGIC_VECTOR (n downto 0);                  --! Input of Datapath from imediate value (instructions...)
22
                          clk : in  STD_LOGIC;                                                                                          --! Clock signal
23
           outEn : in  typeEnDis;                                                                                       --! Enable/Disable datapath output
24
           aluOp : in  aluOps;                                                                                          --! Alu operations
25
           muxSel : in  STD_LOGIC_VECTOR (2 downto 0);                           --! Select inputs from dataPath(Memory,Imediate,RegisterFile,Alu)
26 27 leonardoar
                          muxRegFile : in STD_LOGIC_VECTOR(1 downto 0);                          --! Select Alu InputA (Memory,Imediate,RegFileA)
27 17 leonardoar
           regFileWriteAddr : in  generalRegisters;                                     --! General register write address
28
           regFileWriteEn : in  STD_LOGIC;                                                              --! RegisterFile write enable signal
29
           regFileReadAddrA : in  generalRegisters;                                     --! General register read address (PortA)
30
           regFileReadAddrB : in  generalRegisters;                                     --! General register read address (PortB)
31
           regFileEnA : in  STD_LOGIC;                                                                          --! Enable RegisterFile PortA
32
           regFileEnB : in  STD_LOGIC;                                                                          --! Enable RegisterFile PortB
33
                          outputDp : out  STD_LOGIC_VECTOR (n downto 0);                 --! DataPath Output
34
           dpFlags : out  STD_LOGIC_VECTOR (n downto 0));                        --! Alu Flags
35
end DataPath;
36
 
37
--! @brief DataPath http://en.wikipedia.org/wiki/Datapath
38
--! @details This description will also show how to instantiate components(Alu, RegisterFile, Multiplexer) on your design
39
architecture Behavioral of DataPath is
40
 
41 19 leonardoar
--! Component declaration to instantiate the Multiplexer circuit
42
COMPONENT Multiplexer4_1
43
        generic (n : integer := nBits - 1);                                     --! Generic value (Used to easily change the size of the Alu on the package)
44
        Port ( A   : in  STD_LOGIC_VECTOR (n downto 0);  --! First Input
45
                  B   : in  STD_LOGIC_VECTOR (n downto 0);       --! Second Input
46
                  C   : in  STD_LOGIC_VECTOR (n downto 0);       --! Third Input
47
                  D   : in  STD_LOGIC_VECTOR (n downto 0);       --! Forth Input
48
                  E   : in  STD_LOGIC_VECTOR (n downto 0);       --! Fifth Input
49
        sel : in  STD_LOGIC_VECTOR (2 downto 0); --! Select inputs (1, 2, 3, 4, 5)
50
                  S   : out  STD_LOGIC_VECTOR (n downto 0));     --! Mux Output
51
END COMPONENT;
52
 
53 27 leonardoar
--! Component declaration to instantiate the Multiplexer3_1 circuit
54
COMPONENT Multiplexer3_1 is
55
    generic (n : integer := nBits - 1);                                 --! Generic value (Used to easily change the size of the Alu on the package)
56
         Port ( A : in  STD_LOGIC_VECTOR (n downto 0);           --! First Input
57
           B : in  STD_LOGIC_VECTOR (n downto 0);                --! Second Input
58
           C : in  STD_LOGIC_VECTOR (n downto 0);                --! Third Input
59
           sel : in  STD_LOGIC_VECTOR(1 downto 0);               --! Select inputs (1, 2, 3)
60
           S : out  STD_LOGIC_VECTOR (n downto 0));      --! Mux Output
61
end COMPONENT;
62
 
63 19 leonardoar
--! Component declaration to instantiate the Alu circuit
64
COMPONENT Alu
65
        generic (n : integer := nBits - 1);                                     --! Generic value (Used to easily change the size of the Alu on the package)
66
        Port ( A : in  STD_LOGIC_VECTOR (n downto 0);            --! Alu Operand 1
67
                  B : in  STD_LOGIC_VECTOR (n downto 0);         --! Alu Operand 2
68
                  S : out  STD_LOGIC_VECTOR (n downto 0);                --! Alu Output
69
                  sel : in  aluOps);                                                                    --! Select operation
70
END COMPONENT;
71
 
72
--! Component declaration to instantiate the testRegisterFile circuit
73
COMPONENT RegisterFile
74
        generic (n : integer := nBits - 1);                                             --! Generic value (Used to easily change the size of the registers)
75
        Port ( clk : in  STD_LOGIC;                                                             --! Clock signal
76
                  writeEn : in  STD_LOGIC;                                                              --! Write enable
77
                  writeAddr : in  generalRegisters;                                     --! Write Adress
78
                  input : in  STD_LOGIC_VECTOR (n downto 0);             --! Input 
79
                  Read_A_En : in  STD_LOGIC;                                                    --! Enable read A
80
                  Read_A_Addr : in  generalRegisters;                           --! Read A adress
81
                  Read_B_En : in  STD_LOGIC;                                                    --! Enable read A
82
                  Read_B_Addr : in  generalRegisters;                   --! Read B adress
83
                  A_Out : out  STD_LOGIC_VECTOR (n downto 0);    --! Output A
84
                  B_Out : out  STD_LOGIC_VECTOR (n downto 0));   --! Output B
85
END COMPONENT;
86
 
87
COMPONENT TriStateBuffer
88
        generic (n : integer := nBits - 1);                             --! Generic value (Used to easily change the size of the Alu on the package)
89
        PORT(
90
                A : IN  std_logic_vector(n downto 0);            --! Buffer Input
91
                sel : IN  typeEnDis;                                                            --! Enable or Disable the output
92
                S : OUT  std_logic_vector(n downto 0)            --! Enable or Disable the output
93
          );
94
END COMPONENT;
95
 
96
-- Signals that will connect the various components from the DataPath
97
signal regFilePortA : STD_LOGIC_VECTOR (n downto 0);
98
signal regFilePortB : STD_LOGIC_VECTOR (n downto 0);
99
signal aluOut             : STD_LOGIC_VECTOR (n downto 0);
100
signal muxOut             : STD_LOGIC_VECTOR (n downto 0);
101 27 leonardoar
signal muxOutReg          : STD_LOGIC_VECTOR (n downto 0);
102 17 leonardoar
begin
103 27 leonardoar
        --! Instantiate Multiplexer 5:1
104 19 leonardoar
   uMux: Multiplexer4_1 PORT MAP (
105
          A => inputMm,
106
          B => inputImm,
107
                         C => regFilePortA,
108
                         D => regFilePortB,
109
                         E => aluOut,
110
          sel => muxSel,
111
          S => muxOut
112
        );
113
 
114 27 leonardoar
        --! Instantiate Multiplexer 5:1
115
   uMux2: Multiplexer3_1 PORT MAP (
116
          A => inputMm,
117
          B => inputImm,
118
                         C => regFilePortA,
119
          sel => muxRegFile,
120
          S => muxOutReg
121
        );
122
 
123 19 leonardoar
        --! Instantiate the Unit Under Test (Alu) (Doxygen bug if it's not commented!)
124
   uAlu: Alu PORT MAP (
125 27 leonardoar
          A => muxOutReg,
126 20 leonardoar
          B => regFilePortB,
127 19 leonardoar
          S => aluOut,
128
          sel => aluOp
129
        );
130
 
131
        --! Instantiate the Unit Under Test (RegisterFile) (Doxygen bug if it's not commented!)
132
   uRegisterFile: RegisterFile PORT MAP (
133
          clk => clk,
134
          writeEn => regFileWriteEn,
135
          writeAddr => regFileWriteAddr,
136
          input => muxOut,
137
          Read_A_En => regFileEnA,
138
          Read_A_Addr => regFileReadAddrA,
139
          Read_B_En => regFileEnB,
140
          Read_B_Addr => regFileReadAddrB,
141
          A_Out => regFilePortA,
142
          B_Out => regFilePortB
143
        );
144
 
145
        --!Instantiate the Unit Under Test (Multiplexer2_1) (Doxygen bug if it's not commented!)
146
   uTriState: TriStateBuffer PORT MAP (
147
          A => muxOut,
148
          sel => outEn,
149
          S => outputDp
150
        );
151 17 leonardoar
 
152
end Behavioral;
153
 

powered by: WebSVN 2.1.0

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