Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
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() {
