test-api.vh 3.25 KB
Newer Older
1
2
3
//
// Copyright (C) 2014 Jens Korinth, TU Darmstadt
//
4
// This file is part of Tapasco (TPC).
5
//
6
// Tapasco is free software: you can redistribute it and/or modify
7
8
9
10
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
11
// Tapasco is distributed in the hope that it will be useful,
12
13
14
15
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
17
// along with Tapasco.  If not, see <http://www.gnu.org/licenses/>.
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
`ifndef __TEST_API_VH__
`define __TEST_API_VH__ 1
  // Simple API to write tests:
  `define INTC_BASE			32'h41800000
  `define TARGETIP_BASE 		32'h43C00000
  `define TARGETIP_OFFS 		32'h00010000
  
  task pre_load_mem_from_file;
  input [(1024*8-1):0] filename;
  input [31:0] addr;
  input [31:0] no_bytes;
  begin
   tb.system_i.ps7.inst.ocmc.ocm.pre_load_mem_from_file(
     filename,
     addr,
     no_bytes
   );
  end
  endtask
  
  task setup_system;
  input [7:0] no_inst;
  output [2:0] resp;
  reg [7:0] i;
  reg [31:0] data;
  begin
    // configure slave profiles
    system_i.ps7.inst.set_slave_profile("S_AXI_HP0", 2'b00); // best case
    system_i.ps7.inst.set_slave_profile("S_AXI_ACP", 2'b00); // best case
  
    // setup AXI interrupt controller to receive all irqs
    system_i.ps7.inst.write_data(
      `INTC_BASE + 32'h08, 4, 32'hFFFFFFFF, resp
    );
    system_i.ps7.inst.write_data(
      `INTC_BASE + 32'h1C, 4, 32'h3, resp
    );
    // read ISR
    system_i.ps7.inst.read_data(
      `INTC_BASE, 4, data, resp
    );
  
    for (i = 0; i < no_inst; i = i + 1) begin
      // activate interrupts on first instance of target IP
      system_i.ps7.inst.write_data(
        `TARGETIP_BASE + i * `TARGETIP_OFFS + 32'h04, 4, 32'h1, resp
      );
      system_i.ps7.inst.write_data(
        `TARGETIP_BASE + 32'h08, 4, 32'h1, resp
      );
    end

    $display("--- SYSTEM SETUP FINISHED @ %0d ---", $time);
  end
  endtask
  
  task launch_kernel;
  input [7:0] inst_no;
  output [3:0] irqs;
  reg [2:0] resp;
  begin
    // start run
    system_i.ps7.inst.write_data(
      `TARGETIP_BASE + inst_no * `TARGETIP_OFFS , 4, 32'h1, resp
    );
    
    // wait for ap_done
    system_i.ps7.inst.wait_interrupt( 0, irqs );
  end
  endtask
  
  task read_kernel_reg;
  input [7:0] inst_no;
  input [9:0] register;
  output [31:0] data;
  output [2:0] resp;
  begin
    // read register
    system_i.ps7.inst.read_data(
      `TARGETIP_BASE + inst_no * `TARGETIP_OFFS + (register << 2), 4, data, resp
    );
  end
  endtask
  
  task write_kernel_reg;
  input [7:0] inst_no;
  input [9:0] register;
  input [31:0] data;
  output [2:0] resp;
  begin
    // write register
    system_i.ps7.inst.write_data(
      `TARGETIP_BASE + inst_no * `TARGETIP_OFFS + (register << 2), 4, data, resp
    );
  end
  endtask
  
  task read_mem;
  input [31:0] start_addr;
  input [6:0] no_of_bytes;
  output [1023:0] data;
  begin
    system_i.ps7.inst.ocmc.ocm.read_mem(
      data,
      start_addr,
      no_of_bytes
    );
  end
  endtask
`endif /* __TEST_API_VH__ */