Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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&notify_time)-1;
}
timer_event.notify(sc_core::sc_time(notify_time, sc_core::SC_NS));
break;
default:
Expand Down Expand Up @@ -101,4 +108,4 @@ namespace riscv_tlm::peripherals {

trans.set_response_status(tlm::TLM_OK_RESPONSE);
}
}
}