Fixing arithmetic underflow in SPI I/O loops https://github.com/raspberrypi/pico-sdk/issues/337 (#338)

Co-authored-by: Michael Stoops <spam@michaelstoops.com>
This commit is contained in:
Michael Stoops 2021-04-13 15:06:14 -07:00 committed by GitHub
parent 9c3538e8b0
commit 127543a425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,7 +76,7 @@ int __not_in_flash_func(spi_write_read_blocking)(spi_inst_t *spi, const uint8_t
size_t rx_remaining = len, tx_remaining = len; size_t rx_remaining = len, tx_remaining = len;
while (rx_remaining || tx_remaining) { while (rx_remaining || tx_remaining) {
if (tx_remaining && spi_is_writable(spi) && rx_remaining - tx_remaining < fifo_depth) { if (tx_remaining && spi_is_writable(spi) && rx_remaining < tx_remaining + fifo_depth) {
spi_get_hw(spi)->dr = (uint32_t) *src++; spi_get_hw(spi)->dr = (uint32_t) *src++;
--tx_remaining; --tx_remaining;
} }
@ -125,7 +125,7 @@ int __not_in_flash_func(spi_read_blocking)(spi_inst_t *spi, uint8_t repeated_tx_
size_t rx_remaining = len, tx_remaining = len; size_t rx_remaining = len, tx_remaining = len;
while (rx_remaining || tx_remaining) { while (rx_remaining || tx_remaining) {
if (tx_remaining && spi_is_writable(spi) && rx_remaining - tx_remaining < fifo_depth) { if (tx_remaining && spi_is_writable(spi) && rx_remaining < tx_remaining + fifo_depth) {
spi_get_hw(spi)->dr = (uint32_t) repeated_tx_data; spi_get_hw(spi)->dr = (uint32_t) repeated_tx_data;
--tx_remaining; --tx_remaining;
} }
@ -147,7 +147,7 @@ int __not_in_flash_func(spi_write16_read16_blocking)(spi_inst_t *spi, const uint
size_t rx_remaining = len, tx_remaining = len; size_t rx_remaining = len, tx_remaining = len;
while (rx_remaining || tx_remaining) { while (rx_remaining || tx_remaining) {
if (tx_remaining && spi_is_writable(spi) && rx_remaining - tx_remaining < fifo_depth) { if (tx_remaining && spi_is_writable(spi) && rx_remaining < tx_remaining + fifo_depth) {
spi_get_hw(spi)->dr = (uint32_t) *src++; spi_get_hw(spi)->dr = (uint32_t) *src++;
--tx_remaining; --tx_remaining;
} }
@ -192,7 +192,7 @@ int __not_in_flash_func(spi_read16_blocking)(spi_inst_t *spi, uint16_t repeated_
size_t rx_remaining = len, tx_remaining = len; size_t rx_remaining = len, tx_remaining = len;
while (rx_remaining || tx_remaining) { while (rx_remaining || tx_remaining) {
if (tx_remaining && spi_is_writable(spi) && rx_remaining - tx_remaining < fifo_depth) { if (tx_remaining && spi_is_writable(spi) && rx_remaining < tx_remaining + fifo_depth) {
spi_get_hw(spi)->dr = (uint32_t) repeated_tx_data; spi_get_hw(spi)->dr = (uint32_t) repeated_tx_data;
--tx_remaining; --tx_remaining;
} }