|
@@ -69,13 +69,14 @@
|
69
|
69
|
// using a ring buffer (I think), in which rx_buffer_head is the index of the
|
70
|
70
|
// location to which to write the next incoming character and rx_buffer_tail
|
71
|
71
|
// is the index of the location from which to read.
|
|
72
|
+// 256 is the max limit due to uint8_t head and tail. Thats needed to make them atomic.
|
72
|
73
|
#define RX_BUFFER_SIZE 128
|
73
|
74
|
|
74
|
75
|
|
75
|
76
|
struct ring_buffer {
|
76
|
77
|
unsigned char buffer[RX_BUFFER_SIZE];
|
77
|
|
- int head;
|
78
|
|
- int tail;
|
|
78
|
+ volatile uint8_t head;
|
|
79
|
+ volatile uint8_t tail;
|
79
|
80
|
};
|
80
|
81
|
|
81
|
82
|
#if UART_PRESENT(SERIAL_PORT)
|
|
@@ -92,8 +93,8 @@ class MarlinSerial { //: public Stream
|
92
|
93
|
int read(void);
|
93
|
94
|
void flush(void);
|
94
|
95
|
|
95
|
|
- FORCE_INLINE int available(void) {
|
96
|
|
- return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE;
|
|
96
|
+ FORCE_INLINE uint8_t available(void) {
|
|
97
|
+ return (uint8_t)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE;
|
97
|
98
|
}
|
98
|
99
|
|
99
|
100
|
FORCE_INLINE void write(uint8_t c) {
|
|
@@ -105,7 +106,7 @@ class MarlinSerial { //: public Stream
|
105
|
106
|
FORCE_INLINE void checkRx(void) {
|
106
|
107
|
if (TEST(M_UCSRxA, M_RXCx)) {
|
107
|
108
|
unsigned char c = M_UDRx;
|
108
|
|
- int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
|
|
109
|
+ uint8_t i = (uint8_t)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
|
109
|
110
|
|
110
|
111
|
// if we should be storing the received character into the location
|
111
|
112
|
// just before the tail (meaning that the head would advance to the
|