From 679f311c52a0ecaee3c7081c1b58bd59d8dc831d Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 28 Jun 2019 20:59:16 +0200 Subject: [PATCH] Fixed clint interrupt method invokation --- .cproject | 2 +- platform/incl/sysc/SiFive/clint.h | 16 ++++++++--- platform/src/sysc/clint.cpp | 48 ++++++++++++++++++++++++------- platform/src/sysc/fe310.cpp | 2 +- riscv | 2 +- scc | 2 +- 6 files changed, 54 insertions(+), 18 deletions(-) diff --git a/.cproject b/.cproject index 69c22d9..11e351d 100644 --- a/.cproject +++ b/.cproject @@ -13,7 +13,7 @@ - + diff --git a/platform/incl/sysc/SiFive/clint.h b/platform/incl/sysc/SiFive/clint.h index 5d2f12f..82ab61c 100644 --- a/platform/incl/sysc/SiFive/clint.h +++ b/platform/incl/sysc/SiFive/clint.h @@ -34,6 +34,7 @@ #define _CLINT_H_ #include "scc/tlm_target.h" +#include namespace iss { namespace arch { @@ -48,25 +49,32 @@ namespace SiFive { class core_complex; } -class clint : public sc_core::sc_module, public scc::tlm_target<> { +class clint : public sc_core::sc_module, public scc::tlm_target<>, public tlm::tlm_peek_if { public: - SC_HAS_PROCESS(clint);// NOLINT sc_core::sc_in tlclk_i; sc_core::sc_in lfclk_i; sc_core::sc_in rst_i; sc_core::sc_out mtime_int_o; sc_core::sc_out msip_int_o; + sc_core::sc_export> mtime_i{"mtime_i"}; + clint(sc_core::sc_module_name nm); virtual ~clint() override; // NOLINT // need to keep it in source file because of fwd declaration of clint_regs protected: void clock_cb(); void reset_cb(); - void update_mtime(); + void mtime_evt_cb(); + void update_mtime(bool force = false); + uint64_t peek( tlm::tlm_tag *t = 0 ) const override; + bool nb_peek( uint64_t &t ) const override; + bool nb_can_peek( tlm::tlm_tag *t = 0 ) const override; + const sc_core::sc_event &ok_to_peek( tlm::tlm_tag *t = 0 ) const override; + sc_core::sc_time clk, last_updt; unsigned cnt_fraction; std::unique_ptr regs; - sc_core::sc_event mtime_evt; + sc_core::sc_event mtime_evt, dummy_evt; }; } /* namespace sysc */ diff --git a/platform/src/sysc/clint.cpp b/platform/src/sysc/clint.cpp index c0753aa..51f34c3 100644 --- a/platform/src/sysc/clint.cpp +++ b/platform/src/sysc/clint.cpp @@ -39,7 +39,7 @@ namespace sysc { using namespace sc_core; -const int lfclk_mutiplier = 1 << 12; +const int lfclk_mutiplier = 1 ;//<< 12; clint::clint(sc_core::sc_module_name nm) : sc_core::sc_module(nm) @@ -51,16 +51,21 @@ clint::clint(sc_core::sc_module_name nm) , NAMED(msip_int_o) , NAMEDD(regs, clint_regs) , cnt_fraction(0) { + SC_HAS_PROCESS(clint);// NOLINT + mtime_i.bind(*this); regs->registerResources(*this); SC_METHOD(clock_cb); sensitive << tlclk_i << lfclk_i; SC_METHOD(reset_cb); sensitive << rst_i; dont_initialize(); + SC_METHOD(mtime_evt_cb); + sensitive<mtimecmp.set_write_cb([this](scc::sc_register ®, uint64_t data, sc_core::sc_time d) -> bool { if (!regs->in_reset()) { reg.put(data); - this->update_mtime(); + this->update_mtime(true); } return true; }); @@ -76,9 +81,6 @@ clint::clint(sc_core::sc_module_name nm) msip_int_o.write(regs->r_msip.msip); return true; }); - SC_METHOD(update_mtime); - sensitive << mtime_evt; - dont_initialize(); } void clint::clock_cb() { @@ -99,26 +101,52 @@ void clint::reset_cb() { regs->reset_stop(); } -void clint::update_mtime() { +void clint::mtime_evt_cb() { + update_mtime(); +} + +void clint::update_mtime(bool force) { if (clk > SC_ZERO_TIME) { uint64_t elapsed_clks = (sc_time_stamp() - last_updt) / clk; // get the number of clock periods since last invocation last_updt += elapsed_clks * clk; // increment the last_updt timestamp by the number of clocks - if (elapsed_clks) { // update mtime reg if we have more than 0 elapsed clk periods + if (force || elapsed_clks) { // update mtime reg if we have more than 0 elapsed clk periods regs->r_mtime += elapsed_clks; - mtime_evt.cancel(); + //mtime_evt.cancel(); if (regs->r_mtimecmp > 0) if (regs->r_mtimecmp > regs->r_mtime && clk > sc_core::SC_ZERO_TIME) { sc_core::sc_time next_trigger = - (clk * lfclk_mutiplier) * (regs->r_mtimecmp - regs->mtime) - cnt_fraction * clk; + (clk * lfclk_mutiplier) * (regs->r_mtimecmp - regs->r_mtime) - cnt_fraction * clk; SCTRACE() << "Timer fires at " << sc_time_stamp() + next_trigger; mtime_evt.notify(next_trigger); mtime_int_o.write(false); - } else + } else { + SCTRACE() << "Timer fired at " << sc_time_stamp(); mtime_int_o.write(true); + } } } else last_updt = sc_time_stamp(); } +uint64_t clint::peek(tlm::tlm_tag* t) const { + const_cast(this)->update_mtime(); + return regs->r_mtime; +} + +bool clint::nb_peek(uint64_t& t) const { + const_cast(this)->update_mtime(); + t= regs->r_mtime; + return true; +} + +bool clint::nb_can_peek(tlm::tlm_tag* t) const { + return true; +} + +const sc_core::sc_event& clint::ok_to_peek(tlm::tlm_tag* t) const { + return dummy_evt; +} + } /* namespace sysc */ + diff --git a/platform/src/sysc/fe310.cpp b/platform/src/sysc/fe310.cpp index 1cab7e2..2ae66d7 100644 --- a/platform/src/sysc/fe310.cpp +++ b/platform/src/sysc/fe310.cpp @@ -135,7 +135,7 @@ fe310::fe310(sc_core::sc_module_name nm) i_core_complex->timer_irq_i(s_mtime_int); i_core_complex->global_irq_i(s_core_int); i_core_complex->local_irq_i(s_local_int); - + i_core_complex->mtime_o(i_clint->mtime_i); pins_i(i_gpio0->pins_i); i_gpio0->pins_o(pins_o); diff --git a/riscv b/riscv index d93c2fe..7f06bba 160000 --- a/riscv +++ b/riscv @@ -1 +1 @@ -Subproject commit d93c2feec4c80ece0773fb2366821d01e11db4b6 +Subproject commit 7f06bba239c2f15a08c65f701e31d60d229a66cb diff --git a/scc b/scc index 4be77af..19a0c10 160000 --- a/scc +++ b/scc @@ -1 +1 @@ -Subproject commit 4be77aff604dc78f3c0856b6d17843b276b80b59 +Subproject commit 19a0c10fc2db51527544674227ca44b8d46f8781