altos: Horrible kludge -- disable radio while talking with SD card
authorKeith Packard <keithp@keithp.com>
Mon, 1 Apr 2013 09:39:35 +0000 (02:39 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 1 Apr 2013 09:39:35 +0000 (02:39 -0700)
The SD card really doesn't like the RFI generated by our enormous
radio, so just lock the radio out while working with the card.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_cc115l.c
src/drivers/ao_sdcard.c
src/telegps-v0.1/ao_telegps.c

index 9a4908b501d0030b7f9a2fd169a2bf7bb51d72a3..d6a938ac5c32a8fc0bf6152a08d7da0d64444389 100644 (file)
@@ -23,7 +23,7 @@
 
 #define AO_RADIO_MAX_SEND      sizeof (struct ao_telemetry_generic)
 
-static uint8_t ao_radio_mutex;
+uint8_t ao_radio_mutex;
 
 static uint8_t ao_radio_fifo;          /* fifo drained interrupt received */
 static uint8_t ao_radio_done;          /* tx done interrupt received */
index 6073677a96745ddfbc69a37976e72e9c76a5edd2..59ac94008f84aafb6974f903923caa649e0ad570 100644 (file)
 #include "ao.h"
 #include "ao_sdcard.h"
 
-#define ao_sdcard_get_slow()           ao_spi_get(AO_SDCARD_SPI_BUS, AO_SPI_SPEED_250kHz)
-#define ao_sdcard_get()                        ao_spi_get(AO_SDCARD_SPI_BUS, AO_SPI_SPEED_FAST)
-#define ao_sdcard_put()                        ao_spi_put(AO_SDCARD_SPI_BUS)
+extern uint8_t ao_radio_mutex;
+
+#define ao_sdcard_get_slow() do { ao_mutex_get(&ao_radio_mutex); ao_spi_get(AO_SDCARD_SPI_BUS, AO_SPI_SPEED_250kHz); } while (0)
+#define ao_sdcard_get()        do { ao_mutex_get(&ao_radio_mutex); ao_spi_get(AO_SDCARD_SPI_BUS, AO_SPI_SPEED_FAST); } while (0)
+#define ao_sdcard_put() do { ao_spi_put(AO_SDCARD_SPI_BUS); ao_mutex_put(&ao_radio_mutex); } while (0)
 #define ao_sdcard_send_fixed(d,l)      ao_spi_send_fixed((d), (l), AO_SDCARD_SPI_BUS)
 #define ao_sdcard_send(d,l)            ao_spi_send((d), (l), AO_SDCARD_SPI_BUS)
 #define ao_sdcard_recv(d,l)            ao_spi_recv((d), (l), AO_SDCARD_SPI_BUS)
@@ -686,6 +688,9 @@ static const struct ao_cmds ao_sdcard_cmds[] = {
 void
 ao_sdcard_init(void)
 {
+       stm_pupdr_set(AO_SDCARD_SPI_PORT, AO_SDCARD_SPI_SCK_PIN, STM_PUPDR_PULL_UP);
+       stm_pupdr_set(AO_SDCARD_SPI_PORT, AO_SDCARD_SPI_MISO_PIN, STM_PUPDR_PULL_UP);
+       stm_pupdr_set(AO_SDCARD_SPI_PORT, AO_SDCARD_SPI_MOSI_PIN, STM_PUPDR_PULL_UP);
        ao_spi_init_cs(AO_SDCARD_SPI_CS_PORT, (1 << AO_SDCARD_SPI_CS_PIN));
 #if SDCARD_DEBUG
        ao_cmd_register(&ao_sdcard_cmds[0]);
index 4620de3b3bcfd2f37195ca7bf78a2e601cf8df3e..68116bfb0f2a5af0a569ed708a2e898c57811ac5 100644 (file)
@@ -52,7 +52,7 @@ main(void)
        ao_fat_init();
 
        ao_gps_init();
-//     ao_gps_report_mega_init();
+       ao_gps_report_mega_init();
 
        ao_telemetry_init();
        ao_telemetry_set_interval(AO_SEC_TO_TICKS(1));