Skip to content

Commit f854f3e

Browse files
committed
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.
1 parent 87b151c commit f854f3e

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

drivers/CAN.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ CAN::CAN(PinName rd, PinName td, int hz) : _can(), _irq() {
4646

4747
CAN::~CAN() {
4848
// No lock needed in destructor
49+
50+
// Detaching interrupts releases the sleep lock if it was locked
51+
for (int irq = 0; irq < IrqCnt; irq++) {
52+
attach(NULL, (IrqType)irq);
53+
}
4954
can_irq_free(&_can);
5055
can_free(&_can);
5156
}

drivers/SerialBase.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ void SerialBase:: unlock() {
133133
// Stub
134134
}
135135

136+
SerialBase::~SerialBase()
137+
{
138+
// No lock needed in destructor
139+
140+
// Detaching interrupts releases the sleep lock if it was locked
141+
for (int irq = 0; irq < IrqCnt; irq++) {
142+
attach(NULL, (IrqType)irq);
143+
}
144+
}
145+
136146
#if DEVICE_SERIAL_FC
137147
void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) {
138148
lock();

drivers/SerialBase.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ class SerialBase : private NonCopyable<SerialBase> {
241241

242242
protected:
243243
SerialBase(PinName tx, PinName rx, int baud);
244-
virtual ~SerialBase() {
245-
}
244+
virtual ~SerialBase();
246245

247246
int _base_getc();
248247
int _base_putc(int c);

0 commit comments

Comments
 (0)