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

Subversion Repositories ahbmaster

[/] [ahbmaster/] [trunk/] [test79_AHBmaster/] [component/] [Actel/] [DirectCore/] [CoreAHBLite/] [5.3.101/] [rtl/] [vhdl/] [amba_bfm/] [misc.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: 22340 $
23
-- SVN $Date: 2014-04-11 21:59:35 +0530 (Fri, 11 Apr 2014) $
24
--
25
--
26
-- Resolved SARs
27
-- SAR      Date     Who  Description
28
--
29
--
30
-- Notes: 
31
--        
32
-- *********************************************************************/ 
33
 
34
 
35
library IEEE;
36
use ieee.std_logic_1164.all;
37
use ieee.numeric_std.all;
38
 
39
 
40
package bfm_misc is
41
 
42
type INTEGER_ARRAY is array ( INTEGER range <>) of INTEGER;
43
 
44
subtype NIBBLE     is UNSIGNED ( 3 downto 0);
45
subtype BYTE       is UNSIGNED ( 7 downto 0);
46
subtype WORD       is UNSIGNED (15 downto 0);
47
subtype DWORD      is UNSIGNED (31 downto 0);
48
subtype QWORD      is UNSIGNED (63 downto 0);
49
 
50
type BYTE_ARRAY    is array ( INTEGER range <>) of BYTE;
51
type WORD_ARRAY    is array ( INTEGER range <>) of WORD;
52
type DWORD_ARRAY   is array ( INTEGER range <>) of DWORD;
53
type TIME_ARRAY    is array ( INTEGER range <>) of TIME;
54
type BOOLEAN_ARRAY is array ( INTEGER range <>) of BOOLEAN;
55
 
56
type BOOLEAN_VECTOR is array ( INTEGER range <>) of BOOLEAN;
57
 
58
constant ZERO    : DWORD := (others => '0');
59
constant ZERO16  : WORD := (others => '0');
60
constant ALLONES : std_logic_vector (31 downto 0) := (others => '0');
61
constant UNKNOWN : std_logic_vector (31 downto 0) := (others => 'U');
62
 
63
   procedure waitclocks(signal clock : std_logic; N : INTEGER);
64
 
65
   function to_std_logic( x: UNSIGNED ) return std_logic_vector;
66
   function to_std_logic( x: SIGNED ) return std_logic_vector;
67
   function to_unsigned( x: std_logic_vector ) return UNSIGNED;
68
   function to_signed( x: std_logic_vector ) return SIGNED;
69
 
70
 
71
   function to_std_logic( tmp : INTEGER ) return std_logic;
72
   function to_std_logic_invert( tmp : INTEGER ) return std_logic;
73
   function to_std_logic( tmp : BOOLEAN ) return std_logic;
74
   function to_std_logic_invert( tmp : BOOLEAN ) return std_logic;
75
   function to_boolean( tmp : integer ) return BOOLEAN;
76
   function to_boolean( tmp : std_logic ) return BOOLEAN;
77
   function to_boolean_invert( tmp : std_logic ) return BOOLEAN;
78
   function to_integer( tmp : boolean ) return INTEGER;
79
 
80
   function to_byte  ( x : INTEGER ) return BYTE;
81
   function to_word  ( x : INTEGER ) return WORD;
82
   function to_dword ( x : INTEGER ) return DWORD;
83
 
84
   function to_byte  ( str : STRING ) return BYTE;
85
   function to_word  ( str : STRING ) return WORD;
86
   function to_dword ( str : STRING ) return DWORD;
87
 
88
   function to_dword_signed ( str : STRING ) return SIGNED;
89
 
90
   function init_data( seed : INTEGER; size : INTEGER) return DWORD_ARRAY;
91
   function init_data( seed : STRING; size : INTEGER) return DWORD_ARRAY;
92
 
93
   function maxval (a,b : integer) return integer;
94
   function minval (a,b : integer) return integer;
95
   function absval (a   : integer) return integer;
96
 
97
   function muxop ( s: boolean; a,b   : integer) return integer;
98
 
99
   function is_hex( str : STRING ) return BOOLEAN;
100
   function to_uppercase( c : character) return character;
101
   function onoff( x : boolean) return string;
102
   function notonoff( x : boolean) return string;
103
 
104
   function decode_params( str : string ) return INTEGER_ARRAY;
105
   procedure getstring( para : out string; str : string;  pos : inout integer);
106
 
107
end bfm_misc;
108
 
109
 
110
package body bfm_misc is
111
 
112
---------------------------------------------------------------------
113
-- Handle SIGNED and UNSIGNED to std_logic_vector conversions
114
--
115
 
116
function to_std_logic( x: UNSIGNED ) return std_logic_vector is
117
variable y: std_logic_vector(x'range);
118
begin
119
   for i in x'range loop
120
     y(i) := x(i);
121
   end loop;
122
   return(y);
123
end to_std_logic;
124
 
125
function to_unsigned( x: std_logic_vector ) return UNSIGNED is
126
variable y: UNSIGNED(x'range);
127
begin
128
   for i in x'range loop
129
     y(i) := x(i);
130
   end loop;
131
   return(y);
132
end to_unsigned;
133
 
134
function to_std_logic( x: SIGNED ) return std_logic_vector is
135
variable y: std_logic_vector(x'range);
136
begin
137
   for i in x'range loop
138
     y(i) := x(i);
139
   end loop;
140
   return(y);
141
end to_std_logic;
142
 
143
function to_signed( x: std_logic_vector ) return SIGNED is
144
variable y: SIGNED(x'range);
145
begin
146
   for i in x'range loop
147
     y(i) := x(i);
148
   end loop;
149
   return(y);
150
end to_signed;
151
 
152
 
153
---------------------------------------------------------------------
154
-- Miscellanous Conversions
155
--
156
 
157
function to_integer( tmp : boolean ) return INTEGER is
158
 begin
159
   if tmp then return (1);
160
          else return (0);
161
   end if;
162
end to_integer;
163
 
164
function to_std_logic_invert( tmp : INTEGER ) return std_logic is
165
 begin
166
   if tmp=1 then return ('0');
167
            else return ('1');
168
   end if;
169
 end to_std_logic_invert;
170
 
171
function to_std_logic( tmp : INTEGER ) return std_logic is
172
 begin
173
   if tmp=1 then return ('1');
174
            else return ('0');
175
   end if;
176
 end to_std_logic;
177
 
178
function to_std_logic_invert( tmp : BOOLEAN ) return std_logic is
179
 begin
180
   if tmp then return ('0');
181
          else return ('1');
182
   end if;
183
 end to_std_logic_invert;
184
 
185
function to_std_logic( tmp : BOOLEAN ) return std_logic is
186
 begin
187
   if tmp then return ('1');
188
          else return ('0');
189
   end if;
190
 end to_std_logic;
191
 
192
function to_boolean_invert( tmp : std_logic ) return BOOLEAN is
193
 begin
194
   if to_X01(tmp)='0' then return (TRUE);
195
                      else return (FALSE);
196
   end if;
197
 end to_boolean_invert;
198
 
199
function to_boolean( tmp : std_logic ) return BOOLEAN is
200
 begin
201
   if to_X01(tmp)='1' then return (TRUE);
202
                      else return (FALSE);
203
   end if;
204
 end to_boolean;
205
 
206
function to_boolean( tmp : integer ) return BOOLEAN is
207
 begin
208
   if tmp/=0 then return (TRUE);
209
             else return (FALSE);
210
   end if;
211
 end to_boolean;
212
 
213
 
214
 
215
 
216
 
217
procedure waitclocks(signal clock : std_logic;
218
                     N : INTEGER) is
219
 begin
220
  if N>0 then
221
    for i in 1 to N loop
222
     wait until clock'event and clock='0';
223
    end loop;
224
  end if;
225
 end waitclocks;
226
 
227
function to_byte ( x : INTEGER ) return BYTE is
228
 variable x1 : BYTE;
229
 begin
230
   x1 := to_unsigned( x,8);
231
   return(x1);
232
 end to_byte;
233
 
234
function to_word ( x : INTEGER ) return WORD is
235
 variable x1 : WORD;
236
 begin
237
   x1 := to_unsigned( x,16);
238
   return(x1);
239
 end to_word;
240
 
241
function to_dword ( x : INTEGER ) return DWORD is
242
 variable x1 : DWORD;
243
 begin
244
   x1 := to_unsigned( x,32);
245
   return(x1);
246
  return(x1);
247
 end to_dword;
248
 
249
 
250
function to_byte( str : STRING ) return BYTE is
251
 variable str1 : string ( 1 to 2);
252
 variable x  : INTEGER;
253
 variable dw : byte;
254
 begin
255
  str1 := str;
256
  for i in 1 to 2 loop
257
     case str1(i) is
258
      when '0' to '9' => x:= CHARACTER'POS(str1(i)) - CHARACTER'POS('0');
259
      when 'A' to 'F' => x:= 10 + CHARACTER'POS(str1(i)) - CHARACTER'POS('A');
260
      when 'a' to 'z' => x:= 10 + CHARACTER'POS(str1(i)) - CHARACTER'POS('a');
261
      when others => assert  FALSE
262
                        report "Illegal Character in the Hex String"
263
                        severity failure;
264
     end case;
265
     dw(11- (i*4)  downto 8 - (i*4) ) := to_unsigned(x,4);
266
  end loop;
267
  return(dw);
268
 end to_byte;
269
 
270
function to_word( str : STRING ) return WORD is
271
 variable str1 : string (1 to 4);
272
 variable dw : word;
273
 begin
274
  str1 := str;
275
  dw(15 downto 8) := to_byte( str1(1 to 2));
276
  dw( 7 downto 0) := to_byte( str1(3 to 4));
277
  return(dw);
278
 end to_word;
279
 
280
function to_dword( str : STRING ) return DWORD is
281
 variable str1 : string (1 to 8);
282
 variable dw : dword;
283
 begin
284
  str1 := str;
285
  dw(31 downto 16) := to_word( str1(1 to 4));
286
  dw(15 downto  0) := to_word( str1(5 to 8));
287
  return(dw);
288
 end to_dword;
289
 
290
 
291
 
292
function to_dword_signed ( str : STRING ) return SIGNED is
293
variable r_sign    : SIGNED(31 downto 0);
294
variable r_unsign  : UNSIGNED(31 downto 0);
295
begin
296
  r_unsign := to_dword(str);
297
  for i in r_sign'range loop
298
    r_sign(i) := r_unsign(i);
299
  end loop;
300
  return(r_sign);
301
end to_dword_signed;
302
 
303
 
304
 
305
function init_data( seed : INTEGER; size : INTEGER) return DWORD_ARRAY is
306
 variable xdata : DWORD_ARRAY (0 to 255);
307
 begin
308
  -- In case there are any 16#FFFFFFFF# type constants Causes VSS to complain
309
  assert seed>=0
310
    report "INIT_DATA with integer Seed cannot be negative"
311
    severity failure;
312
  for i in 0 to size-1 loop
313
    xdata(i) := to_dword(seed+i);
314
  end loop;
315
  return(xdata(0 to size-1));
316
end init_data;
317
 
318
function init_data( seed : STRING; size : INTEGER) return DWORD_ARRAY is
319
 variable xdata  : DWORD_ARRAY (0 to 255);
320
 variable seedxx : DWORD;
321
 begin
322
  seedxx := to_dword(seed);
323
  for i in 0 to size-1 loop
324
    xdata(i) := seedxx +i ;
325
  end loop;
326
  return(xdata(0 to size-1));
327
end init_data;
328
 
329
 
330
function maxval( a,b : integer) return integer is
331
 begin
332
  if (a>b) then return(a);
333
   else return(b);
334
  end if;
335
end maxval;
336
 
337
function minval( a,b : integer) return integer is
338
 begin
339
  if (a<b) then return(a);
340
   else return(b);
341
  end if;
342
end minval;
343
 
344
function absval( a : integer) return integer is
345
 begin
346
  if (a>0) then return(a);
347
   else return(-a);
348
  end if;
349
end absval;
350
 
351
function muxop ( s: boolean; a,b   : integer) return integer is
352
 begin
353
   if s then return(a);
354
        else return(b);
355
   end if;
356
end muxop;
357
 
358
 
359
 
360
function is_hex( str : STRING ) return BOOLEAN is
361
variable ok   : boolean;
362
variable str1 : string ( 1 to 2);
363
begin
364
  ok   := TRUE;
365
  str1 := str;
366
  for i in 1 to 2 loop
367
     case str1(i) is
368
      when '0' to '9' =>
369
      when 'A' to 'F' =>
370
      when 'a' to 'z' =>
371
      when others     => OK := FALSE;
372
     end case;
373
  end loop;
374
  return(ok);
375
end is_hex;
376
 
377
 
378
function to_uppercase( c : character) return character is
379
variable ok   : boolean;
380
variable cuc  : character;
381
begin
382
  case c is
383
      when 'a' to 'z' => cuc := character'val(character'pos(c)-32);
384
      when others     => cuc := c;
385
  end case;
386
  return(cuc);
387
end to_uppercase;
388
 
389
 
390
function onoff( x : boolean) return string is
391
 begin
392
  if X then return("On");
393
       else return("Off");
394
  end if;
395
end onoff;
396
 
397
function notonoff( x : boolean) return string is
398
 begin
399
  if not X then return("On");
400
       else return("Off");
401
  end if;
402
end notonoff;
403
 
404
--------------------------------------------------------------------
405
-- returns no of params, para1, para2 etc
406
 
407
function decode_params( str : string) return INTEGER_ARRAY is
408
variable pos    : INTEGER;
409
variable PARAMS : INTEGER_ARRAY(0 to 9);
410
variable i,x    : INTEGER;
411
variable ERR    : BOOLEAN;
412
variable BASE   : INTEGER;
413
variable c      : Character;
414
begin
415
 pos := 2;
416
 i   := 0;
417
 ERR := FALSE;
418
 PARAMS := ( others => 0 );
419
 while str(pos)/=NUL and not ERR loop
420
   while str(pos)=' ' loop
421
     pos := pos+1;
422
   end loop;
423
   x := 0;
424
   BASE := 10;
425
   c := str(pos);
426
   while c/=' ' and c/=NUL and  c/=',' and not ERR loop
427
     case str(pos) is
428
      when '0' to '9' =>  x :=x * BASE + character'pos(c) - character'pos('0');
429
      when 'A' to 'F' =>  BASE := 16;
430
                          x :=x * BASE + 10 + character'pos(c) - character'pos('A');
431
      when 'a' to 'f' =>  BASE := 16;
432
                          x :=x * BASE + 10 + character'pos(c) - character'pos('a');
433
      when '#'        => BASE := 16;
434
      when others => ERR := TRUE;
435
                     --printf("Illegal character POS %d:",fmt(pos)&fmt(str));
436
     end case;
437
     pos := pos +1;
438
     c := str(pos);
439
   end loop;
440
   i := i + 1;
441
   PARAMS(i) := x;
442
 end loop;
443
 if ERR then
444
   PARAMS(0) := 0;
445
 else
446
   PARAMS(0) := i;
447
 end if;
448
-- for i in 0 to PARAMS(0) loop
449
--  printf("Got %d",fmt(params(i)));
450
-- end loop;
451
 
452
 return(PARAMS);
453
end decode_params;
454
 
455
 
456
 
457
procedure getstring( para : out string; str : string;  pos : inout integer) is
458
variable i,x    : INTEGER;
459
variable ERR    : BOOLEAN;
460
variable BASE   : INTEGER;
461
variable c      : Character;
462
begin
463
 i   := 1;
464
 ERR := FALSE;
465
 for i in para'range loop
466
   para(i) :=  NUL;
467
 end loop;
468
 while str(pos)=' ' loop
469
   pos := pos+1;
470
 end loop;
471
 while str(pos) /= ' ' and str(pos)/=',' and str(pos)/=NUL and str(pos)/=';'  loop
472
   para(i) := str(pos);
473
   i := i + 1;
474
   pos := pos + 1;
475
 end loop;
476
end getstring;
477
 
478
end bfm_misc;
479
 
480
 
481
 
482
 
483
 

powered by: WebSVN 2.1.0

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