diff --git a/src/Timer.cpp b/src/Timer.cpp index d8bad5d..e2a83a3 100644 --- a/src/Timer.cpp +++ b/src/Timer.cpp @@ -7,6 +7,9 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "Timer.h" +#define unlikely(x) __builtin_expect(!!(x), 0) + +using namespace sc_core; namespace riscv_tlm::peripherals { @@ -69,8 +72,12 @@ namespace riscv_tlm::peripherals { std::uint64_t notify_time; // notify needs relative time, mtimecmp works in absolute time - notify_time = m_mtimecmp - m_mtime; - + + notify_time = m_mtimecmp.to_ulong() - m_mtime.to_ulong(); + // FIXed m_mtimecmp should be .gt. m_mtime + if ( unlikely( m_mtimecmp.to_ulong() < m_mtime.to_ulong() ) ) { + m_mtimecmp.range(31, 0) = (0xFFFFFFFF¬ify_time)-1; + } timer_event.notify(sc_core::sc_time(notify_time, sc_core::SC_NS)); break; default: @@ -101,4 +108,4 @@ namespace riscv_tlm::peripherals { trans.set_response_status(tlm::TLM_OK_RESPONSE); } -} \ No newline at end of file +}