Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deregister-interrupt-handler-on-move-assign #80

Merged
Merged
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
15 changes: 10 additions & 5 deletions hal_st/cortex/InterruptCortex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace hal
{
namespace
{
constexpr auto invalidIrq = static_cast<IRQn_Type>(0xffff);

void EnableInterrupt(IRQn_Type irq, InterruptPriority priority)
{
if (irq >= 0)
Expand Down Expand Up @@ -58,35 +60,38 @@ namespace hal
: irq(other.irq)
{
InterruptTable::Instance().TakeOverHandler(irq, *this, other);
other.irq = static_cast<IRQn_Type>(0xffff);
other.irq = invalidIrq;
}

InterruptHandler& InterruptHandler::operator=(InterruptHandler&& other)
{
if (irq != invalidIrq)
InterruptTable::Instance().DeregisterHandler(irq, *this);

irq = other.irq;

InterruptTable::Instance().TakeOverHandler(irq, *this, other);
other.irq = static_cast<IRQn_Type>(0xffff);
other.irq = invalidIrq;

return *this;
}

InterruptHandler::~InterruptHandler()
{
if (irq != static_cast<IRQn_Type>(0xffff))
if (irq != invalidIrq)
InterruptTable::Instance().DeregisterHandler(irq, *this);
}

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()
{
InterruptTable::Instance().DeregisterHandler(irq, *this);
this->irq = static_cast<IRQn_Type>(0xffff);
irq = invalidIrq;
}

IRQn_Type InterruptHandler::Irq() const
Expand Down