altos: Get CC115L radio working.
[fw/altos] / src / drivers / ao_cc1120.c
index 3e894f762b6809493bee519fa34cf2276504568b..a26eccbc26d10a16b1719a12a612aeb0fa049dad 100644 (file)
@@ -38,7 +38,7 @@ extern const uint32_t ao_radio_cal;
 
 #define FOSC   32000000
 
-#define ao_radio_select()      ao_spi_get_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS,AO_SPI_SPEED_1MHz)
+#define ao_radio_select()      ao_spi_get_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS,AO_SPI_SPEED_4MHz)
 #define ao_radio_deselect()    ao_spi_put_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS)
 #define ao_radio_spi_send(d,l) ao_spi_send((d), (l), AO_CC1120_SPI_BUS)
 #define ao_radio_spi_send_fixed(d,l) ao_spi_send_fixed((d), (l), AO_CC1120_SPI_BUS)
@@ -747,7 +747,7 @@ ao_radio_send(const void *d, uint8_t size)
 #define AO_RADIO_LOTS  64
 
 void
-ao_radio_send_lots(ao_radio_fill_func fill)
+ao_radio_send_aprs(ao_radio_fill_func fill)
 {
        uint8_t buf[AO_RADIO_LOTS], *b;
        int     cnt;
@@ -834,8 +834,8 @@ ao_radio_rx_isr(void)
 {
        uint8_t d;
 
-       d = stm_spi2.dr;
-       stm_spi2.dr = 0;
+       d = AO_CC1120_SPI.dr;
+       AO_CC1120_SPI.dr = 0;
        if (rx_ignore == 0) {
                if (rx_data_cur >= rx_data_count)
                        ao_exti_disable(AO_CC1120_INT_PORT, AO_CC1120_INT_PIN);
@@ -862,6 +862,7 @@ ao_radio_rx_wait(void)
        do {
                if (ao_radio_mcu_wake)
                        ao_radio_check_marc_status();
+               ao_alarm(AO_MS_TO_TICKS(100));
                ao_arch_block_interrupts();
                rx_waiting = 1;
                while (rx_data_cur - rx_data_consumed < AO_FEC_DECODE_BLOCK &&
@@ -873,6 +874,7 @@ ao_radio_rx_wait(void)
                }
                rx_waiting = 0;
                ao_arch_release_interrupts();
+               ao_clear_alarm();
        } while (ao_radio_mcu_wake);
        if (ao_radio_abort)
                return 0;
@@ -922,10 +924,10 @@ ao_radio_recv(__xdata void *d, uint8_t size)
        ao_radio_wake = 0;
        ao_radio_mcu_wake = 0;
 
-       stm_spi2.cr2 = 0;
+       AO_CC1120_SPI.cr2 = 0;
 
        /* clear any RXNE */
-       (void) stm_spi2.dr;
+       (void) AO_CC1120_SPI.dr;
 
        /* Have the radio signal when the preamble quality goes high */
        ao_radio_reg_write(AO_CC1120_INT_GPIO_IOCFG, CC1120_IOCFG_GPIO_CFG_PQT_REACHED);
@@ -1195,7 +1197,7 @@ static void ao_radio_show(void) {
 }
 
 static void ao_radio_beep(void) {
-       ao_radio_rdf(RDF_PACKET_LEN);
+       ao_radio_rdf();
 }
 
 static void ao_radio_packet(void) {
@@ -1231,6 +1233,7 @@ ao_radio_test_recv()
        }
 }
 
+#if HAS_APRS
 #include <ao_aprs.h>
 
 static void
@@ -1239,13 +1242,16 @@ ao_radio_aprs()
        ao_packet_slave_stop();
        ao_aprs_send();
 }
+#endif
 
 #endif
 
 static const struct ao_cmds ao_radio_cmds[] = {
        { ao_radio_test_cmd,    "C <1 start, 0 stop, none both>\0Radio carrier test" },
 #if CC1120_DEBUG
+#if HAS_APRS
        { ao_radio_aprs,        "G\0Send APRS packet" },
+#endif
        { ao_radio_show,        "R\0Show CC1120 status" },
        { ao_radio_beep,        "b\0Emit an RDF beacon" },
        { ao_radio_packet,      "p\0Send a test packet" },