Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UART write loop could lead to wdt with low bitrates or large buffers #7799

Merged
merged 1 commit into from
Dec 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cores/esp8266/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,10 @@ uart_write(uart_t* uart, const char* buf, size_t size)

size_t ret = size;
const int uart_nr = uart->uart_nr;
while (size--)
while (size--) {
uart_do_write_char(uart_nr, pgm_read_byte(buf++));
optimistic_yield(10000UL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AIUI, optimistic_yield will panic() if not in the CONT context. This would make any SYS-callback printouts (TCP, others) potentially crash.

@devyte, @d-a-v, any comments/ideas? I like the idea, but the forced panic seems worse than a potential WDT...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimistic_yield() checks if it can yield (i. e. in CONT), and if enough time has elapsed since the start of the current loop. If true, it yield()s, otherwise does nothing.

So it shouldn't panic.

However: I seem to remember there was a change to its behavior so that yield actually only happens once every blah ms instead of after blah ms since loop start.

In any case:

  • At a glance, I think the argument of 10000 is way too big, I would use something like 500, i. e. yield at most every 0.5s
  • this yield won't help in the case of slow comms attempted from SYS, but you could argue that comms should be done from CONT

Copy link
Collaborator

@d-a-v d-a-v Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit is µs so 10k is 10ms.
It should be fine.
Maybe 1ms is better to sustain high throughput in case of a network transfer.

edit all functions taking time as parameter should have the unit in their names, starting with delay() ... ah it's arduino API, we can't change it :) Our polled time structure have it though. We also could change optimistic_yield() as it is internal API.

}

return ret;
}
Expand Down