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 <keithp@keithp.com>
{
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.
{
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);
}
/*