Fix double disable segfaulting interrupts (#2132)

Also fixes DigitalOutput not closing correctly.
This commit is contained in:
Thad House
2019-11-25 21:43:58 -08:00
committed by Peter Johnson
parent 6ceafe3cd0
commit 3fcfc8ea72
2 changed files with 13 additions and 3 deletions

View File

@@ -118,7 +118,11 @@ void* HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle,
if (anInterrupt == nullptr) { if (anInterrupt == nullptr) {
return nullptr; return nullptr;
} }
anInterrupt->manager->disable(status);
if (anInterrupt->manager->isEnabled(status)) {
anInterrupt->manager->disable(status);
}
void* param = anInterrupt->param; void* param = anInterrupt->param;
return param; return param;
} }
@@ -152,7 +156,10 @@ void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle,
*status = HAL_HANDLE_ERROR; *status = HAL_HANDLE_ERROR;
return; return;
} }
anInterrupt->manager->enable(status);
if (!anInterrupt->manager->isEnabled(status)) {
anInterrupt->manager->enable(status);
}
} }
void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle, void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
@@ -162,7 +169,9 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
*status = HAL_HANDLE_ERROR; *status = HAL_HANDLE_ERROR;
return; return;
} }
anInterrupt->manager->disable(status); if (anInterrupt->manager->isEnabled(status)) {
anInterrupt->manager->disable(status);
}
} }
int64_t HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle, int64_t HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,

View File

@@ -44,6 +44,7 @@ public class DigitalOutput extends DigitalSource implements Sendable, AutoClosea
@Override @Override
public void close() { public void close() {
super.close();
SendableRegistry.remove(this); SendableRegistry.remove(this);
// Disable the pwm only if we have allocated it // Disable the pwm only if we have allocated it
if (m_pwmGenerator != invalidPwmGenerator) { if (m_pwmGenerator != invalidPwmGenerator) {