TasmotaSerial: Reduce IRAM usage by 280 bytes and improve reliability at 115200 bauds (v2) #6377
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Second try, replaces #6373, 9600 baud tested by @Jason2866 (thanks a lot)
Improvements to TasmotaSerial
attachInterruptArg()
from STAGE and pre-2.6, removes the need for multiple interrupt functions, saves 224 bytes of IRAMm_bit_start_time
time for first byte, instead of computing it in the interrupt handleroptimistic_yield(1)
from the interrupt handler,optimistic_yield
is not in IRAM, I'm not sure it's safe to call it from the interrupt handler. Anyways, low baud (9600) should use thenw
option.while (ESP.getCycleCount()-start < wait)
towhile (ESP.getCycleCount() < wait + start)
, the addition gets out of the loop (minor change)digitalWrite(m_tx_pin, HIGH);
, if the output is not already in HIGH mode then it's too late to change it (Am I missing something?)I did lots of tests with Zigbee and discovered that sometimes bytes were misread. What happens is that when receiving a row of bytes, interrupts are disabled for each byte, re-enabled after stop bit and disables again for next byte. This short window would allow other interrupts to fire and delay enough the Serial interrupt that the first bit would be missed.
I changed so that the interrupt handler wait for 3.5 stop bits if the next message is already there. If so it continues to read it without lifting interrupts, if not it re-enables interrupts.
Overall I saw a huge improvement in reliability when receiving at 115200.
Overall IRAM saving: 280 bytes
Theo, I didn't change the TasmotaSerial verion number.
I hope I did not change the behavior at lower baud rate, this might need some more testing.
Checklist: