mathertel / DmxSerial2

An Arduino library for sending and receiving DMX RDM packets.
BSD 3-Clause "New" or "Revised" License
99 stars 30 forks source link

noDataSince: Prevent loading partially updated value #25

Closed dojoe closed 4 years ago

dojoe commented 5 years ago

Since _gotLastPacket is a multi-byte value, the process of loading it into registers may be interrupted by a UART interrupt, which may change the value of _gotLastPacket. If this happens, the value returned by noDataSince() will be effectively random and may incorrectly trigger timeouts.

Fix this by disabling interrupts around the load, making it atomic.

This is not just a theoretical problem - I actually hit this pretty often with a DMX transmitter that sends very small packets in very quick succession.

mathertel commented 4 years ago

I never had this. Seams to have no negative effect.

mathertel commented 4 years ago

Thanks for the contribution !