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

Subversion Repositories p9813_rgb_led_string_driver

[/] [p9813_rgb_led_string_driver/] [trunk/] [rtl/] [VHDL/] [testbench/] [sim_support_pack.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jclaytons
-- A package containing various synthesizable functions useful in VHDL
2
--
3
-- Author : John Clayton
4
--
5
 
6
library ieee;
7
use ieee.std_logic_1164.all;
8
use ieee.numeric_std.all;
9
use ieee.math_real.all;
10
use std.textio.all;
11
 
12
library work;
13
use work.function_pack.all;
14
 
15
package sim_support_pack is
16
 
17
------------------------------------------------------------------------------------
18
-- function calls
19
------------------------------------------------------------------------------------
20
    function string_to_integer (in_string : string) return integer ;
21
    function vector_to_string (in_vector : std_logic_vector) return string ;
22
    function char_to_bit (in_char : character) return std_logic ;
23
    function char_to_hex (in_char : character) return std_logic_vector ;
24
 
25
    function slv2string(in_vector : std_logic_vector; nibbles : natural) return string ;
26
    function u2string(in_vector : unsigned; nibbles : natural) return string ;
27
    function u2asciichar(in_vector : unsigned(7 downto 0)) return character ;
28
    function asciichar2u(in_char : character) return unsigned;
29
 
30
    function hex_to_ascii(in_vector : std_logic_vector; nibbles : natural) return string ;
31
    function u2ascii(in_vector : unsigned; nibbles : natural) return string ;
32
    function hex_data_wrd(in_vector : std_logic_vector) return string ;
33
    function hex_data_dblwrd(in_vector : std_logic_vector) return string ;
34
    function hex_data_dblwrdz(in_vector : std_logic_vector) return string ;
35
    function str2u2(s: string) return unsigned; -- Converts a string of ASCII characters into unsigned
36
 
37
    function is_hex(c : character) return boolean;
38
    function is_std_logic(c : character) return boolean;
39
    function is_space(c : character) return boolean;
40
 
41
 
42
------------------------------------------------------------------------------------
43
-- procedures
44
------------------------------------------------------------------------------------
45
 
46
 
47
end sim_support_pack;
48
 
49
 
50
package body sim_support_pack is
51
 
52
------------------------------------------------------------------------------------
53
-- 
54
------------------------------------------------------------------------------------
55
--* Title           :  TEST_PARITY
56
--* Filename & Ext  :  test_parity.vhdl
57
--* Author          :  David Bishop X-66788
58
--* Created         :  3/18/97
59
--* Version         :  1.2
60
--* Revision Date   :  97/04/15
61
--* SCCSid          :  1.2 04/15/97 test_parity.vhdl
62
--* WORK Library    :  testchip
63
--* Mod History     :  
64
--* Description     :  This is a parity generator which is written recursively
65
--*                 :  It is designed to test the ability of Simulation and
66
--*                 :  Synthesis tools to check this capability.
67
--* Known Bugs      :  
68
--* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
69
 
70
 
71
  function u_recursive_parity ( x : unsigned ) return std_logic is
72
    variable Upper, Lower : std_logic;
73
    variable Half : integer;
74
    variable BUS_int : unsigned( x'length-1 downto 0 );
75
    variable Result : std_logic;
76
  begin
77
    BUS_int := x;
78
    if ( BUS_int'length = 1 ) then
79
      Result := BUS_int ( BUS_int'left );
80
    elsif ( BUS_int'length = 2 ) then
81
      Result := BUS_int ( BUS_int'right ) xor BUS_int ( BUS_int'left );
82
    else
83
      Half := ( BUS_int'length + 1 ) / 2 + BUS_int'right;
84
      Upper := u_recursive_parity ( BUS_int ( BUS_int'left downto Half ));
85
      Lower := u_recursive_parity ( BUS_int ( Half - 1 downto BUS_int'right ));
86
      Result := Upper xor Lower;
87
    end if;
88
    return Result;
89
  end;
90
 
91
------------------------------------------------------------------------------------
92
-- 
93
------------------------------------------------------------------------------------
94
 
95
    function vector_to_string (in_vector : std_logic_vector) return string is
96
 
97
    variable out_string : string(32 downto 1);
98
 
99
    begin
100
 
101
      for i in in_vector'range loop
102
        if in_vector(i) = '1' then
103
          out_string(i+1) := '1';
104
        elsif in_vector(i) = '0' then
105
          out_string(i+1) := '0';
106
            else
107
                assert false
108
                report " illegal bit vector to bit string"
109
                severity note;
110
        end if;
111
      end loop;
112
      return out_string;
113
 
114
    end vector_to_string;
115
 
116
------------------------------------------------------------------------------------
117
-- 
118
------------------------------------------------------------------------------------
119
 
120
    function string_to_integer (in_string : string) return integer is
121
 
122
    variable int : integer := 0;
123
    begin
124
 
125
        for j in in_string'range loop
126
          case in_string(j) is
127
            when '0' => int := int;
128
            when '1' => int := int + (1 * 10**(j-1));
129
            when '2' => int := int + (2 * 10**(j-1));
130
            when '3' => int := int + (3 * 10**(j-1));
131
            when '4' => int := int + (4 * 10**(j-1));
132
            when '5' => int := int + (5 * 10**(j-1));
133
            when '6' => int := int + (6 * 10**(j-1));
134
            when '7' => int := int + (7 * 10**(j-1));
135
            when '8' => int := int + (8 * 10**(j-1));
136
            when '9' => int := int + (9 * 10**(j-1));
137
            when others =>
138
                assert false
139
                report " illegal character to integer"
140
                severity note;
141
          end case;
142
        end loop;
143
        return  int;
144
    end string_to_integer;
145
 
146
------------------------------------------------------------------------------------
147
-- 
148
------------------------------------------------------------------------------------
149
 
150
    function char_to_bit (in_char : character) return std_logic is
151
 
152
    variable out_bit : std_logic;
153
 
154
    begin
155
 
156
        if (in_char = '1') then
157
            out_bit := '1';
158
        elsif (in_char = '0') then
159
            out_bit := '0';
160
        else
161
            assert false
162
            report "illegal character to bit"
163
            severity note;
164
        end if;
165
 
166
        return out_bit;
167
    end char_to_bit;
168
 
169
------------------------------------------------------------------------------------
170
-- 
171
------------------------------------------------------------------------------------
172
    function char_to_hex (in_char : character) return std_logic_vector is
173
 
174
    variable out_vec : std_logic_vector(3 downto 0);
175
 
176
 
177
    begin
178
            case in_char is
179
              when '0' => out_vec := "0000";
180
              when '1' => out_vec := "0001";
181
              when '2' => out_vec := "0010";
182
              when '3' => out_vec := "0011";
183
              when '4' => out_vec := "0100";
184
              when '5' => out_vec := "0101";
185
              when '6' => out_vec := "0110";
186
              when '7' => out_vec := "0111";
187
              when '8' => out_vec := "1000";
188
              when '9' => out_vec := "1001";
189
              when 'A' | 'a' => out_vec := "1010";
190
              when 'B' | 'b' => out_vec := "1011";
191
              when 'C' | 'c' => out_vec := "1100";
192
              when 'D' | 'd' => out_vec := "1101";
193
              when 'E' | 'e' => out_vec := "1110";
194
              when 'F' | 'f' => out_vec := "1111";
195
              when others =>
196
                assert false
197
                report " illegal character to hex"
198
                severity note;
199
          end case;
200
        return out_vec;
201
    end char_to_hex;
202
 
203
------------------------------------------------------------------------------------
204
-- 
205
------------------------------------------------------------------------------------
206
 
207
    function slv2string(in_vector : std_logic_vector; nibbles : natural) return string is
208
    variable out_string : string(1 to nibbles);
209
    variable temp_in_vector : std_logic_vector(4*nibbles-1 downto 0);
210
    variable vector     : std_logic_vector(3 downto 0);
211
 
212
    begin
213
    temp_in_vector := in_vector(in_vector'length-1 downto in_vector'length-temp_in_vector'length);
214
        for i in 1 to nibbles loop
215
            vector := temp_in_vector((4*(nibbles-i)+3) downto 4*(nibbles-i));
216
            case vector is
217
                when "0000" => out_string(i) := '0';
218
                when "0001" => out_string(i) := '1';
219
                when "0010" => out_string(i) := '2';
220
                when "0011" => out_string(i) := '3';
221
                when "0100" => out_string(i) := '4';
222
                when "0101" => out_string(i) := '5';
223
                when "0110" => out_string(i) := '6';
224
                when "0111" => out_string(i) := '7';
225
                when "1000" => out_string(i) := '8';
226
                when "1001" => out_string(i) := '9';
227
                when "1010" => out_string(i) := 'A';
228
                when "1011" => out_string(i) := 'B';
229
                when "1100" => out_string(i) := 'C';
230
                when "1101" => out_string(i) := 'D';
231
                when "1110" => out_string(i) := 'E';
232
                when "1111" => out_string(i) := 'F';
233
                when others =>
234
                   out_string(i) := 'J';
235
                   assert false
236
                   report " illegal std_logic_vector to string"
237
                   severity note;
238
            end case;
239
        end loop;
240
        return out_string;
241
     end;
242
 
243
------------------------------------------------------------------------------------
244
-- 
245
------------------------------------------------------------------------------------
246
 
247
    function u2string(in_vector : unsigned; nibbles : natural) return string is
248
    variable out_string     : string(1 to nibbles);
249
    variable temp_in_vector : unsigned(4*nibbles-1 downto 0);
250
    variable vector         : unsigned(3 downto 0);
251
 
252
    begin
253
    temp_in_vector := in_vector(in_vector'length-1 downto in_vector'length-temp_in_vector'length);
254
        for i in 1 to nibbles loop
255
            vector := temp_in_vector((4*(nibbles-i)+3) downto 4*(nibbles-i));
256
            case vector is
257
                when "0000" => out_string(i) := '0';
258
                when "0001" => out_string(i) := '1';
259
                when "0010" => out_string(i) := '2';
260
                when "0011" => out_string(i) := '3';
261
                when "0100" => out_string(i) := '4';
262
                when "0101" => out_string(i) := '5';
263
                when "0110" => out_string(i) := '6';
264
                when "0111" => out_string(i) := '7';
265
                when "1000" => out_string(i) := '8';
266
                when "1001" => out_string(i) := '9';
267
                when "1010" => out_string(i) := 'A';
268
                when "1011" => out_string(i) := 'B';
269
                when "1100" => out_string(i) := 'C';
270
                when "1101" => out_string(i) := 'D';
271
                when "1110" => out_string(i) := 'E';
272
                when "1111" => out_string(i) := 'F';
273
                when others =>
274
                   out_string(i) := 'U';
275
                   assert false report " illegal unsigned to string" severity note;
276
            end case;
277
        end loop;
278
        return out_string;
279
     end;
280
 
281
------------------------------------------------------------------------------------
282
-- 
283
------------------------------------------------------------------------------------
284
 
285
    function u2asciichar(in_vector : unsigned(7 downto 0)) return character is
286
    variable out_char       : character;
287
 
288
    begin
289
      case in_vector is
290
          when "00001001" => out_char :=  HT; -- Horizontal Tab
291
          when "00100000" => out_char := ' ';
292
          when "00100001" => out_char := '!';
293
          when "00100010" => out_char := '"';
294
          when "00100011" => out_char := '#';
295
          when "00100100" => out_char := '$';
296
          when "00100101" => out_char := '%';
297
          when "00100110" => out_char := '&';
298
          when "00100111" => out_char := ''';
299
          when "00101000" => out_char := '(';
300
          when "00101001" => out_char := ')';
301
          when "00101010" => out_char := '*';
302
          when "00101011" => out_char := '+';
303
          when "00101100" => out_char := ',';
304
          when "00101101" => out_char := '-';
305
          when "00101110" => out_char := '.';
306
          when "00101111" => out_char := '/';
307
          when "00110000" => out_char := '0';
308
          when "00110001" => out_char := '1';
309
          when "00110010" => out_char := '2';
310
          when "00110011" => out_char := '3';
311
          when "00110100" => out_char := '4';
312
          when "00110101" => out_char := '5';
313
          when "00110110" => out_char := '6';
314
          when "00110111" => out_char := '7';
315
          when "00111000" => out_char := '8';
316
          when "00111001" => out_char := '9';
317
          when "00111010" => out_char := ':';
318
          when "00111011" => out_char := ';';
319
          when "00111100" => out_char := '<';
320
          when "00111101" => out_char := '=';
321
          when "00111110" => out_char := '>';
322
          when "00111111" => out_char := '?';
323
          when "01000000" => out_char := '@';
324
          when "01000001" => out_char := 'A';
325
          when "01000010" => out_char := 'B';
326
          when "01000011" => out_char := 'C';
327
          when "01000100" => out_char := 'D';
328
          when "01000101" => out_char := 'E';
329
          when "01000110" => out_char := 'F';
330
          when "01000111" => out_char := 'G';
331
          when "01001000" => out_char := 'H';
332
          when "01001001" => out_char := 'I';
333
          when "01001010" => out_char := 'J';
334
          when "01001011" => out_char := 'K';
335
          when "01001100" => out_char := 'L';
336
          when "01001101" => out_char := 'M';
337
          when "01001110" => out_char := 'N';
338
          when "01001111" => out_char := 'O';
339
          when "01010000" => out_char := 'P';
340
          when "01010001" => out_char := 'Q';
341
          when "01010010" => out_char := 'R';
342
          when "01010011" => out_char := 'S';
343
          when "01010100" => out_char := 'T';
344
          when "01010101" => out_char := 'U';
345
          when "01010110" => out_char := 'V';
346
          when "01010111" => out_char := 'W';
347
          when "01011000" => out_char := 'X';
348
          when "01011001" => out_char := 'Y';
349
          when "01011010" => out_char := 'Z';
350
          when "01011011" => out_char := '[';
351
          when "01011100" => out_char := '\';
352
          when "01011101" => out_char := ']';
353
          when "01011110" => out_char := '^';
354
          when "01011111" => out_char := '_';
355
          when "01100000" => out_char := '`';
356
          when "01100001" => out_char := 'a';
357
          when "01100010" => out_char := 'b';
358
          when "01100011" => out_char := 'c';
359
          when "01100100" => out_char := 'd';
360
          when "01100101" => out_char := 'e';
361
          when "01100110" => out_char := 'f';
362
          when "01100111" => out_char := 'g';
363
          when "01101000" => out_char := 'h';
364
          when "01101001" => out_char := 'i';
365
          when "01101010" => out_char := 'j';
366
          when "01101011" => out_char := 'k';
367
          when "01101100" => out_char := 'l';
368
          when "01101101" => out_char := 'm';
369
          when "01101110" => out_char := 'n';
370
          when "01101111" => out_char := 'o';
371
          when "01110000" => out_char := 'p';
372
          when "01110001" => out_char := 'q';
373
          when "01110010" => out_char := 'r';
374
          when "01110011" => out_char := 's';
375
          when "01110100" => out_char := 't';
376
          when "01110101" => out_char := 'u';
377
          when "01110110" => out_char := 'v';
378
          when "01110111" => out_char := 'w';
379
          when "01111000" => out_char := 'x';
380
          when "01111001" => out_char := 'y';
381
          when "01111010" => out_char := 'z';
382
          when "01111011" => out_char := '{';
383
          when "01111100" => out_char := '|';
384
          when "01111101" => out_char := '}';
385
          when "01111110" => out_char := '~';
386
          when others =>
387
             out_char := '*';
388
             --assert false report " illegal unsigned to ascii character" severity note;
389
      end case;
390
      return out_char;
391
     end;
392
 
393
------------------------------------------------------------------------------------
394
--
395
------------------------------------------------------------------------------------
396
 
397
    function asciichar2u(in_char : character) return unsigned is
398
    variable out_vect : unsigned(7 downto 0);
399
 
400
    begin
401
      case in_char is
402
          when  HT => out_vect := "00001001";
403
          when ' ' => out_vect := "00100000";
404
          when '!' => out_vect := "00100001";
405
          when '"' => out_vect := "00100010";
406
          when '#' => out_vect := "00100011";
407
          when '$' => out_vect := "00100100";
408
          when '%' => out_vect := "00100101";
409
          when '&' => out_vect := "00100110";
410
          when ''' => out_vect := "00100111";
411
          when '(' => out_vect := "00101000";
412
          when ')' => out_vect := "00101001";
413
          when '*' => out_vect := "00101010";
414
          when '+' => out_vect := "00101011";
415
          when ',' => out_vect := "00101100";
416
          when '-' => out_vect := "00101101";
417
          when '.' => out_vect := "00101110";
418
          when '/' => out_vect := "00101111";
419
          when '0' => out_vect := "00110000";
420
          when '1' => out_vect := "00110001";
421
          when '2' => out_vect := "00110010";
422
          when '3' => out_vect := "00110011";
423
          when '4' => out_vect := "00110100";
424
          when '5' => out_vect := "00110101";
425
          when '6' => out_vect := "00110110";
426
          when '7' => out_vect := "00110111";
427
          when '8' => out_vect := "00111000";
428
          when '9' => out_vect := "00111001";
429
          when ':' => out_vect := "00111010";
430
          when ';' => out_vect := "00111011";
431
          when '<' => out_vect := "00111100";
432
          when '=' => out_vect := "00111101";
433
          when '>' => out_vect := "00111110";
434
          when '?' => out_vect := "00111111";
435
          when '@' => out_vect := "01000000";
436
          when 'A' => out_vect := "01000001";
437
          when 'B' => out_vect := "01000010";
438
          when 'C' => out_vect := "01000011";
439
          when 'D' => out_vect := "01000100";
440
          when 'E' => out_vect := "01000101";
441
          when 'F' => out_vect := "01000110";
442
          when 'G' => out_vect := "01000111";
443
          when 'H' => out_vect := "01001000";
444
          when 'I' => out_vect := "01001001";
445
          when 'J' => out_vect := "01001010";
446
          when 'K' => out_vect := "01001011";
447
          when 'L' => out_vect := "01001100";
448
          when 'M' => out_vect := "01001101";
449
          when 'N' => out_vect := "01001110";
450
          when 'O' => out_vect := "01001111";
451
          when 'P' => out_vect := "01010000";
452
          when 'Q' => out_vect := "01010001";
453
          when 'R' => out_vect := "01010010";
454
          when 'S' => out_vect := "01010011";
455
          when 'T' => out_vect := "01010100";
456
          when 'U' => out_vect := "01010101";
457
          when 'V' => out_vect := "01010110";
458
          when 'W' => out_vect := "01010111";
459
          when 'X' => out_vect := "01011000";
460
          when 'Y' => out_vect := "01011001";
461
          when 'Z' => out_vect := "01011010";
462
          when '[' => out_vect := "01011011";
463
          when '\' => out_vect := "01011100";
464
          when ']' => out_vect := "01011101";
465
          when '^' => out_vect := "01011110";
466
          when '_' => out_vect := "01011111";
467
          when '`' => out_vect := "01100000";
468
          when 'a' => out_vect := "01100001";
469
          when 'b' => out_vect := "01100010";
470
          when 'c' => out_vect := "01100011";
471
          when 'd' => out_vect := "01100100";
472
          when 'e' => out_vect := "01100101";
473
          when 'f' => out_vect := "01100110";
474
          when 'g' => out_vect := "01100111";
475
          when 'h' => out_vect := "01101000";
476
          when 'i' => out_vect := "01101001";
477
          when 'j' => out_vect := "01101010";
478
          when 'k' => out_vect := "01101011";
479
          when 'l' => out_vect := "01101100";
480
          when 'm' => out_vect := "01101101";
481
          when 'n' => out_vect := "01101110";
482
          when 'o' => out_vect := "01101111";
483
          when 'p' => out_vect := "01110000";
484
          when 'q' => out_vect := "01110001";
485
          when 'r' => out_vect := "01110010";
486
          when 's' => out_vect := "01110011";
487
          when 't' => out_vect := "01110100";
488
          when 'u' => out_vect := "01110101";
489
          when 'v' => out_vect := "01110110";
490
          when 'w' => out_vect := "01110111";
491
          when 'x' => out_vect := "01111000";
492
          when 'y' => out_vect := "01111001";
493
          when 'z' => out_vect := "01111010";
494
          when '{' => out_vect := "01111011";
495
          when '|' => out_vect := "01111100";
496
          when '}' => out_vect := "01111101";
497
          when '~' => out_vect := "01111110";
498
          when others =>
499
             out_vect := "00101010";
500
             --assert false report " illegal char to unsigned" severity note;
501
      end case;
502
      return out_vect;
503
     end;
504
 
505
------------------------------------------------------------------------------------
506
--
507
------------------------------------------------------------------------------------
508
 
509
    function hex_to_ascii(in_vector : std_logic_vector; nibbles : natural) return string is
510
    variable out_string : string(1 to nibbles);
511
    variable temp_in_vector : std_logic_vector(4*nibbles-1 downto 0);
512
    variable vector     : std_logic_vector(3 downto 0);
513
 
514
    begin
515
    temp_in_vector := in_vector(in_vector'length-1 downto in_vector'length-temp_in_vector'length);
516
        for i in 1 to nibbles loop
517
            vector := temp_in_vector((4*(nibbles-i)+3) downto 4*(nibbles-i));
518
            case vector is
519
                when "0000" => out_string(i) := '0';
520
                when "0001" => out_string(i) := '1';
521
                when "0010" => out_string(i) := '2';
522
                when "0011" => out_string(i) := '3';
523
                when "0100" => out_string(i) := '4';
524
                when "0101" => out_string(i) := '5';
525
                when "0110" => out_string(i) := '6';
526
                when "0111" => out_string(i) := '7';
527
                when "1000" => out_string(i) := '8';
528
                when "1001" => out_string(i) := '9';
529
                when "1010" => out_string(i) := 'A';
530
                when "1011" => out_string(i) := 'B';
531
                when "1100" => out_string(i) := 'C';
532
                when "1101" => out_string(i) := 'D';
533
                when "1110" => out_string(i) := 'E';
534
                when "1111" => out_string(i) := 'F';
535
                when others =>
536
                   out_string(i) := 'J';
537
                   assert false
538
                   report " illegal std_logic_vector to string"
539
                   severity note;
540
            end case;
541
        end loop;
542
        return out_string;
543
     end;
544
 
545
------------------------------------------------------------------------------------
546
--
547
------------------------------------------------------------------------------------
548
 
549
    function u2ascii(in_vector : unsigned; nibbles : natural) return string is
550
    variable out_string     : string(1 to nibbles);
551
    variable temp_in_vector : unsigned(4*nibbles-1 downto 0);
552
    variable vector         : unsigned(3 downto 0);
553
 
554
    begin
555
    temp_in_vector := in_vector(in_vector'length-1 downto in_vector'length-temp_in_vector'length);
556
        for i in 1 to nibbles loop
557
            vector := temp_in_vector((4*(nibbles-i)+3) downto 4*(nibbles-i));
558
            case vector is
559
                when "0000" => out_string(i) := '0';
560
                when "0001" => out_string(i) := '1';
561
                when "0010" => out_string(i) := '2';
562
                when "0011" => out_string(i) := '3';
563
                when "0100" => out_string(i) := '4';
564
                when "0101" => out_string(i) := '5';
565
                when "0110" => out_string(i) := '6';
566
                when "0111" => out_string(i) := '7';
567
                when "1000" => out_string(i) := '8';
568
                when "1001" => out_string(i) := '9';
569
                when "1010" => out_string(i) := 'A';
570
                when "1011" => out_string(i) := 'B';
571
                when "1100" => out_string(i) := 'C';
572
                when "1101" => out_string(i) := 'D';
573
                when "1110" => out_string(i) := 'E';
574
                when "1111" => out_string(i) := 'F';
575
                when others =>
576
                   out_string(i) := 'U';
577
                   assert false report " illegal unsigned to string" severity note;
578
            end case;
579
        end loop;
580
        return out_string;
581
     end;
582
 
583
------------------------------------------------------------------------------------
584
--
585
------------------------------------------------------------------------------------
586
 
587
    function hex_data_wrd(in_vector : std_logic_vector) return string is
588
    variable out_string : string(1 to 8);
589
    variable temp_in_vector : std_logic_vector(31 downto 0);
590
    variable vector     : std_logic_vector(3 downto 0);
591
 
592
    begin
593
    temp_in_vector := in_vector;
594
        for i in 1 to 8 loop
595
            vector := temp_in_vector((35-(4*i)) downto (32-(4*i)));
596
            case vector is
597
                when "0000" => out_string(i) := '0';
598
                when "0001" => out_string(i) := '1';
599
                when "0010" => out_string(i) := '2';
600
                when "0011" => out_string(i) := '3';
601
                when "0100" => out_string(i) := '4';
602
                when "0101" => out_string(i) := '5';
603
                when "0110" => out_string(i) := '6';
604
                when "0111" => out_string(i) := '7';
605
                when "1000" => out_string(i) := '8';
606
                when "1001" => out_string(i) := '9';
607
                when "1010" => out_string(i) := 'A';
608
                when "1011" => out_string(i) := 'B';
609
                when "1100" => out_string(i) := 'C';
610
                when "1101" => out_string(i) := 'D';
611
                when "1110" => out_string(i) := 'E';
612
                when "1111" => out_string(i) := 'F';
613
                when others =>
614
                   out_string(i) := 'J';
615
                   assert false
616
                   report " illegal std_logic_vector to string"
617
                   severity note;
618
            end case;
619
        end loop;
620
        return out_string;
621
     end;
622
 
623
------------------------------------------------------------------------------------
624
--
625
------------------------------------------------------------------------------------
626
 
627
    function hex_data_dblwrd(in_vector : std_logic_vector) return string is
628
    variable out_string : string(1 to 16);
629
    variable temp_in_vector : std_logic_vector(63 downto 0);
630
    variable vector     : std_logic_vector(3 downto 0);
631
 
632
    begin
633
    temp_in_vector := in_vector;
634
        for i in 1 to 16 loop
635
            vector := temp_in_vector((67-(4*i)) downto (64-(4*i)));
636
            case vector is
637
                when "0000" => out_string(i) := '0';
638
                when "0001" => out_string(i) := '1';
639
                when "0010" => out_string(i) := '2';
640
                when "0011" => out_string(i) := '3';
641
                when "0100" => out_string(i) := '4';
642
                when "0101" => out_string(i) := '5';
643
                when "0110" => out_string(i) := '6';
644
                when "0111" => out_string(i) := '7';
645
                when "1000" => out_string(i) := '8';
646
                when "1001" => out_string(i) := '9';
647
                when "1010" => out_string(i) := 'A';
648
                when "1011" => out_string(i) := 'B';
649
                when "1100" => out_string(i) := 'C';
650
                when "1101" => out_string(i) := 'D';
651
                when "1110" => out_string(i) := 'E';
652
                when "1111" => out_string(i) := 'F';
653
                when others =>
654
                   out_string(i) := 'J';
655
                   assert false
656
                   report " illegal std_logic_vector to string"
657
                   severity note;
658
            end case;
659
        end loop;
660
        return out_string;
661
     end;
662
 
663
------------------------------------------------------------------------------------
664
--
665
------------------------------------------------------------------------------------
666
 
667
    function hex_data_dblwrdz(in_vector : std_logic_vector) return string is
668
    variable out_string : string(1 to 16);
669
    variable temp_in_vector : std_logic_vector(63 downto 0);
670
    variable vector     : std_logic_vector(3 downto 0);
671
 
672
    begin
673
    temp_in_vector := in_vector;
674
        for i in 1 to 16 loop
675
            vector := temp_in_vector((67-(4*i)) downto (64-(4*i)));
676
            case vector is
677
                when "0000" => out_string(i) := '0';
678
                when "0001" => out_string(i) := '1';
679
                when "0010" => out_string(i) := '2';
680
                when "0011" => out_string(i) := '3';
681
                when "0100" => out_string(i) := '4';
682
                when "0101" => out_string(i) := '5';
683
                when "0110" => out_string(i) := '6';
684
                when "0111" => out_string(i) := '7';
685
                when "1000" => out_string(i) := '8';
686
                when "1001" => out_string(i) := '9';
687
                when "1010" => out_string(i) := 'A';
688
                when "1011" => out_string(i) := 'B';
689
                when "1100" => out_string(i) := 'C';
690
                when "1101" => out_string(i) := 'D';
691
                when "1110" => out_string(i) := 'E';
692
                when "1111" => out_string(i) := 'F';
693
                when "ZZZZ" => out_string(i) := 'Z';
694
                when others =>
695
                   out_string(i) := 'J';
696
                   assert false
697
                   report " illegal std_logic_vector to string"
698
                   severity note;
699
            end case;
700
        end loop;
701
        return out_string;
702
     end;
703
 
704
 
705
------------------------------------------------------------------------------------
706
--
707
------------------------------------------------------------------------------------
708
 
709
function str2u2(s: string) return unsigned is
710
  variable uv: unsigned(8*s'high-1 downto 0);
711
  variable k: integer;
712
begin
713
   k := s'high-s'low;
714
  for i in s'range loop
715
--     uv(8*k+7 downto 8*k) := unsigned(chartobyte(s(i)));
716
     uv(8*k+7 downto 8*k) := asciichar2u2(s(i));
717
     k      := k - 1;
718
  end loop;
719
  return uv;
720
end str2u2;
721
 
722
------------------------------------------------------------------------------------
723
--
724
------------------------------------------------------------------------------------
725
    -- returns true if the character is a valid hexadecimal character.
726
    function is_hex(c : character) return boolean is
727
    begin
728
      case c is
729
        when '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
730
             'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' |
731
             'e' | 'f' =>
732
          return(true);
733
        when others =>
734
          return(false);
735
      end case;
736
    end is_hex;
737
 
738
------------------------------------------------------------------------------------
739
--
740
------------------------------------------------------------------------------------
741
    -- returns true if the character is a valid hexadecimal character.
742
    function is_std_logic(c : character) return boolean is
743
    begin
744
      case c is
745
        when '0' | '1' | 'u' | 'U' | 'x' | 'X' | 'z' | 'Z' =>
746
          return(true);
747
        when others =>
748
          return(false);
749
      end case;
750
    end is_std_logic;
751
 
752
------------------------------------------------------------------------------------
753
--
754
------------------------------------------------------------------------------------
755
    -- returns true if the character is whitespace.
756
    function is_space(c : character) return boolean is
757
    begin
758
      case c is
759
        when ' ' | HT =>
760
          return(true);
761
        when others =>
762
          return(false);
763
      end case;
764
    end is_space;
765
 
766
 
767
 
768
end sim_support_pack;
769
 
770
 
771
 

powered by: WebSVN 2.1.0

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