diff --git a/npc/CMakeLists.txt b/npc/CMakeLists.txt index 880181b..9e27367 100644 --- a/npc/CMakeLists.txt +++ b/npc/CMakeLists.txt @@ -17,7 +17,7 @@ find_package(verilator REQUIRED) find_library(NVBOARD_LIBRARY NAMES nvboard) find_path(NVBOARD_INCLUDE_DIR NAMES nvboard.h) -set(TOPMODULE "SegHandler") +set(TOPMODULE "Keyboard") set(SCALA_CORE "${CMAKE_CURRENT_SOURCE_DIR}/core") set(CHISEL_MODULE_CLASS "${CMAKE_PROJECT_NAME}.${TOPMODULE}") file(GLOB_RECURSE SCALA_CORE_SOURCES "${SCALA_CORE}/src/main/scala/*.scala") diff --git a/npc/csrc_nvboard/Keyboard/main.cpp b/npc/csrc_nvboard/Keyboard/main.cpp new file mode 100644 index 0000000..d2f2a28 --- /dev/null +++ b/npc/csrc_nvboard/Keyboard/main.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include + +#ifndef VERILATOR_TOPMODULE +#define VERILATOR_TOPMODULE VKeyboard +#endif + +#define CLASS_SYSTEM_HEADER_NAME(name) CLASS_SYSTEM_HEADER_NAME_IMPL(name) +#define CLASS_SYSTEM_HEADER_NAME_IMPL(name) + +#include CLASS_SYSTEM_HEADER_NAME(VERILATOR_TOPMODULE) + +const int MAX_SIM_TIME = 100; +int keycode = 0; + +template 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){ + keycode = top->io_keycode_bits; + printf("%d\n", keycode); + } + }); + } + delete top; +} \ No newline at end of file