Skip to content

Commit d605c9d

Browse files
authored
Removed clumsy polling alternative for interrupts
1 parent a753874 commit d605c9d

File tree

1 file changed

+2
-63
lines changed

1 file changed

+2
-63
lines changed

Diff for: cores/arduino/HardwareSerial.cpp

+2-63
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
Modified 14 August 2012 by Alarus
2222
Modified 3 December 2013 by Matthijs Kooijman
2323
Modified 1 may 2023 by TempersLee
24+
Modified 28 July 2024 by Maxint R&D
2425
*/
2526

27+
2628
#include <stdio.h>
2729
#include "Arduino.h"
2830
#include "HardwareSerial.h"
@@ -175,59 +177,6 @@ void HardwareSerial::begin(unsigned long baud, byte config)
175177
#endif
176178
}
177179

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-
231180
void HardwareSerial::end()
232181
{
233182
// MMOLE: reintroduced RX buffer to properly implement read/available/peek methods
@@ -245,9 +194,6 @@ int HardwareSerial::available(void)
245194
{
246195
// MMOLE: reintroduced RX buffer to properly implement read/available/peek methods
247196
//return -1;
248-
#if(OPT_USART1_INT==0)
249-
fillRxBuffer(); // use polling to fill the RX buffer
250-
#endif
251197
return ((unsigned int)(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail)) % SERIAL_RX_BUFFER_SIZE;
252198
}
253199

@@ -256,9 +202,6 @@ int HardwareSerial::peek(void)
256202
// MMOLE: reintroduced RX buffer to properly implement read/available/peek methods
257203
// MMOLE 240316: Serial.parseInt() uses peek() with timeout to see if more data is available
258204
//return -1;
259-
#if(OPT_USART1_INT==0)
260-
fillRxBuffer(); // use polling to fill the RX buffer
261-
#endif
262205
if (_rx_buffer_head == _rx_buffer_tail) {
263206
return -1;
264207
} else {
@@ -277,10 +220,6 @@ int HardwareSerial::read(void)
277220
return -1;
278221
}
279222
*/
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
284223

285224
// if the head isn't ahead of the tail, we don't have any characters
286225
if (_rx_buffer_head == _rx_buffer_tail) {

0 commit comments

Comments
 (0)