From cb496a9543d6b9f8ee062827403b5a0c5e013337 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 24 Nov 2017 07:02:28 +0100 Subject: [PATCH] Added configurability of WS output --- .cproject | 4 ++-- .gitignore | 12 +++++------- dbt-core | 2 +- riscv.sc/incl/sysc/SiFive/gpio.h | 3 +++ riscv.sc/incl/sysc/SiFive/uart.h | 3 +++ riscv.sc/incl/sysc/sc_comm_singleton.h | 3 ++- riscv.sc/src/sc_main.cpp | 16 ++++++++++------ riscv.sc/src/sysc/gpio.cpp | 18 +++++++++++------- riscv.sc/src/sysc/sc_comm_singleton.cpp | 6 ++++-- riscv.sc/src/sysc/uart.cpp | 25 ++++++++++++++++--------- sc-components | 2 +- simple-system.json | 10 ++++++++++ 12 files changed, 68 insertions(+), 36 deletions(-) create mode 100644 simple-system.json diff --git a/.cproject b/.cproject index 67a12ff..04b9909 100644 --- a/.cproject +++ b/.cproject @@ -72,7 +72,7 @@ - @@ -155,7 +155,7 @@ - diff --git a/.gitignore b/.gitignore index a3c39fc..4d498bb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,28 +6,26 @@ /avr-gdb.cmd /main.cpp /Debug/ -/Reelease/ /core /*.launch /*.csv /Release/ /*.vcd /*.ods -/build/ +/build*/ /*.logs language.settings.xml /*.gtkw /Debug wo LLVM/ -/atmega.txdb -/atmega.txlgz -/atmega.txlog +/*.txdb +/*.txlgz +/*.txlog /.??*bdb.d.0 /.??*bdb.i.0 /.??*bdb.t /tmp/ -/test1.elf +/*.elf /logs/ /*.log /.gdbinit /*.out -/*.txlog diff --git a/dbt-core b/dbt-core index 3b05de8..53d78d9 160000 --- a/dbt-core +++ b/dbt-core @@ -1 +1 @@ -Subproject commit 3b05de8c14f5d7b5d1ff55f5f244f797992be83d +Subproject commit 53d78d993a8d3310a8b73fec0b601457b3c0ef75 diff --git a/riscv.sc/incl/sysc/SiFive/gpio.h b/riscv.sc/incl/sysc/SiFive/gpio.h index 9bc0b7b..57c98b8 100644 --- a/riscv.sc/incl/sysc/SiFive/gpio.h +++ b/riscv.sc/incl/sysc/SiFive/gpio.h @@ -18,6 +18,7 @@ #define _GPIO_H_ #include "scc/tlm_target.h" +#include "scc/ext_attribute.h" #include namespace sysc { @@ -35,11 +36,13 @@ public: gpio(sc_core::sc_module_name nm); virtual ~gpio() override; // need to keep it in source file because of fwd declaration of gpio_regs + scc::ext_attribute write_to_ws; protected: void clock_cb(); void reset_cb(); void update_pins(); void pins_cb(); + void before_end_of_elaboration(); sc_core::sc_time clk; std::unique_ptr regs; std::shared_ptr handler; diff --git a/riscv.sc/incl/sysc/SiFive/uart.h b/riscv.sc/incl/sysc/SiFive/uart.h index 095f9d4..80a255f 100644 --- a/riscv.sc/incl/sysc/SiFive/uart.h +++ b/riscv.sc/incl/sysc/SiFive/uart.h @@ -17,6 +17,7 @@ #ifndef _UART_H_ #define _UART_H_ +#include "scc/ext_attribute.h" #include "scc/tlm_target.h" namespace sysc { @@ -32,10 +33,12 @@ public: uart(sc_core::sc_module_name nm); virtual ~uart() override; + scc::ext_attribute write_to_ws; protected: void clock_cb(); void reset_cb(); void transmit_data(); + void before_end_of_elaboration(); sc_core::sc_time clk; std::unique_ptr regs; std::vector queue; diff --git a/riscv.sc/incl/sysc/sc_comm_singleton.h b/riscv.sc/incl/sysc/sc_comm_singleton.h index d6c4aa9..6eba890 100644 --- a/riscv.sc/incl/sysc/sc_comm_singleton.h +++ b/riscv.sc/incl/sysc/sc_comm_singleton.h @@ -75,7 +75,8 @@ private: std::unique_ptr m_serv; std::thread t; void thread_func(); - bool client_started; + bool needs_client, client_started; + std::vector endpoints; }; } /* namespace sysc */ diff --git a/riscv.sc/src/sc_main.cpp b/riscv.sc/src/sc_main.cpp index 5e5e076..c99aeee 100644 --- a/riscv.sc/src/sc_main.cpp +++ b/riscv.sc/src/sc_main.cpp @@ -112,7 +112,16 @@ int sc_main(int argc, char *argv[]) { // sr_report_handler::add_sc_object_to_filter(&i_simple_system.i_master, // sc_core::SC_WARNING, sc_core::SC_MEDIUM); // cfg.dump_hierarchy(); - if (vm.count("elf")) cfg.set_value("i_simple_system.i_core_complex.elf_file", vm["elf"].as()); + cfg.configure(); + // overwrite with command line settings + if (vm.count("gdb-port")) + cfg.set_value("i_simple_system.i_core_complex.gdb_server_port", vm["gdb-port"].as()); + if (vm.count("dump-ir")) + cfg.set_value("i_simple_system.i_core_complex.dump_ir", vm.count("dump-ir") != 0); + if (vm.count("elf")) + cfg.set_value("i_simple_system.i_core_complex.elf_file", vm["elf"].as()); + if (vm.count("quantum")) + tlm::tlm_global_quantum::instance().set(sc_core::sc_time(vm["quantum"].as(), sc_core::SC_NS)); if (vm.count("reset")) { auto str = vm["reset"].as(); uint64_t start_address = str.find("0x") == 0 ? std::stoull(str.substr(2), 0, 16) : std::stoull(str, 0, 10); @@ -128,11 +137,6 @@ int sc_main(int argc, char *argv[]) { LOGGER(disass)::print_severity() = false; } } - cfg.set_value("i_simple_system.i_core_complex.gdb_server_port", vm["gdb-port"].as()); - cfg.set_value("i_simple_system.i_core_complex.dump_ir", vm.count("dump-ir") != 0); - if (vm.count("quantum")) { - tlm::tlm_global_quantum::instance().set(sc_core::sc_time(vm["quantum"].as(), sc_core::SC_NS)); - } /////////////////////////////////////////////////////////////////////////// // run simulation /////////////////////////////////////////////////////////////////////////// diff --git a/riscv.sc/src/sysc/gpio.cpp b/riscv.sc/src/sysc/gpio.cpp index 2b761e0..92d5df6 100644 --- a/riscv.sc/src/sysc/gpio.cpp +++ b/riscv.sc/src/sysc/gpio.cpp @@ -29,7 +29,8 @@ gpio::gpio(sc_core::sc_module_name nm) , NAMED(clk_i) , NAMED(rst_i) , NAMED(pins_io) -, NAMEDD(gpio_regs, regs) { +, NAMEDD(gpio_regs, regs) +, NAMED(write_to_ws, true, this){ regs->registerResources(*this); SC_METHOD(clock_cb); sensitive << clk_i; @@ -56,14 +57,18 @@ gpio::gpio(sc_core::sc_module_name nm) } return true; }); - LOG(TRACE)<<"Adding WS handler for "<<(std::string{"/ws/"}+name()); - handler=std::make_shared(); - sc_comm_singleton::inst().registerWebSocketHandler((std::string{"/ws/"}+name()).c_str(), handler); - } gpio::~gpio() {} +void gpio::before_end_of_elaboration() { + if(write_to_ws.value) { + LOG(TRACE)<<"Adding WS handler for "<<(std::string{"/ws/"}+name()); + handler=std::make_shared(); + sc_comm_singleton::inst().registerWebSocketHandler((std::string{"/ws/"}+name()).c_str(), handler); + } +} + void gpio::reset_cb() { if (rst_i.read()) regs->reset_start(); @@ -79,9 +84,8 @@ void gpio::pins_cb(){ auto inval=pins_io.read(); std::string msg(inval.to_string()); sc_core::sc_time now = sc_core::sc_time_stamp(); - sc_comm_singleton::inst().execute([this, msg, now](){ + if(handler) sc_comm_singleton::inst().execute([this, msg, now](){ std::stringstream os; - //os << "[" << std::setw(20) << now << "] "<handler->send(os.str()); }); diff --git a/riscv.sc/src/sysc/sc_comm_singleton.cpp b/riscv.sc/src/sysc/sc_comm_singleton.cpp index 73a474c..0fb93e3 100644 --- a/riscv.sc/src/sysc/sc_comm_singleton.cpp +++ b/riscv.sc/src/sysc/sc_comm_singleton.cpp @@ -35,6 +35,7 @@ inline void die(){perror(nullptr);exit(errno);} sc_comm_singleton::sc_comm_singleton(sc_core::sc_module_name nm) : sc_core::sc_module(nm) , m_serv(new Server(std::make_shared(Logger::Level::WARNING))) +, needs_client(false) , client_started(false){ m_serv->addPageHandler(std::make_shared(*this)); } @@ -47,7 +48,7 @@ sc_comm_singleton::~sc_comm_singleton() { void sc_comm_singleton::start_of_simulation() { //Launch a thread t=std::thread(&sc_comm_singleton::thread_func, this); - start_client(); + if(needs_client) start_client(); } void sc_comm_singleton::end_of_simulation() { @@ -112,6 +113,8 @@ void sc_comm_singleton::registerWebSocketHandler(const char* endpoint, std::shared_ptr handler, bool allowCrossOriginRequests) { get_server().addWebSocketHandler(endpoint, handler, allowCrossOriginRequests); + endpoints.push_back(endpoint); + needs_client=true; } void sc_comm_singleton::execute(std::function f) { @@ -136,7 +139,6 @@ std::shared_ptr sc_comm_singleton::DefaultPageHandler::handle(const Re void WsHandler::onConnect(WebSocket* connection) { _connections.insert(connection); - //connection->send("Connection established");; } void WsHandler::onData(WebSocket* connection, const char* data) { diff --git a/riscv.sc/src/sysc/uart.cpp b/riscv.sc/src/sysc/uart.cpp index 2176a32..dc15dbe 100644 --- a/riscv.sc/src/sysc/uart.cpp +++ b/riscv.sc/src/sysc/uart.cpp @@ -36,7 +36,8 @@ uart::uart(sc_core::sc_module_name nm) , tlm_target<>(clk) , NAMED(clk_i) , NAMED(rst_i) -, NAMEDD(uart_regs, regs) { +, NAMEDD(uart_regs, regs) +, NAMED(write_to_ws, false, this) { regs->registerResources(*this); SC_METHOD(clock_cb); sensitive << clk_i; @@ -50,13 +51,18 @@ uart::uart(sc_core::sc_module_name nm) } return true; }); - LOG(TRACE)<<"Adding WS handler for "<<(std::string{"/ws/"}+name()); - handler=std::make_shared(); - sc_comm_singleton::inst().registerWebSocketHandler((std::string{"/ws/"}+name()).c_str(), handler); } uart::~uart() {} +void uart::before_end_of_elaboration() { + if(write_to_ws.value) { + LOG(TRACE)<<"Adding WS handler for "<<(std::string{"/ws/"}+name()); + handler=std::make_shared(); + sc_comm_singleton::inst().registerWebSocketHandler((std::string{"/ws/"}+name()).c_str(), handler); + } +} + void uart::clock_cb() { this->clk = clk_i.read(); } @@ -74,11 +80,12 @@ void uart::transmit_data() { std::string msg(queue.begin(), queue.end()-1); LOG(INFO) << this->name() << " transmit: '" << msg << "'"; sc_core::sc_time now = sc_core::sc_time_stamp(); - sc_comm_singleton::inst().execute([this, msg, now](){ - std::stringstream os; - os << "{\"time\":\"" << now << "\",\"message\":\""<handler->send(os.str()); - }); + if(handler) + sc_comm_singleton::inst().execute([this, msg, now](){ + std::stringstream os; + os << "{\"time\":\"" << now << "\",\"message\":\""<handler->send(os.str()); + }); queue.clear(); } } diff --git a/sc-components b/sc-components index 174e0f5..251a735 160000 --- a/sc-components +++ b/sc-components @@ -1 +1 @@ -Subproject commit 174e0f55f11fa932c88b99e352e5e9b58cb9ce71 +Subproject commit 251a735cea414b4a79da99ca438da4335bb0fbc5 diff --git a/simple-system.json b/simple-system.json new file mode 100644 index 0000000..0eebd11 --- /dev/null +++ b/simple-system.json @@ -0,0 +1,10 @@ +{ + "i_simple_system":{ + "i_uart0":{ + "write_to_ws": true + }, + "i_gpio0":{ + "write_to_ws": true + } + } +}