diff options
author | Karel Kočí <cynerd@email.cz> | 2015-10-17 15:40:51 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2015-10-17 15:40:51 +0200 |
commit | b0d8f22f3492fbb3f6dc0e8026e63c803af59007 (patch) | |
tree | eb9707612e87856962474885f2a18ae1621d214e /src/spi.c | |
parent | 8fa9db4244f4ee33aa47561c569edfa62fe37928 (diff) | |
download | avr-ioe-b0d8f22f3492fbb3f6dc0e8026e63c803af59007.tar.gz avr-ioe-b0d8f22f3492fbb3f6dc0e8026e63c803af59007.tar.bz2 avr-ioe-b0d8f22f3492fbb3f6dc0e8026e63c803af59007.zip |
Complete commit of current work
Diffstat (limited to 'src/spi.c')
-rw-r--r-- | src/spi.c | 59 |
1 files changed, 14 insertions, 45 deletions
@@ -1,54 +1,23 @@ -#include "../spi.h" +#ifdef CONFIG_IOE_SPI +#ifdef MCUSUPPORT_USART volatile int8_t _spi_busy; -inline void spi_init(enum spiMode mode) { - _spi_busy = 0; - if (mode == SPI_MODE_MASTER) { - // Set MOSI and SCK output - DDR_SPI |= _BV(DD_MOSI) | _BV(DD_SCLK); - // Set MISO pull up resistor - PORT_SPI |= _BV(PORT_MISO); - // Enable SPI master, set clock rate fck/16 and enable SPI interrupt - SPCR = _BV(SPE) | _BV(SPIE) | _BV(MSTR) | _BV(SPR0); - } else { - // Set MISO as output - DDR_SPI |= _BV(DD_MISO); - // Set SCLK and MOSI pull up resistor - PORT_SPI |= _BV(PORT_SCLK) | _BV(PORT_MOSI); - // Enable SPI and interrupt - SPCR = _BV(SPE) | _BV(SPIE); - } -} - -inline int8_t spi_busy(void) { - return _spi_busy; -} - -inline void spi_join(void) { - while (spi_busy()); -} - -inline uint8_t spi_send(uint8_t data) { - spi_transfer(data); - while (spi_busy()); - return SPDR; -} - -inline void spi_transfer(uint8_t data) { - _spi_busy = 1; - SPDR = data; -} - -inline void spi_expose(uint8_t data) { - SPDR = data; -} - ////// Interrupts //////////////////////////////// -void (*spi_receive)(uint8_t data) = 0; +void (*spi_receive) (uint8_t data) = 0; + +#ifdef CONFIG_IOE_CAN_MCP2515 +extern void can_mcp2515_spi_hook(uint8_t); +#endif /* CONFIG_IOE_CAN_MCP2515 */ -SIGNAL(SPI_STC_vect) { +ISR(SPI_STC_vect, ISR_BLOCK) { _spi_busy = 0; +#ifdef CONFIG_IOE_CAN_MCP2515 + can_mcp2515_spi_hook(SPDR); +#endif /* CONFIG_IOE_CAN_MCP2515 */ if (spi_receive) spi_receive(SPDR); } + +#endif /* MCUSUPPORT_SPI */ +#endif /* CONFIG_IOE_SPI */ |