summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorNicolas Schodet2009-04-17 00:25:16 +0200
committerNicolas Schodet2009-04-17 00:25:16 +0200
commitbdd377580a0374cc2893d386eb0f47b802232ac9 (patch)
treeab540b91e372449e419f5b658f6be32d5e95af8e /digital
parente028b462ae78a400a3df396077d0abc16fb429a2 (diff)
* digital/avr/modules/spi:
- fixed bad SPI2X mode. - prepare for software driver.
Diffstat (limited to 'digital')
-rw-r--r--digital/asserv/src/asserv/avrconfig.h5
-rw-r--r--digital/asserv/src/asserv/pwm_mp.avr.c4
-rw-r--r--digital/avr/modules/flash/flash.c5
-rw-r--r--digital/avr/modules/flash/test/avrconfig.h6
-rw-r--r--digital/avr/modules/spi/Makefile.module2
-rw-r--r--digital/avr/modules/spi/avrconfig.h43
-rw-r--r--digital/avr/modules/spi/spi.avr.c102
-rw-r--r--digital/avr/modules/spi/spi.h124
-rw-r--r--digital/avr/modules/spi/spi_hard.avr.c109
-rw-r--r--digital/avr/modules/spi/spi_hard.h63
-rw-r--r--digital/avr/modules/spi/test/avrconfig.h6
-rw-r--r--digital/avr/modules/spi/test/test_spi.c78
-rw-r--r--digital/avr/modules/trace/test/test_target/avrconfig.h7
13 files changed, 340 insertions, 214 deletions
diff --git a/digital/asserv/src/asserv/avrconfig.h b/digital/asserv/src/asserv/avrconfig.h
index f95f74f8..c0403592 100644
--- a/digital/asserv/src/asserv/avrconfig.h
+++ b/digital/asserv/src/asserv/avrconfig.h
@@ -101,5 +101,10 @@
/** Slave send buffer size. */
#define AC_TWI_SL_SEND_BUFFER_SIZE 16
+/* spi - SPI module. */
+/** Select driver: HARD, SOFT, or NONE. */
+#define AC_SPI0_DRIVER HARD
+/** Same thing for an optionnal second SPI driver. */
+#define AC_SPI1_DRIVER NONE
#endif /* avrconfig_h */
diff --git a/digital/asserv/src/asserv/pwm_mp.avr.c b/digital/asserv/src/asserv/pwm_mp.avr.c
index 62ef2190..2349148a 100644
--- a/digital/asserv/src/asserv/pwm_mp.avr.c
+++ b/digital/asserv/src/asserv/pwm_mp.avr.c
@@ -52,8 +52,8 @@ pwm_mp_init (void)
DDRE |= _BV (4);
#endif
#if PWM1or2 || PWM3or4
- spi_init (SPI_IT_DISABLE | SPI_ENABLE | SPI_MSB_FIRST | SPI_MASTER |
- SPI_CPOL_FALLING | SPI_CPHA_SETUP | SPI_FOSC_DIV16);
+ spi_init (SPI_MASTER, SPI_CPOL_FALLING | SPI_CPHA_SETUP, SPI_MSB_FIRST,
+ SPI_FOSC_DIV16);
#endif
/* Reset PWM values at reset. */
pwm_mp_go = 1;
diff --git a/digital/avr/modules/flash/flash.c b/digital/avr/modules/flash/flash.c
index 96acb8ad..dffc6d82 100644
--- a/digital/avr/modules/flash/flash.c
+++ b/digital/avr/modules/flash/flash.c
@@ -105,9 +105,8 @@ flash_init (void)
AC_FLASH_DDR |= _BV(AC_FLASH_BIT_SS);
/* send the read-ID instruction. */
- spi_init (SPI_IT_DISABLE | SPI_ENABLE | SPI_MASTER | SPI_MSB_FIRST
- | SPI_MASTER | SPI_CPOL_FALLING | SPI_CPHA_SETUP
- | SPI_FOSC_DIV16);
+ spi_init (SPI_MASTER, SPI_CPOL_FALLING | SPI_CPHA_SETUP, SPI_MSB_FIRST,
+ SPI_FOSC_DIV16);
AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS);
spi_send (FLASH_READ_ID);
diff --git a/digital/avr/modules/flash/test/avrconfig.h b/digital/avr/modules/flash/test/avrconfig.h
index c4d9f159..0c80a8d2 100644
--- a/digital/avr/modules/flash/test/avrconfig.h
+++ b/digital/avr/modules/flash/test/avrconfig.h
@@ -83,6 +83,12 @@
/** Support for quote parameter. */
#define AC_PROTO_QUOTE 1
+/* spi - SPI module. */
+/** Select driver: HARD, SOFT, or NONE. */
+#define AC_SPI0_DRIVER HARD
+/** Same thing for an optionnal second SPI driver. */
+#define AC_SPI1_DRIVER NONE
+
/* flash - Flash SPI AVR module. */
/** Flash PORT used. */
#define AC_FLASH_PORT PORTD
diff --git a/digital/avr/modules/spi/Makefile.module b/digital/avr/modules/spi/Makefile.module
index 396ba9e3..eb5567ef 100644
--- a/digital/avr/modules/spi/Makefile.module
+++ b/digital/avr/modules/spi/Makefile.module
@@ -1 +1 @@
-spi_SOURCES = spi.avr.c
+spi_SOURCES = spi_hard.avr.c
diff --git a/digital/avr/modules/spi/avrconfig.h b/digital/avr/modules/spi/avrconfig.h
new file mode 100644
index 00000000..d11cc156
--- /dev/null
+++ b/digital/avr/modules/spi/avrconfig.h
@@ -0,0 +1,43 @@
+#ifndef avrconfig_h
+#define avrconfig_h
+/* avrconfig.h - SPI module configuration template. */
+/* avr.spi - SPI AVR module. {{{
+ *
+ * Copyright (C) 2009 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+/* spi - SPI module. */
+/** Select driver: HARD, SOFT, or NONE. */
+#define AC_SPI0_DRIVER HARD
+/** For software SPI, specify SCK IO port. */
+#define AC_SPI0_SOFT_SCK_IO D, 5
+/** For software SPI, specify MOSI IO port. */
+#define AC_SPI0_SOFT_MOSI_IO D, 7
+/** For software SPI, specify MISO IO port. */
+#define AC_SPI0_SOFT_MISO_IO D, 6
+/** Same thing for an optionnal second SPI driver. */
+#define AC_SPI1_DRIVER NONE
+#define AC_SPI1_SOFT_SCK_IO
+#define AC_SPI1_SOFT_MOSI_IO
+#define AC_SPI1_SOFT_MISO_IO
+
+#endif /* avrconfig_h */
diff --git a/digital/avr/modules/spi/spi.avr.c b/digital/avr/modules/spi/spi.avr.c
deleted file mode 100644
index 0ffee4de..00000000
--- a/digital/avr/modules/spi/spi.avr.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/* spi.avr.c */
-/* avr.spi - SPI AVR module. {{{
- *
- * Copyright (C) 2008 Nélio Laranjeiro
- *
- * APBTeam:
- * Web: http://apbteam.org/
- * Email: team AT apbteam DOT org
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * }}} */
-#include "common.h"
-
-#include "io.h"
-
-#include "spi.h"
-
-/** Initialise the SPI Control Register.
- * \param spcr the spcr register data to be store in the register.
- */
-void
-spi_init (uint8_t spcr)
-{
- /* Master configuration. */
- if (spcr & _BV(MSTR))
- {
- SPI_PORT |= _BV(SPI_BIT_SS);
- SPI_DDR |= _BV(SPI_BIT_SS);
-
- SPI_DDR &= ~_BV(SPI_BIT_MISO);
- SPI_PORT &= ~_BV(SPI_BIT_MISO);
-
- SPI_PORT |= _BV(SPI_BIT_MOSI);
- SPI_DDR |= _BV(SPI_BIT_MOSI);
-
- SPI_PORT |= _BV(SPI_BIT_SCK);
- SPI_DDR |= _BV(SPI_BIT_SCK);
- }
- else
- {
- SPI_DDR &= ~_BV(SPI_BIT_SS);
- SPI_PORT |= _BV(SPI_BIT_SS);
-
- SPI_PORT |= _BV(SPI_BIT_MISO);
- SPI_DDR |= _BV(SPI_BIT_MISO);
-
- SPI_DDR &= ~_BV(SPI_BIT_MOSI);
- SPI_PORT &= ~_BV(SPI_BIT_MOSI);
-
- SPI_DDR &= ~_BV(SPI_BIT_SCK);
- SPI_PORT &= ~_BV(SPI_BIT_SCK);
- }
-
- SPCR = spcr;
-}
-
-/** Send a data to the Slave.
- * \param data the data to send
- */
-void
-spi_send (uint8_t data)
-{
- spi_send_and_recv (data);
-}
-
-/** Receive a data from the SPI bus.
- * \return the data received from the bus.
- */
-uint8_t
-spi_recv (void)
-{
- return spi_send_and_recv (0);
-}
-
-/** Send and receive data.
- * \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)))
- ;
- /* Return data register. */
- return SPDR;
-}
-
diff --git a/digital/avr/modules/spi/spi.h b/digital/avr/modules/spi/spi.h
index 635debd6..0b0acf27 100644
--- a/digital/avr/modules/spi/spi.h
+++ b/digital/avr/modules/spi/spi.h
@@ -26,70 +26,78 @@
* }}} */
#include "io.h"
-#define SPI_DDR DDRB
-#define SPI_PORT PORTB
+/* Configuration constants are used for all drivers, even if values come from
+ * hardware driver. */
-#if defined (__AVR_ATmega128__)
-#define SPI_BIT_SS 0
-#define SPI_BIT_SCK 1
-#define SPI_BIT_MOSI 2
-#define SPI_BIT_MISO 3
-#elif defined (__AVR_ATmega16__)
-#define SPI_BIT_SS 4
-#define SPI_BIT_SCK 7
-#define SPI_BIT_MOSI 5
-#define SPI_BIT_MISO 6
-#else
-#error "Not implemented"
-#endif
+/** Operate as a slave. */
+#define SPI_SLAVE 0
+/** Operate as master. */
+#define SPI_MASTER _BV (MSTR)
-#define SPI_IT_ENABLE _BV(SPIE)
-#define SPI_IT_DISABLE 0x0
-#define SPI_ENABLE _BV(SPE)
-#define SPI_DISABLE 0x0
-#define SPI_MSB_FIRST 0x00
-#define SPI_LSB_FIRST _BV(DORD)
-#define SPI_MASTER _BV(MSTR)
-#define SPI_SLAVE 0x00
-#define SPI_CPOL_RISING 0x0
-#define SPI_CPOL_FALLING _BV(CPOL)
-#define SPI_CPHA_SAMPLE 0x0
-#define SPI_CPHA_SETUP _BV(CPHA)
+/** Output MSB first. */
+#define SPI_MSB_FIRST 0
+/** Output LSB first. */
+#define SPI_LSB_FIRST _BV (DORD)
-enum spi_fosc_t
-{
- SPI_FOSC_DIV4,
- SPI_FOSC_DIV16,
- SPI_FOSC_DIV64,
- SPI_FOSC_DIV128,
- SPI_FOSC_DIV2,
- SPI_FOSC_DIV8,
- SPI_FOSC_DIV32
-};
+/** Clock polarity: rising edge is the leading one, SCK is low when idle. */
+#define SPI_CPOL_RISING 0
+/** Clock polarity: falling edge is the leading one, SCK is high when idle. */
+#define SPI_CPOL_FALLING _BV (CPOL)
+/** Clock phase: sample on leading edge. */
+#define SPI_CPHA_SAMPLE 0
+/** Clock phase: setup on leading edge. */
+#define SPI_CPHA_SETUP _BV (CPHA)
-/** Initialise the SPI Control Register.
- * \param spcr the spcr register data to be store in the register.
- */
-void
-spi_init (uint8_t spcr);
+/** SPI mode 0, sample on rising edge, setup on falling edge. */
+#define SPI_MODE_0 (SPI_CPOL_RISING | SPI_CPHA_SAMPLE)
+/** SPI mode 1, setup on rising edge, sample on falling edge. */
+#define SPI_MODE_1 (SPI_CPOL_RISING | SPI_CPHA_SETUP)
+/** SPI mode 2, sample on falling edge, setup on rising edge. */
+#define SPI_MODE_2 (SPI_CPOL_FALLING | SPI_CPHA_SAMPLE)
+/** SPI mode 3, setup on falling edge, sample on rising edge. */
+#define SPI_MODE_3 (SPI_CPOL_FALLING | SPI_CPHA_SETUP)
+/** SPI mode mask. */
+#define SPI_MODE_MASK SPI_MODE_3
-/** Send a data to the Slave.
- * \param data the data to send
- */
-void
-spi_send (uint8_t data);
+/* Define selected drivers. */
+#define SPI_DRIVER_NONE '0'
+#define SPI_DRIVER_HARD 'h'
+#define SPI_DRIVER_SOFT 's'
+#define SPI_DRIVER__(drv) SPI_DRIVER_ ## drv
+#define SPI_DRIVER_(drv) SPI_DRIVER__ (drv)
+#define SPI0_DRIVER SPI_DRIVER_ (AC_SPI0_DRIVER)
+#define SPI1_DRIVER SPI_DRIVER_ (AC_SPI1_DRIVER)
-/** Receive a data from the SPI bus.
- * \return the data received from the bus.
- */
-uint8_t
-spi_recv (void);
+/* Include drivers header. */
+#if SPI0_DRIVER == SPI_DRIVER_HARD || SPI1_DRIVER == SPI_DRIVER_HARD
+# include "spi_hard.h"
+#endif
+#if SPI0_DRIVER == SPI_DRIVER_SOFT || SPI1_DRIVER == SPI_DRIVER_SOFT
+# error "spi: driver soft not supported yet"
+#endif
-/** Send and receive data.
- * \param data the data to send.
- * \return the data received.
- */
-uint8_t
-spi_send_and_recv (uint8_t data);
+/* Map names to drivers. */
+#if SPI0_DRIVER == SPI_DRIVER_HARD
+# define spi_init spi_hard_init
+# define spi_send spi_hard_send
+# define spi_recv spi_hard_recv
+# define spi_send_and_recv spi_hard_send_and_recv
+#elif SPI0_DRIVER == SPI_DRIVER_SOFT
+# define spi_init spi_soft_init
+# define spi_send spi_soft_send
+# define spi_recv spi_soft_recv
+# define spi_send_and_recv spi_soft_send_and_recv
+#endif
+#if SPI1_DRIVER == SPI_DRIVER_HARD
+# define spi1_init spi_hard_init
+# define spi1_send spi_hard_send
+# define spi1_recv spi_hard_recv
+# define spi1_send_and_recv spi_hard_send_and_recv
+#elif SPI1_DRIVER == SPI_DRIVER_SOFT
+# define spi1_init spi_soft_init
+# define spi1_send spi_soft_send
+# define spi1_recv spi_soft_recv
+# define spi1_send_and_recv spi_soft_send_and_recv
+#endif
#endif /* spi_h */
diff --git a/digital/avr/modules/spi/spi_hard.avr.c b/digital/avr/modules/spi/spi_hard.avr.c
new file mode 100644
index 00000000..15282dde
--- /dev/null
+++ b/digital/avr/modules/spi/spi_hard.avr.c
@@ -0,0 +1,109 @@
+/* spi_hard.avr.c - SPI driver using hardware implementation. */
+/* avr.spi - SPI AVR module. {{{
+ *
+ * Copyright (C) 2008 Nélio Laranjeiro
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include "common.h"
+
+#include "io.h"
+
+#include "spi.h"
+
+#if SPI0_DRIVER == SPI_DRIVER_HARD || SPI1_DRIVER == SPI_DRIVER_HARD
+
+#if defined (__AVR_ATmega128__) \
+ || defined (__AVR_ATmega64__) \
+ || defined (__AVR_AT90USB162__)
+# define SPI_SS_IO B, 0
+# define SPI_SCK_IO B, 1
+# define SPI_MOSI_IO B, 2
+# define SPI_MISO_IO B, 3
+#elif defined (__AVR_ATmega16__)
+# define SPI_SS_IO B, 4
+# define SPI_SCK_IO B, 7
+# define SPI_MOSI_IO B, 5
+# define SPI_MISO_IO B, 6
+#else
+# error "spi: not implemented on this chip"
+#endif
+
+void
+spi_hard_init_ (uint8_t spcr, uint8_t spi2x)
+{
+ if (spcr & SPI_MASTER)
+ {
+ /* Master configuration. */
+ /* SS must be output or SPI could switch to slave mode. */
+ IO_PORT (SPI_SS_IO) |= IO_BV (SPI_SS_IO);
+ IO_DDR (SPI_SS_IO) |= IO_BV (SPI_SS_IO);
+ IO_DDR (SPI_MISO_IO) &= ~IO_BV (SPI_MISO_IO);
+ IO_PORT (SPI_MISO_IO) &= ~IO_BV (SPI_MISO_IO);
+ IO_PORT (SPI_MOSI_IO) |= IO_BV (SPI_MOSI_IO);
+ IO_DDR (SPI_MOSI_IO) |= IO_BV (SPI_MOSI_IO);
+ IO_PORT (SPI_SCK_IO) |= IO_BV (SPI_SCK_IO);
+ IO_DDR (SPI_SCK_IO) |= IO_BV (SPI_SCK_IO);
+ }
+ else
+ {
+ /* Slave configuration, will set MISO later. */
+ IO_DDR (SPI_SS_IO) &= ~IO_BV (SPI_SS_IO);
+ IO_PORT (SPI_SS_IO) |= IO_BV (SPI_SS_IO);
+ IO_DDR (SPI_MOSI_IO) &= ~IO_BV (SPI_MOSI_IO);
+ IO_PORT (SPI_MOSI_IO) &= ~IO_BV (SPI_MOSI_IO);
+ IO_DDR (SPI_SCK_IO) &= ~IO_BV (SPI_SCK_IO);
+ IO_PORT (SPI_SCK_IO) &= ~IO_BV (SPI_SCK_IO);
+ }
+ SPCR = spcr | _BV (SPE);
+ SPSR = spi2x;
+ if (!(spcr & SPI_MASTER))
+ {
+ /* Slave configuration, set MISO now or else it will be an output for
+ * a short time until SPI is activate. */
+ IO_PORT (SPI_MISO_IO) |= IO_BV (SPI_MISO_IO);
+ IO_DDR (SPI_MISO_IO) |= IO_BV (SPI_MISO_IO);
+ }
+}
+
+void
+spi_hard_send (uint8_t data)
+{
+ spi_hard_send_and_recv (data);
+}
+
+uint8_t
+spi_hard_recv (void)
+{
+ return spi_hard_send_and_recv (0);
+}
+
+uint8_t
+spi_hard_send_and_recv (uint8_t data)
+{
+ SPDR = data;
+ /* Wait the end of the transmission. */
+ while (!(SPSR & _BV(SPIF)))
+ ;
+ /* Return data register. */
+ return SPDR;
+}
+
+#endif /* SPI0_DRIVER == SPI_DRIVER_HARD || SPI1_DRIVER == SPI_DRIVER_HARD */
diff --git a/digital/avr/modules/spi/spi_hard.h b/digital/avr/modules/spi/spi_hard.h
new file mode 100644
index 00000000..6e09f415
--- /dev/null
+++ b/digital/avr/modules/spi/spi_hard.h
@@ -0,0 +1,63 @@
+#ifndef spi_hard_h
+#define spi_hard_h
+/* spi_hard.h */
+/* avr.spi - SPI AVR module. {{{
+ *
+ * Copyright (C) 2008 Nélio Laranjeiro
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+/** Hardware available clock rates. */
+enum spi_fosc_t
+{
+ SPI_FOSC_DIV2 = (_BV (SPI2X) << 8),
+ SPI_FOSC_DIV4 = 0,
+ SPI_FOSC_DIV8 = (_BV (SPI2X) << 8) | _BV (SPR0),
+ SPI_FOSC_DIV16 = _BV (SPR0),
+ SPI_FOSC_DIV32 = (_BV (SPI2X) << 8) | _BV (SPR1),
+ SPI_FOSC_DIV64 = _BV (SPR1),
+ SPI_FOSC_DIV128 = _BV (SPR1) | _BV (SPR0),
+};
+
+/** Initialise SPI driver.
+ * - master: slave or master mode
+ * - mode: clock polarity and phase
+ * - order: byte order (MSB or LSB)
+ * - speed: clock rate (use SPI_FOSC_DIV*) */
+#define spi_hard_init(master, mode, order, speed) \
+ spi_hard_init_ ((master) | (mode) | (order) | ((speed) & 0xff), \
+ (speed) >> 8)
+void
+spi_hard_init_ (uint8_t spcr, uint8_t spi2x);
+
+/** Send data. */
+void
+spi_hard_send (uint8_t data);
+
+/** Receive data. */
+uint8_t
+spi_hard_recv (void);
+
+/** Send and receive data. */
+uint8_t
+spi_hard_send_and_recv (uint8_t data);
+
+#endif /* spi_hard_h */
diff --git a/digital/avr/modules/spi/test/avrconfig.h b/digital/avr/modules/spi/test/avrconfig.h
index 19eec3cf..7b61acba 100644
--- a/digital/avr/modules/spi/test/avrconfig.h
+++ b/digital/avr/modules/spi/test/avrconfig.h
@@ -83,4 +83,10 @@
/** Support for quote parameter. */
#define AC_PROTO_QUOTE 1
+/* spi - SPI module. */
+/** Select driver: HARD, SOFT, or NONE. */
+#define AC_SPI0_DRIVER HARD
+/** Same thing for an optionnal second SPI driver. */
+#define AC_SPI1_DRIVER NONE
+
#endif /* avrconfig_h */
diff --git a/digital/avr/modules/spi/test/test_spi.c b/digital/avr/modules/spi/test/test_spi.c
index 951dfb41..d82c5843 100644
--- a/digital/avr/modules/spi/test/test_spi.c
+++ b/digital/avr/modules/spi/test/test_spi.c
@@ -24,63 +24,47 @@
* }}} */
#include "common.h"
+#include "io.h"
#include "modules/proto/proto.h"
+#include "modules/uart/uart.h"
#include "modules/spi/spi.h"
-#include "io.h"
+#include "modules/utils/utils.h"
void
proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
{
- //TODO Still don't know what to to
+ /* TODO: command to select a slave. */
+#define c(cmd, size) (cmd << 8 | size)
+ switch (c (cmd, size))
+ {
+ case c ('z', 0):
+ utils_reset ();
+ break;
+ case c ('s', 1):
+ spi_send (args[0]);
+ break;
+ case c ('r', 0):
+ proto_send1b ('R', spi_recv ());
+ break;
+ case c ('r', 1):
+ proto_send1b ('R', spi_send_and_recv (args[0]));
+ break;
+ default:
+ proto_send0 ('?');
+ return;
+ }
+ proto_send (cmd, size, args);
+#undef c
}
int
main (void)
{
- //uint8_t test [10];
- //uint8_t res;
-
- /*res = SPI_IT_ENABLE;
- spi_init (res);
- res = SPI_IT_DISABLE;
- spi_init (res);
- res = SPI_ENABLE;
- spi_init (res);
- res = SPI_DISABLE;
- spi_init (res);
- res = SPI_LSB_FIRST;
- spi_init (res);
- res = SPI_MSB_FIRST;
- spi_init (res);
- res = SPI_MASTER;
- spi_init (res);
- res = SPI_SLAVE;
- spi_init (res);
- res = SPI_CPOL_RISING;
- spi_init (res);
- res = SPI_CPOL_FALLING;
- spi_init (res);
- res = SPI_CPHA_SAMPLE;
- spi_init (res);
- res = SPI_CPHA_SETUP;
- spi_init (res);
- */
-
- //initialise the spi.
- spi_init (0x14);
-
- proto_send0 (PORTB);
- proto_send0 (DDRB);
-
-
- /*test[0] = 0x2;
- test[1] = 0x3;
- test[2] = 0x4;
-
- spi_send (3);
-
- res = spi_recv ();
- */
- return 0;
+ spi_init (SPI_MASTER, SPI_MODE_0, SPI_MSB_FIRST, SPI_FOSC_DIV128);
+ uart0_init ();
+ sei ();
+ proto_send0 ('z');
+ while (1)
+ proto_accept (uart0_getc ());
}
diff --git a/digital/avr/modules/trace/test/test_target/avrconfig.h b/digital/avr/modules/trace/test/test_target/avrconfig.h
index c4d9f159..277c6386 100644
--- a/digital/avr/modules/trace/test/test_target/avrconfig.h
+++ b/digital/avr/modules/trace/test/test_target/avrconfig.h
@@ -83,6 +83,12 @@
/** Support for quote parameter. */
#define AC_PROTO_QUOTE 1
+/* spi - SPI module. */
+/** Select driver: HARD, SOFT, or NONE. */
+#define AC_SPI0_DRIVER HARD
+/** Same thing for an optionnal second SPI driver. */
+#define AC_SPI1_DRIVER NONE
+
/* flash - Flash SPI AVR module. */
/** Flash PORT used. */
#define AC_FLASH_PORT PORTD
@@ -91,5 +97,4 @@
/** Flash SS pin. */
#define AC_FLASH_BIT_SS 5
-
#endif /* avrconfig_h */