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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [gaisler/] [sim/] [sim.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
------------------------------------------------------------------------------
2
--  This file is a part of the GRLIB VHDL IP LIBRARY
3
--  Copyright (C) 2003, Gaisler Research
4
--
5
--  This program is free software; you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation; either version 2 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This program is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
--
15
--  You should have received a copy of the GNU General Public License
16
--  along with this program; if not, write to the Free Software
17
--  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
18
-----------------------------------------------------------------------------
19
-- Package:     sim
20
-- File:        sim.vhd
21
-- Author:      Jiri Gaisler - Gaisler Research
22
-- Description: Simulation models and functions declarations
23
------------------------------------------------------------------------------
24
 
25
-- pragma translate_off
26
 
27
library ieee;
28
use ieee.std_logic_1164.all;
29
use std.textio.all;
30
library grlib;
31
use grlib.stdlib.all;
32
use grlib.stdio.all;
33
use grlib.amba.all;
34
 
35
 
36
package sim is
37
 
38
  component sram
39
      generic (index : integer := 0;             -- Byte lane (0 - 3)
40
        Abits: Positive := 10;          -- Default 10 address bits (1 Kbyte)
41
        tacc : integer := 10;           -- access time (ns)
42
        fname : string := "ram.dat";    -- File to read from
43
        clear : integer := 0);   -- Clear memory
44
      port (
45
        a : in std_logic_vector(abits-1 downto 0);
46
        D : inout std_logic_vector(7 downto 0);
47
        CE1 : in std_logic;
48
        WE : in std_logic;
49
        OE : in std_logic);
50
  end component;
51
 
52
  component sram16
53
  generic (
54
    index : integer := 0;                -- Byte lane (0 - 3)
55
    abits: Positive := 10;              -- Default 10 address bits (1 Kbyte)
56
    echk : integer := 0;         -- Generate EDAC checksum
57
    tacc : integer := 10;               -- access time (ns)
58
    fname : string := "ram.dat");       -- File to read from
59
  port (
60
    a : in std_logic_vector(abits-1 downto 0);
61
    d : inout std_logic_vector(15 downto 0);
62
    lb : in std_logic;
63
    ub : in std_logic;
64
    ce : in std_logic;
65
    we : in std_ulogic;
66
    oe : in std_ulogic);
67
  end component;
68
 
69
  component sramft
70
      generic (index : integer := 0;             -- Byte lane (0 - 3)
71
               Abits: Positive := 10;           -- Default 10 address bits (1 Kbyte)
72
               tacc : integer := 10;            -- access time (ns)
73
               fname : string := "ram.dat");    -- File to read from
74
      port (
75
        a : in std_logic_vector(abits-1 downto 0);
76
        D : inout std_logic_vector(7 downto 0);
77
        CE1 : in std_logic;
78
        WE : in std_logic;
79
        OE : in std_logic);
80
  end component;
81
 
82
  procedure hexread(L : inout line; value:out bit_vector);
83
  procedure hexread(L : inout line; value:out std_logic_vector);
84
  function ishex(c : character) return boolean;
85
  function buskeep(signal v : in std_logic_vector) return std_logic_vector;
86
  function buskeep(signal c : in std_logic) return std_logic;
87
 
88
  component phy is
89
    generic(
90
      address       : integer range 0 to 31 := 0;
91
      extended_regs : integer range 0 to 1  := 1;
92
      aneg          : integer range 0 to 1  := 1;
93
      base100_t4    : integer range 0 to 1  := 0;
94
      base100_x_fd  : integer range 0 to 1  := 1;
95
      base100_x_hd  : integer range 0 to 1  := 1;
96
      fd_10         : integer range 0 to 1  := 1;
97
      hd_10         : integer range 0 to 1  := 1;
98
      base100_t2_fd : integer range 0 to 1  := 1;
99
      base100_t2_hd : integer range 0 to 1  := 1;
100
      base1000_x_fd : integer range 0 to 1  := 0;
101
      base1000_x_hd : integer range 0 to 1  := 0;
102
      base1000_t_fd : integer range 0 to 1  := 1;
103
      base1000_t_hd : integer range 0 to 1  := 1
104
      );
105
    port(
106
      rstn     : in std_logic;
107
      mdio     : inout std_logic;
108
      tx_clk   : out std_logic;
109
      rx_clk   : out std_logic;
110
      rxd      : out std_logic_vector(7 downto 0);
111
      rx_dv    : out std_logic;
112
      rx_er    : out std_logic;
113
      rx_col   : out std_logic;
114
      rx_crs   : out std_logic;
115
      txd      : in std_logic_vector(7 downto 0);
116
      tx_en    : in std_logic;
117
      tx_er    : in std_logic;
118
      mdc      : in std_logic;
119
      gtx_clk  : in std_logic
120
      );
121
  end component;
122
 
123
  type ata_in_type is record                    --signals from host to device
124
    csel : std_logic;                           --cable select
125
    cs   : std_logic_vector(1 downto 0);                 --chip select
126
    --dd   : std_logic_vector(15 downto 0);             --data bus
127
    dasp : std_logic;                           --Device active / slave present
128
    da   : std_logic_vector(2 downto 0);                 --device adress
129
    dmack: std_logic;                           --DMA acknowledge
130
    dior : std_logic;                           --I/O read strobe
131
    diow : std_logic;                           --I/O write strobe
132
    reset: std_logic;                           --Reset
133
  end record;
134
 
135
  constant ATAI_RESET_VECTOR : ata_in_type := ('0',(others=>'0'),'0',
136
    (others=>'0'),'0','0','0','0');
137
 
138
  type ata_out_type is record                   --signals from device to host
139
    dmarq: std_logic;                           --DMA request
140
    intrq: std_logic;                           --Interrupt request
141
    iordy: std_logic;                           --I/O ready
142
    pdiag: std_logic;                           --Passed diagnostics
143
  end record;
144
 
145
  constant ATAO_RESET_VECTOR : ata_out_type := ('0','0','1','0');
146
 
147
  component ata_device is
148
  generic(sector_length: integer :=512; --in bytes
149
        disk_size: integer :=32; --in sectors
150
        log2_size : integer :=14; --Log2(sector_length*disk_size), abits
151
        Tlr : time := 35 ns
152
        );
153
  port(
154
  --for convinience, not part of ATA interface
155
    clk   : in std_logic;
156
    rst   : in std_logic;
157
  --interface to host bus adapter
158
    d     : inout std_logic_vector(15 downto 0) := (others=>'Z');
159
    atai  : in  ata_in_type := ATAI_RESET_VECTOR;
160
    atao  : out ata_out_type:= ATAO_RESET_VECTOR);
161
  end component;
162
 
163
  procedure leon3_subtest(subtest : integer);
164
  procedure mctrl_subtest(subtest : integer);
165
  procedure gptimer_subtest(subtest : integer);
166
  procedure dsu3_subtest(subtest : integer);
167
  procedure spw_subtest(subtest : integer);
168
  procedure spictrl_subtest(subtest : integer);
169
  procedure i2cmst_subtest(subtest : integer);
170
  procedure uhc_subtest(subtest : integer);
171
  procedure ehc_subtest(subtest : integer);
172
  procedure irqmp_subtest(subtest : integer);
173
  procedure spimctrl_subtest(subtest : integer);
174
  procedure svgactrl_subtest(subtest : integer);
175
 
176
  component ahbrep
177
  generic (
178
    hindex  : integer := 0;
179
    haddr   : integer := 0;
180
    hmask   : integer := 16#fff#;
181
    halt    : integer := 1);
182
  port (
183
    rst     : in  std_ulogic;
184
    clk     : in  std_ulogic;
185
    ahbsi   : in  ahb_slv_in_type;
186
    ahbso   : out ahb_slv_out_type
187
  );
188
  end component;
189
 
190
  component i2c_slave_model
191
    port (
192
      scl : inout std_logic;
193
      sda : inout std_logic
194
      );
195
  end component;
196
 
197
  component ulpi
198
    generic (
199
      LSDEV      : boolean := false -- Low-Speed device attached
200
      );
201
    port (
202
      clkout  : out   std_ulogic;
203
      d       : inout std_logic_vector(7 downto 0);
204
      nxt     : out   std_ulogic;
205
      stp     : in    std_ulogic;
206
      dir     : out   std_ulogic;
207
      resetn  : in    std_ulogic
208
    );
209
  end component;
210
 
211
  component utmi
212
    generic (
213
      LSDEV      : boolean := false;  -- Low-Speed device attached
214
      utmi_dw8   : integer            -- Interface data width
215
      );
216
    port (
217
      uclk      : out std_ulogic;
218
      xcvrsel   : in  std_logic_vector(1 downto 0);
219
      termsel   : in  std_ulogic;
220
      suspendm  : in  std_ulogic;
221
      opmode    : in  std_logic_vector(1 downto 0);
222
      txvalid   : in  std_ulogic;
223
      drvvbus   : in  std_ulogic;
224
      validho   : in  std_ulogic;
225
      host      : in  std_ulogic;
226
      utm_rst   : in  std_ulogic;
227
      linestate : out std_logic_vector(1 downto 0);
228
      txready   : out std_ulogic;
229
      rxvalid   : out std_ulogic;
230
      rxactive  : out std_ulogic;
231
      rxerror   : out std_ulogic;
232
      vbusvalid : out std_ulogic;
233
      validhi   : out std_ulogic;
234
      hostdisc  : out std_ulogic;
235
      datah     : inout std_logic_vector(7 downto 0);
236
      data      : inout std_logic_vector(7 downto 0)
237
      );
238
  end component;
239
 
240
end;
241
 
242
package body sim is
243
 
244
  function to_xlhz(i : std_logic) return std_logic is
245
  begin
246
    case to_X01Z(i) is
247
    when 'Z' => return('Z');
248
    when '0' => return('L');
249
    when '1' => return('H');
250
    when others => return('X');
251
    end case;
252
  end;
253
 
254
  type logic_xlhz_table IS ARRAY (std_logic'LOW TO std_logic'HIGH) OF std_logic;
255
 
256
  constant cvt_to_xlhz : logic_xlhz_table := (
257
                         'Z',  -- 'U'
258
                         'Z',  -- 'X'
259
                         'L',  -- '0'
260
                         'H',  -- '1'
261
                         'Z',  -- 'Z'
262
                         'Z',  -- 'W'
263
                         'L',  -- 'L'
264
                         'H',  -- 'H'
265
                         'Z'   -- '-'
266
                        );
267
  function buskeep (signal v : in std_logic_vector) return std_logic_vector is
268
  variable res : std_logic_vector(v'range);
269
  begin
270
    for i in v'range loop res(i) := cvt_to_xlhz(v(i)); end loop;
271
    return(res);
272
  end;
273
 
274
  function buskeep (signal c : in std_logic) return std_logic is
275
  begin
276
    return(cvt_to_xlhz(c));
277
  end;
278
 
279
  procedure char2hex(C: character; result: out bit_vector(3 downto 0);
280
            good: out boolean; report_error: in boolean) is
281
  begin
282
    good := true;
283
    case C is
284
    when '0' => result :=  x"0";
285
    when '1' => result :=  x"1";
286
    when '2' => result :=  X"2";
287
    when '3' => result :=  X"3";
288
    when '4' => result :=  X"4";
289
    when '5' => result :=  X"5";
290
    when '6' => result :=  X"6";
291
    when '7' => result :=  X"7";
292
    when '8' => result :=  X"8";
293
    when '9' => result :=  X"9";
294
    when 'A' => result :=  X"A";
295
    when 'B' => result :=  X"B";
296
    when 'C' => result :=  X"C";
297
    when 'D' => result :=  X"D";
298
    when 'E' => result :=  X"E";
299
    when 'F' => result :=  X"F";
300
 
301
    when 'a' => result :=  X"A";
302
    when 'b' => result :=  X"B";
303
    when 'c' => result :=  X"C";
304
    when 'd' => result :=  X"D";
305
    when 'e' => result :=  X"E";
306
    when 'f' => result :=  X"F";
307
    when others =>
308
      if report_error then
309
        assert false report
310
          "hexread error: read a '" & C & "', expected a hex character (0-F).";
311
      end if;
312
      good := false;
313
    end case;
314
  end;
315
 
316
  procedure hexread(L:inout line; value:out bit_vector)  is
317
                variable OK: boolean;
318
                variable C:  character;
319
                constant NE: integer := value'length/4; --'
320
                variable BV: bit_vector(0 to value'length-1);    --'
321
                variable S:  string(1 to NE-1);
322
  begin
323
    if value'length mod 4 /= 0 then      --'
324
      assert false report
325
        "hexread Error: Trying to read vector " &
326
        "with an odd (non multiple of 4) length";
327
      return;
328
    end if;
329
 
330
    loop                                    -- skip white space
331
      read(L,C);
332
      exit when ((C /= ' ') and (C /= CR) and (C /= HT));
333
    end loop;
334
 
335
    char2hex(C, BV(0 to 3), OK, false);
336
    if not OK then
337
      return;
338
    end if;
339
 
340
    read(L, S, OK);
341
--    if not OK then
342
--      assert false report "hexread Error: Failed to read the STRING";
343
--      return;
344
--    end if;
345
 
346
    for I in 1 to NE-1 loop
347
      char2hex(S(I), BV(4*I to 4*I+3), OK, false);
348
      if not OK then
349
        return;
350
      end if;
351
    end loop;
352
    value := BV;
353
  end hexread;
354
 
355
  procedure hexread(L:inout line; value:out std_ulogic_vector) is
356
    variable tmp: bit_vector(value'length-1 downto 0);   --'
357
  begin
358
    hexread(L, tmp);
359
    value := TO_X01(tmp);
360
  end hexread;
361
 
362
  procedure hexread(L:inout line; value:out std_logic_vector) is
363
    variable tmp: std_ulogic_vector(value'length-1 downto 0);    --'
364
  begin
365
    hexread(L, tmp);
366
    value := std_logic_vector(tmp);
367
  end hexread;
368
 
369
  function ishex(c:character) return boolean is
370
  variable tmp : bit_vector(3 downto 0);
371
  variable OK : boolean;
372
  begin
373
    char2hex(C, tmp, OK, false);
374
    return OK;
375
  end ishex;
376
 
377
  procedure gptimer_subtest(subtest : integer) is
378
  begin
379
 
380
    case subtest is
381
    when 0 | 1 | 2 | 3 | 4 | 5 | 6  => print("  timer " & tost(subtest+1));
382
    when 8  => print("  chain mode");
383
    when others => print("  sub-system test " & tost(subtest));
384
    end case;
385
 
386
  end;
387
 
388
  procedure leon3_subtest(subtest : integer) is
389
  begin
390
 
391
    case (subtest mod 16) is
392
    when 3 => print("  CPU#" & (tost(subtest/16)) & " register file");
393
    when 4 => print("  CPU#" & (tost(subtest/16)) & " multiplier");
394
    when 5 => print("  CPU#" & (tost(subtest/16)) & " radix-2 divider");
395
    when 6 => print("  CPU#" & (tost(subtest/16)) & " cache system");
396
    when 7 => print("  CPU#" & (tost(subtest/16)) & " multi-processing");
397
    when 8 => print("  CPU#" & (tost(subtest/16)) & " floating-point unit");
398
    when 9 => print("  CPU#" & (tost(subtest/16)) & " itag cache ram");
399
    when 10 => print("  CPU#" & (tost(subtest/16)) & " dtag cache ram");
400
    when 11 => print("  CPU#" & (tost(subtest/16)) & " idata cache ram");
401
    when 12 => print("  CPU#" & (tost(subtest/16)) & " ddata cache ram");
402
    when 13 => print("  CPU#" & (tost(subtest/16)) & " GRFPU test");
403
    when 14 => print("  CPU#" & (tost(subtest/16)) & " memory management unit");
404
    when others => print("  sub-system test " & tost(subtest));
405
    end case;
406
 
407
  end;
408
 
409
  procedure mctrl_subtest(subtest : integer) is
410
  begin
411
 
412
    case subtest is
413
    when 3 => print("  sub-word write");
414
    when 4 => print("  EDAC");
415
    when 5 => print("  write protection");
416
    when others => print("  sub-system test " & tost(subtest));
417
    end case;
418
 
419
  end;
420
 
421
  procedure dsu3_subtest(subtest : integer) is
422
  begin
423
 
424
    case subtest is
425
    when 1 => print("  AHB trace buffer memory (0x55555555)");
426
    when 2 => print("  AHB trace buffer memory (0xAAAAAAAA)");
427
    when 3 => print("  AHB trace buffer addressing");
428
    when others => print("  sub-system test " & tost(subtest));
429
    end case;
430
 
431
  end;
432
 
433
  procedure spw_subtest(subtest : integer) is
434
  begin
435
 
436
    case subtest is
437
    when 1 => print("  Nominal operation, snooping enabled");
438
    when 2 => print("  Nominal operation, snooping disabled");
439
    when 3 => print("  RMAP packet reception");
440
    when 4 => print("  Time functionality");
441
    when others => print("  sub-system test " & tost(subtest));
442
    end case;
443
 
444
  end;
445
 
446
  procedure spictrl_subtest(subtest : integer) is
447
  begin
448
 
449
    case subtest is
450
    when 1 => print("  APB interface reset values");
451
    when 2 => print("  Loopback mode");
452
    when others => print("  sub-system test " & tost(subtest));
453
    end case;
454
 
455
  end;
456
 
457
  procedure i2cmst_subtest(subtest : integer) is
458
  begin
459
 
460
    case subtest is
461
    when 1 => print("  APB interface reset values");
462
    when 2 => print("  Data transfer");
463
    when others => print("  sub-system test " & tost(subtest));
464
    end case;
465
 
466
  end;
467
 
468
  procedure uhc_subtest(subtest : integer) is
469
  begin
470
 
471
    case subtest is
472
    when 1 => print("  I/O register reset values");
473
    when 2 => print("  Host Controller Reset");
474
    when 3 => print("  Isochronous IN and OUT");
475
    when 4 => print("  Control OUT, Bulk IN");
476
    when others => print("  sub-system test " & tost(subtest));
477
    end case;
478
 
479
  end;
480
 
481
  procedure ehc_subtest(subtest : integer) is
482
  begin
483
 
484
    case subtest is
485
    when 1 => print("  Register reset values");
486
    when 2 => print("  Host Controller Reset");
487
    when 3 => print("  Periodic schedule");
488
    when 4 => print("  Asynchronous schedule");
489
    when others => print("  sub-system test " & tost(subtest));
490
    end case;
491
 
492
  end;
493
  procedure irqmp_subtest(subtest : integer) is
494
  begin
495
 
496
    case subtest is
497
    when 1 => print("  Nominal interrupts");
498
    when 2 => print("  Extended interrupts");
499
    when others => print("  sub-system test " & tost(subtest));
500
    end case;
501
 
502
  end;
503
 
504
  procedure spimctrl_subtest(subtest : integer) is
505
  begin
506
 
507
    case subtest is
508
    when 1 => print("  Initial values");
509
    when 2 => print("  User mode transfer");
510
    when others => print("  sub-system test " & tost(subtest));
511
    end case;
512
 
513
  end;
514
 
515
  procedure svgactrl_subtest(subtest : integer) is
516
  begin
517
 
518
    case subtest is
519
    when 1 => print("  Check available clocks");
520
    when 2 => print("  Draw screen");
521
    when others => print("  sub-system test " & tost(subtest));
522
    end case;
523
 
524
  end;
525
 
526
 
527
end;
528
-- pragma translate_on

powered by: WebSVN 2.1.0

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