diff --git a/atusb/fw/mac.c b/atusb/fw/mac.c index d4fd366..d87a063 100644 --- a/atusb/fw/mac.c +++ b/atusb/fw/mac.c @@ -113,7 +113,7 @@ static void rx_done(void *user) static void receive_frame(void) { - uint8_t size, i; + uint8_t size; uint8_t *buf; spi_begin(); @@ -128,8 +128,7 @@ static void receive_frame(void) } buf = rx_buf[rx_in]; - for (i = 0; i != size+1; i++) - buf[i+1] = spi_recv(); + spi_recv_block(buf+1, size+1); spi_end(); buf[0] = size; diff --git a/atusb/fw/spi.c b/atusb/fw/spi.c index 91a2de9..ded5673 100644 --- a/atusb/fw/spi.c +++ b/atusb/fw/spi.c @@ -47,6 +47,21 @@ void spi_end(void) } +void spi_recv_block(uint8_t *buf, uint8_t n) +{ + if (!n) + return; + UDR1 = 0; + while (--n) { + while (!(UCSR1A & 1 << RXC1)); + *buf++ = UDR1; + UDR1 = 0; + } + while (!(UCSR1A & 1 << RXC1)); + *buf++ = UDR1; +} + + void spi_off(void) { spi_initialized = 0; diff --git a/atusb/fw/spi.h b/atusb/fw/spi.h index ff9d005..6e04f4e 100644 --- a/atusb/fw/spi.h +++ b/atusb/fw/spi.h @@ -1,8 +1,8 @@ /* * fw/spi.h - ATmega8 family SPI I/O * - * Written 2011 by Werner Almesberger - * Copyright 2011 Werner Almesberger + * Written 2011, 2013 by Werner Almesberger + * Copyright 2011, 2013 Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,4 +25,6 @@ void spi_init(void); #define spi_send(v) (void) spi_io(v) #define spi_recv(v) spi_io(0) +void spi_recv_block(uint8_t *buf, uint8_t n); + #endif /* !SPI_H */