mirror of https://github.com/ARMmbed/mbed-os.git
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).pull/4912/head
parent
e57f0bcd26
commit
5b33d2583d
|
|
@ -123,7 +123,10 @@ void CAN::attach(Callback<void()> func, IrqType type) {
|
||||||
_irq[(CanIrqType)type] = func;
|
_irq[(CanIrqType)type] = func;
|
||||||
can_irq_set(&_can, (CanIrqType)type, 1);
|
can_irq_set(&_can, (CanIrqType)type, 1);
|
||||||
} else {
|
} else {
|
||||||
|
// unlock deep sleep only the first time
|
||||||
|
if (_irq[(CanIrqType)type] != callback(donothing)) {
|
||||||
sleep_manager_unlock_deep_sleep();
|
sleep_manager_unlock_deep_sleep();
|
||||||
|
}
|
||||||
_irq[(CanIrqType)type] = callback(donothing);
|
_irq[(CanIrqType)type] = callback(donothing);
|
||||||
can_irq_set(&_can, (CanIrqType)type, 0);
|
can_irq_set(&_can, (CanIrqType)type, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,11 +129,11 @@ void I2C::unlock() {
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
lock();
|
lock();
|
||||||
sleep_manager_lock_deep_sleep();
|
|
||||||
if (i2c_active(&_i2c)) {
|
if (i2c_active(&_i2c)) {
|
||||||
unlock();
|
unlock();
|
||||||
return -1; // transaction ongoing
|
return -1; // transaction ongoing
|
||||||
}
|
}
|
||||||
|
sleep_manager_lock_deep_sleep();
|
||||||
aquire();
|
aquire();
|
||||||
|
|
||||||
_callback = callback;
|
_callback = callback;
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,10 @@ void SerialBase::attach(Callback<void()> func, IrqType type) {
|
||||||
_irq[type] = func;
|
_irq[type] = func;
|
||||||
serial_irq_set(&_serial, (SerialIrq)type, 1);
|
serial_irq_set(&_serial, (SerialIrq)type, 1);
|
||||||
} else {
|
} else {
|
||||||
|
// unlock deep sleep only the first time
|
||||||
|
if (_irq[type] != donothing) {
|
||||||
sleep_manager_unlock_deep_sleep();
|
sleep_manager_unlock_deep_sleep();
|
||||||
|
}
|
||||||
_irq[type] = donothing;
|
_irq[type] = donothing;
|
||||||
serial_irq_set(&_serial, (SerialIrq)type, 0);
|
serial_irq_set(&_serial, (SerialIrq)type, 0);
|
||||||
}
|
}
|
||||||
|
|
@ -248,6 +251,7 @@ void SerialBase::start_read(void *buffer, int buffer_size, char buffer_width, co
|
||||||
{
|
{
|
||||||
_rx_callback = callback;
|
_rx_callback = callback;
|
||||||
_thunk_irq.callback(&SerialBase::interrupt_handler_asynch);
|
_thunk_irq.callback(&SerialBase::interrupt_handler_asynch);
|
||||||
|
sleep_manager_lock_deep_sleep();
|
||||||
serial_rx_asynch(&_serial, buffer, buffer_size, buffer_width, _thunk_irq.entry(), event, char_match, _rx_usage);
|
serial_rx_asynch(&_serial, buffer, buffer_size, buffer_width, _thunk_irq.entry(), event, char_match, _rx_usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue