altos: Add initial TeleBT code
authorKeith Packard <keithp@keithp.com>
Fri, 1 Apr 2011 03:58:14 +0000 (20:58 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 1 Apr 2011 03:59:07 +0000 (20:59 -0700)
Prototyping with a TeleMetrum v0.1 board and a serial link to a
bluetooth module.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/Makefile
src/Makefile.proto
src/ao.h
src/ao_btm.c [new file with mode: 0644]
src/ao_pins.h
src/ao_serial.c
src/ao_stdio.c
src/ao_telebt.c [new file with mode: 0644]
src/telebt-v0.0/.gitignore [new file with mode: 0644]
src/telebt-v0.0/.sdcdbrc [new file with mode: 0644]
src/telebt-v0.0/Makefile.defs [new file with mode: 0644]

index a5dec57b2144efc8d5fd7074444095daa13a02f9..d83ec668b8e3a9a8a4fd6d9629100e15842fc18d 100644 (file)
@@ -10,6 +10,7 @@ SUBDIRS=\
        telemetrum-v1.1 telemetrum-v1.0 \
        teledongle-v0.2 teledongle-v0.1 \
        telemini-v0.1 telenano-v0.1 \
+       telebt-v0.0 \
        telemetrum-v0.1-sky telemetrum-v0.1-sirf \
        tidongle test
 
index 5aad445fa44c3aaff4efc9ad5c89b71bc02712b7..ca68edbcba016322c3f80db92f8ac8fbe489c32f 100644 (file)
@@ -136,12 +136,20 @@ M25_DRIVER_SRC = \
 #
 SIRF_DRIVER_SRC = \
        ao_gps_sirf.c
+
 #
 # Skytraq driver source
 #
 SKY_DRIVER_SRC = \
        ao_gps_skytraq.c
 
+
+#
+# BTM-182 driver source
+#
+BTM_DRIVER_SRC = \
+       ao_btm.c
+
 #
 # Tasks run on TeleMetrum
 #
@@ -229,6 +237,24 @@ TNANO_BASE_SRC = \
        $(TNANO_TASK_SRC) \
        $(TNANO_MAIN_SRC)
 
+#
+# Sources for TeleDongle
+#
+
+TBT_MAIN_SRC = \
+       ao_telebt.c
+
+TBT_BASE_SRC = \
+       $(ALTOS_SRC) \
+       $(ALTOS_DRIVER_SRC) \
+       $(TELE_RECEIVER_SRC) \
+       $(TELE_COMMON_SRC) \
+       $(SERIAL_DRIVER_SRC) \
+       $(USB_DRIVER_SRC) \
+       $(BTM_DRIVER_SRC) \
+       $(DBG_SRC) \
+       $(TBT_MAIN_SRC)
+
 #
 # TI Dongle sources
 #
index 89109fd964449926bb4141020f61aa90c0982df1..64f33f0b2c18a938320204709cd7e1e9173373fa 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -903,6 +903,10 @@ ao_dbg_init(void);
 #endif
 
 #if HAS_SERIAL_1
+#ifndef USE_SERIAL_STDIN
+#error Please define USE_SERIAL_STDIN
+#endif
+
 void
 ao_serial_rx1_isr(void) __interrupt 3;
 
@@ -912,12 +916,21 @@ ao_serial_tx1_isr(void) __interrupt 14;
 char
 ao_serial_getchar(void) __critical;
 
+#if USE_SERIAL_STDIN
+char
+ao_serial_pollchar(void) __critical;
+
+void
+ao_serial_set_stdin(uint8_t stdin);
+#endif
+
 void
 ao_serial_putchar(char c) __critical;
 
 #define AO_SERIAL_SPEED_4800   0
 #define AO_SERIAL_SPEED_9600   1
-#define AO_SERIAL_SPEED_57600  2
+#define AO_SERIAL_SPEED_19200  2
+#define AO_SERIAL_SPEED_57600  3
 
 void
 ao_serial_set_speed(uint8_t speed);
@@ -1332,4 +1345,9 @@ ao_packet_slave_stop(void);
 void
 ao_packet_slave_init(uint8_t enable);
 
+/* ao_btm.c */
+
+void
+ao_btm_init(void);
+
 #endif /* _AO_H_ */
diff --git a/src/ao_btm.c b/src/ao_btm.c
new file mode 100644 (file)
index 0000000..224d3e8
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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 "ao.h"
+
+uint8_t        ao_btm_enable;
+extern volatile __xdata struct ao_fifo ao_usart1_rx_fifo;
+
+void
+ao_btm(void)
+{
+       char    c;
+       while (ao_btm_enable) {
+               c = ao_serial_pollchar();
+               if (c != AO_READ_AGAIN)
+                       ao_usb_putchar(c);
+               else {
+                       ao_usb_flush();
+                       ao_sleep(&ao_usart1_rx_fifo);
+               }
+       }
+       ao_exit();
+}
+
+__xdata struct ao_task ao_btm_task;
+
+static void
+ao_btm_forward(void)
+{
+       char c;
+       ao_btm_enable = 1;
+       flush();
+       ao_add_task(&ao_btm_task, ao_btm, "btm");
+
+       while ((c = ao_usb_getchar()) != '~') {
+               if (c == '\n') c = '\r';
+               ao_serial_putchar(c);
+       }
+       ao_btm_enable = 0;
+       while (ao_btm_task.wchan) {
+               ao_wakeup(&ao_usart1_rx_fifo);
+               ao_delay(AO_MS_TO_TICKS(10));
+       }
+}
+
+__code struct ao_cmds ao_btm_cmds[] = {
+       { ao_btm_forward,       "B <data>\0BTM serial link." },
+       { 0, NULL },
+};
+
+
+void
+ao_btm_init (void)
+{
+       ao_serial_init();
+       ao_serial_set_speed(AO_SERIAL_SPEED_19200);
+       ao_cmd_register(&ao_btm_cmds[0]);
+}
index 30f2decc1e92987e6d7a594f81a20a8e36df2677..a4ebd63bb21cbb1ed6da51a6f22bb62d60fef7a3 100644 (file)
@@ -25,6 +25,7 @@
        #define HAS_GPS                 1
        #define HAS_SERIAL_1            1
        #define HAS_ADC                 1
+       #define USE_SERIAL_STDIN        0
        #define HAS_EEPROM              1
        #define USE_INTERNAL_FLASH      0
        #define HAS_DBG                 1
@@ -49,6 +50,7 @@
        #define HAS_BEEP                1
        #define HAS_GPS                 1
        #define HAS_SERIAL_1            1
+       #define USE_SERIAL_STDIN        0
        #define HAS_ADC                 1
        #define HAS_EEPROM              1
        #define USE_INTERNAL_FLASH      0
@@ -77,6 +79,7 @@
        #define HAS_USB                 1
        #define HAS_BEEP                0
        #define HAS_SERIAL_1            0
+       #define USE_SERIAL_STDIN        0
        #define HAS_ADC                 0
        #define HAS_DBG                 1
        #define HAS_EEPROM              0
        #define HAS_BEEP                0
        #define HAS_GPS                 0
        #define HAS_SERIAL_1            0
+       #define USE_SERIAL_STDIN        0
        #define HAS_ADC                 1
        #define HAS_EEPROM              1
        #define USE_INTERNAL_FLASH      1
        #define HAS_BEEP                0
        #define HAS_GPS                 0
        #define HAS_SERIAL_1            0
+       #define USE_SERIAL_STDIN        0
        #define HAS_ADC                 1
        #define HAS_EEPROM              1
        #define USE_INTERNAL_FLASH      1
        #define HAS_BEEP                1
        #define HAS_GPS                 1
        #define HAS_SERIAL_1            1
+       #define USE_SERIAL_STDIN        0
        #define HAS_ADC                 1
        #define HAS_DBG                 0
        #define HAS_EEPROM              1
        #define HAS_USB                 1
        #define HAS_BEEP                0
        #define HAS_SERIAL_1            0
+       #define USE_SERIAL_STDIN        0
        #define HAS_ADC                 0
        #define HAS_DBG                 0
        #define HAS_EEPROM              0
        #define HAS_USB                 1
        #define HAS_BEEP                0
        #define HAS_SERIAL_1            0
+       #define USE_SERIAL_STDIN        0
        #define HAS_ADC                 0
        #define HAS_DBG                 1
        #define HAS_EEPROM              0
        #define HAS_IGNITE              0
 #endif
 
+#if defined(TELEBT_V_0_0)
+       #define HAS_FLIGHT              0
+       #define HAS_USB                 1
+       #define HAS_BEEP                0
+       #define HAS_SERIAL_1            1
+       #define USE_SERIAL_STDIN        1
+       #define HAS_ADC                 0
+       #define HAS_DBG                 1
+       #define HAS_EEPROM              0
+       #define DBG_ON_P1               0
+       #define DBG_ON_P0               1
+       #define IGNITE_ON_P2            0
+       #define IGNITE_ON_P0            0
+       #define PACKET_HAS_MASTER       1
+       #define PACKET_HAS_SLAVE        0
+       #define AO_LED_RED              2
+       #define AO_LED_GREEN            1
+       #define LEDS_AVAILABLE          (AO_LED_RED|AO_LED_GREEN)
+       #define SPI_CS_ON_P1            1
+       #define SPI_CS_ON_P0            0
+       #define HAS_IGNITE              0
+#endif
+
 #if DBG_ON_P1
 
        #define DBG_CLOCK       (1 << 4)        /* mi0 */
 #error Please define HAS_SERIAL_1
 #endif
 
+#ifndef USE_SERIAL_STDIN
+#error Please define USE_SERIAL_STDIN
+#endif
+
 #ifndef HAS_ADC
 #error Please define HAS_ADC
 #endif
index dd383fca18ff141a5ffd7c0af0f923f746437eca..b8e9d2bf3a3db377a91e70e4e679d13546cba121 100644 (file)
 volatile __xdata struct ao_fifo        ao_usart1_rx_fifo;
 volatile __xdata struct ao_fifo        ao_usart1_tx_fifo;
 
+#if USE_SERIAL_STDIN
+__pdata uint8_t        ao_serial_stdin;
+#endif
+
 void
 ao_serial_rx1_isr(void) __interrupt 3
 {
        if (!ao_fifo_full(ao_usart1_rx_fifo))
                ao_fifo_insert(ao_usart1_rx_fifo, U1DBUF);
        ao_wakeup(&ao_usart1_rx_fifo);
+#if USE_SERIAL_STDIN
+       if (ao_serial_stdin)
+               ao_wakeup(&ao_stdin_ready);
+#endif
 }
 
 static __xdata uint8_t ao_serial_tx1_started;
@@ -69,6 +77,29 @@ ao_serial_getchar(void) __critical
        return c;
 }
 
+#if USE_SERIAL_STDIN
+char
+ao_serial_pollchar(void) __critical
+{
+       char    c;
+#if 0
+       if (!ao_serial_stdin)
+               return AO_READ_AGAIN;
+#endif
+       if (ao_fifo_empty(ao_usart1_rx_fifo))
+               return AO_READ_AGAIN;
+       ao_fifo_remove(ao_usart1_rx_fifo,c);
+       return c;
+}
+
+void
+ao_serial_set_stdin(uint8_t stdin)
+{
+       ao_serial_stdin = stdin;
+}
+
+#endif
+
 void
 ao_serial_putchar(char c) __critical
 {
@@ -109,6 +140,10 @@ static const struct {
                /* .baud = */ 163,
                /* .gcr  = */ (8 << UxGCR_BAUD_E_SHIFT) | UxGCR_ORDER_LSB
        },
+       /* [AO_SERIAL_SPEED_19200] = */ {
+               /* .baud = */ 163,
+               /* .gcr  = */ (9 << UxGCR_BAUD_E_SHIFT) | UxGCR_ORDER_LSB
+       },
        /* [AO_SERIAL_SPEED_57600] = */ {
                /* .baud = */ 59,
                /* .gcr =  */ (11 << UxGCR_BAUD_E_SHIFT) | UxGCR_ORDER_LSB
@@ -156,4 +191,11 @@ ao_serial_init(void)
        IEN2 |= IEN2_UTX1IE;
 
        ao_cmd_register(&ao_serial_cmds[0]);
+#if 0
+#if USE_SERIAL_STDIN
+       ao_add_stdio(ao_serial_pollchar,
+                    ao_serial_putchar,
+                    NULL);
+#endif
+#endif
 }
index 6e1f5effde50409d1f89967381a9d5054ce8a05a..c7080ec147407916c59fcf174cdba68d51ea2aba 100644 (file)
@@ -21,7 +21,7 @@
  * Basic I/O functions to support SDCC stdio package
  */
 
-#define AO_NUM_STDIOS  2
+#define AO_NUM_STDIOS  (HAS_USB + PACKET_HAS_SLAVE + USE_SERIAL_STDIN)
 
 static __xdata struct ao_stdio stdios[AO_NUM_STDIOS];
 static __data int8_t ao_cur_stdio;
diff --git a/src/ao_telebt.c b/src/ao_telebt.c
new file mode 100644 (file)
index 0000000..295f0ce
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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 "ao.h"
+
+void
+main(void)
+{
+       ao_clock_init();
+
+       /* Turn on the LED until the system is stable */
+       ao_led_init(LEDS_AVAILABLE);
+       ao_led_on(AO_LED_RED);
+       ao_timer_init();
+       ao_cmd_init();
+       ao_usb_init();
+       ao_monitor_init(AO_LED_GREEN, TRUE);
+       ao_rssi_init(AO_LED_RED);
+       ao_radio_init();
+       ao_packet_master_init();
+       ao_btm_init();
+#if HAS_DBG
+       ao_dbg_init();
+#endif
+       ao_config_init();
+       ao_start_scheduler();
+}
diff --git a/src/telebt-v0.0/.gitignore b/src/telebt-v0.0/.gitignore
new file mode 100644 (file)
index 0000000..1acfbfc
--- /dev/null
@@ -0,0 +1,2 @@
+telebt-*
+ao_product.h
diff --git a/src/telebt-v0.0/.sdcdbrc b/src/telebt-v0.0/.sdcdbrc
new file mode 100644 (file)
index 0000000..710b4a2
--- /dev/null
@@ -0,0 +1 @@
+--directory=..
diff --git a/src/telebt-v0.0/Makefile.defs b/src/telebt-v0.0/Makefile.defs
new file mode 100644 (file)
index 0000000..f0bb5e0
--- /dev/null
@@ -0,0 +1,8 @@
+PROG = telebt-v0.0-$(VERSION).ihx
+
+SRC = \
+       $(TBT_BASE_SRC)
+
+PRODUCT=TeleBT-v0.0
+PRODUCT_DEF=-DTELEBT_V_0_0
+IDPRODUCT=0x000e