@@ -32,6 +32,7 @@ UARTSerial::UARTSerial(PinName tx, PinName rx, int baud) :
32
32
SerialBase (tx, rx, baud),
33
33
_blocking (true ),
34
34
_tx_irq_enabled (false ),
35
+ _rx_irq_enabled (true ),
35
36
_dcd_irq (NULL )
36
37
{
37
38
/* Attatch IRQ routines to the serial device. */
@@ -68,6 +69,22 @@ void UARTSerial::set_data_carrier_detect(PinName dcd_pin, bool active_high)
68
69
}
69
70
}
70
71
72
+ void UARTSerial::set_format (int bits, Parity parity, int stop_bits)
73
+ {
74
+ api_lock ();
75
+ SerialBase::format (bits, parity, stop_bits);
76
+ api_unlock ();
77
+ }
78
+
79
+ #if DEVICE_SERIAL_FC
80
+ void UARTSerial::set_flow_control (Flow type, PinName flow1, PinName flow2)
81
+ {
82
+ api_lock ();
83
+ SerialBase::set_flow_control (type, flow1, flow2);
84
+ api_unlock ();
85
+ }
86
+ #endif
87
+
71
88
int UARTSerial::close ()
72
89
{
73
90
/* Does not let us pass a file descriptor. So how to close ?
@@ -176,6 +193,16 @@ ssize_t UARTSerial::read(void* buffer, size_t length)
176
193
data_read++;
177
194
}
178
195
196
+ core_util_critical_section_enter ();
197
+ if (!_rx_irq_enabled) {
198
+ UARTSerial::rx_irq (); // only read from hardware in one place
199
+ if (!_rxbuf.full ()) {
200
+ SerialBase::attach (callback (this , &UARTSerial::rx_irq), RxIrq);
201
+ _rx_irq_enabled = true ;
202
+ }
203
+ }
204
+ core_util_critical_section_exit ();
205
+
179
206
api_unlock ();
180
207
181
208
return data_read;
@@ -243,13 +270,14 @@ void UARTSerial::rx_irq(void)
243
270
244
271
/* Fill in the receive buffer if the peripheral is readable
245
272
* and receive buffer is not full. */
246
- while (SerialBase::readable ()) {
273
+ while (!_rxbuf. full () && SerialBase::readable ()) {
247
274
char data = SerialBase::_base_getc ();
248
- if (!_rxbuf.full ()) {
249
- _rxbuf.push (data);
250
- } else {
251
- /* Drop - can we report in some way? */
252
- }
275
+ _rxbuf.push (data);
276
+ }
277
+
278
+ if (_rx_irq_enabled && _rxbuf.full ()) {
279
+ SerialBase::attach (NULL , RxIrq);
280
+ _rx_irq_enabled = false ;
253
281
}
254
282
255
283
/* Report the File handler that data is ready to be read from the buffer. */
0 commit comments