ARM: split out spi-avr.c from spi.c

This commit is contained in:
Nico Tonnhofer 2016-09-17 21:23:47 +02:00
parent d9a350749d
commit 7223c9dea8
2 changed files with 43 additions and 28 deletions

36
spi-avr.c Normal file
View File

@ -0,0 +1,36 @@
/** \file
\brief SPI routines, AVR specific part.
*/
#if defined TEACUP_C_INCLUDE && defined __AVR__
/** Initialise SPI subsystem.
Code copied from ATmega164/324/644/1284 data sheet, section 18.2, page 160,
or moved here from mendel.c.
*/
void spi_init() {
// Set SCK (clock) and MOSI line to output, ie. set USART in master mode.
SET_OUTPUT(SCK);
SET_OUTPUT(MOSI);
SET_INPUT(MISO);
// SS must be set as output to disconnect it from the SPI subsystem.
// Too bad if something else tries to use this pin as digital input.
// See ATmega164/324/644/1284 data sheet, section 18.3.2, page 162.
// Not written there: this must apparently be done before setting the SPRC
// register, else future R/W-operations may hang.
SET_OUTPUT(SS);
#ifdef SPI_2X
SPSR = 0x01;
#else
SPSR = 0x00;
#endif
// This sets the whole SPRC register.
spi_speed_100_400();
}
#endif /* defined TEACUP_C_INCLUDE && defined __AVR__ */

35
spi.c
View File

@ -1,4 +1,3 @@
/** \file /** \file
\brief SPI subsystem \brief SPI subsystem
@ -11,36 +10,16 @@
happens before reading and writing, data exchange its self is the same for happens before reading and writing, data exchange its self is the same for
each device, then. each device, then.
*/ */
#include "spi.h" #include "spi.h"
#ifdef SPI #ifdef SPI
/** Initialise SPI subsystem. #define TEACUP_C_INCLUDE
#include "spi-avr.c"
Code copied from ATmega164/324/644/1284 data sheet, section 18.2, page 160, // Each ARM needs it's own file
or moved here from mendel.c. // #include "spi-lpc.c"
*/ // #include "spi-stm32.c"
void spi_init() { #undef TEACUP_C_INCLUDE
// Set SCK (clock) and MOSI line to output, ie. set USART in master mode.
SET_OUTPUT(SCK);
SET_OUTPUT(MOSI);
SET_INPUT(MISO);
// SS must be set as output to disconnect it from the SPI subsystem.
// Too bad if something else tries to use this pin as digital input.
// See ATmega164/324/644/1284 data sheet, section 18.3.2, page 162.
// Not written there: this must apparently be done before setting the SPRC
// register, else future R/W-operations may hang.
SET_OUTPUT(SS);
#ifdef SPI_2X
SPSR = 0x01;
#else
SPSR = 0x00;
#endif
// This sets the whole SPRC register.
spi_speed_100_400();
}
#endif /* SPI */ #endif /* SPI */