mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: drivers/CAN.cpp
- Revision:
- 174:b96e65c34a4d
- Parent:
- 169:e3b6fe271b81
- Child:
- 175:af195413fb11
--- a/drivers/CAN.cpp Fri Sep 15 14:59:18 2017 +0100 +++ b/drivers/CAN.cpp Mon Oct 02 15:33:19 2017 +0100 @@ -18,16 +18,15 @@ #if DEVICE_CAN #include "cmsis.h" +#include "platform/mbed_sleep.h" namespace mbed { -static void donothing() {} - CAN::CAN(PinName rd, PinName td) : _can(), _irq() { // No lock needed in constructor for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) { - _irq[i] = callback(donothing); + _irq[i] = NULL; } can_init(&_can, rd, td); @@ -38,7 +37,7 @@ // No lock needed in constructor for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) { - _irq[i].attach(donothing); + _irq[i] = NULL; } can_init_freq(&_can, rd, td, hz); @@ -115,10 +114,18 @@ void CAN::attach(Callback<void()> func, IrqType type) { lock(); if (func) { + // lock deep sleep only the first time + if (!_irq[(CanIrqType)type]) { + sleep_manager_lock_deep_sleep(); + } _irq[(CanIrqType)type] = func; can_irq_set(&_can, (CanIrqType)type, 1); } else { - _irq[(CanIrqType)type] = callback(donothing); + // unlock deep sleep only the first time + if (_irq[(CanIrqType)type]) { + sleep_manager_unlock_deep_sleep(); + } + _irq[(CanIrqType)type] = NULL; can_irq_set(&_can, (CanIrqType)type, 0); } unlock(); @@ -126,7 +133,9 @@ void CAN::_irq_handler(uint32_t id, CanIrqType type) { CAN *handler = (CAN*)id; - handler->_irq[type].call(); + if (handler->_irq[type]) { + handler->_irq[type].call(); + } } void CAN::lock() {