summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile1
-rw-r--r--src/Makefile.proto26
-rw-r--r--src/ao.h46
-rw-r--r--src/ao_btm.c253
-rw-r--r--src/ao_cmd.c17
-rw-r--r--src/ao_packet_master.c6
-rw-r--r--src/ao_pins.h36
-rw-r--r--src/ao_serial.c50
-rw-r--r--src/ao_stdio.c35
-rw-r--r--src/ao_telebt.c41
-rw-r--r--src/ao_usb.c4
-rw-r--r--src/cc1111.h13
-rw-r--r--src/telebt-v0.0/.gitignore2
-rw-r--r--src/telebt-v0.0/.sdcdbrc1
-rw-r--r--src/telebt-v0.0/Makefile.defs8
15 files changed, 485 insertions, 54 deletions
diff --git a/src/Makefile b/src/Makefile
index a5dec57b..d83ec668 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -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
diff --git a/src/Makefile.proto b/src/Makefile.proto
index 5aad445f..ca68edbc 100644
--- a/src/Makefile.proto
+++ b/src/Makefile.proto
@@ -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
#
@@ -230,6 +238,24 @@ TNANO_BASE_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
#
TI_MAIN_SRC = \
diff --git a/src/ao.h b/src/ao.h
index 89109fd9..226f9a22 100644
--- a/src/ao.h
+++ b/src/ao.h
@@ -107,6 +107,7 @@ ao_start_scheduler(void);
#define AO_PANIC_REBOOT 8 /* Reboot failed */
#define AO_PANIC_FLASH 9 /* Invalid flash part (or wrong blocksize) */
#define AO_PANIC_USB 10 /* Trying to send USB packet while busy */
+#define AO_PANIC_BT 11 /* Communications with bluetooth device failed */
/* Stop the operating system, beeping and blinking the reason */
void
@@ -403,6 +404,14 @@ ao_cmd_register(__code struct ao_cmds *cmds);
void
ao_cmd_init(void);
+#if HAS_CMD_FILTER
+/*
+ * Provided by an external module to filter raw command lines
+ */
+uint8_t
+ao_cmd_filter(void);
+#endif
+
/*
* ao_dma.c
*/
@@ -903,6 +912,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 +925,24 @@ 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;
+void
+ao_serial_drain(void) __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);
@@ -1154,14 +1179,22 @@ struct ao_stdio {
char (*pollchar)(void);
void (*putchar)(char c) __reentrant;
void (*flush)(void);
+ uint8_t echo;
};
+extern __xdata struct ao_stdio ao_stdios[];
+extern __data int8_t ao_cur_stdio;
+extern __data int8_t ao_num_stdios;
+
void
flush(void);
extern __xdata uint8_t ao_stdin_ready;
-void
+uint8_t
+ao_echo(void);
+
+int8_t
ao_add_stdio(char (*pollchar)(void),
void (*putchar)(char) __reentrant,
void (*flush)(void)) __reentrant;
@@ -1332,4 +1365,13 @@ ao_packet_slave_stop(void);
void
ao_packet_slave_init(uint8_t enable);
+/* ao_btm.c */
+
+/* Shared by USB, so the USB code calls this function */
+void
+ao_btm_isr(void);
+
+void
+ao_btm_init(void);
+
#endif /* _AO_H_ */
diff --git a/src/ao_btm.c b/src/ao_btm.c
new file mode 100644
index 00000000..db0ff6b0
--- /dev/null
+++ b/src/ao_btm.c
@@ -0,0 +1,253 @@
+/*
+ * 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"
+
+int8_t ao_btm_stdio;
+__xdata uint8_t ao_btm_connected;
+
+#define AO_BTM_MAX_REPLY 16
+__xdata char ao_btm_reply[AO_BTM_MAX_REPLY];
+
+extern volatile __xdata struct ao_fifo ao_usart1_rx_fifo;
+
+/*
+ * Read a line of data from the serial port, truncating
+ * it after a few characters.
+ */
+
+uint8_t
+ao_btm_get_line(void)
+{
+ uint8_t ao_btm_reply_len = 0;
+ char c;
+
+ for (;;) {
+
+ while ((c = ao_serial_pollchar()) != AO_READ_AGAIN) {
+ if (ao_btm_reply_len < sizeof (ao_btm_reply))
+ ao_btm_reply[ao_btm_reply_len++] = c;
+ if (c == '\r' || c == '\n')
+ goto done;
+ }
+ for (c = 0; c < 10; c++) {
+ ao_delay(AO_MS_TO_TICKS(10));
+ if (!ao_fifo_empty(ao_usart1_rx_fifo))
+ break;
+ }
+ if (c == 10)
+ goto done;
+ }
+done:
+ for (c = ao_btm_reply_len; c < sizeof (ao_btm_reply);)
+ ao_btm_reply[c++] = '\0';
+ return ao_btm_reply_len;
+}
+
+/*
+ * Drain the serial port completely
+ */
+void
+ao_btm_drain()
+{
+ while (ao_btm_get_line())
+ ;
+}
+
+/*
+ * Set the stdio echo for the bluetooth link
+ */
+void
+ao_btm_echo(uint8_t echo)
+{
+ ao_stdios[ao_btm_stdio].echo = echo;
+}
+
+/*
+ * Delay between command charaters; the BT module
+ * can't keep up with 57600 baud
+ */
+
+void
+ao_btm_putchar(char c)
+{
+ ao_serial_putchar(c);
+ ao_delay(1);
+}
+
+/*
+ * Wait for the bluetooth device to return
+ * status from the previously executed command
+ */
+uint8_t
+ao_btm_wait_reply(void)
+{
+ for (;;) {
+ ao_btm_get_line();
+ if (!strncmp(ao_btm_reply, "OK", 2))
+ return 1;
+ if (!strncmp(ao_btm_reply, "ERROR", 5))
+ return -1;
+ if (ao_btm_reply[0] == '\0')
+ return 0;
+ }
+}
+
+void
+ao_btm_string(__code char *cmd)
+{
+ char c;
+
+ while (c = *cmd++)
+ ao_btm_putchar(c);
+}
+
+uint8_t
+ao_btm_cmd(__code char *cmd)
+{
+ ao_btm_drain();
+ ao_btm_string(cmd);
+ return ao_btm_wait_reply();
+}
+
+uint8_t
+ao_btm_set_name(void)
+{
+ char sn[8];
+ char *s = sn + 8;
+ char c;
+ int n;
+ ao_btm_string("ATN=TeleBT-");
+ *--s = '\0';
+ *--s = '\r';
+ n = ao_serial_number;
+ do {
+ *--s = '0' + n % 10;
+ } while (n /= 10);
+ while ((c = *s++))
+ ao_btm_putchar(c);
+ return ao_btm_wait_reply();
+}
+
+uint8_t
+ao_btm_try_speed(uint8_t speed)
+{
+ ao_serial_set_speed(speed);
+ ao_btm_drain();
+ (void) ao_btm_cmd("\rATE0\rATQ0\r");
+ if (ao_btm_cmd("AT\r") == 1)
+ return 1;
+ return 0;
+}
+
+/*
+ * A thread to initialize the bluetooth device and
+ * hang around to blink the LED when connected
+ */
+void
+ao_btm(void)
+{
+ /*
+ * Wait for the bluetooth device to boot
+ */
+ ao_delay(AO_SEC_TO_TICKS(3));
+
+ /*
+ * The first time we connect, the BTM-180 comes up at 19200 baud.
+ * After that, it will remember and come up at 57600 baud. So, see
+ * if it is already running at 57600 baud, and if that doesn't work
+ * then tell it to switch to 57600 from 19200 baud.
+ */
+ while (!ao_btm_try_speed(AO_SERIAL_SPEED_57600)) {
+ ao_delay(AO_SEC_TO_TICKS(1));
+ if (ao_btm_try_speed(AO_SERIAL_SPEED_19200))
+ ao_btm_cmd("ATL4\r");
+ ao_delay(AO_SEC_TO_TICKS(1));
+ }
+
+ /* Disable echo */
+ ao_btm_cmd("ATE0\r");
+
+ /* Enable flow control */
+ ao_btm_cmd("ATC1\r");
+
+ /* Set the reported name to something we can find on the host */
+ ao_btm_set_name();
+
+ /* Turn off status reporting */
+ ao_btm_cmd("ATQ1\r");
+
+ ao_btm_stdio = ao_add_stdio(ao_serial_pollchar,
+ ao_serial_putchar,
+ NULL);
+ ao_btm_echo(0);
+
+ for (;;) {
+ while (!ao_btm_connected)
+ ao_sleep(&ao_btm_connected);
+ while (ao_btm_connected) {
+ ao_led_for(AO_LED_GREEN, AO_MS_TO_TICKS(20));
+ ao_delay(AO_SEC_TO_TICKS(3));
+ }
+ }
+}
+
+__xdata struct ao_task ao_btm_task;
+
+void
+ao_btm_check_link() __critical
+{
+ if (P2_1) {
+ ao_btm_connected = 0;
+ PICTL |= PICTL_P2ICON;
+ } else {
+ ao_btm_connected = 1;
+ PICTL &= ~PICTL_P2ICON;
+ }
+}
+
+void
+ao_btm_isr(void)
+{
+ if (P2IFG & (1 << 1)) {
+ ao_btm_check_link();
+ ao_wakeup(&ao_btm_connected);
+ }
+ P2IFG = 0;
+}
+
+void
+ao_btm_init (void)
+{
+ ao_serial_init();
+ ao_serial_set_speed(AO_SERIAL_SPEED_19200);
+
+ /*
+ * Configure link status line
+ */
+
+ /* Set P2_1 to input, pull-down */
+ P2DIR &= ~(1 << 1);
+ P2INP |= P2INP_MDP2_1_TRISTATE;
+
+ /* Enable P2 interrupts */
+ IEN2 |= IEN2_P2IE;
+ ao_btm_check_link();
+ PICTL |= PICTL_P2IEN;
+
+ ao_add_task(&ao_btm_task, ao_btm, "bt");
+}
diff --git a/src/ao_cmd.c b/src/ao_cmd.c
index 6007773c..23346c3d 100644
--- a/src/ao_cmd.c
+++ b/src/ao_cmd.c
@@ -21,7 +21,6 @@ __xdata uint16_t ao_cmd_lex_i;
__xdata uint32_t ao_cmd_lex_u32;
__xdata char ao_cmd_lex_c;
__xdata enum ao_cmd_status ao_cmd_status;
-static __xdata uint8_t lex_echo;
#define CMD_LEN 32
@@ -41,7 +40,7 @@ static void
readline(void)
{
__xdata char c;
- if (lex_echo)
+ if (ao_echo())
put_string("> ");
cmd_len = 0;
for (;;) {
@@ -50,7 +49,7 @@ readline(void)
/* backspace/delete */
if (c == '\010' || c == '\177') {
if (cmd_len != 0) {
- if (lex_echo)
+ if (ao_echo())
put_string("\010 \010");
--cmd_len;
}
@@ -60,7 +59,7 @@ readline(void)
/* ^U */
if (c == '\025') {
while (cmd_len != 0) {
- if (lex_echo)
+ if (ao_echo())
put_string("\010 \010");
--cmd_len;
}
@@ -72,18 +71,18 @@ readline(void)
c = '\n';
if (c == '\n') {
- if (lex_echo)
+ if (ao_echo())
putchar('\n');
break;
}
if (cmd_len >= CMD_LEN - 2) {
- if (lex_echo)
+ if (ao_echo())
putchar('\007');
continue;
}
cmd_line[cmd_len++] = c;
- if (lex_echo)
+ if (ao_echo())
putchar(c);
}
cmd_line[cmd_len++] = '\n';
@@ -198,7 +197,8 @@ static void
echo(void)
{
ao_cmd_hex();
- lex_echo = ao_cmd_lex_i != 0;
+ if (ao_cmd_status == ao_cmd_success)
+ ao_stdios[ao_cur_stdio].echo = ao_cmd_lex_i != 0;
}
static void
@@ -272,7 +272,6 @@ ao_cmd(void)
__code struct ao_cmds * __xdata cs;
void (*__xdata func)(void);
- lex_echo = 1;
for (;;) {
readline();
ao_cmd_lex();
diff --git a/src/ao_packet_master.c b/src/ao_packet_master.c
index 069bc5df..e721ffba 100644
--- a/src/ao_packet_master.c
+++ b/src/ao_packet_master.c
@@ -26,7 +26,7 @@ ao_packet_getchar(void) __critical
break;
if (ao_packet_master_sleeping)
ao_wakeup(&ao_packet_master_sleeping);
- ao_usb_flush();
+ flush();
ao_sleep(&ao_stdin_ready);
}
return c;
@@ -39,7 +39,7 @@ ao_packet_echo(void) __reentrant
while (ao_packet_enable) {
c = ao_packet_getchar();
if (c != AO_READ_AGAIN)
- ao_usb_putchar(c);
+ putchar(c);
}
ao_exit();
}
@@ -112,7 +112,7 @@ ao_packet_forward(void) __reentrant
ao_set_monitor(0);
ao_add_task(&ao_packet_task, ao_packet_master, "master");
ao_add_task(&ao_packet_echo_task, ao_packet_echo, "echo");
- while ((c = ao_usb_getchar()) != '~') {
+ while ((c = getchar()) != '~') {
if (c == '\r') c = '\n';
ao_packet_putchar(c);
}
diff --git a/src/ao_pins.h b/src/ao_pins.h
index 2161c5d2..324d7827 100644
--- a/src/ao_pins.h
+++ b/src/ao_pins.h
@@ -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
@@ -100,6 +103,7 @@
#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
@@ -124,6 +128,7 @@
#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
@@ -147,6 +152,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_DBG 0
#define HAS_EEPROM 1
@@ -173,6 +179,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 0
#define HAS_EEPROM 0
@@ -195,6 +202,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
@@ -211,6 +219,30 @@
#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 HAS_BTM 1
+ #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 */
@@ -271,6 +303,10 @@
#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
diff --git a/src/ao_serial.c b/src/ao_serial.c
index dd383fca..9c0b798d 100644
--- a/src/ao_serial.c
+++ b/src/ao_serial.c
@@ -26,6 +26,9 @@ 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
+ ao_wakeup(&ao_stdin_ready);
+#endif
}
static __xdata uint8_t ao_serial_tx1_started;
@@ -50,8 +53,6 @@ ao_serial_tx1_isr(void) __interrupt 14
ao_wakeup(&ao_usart1_tx_fifo);
}
-static __pdata serial_echo;
-
char
ao_serial_getchar(void) __critical
{
@@ -59,16 +60,21 @@ ao_serial_getchar(void) __critical
while (ao_fifo_empty(ao_usart1_rx_fifo))
ao_sleep(&ao_usart1_rx_fifo);
ao_fifo_remove(ao_usart1_rx_fifo, c);
- if (serial_echo) {
- printf("%02x ", ((int) c) & 0xff);
- if (c >= ' ')
- putchar(c);
- putchar('\n');
- flush();
- }
return c;
}
+#if USE_SERIAL_STDIN
+char
+ao_serial_pollchar(void) __critical
+{
+ char c;
+ if (ao_fifo_empty(ao_usart1_rx_fifo))
+ return AO_READ_AGAIN;
+ ao_fifo_remove(ao_usart1_rx_fifo,c);
+ return c;
+}
+#endif
+
void
ao_serial_putchar(char c) __critical
{
@@ -78,25 +84,13 @@ ao_serial_putchar(char c) __critical
ao_serial_tx1_start();
}
-static void
+void
ao_serial_drain(void) __critical
{
while (!ao_fifo_empty(ao_usart1_tx_fifo))
ao_sleep(&ao_usart1_tx_fifo);
}
-static void
-monitor_serial(void)
-{
- ao_cmd_hex();
- serial_echo = ao_cmd_lex_i != 0;
-}
-
-__code struct ao_cmds ao_serial_cmds[] = {
- { monitor_serial, "M <enable>\0Monitor serial data" },
- { 0, NULL },
-};
-
static const struct {
uint8_t baud;
uint8_t gcr;
@@ -109,6 +103,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
@@ -121,6 +119,7 @@ ao_serial_set_speed(uint8_t speed)
ao_serial_drain();
if (speed > AO_SERIAL_SPEED_57600)
return;
+ U1UCR |= UxUCR_FLUSH;
U1BAUD = ao_serial_speeds[speed].baud;
U1GCR = ao_serial_speeds[speed].gcr;
}
@@ -131,7 +130,8 @@ ao_serial_init(void)
/* Set up the USART pin assignment */
PERCFG = (PERCFG & ~PERCFG_U1CFG_ALT_MASK) | PERCFG_U1CFG_ALT_2;
- /* ee has already set the P2SEL bits */
+ P2SEL = (P2SEL & ~(P2SEL_PRI3P1_MASK | P2SEL_PRI2P1_MASK)) |
+ (P2SEL_PRI3P1_USART1 | P2SEL_PRI2P1_USART1);
/* Make the USART pins be controlled by the USART */
P1SEL |= (1 << 6) | (1 << 7);
@@ -145,7 +145,7 @@ ao_serial_init(void)
/* Reasonable serial parameters */
U1UCR = (UxUCR_FLUSH |
UxUCR_FLOW_DISABLE |
- UxUCR_D9_ODD_PARITY |
+ UxUCR_D9_EVEN_PARITY |
UxUCR_BIT9_8_BITS |
UxUCR_PARITY_DISABLE |
UxUCR_SPB_1_STOP_BIT |
@@ -154,6 +154,4 @@ ao_serial_init(void)
IEN0 |= IEN0_URX1IE;
IEN2 |= IEN2_UTX1IE;
-
- ao_cmd_register(&ao_serial_cmds[0]);
}
diff --git a/src/ao_stdio.c b/src/ao_stdio.c
index 6e1f5eff..6b890832 100644
--- a/src/ao_stdio.c
+++ b/src/ao_stdio.c
@@ -21,25 +21,25 @@
* 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;
-static __data int8_t ao_num_stdios;
+__xdata struct ao_stdio ao_stdios[AO_NUM_STDIOS];
+__data int8_t ao_cur_stdio;
+__data int8_t ao_num_stdios;
void
putchar(char c)
{
if (c == '\n')
- (*stdios[ao_cur_stdio].putchar)('\r');
- (*stdios[ao_cur_stdio].putchar)(c);
+ (*ao_stdios[ao_cur_stdio].putchar)('\r');
+ (*ao_stdios[ao_cur_stdio].putchar)(c);
}
void
flush(void)
{
- if (stdios[ao_cur_stdio].flush)
- stdios[ao_cur_stdio].flush();
+ if (ao_stdios[ao_cur_stdio].flush)
+ ao_stdios[ao_cur_stdio].flush();
}
__xdata uint8_t ao_stdin_ready;
@@ -51,7 +51,7 @@ getchar(void) __reentrant __critical
int8_t stdio = ao_cur_stdio;
for (;;) {
- c = stdios[stdio].pollchar();
+ c = ao_stdios[stdio].pollchar();
if (c != AO_READ_AGAIN)
break;
if (++stdio == ao_num_stdios)
@@ -63,15 +63,22 @@ getchar(void) __reentrant __critical
return c;
}
-void
+uint8_t
+ao_echo(void)
+{
+ return ao_stdios[ao_cur_stdio].echo;
+}
+
+int8_t
ao_add_stdio(char (*pollchar)(void),
void (*putchar)(char),
void (*flush)(void)) __reentrant
{
if (ao_num_stdios == AO_NUM_STDIOS)
ao_panic(AO_PANIC_STDIO);
- stdios[ao_num_stdios].pollchar = pollchar;
- stdios[ao_num_stdios].putchar = putchar;
- stdios[ao_num_stdios].flush = flush;
- ao_num_stdios++;
+ ao_stdios[ao_num_stdios].pollchar = pollchar;
+ ao_stdios[ao_num_stdios].putchar = putchar;
+ ao_stdios[ao_num_stdios].flush = flush;
+ ao_stdios[ao_num_stdios].echo = 1;
+ return ao_num_stdios++;
}
diff --git a/src/ao_telebt.c b/src/ao_telebt.c
new file mode 100644
index 00000000..295f0cec
--- /dev/null
+++ b/src/ao_telebt.c
@@ -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/ao_usb.c b/src/ao_usb.c
index b4e3f1fe..ece6756a 100644
--- a/src/ao_usb.c
+++ b/src/ao_usb.c
@@ -46,6 +46,7 @@ void
ao_usb_isr(void) __interrupt 6
{
USBIF = 0;
+ IRCON2 &= ~IRCON2_USBIF;
ao_usb_iif |= USBIIF;
if (ao_usb_iif & 1)
ao_wakeup(&ao_usb_task);
@@ -57,6 +58,9 @@ ao_usb_isr(void) __interrupt 6
if (USBCIF & USBCIF_RSTIF)
ao_usb_set_interrupts();
+#if HAS_BTM
+ ao_btm_isr();
+#endif
}
struct ao_usb_setup {
diff --git a/src/cc1111.h b/src/cc1111.h
index effb1a68..a07490e5 100644
--- a/src/cc1111.h
+++ b/src/cc1111.h
@@ -565,14 +565,19 @@ sfr at 0xF5 P2SEL;
#define P2SEL_PRI3P1_MASK (1 << 6)
#define P2SEL_PRI2P1_USART1 (0 << 5)
#define P2SEL_PRI2P1_TIMER3 (1 << 5)
+#define P2SEL_PRI2P1_MASK (1 << 5)
#define P2SEL_PRI1P1_TIMER1 (0 << 4)
#define P2SEL_PRI1P1_TIMER4 (1 << 4)
+#define P2SEL_PRI1P1_MASK (1 << 4)
#define P2SEL_PRI0P1_USART0 (0 << 3)
#define P2SEL_PRI0P1_TIMER1 (1 << 3)
+#define P2SEL_PRI0P1_MASK (1 << 3)
#define P2SEL_SELP2_4_GPIO (0 << 2)
#define P2SEL_SELP2_4_PERIPHERAL (1 << 2)
+#define P2SEL_SELP2_4_MASK (1 << 2)
#define P2SEL_SELP2_3_GPIO (0 << 1)
#define P2SEL_SELP2_3_PERIPHERAL (1 << 1)
+#define P2SEL_SELP2_3_MASK (1 << 1)
#define P2SEL_SELP2_0_GPIO (0 << 0)
#define P2SEL_SELP2_0_PERIPHERAL (1 << 0)
#define P2SEL_SELP2_0_MASK (1 << 0)
@@ -657,6 +662,14 @@ sfr at 0x8B P2IFG;
#define P0IFG_USB_RESUME (1 << 7)
+sfr at 0x8C PICTL;
+#define PICTL_P2IEN (1 << 5)
+#define PICTL_P0IENH (1 << 4)
+#define PICTL_P0IENL (1 << 3)
+#define PICTL_P2ICON (1 << 2)
+#define PICTL_P1ICON (1 << 1)
+#define PICTL_P0ICON (1 << 0)
+
/* GPIO pins */
sfr at 0x80 P0;
diff --git a/src/telebt-v0.0/.gitignore b/src/telebt-v0.0/.gitignore
new file mode 100644
index 00000000..1acfbfcc
--- /dev/null
+++ b/src/telebt-v0.0/.gitignore
@@ -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
index 00000000..710b4a2f
--- /dev/null
+++ b/src/telebt-v0.0/.sdcdbrc
@@ -0,0 +1 @@
+--directory=..
diff --git a/src/telebt-v0.0/Makefile.defs b/src/telebt-v0.0/Makefile.defs
new file mode 100644
index 00000000..f0bb5e0c
--- /dev/null
+++ b/src/telebt-v0.0/Makefile.defs
@@ -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