From: Keith Packard Date: Tue, 11 Oct 2011 22:03:04 +0000 (-0600) Subject: altos/avr: SPI mutex is now held by the caller, not the SPI driver X-Git-Tag: 1.0.9.3~13 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=06b044629951b06c7ec9b0105b89f51b2880ebd0 altos/avr: SPI mutex is now held by the caller, not the SPI driver SPI transactions generally require a read followed by a write, with the chip select held the whole time. As a result, the SPI bus must be held across multiple transactions. To make this reliable, the caller must hold the SPI mutex, instead of the underlying SPI driver. Signed-off-by: Keith Packard --- diff --git a/src/avr/ao_spi_usart.c b/src/avr/ao_spi_usart.c index 6ed708ff..1996fcd9 100644 --- a/src/avr/ao_spi_usart.c +++ b/src/avr/ao_spi_usart.c @@ -33,14 +33,12 @@ ao_spi_send(void __xdata *block, uint16_t len) __reentrant { uint8_t *d = block; - ao_mutex_get(&ao_spi_mutex); while (len--) { while (!(UCSR1A & (1 << UDRE1))); UDR1 = *d++; while (!(UCSR1A & (1 << RXC1))); (void) UDR1; } - ao_mutex_put(&ao_spi_mutex); } /* Receive bytes over SPI. @@ -54,14 +52,12 @@ ao_spi_recv(void __xdata *block, uint16_t len) __reentrant { uint8_t *d = block; - ao_mutex_get(&ao_spi_mutex); while (len--) { while (!(UCSR1A & (1 << UDRE1))); UDR1 = 0; while (!(UCSR1A & (1 << RXC1))); *d++ = UDR1; } - ao_mutex_put(&ao_spi_mutex); } /*