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

Subversion Repositories t400

[/] [t400/] [trunk/] [bench/] [vhdl/] [lpm_rom.vhd] - Blame information for rev 179

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 arniml
--------------------------------------------------------------------------
2
--   This VHDL file was developed by Altera Corporation.  It may be
3
-- freely copied and/or distributed at no cost.  Any persons using this
4
-- file for any purpose do so at their own risk, and are responsible for
5
-- the results of such use.  Altera Corporation does not guarantee that
6
-- this file is complete, correct, or fit for any particular purpose.
7
-- NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.  This notice must
8
-- accompany any copy of this file.
9
--
10
--------------------------------------------------------------------------
11
-- LPM Synthesizable Models (Support string type generic)
12
--------------------------------------------------------------------------
13
-- Version 2.0 (lpm 220)      Date 01/04/00
14
--
15
-- 1. Fixed LPM_RAM_DQ, LPM_RAM_DP, LPM_RAM_IO and LPM_ROM to correctly
16
--    read in values from LPM_FILE (*.hex) when the DATA width is greater
17
--    than 16 bits.
18
-- 2. Explicit sign conversions are added to standard logic vector
19
--    comparisons in LPM_RAM_DQ, LPM_RAM_DP, LPM_RAM_IO, LPM_ROM, and
20
--    LPM_COMPARE.
21
-- 3. LPM_FIFO_DC is rewritten to have correct outputs.
22
-- 4. LPM_FIFO outputs zeros when nothing has been read from it, and
23
--    outputs LPM_NUMWORDS mod exp(2, LPM_WIDTHU) when it is full.
24
-- 5. Fixed LPM_DIVIDE to divide correctly.
25
--------------------------------------------------------------------------
26
-- Version 1.9 (lpm 220)      Date 11/30/99
27
--
28
-- 1. Fixed UNUSED file not found problem and initialization problem
29
--    with LPM_RAM_DP, LPM_RAM_DQ, and LPM_RAM_IO.
30
-- 2. Fixed LPM_MULT when SUM port is not used.
31
-- 3. Fixed LPM_FIFO_DC to enable read when rdclock and wrclock rise
32
--    at the same time.
33
-- 4. Fixed LPM_COUNTER comparison problem when signed library is loaded
34
--    and counter is incrementing.
35
-- 5. Got rid of "Illegal Character" error message at time = 0 ns when
36
--    simulating LPM_COUNTER.
37
--------------------------------------------------------------------------
38
-- Version 1.8 (lpm 220)      Date 10/25/99
39
--
40
-- 1. Some LPM_PVALUE implementations were missing, and now implemented.
41
-- 2. Fixed LPM_COUNTER to count correctly without conversion overflow,
42
--    that is, when LPM_MODULUS = 2 ** LPM_WIDTH.
43
-- 3. Fixed LPM_RAM_DP sync process sensitivity list to detect wraddress
44
--    changes.
45
--------------------------------------------------------------------------
46
-- Version 1.7 (lpm 220)      Date 07/13/99
47
--
48
-- Changed LPM_RAM_IO so that it can be used to simulate both MP2 and
49
--   Quartus behaviour and LPM220-compliant behaviour.
50
--------------------------------------------------------------------------
51
-- Version 1.6 (lpm 220)      Date 06/15/99
52
--
53
-- 1. Fixed LPM_ADD_SUB sign extension problem and subtraction bug.
54
-- 2. Fixed LPM_COUNTER to use LPM_MODULUS value.
55
-- 3. Added CIN and COUT port, and discarded EQ port in LPM_COUNTER to
56
--    comply with the specfication.
57
-- 4. Included LPM_RAM_DP, LPM_RAM_DQ, LPM_RAM_IO, LPM_ROM, LPM_FIFO, and
58
--    LPM_FIFO_DC; they are all initialized to 0's.
59
--------------------------------------------------------------------------
60
-- Version 1.5 (lpm 220)      Date 05/10/99
61
--
62
-- Changed LPM_MODULUS from string type to integer.
63
--------------------------------------------------------------------------
64
-- Version 1.4 (lpm 220)      Date 02/05/99
65
-- 
66
-- 1. Added LPM_DIVIDE module.
67
-- 2. Added CLKEN port to LPM_MUX, LPM_DECODE, LPM_ADD_SUB, LPM_MULT
68
--    and LPM_COMPARE
69
-- 3. Replaced the constants holding string with the actual string.
70
--------------------------------------------------------------------------
71
-- Version 1.3                Date 07/30/96
72
--
73
-- Modification History
74
--
75
-- 1. Changed the DEFAULT value to "UNUSED" for LPM_SVALUE, LPM_AVALUE,
76
-- LPM_MODULUS, and LPM_NUMWORDS, LPM_HINT,LPM_STRENGTH, LPM_DIRECTION,
77
-- and LPM_PVALUE
78
--
79
-- 2. Added the two dimentional port components (AND, OR, XOR, and MUX).
80
--------------------------------------------------------------------------
81
-- Excluded Functions:
82
--
83
--   LPM_FSM and LPM_TTABLE
84
--
85
--------------------------------------------------------------------------
86
-- Assumptions:
87
--
88
-- 1. All ports and signal types are std_logic or std_logic_vector
89
--    from IEEE 1164 package.
90
-- 2. Synopsys std_logic_arith, std_logic_unsigned, and std_logic_signed
91
--    package are assumed to be accessible from IEEE library.
92
-- 3. lpm_component_package must be accessible from library work.
93
-- 4. The default value of LPM_SVALUE, LPM_AVALUE, LPM_MODULUS, LPM_HINT,
94
--    LPM_NUMWORDS, LPM_STRENGTH, LPM_DIRECTION, and LPM_PVALUE is
95
--    string "UNUSED".
96
--------------------------------------------------------------------------
97
 
98
library IEEE;
99
use IEEE.std_logic_1164.all;
100
use IEEE.numeric_std.all;
101
--use work.LPM_COMPONENTS.all;
102
use std.textio.all;
103
 
104
entity LPM_ROM is
105
        generic (LPM_WIDTH : positive;
106
                         LPM_WIDTHAD : positive;
107
                         LPM_NUMWORDS : natural := 0;
108
                         LPM_ADDRESS_CONTROL : string := "REGISTERED";
109
                         LPM_OUTDATA : string := "REGISTERED";
110
                         LPM_FILE : string;
111
                         LPM_TYPE : string := "LPM_ROM";
112
                         LPM_HINT : string := "UNUSED");
113
        port (ADDRESS : in STD_LOGIC_VECTOR(LPM_WIDTHAD-1 downto 0);
114
                  INCLOCK : in STD_LOGIC := '0';
115
                  OUTCLOCK : in STD_LOGIC := '0';
116
                  MEMENAB : in STD_LOGIC := '1';
117
                  Q : out STD_LOGIC_VECTOR(LPM_WIDTH-1 downto 0));
118
 
119
        function int_to_str( value : integer ) return string is
120
        variable ivalue,index : integer;
121
        variable digit : integer;
122
        variable line_no: string(8 downto 1) := "        ";
123
        begin
124
                ivalue := value;
125
                index := 1;
126
                while (ivalue > 0 ) loop
127
                        digit := ivalue MOD 10;
128
                        ivalue := ivalue/10;
129
                        case digit is
130
                                when 0 =>
131
                                        line_no(index) := '0';
132
                                when 1 =>
133
                                        line_no(index) := '1';
134
                                when 2 =>
135
                                        line_no(index) := '2';
136
                                when 3 =>
137
                                        line_no(index) := '3';
138
                                when 4 =>
139
                                        line_no(index) := '4';
140
                                when 5 =>
141
                                        line_no(index) := '5';
142
                                when 6 =>
143
                                        line_no(index) := '6';
144
                                when 7 =>
145
                                        line_no(index) := '7';
146
                                when 8 =>
147
                                        line_no(index) := '8';
148
                                when 9 =>
149
                                        line_no(index) := '9';
150
                                when others =>
151
                                        ASSERT FALSE
152
                                        REPORT "Illegal number!"
153
                                        SEVERITY ERROR;
154
                        end case;
155
                        index := index + 1;
156
                end loop;
157
                return line_no;
158
        end;
159
 
160
        function hex_str_to_int( str : string ) return integer is
161
        variable len : integer := str'length;
162
        variable ivalue : integer := 0;
163
        variable digit : integer;
164
        begin
165
                for i in len downto 1 loop
166
                        case str(i) is
167
                                when '0' =>
168
                                        digit := 0;
169
                                when '1' =>
170
                                        digit := 1;
171
                                when '2' =>
172
                                        digit := 2;
173
                                when '3' =>
174
                                        digit := 3;
175
                                when '4' =>
176
                                        digit := 4;
177
                                when '5' =>
178
                                        digit := 5;
179
                                when '6' =>
180
                                        digit := 6;
181
                                when '7' =>
182
                                        digit := 7;
183
                                when '8' =>
184
                                        digit := 8;
185
                                when '9' =>
186
                                        digit := 9;
187
                                when 'A' =>
188
                                        digit := 10;
189
                                when 'a' =>
190
                                        digit := 10;
191
                                when 'B' =>
192
                                        digit := 11;
193
                                when 'b' =>
194
                                        digit := 11;
195
                                when 'C' =>
196
                                        digit := 12;
197
                                when 'c' =>
198
                                        digit := 12;
199
                                when 'D' =>
200
                                        digit := 13;
201
                                when 'd' =>
202
                                        digit := 13;
203
                                when 'E' =>
204
                                        digit := 14;
205
                                when 'e' =>
206
                                        digit := 14;
207
                                when 'F' =>
208
                                        digit := 15;
209
                                when 'f' =>
210
                                        digit := 15;
211
                                when others =>
212
                                        ASSERT FALSE
213
                                        REPORT "Illegal character "&  str(i) & "in Intel Hex File! "
214
                                        SEVERITY ERROR;
215
                        end case;
216
                        ivalue := ivalue * 16 + digit;
217
                end loop;
218
                return ivalue;
219
        end;
220
 
221
        procedure Shrink_line(L : inout LINE; pos : in integer) is
222
        subtype nstring is string(1 to pos);
223
        variable stmp : nstring;
224
        begin
225
                if pos >= 1 then
226
                        read(l, stmp);
227
                end if;
228
        end;
229
 
230
end LPM_ROM;
231
 
232
architecture LPM_SYN of lpm_rom is
233
 
234
--type lpm_memory is array(lpm_numwords-1 downto 0) of std_logic_vector(lpm_width-1 downto 0);
235
type lpm_memory is array(integer range (2**lpm_widthad)-1 downto 0) of std_logic_vector(lpm_width-1 downto 0);
236
 
237
signal q2, q_tmp, q_reg : std_logic_vector(lpm_width-1 downto 0);
238
signal address_tmp, address_reg : std_logic_vector(lpm_widthad-1 downto 0);
239
 
240
begin
241
 
242
        enable_mem: process(memenab, q2)
243
        begin
244
                if (memenab = '1') then
245
                        q <= q2;
246
                else
247
                        q <= (OTHERS => 'Z');
248
                end if;
249
        end process;
250
 
251
        sync: process(address, address_reg, q_tmp, q_reg)
252
        begin
253
                if (lpm_address_control = "REGISTERED") then
254
                        address_tmp <= address_reg;
255
                else
256
                        address_tmp <= address;
257
                end if;
258
                if (lpm_outdata = "REGISTERED") then
259
                        q2 <= q_reg;
260
                else
261
                        q2 <= q_tmp;
262
                end if;
263
        end process;
264
 
265
        input_reg: process (inclock)
266
        begin
267
    if inclock'event and inclock = '1' then
268
                        address_reg <= address;
269
                end if;
270
        end process;
271
 
272
        output_reg: process (outclock)
273
        begin
274
                if outclock'event and outclock = '1' then
275
                        q_reg <= q_tmp;
276
                end if;
277
        end process;
278
 
279
        memory: process(memenab, address_tmp)
280
        variable mem_data : lpm_memory;
281
        variable mem_data_tmp : integer := 0;
282
        variable mem_init: boolean := false;
283
        variable i, j, k, lineno : integer := 0;
284
        variable buf: line ;
285
        variable booval: boolean ;
286
        FILE mem_data_file: TEXT IS IN LPM_FILE;
287
        variable base, byte, rec_type, datain, addr, checksum: string(2 downto 1);
288
        variable startadd: string(4 downto 1);
289
        variable ibase: integer := 0;
290
        variable ibyte: integer := 0;
291
        variable istartadd: integer := 0;
292
        variable check_sum_vec, check_sum_vec_tmp: unsigned(7 downto 0);
293
        begin
294
                -- INITIALIZE --
295
                if NOT(mem_init) then
296
                        -- INITIALIZE TO 0 --
297
                        for i in mem_data'LOW to mem_data'HIGH loop
298
                                mem_data(i) := (OTHERS => '0');
299
                        end loop;
300
 
301
                        if (LPM_FILE = "UNUSED") then
302
                                ASSERT FALSE
303
                                REPORT "Initialization file not found!"
304
                                SEVERITY ERROR;
305
                        else
306
                                WHILE NOT ENDFILE(mem_data_file) loop
307
                                        booval := true;
308
                                        READLINE(mem_data_file, buf);
309
                                        lineno := lineno + 1;
310
                                        check_sum_vec := (OTHERS => '0');
311
                                        if (buf(buf'LOW) = ':') then
312
                                                i := 1;
313
                                                shrink_line(buf, i);
314
                                                READ(L=>buf, VALUE=>byte, good=>booval);
315
                                                if not (booval) then
316
                                                        ASSERT FALSE
317
                                                        REPORT "[Line "& int_to_str(lineno) & "]:Illegal Intel Hex Format!"
318
                                                        SEVERITY ERROR;
319
                                                end if;
320
                                                ibyte := hex_str_to_int(byte);
321
                                                check_sum_vec := unsigned(check_sum_vec) + to_unsigned(ibyte, 8);
322
                                                READ(L=>buf, VALUE=>startadd, good=>booval);
323
                                                if not (booval) then
324
                                                        ASSERT FALSE
325
                                                        REPORT "[Line "& int_to_str(lineno) & "]:Illegal Intel Hex Format! "
326
                                                        SEVERITY ERROR;
327
                                                end if;
328
                                                istartadd := hex_str_to_int(startadd);
329
                                                addr(2) := startadd(4);
330
                                                addr(1) := startadd(3);
331
                                                check_sum_vec := unsigned(check_sum_vec) + to_unsigned(hex_str_to_int(addr), check_sum_vec'length);
332
                                                addr(2) := startadd(2);
333
                                                addr(1) := startadd(1);
334
                                                check_sum_vec := unsigned(check_sum_vec) + to_unsigned(hex_str_to_int(addr), check_sum_vec'length);
335
                                                READ(L=>buf, VALUE=>rec_type, good=>booval);
336
                                                if not (booval) then
337
                                                        ASSERT FALSE
338
                                                        REPORT "[Line "& int_to_str(lineno) & "]:Illegal Intel Hex Format! "
339
                                                        SEVERITY ERROR;
340
                                                end if;
341
                                                check_sum_vec := unsigned(check_sum_vec) + to_unsigned(hex_str_to_int(rec_type), check_sum_vec'length);
342
                                        else
343
                                                ASSERT FALSE
344
                                                REPORT "[Line "& int_to_str(lineno) & "]:Illegal Intel Hex Format! "
345
                                                SEVERITY ERROR;
346
                                        end if;
347
                                        case rec_type is
348
                                                when "00"=>  -- Data record
349
                                                        i := 0;
350
                                                        k := lpm_width / 8;
351
                                                        if ((lpm_width MOD 8) /= 0) then
352
                                                                k := k + 1;
353
                                                        end if;
354
                                                        -- k = no. of bytes per CAM entry.
355
                                                        while (i < ibyte) loop
356
                                                                mem_data_tmp := 0;
357
                                                                for j in 1 to k loop
358
                                                                        READ(L=>buf, VALUE=>datain,good=>booval); -- read in data a byte (2 hex chars) at a time.
359
                                                                        if not (booval) then
360
                                                                                ASSERT FALSE
361
                                                                                REPORT "[Line "& int_to_str(lineno) & "]:Illegal Intel Hex Format! "
362
                                                                                SEVERITY ERROR;
363
                                                                        end if;
364
                                                                        check_sum_vec := unsigned(check_sum_vec) + to_unsigned(hex_str_to_int(datain), check_sum_vec'length);
365
                                                                        mem_data_tmp := mem_data_tmp * 256 + hex_str_to_int(datain);
366
                                                                end loop;
367
                                                                i := i + k;
368
                                                                mem_data(ibase + istartadd) := STD_LOGIC_VECTOR(to_unsigned(mem_data_tmp, lpm_width));
369
                                                                istartadd := istartadd + 1;
370
                                                        end loop;
371
                                                when "01"=>
372
                                                        exit;
373
                                                when "02"=>
374
                                                        ibase := 0;
375
                                                        if (ibyte /= 2) then
376
                                                                ASSERT FALSE
377
                                                                REPORT "[Line "& int_to_str(lineno) & "]:Illegal Intel Hex Format for record type 02! "
378
                                                                SEVERITY ERROR;
379
                                                        end if;
380
                                                        for i in 0 to (ibyte-1) loop
381
                                                                READ(L=>buf, VALUE=>base,good=>booval);
382
                                                                ibase := ibase * 256 + hex_str_to_int(base);
383
                                                                if not (booval) then
384
                                                                        ASSERT FALSE
385
                                                                        REPORT "[Line "& int_to_str(lineno) & "]:Illegal Intel Hex Format! "
386
                                                                        SEVERITY ERROR;
387
                                                                end if;
388
                                                                check_sum_vec := unsigned(check_sum_vec) + to_unsigned(hex_str_to_int(base), check_sum_vec'length);
389
                                                        end loop;
390
                                                        ibase := ibase * 16;
391
                                                when OTHERS =>
392
                                                        ASSERT FALSE
393
                                                        REPORT "[Line "& int_to_str(lineno) & "]:Illegal record type in Intel Hex File! "
394
                                                        SEVERITY ERROR;
395
                                        end case;
396
                                        READ(L=>buf, VALUE=>checksum,good=>booval);
397
                                        if not (booval) then
398
                                                ASSERT FALSE
399
                                                REPORT "[Line "& int_to_str(lineno) & "]:Checksum is missing! "
400
                                                SEVERITY ERROR;
401
                                        end if;
402
 
403
                                        check_sum_vec := unsigned(not (check_sum_vec)) + 1 ;
404
                                        check_sum_vec_tmp := to_unsigned(hex_str_to_int(checksum),8);
405
 
406
                                        if (unsigned(check_sum_vec) /= unsigned(check_sum_vec_tmp)) then
407
                                                ASSERT FALSE
408
                                                REPORT "[Line "& int_to_str(lineno) & "]:Incorrect checksum!"
409
                                                SEVERITY ERROR;
410
                                        end if;
411
                                end loop;
412
                        end if;
413
                        mem_init := TRUE;
414
                end if;
415
 
416
                -- MEMORY FUNCTION --
417
                --if memenab = '1' then
418
                        q_tmp <= mem_data(to_integer(UNSIGNED(address_tmp)));
419
                --else
420
                --    q_tmp <= (OTHERS => 'Z');
421
                --end if;
422
        end process;
423
 
424
end LPM_SYN;
425
 
426
 
427
---------------------------------------------------------------------------
428
 
429
 
430
-- pragma translate_off
431
configuration lpm_rom_c0 of lpm_rom is
432
 
433
  for lpm_syn
434
  end for;
435
 
436
end lpm_rom_c0;
437
-- pragma translate_on

powered by: WebSVN 2.1.0

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