UART write loop could lead to wdt with low bitrates or large buffers by dok-net · Pull Request #7799 · esp8266/Arduino (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation7 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

dok-net

EspSoftwareSerial successfully uses optimistic_yield for the same purpose already.
Fixes #7746

@dok-net

d-a-v

Choose a reason for hiding this comment

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

LGTM !

earlephilhower

Choose a reason for hiding this comment

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

Just worried about yield() in the UART code. Need to be very sure it's safe and not used by SYS to log/etc...

uart_do_write_char(uart_nr, pgm_read_byte(buf++));
optimistic_yield(10000UL);

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...

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:

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.

devyte

uart_do_write_char(uart_nr, pgm_read_byte(buf++));
optimistic_yield(10000UL);

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:

devyte

Choose a reason for hiding this comment

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

Oops, when I took a look before I saw ms. You're right, it's us. Maybe I need glasses...
One yield every 10ms should be ok. It might be worth testing if there's a difference vs 1ms before merging, but I don't see that as a stopper.

Approving.

earlephilhower

Choose a reason for hiding this comment

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

Fair enough, thanks for the clarification. LGTM!