From e028b462ae78a400a3df396077d0abc16fb429a2 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 17 Apr 2009 00:25:00 +0200 Subject: * digital/avr/modules/spi: - some cleanup. --- digital/avr/modules/flash/Makefile | 5 --- digital/avr/modules/spi/Makefile | 5 --- digital/avr/modules/spi/Makefile.module | 0 digital/avr/modules/spi/spi.avr.c | 63 +++++++++----------------------- digital/avr/modules/spi/spi.h | 31 +++------------- digital/avr/modules/spi/test/Makefile | 0 digital/avr/modules/spi/test/avrconfig.h | 2 +- digital/avr/modules/spi/test/test_spi.c | 11 +----- 8 files changed, 26 insertions(+), 91 deletions(-) delete mode 100644 digital/avr/modules/flash/Makefile delete mode 100755 digital/avr/modules/spi/Makefile mode change 100755 => 100644 digital/avr/modules/spi/Makefile.module mode change 100755 => 100644 digital/avr/modules/spi/test/Makefile diff --git a/digital/avr/modules/flash/Makefile b/digital/avr/modules/flash/Makefile deleted file mode 100644 index fa689635..00000000 --- a/digital/avr/modules/flash/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -BASE = ../.. -DOC = spi.html -EXTRACTDOC = spi.h spi.c - -include $(BASE)/make/Makefile.gen diff --git a/digital/avr/modules/spi/Makefile b/digital/avr/modules/spi/Makefile deleted file mode 100755 index 9068899d..00000000 --- a/digital/avr/modules/spi/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -BASE = ../.. -DOC = spi.html -EXTRACTDOC = spi.h spi.avr.c - -include $(BASE)/make/Makefile.gen diff --git a/digital/avr/modules/spi/Makefile.module b/digital/avr/modules/spi/Makefile.module old mode 100755 new mode 100644 diff --git a/digital/avr/modules/spi/spi.avr.c b/digital/avr/modules/spi/spi.avr.c index 581756f1..0ffee4de 100644 --- a/digital/avr/modules/spi/spi.avr.c +++ b/digital/avr/modules/spi/spi.avr.c @@ -1,5 +1,5 @@ /* spi.avr.c */ -/* {{{ +/* avr.spi - SPI AVR module. {{{ * * Copyright (C) 2008 Nélio Laranjeiro * @@ -22,31 +22,20 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * }}} */ -#include "io.h" #include "common.h" -#include "spi.h" -/** For host */ -#ifdef HOST -static uint8_t SPCR; -static uint8_t SPDR; -static uint8_t SPSR; -static uint8_t SPIF; -#endif +#include "io.h" -/** Spi driver context. */ -static spi_t spi_global; +#include "spi.h" /** Initialise the SPI Control Register. - * \param sprc the sprc register data to be store in the register. - * \param cb the function call back to call the user which receive the data. - * \param user_data the user data to be provieded in the function call back. + * \param spcr the spcr register data to be store in the register. */ void -spi_init(uint8_t sprc) +spi_init (uint8_t spcr) { /* Master configuration. */ - if (sprc & _BV(MSTR)) + if (spcr & _BV(MSTR)) { SPI_PORT |= _BV(SPI_BIT_SS); SPI_DDR |= _BV(SPI_BIT_SS); @@ -75,55 +64,39 @@ spi_init(uint8_t sprc) SPI_PORT &= ~_BV(SPI_BIT_SCK); } - SPCR = sprc; - spi_global.interruption = SPCR & _BV(SPIE); + SPCR = spcr; } /** Send a data to the Slave. * \param data the data to send */ void -spi_send(uint8_t data) +spi_send (uint8_t data) { - SPDR = data; - // Wait the end of the transmission. - while(!(SPSR & _BV(SPIF))); + spi_send_and_recv (data); } /** Receive a data from the SPI bus. * \return the data received from the bus. */ uint8_t -spi_recv(void) +spi_recv (void) { - SPDR = 0; - /* Wait for reception complete */ - while(!(SPSR & _BV(SPIF))); - - /* Return data register */ - return SPDR; + return spi_send_and_recv (0); } /** Send and receive data. - * \param data the data to send. - * \return the data received. - */ + * \param data the data to send. + * \return the data received. + */ uint8_t spi_send_and_recv (uint8_t data) { SPDR = data; - // Wait the end of the transmission. - while(!(SPSR & _BV(SPIF))); - + /* Wait the end of the transmission. */ + while (!(SPSR & _BV(SPIF))) + ; + /* Return data register. */ return SPDR; } -/** Return the status register from the SPI driver. - * \return the status register value - */ -uint8_t -spi_status(void) -{ - return SPSR; -} - diff --git a/digital/avr/modules/spi/spi.h b/digital/avr/modules/spi/spi.h index 9d43eec0..635debd6 100644 --- a/digital/avr/modules/spi/spi.h +++ b/digital/avr/modules/spi/spi.h @@ -1,7 +1,7 @@ #ifndef spi_h #define spi_h /* spi.h */ -/* {{{ +/* avr.spi - SPI AVR module. {{{ * * Copyright (C) 2008 Nélio Laranjeiro * @@ -67,38 +67,23 @@ enum spi_fosc_t SPI_FOSC_DIV32 }; -struct spi_t -{ - /** interruption status. */ - int8_t interruption; -}; -typedef struct spi_t spi_t; - /** Initialise the SPI Control Register. - * \param sprc the sprc register data to be store in the register. - * \param cb the function call back to call the user which receive the data. - * \param user_data the user data to be provieded in the function call back. + * \param spcr the spcr register data to be store in the register. */ void -spi_init(uint8_t sprc); - -/** Uninitialise the SPI module. - * Unused on the target - */ -void -spi_uninit (void); +spi_init (uint8_t spcr); /** Send a data to the Slave. * \param data the data to send */ void -spi_send(uint8_t data); +spi_send (uint8_t data); /** Receive a data from the SPI bus. * \return the data received from the bus. */ uint8_t -spi_recv(void); +spi_recv (void); /** Send and receive data. * \param data the data to send. @@ -107,10 +92,4 @@ spi_recv(void); uint8_t spi_send_and_recv (uint8_t data); -/** Return the status register from the SPI driver. - * \return the status register value - */ -uint8_t -spi_status(void); - #endif /* spi_h */ diff --git a/digital/avr/modules/spi/test/Makefile b/digital/avr/modules/spi/test/Makefile old mode 100755 new mode 100644 diff --git a/digital/avr/modules/spi/test/avrconfig.h b/digital/avr/modules/spi/test/avrconfig.h index ac0b3b3a..19eec3cf 100644 --- a/digital/avr/modules/spi/test/avrconfig.h +++ b/digital/avr/modules/spi/test/avrconfig.h @@ -32,7 +32,7 @@ /* uart - UART module. */ /** Select hardware uart for primary uart: 0, 1 or -1 to disable. */ -#define AC_UART0_PORT 0 +#define AC_UART0_PORT 1 /** Baudrate: 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800, * 115200, 230400, 250000, 500000, 1000000. */ #define AC_UART0_BAUDRATE 115200 diff --git a/digital/avr/modules/spi/test/test_spi.c b/digital/avr/modules/spi/test/test_spi.c index a17e6271..951dfb41 100644 --- a/digital/avr/modules/spi/test/test_spi.c +++ b/digital/avr/modules/spi/test/test_spi.c @@ -22,18 +22,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * }}} */ -#include -#include +#include "common.h" #include "modules/proto/proto.h" +#include "modules/spi/spi.h" #include "io.h" -#include "../spi.h" - -/** Call back function to be called on the AVR interruption */ -void -spi_interruption_function (void *user_data, uint8_t data) -{ -} void proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) -- cgit v1.2.3