forked from OpenXiangShan/tl-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Emu.h
90 lines (79 loc) · 2.39 KB
/
Emu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
//
// Created by ljw on 10/22/21.
//
#ifndef TLC_TEST_EMU_H
#define TLC_TEST_EMU_H
#include "verilated.h"
#include "VTestTop.h"
#include <getopt.h>
#if VM_TRACE == 1
#include "verilated_vcd_c.h"
#endif
#include "../Utils/ScoreBoard.h"
#include "../Utils/Common.h"
#include "../TLAgent/ULAgent.h"
#include "../TLAgent/CAgent.h"
#include "../Fuzzer/Fuzzer.h"
#include "../ChiselDB/chisel_db.h"
class Emu {
private:
typedef tl_agent::BaseAgent BaseAgent_t;
typedef tl_agent::ULAgent ULAgent_t;
typedef tl_agent::CAgent CAgent_t;
const static int NR_AGENTS = NR_CAGENTS + NR_ULAGENTS;
VTestTop *dut_ptr;
VerilatedVcdC* tfp;
GlobalBoard<paddr_t> *globalBoard;
BaseAgent_t ** const agents = new BaseAgent_t*[NR_AGENTS];
Fuzzer ** const fuzzers = new Fuzzer*[NR_AGENTS];
uint64_t seed = 0, wave_begin = 0, wave_end = 0;
bool enable_wave = true;
bool wave_full = false;
inline char* cycle_wavefile(uint64_t cycles, time_t t);
void parse_args(int argc, char **argv);
public:
Emu(int argc, char **argv);
~Emu();
uint64_t exe_cycles = 10000000;
inline void reset(uint64_t n);
inline void neg_edge();
inline void pos_edge();
inline void update_cycles(uint64_t inc);
void execute(uint64_t nr_cycle);
tl_agent::Port<tl_agent::ReqField, tl_agent::RespField, tl_agent::EchoField, BEATSIZE>* naive_gen_port();
tl_agent::Port<tl_agent::ReqField, tl_agent::RespField, tl_agent::EchoField, BEATSIZE>* naive_gen_port2();
};
inline void Emu::reset(uint64_t n) {
for (uint64_t i = 0; i < n; i++) {
dut_ptr->reset = 1;
dut_ptr->clock = 0;
dut_ptr->eval();
dut_ptr->clock = 1;
dut_ptr->eval();
}
dut_ptr->reset = 0;
}
inline void Emu::neg_edge() {
dut_ptr->clock = 0;
dut_ptr->eval();
}
inline void Emu::pos_edge() {
dut_ptr->clock = 1;
dut_ptr->eval();
}
inline void Emu::update_cycles(uint64_t inc) {
Cycles += inc;
if (Cycles % 1000000 == 0) { printf("*\n"); }
}
inline char* Emu::cycle_wavefile(uint64_t cycles, time_t t) {
static char buf[1024];
char buf_time[64];
strftime(buf_time, sizeof(buf_time), "%F@%T", localtime(&t));
char *pwd = getcwd(NULL, 0);
assert(pwd != NULL);
int len = snprintf(buf, 1024, "%s/%s_%lu", pwd, buf_time, cycles);
strcpy(buf + len, ".vcd");
printf("dump wave to %s...\n", buf);
return buf;
}
#endif //TLC_TEST_EMU_H