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

Subversion Repositories System09

[/] [System09/] [rev_86/] [rtl/] [VHDL/] [trap.vhd] - Blame information for rev 169

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

Line No. Rev Author Line
1 19 dilbert57
--===========================================================================--
2
--
3
--  S Y N T H E Z I A B L E    Timer   C O R E
4
--
5
--  www.OpenCores.Org - May 2003
6
--  This core adheres to the GNU public license  
7
--
8
-- File name      : Trap.vhd
9
--
10
-- entity name    : trap
11
--
12
-- Purpose        : Implements a 8 bit address and data comparitor module
13
--
14
-- Dependencies   : ieee.Std_Logic_1164
15
--                  ieee.std_logic_unsigned
16
--
17
-- Author         : John E. Kent      
18
--
19
--===========================================================================----
20
--
21
-- Revision History:
22
--
23
-- Date:          Revision         Author
24
-- 5 May 2003     0.1              John Kent
25
--
26
--===========================================================================----
27
--
28
-- Register Memory Map
29
--
30
-- $00 - Address Comparitor High Byte
31
-- $01 - Address Comparitor Low byte
32
-- $02 - Data    Comparitor
33
-- $03 - Control Comparitor
34
-- $04 - Address Qualifier High Byte
35
-- $05 - Address Qualifier Low byte
36
-- $06 - Data    Qualifier
37
-- $07 - Control Qualifier
38
--
39
-- Address, Data and Control signals must match in the Comparitor registers 
40
-- Matches are qualified by setting a bit in the Qualifier registers
41
--
42
-- Control Comparitor / Qualify (write)
43
-- b0 - r/w        1=read  0=write
44
-- b1 - vma        1=valid 0=invalid
45
-- b7 - irq output 1=match 0=mismatch
46
--
47
-- Control Qualifier Read
48
-- b7 - match flag
49
--
50
library ieee;
51
use ieee.std_logic_1164.all;
52
use ieee.std_logic_unsigned.all;
53
 
54
entity trap is
55
        port (
56
         clk        : in  std_logic;
57
    rst        : in  std_logic;
58
    cs         : in  std_logic;
59
    rw         : in  std_logic;
60
         vma        : in  std_logic;
61
    addr       : in  std_logic_vector(15 downto 0);
62
    data_in    : in  std_logic_vector(7 downto 0);
63
         data_out   : out std_logic_vector(7 downto 0);
64
         irq        : out std_logic
65
  );
66
end;
67
 
68
architecture trap_arch of trap is
69
 
70
--
71
-- Trap registers
72
--
73
signal comp_addr_hi : std_logic_vector(7 downto 0);
74
signal comp_addr_lo : std_logic_vector(7 downto 0);
75
signal qual_addr_hi : std_logic_vector(7 downto 0);
76
signal qual_addr_lo : std_logic_vector(7 downto 0);
77
signal comp_data    : std_logic_vector(7 downto 0);
78
signal qual_data    : std_logic_vector(7 downto 0);
79
signal comp_ctrl    : std_logic_vector(7 downto 0);
80
signal qual_ctrl    : std_logic_vector(7 downto 0);
81
signal match_flag   : std_logic;
82
begin
83
 
84
 
85
--------------------------------
86
--
87
-- write control registers
88
--
89
--------------------------------
90
trap_write : process( clk, rst, cs, rw, addr, data_in,
91
                      comp_addr_hi, comp_addr_lo, comp_data, comp_ctrl,
92
                      qual_addr_hi, qual_addr_lo, qual_data, qual_ctrl )
93
begin
94
  if clk'event and clk = '0' then
95
    if rst = '1' then
96
                  comp_addr_hi <= "00000000";
97
                  comp_addr_lo <= "00000000";
98
                  comp_data    <= "00000000";
99
                  comp_ctrl    <= "00000000";
100
                  qual_addr_hi <= "00000000";
101
                  qual_addr_lo <= "00000000";
102
                  qual_data    <= "00000000";
103
                  qual_ctrl    <= "00000000";
104
    elsif cs = '1' and rw = '0' then
105
           case addr(2 downto 0) is
106
                when "000" =>
107
                  comp_addr_hi <= data_in;
108
                  comp_addr_lo <= comp_addr_lo;
109
                  comp_data    <= comp_data;
110
                  comp_ctrl    <= comp_ctrl;
111
                  qual_addr_hi <= qual_addr_hi;
112
                  qual_addr_lo <= qual_addr_lo;
113
                  qual_data    <= qual_data;
114
                  qual_ctrl    <= qual_ctrl;
115
                when "001" =>
116
                  comp_addr_hi <= comp_addr_hi;
117
                  comp_addr_lo <= data_in;
118
                  comp_data    <= comp_data;
119
                  comp_ctrl    <= comp_ctrl;
120
                  qual_addr_hi <= qual_addr_hi;
121
                  qual_addr_lo <= qual_addr_lo;
122
                  qual_data    <= qual_data;
123
                  qual_ctrl    <= qual_ctrl;
124
                when "010" =>
125
                  comp_addr_hi <= comp_addr_hi;
126
                  comp_addr_lo <= comp_addr_lo;
127
                  comp_data    <= data_in;
128
                  comp_ctrl    <= comp_ctrl;
129
                  qual_addr_hi <= qual_addr_hi;
130
                  qual_addr_lo <= qual_addr_lo;
131
                  qual_data    <= qual_data;
132
                  qual_ctrl    <= qual_ctrl;
133
                when "011" =>
134
                  comp_addr_hi <= comp_addr_hi;
135
                  comp_addr_lo <= comp_addr_lo;
136
                  comp_data    <= comp_data;
137
                  comp_ctrl    <= data_in;
138
                  qual_addr_hi <= qual_addr_hi;
139
                  qual_addr_lo <= qual_addr_lo;
140
                  qual_data    <= qual_data;
141
                  qual_ctrl    <= qual_ctrl;
142
                when "100" =>
143
                  comp_addr_hi <= comp_addr_hi;
144
                  comp_addr_lo <= comp_addr_lo;
145
                  comp_data    <= comp_data;
146
                  comp_ctrl    <= comp_ctrl;
147
                  qual_addr_hi <= data_in;
148
                  qual_addr_lo <= qual_addr_lo;
149
                  qual_data    <= qual_data;
150
                  qual_ctrl    <= qual_ctrl;
151
                when "101" =>
152
                  comp_addr_hi <= comp_addr_hi;
153
                  comp_addr_lo <= comp_addr_lo;
154
                  comp_data    <= comp_data;
155
                  comp_ctrl    <= comp_ctrl;
156
                  qual_addr_hi <= qual_addr_hi;
157
                  qual_addr_lo <= data_in;
158
                  qual_data    <= qual_data;
159
                  qual_ctrl    <= qual_ctrl;
160
                when "110" =>
161
                  comp_addr_hi <= comp_addr_hi;
162
                  comp_addr_lo <= comp_addr_lo;
163
                  comp_data    <= comp_data;
164
                  comp_ctrl    <= comp_ctrl;
165
                  qual_addr_hi <= qual_addr_hi;
166
                  qual_addr_lo <= qual_addr_lo;
167
                  qual_data    <= data_in;
168
                  qual_ctrl    <= qual_ctrl;
169
--              when "111" =>
170
      when others =>
171
                  comp_addr_hi <= comp_addr_hi;
172
                  comp_addr_lo <= comp_addr_lo;
173
                  comp_data    <= comp_data;
174
                  comp_ctrl    <= comp_ctrl;
175
                  qual_addr_hi <= qual_addr_hi;
176
                  qual_addr_lo <= qual_addr_lo;
177
                  qual_data    <= qual_data;
178
                  qual_ctrl    <= data_in;
179
                end case;
180
         else
181
                  comp_addr_hi <= comp_addr_hi;
182
                  comp_addr_lo <= comp_addr_lo;
183
                  comp_data    <= comp_data;
184
                  comp_ctrl    <= comp_ctrl;
185
                  qual_addr_hi <= qual_addr_hi;
186
                  qual_addr_lo <= qual_addr_lo;
187
                  qual_data    <= qual_data;
188
                  qual_ctrl    <= qual_ctrl;
189
         end if;
190
  end if;
191
end process;
192
 
193
--
194
-- trap data output mux
195
--
196
trap_read : process( addr,
197
                     comp_addr_hi, comp_addr_lo, comp_data, comp_ctrl,
198
                     qual_addr_hi, qual_addr_lo, qual_data, qual_ctrl,
199
                                                        match_flag )
200
begin
201
   case addr(2 downto 0) is
202
        when "000" =>
203
           data_out <= comp_addr_hi;
204
        when "001" =>
205
           data_out <= comp_addr_lo;
206
        when "010" =>
207
           data_out <= comp_data;
208
        when "011" =>
209
           data_out <= comp_ctrl;
210
        when "100" =>
211
           data_out <= qual_addr_hi;
212
        when "101" =>
213
           data_out <= qual_addr_lo;
214
        when "110" =>
215
           data_out <= qual_data;
216
--      when "111" =>
217
   when others =>
218
           data_out(6 downto 0) <= qual_ctrl(6 downto 0);
219
                data_out(7) <= match_flag;
220
        end case;
221
end process;
222
 
223
 
224
--
225
-- Trap hardware
226
--
227
trap_match : process( Clk, rst, cs, rw, addr, vma, match_flag, data_in,
228
                      comp_addr_hi, comp_addr_lo, comp_data, comp_ctrl,
229
                                                         qual_addr_hi, qual_addr_lo, qual_data, qual_ctrl)
230
variable match         : std_logic;
231
variable match_addr_hi : std_logic;
232
variable match_addr_lo : std_logic;
233
variable match_data    : std_logic;
234
variable match_ctrl    : std_logic;
235
 
236
begin
237
  match_addr_hi :=
238
           ((comp_addr_hi(7) xor addr(15)  ) and qual_addr_hi(7) ) or
239
                     ((comp_addr_hi(6) xor addr(14)  ) and qual_addr_hi(6) ) or
240
                     ((comp_addr_hi(5) xor addr(13)  ) and qual_addr_hi(5) ) or
241
                     ((comp_addr_hi(4) xor addr(12)  ) and qual_addr_hi(4) ) or
242
                     ((comp_addr_hi(3) xor addr(11)  ) and qual_addr_hi(3) ) or
243
                     ((comp_addr_hi(2) xor addr(10)  ) and qual_addr_hi(2) ) or
244
                     ((comp_addr_hi(1) xor addr( 9)  ) and qual_addr_hi(1) ) or
245
                     ((comp_addr_hi(0) xor addr( 8)  ) and qual_addr_hi(0) );
246
  match_addr_lo :=
247
                     ((comp_addr_lo(7) xor addr( 7)  ) and qual_addr_lo(7) ) or
248
                     ((comp_addr_lo(6) xor addr( 6)  ) and qual_addr_lo(6) ) or
249
                     ((comp_addr_lo(5) xor addr( 5)  ) and qual_addr_lo(5) ) or
250
                     ((comp_addr_lo(4) xor addr( 4)  ) and qual_addr_lo(4) ) or
251
                     ((comp_addr_lo(3) xor addr( 3)  ) and qual_addr_lo(3) ) or
252
                     ((comp_addr_lo(2) xor addr( 2)  ) and qual_addr_lo(2) ) or
253
                     ((comp_addr_lo(1) xor addr( 1)  ) and qual_addr_lo(1) ) or
254
                     ((comp_addr_lo(0) xor addr( 0)  ) and qual_addr_lo(0) );
255
  match_data :=
256
           ((comp_data(7)    xor data_in(7)) and qual_data(7)    ) or
257
           ((comp_data(6)    xor data_in(6)) and qual_data(6)    ) or
258
           ((comp_data(5)    xor data_in(5)) and qual_data(5)    ) or
259
           ((comp_data(4)    xor data_in(4)) and qual_data(4)    ) or
260
           ((comp_data(3)    xor data_in(3)) and qual_data(3)    ) or
261
           ((comp_data(2)    xor data_in(2)) and qual_data(2)    ) or
262
           ((comp_data(1)    xor data_in(1)) and qual_data(1)    ) or
263
           ((comp_data(0)    xor data_in(0)) and qual_data(0)    );
264
  match_ctrl :=
265
           ((comp_ctrl(0)    xor rw        ) and qual_ctrl(0)    ) or
266
           ((comp_ctrl(1)    xor vma       ) and qual_ctrl(1)    );
267
 
268
   match := not ( match_addr_hi or match_addr_lo or match_data or match_ctrl);
269
 
270
    if clk'event and clk = '0' then
271
           if rst = '1' then
272
                  match_flag <= '0';
273
      elsif cs = '1' and rw = '0' then
274
                  match_flag <= '0';
275
      else
276
                  if match = comp_ctrl(7) then
277
                    match_flag <= '1';
278
                  else
279
                    match_flag <= match_flag;
280
                  end if;
281
 
282
                end if;
283
    end if;
284
         irq <= match_flag and qual_ctrl(7);
285
  end process;
286
 
287
end trap_arch;
288
 

powered by: WebSVN 2.1.0

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