Skip to content

Commit 5b33d25

Browse files
committed
drivers: fix attach sleep locking
attach/detach can be multiple invoked. Therefore lock/unlock deep sleep only for the very first time it is invoked (when callbacks are actually changed).
1 parent e57f0bc commit 5b33d25

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

drivers/CAN.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ void CAN::attach(Callback<void()> func, IrqType type) {
123123
_irq[(CanIrqType)type] = func;
124124
can_irq_set(&_can, (CanIrqType)type, 1);
125125
} else {
126-
sleep_manager_unlock_deep_sleep();
126+
// unlock deep sleep only the first time
127+
if (_irq[(CanIrqType)type] != callback(donothing)) {
128+
sleep_manager_unlock_deep_sleep();
129+
}
127130
_irq[(CanIrqType)type] = callback(donothing);
128131
can_irq_set(&_can, (CanIrqType)type, 0);
129132
}

drivers/I2C.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ void I2C::unlock() {
129129
int I2C::transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event, bool repeated)
130130
{
131131
lock();
132-
sleep_manager_lock_deep_sleep();
133132
if (i2c_active(&_i2c)) {
134133
unlock();
135134
return -1; // transaction ongoing
136135
}
136+
sleep_manager_lock_deep_sleep();
137137
aquire();
138138

139139
_callback = callback;

drivers/SerialBase.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ void SerialBase::attach(Callback<void()> func, IrqType type) {
8484
_irq[type] = func;
8585
serial_irq_set(&_serial, (SerialIrq)type, 1);
8686
} else {
87-
sleep_manager_unlock_deep_sleep();
87+
// unlock deep sleep only the first time
88+
if (_irq[type] != donothing) {
89+
sleep_manager_unlock_deep_sleep();
90+
}
8891
_irq[type] = donothing;
8992
serial_irq_set(&_serial, (SerialIrq)type, 0);
9093
}
@@ -248,6 +251,7 @@ void SerialBase::start_read(void *buffer, int buffer_size, char buffer_width, co
248251
{
249252
_rx_callback = callback;
250253
_thunk_irq.callback(&SerialBase::interrupt_handler_asynch);
254+
sleep_manager_lock_deep_sleep();
251255
serial_rx_asynch(&_serial, buffer, buffer_size, buffer_width, _thunk_irq.entry(), event, char_match, _rx_usage);
252256
}
253257

0 commit comments

Comments
 (0)