Ensure that VIA timers are stopped when the object is destroyed.

This commit is contained in:
Mihai Parparita 2024-03-07 23:23:01 -08:00
parent f218a38294
commit 10af336cd1
2 changed files with 24 additions and 2 deletions

View File

@ -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<InterruptCtrl*>(
@ -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;
});
}

View File

@ -155,7 +155,7 @@ enum {
class ViaCuda : public HWComponent, public I2CBus {
public:
ViaCuda();
~ViaCuda() = default;
~ViaCuda();
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<ViaCuda>(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];