-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathsim_main.cpp
More file actions
52 lines (45 loc) · 1.09 KB
/
sim_main.cpp
File metadata and controls
52 lines (45 loc) · 1.09 KB
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
#include <stdio.h>
#include "Vj1b.h"
#include "Vj1b___024root.h"
#include "verilated_vcd_c.h"
int main(int argc, char **argv)
{
Verilated::commandArgs(argc, argv);
Vj1b* top = new Vj1b;
if (argc != 2) {
fprintf(stderr, "usage: sim <hex-file>\n");
exit(1);
}
FILE *hex = fopen(argv[1], "r");
int i;
for (i = 0; i < 8192; i++) {
unsigned int v;
if (fscanf(hex, "%x\n", &v) != 1) {
fprintf(stderr, "invalid hex value at line %d\n", i + 1);
exit(1);
}
top->rootp->v__DOT__ram[i] = v;
}
top->resetq = 0;
top->eval();
top->resetq = 1;
top->uart0_valid = 1; // pretend to always have a character waiting
for (i = 0; ; i++) {
top->clk = 1;
top->eval();
top->clk = 0;
top->eval();
if (top->uart0_wr) {
putchar(top->uart_w);
}
if (top->uart0_rd) {
int c = getchar();
if (c == EOF)
break;
top->uart0_data = (c == '\n') ? '\r' : c;
}
}
printf("Simulation ended after %d cycles\n", i);
delete top;
exit(0);
}