altos: Put SPI in slower mode when talking to companion board
authorKeith Packard <keithp@keithp.com>
Fri, 12 Aug 2011 12:38:16 +0000 (05:38 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 14 Aug 2011 01:46:12 +0000 (18:46 -0700)
The AVR CPU on the other side just can't go very fast. This reduces
the SPI clock by a factor of 16, just under 200kHz. As the companion
commands are reasonably short, this shouldn't have a huge effect on
overall SPI utilization.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao_companion.c

index 8db3273eaea126cce802ee0f11bdef5b61216e83..556ce0447f15cf0c488850043f1d5a3c0378d223 100644 (file)
 
 #include "ao.h"
 
-#define COMPANION_SELECT()     ao_spi_get_bit(COMPANION_CS)
-#define COMPANION_DESELECT()   ao_spi_put_bit(COMPANION_CS)
+#define ao_spi_slow() (U0GCR = (UxGCR_CPOL_NEGATIVE |          \
+                               UxGCR_CPHA_FIRST_EDGE |         \
+                               UxGCR_ORDER_MSB |               \
+                               (13 << UxGCR_BAUD_E_SHIFT)))
+
+#define ao_spi_fast() (U0GCR = (UxGCR_CPOL_NEGATIVE |          \
+                               UxGCR_CPHA_FIRST_EDGE |         \
+                               UxGCR_ORDER_MSB |               \
+                               (17 << UxGCR_BAUD_E_SHIFT)))
+
+#define COMPANION_SELECT()     do { ao_spi_get_bit(COMPANION_CS); ao_spi_slow(); } while (0)
+#define COMPANION_DESELECT()   do { ao_spi_fast(); ao_spi_put_bit(COMPANION_CS); } while (0)
 
 static __xdata struct ao_companion_command     ao_companion_command;
 __xdata struct ao_companion_setup              ao_companion_setup;