From 10af336cd13f962bc584b4075692d4085fb8bae9 Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Thu, 7 Mar 2024 23:23:01 -0800 Subject: [PATCH] Ensure that VIA timers are stopped when the object is destroyed. --- devices/common/viacuda.cpp | 23 ++++++++++++++++++++++- devices/common/viacuda.h | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/devices/common/viacuda.cpp b/devices/common/viacuda.cpp index ff2f681..78eebc9 100644 --- a/devices/common/viacuda.cpp +++ b/devices/common/viacuda.cpp @@ -88,6 +88,26 @@ ViaCuda::ViaCuda() { this->int_ctrl = nullptr; } +ViaCuda::~ViaCuda() +{ + if (this->sr_timer_on) { + TimerManager::get_instance()->cancel_timer(this->sr_timer_id); + this->sr_timer_on = false; + } + if (this->t1_active) { + TimerManager::get_instance()->cancel_timer(this->t1_timer_id); + this->t1_active = false; + } + if (this->t2_active) { + TimerManager::get_instance()->cancel_timer(this->t2_timer_id); + this->t2_active = false; + } + if (this->treq_timer_id) { + TimerManager::get_instance()->cancel_timer(this->treq_timer_id); + this->treq_timer_id = 0; + } +} + int ViaCuda::device_postinit() { this->int_ctrl = dynamic_cast( @@ -342,11 +362,12 @@ void ViaCuda::write(uint8_t new_state) { process_packet(); // start response transaction - TimerManager::get_instance()->add_oneshot_timer( + this->treq_timer_id = TimerManager::get_instance()->add_oneshot_timer( USECS_TO_NSECS(13), // delay TREQ assertion for New World [this]() { this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ this->treq = 0; + this->treq_timer_id = 0; }); } diff --git a/devices/common/viacuda.h b/devices/common/viacuda.h index 45079d6..d097570 100644 --- a/devices/common/viacuda.h +++ b/devices/common/viacuda.h @@ -155,7 +155,7 @@ enum { class ViaCuda : public HWComponent, public I2CBus { public: ViaCuda(); - ~ViaCuda() = default; + ~ViaCuda(); static std::unique_ptr create() { return std::unique_ptr(new ViaCuda()); @@ -206,6 +206,7 @@ private: uint8_t old_tip; uint8_t old_byteack; uint8_t treq; + uint32_t treq_timer_id = 0; uint8_t in_buf[CUDA_IN_BUF_SIZE]; int32_t in_count; uint8_t out_buf[16];