Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions core/timermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,14 @@ uint64_t TimerManager::process_timers()
if (cur_timer->interval_ns) {
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
uint64_t timeout_ns_new = timeout_ns + cur_timer->interval_ns;
if (timeout_ns_new <= time_now)
timeout_ns_new = time_now + cur_timer->interval_ns;
if (timeout_ns_new <= time_now) {
// Skip missed periods without changing the timer's phase.
// Rebasing deadlines on time_now would align timers that
// have the same period.
const uint64_t periods_to_skip =
((time_now - timeout_ns_new) / cur_timer->interval_ns) + 1;
timeout_ns_new += periods_to_skip * cur_timer->interval_ns;
}
cur_timer->timeout_ns = timeout_ns_new;
this->timer_queue.push(cur_timer);
} else {
Expand Down
31 changes: 17 additions & 14 deletions devices/video/videoctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,30 @@ void VideoCtrlBase::start_refresh_task() {
this->display.configure(this->active_width, this->active_height);

uint64_t refresh_interval = static_cast<uint64_t>(1.0f / refresh_rate * NS_PER_SEC + 0.5);
TimerManager::get_instance()->add_cyclic_timer(this->refresh_timer,
refresh_interval,
[this](uint64_t, uint64_t) {
// assert VBL interrupt
this->vbl_cb(1);
this->update_screen();
}
);

if (vert_blank == 0) {
LOG_F(ERROR, "Vertical blank is 0. Using 25 instead.");
vert_blank = 25;
}

uint64_t vbl_duration = static_cast<uint64_t>((double)hori_total * vert_blank / this->pixel_clock * NS_PER_SEC + 0.5);
TimerManager::get_instance()-> add_cyclic_timer(this->vbl_end_timer,
TimerManager::get_instance()->add_cyclic_timer(
this->refresh_timer,
refresh_interval,
refresh_interval + vbl_duration,
[this](uint64_t, uint64_t) {
// deassert VBL interrupt
this->vbl_cb(0);
[this, vbl_duration](uint64_t, uint64_t) {
this->vbl_cb(1); // assert VBL interrupt

if (this->vbl_end_timer.active) {
TimerManager::get_instance()->cancel_timer(this->vbl_end_timer);
}
TimerManager::get_instance()->add_oneshot_timer(
this->vbl_end_timer,
vbl_duration,
[this](uint64_t, uint64_t) {
this->vbl_cb(0); // deassert VBL interrupt
}
);

this->update_screen();
}
);
}
Expand Down
Loading