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

Subversion Repositories opencpu32

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

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
           regFileWriteAddr : in  generalRegisters;                                     --! General register write address
27
           regFileWriteEn : in  STD_LOGIC;                                                              --! RegisterFile write enable signal
28
           regFileReadAddrA : in  generalRegisters;                                     --! General register read address (PortA)
29
           regFileReadAddrB : in  generalRegisters;                                     --! General register read address (PortB)
30
           regFileEnA : in  STD_LOGIC;                                                                          --! Enable RegisterFile PortA
31
           regFileEnB : in  STD_LOGIC;                                                                          --! Enable RegisterFile PortB
32
                          outputDp : out  STD_LOGIC_VECTOR (n downto 0);                 --! DataPath Output
33
           dpFlags : out  STD_LOGIC_VECTOR (n downto 0));                        --! Alu Flags
34
end DataPath;
35
 
36
--! @brief DataPath http://en.wikipedia.org/wiki/Datapath
37
--! @details This description will also show how to instantiate components(Alu, RegisterFile, Multiplexer) on your design
38
architecture Behavioral of DataPath is
39
 
40 19 leonardoar
--! Component declaration to instantiate the Multiplexer circuit
41
COMPONENT Multiplexer4_1
42
        generic (n : integer := nBits - 1);                                     --! Generic value (Used to easily change the size of the Alu on the package)
43
        Port ( A   : in  STD_LOGIC_VECTOR (n downto 0);  --! First Input
44
                  B   : in  STD_LOGIC_VECTOR (n downto 0);       --! Second Input
45
                  C   : in  STD_LOGIC_VECTOR (n downto 0);       --! Third Input
46
                  D   : in  STD_LOGIC_VECTOR (n downto 0);       --! Forth Input
47
                  E   : in  STD_LOGIC_VECTOR (n downto 0);       --! Fifth Input
48
        sel : in  STD_LOGIC_VECTOR (2 downto 0); --! Select inputs (1, 2, 3, 4, 5)
49
                  S   : out  STD_LOGIC_VECTOR (n downto 0));     --! Mux Output
50
END COMPONENT;
51
 
52
--! Component declaration to instantiate the Alu circuit
53
COMPONENT Alu
54
        generic (n : integer := nBits - 1);                                     --! Generic value (Used to easily change the size of the Alu on the package)
55
        Port ( A : in  STD_LOGIC_VECTOR (n downto 0);            --! Alu Operand 1
56
                  B : in  STD_LOGIC_VECTOR (n downto 0);         --! Alu Operand 2
57
                  S : out  STD_LOGIC_VECTOR (n downto 0);                --! Alu Output
58
                  sel : in  aluOps);                                                                    --! Select operation
59
END COMPONENT;
60
 
61
--! Component declaration to instantiate the testRegisterFile circuit
62
COMPONENT RegisterFile
63
        generic (n : integer := nBits - 1);                                             --! Generic value (Used to easily change the size of the registers)
64
        Port ( clk : in  STD_LOGIC;                                                             --! Clock signal
65
                  writeEn : in  STD_LOGIC;                                                              --! Write enable
66
                  writeAddr : in  generalRegisters;                                     --! Write Adress
67
                  input : in  STD_LOGIC_VECTOR (n downto 0);             --! Input 
68
                  Read_A_En : in  STD_LOGIC;                                                    --! Enable read A
69
                  Read_A_Addr : in  generalRegisters;                           --! Read A adress
70
                  Read_B_En : in  STD_LOGIC;                                                    --! Enable read A
71
                  Read_B_Addr : in  generalRegisters;                   --! Read B adress
72
                  A_Out : out  STD_LOGIC_VECTOR (n downto 0);    --! Output A
73
                  B_Out : out  STD_LOGIC_VECTOR (n downto 0));   --! Output B
74
END COMPONENT;
75
 
76
COMPONENT TriStateBuffer
77
        generic (n : integer := nBits - 1);                             --! Generic value (Used to easily change the size of the Alu on the package)
78
        PORT(
79
                A : IN  std_logic_vector(n downto 0);            --! Buffer Input
80
                sel : IN  typeEnDis;                                                            --! Enable or Disable the output
81
                S : OUT  std_logic_vector(n downto 0)            --! Enable or Disable the output
82
          );
83
END COMPONENT;
84
 
85
-- Signals that will connect the various components from the DataPath
86
signal regFilePortA : STD_LOGIC_VECTOR (n downto 0);
87
signal regFilePortB : STD_LOGIC_VECTOR (n downto 0);
88
signal aluOut             : STD_LOGIC_VECTOR (n downto 0);
89
signal muxOut             : STD_LOGIC_VECTOR (n downto 0);
90 17 leonardoar
begin
91 19 leonardoar
        --! Instantiate Multiplexer
92
   uMux: Multiplexer4_1 PORT MAP (
93
          A => inputMm,
94
          B => inputImm,
95
                         C => regFilePortA,
96
                         D => regFilePortB,
97
                         E => aluOut,
98
          sel => muxSel,
99
          S => muxOut
100
        );
101
 
102
        --! Instantiate the Unit Under Test (Alu) (Doxygen bug if it's not commented!)
103
   uAlu: Alu PORT MAP (
104 20 leonardoar
          A => regFilePortA,
105
          B => regFilePortB,
106 19 leonardoar
          S => aluOut,
107
          sel => aluOp
108
        );
109
 
110
        --! Instantiate the Unit Under Test (RegisterFile) (Doxygen bug if it's not commented!)
111
   uRegisterFile: RegisterFile PORT MAP (
112
          clk => clk,
113
          writeEn => regFileWriteEn,
114
          writeAddr => regFileWriteAddr,
115
          input => muxOut,
116
          Read_A_En => regFileEnA,
117
          Read_A_Addr => regFileReadAddrA,
118
          Read_B_En => regFileEnB,
119
          Read_B_Addr => regFileReadAddrB,
120
          A_Out => regFilePortA,
121
          B_Out => regFilePortB
122
        );
123
 
124
        --!Instantiate the Unit Under Test (Multiplexer2_1) (Doxygen bug if it's not commented!)
125
   uTriState: TriStateBuffer PORT MAP (
126
          A => muxOut,
127
          sel => outEn,
128
          S => outputDp
129
        );
130 17 leonardoar
 
131
end Behavioral;
132
 

powered by: WebSVN 2.1.0

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