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 10:18:26 +00:00
|
|
|
#define CLASS_SYSTEM_HEADER_NAME(name) CLASS_SYSTEM_HEADER_NAME_IMPL(name)
|
|
|
|
#define CLASS_SYSTEM_HEADER_NAME_IMPL(name) <name.h>
|
|
|
|
#include CLASS_SYSTEM_HEADER_NAME(VERILATOR_TOPMODULE)
|
|
|
|
#undef CLASS_SYSTEM_HEADER_NAME
|
|
|
|
#undef CLASS_SYSTEM_HEADER_NAME_IMPL
|
|
|
|
|
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, [&] {
|
2024-01-10 09:11:08 +00:00
|
|
|
if (keycode != top->io_keycode_bits){
|
|
|
|
keycode = top->io_keycode_bits;
|
2024-01-10 09:10:11 +00:00
|
|
|
printf("%d\n", keycode);
|
2024-01-10 07:20:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
delete top;
|
2024-01-01 05:29:52 +00:00
|
|
|
}
|