Switch from --model-large to --model-small
authorKeith Packard <keithp@keithp.com>
Tue, 14 Apr 2009 18:04:09 +0000 (11:04 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 14 Apr 2009 18:04:09 +0000 (11:04 -0700)
This shrinks the application quite a bit, and should make it faster as well.

Signed-off-by: Keith Packard <keithp@keithp.com>
Makefile
ao.h
ao_main.c [new file with mode: 0644]
ao_task.c
ao_test.c
ao_usb.c

index ab1a253be1ba4fb913d01b9b1b84e4a04ff70218..9284ed259be8b0244c5469f57df1884adba95825 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,14 +4,9 @@ NO_OPT=--nogcse --noinvariant --noinduction --nojtbound --noloopreverse \
        --nolabelopt --nooverlay --peep-asm
 DEBUG=--debug
 
-CFLAGS=--model-large $(DEBUG) --less-pedantic \
-       --no-peep --int-long-reent --float-reent \
+CFLAGS=--model-small $(DEBUG) --less-pedantic
 
 LDFLAGS=--out-fmt-ihx
-LDFLAGS_RAM=$(LDFLAGS) --code-loc 0xf000 --code-size 0x800 \
-       --xram-loc 0xf800 --xram-size 0x700 --iram-size 0xff
-
-
 LDFLAGS_FLASH=$(LDFLAGS) --code-loc 0x0000 --code-size 0x8000 \
        --xram-loc 0xf000 --xram-size 0xf00 --iram-size 0xff
 
@@ -22,12 +17,13 @@ INC = \
 SRC = \
        ao_adc.c \
        ao_beep.c \
+       ao_cmd.c \
        ao_led.c \
+       ao_panic.c \
        ao_task.c \
        ao_timer.c \
        ao_usb.c \
-       ao_panic.c \
-       ao_test.c \
+       ao_main.c \
        _bp.c
        
 ADB=$(SRC:.c=.adb)
diff --git a/ao.h b/ao.h
index 7cb0fbfe7786c9ff7203a6443a01efb6823f5576..8a344ccab2b19847d93da807f2d286db3a9d8d0c 100644 (file)
--- a/ao.h
+++ b/ao.h
@@ -29,7 +29,7 @@
 /* Stack runs from above the allocated __data space to 0xfe, which avoids
  * writing to 0xff as that triggers the stack overflow indicator
  */
-#define AO_STACK_START 0x28
+#define AO_STACK_START 0x4b
 #define AO_STACK_END   0xfe
 #define AO_STACK_SIZE  (AO_STACK_END - AO_STACK_START + 1)
 
@@ -42,9 +42,6 @@ struct ao_task {
 
 #define AO_NUM_TASKS           10      /* maximum number of tasks */
 
-#define ao_interrupt_disable() (EA = 0)
-#define ao_interrupt_enable()  (EA = 1)
-
 /*
  ao_task.c
  */
@@ -254,4 +251,10 @@ ao_usb_isr(void) interrupt 6;
 void
 ao_usb_init(void);
 
+/*
+ * ao_cmd.c
+ */
+void
+ao_cmd_init(void);
+
 #endif /* _AO_H_ */
diff --git a/ao_main.c b/ao_main.c
new file mode 100644 (file)
index 0000000..2cf6c80
--- /dev/null
+++ b/ao_main.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2009 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)
+{
+       CLKCON = 0;
+       while (!(SLEEP & SLEEP_XOSC_STB))
+               ;
+
+       ao_timer_init();
+       ao_adc_init();
+       ao_beep_init();
+       ao_led_init();
+       ao_usb_init();
+       ao_cmd_init();
+       ao_start_scheduler();
+}
index 24bd319ac563b69d33dd77999a0a532763eaa592..2e0a8b33207921e87feee02f0382240429ab0c5e 100644 (file)
--- a/ao_task.c
+++ b/ao_task.c
@@ -162,9 +162,9 @@ ao_yield(void) _naked
 int
 ao_sleep(__xdata void *wchan)
 {
-       ao_interrupt_disable();
+       __critical {
        ao_cur_task->wchan = wchan;
-       ao_interrupt_enable();
+       }
        ao_yield();
 }
 
@@ -181,11 +181,6 @@ ao_wakeup(__xdata void *wchan)
 void
 ao_start_scheduler(void)
 {
-       ao_timer_init();
-       ao_adc_init();
-       ao_beep_init();
-       ao_led_init();
-       ao_usb_init();
 
        ao_cur_task_id = AO_NO_TASK;
        ao_cur_task = NULL;
index 5d50ab8332e13c1cc4d02b027e07c7639016b884..0fdfcfa1583fd1bfb21a600b7754f5398dd7470c 100644 (file)
--- a/ao_test.c
+++ b/ao_test.c
@@ -50,7 +50,7 @@ blink_0(void)
 void
 blink_1(void)
 {
-       static struct ao_adc adc;
+       static __xdata struct ao_adc adc;
 
        for (;;) {
                ao_sleep(&ao_adc_ring);
@@ -74,7 +74,7 @@ wakeup(void)
 void
 beep(void)
 {
-       static struct ao_adc adc;
+       static __xdata struct ao_adc adc;
 
        for (;;) {
                ao_delay(AO_SEC_TO_TICKS(1));
@@ -89,11 +89,11 @@ echo(void)
 {
        uint8_t c;
        for (;;) {
+               ao_usb_flush();
                c = ao_usb_getchar();
                ao_usb_putchar(c);
                if (c == '\r')
                        ao_usb_putchar('\n');
-               ao_usb_flush();
        }
 }
 
@@ -104,10 +104,16 @@ main(void)
        while (!(SLEEP & SLEEP_XOSC_STB))
                ;
 
-       ao_add_task(&blink_0_task, blink_0);
-       ao_add_task(&blink_1_task, blink_1);
-       ao_add_task(&wakeup_task, wakeup);
-       ao_add_task(&beep_task, beep);
+//     ao_add_task(&blink_0_task, blink_0);
+//     ao_add_task(&blink_1_task, blink_1);
+//     ao_add_task(&wakeup_task, wakeup);
+//     ao_add_task(&beep_task, beep);
        ao_add_task(&echo_task, echo);
+       ao_timer_init();
+       ao_adc_init();
+       ao_beep_init();
+       ao_led_init();
+       ao_usb_init();
+       
        ao_start_scheduler();
 }
index 20a853a45e43d167d10545e88b79ab6ab286dec1..dd0471d182d3adac0784b42616f053a232bc5320 100644 (file)
--- a/ao_usb.c
+++ b/ao_usb.c
@@ -32,8 +32,8 @@ struct ao_task __xdata ao_usb_task;
 #define AO_USB_IN_SIZE         256
 #define AO_USB_OUT_SIZE                128
 
-static uint16_t        ao_usb_in_bytes;
-static uint16_t        ao_usb_out_bytes;
+static __xdata uint16_t        ao_usb_in_bytes;
+static __xdata uint16_t        ao_usb_out_bytes;
 static __data uint8_t  ao_usb_iif;
 static __data uint8_t  ao_usb_oif;
 
@@ -65,7 +65,7 @@ struct ao_usb_setup {
        uint16_t        value;
        uint16_t        index;
        uint16_t        length;
-} ao_usb_setup;
+} __xdata ao_usb_setup;
 
 __data uint8_t ao_usb_ep0_state;
 uint8_t * __data ao_usb_ep0_in_data;
@@ -421,15 +421,13 @@ ao_usb_ep0(void)
 
        ao_usb_ep0_state = AO_USB_EP0_IDLE;
        for (;;) {
-               ao_interrupt_disable();
-               for (;;) {
+               __critical for (;;) {
                        if (ao_usb_iif & 1) {
                                ao_usb_iif &= ~1;
                                break;
                        }
                        ao_sleep(&ao_usb_task);
                }
-               ao_interrupt_enable();
                USBINDEX = 0;
                cs0 = USBCS0;
                if (cs0 & USBCS0_SETUP_END) {
@@ -466,21 +464,18 @@ ao_usb_ep0(void)
 }
 
 void
-ao_usb_flush(void)
+ao_usb_flush(void) __critical
 {
-       ao_interrupt_disable();
        if (ao_usb_in_bytes) {
                USBINDEX = AO_USB_IN_EP;
                USBCSIL |= USBCSIL_INPKT_RDY;
                ao_usb_in_bytes = 0;
        }
-       ao_interrupt_enable();
 }
 
 void
-ao_usb_putchar(uint8_t c)
+ao_usb_putchar(uint8_t c) __critical
 {
-       ao_interrupt_disable();
        for (;;) {
                USBINDEX = AO_USB_IN_EP;
                if ((USBCSIL & USBCSIL_INPKT_RDY) == 0)
@@ -488,16 +483,17 @@ ao_usb_putchar(uint8_t c)
                ao_sleep(&ao_usb_in_bytes);
        }
        USBFIFO[AO_USB_IN_EP << 1] = c;
-       if (++ao_usb_in_bytes == AO_USB_IN_SIZE)
-               ao_usb_flush();
-       ao_interrupt_enable();
+       if (++ao_usb_in_bytes == AO_USB_IN_SIZE) {
+               USBINDEX = AO_USB_IN_EP;
+               USBCSIL |= USBCSIL_INPKT_RDY;
+               ao_usb_in_bytes = 0;
+       }
 }
 
 uint8_t
-ao_usb_getchar(void)
+ao_usb_getchar(void) __critical
 {
        uint8_t c;
-       ao_interrupt_disable();
        while (ao_usb_out_bytes == 0) {
                for (;;) {
                        USBINDEX = AO_USB_OUT_EP;
@@ -513,7 +509,6 @@ ao_usb_getchar(void)
                USBINDEX = AO_USB_OUT_EP;
                USBCSOL &= ~USBCSOL_OUTPKT_RDY;
        }
-       ao_interrupt_enable();
        return c;
 }