Skip to content

Commit aa2969f

Browse files
author
Sebastian Stockhammer
committed
Public SerialBase::enable_input
1 parent b3b7f98 commit aa2969f

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

drivers/SerialBase.h

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,30 @@ class SerialBase : private NonCopyable<SerialBase> {
155155
*/
156156
void send_break();
157157

158+
/** Enable serial input
159+
*
160+
* If both serial input and serial output are disabled, the
161+
* peripheral is freed. If either serial input or serial
162+
* output is re-enabled, the peripheral is reinitialized.
163+
*
164+
* On reinitialisation rx interrupts will be enabled if a
165+
* rx handler is attached. The rx handler is called once
166+
* during reinitialisation.
167+
*/
168+
void enable_input(bool enable = true);
169+
170+
/** Enable serial output
171+
*
172+
* If both serial input and serial output are disabled, the
173+
* peripheral is freed. If either serial input or serial
174+
* output is re-enabled, the peripheral is reinitialized.
175+
*
176+
* On reinitialisation tx interrupts will be enabled if a
177+
* tx handler is attached. The tx handler is called once
178+
* during reinitialisation.
179+
*/
180+
void enable_output(bool enable = true);
181+
158182
#if !defined(DOXYGEN_ONLY)
159183
protected:
160184

@@ -303,22 +327,6 @@ class SerialBase : private NonCopyable<SerialBase> {
303327
*/
304328
void _deinit();
305329

306-
/** Enable serial input
307-
*
308-
* If both serial input and serial output are disabled, the
309-
* peripheral is freed. If either serial input or serial
310-
* output is re-enabled, the peripheral is reinitialized.
311-
*/
312-
void _enable_input(bool enable = true);
313-
314-
/** Enable serial output
315-
*
316-
* If both serial input and serial output are disabled, the
317-
* peripheral is freed. If either serial input or serial
318-
* output is re-enabled, the peripheral is reinitialized.
319-
*/
320-
void _enable_output(bool enable = true);
321-
322330
#if DEVICE_SERIAL_ASYNCH
323331
CThunk<SerialBase> _thunk_irq;
324332
DMAUsage _tx_usage;

drivers/source/SerialBase.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ void SerialBase::_deinit()
130130
serial_free(&_serial);
131131
}
132132

133-
void SerialBase::_enable_input(bool enable)
133+
void SerialBase::enable_input(bool enable)
134134
{
135+
lock();
135136
if (_rx_enabled != enable) {
136137
if (enable && !_tx_enabled) {
137138
_init();
@@ -156,10 +157,12 @@ void SerialBase::_enable_input(bool enable)
156157
_deinit();
157158
}
158159
}
160+
unlock();
159161
}
160162

161-
void SerialBase::_enable_output(bool enable)
163+
void SerialBase::enable_output(bool enable)
162164
{
165+
lock();
163166
if (_tx_enabled != enable) {
164167
if (enable && !_rx_enabled) {
165168
_init();
@@ -184,6 +187,7 @@ void SerialBase::_enable_output(bool enable)
184187
_deinit();
185188
}
186189
}
190+
unlock();
187191
}
188192

189193
void SerialBase::set_break()

drivers/source/UARTSerial.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void UARTSerial::disable_tx_irq()
367367
int UARTSerial::enable_input(bool enabled)
368368
{
369369
api_lock();
370-
_enable_input(enabled);
370+
SerialBase::enable_input(enabled);
371371
api_unlock();
372372

373373
return 0;
@@ -376,7 +376,7 @@ int UARTSerial::enable_input(bool enabled)
376376
int UARTSerial::enable_output(bool enabled)
377377
{
378378
api_lock();
379-
_enable_input(enabled);
379+
SerialBase::enable_input(enabled);
380380
api_unlock();
381381

382382
return 0;

0 commit comments

Comments
 (0)