Skip to content

Commit 717e851

Browse files
author
Sebastian Stockhammer
committed
Setup interrupts after serial is enabled
1 parent 9fed18a commit 717e851

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

drivers/source/UARTSerial.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,7 @@ ssize_t UARTSerial::write(const void *buffer, size_t length)
192192
data_written++;
193193
}
194194

195-
core_util_critical_section_enter();
196-
if (_tx_enabled && !_tx_irq_enabled) {
197-
UARTSerial::tx_irq(); // only write to hardware in one place
198-
if (!_txbuf.empty()) {
199-
enable_tx_irq();
200-
}
201-
}
202-
core_util_critical_section_exit();
195+
enable_tx_irq();
203196
}
204197

205198
api_unlock();
@@ -234,14 +227,7 @@ ssize_t UARTSerial::read(void *buffer, size_t length)
234227
data_read++;
235228
}
236229

237-
core_util_critical_section_enter();
238-
if (_rx_enabled && !_rx_irq_enabled) {
239-
UARTSerial::rx_irq(); // only read from hardware in one place
240-
if (!_rxbuf.full()) {
241-
enable_rx_irq();
242-
}
243-
}
244-
core_util_critical_section_exit();
230+
enable_rx_irq();
245231

246232
api_unlock();
247233

@@ -351,8 +337,15 @@ void UARTSerial::tx_irq(void)
351337
/* These are all called from critical section */
352338
void UARTSerial::enable_rx_irq()
353339
{
354-
SerialBase::attach(callback(this, &UARTSerial::rx_irq), RxIrq);
355-
_rx_irq_enabled = true;
340+
core_util_critical_section_enter();
341+
if (_rx_enabled && !_rx_irq_enabled) {
342+
UARTSerial::rx_irq(); // only read from hardware in one place
343+
if (!_rxbuf.full()) {
344+
SerialBase::attach(callback(this, &UARTSerial::rx_irq), RxIrq);
345+
_rx_irq_enabled = true;
346+
}
347+
}
348+
core_util_critical_section_exit();
356349
}
357350

358351
void UARTSerial::disable_rx_irq()
@@ -363,8 +356,15 @@ void UARTSerial::disable_rx_irq()
363356

364357
void UARTSerial::enable_tx_irq()
365358
{
366-
SerialBase::attach(callback(this, &UARTSerial::tx_irq), TxIrq);
367-
_tx_irq_enabled = true;
359+
core_util_critical_section_enter();
360+
if (_tx_enabled && !_tx_irq_enabled) {
361+
UARTSerial::tx_irq(); // only write to hardware in one place
362+
if (!_txbuf.empty()) {
363+
SerialBase::attach(callback(this, &UARTSerial::tx_irq), TxIrq);
364+
_tx_irq_enabled = true;
365+
}
366+
}
367+
core_util_critical_section_exit();
368368
}
369369

370370
void UARTSerial::disable_tx_irq()
@@ -377,6 +377,7 @@ int UARTSerial::enable_input(bool enabled)
377377
{
378378
api_lock();
379379
SerialBase::enable_input(enabled);
380+
enable_rx_irq(); // Enable interrupt to handle incoming data
380381
api_unlock();
381382

382383
return 0;
@@ -386,6 +387,7 @@ int UARTSerial::enable_output(bool enabled)
386387
{
387388
api_lock();
388389
SerialBase::enable_output(enabled);
390+
enable_tx_irq(); // Enable interrupt to flush buffered data
389391
api_unlock();
390392

391393
return 0;

0 commit comments

Comments
 (0)