From f854f3e6db95b4676e0aa1b1e7cc65d23d3019cd Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Thu, 28 Sep 2017 16:43:03 -0500 Subject: [PATCH] Properly unlock sleep in destructor of drivers Unlock sleep in CAN and SerialBase. This prevents deep sleep from staying locked if these objects are destroyed without first clearing the callbacks. --- drivers/CAN.cpp | 5 +++++ drivers/SerialBase.cpp | 10 ++++++++++ drivers/SerialBase.h | 3 +-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/CAN.cpp b/drivers/CAN.cpp index e49b7adfcb..b84d6082ce 100644 --- a/drivers/CAN.cpp +++ b/drivers/CAN.cpp @@ -46,6 +46,11 @@ CAN::CAN(PinName rd, PinName td, int hz) : _can(), _irq() { CAN::~CAN() { // No lock needed in destructor + + // Detaching interrupts releases the sleep lock if it was locked + for (int irq = 0; irq < IrqCnt; irq++) { + attach(NULL, (IrqType)irq); + } can_irq_free(&_can); can_free(&_can); } diff --git a/drivers/SerialBase.cpp b/drivers/SerialBase.cpp index e07a44149d..5ec47ff83a 100644 --- a/drivers/SerialBase.cpp +++ b/drivers/SerialBase.cpp @@ -133,6 +133,16 @@ void SerialBase:: unlock() { // Stub } +SerialBase::~SerialBase() +{ + // No lock needed in destructor + + // Detaching interrupts releases the sleep lock if it was locked + for (int irq = 0; irq < IrqCnt; irq++) { + attach(NULL, (IrqType)irq); + } +} + #if DEVICE_SERIAL_FC void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) { lock(); diff --git a/drivers/SerialBase.h b/drivers/SerialBase.h index 835e1a33b1..faf29a0699 100644 --- a/drivers/SerialBase.h +++ b/drivers/SerialBase.h @@ -241,8 +241,7 @@ protected: protected: SerialBase(PinName tx, PinName rx, int baud); - virtual ~SerialBase() { - } + virtual ~SerialBase(); int _base_getc(); int _base_putc(int c);