Skip to content

Commit

Permalink
Test if RX-buffer is full
Browse files Browse the repository at this point in the history
  • Loading branch information
AnHardt committed Jan 27, 2016
1 parent 62bad1b commit 700c3d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Marlin/MarlinSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
ring_buffer rx_buffer = { { 0 }, 0, 0 };
#endif

bool ser_chars_rejected = false;

FORCE_INLINE void store_char(unsigned char c) {
int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;

Expand All @@ -42,6 +44,10 @@ FORCE_INLINE void store_char(unsigned char c) {
if (i != rx_buffer.tail) {
rx_buffer.buffer[rx_buffer.head] = c;
rx_buffer.head = i;
}
else
{
ser_chars_rejected = true;
}
}

Expand Down
2 changes: 2 additions & 0 deletions Marlin/MarlinSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ struct ring_buffer {
int tail;
};

extern bool ser_chars_rejected;

#if UART_PRESENT(SERIAL_PORT)
extern ring_buffer rx_buffer;
#endif
Expand Down
7 changes: 7 additions & 0 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,13 @@ void setup() {
* - Call LCD update
*/
void loop() {
if ( ser_chars_rejected ) {
SERIAL_ERROR_START;
SERIAL_ECHOLNPGM("Serial: incoming chars rejected - ring buffer full");
//kill(PSTR("ERR: ring buffer full"));
ser_chars_rejected = false;
}

if (commands_in_queue < BUFSIZE - 1) get_command();

#if ENABLED(SDSUPPORT)
Expand Down

0 comments on commit 700c3d6

Please sign in to comment.