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.
pull/5220/head
Russ Butler 2017-09-28 16:43:03 -05:00
parent 87b151c8a0
commit f854f3e6db
3 changed files with 16 additions and 2 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -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);