21
21
Modified 14 August 2012 by Alarus
22
22
Modified 3 December 2013 by Matthijs Kooijman
23
23
Modified 1 may 2023 by TempersLee
24
+ Modified 28 July 2024 by Maxint R&D
24
25
*/
25
26
27
+
26
28
#include < stdio.h>
27
29
#include " Arduino.h"
28
30
#include " HardwareSerial.h"
@@ -175,59 +177,6 @@ void HardwareSerial::begin(unsigned long baud, byte config)
175
177
#endif
176
178
}
177
179
178
-
179
- #if (OPT_USART1_INT==1)
180
- #else
181
- // MMOLE: reintroduced RX buffer to properly implement read/available/peek methods
182
- void HardwareSerial::fillRxBuffer (void ) // private method: read all characters that can be read
183
- {
184
- // Fill RX buffer during read/available calls
185
- // Newly received characters are added to the buffer
186
- // _rx_buffer_head is the location of the new character
187
- // _rx_buffer_tail is the location of the oldest character that is not read yet
188
- unsigned char c;
189
- /*
190
- while(uart_getc(&_serial, &c) == 0)
191
- {
192
- _rx_buffer[_rx_buffer_head]=c;
193
- _rx_buffer_head = (rx_buffer_index_t)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
194
- }
195
- */
196
- // To avoid buffer underruns, we try to read during at least a few millis.
197
- // Perhaps there is a better way, but for now it works.
198
- // Maybe we should also do something to handle disruption of interrupts
199
- /*
200
- #define SERIAL_WAIT_FOR_RX 5000L
201
- uint32_t uStart=micros();
202
- while((micros()-uStart)<SERIAL_WAIT_FOR_RX)
203
- */
204
- #define SERIAL_WAIT_FOR_RX 3
205
- uint32_t uStart=millis ();
206
- while ((millis ()-uStart)<SERIAL_WAIT_FOR_RX)
207
- {
208
- if (uart_getc (&_serial, &c) == 0 )
209
- {
210
- /*
211
- _rx_buffer[_rx_buffer_head]=c;
212
- _rx_buffer_head = (rx_buffer_index_t)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
213
- /**/
214
- rx_buffer_index_t i = (unsigned int )(_rx_buffer_head + 1 ) % SERIAL_RX_BUFFER_SIZE;
215
-
216
- // if we should be storing the received character into the location
217
- // just before the tail (meaning that the head would advance to the
218
- // current location of the tail), we're about to overflow the buffer
219
- // and so we don't write the character or advance the head.
220
- if (i != _rx_buffer_tail) {
221
- _rx_buffer[_rx_buffer_head] = c;
222
- _rx_buffer_head = i;
223
- }
224
- /* */
225
- }
226
- }
227
- }
228
- #endif
229
-
230
-
231
180
void HardwareSerial::end ()
232
181
{
233
182
// MMOLE: reintroduced RX buffer to properly implement read/available/peek methods
@@ -245,9 +194,6 @@ int HardwareSerial::available(void)
245
194
{
246
195
// MMOLE: reintroduced RX buffer to properly implement read/available/peek methods
247
196
// return -1;
248
- #if (OPT_USART1_INT==0)
249
- fillRxBuffer (); // use polling to fill the RX buffer
250
- #endif
251
197
return ((unsigned int )(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail)) % SERIAL_RX_BUFFER_SIZE;
252
198
}
253
199
@@ -256,9 +202,6 @@ int HardwareSerial::peek(void)
256
202
// MMOLE: reintroduced RX buffer to properly implement read/available/peek methods
257
203
// MMOLE 240316: Serial.parseInt() uses peek() with timeout to see if more data is available
258
204
// return -1;
259
- #if (OPT_USART1_INT==0)
260
- fillRxBuffer (); // use polling to fill the RX buffer
261
- #endif
262
205
if (_rx_buffer_head == _rx_buffer_tail) {
263
206
return -1 ;
264
207
} else {
@@ -277,10 +220,6 @@ int HardwareSerial::read(void)
277
220
return -1;
278
221
}
279
222
*/
280
- #if (OPT_USART1_INT==0)
281
- // Fill RX buffer during read/available calls
282
- fillRxBuffer (); // use polling to fill the RX buffer
283
- #endif
284
223
285
224
// if the head isn't ahead of the tail, we don't have any characters
286
225
if (_rx_buffer_head == _rx_buffer_tail) {
0 commit comments