X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Favr%2Fao_spi_slave.c;h=15e9924da5d6f20c4b1b454a3393d3fea9d23c31;hb=0ff5f0fbc4900ad45bb7910ffc0c5a4e4cc4b857;hp=76f574c6480f6ac1012f9a43295d1c75fa4a765b;hpb=128bbfa150f88c09f7adde2434b7bf0b5a9ed556;p=fw%2Faltos diff --git a/src/avr/ao_spi_slave.c b/src/avr/ao_spi_slave.c index 76f574c6..15e9924d 100644 --- a/src/avr/ao_spi_slave.c +++ b/src/avr/ao_spi_slave.c @@ -18,22 +18,24 @@ #include "ao.h" uint8_t -ao_spi_read(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_write(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_write(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 @@ -87,7 +87,7 @@ ao_spi_slave_init(void) (1 << 3) | /* MISO, output */ (0 << 2) | /* MOSI, no pull-up */ (0 << 1) | /* SCK, no pull-up */ - (0 << 0)); /* SS, no pull-up */ + (1 << 0)); /* SS, pull-up */ #endif #if SPI_SLAVE_PIN_2_5 PCMSK0 |= (1 << PCINT2); /* Enable PCINT2 pin change */ @@ -103,7 +103,7 @@ ao_spi_slave_init(void) (0 << 5) | /* SCK, no pull-up */ (1 << 4) | /* MISO, output */ (0 << 3) | /* MOSI, no pull-up */ - (0 << 2)); /* SS, no pull-up */ + (1 << 2)); /* SS, pull-up */ #endif SPCR = (0 << SPIE) | /* Disable SPI interrupts */