From 7fc6be497e313d73e68c27f4cce057876b18f188 Mon Sep 17 00:00:00 2001 From: Daan Timmer <8293597+daantimmer@users.noreply.github.com> Date: Thu, 23 Feb 2023 11:01:44 +0000 Subject: [PATCH 1/4] Added DeregisterHandler call for the InterruptHandler that is moved in to --- hal_st/cortex/InterruptCortex.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/hal_st/cortex/InterruptCortex.cpp b/hal_st/cortex/InterruptCortex.cpp index b381868a..bbc2c603 100644 --- a/hal_st/cortex/InterruptCortex.cpp +++ b/hal_st/cortex/InterruptCortex.cpp @@ -63,6 +63,7 @@ namespace hal InterruptHandler& InterruptHandler::operator=(InterruptHandler&& other) { + InterruptTable::Instance().DeregisterHandler(irq, *this); irq = other.irq; InterruptTable::Instance().TakeOverHandler(irq, *this, other); From 936fc9567f330eee51e256c0e3829a83a46251f9 Mon Sep 17 00:00:00 2001 From: Daan Timmer <8293597+daantimmer@users.noreply.github.com> Date: Thu, 23 Feb 2023 11:05:29 +0000 Subject: [PATCH 2/4] Refactored invalidIrq value --- hal_st/cortex/InterruptCortex.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hal_st/cortex/InterruptCortex.cpp b/hal_st/cortex/InterruptCortex.cpp index bbc2c603..1478909a 100644 --- a/hal_st/cortex/InterruptCortex.cpp +++ b/hal_st/cortex/InterruptCortex.cpp @@ -6,6 +6,8 @@ namespace hal { namespace { + constexpr auto invalidIrq = static_cast(0xffff); + void EnableInterrupt(IRQn_Type irq, InterruptPriority priority) { if (irq >= 0) @@ -58,7 +60,7 @@ namespace hal : irq(other.irq) { InterruptTable::Instance().TakeOverHandler(irq, *this, other); - other.irq = static_cast(0xffff); + other.irq = invalidIrq; } InterruptHandler& InterruptHandler::operator=(InterruptHandler&& other) @@ -67,14 +69,14 @@ namespace hal irq = other.irq; InterruptTable::Instance().TakeOverHandler(irq, *this, other); - other.irq = static_cast(0xffff); + other.irq = invalidIrq; return *this; } InterruptHandler::~InterruptHandler() { - if (irq != static_cast(0xffff)) + if (irq != invalidIrq) InterruptTable::Instance().DeregisterHandler(irq, *this); } @@ -87,7 +89,7 @@ namespace hal void InterruptHandler::Unregister() { InterruptTable::Instance().DeregisterHandler(irq, *this); - this->irq = static_cast(0xffff); + irq = invalidIrq; } IRQn_Type InterruptHandler::Irq() const From 526a5bc0b9c4f3b7dbfa6c218f566146481c4051 Mon Sep 17 00:00:00 2001 From: Daan Timmer <8293597+daantimmer@users.noreply.github.com> Date: Thu, 23 Feb 2023 11:05:53 +0000 Subject: [PATCH 3/4] Refactored inconsistent access to shadowed member variable irq --- hal_st/cortex/InterruptCortex.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hal_st/cortex/InterruptCortex.cpp b/hal_st/cortex/InterruptCortex.cpp index 1478909a..1d86ba50 100644 --- a/hal_st/cortex/InterruptCortex.cpp +++ b/hal_st/cortex/InterruptCortex.cpp @@ -83,7 +83,7 @@ namespace hal void InterruptHandler::Register(IRQn_Type irq, InterruptPriority priority) { this->irq = irq; - InterruptTable::Instance().RegisterHandler(irq, *this, priority); + InterruptTable::Instance().RegisterHandler(this->irq, *this, priority); } void InterruptHandler::Unregister() From a753515319e4def87c7502c66e49e2ab7f06a666 Mon Sep 17 00:00:00 2001 From: Daan Timmer <8293597+daantimmer@users.noreply.github.com> Date: Tue, 14 Mar 2023 08:41:16 +0100 Subject: [PATCH 4/4] chore: added check before DeregisterHandler that the currently handler is a valid one --- hal_st/cortex/InterruptCortex.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hal_st/cortex/InterruptCortex.cpp b/hal_st/cortex/InterruptCortex.cpp index 1d86ba50..6a5ef35a 100644 --- a/hal_st/cortex/InterruptCortex.cpp +++ b/hal_st/cortex/InterruptCortex.cpp @@ -65,7 +65,9 @@ namespace hal InterruptHandler& InterruptHandler::operator=(InterruptHandler&& other) { - InterruptTable::Instance().DeregisterHandler(irq, *this); + if (irq != invalidIrq) + InterruptTable::Instance().DeregisterHandler(irq, *this); + irq = other.irq; InterruptTable::Instance().TakeOverHandler(irq, *this, other);