Merge remote-tracking branch 'mjb/altosdroid'
[fw/altos] / src / avr / ao_spi_slave.c
index b742d29aa6de10b73bb6d1ce8e60f756c0d7fc3f..15e9924da5d6f20c4b1b454a3393d3fea9d23c31 100644 (file)
 #include "ao.h"
 
 uint8_t
-ao_spi_slave_recv(uint8_t *buf, uint8_t len)
+ao_spi_slave_recv(void *buf, uint16_t len)
 {
+       uint8_t *b = buf;
        while (len--) {
                while (!(SPSR & (1 << SPIF)))
                        if ((PINB & (1 << PINB0)))
                                return 0;
-               *buf++ = SPDR;
+               *b++ = SPDR;
        }
        return 1;
 }
 
 void
-ao_spi_slave_send(uint8_t *buf, uint8_t len)
+ao_spi_slave_send(void *buf, uint16_t len)
 {
+       uint8_t *b = buf;
        while (len--) {
-               SPDR = *buf++;
+               SPDR = *b++;
                while (!(SPSR & (1 << SPIF)))
                        if ((PINB & (1 << PINB0)))
                                return;
@@ -44,9 +46,8 @@ ao_spi_slave_send(uint8_t *buf, uint8_t len)
 
 static uint8_t ao_spi_slave_running;
 
-ISR(PCINT0_vect)
+ISR(PCINT0_vect, ISR_BLOCK)
 {
-       cli();
 #if SPI_SLAVE_PIN_0_3
        if ((PINB & (1 << PORTB0)) == 0)
 #endif
@@ -61,7 +62,6 @@ ISR(PCINT0_vect)
        } else {
                ao_spi_slave_running = 0;
        }
-       sei();
 }
 
 void