UBNanosatLab / lfr-firmware

Little Free Radio Firmware
https://lfradio.space
GNU General Public License v3.0
16 stars 1 forks source link

Fix I2C blocking send #33

Closed iracigt closed 4 years ago

iracigt commented 4 years ago

This addresses a bug visible as a sudden frequency shift while transmitting. A bug in the blocking behavior of i2c_write corrupts the I2C transaction to the DAC such that the VCTCXO VCTL is adjusted, skewing the transmit frequency. The issue stems from using the byte count as an indication of bytes sent, when in fact this is off by one. This sets up a race condition where future I2C transactions may be started before the current one completes. Adding an explicit TX done flag, set when the stop condition is asserted, resolves this issue. Note that the entry to i2c_write checks that the stop condition has finished, preventing another race.