From e13fd327e5db2b2924e302505ef80f3020241fdd Mon Sep 17 00:00:00 2001 From: tracer-ysyx Date: Wed, 10 Jan 2024 17:24:32 +0800 Subject: [PATCH] =?UTF-8?q?>=20configure(npc)=20=20ysyx=5F22040000=20?= =?UTF-8?q?=E6=9D=8E=E5=BF=83=E6=9D=A8=20=20Linux=20calcite=206.1.69=20#1-?= =?UTF-8?q?NixOS=20SMP=20PREEMPT=5FDYNAMIC=20Wed=20Dec=2020=2016:00:29=20U?= =?UTF-8?q?TC=202023=20x86=5F64=20GNU/Linux=20=20=2017:24:32=20=20up=202?= =?UTF-8?q?=20days=2016:25,=20=202=20users,=20=20load=20average:=200.46,?= =?UTF-8?q?=200.75,=200.74?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- npc/CMakeLists.txt | 2 +- npc/csrc_nvboard/Keyboard/main.cpp | 59 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 npc/csrc_nvboard/Keyboard/main.cpp 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