@@ -132,10 +132,12 @@ void UART::on_rx() {
132
132
return ;
133
133
}
134
134
#endif
135
- while (_serial->obj ->readable ()) {
135
+ while (_serial->obj ->readable () && rx_buffer. availableForStore () ) {
136
136
char c;
137
+ core_util_critical_section_enter ();
137
138
_serial->obj ->read (&c, 1 );
138
139
rx_buffer.store_char (c);
140
+ core_util_critical_section_exit ();
139
141
}
140
142
}
141
143
@@ -160,7 +162,10 @@ int UART::available() {
160
162
return _SerialUSB.available ();
161
163
}
162
164
#endif
163
- return rx_buffer.available ();
165
+ core_util_critical_section_enter ();
166
+ int c = rx_buffer.available ();
167
+ core_util_critical_section_exit ();
168
+ return c;
164
169
}
165
170
166
171
int UART::peek () {
@@ -169,7 +174,10 @@ int UART::peek() {
169
174
return _SerialUSB.peek ();
170
175
}
171
176
#endif
172
- return rx_buffer.peek ();
177
+ core_util_critical_section_enter ();
178
+ int c = rx_buffer.peek ();
179
+ core_util_critical_section_exit ();
180
+ return c;
173
181
}
174
182
175
183
int UART::read () {
@@ -178,7 +186,10 @@ int UART::read() {
178
186
return _SerialUSB.read ();
179
187
}
180
188
#endif
181
- return rx_buffer.read_char ();
189
+ core_util_critical_section_enter ();
190
+ int c = rx_buffer.read_char ();
191
+ core_util_critical_section_exit ();
192
+ return c;
182
193
}
183
194
184
195
void UART::flush () {
0 commit comments