Skip to content

Commit

Permalink
Merge pull request #596 from Paciente8159/serial-multistream-guard-op…
Browse files Browse the repository at this point in the history
…tion

added multistream parallel access guard option
  • Loading branch information
Paciente8159 committed Jan 22, 2024
2 parents eb99e92 + 26781a9 commit 3b6b1b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
26 changes: 23 additions & 3 deletions uCNC/src/interface/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,26 @@ void stream_stdin(uint8_t *p)
}
#endif

void serial_stream_change(serial_stream_t *stream)
#ifdef ENABLE_MULTISTREAM_GUARD
static bool serial_rx_busy;
#endif

bool serial_stream_change(serial_stream_t *stream)
{
#ifndef DISABLE_MULTISTREAM_SERIAL
uint8_t cleanup __attribute__((__cleanup__(stream_stdin))) = 0;

#ifdef ENABLE_MULTISTREAM_GUARD
if (serial_rx_busy)
{
return false;
}
#endif
serial_peek_buffer = 0;
if (stream != NULL)
{
current_stream = stream;
return;
return true;
}

// starts by the prioritary and test one by one until one that as characters available is found
Expand All @@ -130,6 +141,7 @@ void serial_stream_change(serial_stream_t *stream)
stream_available = mcu_available;
stream_clear = mcu_clear;
#endif
return true;
}

void serial_stream_readonly(stream_getc_cb getc_cb, stream_available_cb available_cb, stream_clear_cb clear_cb)
Expand All @@ -156,6 +168,9 @@ void serial_stream_eeprom(uint16_t address)
char serial_getc(void)
{
uint8_t peek = serial_peek();
#ifdef ENABLE_MULTISTREAM_GUARD
serial_rx_busy = (peek != EOL);
#endif
serial_peek_buffer = 0;
return peek;
}
Expand Down Expand Up @@ -217,6 +232,12 @@ uint8_t serial_available(void)
uint8_t count = stream_available();
if (!count)
{
#ifdef ENABLE_MULTISTREAM_GUARD
if (serial_rx_busy)
{
return count;
}
#endif
serial_stream_t *p = default_stream;
while (p != NULL)
{
Expand All @@ -237,7 +258,6 @@ uint8_t serial_available(void)
p = p->next;
}
}

return count;
#else
return stream_available();
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/interface/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extern "C"
void serial_init();

void serial_stream_register(serial_stream_t *stream);
void serial_stream_change(serial_stream_t *stream);
bool serial_stream_change(serial_stream_t *stream);
void serial_stream_readonly(stream_getc_cb getc_cb, stream_available_cb available_cb, stream_clear_cb clear_cb);
void serial_stream_eeprom(uint16_t address);

Expand Down

0 comments on commit 3b6b1b8

Please sign in to comment.