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

Subversion Repositories pavr

[/] [pavr/] [trunk/] [src/] [pavr_util.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 doru
-- <File header>
2
-- Project
3
--    pAVR (pipelined AVR) is an 8 bit RISC controller, compatible with Atmel's
4
--    AVR core, but about 3x faster in terms of both clock frequency and MIPS.
5
--    The increase in speed comes from a relatively deep pipeline. The original
6
--    AVR core has only two pipeline stages (fetch and execute), while pAVR has
7
--    6 pipeline stages:
8
--       1. PM    (read Program Memory)
9
--       2. INSTR (load Instruction)
10
--       3. RFRD  (decode Instruction and read Register File)
11
--       4. OPS   (load Operands)
12
--       5. ALU   (execute ALU opcode or access Unified Memory)
13
--       6. RFWR  (write Register File)
14
-- Version
15
--    0.32
16
-- Date
17
--    2002 August 07
18
-- Author
19
--    Doru Cuturela, doruu@yahoo.com
20
-- License
21
--    This program is free software; you can redistribute it and/or modify
22
--    it under the terms of the GNU General Public License as published by
23
--    the Free Software Foundation; either version 2 of the License, or
24
--    (at your option) any later version.
25
--    This program is distributed in the hope that it will be useful,
26
--    but WITHOUT ANY WARRANTY; without even the implied warranty of
27
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
--    GNU General Public License for more details.
29
--    You should have received a copy of the GNU General Public License
30
--    along with this program; if not, write to the Free Software
31
--    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
-- </File header>
33
 
34
 
35
 
36
-- <File info>
37
-- This file defines utilities used throughout pAVR sources:
38
--    - Bypass Unit access function
39
--       The input address is compared to all bypass entries flagged as active
40
--          (actually holding data). If match, read data from that entry, and
41
--          output it rather than the input data.
42
--       Multiple match can occur on an address.
43
--       If multiple match, the newest entry wins.
44
--       If 2 simultaneous entries match, the one in bypass chain having lower
45
--       index wins (that is, chain 0 beats chain 1 that beats chain 2). However,
46
--          this shouldn't happen (the controller should never fill the Bypass
47
--          registers with such data). That would indicate a design bug.
48
--    - Interrupt arbitrer function
49
--       This function prioritizes the interrupts.
50
--       Interfaces signals:
51
--          - input vector
52
--             This holds all interrupt flags. Interrupts trying to `come out'
53
--             are in 1 logic.
54
--          - output vector
55
--             All losing interrupts from input are disabled (0 logic). The winer
56
--             takes it all (1 logic).
57
--             The winner is the rightmost line that is in 1 logic.
58
-- </File info>
59
 
60
 
61
 
62
-- <File body>
63
library work;
64
use work.std_util.all;
65
library ieee;
66
use ieee.std_logic_1164.all;
67
 
68
 
69
 
70
package pavr_util is
71
 
72
   -- Reading through Bypass Unit
73
   function read_through_bpu(vin: std_logic_vector; vin_addr: std_logic_vector;
74
                             -- Bypass chain 0
75
                             bpr00: std_logic_vector; bpr00_addr: std_logic_vector; bpr00_active: std_logic;
76
                             bpr01: std_logic_vector; bpr01_addr: std_logic_vector; bpr01_active: std_logic;
77
                             bpr02: std_logic_vector; bpr02_addr: std_logic_vector; bpr02_active: std_logic;
78
                             bpr03: std_logic_vector; bpr03_addr: std_logic_vector; bpr03_active: std_logic;
79
                             -- Bypass chain 1
80
                             bpr10: std_logic_vector; bpr10_addr: std_logic_vector; bpr10_active: std_logic;
81
                             bpr11: std_logic_vector; bpr11_addr: std_logic_vector; bpr11_active: std_logic;
82
                             bpr12: std_logic_vector; bpr12_addr: std_logic_vector; bpr12_active: std_logic;
83
                             bpr13: std_logic_vector; bpr13_addr: std_logic_vector; bpr13_active: std_logic;
84
                             -- Bypass chain 2
85
                             bpr20: std_logic_vector; bpr20_addr: std_logic_vector; bpr20_active: std_logic;
86
                             bpr21: std_logic_vector; bpr21_addr: std_logic_vector; bpr21_active: std_logic;
87
                             bpr22: std_logic_vector; bpr22_addr: std_logic_vector; bpr22_active: std_logic;
88
                             bpr23: std_logic_vector; bpr23_addr: std_logic_vector; bpr23_active: std_logic
89
                            )
90
      return std_logic_vector;
91
 
92
   -- Prioritize interrupts
93
   function prioritize_int(vin: std_logic_vector) return std_logic_vector;
94
 
95
end;
96
 
97
 
98
 
99
package body pavr_util is
100
 
101
   -- Here, all data is expected to be 8 bits wide, and all addresses 5 bits wide.
102
   --    Even though this could have been done length independent, pAVR will never
103
   --    need that.
104
   function read_through_bpu(vin: std_logic_vector; vin_addr: std_logic_vector;
105
                             bpr00: std_logic_vector; bpr00_addr: std_logic_vector; bpr00_active: std_logic;
106
                             bpr01: std_logic_vector; bpr01_addr: std_logic_vector; bpr01_active: std_logic;
107
                             bpr02: std_logic_vector; bpr02_addr: std_logic_vector; bpr02_active: std_logic;
108
                             bpr03: std_logic_vector; bpr03_addr: std_logic_vector; bpr03_active: std_logic;
109
                             bpr10: std_logic_vector; bpr10_addr: std_logic_vector; bpr10_active: std_logic;
110
                             bpr11: std_logic_vector; bpr11_addr: std_logic_vector; bpr11_active: std_logic;
111
                             bpr12: std_logic_vector; bpr12_addr: std_logic_vector; bpr12_active: std_logic;
112
                             bpr13: std_logic_vector; bpr13_addr: std_logic_vector; bpr13_active: std_logic;
113
                             bpr20: std_logic_vector; bpr20_addr: std_logic_vector; bpr20_active: std_logic;
114
                             bpr21: std_logic_vector; bpr21_addr: std_logic_vector; bpr21_active: std_logic;
115
                             bpr22: std_logic_vector; bpr22_addr: std_logic_vector; bpr22_active: std_logic;
116
                             bpr23: std_logic_vector; bpr23_addr: std_logic_vector; bpr23_active: std_logic
117
                            )
118
   return std_logic_vector is
119
      variable bpr00_match, bpr01_match, bpr02_match, bpr03_match,
120
               bpr10_match, bpr11_match, bpr12_match, bpr13_match,
121
               bpr20_match, bpr21_match, bpr22_match, bpr23_match : std_logic;
122
      variable tmpv1, tmpv2, tmpv3, tmpv4: std_logic_vector(2 downto 0);
123
      variable r: std_logic_vector(7 downto 0);
124
   begin
125
      r := vin;
126
 
127
      bpr00_match := cmp_std_logic_vector(bpr00_addr, vin_addr);
128
      bpr01_match := cmp_std_logic_vector(bpr01_addr, vin_addr);
129
      bpr02_match := cmp_std_logic_vector(bpr02_addr, vin_addr);
130
      bpr03_match := cmp_std_logic_vector(bpr03_addr, vin_addr);
131
      bpr10_match := cmp_std_logic_vector(bpr10_addr, vin_addr);
132
      bpr11_match := cmp_std_logic_vector(bpr11_addr, vin_addr);
133
      bpr12_match := cmp_std_logic_vector(bpr12_addr, vin_addr);
134
      bpr13_match := cmp_std_logic_vector(bpr13_addr, vin_addr);
135
      bpr20_match := cmp_std_logic_vector(bpr20_addr, vin_addr);
136
      bpr21_match := cmp_std_logic_vector(bpr21_addr, vin_addr);
137
      bpr22_match := cmp_std_logic_vector(bpr22_addr, vin_addr);
138
      bpr23_match := cmp_std_logic_vector(bpr23_addr, vin_addr);
139
 
140
      tmpv1 := (bpr00_match and bpr00_active) & (bpr10_match and bpr10_active) & (bpr20_match and bpr20_active);
141
      tmpv2 := (bpr01_match and bpr01_active) & (bpr11_match and bpr11_active) & (bpr21_match and bpr21_active);
142
      tmpv3 := (bpr02_match and bpr02_active) & (bpr12_match and bpr12_active) & (bpr22_match and bpr22_active);
143
      tmpv4 := (bpr03_match and bpr03_active) & (bpr13_match and bpr13_active) & (bpr23_match and bpr23_active);
144
 
145
      case tmpv1 is
146
         when "000" =>
147
            case tmpv2 is
148
               when "000" =>
149
                  case tmpv3 is
150
                     when "000" =>
151
                        case tmpv4 is
152
                           when "000" =>
153
                              null;
154
                           when "001" =>
155
                              r := bpr23;
156
                           when "010" =>
157
                              r := bpr13;
158
                           when others =>
159
                              r := bpr03;
160
                        end case;
161
                     when "001" =>
162
                        r := bpr22;
163
                     when "010" =>
164
                        r := bpr12;
165
                     when others =>
166
                        r := bpr02;
167
                  end case;
168
               when "001" =>
169
                  r := bpr21;
170
               when "010" =>
171
                  r := bpr11;
172
               when others =>
173
                  r := bpr01;
174
            end case;
175
         when "001" =>
176
            r := bpr20;
177
         when "010" =>
178
            r := bpr10;
179
         when others =>
180
            r := bpr00;
181
      end case;
182
 
183
      return r;
184
   end;
185
 
186
 
187
 
188
   -- Input: a vector that is built by interrupt flags.
189
   -- Output: a vector derived from input, that has all elements zero, except for
190
   --    the rightmost position where a 1 occurs in the input.
191
   -- Both input and output have the width 32. That is, maximum 32 interrupt
192
   --    sources are supported.
193
   -- This should synthesize into an asynchronous device with about 5-6 elemetary
194
   --    gates delay.
195
   function prioritize_int(vin: std_logic_vector) return std_logic_vector is
196
      variable vout: std_logic_vector(31 downto 0);
197
      variable or16: std_logic;
198
      variable or8: std_logic_vector(1 downto 0);
199
      variable or4: std_logic_vector(3 downto 0);
200
      variable or2: std_logic_vector(7 downto 0);
201
   begin
202
 
203
      or16   := vin( 0) or
204
                vin( 1) or
205
                vin( 2) or
206
                vin( 3) or
207
                vin( 4) or
208
                vin( 5) or
209
                vin( 6) or
210
                vin( 7) or
211
                vin( 8) or
212
                vin( 9) or
213
                vin(10) or
214
                vin(11) or
215
                vin(12) or
216
                vin(13) or
217
                vin(14) or
218
                vin(15);
219
 
220
      or8(0) := vin( 0) or
221
                vin( 1) or
222
                vin( 2) or
223
                vin( 3) or
224
                vin( 4) or
225
                vin( 5) or
226
                vin( 6) or
227
                vin( 7);
228
 
229
      or8(1) := vin(16) or
230
                vin(17) or
231
                vin(18) or
232
                vin(19) or
233
                vin(20) or
234
                vin(21) or
235
                vin(22) or
236
                vin(23);
237
 
238
      or4(0) := vin( 0) or
239
                vin( 1) or
240
                vin( 2) or
241
                vin( 3);
242
 
243
      or4(1) := vin( 8) or
244
                vin( 9) or
245
                vin(10) or
246
                vin(11);
247
 
248
      or4(2) := vin(16) or
249
                vin(17) or
250
                vin(18) or
251
                vin(19);
252
 
253
      or4(3) := vin(24) or
254
                vin(25) or
255
                vin(26) or
256
                vin(27);
257
 
258
      or2(0) := vin( 0) or
259
                vin( 1);
260
 
261
      or2(1) := vin( 4) or
262
                vin( 5);
263
 
264
      or2(2) := vin( 8) or
265
                vin( 9);
266
 
267
      or2(3) := vin(12) or
268
                vin(13);
269
 
270
      or2(4) := vin(16) or
271
                vin(17);
272
 
273
      or2(5) := vin(20) or
274
                vin(21);
275
 
276
      or2(6) := vin(24) or
277
                vin(25);
278
 
279
      or2(7) := vin(28) or
280
                vin(29);
281
 
282
      for i in 0 to 15 loop
283
         vout(2*i)   := vin(2*i);
284
         vout(2*i+1) := vin(2*i+1) and (not vin(2*i));
285
      end loop;
286
 
287
      for i in 0 to 7 loop
288
         vout(4*i)   := vout(4*i)   and (    or2(i));
289
         vout(4*i+1) := vout(4*i+1) and (    or2(i));
290
         vout(4*i+2) := vout(4*i+2) and (not or2(i));
291
         vout(4*i+3) := vout(4*i+3) and (not or2(i));
292
      end loop;
293
 
294
      for i in 0 to 3 loop
295
         vout(8*i)   := vout(8*i)   and (    or4(i));
296
         vout(8*i+1) := vout(8*i+1) and (    or4(i));
297
         vout(8*i+2) := vout(8*i+2) and (    or4(i));
298
         vout(8*i+3) := vout(8*i+3) and (    or4(i));
299
         vout(8*i+4) := vout(8*i+4) and (not or4(i));
300
         vout(8*i+5) := vout(8*i+5) and (not or4(i));
301
         vout(8*i+6) := vout(8*i+6) and (not or4(i));
302
         vout(8*i+7) := vout(8*i+7) and (not or4(i));
303
      end loop;
304
 
305
      for i in 0 to 1 loop
306
         vout(16*i   ) := vout(16*i   ) and (    or8(i));
307
         vout(16*i+ 1) := vout(16*i+ 1) and (    or8(i));
308
         vout(16*i+ 2) := vout(16*i+ 2) and (    or8(i));
309
         vout(16*i+ 3) := vout(16*i+ 3) and (    or8(i));
310
         vout(16*i+ 4) := vout(16*i+ 4) and (    or8(i));
311
         vout(16*i+ 5) := vout(16*i+ 5) and (    or8(i));
312
         vout(16*i+ 6) := vout(16*i+ 6) and (    or8(i));
313
         vout(16*i+ 7) := vout(16*i+ 7) and (    or8(i));
314
         vout(16*i+ 8) := vout(16*i+ 8) and (not or8(i));
315
         vout(16*i+ 9) := vout(16*i+ 9) and (not or8(i));
316
         vout(16*i+10) := vout(16*i+10) and (not or8(i));
317
         vout(16*i+11) := vout(16*i+11) and (not or8(i));
318
         vout(16*i+12) := vout(16*i+12) and (not or8(i));
319
         vout(16*i+13) := vout(16*i+13) and (not or8(i));
320
         vout(16*i+14) := vout(16*i+14) and (not or8(i));
321
         vout(16*i+15) := vout(16*i+15) and (not or8(i));
322
      end loop;
323
 
324
      vout( 0) := vout( 0) and (    or16) ;
325
      vout( 1) := vout( 1) and (    or16) ;
326
      vout( 2) := vout( 2) and (    or16) ;
327
      vout( 3) := vout( 3) and (    or16) ;
328
      vout( 4) := vout( 4) and (    or16) ;
329
      vout( 5) := vout( 5) and (    or16) ;
330
      vout( 6) := vout( 6) and (    or16) ;
331
      vout( 7) := vout( 7) and (    or16) ;
332
      vout( 8) := vout( 8) and (    or16) ;
333
      vout( 9) := vout( 9) and (    or16) ;
334
      vout(10) := vout(10) and (    or16) ;
335
      vout(11) := vout(11) and (    or16) ;
336
      vout(12) := vout(12) and (    or16) ;
337
      vout(13) := vout(13) and (    or16) ;
338
      vout(14) := vout(14) and (    or16) ;
339
      vout(15) := vout(15) and (    or16) ;
340
      vout(16) := vout(16) and (not or16) ;
341
      vout(17) := vout(17) and (not or16) ;
342
      vout(18) := vout(18) and (not or16) ;
343
      vout(19) := vout(19) and (not or16) ;
344
      vout(20) := vout(20) and (not or16) ;
345
      vout(21) := vout(21) and (not or16) ;
346
      vout(22) := vout(22) and (not or16) ;
347
      vout(23) := vout(23) and (not or16) ;
348
      vout(24) := vout(24) and (not or16) ;
349
      vout(25) := vout(25) and (not or16) ;
350
      vout(26) := vout(26) and (not or16) ;
351
      vout(27) := vout(27) and (not or16) ;
352
      vout(28) := vout(28) and (not or16) ;
353
      vout(29) := vout(29) and (not or16) ;
354
      vout(30) := vout(30) and (not or16) ;
355
      vout(31) := vout(31) and (not or16) ;
356
 
357
      return vout;
358
 
359
   end;
360
 
361
 
362
end;
363
-- </File body>

powered by: WebSVN 2.1.0

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