ysyx-workbench/npc/csrc_nvboard/main.cpp
tracer-ysyx d4f0936612
> build_npc_VSegHandler_nvboard
ysyx_22040000 李心杨
 Linux calcite 6.1.69 #1-NixOS SMP PREEMPT_DYNAMIC Wed Dec 20 16:00:29 UTC 2023 x86_64 GNU/Linux
  15:29:05  up 2 days 14:29,  2 users,  load average: 1.69, 1.94, 1.64
2024-01-10 15:29:05 +08:00

55 lines
No EOL
1.1 KiB
C++

#include <VSegHandler.h>
#include <cassert>
#include <cstdlib>
#include <nvboard.h>
#include <verilated.h>
#include <verilated_vcd_c.h>
#ifndef VERILATOR_TOPMODULE
#define VERILATOR_TOPMODULE VSegHandler
#endif
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();
f();
}
void nvboard_bind_all_pins(VERILATOR_TOPMODULE *top);
static void single_cycle(VERILATOR_TOPMODULE *top) {
top->clock = 0;
top->eval();
top->clock = 1;
top->eval();
}
static void reset(VERILATOR_TOPMODULE *top, int n) {
top->reset = 1;
while (n-- > 0)
single_cycle(top);
top->reset = 0;
}
int main(int argc, char **argv, char **env) {
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) {
printf("keycode: 0x%x display: %x %x\n", top->io_keycode_bits, top->io_segs_1, top->io_segs_0);
keycode = top->io_keycode_bits;
}
});
}
delete top;
}