OSDN Git Service

0c56f266ccf45841f784d07e0d3ccbe2c24aa10b
[motonesfpga/motonesfpga.git] / simulation / cpu / cpu_registers.vhd
1
2 ----------------------------------------
3 --- d-flipflop with set/reset
4 ----------------------------------------
5
6 library ieee;
7 use ieee.std_logic_1164.all;
8
9 entity d_flip_flop is 
10     generic (
11             dsize : integer := 8
12             );
13     port (  
14             clk     : in std_logic;
15             res_n   : in std_logic;
16             set_n   : in std_logic;
17             we_n    : in std_logic;
18             d       : in std_logic_vector (dsize - 1 downto 0);
19             q       : out std_logic_vector (dsize - 1 downto 0)
20         );
21 end d_flip_flop;
22
23 architecture rtl of d_flip_flop is
24 begin
25
26     process (clk, res_n, set_n)
27     begin
28         if (res_n = '0') then
29             q <= (others => '0');
30         elsif (clk'event and clk = '1' and set_n = '0') then
31             q <= d;
32         elsif (clk'event and clk = '1') then
33             if (we_n = '0') then
34                 q <= d;
35             end if;
36         end if;
37     end process;
38 end rtl;
39
40 ----------------------------------------
41 --- data latch declaration
42 ----------------------------------------
43
44 library ieee;
45 use ieee.std_logic_1164.all;
46
47 entity latch is 
48     generic (
49             dsize : integer := 8
50             );
51     port (  
52             clk     : in std_logic;
53             d       : in std_logic_vector (dsize - 1 downto 0);
54             q       : out std_logic_vector (dsize - 1 downto 0)
55         );
56 end latch;
57
58 architecture rtl of latch is
59 begin
60
61     process (clk, d)
62     begin
63         if ( clk = '1') then
64             --latch only when clock is high
65             q <= d;
66         end if;
67     end process;
68 end rtl;
69
70 ----------------------------------------
71 --- tri-state buffer
72 ----------------------------------------
73
74 library ieee;
75 use ieee.std_logic_1164.all;
76
77 entity tri_state_buffer is 
78     generic (
79             dsize : integer := 8
80             );
81     port (  
82             oe_n    : in std_logic;
83             d       : in std_logic_vector (dsize - 1 downto 0);
84             q       : out std_logic_vector (dsize - 1 downto 0)
85         );
86 end tri_state_buffer;
87
88 architecture rtl of tri_state_buffer is
89 begin
90     q <= d when oe_n = '0' else
91         (others => 'Z');
92 end rtl;
93
94
95 ----------------------------------------
96 --- dual port d flip flop w/ tri-state buffer
97 ----------------------------------------
98
99 library ieee;
100 use ieee.std_logic_1164.all;
101
102 entity dual_dff is 
103     generic (
104             dsize : integer := 8
105             );
106     port (  
107             clk             : in std_logic;
108             res_n           : in std_logic;
109             set_n           : in std_logic;
110             gate_cmd        : in std_logic_vector (3 downto 0);
111             front_port      : inout std_logic_vector (dsize - 1 downto 0);
112             back_in_port    : in std_logic_vector (dsize - 1 downto 0);
113             back_out_port   : out std_logic_vector (dsize - 1 downto 0)
114         );
115 end dual_dff;
116
117 architecture rtl of dual_dff is
118
119 component d_flip_flop
120     generic (
121             dsize : integer := 8
122             );
123     port (  
124             clk     : in std_logic;
125             res_n   : in std_logic;
126             set_n   : in std_logic;
127             we_n    : in std_logic;
128             d       : in std_logic_vector (dsize - 1 downto 0);
129             q       : out std_logic_vector (dsize - 1 downto 0)
130         );
131 end component;
132
133 component tri_state_buffer
134     generic (
135             dsize : integer := 8
136             );
137     port (  
138             oe_n    : in std_logic;
139             d       : in std_logic_vector (dsize - 1 downto 0);
140             q       : out std_logic_vector (dsize - 1 downto 0)
141         );
142 end component;
143
144 signal we_n : std_logic;
145 signal q : std_logic_vector (dsize - 1 downto 0);
146 signal d : std_logic_vector (dsize - 1 downto 0);
147
148 begin
149     ----------gate_cmd format 
150     ------3 : front port oe_n
151     ------2 : front port we_n
152     ------1 : back port oe_n
153     ------0 : back port we_n
154     we_n <= (gate_cmd(2) and gate_cmd(0));
155
156     d <= front_port when gate_cmd(2) = '0' else
157          back_in_port when gate_cmd(0) = '0' else
158          (others => 'Z');
159
160     dff_inst : d_flip_flop generic map (dsize) 
161                     port map(clk, res_n, set_n, we_n, d, q);
162
163     front_tsb : tri_state_buffer generic map (dsize) 
164                     port map(gate_cmd(3), q, front_port);
165
166     back_tsb : tri_state_buffer generic map (dsize) 
167                     port map(gate_cmd(1), q, back_out_port);
168 end rtl;
169
170
171 -----------------
172
173 ----------------------------------------
174 --- data bus buffer
175 ----------------------------------------
176
177 library ieee;
178 use ieee.std_logic_1164.all;
179
180 entity data_bus_buffer is 
181     generic (
182             dsize : integer := 8
183             );
184     port (  
185             clk         : in std_logic;
186             r_nw        : in std_logic;
187             int_oe_n    : in std_logic;
188             int_dbus : inout std_logic_vector (dsize - 1 downto 0);
189             ext_dbus : inout std_logic_vector (dsize - 1 downto 0)
190         );
191 end data_bus_buffer;
192
193 architecture rtl of data_bus_buffer is
194 component latch
195     generic (
196             dsize : integer := 8
197             );
198     port (  
199             clk     : in std_logic;
200             d       : in std_logic_vector (dsize - 1 downto 0);
201             q       : out std_logic_vector (dsize - 1 downto 0)
202         );
203 end component;
204
205 component tri_state_buffer
206     generic (
207             dsize : integer := 8
208             );
209     port (  
210             oe_n    : in std_logic;
211             d       : in std_logic_vector (dsize - 1 downto 0);
212             q       : out std_logic_vector (dsize - 1 downto 0)
213         );
214 end component;
215
216 signal rd_clk : std_logic;
217 signal wr_clk : std_logic;
218 signal read_buf : std_logic_vector (dsize - 1 downto 0);
219 signal write_buf : std_logic_vector (dsize - 1 downto 0);
220 begin
221     rd_clk <= r_nw and clk;
222     wr_clk <= (not r_nw) and clk;
223
224     --read from i/o to cpu
225     latch_r : latch generic map (dsize) 
226                     port map(rd_clk, ext_dbus, read_buf);
227     read_tsb : tri_state_buffer generic map (dsize) 
228                     port map(int_oe_n, read_buf, int_dbus);
229     --write from cpu to io
230     latch_w : latch generic map (dsize) 
231                     port map(wr_clk, int_dbus, write_buf);
232     write_tsb : tri_state_buffer generic map (dsize) 
233                     port map(r_nw, write_buf, ext_dbus);
234 end rtl;
235
236 ------------------------------------------
237 ----- input data latch register
238 ------------------------------------------
239
240 library ieee;
241 use ieee.std_logic_1164.all;
242
243 entity input_data_latch is 
244     generic (
245             dsize : integer := 8
246             );
247     port (  
248             clk         : in std_logic;
249             oe_n        : in std_logic;
250             we_n        : in std_logic;
251             int_dbus    : in std_logic_vector (dsize - 1 downto 0);
252             alu_bus     : out std_logic_vector (dsize - 1 downto 0)
253         );
254 end input_data_latch;
255
256 architecture rtl of input_data_latch is
257
258 component latch
259     generic (
260             dsize : integer := 8
261             );
262     port (  
263             clk     : in std_logic;
264             d       : in std_logic_vector (dsize - 1 downto 0);
265             q       : out std_logic_vector (dsize - 1 downto 0)
266         );
267 end component;
268
269 component tri_state_buffer
270     generic (
271             dsize : integer := 8
272             );
273     port (  
274             oe_n    : in std_logic;
275             d       : in std_logic_vector (dsize - 1 downto 0);
276             q       : out std_logic_vector (dsize - 1 downto 0)
277         );
278 end component;
279
280 signal latch_clk : std_logic;
281 signal latch_buf : std_logic_vector (dsize - 1 downto 0);
282
283 begin
284     latch_clk <= (not we_n) and clk;
285     latch_inst : latch generic map (dsize) 
286                     port map(latch_clk, int_dbus, latch_buf);
287     iput_data_tsb : tri_state_buffer generic map (dsize) 
288                     port map(oe_n, latch_buf, alu_bus);
289
290 end rtl;
291
292