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

Subversion Repositories ahbmaster

[/] [ahbmaster/] [trunk/] [test79_AHBmaster/] [component/] [work/] [top/] [CoreUARTapb_0/] [rtl/] [vhdl/] [amba_bfm/] [textio.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 uson
-- ********************************************************************/ 
2
-- Actel Corporation Proprietary and Confidential
3
-- Copyright 2008 Actel Corporation.  All rights reserved.
4
--
5
-- ANY USE OR REDISTRIBUTION IN PART OR IN WHOLE MUST BE HANDLED IN 
6
-- ACCORDANCE WITH THE ACTEL LICENSE AGREEMENT AND MUST BE APPROVED 
7
-- IN ADVANCE IN WRITING.  
8
--  
9
-- Description: AMBA BFMs
10
--              AHB Lite BFM  
11
--
12
-- Revision Information:
13
-- Date     Description
14
-- 01Sep07  Initial Release 
15
-- 14Sep07  Updated for 1.2 functionality
16
-- 25Sep07  Updated for 1.3 functionality
17
-- 09Nov07  Updated for 1.4 functionality
18
-- 08May08  2.0 for Soft IP Usage
19
--
20
--
21
-- SVN Revision Information:
22
-- SVN $Revision: 2437 $
23
-- SVN $Date: 2008-09-18 03:33:46 -0700 (Thu, 18 Sep 2008) $
24
--
25
--
26
-- Resolved SARs
27
-- SAR      Date     Who  Description
28
--
29
--
30
-- Notes: 
31
--        
32
-- *********************************************************************/ 
33
 
34
 
35
 
36
-- *********************************************************************/ 
37
-- Copyright 2005 Actel Corporation.  All rights reserved.
38
-- IP Solutions Group
39
--  
40
-- ANY USE OR REDISTRIBUTION IN PART OR IN WHOLE MUST BE HANDLED IN 
41
-- ACCORDANCE WITH THE ACTEL LICENSE AGREEMENT AND MUST BE APPROVED 
42
-- IN ADVANCE IN WRITING.  
43
--
44
-- File        :  textio.vhd
45
--  
46
-- Originator  :  I Bryant  
47
--  
48
-- Date        :  22 Jan 1997    
49
--
50
-- Description :  Implements Basic Printing Routines for the Test harness
51
--  
52
-- Revision History: 
53
--      3.02 08Jan99 IPB  : Nokia Modifications 
54
--      2.0  01Jun01 IPB  : VariCore Production Code Release 1  
55
--      2.1  11Mar02 IPB  : Added %t support
56
-- Revision history for version in the Core1553 Cores
57
-- Rev: 1.0 01Apr02 IPB  : Initial Code (Copied from PCI Cores) 
58
-- Rev: 1.1 09Jul02 IPB  : First Cut EAP
59
-- Rev: 1.2 01Aug02 IPB  : Second EAP 
60
-- Rev: 2.0 22Aug02 IPB  : Production 
61
-- Rev: 2.1 22Oct03 IPB  : Updated to use IEEE.NUMERIC and 1076-93
62
-- Rev: 2.2 10Mar04 IPB  : Added sprintf functions and %c support
63
-- BRM Release
64
-- Rev: 1.0 01May04  IPB  : Pre Production  
65
-- Rev: 2.0 27May04  IPB  : First Production Release 
66
-- Rev: 2.1 24Jan05  IPB  : PA3/E Production Release 
67
--
68
-- CoreABC Release
69
-- Rev: 1.1  08May06 IPB  : EAP Release 
70
--
71
-- CoreConsolisation AMBA Project
72
-- Rev: 3.1  07Jan07  IPB  : CoreConsole Release  - Fixed negative number handling in %u on 32 bit values 
73
--
74
-- AMBA BFM
75
-- Rev: 1.0  18Jul07  IPB : 
76
-- Rev: 1.1  24Aug07  IPB : See users guide 1.0 for changes  
77
-- Rev: 1.2  14Sep07  IPB : See users guide 1.2 for changes  
78
--      
79
-- Notes :
80
--  Supported Formats
81
--              %d decimal
82
--              %h hexadecimal Integer or known vector
83
--              %x hexadecimal Integer or vector with X's
84
--              %u hexadecimal Integer or vector unsigned hex value
85
--              %b binary
86
--              %s string
87
--              %t prints time in ns
88
--
89
--  Also Supports %6 i.e Width Field
90
--                %0 Fill with Zeros
91
--
92
---------------------------------------------------------------------------
93
 
94
library std;
95
use std.textio.all;
96
 
97
 
98
use work.bfm_misc.all;
99
 
100
library ieee;
101
use ieee.std_logic_1164.all;
102
use ieee.numeric_std.all;
103
 
104
 
105
---------------------------------------------------------------------------
106
-- Declarations etc
107
--
108
 
109
package bfm_textio is
110
 
111
constant MAXSTRLEN : INTEGER := 256;
112
type     T_NUMTYPE is ( NONE, INT, VECT, STRG);
113
 
114
type T_FMT is record
115
   f_type      : T_NUMTYPE;
116
   f_integer   : INTEGER;
117
   f_vector    : QWORD;
118
   f_length    : INTEGER;
119
   f_string    : STRING (1 to MAXSTRLEN);
120
end record;
121
 
122
type T_FMT_ARRAY is array ( integer range <> ) of T_FMT;
123
 
124
function is01 ( v: std_logic) return BOOLEAN;
125
function is01 ( v: unsigned; len : INTEGER) return BOOLEAN;
126
 
127
function strlen( str: STRING) return INTEGER;
128
function strcopy ( instr : STRING) return STRING;
129
 
130
procedure printf( str : STRING; params : T_FMT_ARRAY);
131
procedure printf( str : STRING; params : T_FMT);
132
procedure printf( str : STRING );
133
 
134
procedure sprintf( strout : out STRING; str : STRING; params : T_FMT_ARRAY);
135
procedure sprintf( strout : out STRING; str : STRING; params : T_FMT);
136
procedure sprintf( strout : out STRING; str : STRING );
137
 
138
procedure ifprintf( enable : BOOLEAN; str : STRING; params : T_FMT_ARRAY);
139
procedure ifprintf( enable : BOOLEAN; str : STRING; params : T_FMT);
140
procedure ifprintf( enable : BOOLEAN; str : STRING );
141
 
142
function fmt ( x : INTEGER) return T_FMT;
143
function fmt ( x : std_logic_vector) return T_FMT;
144
function fmt ( x : unsigned) return T_FMT;
145
function fmt ( x : string ) return T_FMT;
146
function fmt ( x : character ) return T_FMT;
147
function fmt ( x : boolean ) return T_FMT;
148
function fmt ( x : std_logic) return T_FMT;
149
 
150
function inttostr( value : INTEGER; base : INTEGER;
151
                   numlen : INTEGER :=0; zeros: BOOLEAN:=FALSE) return STRING;
152
 
153
 
154
function inrange ( x, l: integer) return integer;
155
 
156
 
157
 
158
end bfm_textio;
159
 
160
 
161
---------------------------------------------------------------------------
162
-- The Body
163
--
164
 
165
package body bfm_textio is
166
 
167
 
168
 function inrange ( x, l: integer) return integer is
169
 begin
170
  if x<=l then return(x); else return(l);
171
  end if;
172
 end inrange;
173
 
174
---------------------------------------------------------------------------
175
-- Basic Character Converters
176
--
177
 
178
function to_char( x : INTEGER range 0 to 15) return character is
179
 begin
180
  case x is
181
    when 0  => return('0');
182
    when 1  => return('1');
183
    when 2  => return('2');
184
    when 3  => return('3');
185
    when 4  => return('4');
186
    when 5  => return('5');
187
    when 6  => return('6');
188
    when 7  => return('7');
189
    when 8  => return('8');
190
    when 9  => return('9');
191
    when 10 => return('A');
192
    when 11 => return('B');
193
    when 12 => return('C');
194
    when 13 => return('D');
195
    when 14 => return('E');
196
    when 15 => return('F');
197
  end case;
198
end to_char;
199
 
200
function to_char( v : std_logic ) return CHARACTER is
201
 begin
202
   case v is
203
    when '0' => return('0');
204
    when '1' => return('1');
205
    when 'L' => return('L');
206
    when 'H' => return('H');
207
    when 'Z' => return('Z');
208
    when 'X' => return('X');
209
    when 'U' => return('U');
210
    when '-' => return('-');
211
    when 'W' => return('W');
212
   end case;
213
 end to_char;
214
 
215
---------------------------------------------------------------------------
216
-- special std_logic_vector handling
217
--
218
 
219
function is01 ( v: std_logic) return BOOLEAN is
220
 begin
221
  return ( v='0' or v='1');
222
 end is01;
223
 
224
function is01 ( v: UNSIGNED ; len : INTEGER) return BOOLEAN is
225
 variable ok : BOOLEAN;
226
 begin
227
  ok := TRUE;
228
  for i in 0 to len-1 loop
229
    ok := ok and is01( v(i));
230
  end loop;
231
  return (ok);
232
 end is01;
233
 
234
---------------------------------------------------------------------------
235
-- special integer to unsigned 
236
--
237
 
238
function to_unsigned_32 ( x : integer ) return UNSIGNED is
239
  variable x1 : UNSIGNED(31 downto 0);
240
  variable xi : integer;
241
begin
242
  -- Note this causes an integer overflow on VSS and QuickVHDL
243
  -- Cannout handle -ve numbers 
244
  -- x1 := conv_std_logic_vector( x,32);
245
  if x < 0 then
246
    xi              := x + 2 ** 30 + 2 ** 30;
247
    x1(30 downto 0) := to_unsigned( xi, 31);
248
    x1(31)          := '1';
249
  else
250
    x1(30 downto 0) := to_unsigned( x, 31);
251
    x1(31)          := '0';
252
  end if;
253
  return(x1);
254
end to_unsigned_32;
255
 
256
 
257
---------------------------------------------------------------------------
258
-- String Functions
259
--
260
 
261
function strlen( str: STRING) return INTEGER is
262
 variable i: INTEGER;
263
 begin
264
  i:=1;
265
  while i<= MAXSTRLEN and str(i)/=NUL loop
266
   i:=i+1;
267
  end loop;
268
  return(i-1);
269
 end strlen;
270
 
271
function strcopy ( instr : STRING) return STRING is
272
 variable outstr : STRING (1 to MAXSTRLEN);
273
 variable i: INTEGER;
274
 begin
275
  outstr(1 to instr'length) := instr;
276
  outstr(instr'length+1) := NUL;
277
  return(outstr);
278
 end strcopy;
279
 
280
---------------------------------------------------------------------------
281
-- Number Printing Routines
282
--
283
 
284
function hexchar ( vect : UNSIGNED) return character is
285
 variable v : UNSIGNED ( 3 downto 0);
286
 variable char : CHARACTER;
287
 begin
288
   v := vect;
289
   if is01(v(0)) and is01(v(1)) and is01(v(2)) and is01(v(3)) then
290
      char := to_char (to_integer(v));
291
   elsif v(0)=v(1) and v(0)=v(2) and v(0)=v(3) then
292
      char:= to_char(v(0));
293
   else
294
      char:='?';
295
   end if;
296
   return(char);
297
 end hexchar;
298
 
299
function inttostr( value : INTEGER; base : INTEGER;
300
                   numlen : INTEGER :=0; zeros: BOOLEAN:=FALSE) return STRING is
301
 variable str : STRING (1 to MAXSTRLEN);
302
 variable s1  : STRING (MAXSTRLEN downto 1);
303
 variable pos,x,xn,x1 : INTEGER;
304
 begin
305
  if  value=-2147483648 then
306
   -- str(1 to 9) := "UNDERFLOW";
307
   -- str(10) := NUL;
308
    str(1 to 11) := "-2147483648";         -- print actual value anyway
309
    str(12) := NUL;
310
  else
311
    x   := abs(value);
312
    pos := 0;
313
    while x>0 or pos=0 loop
314
      pos:=pos+1;
315
      xn := x / base;
316
      x1 := x - xn * base ;
317
      x  := xn;
318
      s1(pos) := to_char(x1);
319
    end loop;
320
    if value<0  then
321
      pos:=pos+1;
322
      s1(pos):='-';
323
    end if;
324
    if pos>numlen then
325
      str(1 to pos) := s1 (pos downto 1);
326
      str(pos+1) := NUL;
327
    else
328
      case ZEROS is
329
        when TRUE  => str := (others => '0');
330
        when FALSE => str := (others => ' ');
331
      end case;
332
      str( (1+numlen-pos) to numlen) := s1(pos downto 1);
333
      str(numlen+1) := NUL;
334
    end if;
335
  end if;
336
  return(str);
337
 end inttostr;
338
 
339
 
340
function vecttostr( value : UNSIGNED; len : INTEGER; base : INTEGER;
341
                    numlen : INTEGER :=0;
342
                    zeros: BOOLEAN:=FALSE) return STRING is
343
 variable str : STRING (1 to MAXSTRLEN);
344
 variable s1  : STRING (MAXSTRLEN downto 1);
345
 variable pos, len4 : INTEGER;
346
 variable x : QWORD;
347
 variable vect4 : UNSIGNED(3 downto 0);
348
 begin
349
  x:=value;
350
  if len<64 then
351
    x(63 downto len) := (others =>'0');
352
  end if;
353
  case base is
354
   when 2   => for i in 0 to len-1 loop
355
                   s1(i+1) := to_char(value(i));
356
               end loop;
357
               pos:=len;
358
   when 16  => len4 := ((len+3)/4);
359
               for i in 0 to len4-1 loop
360
                 vect4 := x( 3+(4*i) downto 4*i);
361
                 s1(i+1) := hexchar(vect4);
362
               end loop;
363
               pos:=len4;
364
   when others =>  s1:=strcopy("ESAB LAGELLI");
365
  end case;
366
  if pos>numlen then
367
    str(1 to pos) := s1 (pos downto 1);
368
    str(pos+1) := NUL;
369
  else
370
    case ZEROS is
371
      when TRUE  => str := (others => '0');
372
      when FALSE => str := (others => ' ');
373
    end case;
374
    str( (1+numlen-pos) to numlen) := s1(pos downto 1);
375
    str(numlen+1) := NUL;
376
  end if;
377
  return(str);
378
 end vecttostr;
379
 
380
---------------------------------------------------------------------------
381
-- Multi Type input handlers
382
--
383
 
384
function fmt ( x : BOOLEAN) return T_FMT is
385
 variable fm : T_FMT;
386
 begin
387
  fm.f_type := INT;
388
  if x then fm.f_integer := 1;
389
       else fm.f_integer := 0;
390
  end if;
391
  return(fm);
392
 end fmt;
393
 
394
function fmt ( x : INTEGER) return T_FMT is
395
 variable fm : T_FMT;
396
 begin
397
  fm.f_type := INT;
398
  fm.f_integer := x;
399
  return(fm);
400
 end fmt;
401
 
402
function fmt ( x : UNSIGNED) return T_FMT is
403
 variable fm : T_FMT;
404
 begin
405
  fm.f_type   := VECT;
406
  fm.f_vector(x'length-1 downto 0) := x;
407
  fm.f_length := x'length;
408
  return(fm);
409
 end fmt;
410
 
411
function fmt ( x : std_logic_vector) return T_FMT is
412
 variable fm : T_FMT;
413
 begin
414
  fm.f_type   := VECT;
415
  fm.f_vector(x'length-1 downto 0) := to_unsigned(x);
416
  fm.f_length := x'length;
417
  return(fm);
418
 end fmt;
419
 
420
function fmt ( x : string ) return T_FMT is
421
 variable fm : T_FMT;
422
 begin
423
  fm.f_type   := STRG;
424
  fm.f_string(x'range) := x;
425
  if x'length+1<MAXSTRLEN then
426
    fm.f_string(x'length+1) := NUL;
427
  end if;
428
  fm.f_length := x'length;
429
  return(fm);
430
 end fmt;
431
 
432
function fmt ( x : character ) return T_FMT is
433
 variable fm : T_FMT;
434
 begin
435
  fm.f_type   := STRG;
436
  fm.f_string(1) := x;
437
  fm.f_string(2) := NUL;
438
  fm.f_length := 1;
439
  return(fm);
440
 end fmt;
441
 
442
function fmt ( x : std_logic) return T_FMT is
443
 variable fm : T_FMT;
444
 variable x1 : UNSIGNED ( 0 downto 0);
445
 begin
446
  x1(0) := x;
447
  fm.f_type   := VECT;
448
  fm.f_vector(x1'length-1 downto 0) := x1;
449
  fm.f_length := x1'length;
450
  return(fm);
451
 end fmt;
452
 
453
---------------------------------------------------------------------------
454
-- The Main Print Routine
455
--
456
 
457
 
458
 
459
procedure theprintf( SPRINTF : BOOLEAN;
460
                     strout    : out string;
461
                     str     : STRING;
462
                     Params  : T_FMT_ARRAY ) is
463
 variable ll : LINE;
464
 variable str1,pstr : STRING (1 to MAXSTRLEN);
465
 variable ip,op,pp,iplen : INTEGER;
466
 variable numlen : INTEGER;
467
 variable zeros  : BOOLEAN;
468
 variable more   : BOOLEAN;
469
 variable intval : INTEGER;
470
 variable vectval: QWORD;
471
 variable len    : INTEGER;
472
 variable ftype  : T_NUMTYPE;
473
 variable tnow   : INTEGER;
474
 begin
475
   iplen := str'length;
476
   ip:=1; op:=0; pp:=params'low;
477
   while ip<=iplen and str( inrange(ip,iplen))/=NUL loop
478
     if str(ip) = '%' then
479
       more:=TRUE;
480
       numlen:=0; zeros:=FALSE;
481
       while more loop
482
          more:=FALSE;
483
          ip:=ip+1;
484
          if str(ip)/='t' then   -- 17Jul07  %t has no parameters, errors if last parameter!
485
                    ftype  := params(pp).f_type;
486
            intval := params(pp).f_integer;
487
            vectval:= params(pp).f_vector;
488
            len    := params(pp).f_length;
489
                  end if;
490
          case str(ip) is
491
            when '0'     => ZEROS:=TRUE;
492
                            more:=TRUE;
493
            when '1' to '9' =>
494
                            numlen:= 10* numlen + character'pos(str(ip))-48;
495
                            more := TRUE;
496
            when '%'     => pstr := strcopy("%");
497
            when 'd'     => case ftype is
498
                              when INT  => pstr := inttostr(intval,10,numlen,zeros);
499
                              when VECT => if is01(vectval,len) then
500
                                             intval:= to_integer(vectval(len-1 downto 0));
501
                                             pstr := inttostr(intval,10,numlen,zeros);
502
                                           end if;
503
                              when others => pstr := strcopy("INVALID PRINTF d:" & str);
504
                            end case;
505
                            pp:=pp+1;
506
            when 't'     => tnow := NOW / 1 ns;
507
                            pstr := inttostr(tnow,10,numlen,zeros);
508
            when 'h'     => case ftype is
509
                              when INT  => pstr := inttostr(intval,16,numlen,zeros);
510
                              when VECT => if is01(vectval,len) then
511
                                             intval:= to_integer(vectval(len-1 downto 0));
512
                                             pstr  := inttostr(intval,16,numlen,zeros);
513
                                           end if;
514
                              when others => pstr := strcopy("INVALID PRINTF h:" & str);
515
                            end case;
516
                            pp:=pp+1;
517
            when 'u'     => case ftype is
518
                              when INT  => vectval := ( others => '0');
519
                                           vectval(31 downto 0) := to_unsigned_32(intval);
520
                                           len:=32;
521
                                           pstr := vecttostr(vectval,len,16,numlen,zeros);
522
                              when VECT =>  pstr := vecttostr(vectval,len,16,numlen,zeros);
523
                              when others => pstr := strcopy("INVALID PRINTF h:" & str);
524
                            end case;
525
                            pp:=pp+1;
526
            when 'b'     => case ftype is
527
                              when INT    => vectval := ( others => '0');
528
                                             vectval(31 downto 0) := to_unsigned(intval,32);
529
                                             len:=1;
530
                                             for i in 1 to 31 loop
531
                                             if vectval(i)='1' then
532
                                               len:=i;
533
                                             end if;
534
                                             end loop;
535
                                             pstr := vecttostr(vectval,len,2,numlen,zeros);
536
                              when VECT   => pstr := vecttostr(vectval,len,2,numlen,zeros);
537
                              when others => pstr := strcopy("INVALID PRINTF b:" & str);
538
                            end case;
539
                            pp:=pp+1;
540
            when 'x'     => case ftype is
541
                             -- when INT  => pstr := inttostr(intval,16,numlen,zeros);  --28nov07 to sort out -ve nos
542
                              when INT  => vectval := ( others => '0');
543
                                           vectval(31 downto 0) := to_unsigned_32(intval);
544
                                           len:=32;
545
                                           pstr := vecttostr(vectval,len,16,numlen,zeros);
546
                              when VECT => pstr := vecttostr(vectval,len,16,numlen,zeros);
547
                              when others => pstr := strcopy("INVALID PRINTF x:" & str);
548
                            end case;
549
                            pp:=pp+1;
550
            when 's'     => case ftype is
551
                              when STRG   => pstr :=params(pp).f_string;
552
                              when others => pstr := strcopy("INVALID PRINTF s:" & str);
553
                            end case;
554
                            pp:=pp+1;
555
            when 'c'     => case ftype is
556
                              when STRG   => pstr :=params(pp).f_string;
557
                              when others => pstr := strcopy("INVALID PRINTF s:" & str);
558
                            end case;
559
                            pp:=pp+1;
560
            when others  => pstr := strcopy("ILLEGAL FORMAT");
561
                            assert FALSE
562
                             report "TEXTIO Processing Problem"
563
                             severity FAILURE;
564
          end case;
565
       end loop;
566
       len := strlen(pstr);
567
       for i in 1 to len loop
568
          str1(op+i) := pstr(i);
569
       end loop;
570
       ip:=ip+1;
571
       op:=op+len;
572
     elsif str(ip)='\' then
573
       case str(ip+1) is
574
         when 'n' => str1(op+1):= NUL;
575
                     if not SPRINTF then
576
                       write( ll , str1 );
577
                       writeline( output, ll);
578
                     end if;
579
                     op := 0; ip:=ip+1;
580
                     str1(op+1) := NUL;
581
         when others =>
582
       end case;
583
       ip:=ip+1;
584
     else
585
      op:=op+1;
586
      str1(op) := str(ip);
587
      ip:=ip+1;
588
     end if;
589
   end loop;
590
   if op>0 then
591
     str1(op+1):=NUL;
592
     if SPRINTF then
593
       strout := str1(strout'range);
594
     else
595
       write( ll , str1 );
596
       writeline(output, ll);
597
     end if;
598
   end if;
599
 end theprintf;
600
 
601
-------------------------------------------------------------------------------------
602
 
603
procedure printf( str : STRING; params : T_FMT ) is
604
variable strout : STRING (1 to MAXSTRLEN);
605
variable f_fmt : T_FMT_ARRAY ( 1 to 1);
606
begin
607
  f_fmt(1) := params;
608
  theprintf(FALSE,strout,str,f_fmt);
609
end printf;
610
 
611
procedure printf( str : STRING ) is
612
variable strout : STRING (1 to MAXSTRLEN);
613
variable fm : T_FMT_ARRAY ( 1 to 1);
614
begin
615
  fm(1).f_type := NONE;
616
  theprintf(FALSE,strout,str,fm);
617
end printf;
618
 
619
procedure printf(  str    : STRING;
620
                   Params : T_FMT_ARRAY ) is
621
variable strout : STRING (1 to MAXSTRLEN);
622
begin
623
  theprintf(FALSE,strout,str,Params);
624
end printf;
625
 
626
 
627
-------------------------------------------------------------------------------------
628
 
629
procedure sprintf( strout : out STRING;
630
                   str    : STRING;
631
                   Params : T_FMT_ARRAY ) is
632
begin
633
  theprintf( TRUE, strout, str,Params);
634
end sprintf;
635
 
636
 
637
procedure sprintf( strout : out STRING; str : STRING; params : T_FMT ) is
638
variable f_fmt : T_FMT_ARRAY ( 1 to 1);
639
begin
640
  f_fmt(1) := params;
641
  theprintf( TRUE,strout,str,f_fmt);
642
end sprintf;
643
 
644
 
645
procedure sprintf( strout : out STRING; str : STRING ) is
646
variable fm : T_FMT_ARRAY ( 1 to 1);
647
begin
648
  fm(1).f_type := NONE;
649
  theprintf( TRUE,strout,str,fm);
650
end sprintf;
651
 
652
 
653
-------------------------------------------------------------------------------------
654
 
655
 
656
procedure ifprintf( enable : BOOLEAN;
657
                    str    : STRING;
658
                    Params : T_FMT_ARRAY ) is
659
begin
660
 if enable then
661
   printf(str,params);
662
 end if;
663
end ifprintf;
664
 
665
procedure ifprintf( enable : BOOLEAN; str : STRING; params : T_FMT ) is
666
variable f_fmt : T_FMT_ARRAY ( 1 to 1);
667
begin
668
 if enable then
669
    f_fmt(1) := params;
670
    printf(str,f_fmt);
671
 end if;
672
end ifprintf;
673
 
674
procedure ifprintf( enable : BOOLEAN; str : STRING ) is
675
variable fm : T_FMT_ARRAY ( 1 to 1);
676
begin
677
 if enable then
678
   fm(1).f_type := NONE;
679
   printf(str,fm);
680
 end if;
681
end ifprintf;
682
 
683
 
684
 
685
end bfm_textio;
686
 
687
 
688
 
689
---------------------------------------------------------------------------
690
-- This a Test For the above Routines
691
--
692
 
693
library IEEE;
694
use ieee.std_logic_1164.all;
695
use IEEE.std_logic_arith.all;
696
 
697
 
698
use std.textio.all;
699
use work.bfm_textio.all;
700
 
701
 
702
entity bfm_textio_test is
703
 
704
end bfm_textio_test;
705
 
706
architecture TB of bfm_textio_test is
707
begin
708
 
709
process
710
variable dw : std_logic_vector ( 9 downto 0);
711
variable xx : std_logic_vector(15 downto 0);
712
variable ll : LINE;
713
file FSTR   : text  open write_mode is "Cpulog.txt" ;
714
variable strout : STRING(1 to 80);
715
variable intval : integer;
716
begin
717
  wait for 1 ns ;
718
  printf("Textio Test strings v1.2");
719
  printf("Note I think MTI uses variable width Fonts");
720
  xx:= conv_std_logic_vector( 16#AAAA#,16);
721
  printf("Using 04x %04x",fmt(xx));
722
  printf("Using 04u %04u",fmt(xx));
723
  printf("-d...123456 = %d",fmt(123456));
724
  printf("-8d..123456 = %8d",fmt(123456));
725
  printf("-08d.123456 = %08d",fmt(123456));
726
  printf("-02d.123456 = %02d",fmt(123456));
727
  printf("This is a Binary %016b",fmt(16#55AA#));
728
  printf("This is a Decimal %d",fmt(1234));
729
  printf("This is a Hex %h",fmt(16#1234#));
730
  printf("This is a Simple String");
731
  printf("This is a Simple String with a CRLF\nin the middle");
732
  printf("Read Location %d = %h",fmt(123456)&fmt(16#654321#));
733
  printf("-d...-123456 = %d",fmt(-123456));
734
  printf("-d...-123456 = %08d",fmt(-123456));
735
  dw := ( others => '0');
736
  printf("-x...000 = %x",fmt(dw));
737
  dw := "0101010101";
738
  printf("-x...155 = %x",fmt(dw));
739
  printf("-b...155 = %b",fmt(dw));
740
  dw := "0101U10101";
741
  printf("-x...1?5 = %x",fmt(dw));
742
  printf("-b...1?5 = %b",fmt(dw));
743
  dw := "01UUUU0101";
744
  printf("-x...1U5 = %x",fmt(dw));
745
  printf("-b...1U5 = %b",fmt(dw));
746
  printf(" Time is %t ns ");
747
  printf("Negative handling");
748
  intval := 16#0C00000#;                -- set this line to C0000000  for testing
749
  printf(" 08x = %08x",fmt(intval));    -- since 16#C000000# is illegal according to the LRM
750
  printf(" 08h = %08h",fmt(intval));
751
  printf(" 08u = %08u",fmt(intval));
752
 
753
  sprintf( strout , "SPRINTF Read Location %d = %h",fmt(123456)&fmt(16#654321#));
754
  printf("OUT STRING %s",fmt(strout));
755
  write( ll , strout );
756
  writeline(FSTR, ll);
757
  file_close( FSTR);
758
 
759
 
760
  wait for 1 ns;
761
  wait;
762
 end process;
763
 
764
 
765
end TB;
766
 
767
 
768
 
769
 
770
 
771
 
772
 
773
 
774
 
775
 
776
 
777
 
778
 
779
 
780
 
781
 

powered by: WebSVN 2.1.0

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