2024-01-10 07:20:50 +00:00
|
|
|
#include <VSegHandler.h>
|
2024-01-01 05:29:52 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdlib>
|
2024-01-10 07:20:50 +00:00
|
|
|
#include <nvboard.h>
|
2024-01-01 05:29:52 +00:00
|
|
|
#include <verilated.h>
|
2024-01-05 16:40:41 +00:00
|
|
|
#include <verilated_vcd_c.h>
|
2024-01-01 05:29:52 +00:00
|
|
|
|
2024-01-10 07:07:02 +00:00
|
|
|
#ifndef VERILATOR_TOPMODULE
|
|
|
|
#define VERILATOR_TOPMODULE VSegHandler
|
|
|
|
#endif
|
|
|
|
|
2024-01-10 07:20:50 +00:00
|
|
|
const int MAX_SIM_TIME = 100;
|
|
|
|
int keycode = 0;
|
|
|
|
|
|
|
|
template <class F> void cycle(VERILATOR_TOPMODULE *top, F &&f) {
|
|
|
|
top->clock = 0;
|
|
|
|
top->eval();
|
|
|
|
top->clock = 1;
|
|
|
|
top->eval();
|
2024-01-10 07:29:05 +00:00
|
|
|
f();
|
2024-01-10 07:20:50 +00:00
|
|
|
}
|
2024-01-01 05:29:52 +00:00
|
|
|
|
2024-01-10 07:20:50 +00:00
|
|
|
void nvboard_bind_all_pins(VERILATOR_TOPMODULE *top);
|
2024-01-10 07:07:02 +00:00
|
|
|
|
2024-01-10 07:20:50 +00:00
|
|
|
static void single_cycle(VERILATOR_TOPMODULE *top) {
|
|
|
|
top->clock = 0;
|
|
|
|
top->eval();
|
|
|
|
top->clock = 1;
|
|
|
|
top->eval();
|
2024-01-10 07:07:02 +00:00
|
|
|
}
|
|
|
|
|
2024-01-10 07:20:50 +00:00
|
|
|
static void reset(VERILATOR_TOPMODULE *top, int n) {
|
2024-01-10 07:07:02 +00:00
|
|
|
top->reset = 1;
|
2024-01-10 07:20:50 +00:00
|
|
|
while (n-- > 0)
|
|
|
|
single_cycle(top);
|
2024-01-10 07:07:02 +00:00
|
|
|
top->reset = 0;
|
|
|
|
}
|
2024-01-01 05:29:52 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv, char **env) {
|
2024-01-10 07:20:50 +00:00
|
|
|
VERILATOR_TOPMODULE *top = new VERILATOR_TOPMODULE;
|
|
|
|
|
|
|
|
nvboard_bind_all_pins(top);
|
|
|
|
nvboard_init();
|
|
|
|
reset(top, 10);
|
|
|
|
while (true) {
|
|
|
|
nvboard_update();
|
|
|
|
cycle(top, [&] {
|
|
|
|
if (keycode != top->io_keycode_bits) {
|
2024-01-10 07:25:14 +00:00
|
|
|
printf("keycode: 0x%x display: %x %x\n", top->io_keycode_bits, top->io_segs_1, top->io_segs_0);
|
2024-01-10 07:20:50 +00:00
|
|
|
keycode = top->io_keycode_bits;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
delete top;
|
2024-01-01 05:29:52 +00:00
|
|
|
}
|