blob: 5211117246157ea3dc8d560319c362bc399a2b86 [file] [log] [blame]
Derek Chow32e0b832023-08-10 10:44:42 -07001// Copyright 2023 Google LLC
Cindy Liu0959e532023-10-19 11:45:06 -07002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
Derek Chow32e0b832023-08-10 10:44:42 -070014
15#include "tests/verilator_sim/sysc_tb.h"
16
17#include "VKelvin.h"
18#include "tests/verilator_sim/matcha/kelvin_if.h"
19#include "tests/verilator_sim/kelvin/debug_if.h"
20
21struct Kelvin_tb : Sysc_tb {
22 sc_in<bool> io_halted;
23 sc_in<bool> io_fault;
24
25 using Sysc_tb::Sysc_tb; // constructor
26
27 void posedge() {
28 check(!io_fault, "io_fault");
29 if (io_halted) sc_stop();
30 }
31};
32
33static void Kelvin_run(const char* name, const char* bin, const bool trace) {
34 VKelvin core(name);
35 Kelvin_tb tb("Kelvin_tb", 100000000, /* random= */ false);
36 Kelvin_if mif("Kelvin_if", bin);
37 Debug_if dbg("Debug_if", &mif);
38
39 sc_signal<bool> host_req;
40 sc_signal<bool> finish;
41 sc_signal<bool> fault;
42 sc_signal<bool> clk_freeze;
43 sc_signal<bool> ml_reset;
44 sc_signal<bool> volt_sel;
45 sc_signal<bool> slog_valid;
46 sc_signal<sc_bv<5> > slog_addr;
47 sc_signal<sc_bv<32> > slog_data;
48 sc_signal<sc_bv<32> > pc_start;
49 sc_signal<bool> cvalid;
50 sc_signal<bool> cready;
51 sc_signal<bool> cwrite;
52 sc_signal<sc_bv<32> > caddr;
53 sc_signal<sc_bv<7> > cid;
54 sc_signal<sc_bv<256> > wdata;
55 sc_signal<sc_bv<32> > wmask;
56 sc_signal<bool> rvalid;
57 sc_signal<sc_bv<7> > rid;
58 sc_signal<sc_bv<256> > rdata;
59
60 ml_reset = 0;
61 clk_freeze = 0;
62 pc_start = 0x00000000;
63 volt_sel = 0;
64
65 tb.io_halted(finish);
66 tb.io_fault(fault);
67
68 core.clk_i(tb.clock);
69 core.rst_ni(tb.resetn);
70 core.ml_reset(ml_reset);
71 core.clk_freeze(clk_freeze);
72 core.pc_start(pc_start);
73 core.volt_sel(volt_sel);
74 core.finish(finish);
75 core.fault(fault);
76 core.host_req(host_req);
77 core.slog_valid(slog_valid);
78 core.slog_addr(slog_addr);
79 core.slog_data(slog_data);
80
Alex Van Damme06ce3642024-02-13 13:07:40 -080081 core.mem_cvalid(cvalid);
82 core.mem_cready(cready);
83 core.mem_cwrite(cwrite);
84 core.mem_caddr(caddr);
85 core.mem_cid(cid);
86 core.mem_wdata(wdata);
87 core.mem_wmask(wmask);
88 core.mem_rvalid(rvalid);
89 core.mem_rid(rid);
90 core.mem_rdata(rdata);
Derek Chow32e0b832023-08-10 10:44:42 -070091
92 mif.clock(tb.clock);
93 mif.reset(tb.reset);
94 mif.io_bus_cvalid(cvalid);
95 mif.io_bus_cready(cready);
96 mif.io_bus_cwrite(cwrite);
97 mif.io_bus_caddr(caddr);
98 mif.io_bus_cid(cid);
99 mif.io_bus_wdata(wdata);
100 mif.io_bus_wmask(wmask);
101 mif.io_bus_rvalid(rvalid);
102 mif.io_bus_rid(rid);
103 mif.io_bus_rdata(rdata);
104
105 dbg.clock(tb.clock);
106 dbg.reset(tb.reset);
107 dbg.io_slog_valid(slog_valid);
108 dbg.io_slog_addr(slog_addr);
109 dbg.io_slog_data(slog_data);
110
111 if (trace) {
112 tb.trace(core);
113 }
114
115 tb.start();
116}
117
118int sc_main(int argc, char *argv[]) {
119 if (argc <= 1) {
120 printf("Expected binary file argument\n");
121 return -1;
122 }
123
124 const char* path = argv[1];
125 Kelvin_run(Sysc_tb::get_name(argv[0]), path, false);
126 return 0;
127}