src-avr: Add telescience build target
authorKeith Packard <keithp@keithp.com>
Fri, 20 May 2011 06:43:17 +0000 (23:43 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 20 May 2011 06:43:17 +0000 (23:43 -0700)
No serial output, just USB

Signed-off-by: Keith Packard <keithp@keithp.com>
12 files changed:
src-avr/ao_cmd.c
src-avr/ao_m25.c
src-avr/ao_pins.h
src-avr/ao_serial_avr.c
src-avr/ao_spi_usart.c [new file with mode: 0644]
src-avr/ao_stdio.c
src-avr/ao_task.c
src-avr/ao_telescience.c [new file with mode: 0644]
src-avr/ao_timer.c
src-avr/ao_usb_avr.c
src-avr/avr.h
src-avr/telescience/Makefile [new file with mode: 0644]

index ee70589f55ebc5f9ad46628461b6477b806b0dea..131c3d8934af11a32e82e9b8755e5d06ca590ee7 100644 (file)
@@ -45,7 +45,6 @@ readline(void)
        cmd_len = 0;
        for (;;) {
                flush();
-               printf ("readline sleeping...\n");
                c = getchar();
                /* backspace/delete */
                if (c == '\010' || c == '\177') {
@@ -88,7 +87,6 @@ readline(void)
        }
        cmd_line[cmd_len++] = '\n';
        cmd_line[cmd_len++] = '\0';
-       printf("cmd_len %d\n", cmd_len);
        cmd_i = 0;
 }
 
@@ -280,7 +278,6 @@ ao_cmd(void)
        __code struct ao_cmds * __xdata cs;
        void (*__xdata func)(void);
 
-       printf ("ao_cmd\n");
        for (;;) {
                readline();
                ao_cmd_lex();
index afd5df760aaf1864b0aadb36ac2390957ffd561e..9073e3bb4ef14dbda12c285bbcba353dddec7e8d 100644 (file)
@@ -376,5 +376,7 @@ ao_storage_device_init(void)
        /* Set up chip select wires */
        SPI_CS_PORT |= M25_CS_MASK;     /* raise all CS pins */
        SPI_CS_DIR |= M25_CS_MASK;      /* set CS pins as outputs */
+#ifdef SPI_CS_SEL
        SPI_CS_SEL &= ~M25_CS_MASK;     /* set CS pins as GPIO */
+#endif
 }
index f08af0747c5b36a44971bcae1fa792b80fb490bd..aec8994b87058aed7a4dbd0aef10dd7ab3f35e66 100644 (file)
 #endif
 
 #ifdef TELESCIENCE
-       #define AO_LED_RED              (1<<7)
-       #define LEDS_AVAILABLE          (AO_LED_RED)
+       #define LEDS_AVAILABLE          0
        #define HAS_USB                 1
        #define TEENSY                  0
+       #define USE_SERIAL_STDIN        1
+       #define HAS_SERIAL_1            1
+       #define HAS_USB                 1
+       #define PACKET_HAS_SLAVE        0
+
        #define AVR_VCC_5V              0
        #define AVR_VCC_3V3             1
        #define AVR_CLOCK               8000000UL
+
+       #define SPI_CS_PORT             PORTE
+       #define SPI_CS_DIR              DDRE
+       #define M25_CS_MASK             (1 << PORTE6)
+       #define M25_MAX_CHIPS           1
 #endif
 
 #ifndef AVR
index 5c098f0b6f65816fca814be5d65b13b3a4c5610e..2fe39755487a6f18c22b27770326fafbc03c4607 100644 (file)
 __xdata struct ao_fifo ao_usart1_rx_fifo;
 __xdata struct ao_fifo ao_usart1_tx_fifo;
 
+void
+ao_debug_out(char c)
+{
+       if (c == '\n')
+               ao_debug_out('\r');
+       loop_until_bit_is_set(UCSR1A, UDRE1);
+       UDR1 = c;
+}
+
 ISR(USART1_RX_vect)
 {
        if (!ao_fifo_full(ao_usart1_rx_fifo))
@@ -145,6 +154,7 @@ ao_serial_init(void)
                  (1 << TXEN1) |        /* Enable transmitter */
                  (1 << RXCIE1) |       /* Enable receive interrupts */
                  (1 << UDRIE1));       /* Enable transmit empty interrupts */
+#if 0
 #if USE_SERIAL_STDIN
        int8_t  i;
        i = ao_add_stdio(ao_serial_pollchar,
@@ -152,4 +162,5 @@ ao_serial_init(void)
                         NULL);
        printf("Register serial stdio as %d\n", i);
 #endif
+#endif
 }
diff --git a/src-avr/ao_spi_usart.c b/src-avr/ao_spi_usart.c
new file mode 100644 (file)
index 0000000..6ed708f
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * 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"
+
+/*
+ * Atmega32u4 USART in MSPIM (master SPI mode)
+ */
+
+__xdata uint8_t        ao_spi_mutex;
+
+/* Send bytes over SPI.
+ *
+ * This just polls; the SPI is set to go as fast as possible,
+ * so using interrupts would take way too long
+ */
+void
+ao_spi_send(void __xdata *block, uint16_t len) __reentrant
+{
+       uint8_t *d = block;
+
+       ao_mutex_get(&ao_spi_mutex);
+       while (len--) {
+               while (!(UCSR1A & (1 << UDRE1)));
+               UDR1 = *d++;
+               while (!(UCSR1A & (1 << RXC1)));
+               (void) UDR1;
+       }
+       ao_mutex_put(&ao_spi_mutex);
+}
+
+/* Receive bytes over SPI.
+ *
+ * This sets up tow DMA engines, one reading the data and another
+ * writing constant values to the SPI transmitter as that is what
+ * clocks the data coming in.
+ */
+void
+ao_spi_recv(void __xdata *block, uint16_t len) __reentrant
+{
+       uint8_t *d = block;
+
+       ao_mutex_get(&ao_spi_mutex);
+       while (len--) {
+               while (!(UCSR1A & (1 << UDRE1)));
+               UDR1 = 0;
+               while (!(UCSR1A & (1 << RXC1)));
+               *d++ = UDR1;
+       }
+       ao_mutex_put(&ao_spi_mutex);
+}
+
+/*
+ * Initialize USART0 for SPI using config alt 2
+ *
+ *     MO      P1_5
+ *     MI      P1_4
+ *     CLK     P1_3
+ *
+ * Chip select is the responsibility of the caller
+ */
+
+#define XCK1_DDR       DDRD
+#define XCK1_PORT      PORTD
+#define XCK1           PORTD5
+#define XMS1_DDR       DDRE
+#define XMS1_PORT      PORTE
+#define XMS1           PORTE6
+
+void
+ao_spi_init(void)
+{
+       /* Ensure the USART is powered */
+       PRR1 &= ~(1 << PRUSART1);
+
+       /*
+        * Set pin directions
+        */
+       XCK1_DDR |= (1 << XCK1);
+
+       /* Clear chip select (which is negated) */
+       XMS1_PORT |= (1 < XMS1);
+       XMS1_DDR |= (1 << XMS1);
+
+       /* Set baud register to zero (required before turning transmitter on) */
+       UBRR1 = 0;
+
+       UCSR1C = ((0x3 << UMSEL10) |    /* Master SPI mode */
+                 (0 << UCSZ10) |       /* SPI mode 0 */
+                 (0 << UCPOL1));       /* SPI mode 0 */
+
+       /* Enable transmitter and receiver */
+       UCSR1B = ((1 << RXEN1) |
+                 (1 << TXEN1));
+
+       /* It says that 0 is a legal value; we'll see... */
+       UBRR1 = 0;
+}
index 6702fab0ba19d53791319469956e3a388793ea24..0ec0fc2e91a339d10db0ad821f8cfe457626f862 100644 (file)
@@ -37,6 +37,8 @@ __data int8_t ao_num_stdios;
 void
 putchar(char c)
 {
+       if (ao_cur_stdio >= ao_num_stdios || !ao_stdios[ao_cur_stdio].putchar)
+               return;
        if (c == '\n')
                (*ao_stdios[ao_cur_stdio].putchar)('\r');
        (*ao_stdios[ao_cur_stdio].putchar)(c);
@@ -58,10 +60,12 @@ ao_getchar(void) __reentrant __critical
        int8_t stdio = ao_cur_stdio;
 
        for (;;) {
-               c = ao_stdios[stdio].pollchar();
-               if (c != AO_READ_AGAIN)
-                       break;
-               if (++stdio == ao_num_stdios)
+               if (stdio < ao_num_stdios) {
+                       c = ao_stdios[stdio].pollchar();
+                       if (c != AO_READ_AGAIN)
+                               break;
+               }
+               if (++stdio >= ao_num_stdios)
                        stdio = 0;
                if (stdio == ao_cur_stdio)
                        ao_sleep(&ao_stdin_ready);
@@ -87,6 +91,7 @@ ao_add_stdio(char (*pollchar)(void),
        ao_stdios[ao_num_stdios].putchar = putchar;
        ao_stdios[ao_num_stdios].flush = flush;
        ao_stdios[ao_num_stdios].echo = 1;
+       ao_wakeup(&ao_stdin_ready);
        return ao_num_stdios++;
 }
 
@@ -94,7 +99,7 @@ ao_add_stdio(char (*pollchar)(void),
 int
 stdio_put(char c, FILE *stream)
 {
-#if 0
+#if 1
        if (ao_cur_task && ao_num_stdios)
                putchar(c);
        else
@@ -124,6 +129,5 @@ ao_stdio_init(void)
 {
        stdout = &mystdout;
        stdin = &mystdin;
-       printf("%d stdios registered\n", ao_num_stdios);
 }
 #endif
index b3bee6c993e061aab6241f00c579ff1950b00461..83f12e2b2fa3b2fbea5943d878757b0d444fa8cd 100644 (file)
@@ -105,14 +105,14 @@ ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *nam
 void
 ao_show_task_from(void)
 {
-       if (ao_cur_task)
-               printf("switching from %s\n", ao_cur_task->name);
+//     if (ao_cur_task)
+//             printf("switching from %s\n", ao_cur_task->name);
 }
 
 void
 ao_show_task_to(void)
 {
-       printf("switching to %s\n", ao_cur_task->name);
+//     printf("switching to %s\n", ao_cur_task->name);
 }
 
 /* Task switching function. This must not use any stack variables */
diff --git a/src-avr/ao_telescience.c b/src-avr/ao_telescience.c
new file mode 100644 (file)
index 0000000..4bbe14c
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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"
+
+int
+main(void)
+{
+       ao_clock_init();
+
+       PORTE |= (1 << 6);
+       DDRE |= (1 << 6);
+
+       ao_stdio_init();
+       ao_timer_init();
+       ao_cmd_init();
+//     ao_spi_init();
+//     ao_storage_init();
+       ao_usb_init();
+
+       /* Turn on the LED until the system is stable */
+       ao_start_scheduler();
+       return 0;
+}
index 9142a497db0ecce76dcb56eae58454aff977e9bc..cc48dd2a39ff07ae8209d0459eb81baabaaf4723 100644 (file)
@@ -41,6 +41,9 @@ volatile __data uint8_t       ao_adc_interval = 1;
 volatile __data uint8_t        ao_adc_count;
 #endif
 
+void
+ao_debug_out(char c);
+
 #ifdef AVR
 ISR(TIMER1_COMPA_vect)
 #else
index fbae08bac8623e66d3c043bd6343e7ed0a51be3c..bc6d1d38958df5bc9ce8e0adbf4aa6bd602aa4f8 100644 (file)
 #include "ao.h"
 #include "ao_usb.h"
 
-//#define printf(format, args...)
+#define USB_DEBUG 0
+
+#if USB_DEBUG
+#define debug(format, args...) printf(format, ## args)
+#else
+#define debug(format, args...)
+#endif
 
 struct ao_task __xdata ao_usb_task;
 
@@ -47,7 +53,6 @@ void
 ao_usb_set_address(uint8_t address)
 {
        UDADDR = (0 << ADDEN) | address;
-       ao_usb_running = 1;
        ao_usb_addr_pending = 1;
 }
 
@@ -60,14 +65,14 @@ static void
 ao_usb_dump_ep(uint8_t ep)
 {
        UENUM = ep;
-       printf ("EP %d: UECONX %02x UECFG0X %02x UECFG1X %02x UEIENX %02x UESTA0X %02x UESTA1X %02X\n",
+       debug ("EP %d: UECONX %02x UECFG0X %02x UECFG1X %02x UEIENX %02x UESTA0X %02x UESTA1X %02X\n",
                ep, UECONX, UECFG0X, UECFG1X, UEIENX, UESTA0X, UESTA1X);
 }
 
 static void
 ao_usb_set_ep0(void)
 {
-       printf ("set_ep0\n");
+       debug ("set_ep0\n");
        /* Set the CONTROL max packet size, single buffered */
        UENUM = 0;
        UECONX = (1 << EPEN);                                   /* Enable */
@@ -118,6 +123,7 @@ ao_usb_set_configuration(void)
        UEIENX = ((1 << RXOUTE));                               /* Enable OUT complete interrupt */
 
        ao_usb_dump_ep(AO_USB_OUT_EP);
+       ao_usb_running = 1;
 }
 
 ISR(USB_GEN_vect)
@@ -171,7 +177,7 @@ ao_usb_ep0_flush(void)
        cli();
        UENUM = 0;
        if (!(UEINTX & (1 << TXINI))) {
-               printf("EP0 not accepting IN data\n");
+               debug("EP0 not accepting IN data\n");
                ao_usb_ep0_set_in_pending(1);
        } else {
                this_len = ao_usb_ep0_in_len;
@@ -186,13 +192,13 @@ ao_usb_ep0_flush(void)
                else
                        ao_usb_ep0_set_in_pending(1);
 
-               printf ("Flush EP0 len %d:", this_len);
+               debug ("Flush EP0 len %d:", this_len);
                while (this_len--) {
                        uint8_t c = *ao_usb_ep0_in_data++;
-                       printf(" %02x", c);
+                       debug(" %02x", c);
                        UEDATX = c;
                }
-               printf ("\n");
+               debug ("\n");
 
                /* Clear the TXINI bit to send the packet */
                UEINTX &= ~(1 << TXINI);
@@ -208,17 +214,17 @@ ao_usb_ep0_fill(uint8_t len, uint8_t ack)
                len = ao_usb_ep0_out_len;
        ao_usb_ep0_out_len -= len;
 
-//     printf ("EP0 UEINTX %02x UEBCLX %d UEBCHX %d\n",
+//     debug ("EP0 UEINTX %02x UEBCLX %d UEBCHX %d\n",
 //             UEINTX, UEBCLX, UEBCHX);
        /* Pull all of the data out of the packet */
-       printf ("Fill EP0 len %d:", len);
+       debug ("Fill EP0 len %d:", len);
        UENUM = 0;
        while (len--) {
                uint8_t c = UEDATX;
                *ao_usb_ep0_out_data++ = c;
-               printf (" %02x", c);
+               debug (" %02x", c);
        }
-       printf ("\n");
+       debug ("\n");
 
        /* ACK the packet */
        UEINTX &= ~ack;
@@ -238,7 +244,7 @@ ao_usb_ep0_setup(void)
        ao_usb_ep0_out_len = 8;
        ao_usb_ep0_fill(8, (1 << RXSTPI) | (1 << RXOUTI) | (1 << TXINI));
        if (ao_usb_ep0_out_len != 0) {
-               printf ("invalid setup packet length\n");
+               debug ("invalid setup packet length\n");
                return;
        }
 
@@ -266,31 +272,31 @@ ao_usb_ep0_setup(void)
        ao_usb_ep0_in_len = 0;
        switch(ao_usb_setup.dir_type_recip & AO_USB_SETUP_TYPE_MASK) {
        case AO_USB_TYPE_STANDARD:
-               printf ("Standard setup packet\n");
+               debug ("Standard setup packet\n");
                switch(ao_usb_setup.dir_type_recip & AO_USB_SETUP_RECIP_MASK) {
                case AO_USB_RECIP_DEVICE:
-                       printf ("Device setup packet\n");
+                       debug ("Device setup packet\n");
                        switch(ao_usb_setup.request) {
                        case AO_USB_REQ_GET_STATUS:
-                               printf ("get status\n");
+                               debug ("get status\n");
                                ao_usb_ep0_queue_byte(0);
                                ao_usb_ep0_queue_byte(0);
                                break;
                        case AO_USB_REQ_SET_ADDRESS:
-                               printf ("set address %d\n", ao_usb_setup.value);
+                               debug ("set address %d\n", ao_usb_setup.value);
                                ao_usb_set_address(ao_usb_setup.value);
                                break;
                        case AO_USB_REQ_GET_DESCRIPTOR:
-                               printf ("get descriptor %d\n", ao_usb_setup.value);
+                               debug ("get descriptor %d\n", ao_usb_setup.value);
                                ao_usb_get_descriptor(ao_usb_setup.value);
                                break;
                        case AO_USB_REQ_GET_CONFIGURATION:
-                               printf ("get configuration %d\n", ao_usb_configuration);
+                               debug ("get configuration %d\n", ao_usb_configuration);
                                ao_usb_ep0_queue_byte(ao_usb_configuration);
                                break;
                        case AO_USB_REQ_SET_CONFIGURATION:
                                ao_usb_configuration = ao_usb_setup.value;
-                               printf ("set configuration %d\n", ao_usb_configuration);
+                               debug ("set configuration %d\n", ao_usb_configuration);
                                ao_usb_set_configuration();
                                break;
                        }
@@ -299,7 +305,7 @@ ao_usb_ep0_setup(void)
 #ifndef AVR
                        #pragma disable_warning 110
 #endif
-                       printf ("Interface setup packet\n");
+                       debug ("Interface setup packet\n");
                        switch(ao_usb_setup.request) {
                        case AO_USB_REQ_GET_STATUS:
                                ao_usb_ep0_queue_byte(0);
@@ -313,7 +319,7 @@ ao_usb_ep0_setup(void)
                        }
                        break;
                case AO_USB_RECIP_ENDPOINT:
-                       printf ("Endpoint setup packet\n");
+                       debug ("Endpoint setup packet\n");
                        switch(ao_usb_setup.request) {
                        case AO_USB_REQ_GET_STATUS:
                                ao_usb_ep0_queue_byte(0);
@@ -324,15 +330,15 @@ ao_usb_ep0_setup(void)
                }
                break;
        case AO_USB_TYPE_CLASS:
-               printf ("Class setup packet\n");
+               debug ("Class setup packet\n");
                switch (ao_usb_setup.request) {
                case SET_LINE_CODING:
-                       printf ("set line coding\n");
+                       debug ("set line coding\n");
                        ao_usb_ep0_out_len = 7;
                        ao_usb_ep0_out_data = (__xdata uint8_t *) &ao_usb_line_coding;
                        break;
                case GET_LINE_CODING:
-                       printf ("get line coding\n");
+                       debug ("get line coding\n");
                        ao_usb_ep0_in_len = 7;
                        ao_usb_ep0_in_data = (uint8_t *) &ao_usb_line_coding;
                        break;
@@ -344,7 +350,7 @@ ao_usb_ep0_setup(void)
        if (ao_usb_ep0_state != AO_USB_EP0_DATA_OUT) {
                if (ao_usb_setup.length < ao_usb_ep0_in_len)
                        ao_usb_ep0_in_len = ao_usb_setup.length;
-               printf ("Start ep0 in delivery %d\n", ao_usb_ep0_in_len);
+               debug ("Start ep0 in delivery %d\n", ao_usb_ep0_in_len);
                ao_usb_ep0_set_in_pending(1);
        }
 }
@@ -355,21 +361,21 @@ ao_usb_ep0(void)
 {
        uint8_t intx, udint;
 
-       printf ("usb task started\n");
+       debug ("usb task started\n");
        ao_usb_ep0_state = AO_USB_EP0_IDLE;
        for (;;) {
                cli();
                for (;;) {
                        udint = UDINT;
                        UDINT = 0;
-//                     printf ("UDINT %02x\n", udint);
+//                     debug ("UDINT %02x\n", udint);
                        if (udint & (1 << EORSTI)) {
                                ao_usb_configuration = 0;
                                ao_usb_set_ep0();
                        }
                        UENUM = 0;
                        intx = UEINTX;
-//                     printf ("UEINTX %02x\n", intx);
+//                     debug ("UEINTX %02x\n", intx);
                        if (intx & ((1 << RXSTPI) | (1 << RXOUTI)))
                                break;
                        if ((intx & (1 << TXINI))) {
@@ -384,11 +390,11 @@ ao_usb_ep0(void)
                                        UEIENX = ((1 << RXSTPE) | (1 << RXOUTE));       /* Disable IN interrupt */
                                }
                        }
-//                     printf ("usb task sleeping...\n");
+//                     debug ("usb task sleeping...\n");
                        ao_sleep(&ao_usb_task);
                }
                sei();
-//             printf ("UEINTX for ep0 is %02x\n", intx);
+//             debug ("UEINTX for ep0 is %02x\n", intx);
                if (intx & (1 << RXSTPI)) {
                        ao_usb_ep0_setup();
                }
@@ -397,7 +403,7 @@ ao_usb_ep0(void)
                        ao_usb_ep0_set_in_pending(1);
                }
                if (intx & (1 << TXINI) && ao_usb_ep0_in_pending) {
-                       printf ("continue sending ep0 IN data\n");
+                       debug ("continue sending ep0 IN data\n");
                        ao_usb_ep0_flush();
                }
        }
@@ -459,8 +465,6 @@ ao_usb_putchar(char c) __critical __reentrant
        if (!ao_usb_running)
                return;
 
-       ao_usb_in_flushed = 0;
-
        ao_usb_in_wait();
 
        /* Queue a byte */
@@ -470,6 +474,7 @@ ao_usb_putchar(char c) __critical __reentrant
        /* Send the packet when full */
        if ((UEINTX & (1 << RWAL)) == 0)
                ao_usb_in_send();
+       ao_usb_in_flushed = 0;
 }
 
 static char
@@ -478,10 +483,13 @@ _ao_usb_pollchar(void)
        char c;
        uint8_t intx;
 
+       if (!ao_usb_running)
+               return AO_READ_AGAIN;
+
        for (;;) {
                UENUM = AO_USB_OUT_EP;
                intx = UEINTX;
-               printf("usb_pollchar UEINTX %02d\n", intx);
+               debug("usb_pollchar UEINTX %02d\n", intx);
                if (intx & (1 << RWAL))
                        break;
 
@@ -530,7 +538,9 @@ ISR(USB_COM_vect)
 {
        uint8_t i = UEINT;
 
+#ifdef AO_LED_RED
        ao_led_toggle(AO_LED_RED);
+#endif
        UEINT = 0;
        if (i & (1 << 0))
                ao_wakeup(&ao_usb_task);
@@ -544,7 +554,10 @@ ISR(USB_COM_vect)
 #define AO_PAD_REGULATOR_INIT  (1 << UVREGE)   /* Turn on pad regulator */
 #endif
 #if AVR_VCC_3V3
-#define AO_PAD_REGULATOR_INIT  0               /* Turn off pad regulator */
+/* TeleScience V0.1 has a hardware bug -- UVcc is hooked up, but UCap is not
+ * Make this work by running power through UVcc to the USB system
+ */
+#define AO_PAD_REGULATOR_INIT  (1 << UVREGE)   /* Turn off pad regulator */
 #endif
 
 #if AVR_CLOCK == 16000000UL
@@ -598,11 +611,14 @@ ao_usb_enable(void)
 
        ao_usb_configuration = 0;
 
-       printf ("ao_usb_enable\n");
+       debug ("ao_usb_enable\n");
 
+       debug ("UHWCON %02x USBCON %02x PLLCSR %02x UDIEN %02x\n",
+              UHWCON, USBCON, PLLCSR, UDIEN);
        UDCON = (0 << DETACH);  /* Clear the DETACH bit to plug into the bus */
 }
 
+#if USB_DEBUG
 struct ao_task __xdata ao_usb_echo_task;
 
 static void
@@ -616,14 +632,15 @@ ao_usb_echo(void)
                ao_usb_flush();
        }
 }
+#endif
 
 void
 ao_usb_init(void)
 {
        ao_usb_enable();
 
-       printf ("ao_usb_init\n");
+       debug ("ao_usb_init\n");
        ao_add_task(&ao_usb_task, ao_usb_ep0, "usb");
-       ao_add_task(&ao_usb_echo_task, ao_usb_echo, "usb echo");
-//     ao_add_stdio(ao_usb_pollchar, ao_usb_putchar, ao_usb_flush);
+//     ao_add_task(&ao_usb_echo_task, ao_usb_echo, "usb echo");
+       ao_add_stdio(ao_usb_pollchar, ao_usb_putchar, ao_usb_flush);
 }
index 0f46da08ffeb4e127c5a5b91f96b96f73cdff581..8c9c7bd70eaeac0c0ce465d5cba50e25ec31c34c 100644 (file)
@@ -22,7 +22,6 @@
 #include <avr/io.h>
 #include <avr/interrupt.h>
 
-#define TEENSY 1
 #if TEENSY
 #define F_CPU 16000000UL       // 16 MHz
 #else
diff --git a/src-avr/telescience/Makefile b/src-avr/telescience/Makefile
new file mode 100644 (file)
index 0000000..a5bea67
--- /dev/null
@@ -0,0 +1,107 @@
+#
+# AltOS build
+#
+#
+vpath %.c ..
+vpath %.h ..
+vpath make-altitude ..
+vpath make-kalman ..
+vpath kalman.5c ../kalman
+vpath kalman_filter.5c ../kalman
+vpath load_csv.5c ../kalman
+vpath matrix.5c ../kalman
+vpath ao-make-product.5c ..
+
+MCU=atmega32u4
+DUDECPUTYPE=m32u4
+#PROGRAMMER=stk500v2 -P usb
+PROGRAMMER=usbtiny
+LOADCMD=avrdude
+LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w:
+CC=avr-gcc
+OBJCOPY=avr-objcopy
+
+ifndef VERSION
+include ../Version
+endif
+
+INC = \
+       ao.h \
+       ao_usb.h \
+       ao_pins.h \
+       altitude.h \
+       ao_kalman.h
+
+#
+# Common AltOS sources
+#
+TELESCIENCE_STORAGE= \
+       ao_m25.c \
+       ao_spi_usart.c \
+       ao_storage.c \
+
+ALTOS_SRC = \
+       ao_cmd.c \
+       ao_mutex.c \
+       ao_panic.c \
+       ao_product.c \
+       ao_stdio.c \
+       ao_task.c \
+       ao_timer.c \
+       ao_led.c \
+       ao_usb_avr.c
+
+PRODUCT=TeleScience-v0.1
+MCU=atmega32u4
+PRODUCT_DEF=-DTELESCIENCE
+IDPRODUCT=0x000a
+CFLAGS += -g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues $(PRODUCT_DEF) -I. -DAVR
+
+NICKLE=nickle
+
+PROG=telescience-v0.1
+
+SRC=$(ALTOS_SRC) ao_telescience.c
+OBJ=$(SRC:.c=.o)
+
+V=0
+# The user has explicitly enabled quiet compilation.
+ifeq ($(V),0)
+quiet = @printf "  $1 $2 $@\n"; $($1)
+endif
+# Otherwise, print the full command line.
+quiet ?= $($1)
+
+all: $(PROG)
+
+$(PROG): Makefile $(OBJ)
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ)
+
+$(PROG).hex: $(PROG)
+       avr-size $(PROG)
+       $(OBJCOPY) -R .eeprom -O ihex $(PROG) $@
+
+
+load: $(PROG).hex
+       $(LOADCMD) $(LOADARG)$(PROG).hex
+
+../altitude.h: make-altitude
+       nickle $< > $@
+
+ao_product.h: ao-make-product.5c ../Version
+       $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@
+
+ao_product.rel: ao_product.c ao_product.h
+       $(call quiet,CC) -c $(CFLAGS) -D PRODUCT_DEFS='\"ao_product.h\"' -o$@ $<
+
+distclean:     clean
+
+clean:
+       rm -f $(OBJ)
+       rm -f ao_product.h
+
+install:
+
+uninstall:
+
+$(OBJ): ao.h ao_product.h
\ No newline at end of file