Fixed clint interrupt method invokation

This commit is contained in:
Eyck Jentzsch 2019-06-28 20:59:16 +02:00
parent 9ba1482fc2
commit 679f311c52
6 changed files with 54 additions and 18 deletions

View File

@ -13,7 +13,7 @@
</extensions> </extensions>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1751741082" name="Debug" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=" parent="cdt.managedbuild.config.gnu.exe.debug"> <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1751741082" name="Debug" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=" parent="cdt.managedbuild.config.gnu.exe.debug">
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1751741082." name="/" resourcePath=""> <folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1751741082." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1289745146" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug"> <toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1289745146" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
<targetPlatform binaryParser="org.eclipse.cdt.core.GNU_ELF;org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.exe.debug.1460698591" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/> <targetPlatform binaryParser="org.eclipse.cdt.core.GNU_ELF;org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.exe.debug.1460698591" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>

View File

@ -34,6 +34,7 @@
#define _CLINT_H_ #define _CLINT_H_
#include "scc/tlm_target.h" #include "scc/tlm_target.h"
#include <tlm_core/tlm_1/tlm_req_rsp/tlm_1_interfaces/tlm_core_ifs.h>
namespace iss { namespace iss {
namespace arch { namespace arch {
@ -48,25 +49,32 @@ namespace SiFive {
class core_complex; 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<uint64_t> {
public: public:
SC_HAS_PROCESS(clint);// NOLINT
sc_core::sc_in<sc_core::sc_time> tlclk_i; sc_core::sc_in<sc_core::sc_time> tlclk_i;
sc_core::sc_in<sc_core::sc_time> lfclk_i; sc_core::sc_in<sc_core::sc_time> lfclk_i;
sc_core::sc_in<bool> rst_i; sc_core::sc_in<bool> rst_i;
sc_core::sc_out<bool> mtime_int_o; sc_core::sc_out<bool> mtime_int_o;
sc_core::sc_out<bool> msip_int_o; sc_core::sc_out<bool> msip_int_o;
sc_core::sc_export<tlm::tlm_peek_if<uint64_t>> mtime_i{"mtime_i"};
clint(sc_core::sc_module_name nm); 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 virtual ~clint() override; // NOLINT // need to keep it in source file because of fwd declaration of clint_regs
protected: protected:
void clock_cb(); void clock_cb();
void reset_cb(); void reset_cb();
void update_mtime(); void mtime_evt_cb();
void update_mtime(bool force = false);
uint64_t peek( tlm::tlm_tag<uint64_t> *t = 0 ) const override;
bool nb_peek( uint64_t &t ) const override;
bool nb_can_peek( tlm::tlm_tag<uint64_t> *t = 0 ) const override;
const sc_core::sc_event &ok_to_peek( tlm::tlm_tag<uint64_t> *t = 0 ) const override;
sc_core::sc_time clk, last_updt; sc_core::sc_time clk, last_updt;
unsigned cnt_fraction; unsigned cnt_fraction;
std::unique_ptr<clint_regs> regs; std::unique_ptr<clint_regs> regs;
sc_core::sc_event mtime_evt; sc_core::sc_event mtime_evt, dummy_evt;
}; };
} /* namespace sysc */ } /* namespace sysc */

View File

@ -39,7 +39,7 @@
namespace sysc { namespace sysc {
using namespace sc_core; using namespace sc_core;
const int lfclk_mutiplier = 1 << 12; const int lfclk_mutiplier = 1 ;//<< 12;
clint::clint(sc_core::sc_module_name nm) clint::clint(sc_core::sc_module_name nm)
: sc_core::sc_module(nm) : sc_core::sc_module(nm)
@ -51,16 +51,21 @@ clint::clint(sc_core::sc_module_name nm)
, NAMED(msip_int_o) , NAMED(msip_int_o)
, NAMEDD(regs, clint_regs) , NAMEDD(regs, clint_regs)
, cnt_fraction(0) { , cnt_fraction(0) {
SC_HAS_PROCESS(clint);// NOLINT
mtime_i.bind(*this);
regs->registerResources(*this); regs->registerResources(*this);
SC_METHOD(clock_cb); SC_METHOD(clock_cb);
sensitive << tlclk_i << lfclk_i; sensitive << tlclk_i << lfclk_i;
SC_METHOD(reset_cb); SC_METHOD(reset_cb);
sensitive << rst_i; sensitive << rst_i;
dont_initialize(); dont_initialize();
SC_METHOD(mtime_evt_cb);
sensitive<<mtime_evt;
dont_initialize();
regs->mtimecmp.set_write_cb([this](scc::sc_register<uint64_t> &reg, uint64_t data, sc_core::sc_time d) -> bool { regs->mtimecmp.set_write_cb([this](scc::sc_register<uint64_t> &reg, uint64_t data, sc_core::sc_time d) -> bool {
if (!regs->in_reset()) { if (!regs->in_reset()) {
reg.put(data); reg.put(data);
this->update_mtime(); this->update_mtime(true);
} }
return true; return true;
}); });
@ -76,9 +81,6 @@ clint::clint(sc_core::sc_module_name nm)
msip_int_o.write(regs->r_msip.msip); msip_int_o.write(regs->r_msip.msip);
return true; return true;
}); });
SC_METHOD(update_mtime);
sensitive << mtime_evt;
dont_initialize();
} }
void clint::clock_cb() { void clint::clock_cb() {
@ -99,26 +101,52 @@ void clint::reset_cb() {
regs->reset_stop(); 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) { if (clk > SC_ZERO_TIME) {
uint64_t elapsed_clks = uint64_t elapsed_clks =
(sc_time_stamp() - last_updt) / clk; // get the number of clock periods since last invocation (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 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; regs->r_mtime += elapsed_clks;
mtime_evt.cancel(); //mtime_evt.cancel();
if (regs->r_mtimecmp > 0) if (regs->r_mtimecmp > 0)
if (regs->r_mtimecmp > regs->r_mtime && clk > sc_core::SC_ZERO_TIME) { if (regs->r_mtimecmp > regs->r_mtime && clk > sc_core::SC_ZERO_TIME) {
sc_core::sc_time next_trigger = 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; SCTRACE() << "Timer fires at " << sc_time_stamp() + next_trigger;
mtime_evt.notify(next_trigger); mtime_evt.notify(next_trigger);
mtime_int_o.write(false); mtime_int_o.write(false);
} else } else {
SCTRACE() << "Timer fired at " << sc_time_stamp();
mtime_int_o.write(true); mtime_int_o.write(true);
} }
}
} else } else
last_updt = sc_time_stamp(); last_updt = sc_time_stamp();
} }
uint64_t clint::peek(tlm::tlm_tag<uint64_t>* t) const {
const_cast<clint*>(this)->update_mtime();
return regs->r_mtime;
}
bool clint::nb_peek(uint64_t& t) const {
const_cast<clint*>(this)->update_mtime();
t= regs->r_mtime;
return true;
}
bool clint::nb_can_peek(tlm::tlm_tag<uint64_t>* t) const {
return true;
}
const sc_core::sc_event& clint::ok_to_peek(tlm::tlm_tag<uint64_t>* t) const {
return dummy_evt;
}
} /* namespace sysc */ } /* namespace sysc */

View File

@ -135,7 +135,7 @@ fe310::fe310(sc_core::sc_module_name nm)
i_core_complex->timer_irq_i(s_mtime_int); i_core_complex->timer_irq_i(s_mtime_int);
i_core_complex->global_irq_i(s_core_int); i_core_complex->global_irq_i(s_core_int);
i_core_complex->local_irq_i(s_local_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); pins_i(i_gpio0->pins_i);
i_gpio0->pins_o(pins_o); i_gpio0->pins_o(pins_o);

2
riscv

@ -1 +1 @@
Subproject commit d93c2feec4c80ece0773fb2366821d01e11db4b6 Subproject commit 7f06bba239c2f15a08c65f701e31d60d229a66cb

2
scc

@ -1 +1 @@
Subproject commit 4be77aff604dc78f3c0856b6d17843b276b80b59 Subproject commit 19a0c10fc2db51527544674227ca44b8d46f8781