Browse Source

Added configurability of WS output

pull/1/head
Eyck Jentzsch 3 years ago
parent
commit
cb496a9543
12 changed files with 68 additions and 36 deletions
  1. +2
    -2
      .cproject
  2. +5
    -7
      .gitignore
  3. +1
    -1
      dbt-core
  4. +3
    -0
      riscv.sc/incl/sysc/SiFive/gpio.h
  5. +3
    -0
      riscv.sc/incl/sysc/SiFive/uart.h
  6. +2
    -1
      riscv.sc/incl/sysc/sc_comm_singleton.h
  7. +10
    -6
      riscv.sc/src/sc_main.cpp
  8. +11
    -7
      riscv.sc/src/sysc/gpio.cpp
  9. +4
    -2
      riscv.sc/src/sysc/sc_comm_singleton.cpp
  10. +16
    -9
      riscv.sc/src/sysc/uart.cpp
  11. +1
    -1
      sc-components
  12. +10
    -0
      simple-system.json

+ 2
- 2
.cproject View File

@ -72,7 +72,7 @@
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.base.1444789864" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
<option id="gnu.both.asm.option.include.paths.431492963" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath"/>
<option id="gnu.both.asm.option.include.paths.431492963" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths"/>
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.463921398" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
@ -155,7 +155,7 @@
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.base.1511882711" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
<option id="gnu.both.asm.option.include.paths.905852970" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath"/>
<option id="gnu.both.asm.option.include.paths.905852970" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths"/>
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1565549569" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>

+ 5
- 7
.gitignore View File

@ -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

+ 1
- 1
dbt-core

@ -1 +1 @@
Subproject commit 3b05de8c14f5d7b5d1ff55f5f244f797992be83d
Subproject commit 53d78d993a8d3310a8b73fec0b601457b3c0ef75

+ 3
- 0
riscv.sc/incl/sysc/SiFive/gpio.h View File

@ -18,6 +18,7 @@
#define _GPIO_H_
#include "scc/tlm_target.h"
#include "scc/ext_attribute.h"
#include <sysc/communication/sc_signal_rv_ports.h>
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<bool> 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<gpio_regs> regs;
std::shared_ptr<sysc::WsHandler> handler;

+ 3
- 0
riscv.sc/incl/sysc/SiFive/uart.h View File

@ -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<bool> 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<uart_regs> regs;
std::vector<uint8_t> queue;

+ 2
- 1
riscv.sc/incl/sysc/sc_comm_singleton.h View File

@ -75,7 +75,8 @@ private:
std::unique_ptr<seasocks::Server> m_serv;
std::thread t;
void thread_func();
bool client_started;
bool needs_client, client_started;
std::vector<std::string> endpoints;
};
} /* namespace sysc */

+ 10
- 6
riscv.sc/src/sc_main.cpp View File

@ -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<std::string>());
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<unsigned short>());
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<std::string>());
if (vm.count("quantum"))
tlm::tlm_global_quantum::instance().set(sc_core::sc_time(vm["quantum"].as<unsigned>(), sc_core::SC_NS));
if (vm.count("reset")) {
auto str = vm["reset"].as<std::string>();
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<unsigned short>());
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<unsigned>(), sc_core::SC_NS));
}
///////////////////////////////////////////////////////////////////////////
// run simulation
///////////////////////////////////////////////////////////////////////////

+ 11
- 7
riscv.sc/src/sysc/gpio.cpp View File

@ -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<WsHandler>();
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<WsHandler>();
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 << "] "<<msg;
os << "{\"time\":\"" << now << "\",\"data\":\""<<msg<<"\"}";
this->handler->send(os.str());
});

+ 4
- 2
riscv.sc/src/sysc/sc_comm_singleton.cpp View File

@ -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<PrintfLogger>(Logger::Level::WARNING)))
, needs_client(false)
, client_started(false){
m_serv->addPageHandler(std::make_shared<DefaultPageHandler>(*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<WebSocket::Handler> handler,
bool allowCrossOriginRequests) {
get_server().addWebSocketHandler(endpoint, handler, allowCrossOriginRequests);
endpoints.push_back(endpoint);
needs_client=true;
}
void sc_comm_singleton::execute(std::function<void()> 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) {

+ 16
- 9
riscv.sc/src/sysc/uart.cpp View File

@ -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<WsHandler>();
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<WsHandler>();
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\":\""<<msg<<"\"}";
this->handler->send(os.str());
});
if(handler)
sc_comm_singleton::inst().execute([this, msg, now](){
std::stringstream os;
os << "{\"time\":\"" << now << "\",\"message\":\""<<msg<<"\"}";
this->handler->send(os.str());
});
queue.clear();
}
}

+ 1
- 1
sc-components

@ -1 +1 @@
Subproject commit 174e0f55f11fa932c88b99e352e5e9b58cb9ce71
Subproject commit 251a735cea414b4a79da99ca438da4335bb0fbc5

+ 10
- 0
simple-system.json View File

@ -0,0 +1,10 @@
{
"i_simple_system":{
"i_uart0":{
"write_to_ws": true
},
"i_gpio0":{
"write_to_ws": true
}
}
}

Loading…
Cancel
Save