This shrinks the application quite a bit, and should make it faster as well.
Signed-off-by: Keith Packard <keithp@keithp.com>
--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
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)
/* 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)
#define AO_NUM_TASKS 10 /* maximum number of tasks */
-#define ao_interrupt_disable() (EA = 0)
-#define ao_interrupt_enable() (EA = 1)
-
/*
ao_task.c
*/
void
ao_usb_init(void);
+/*
+ * ao_cmd.c
+ */
+void
+ao_cmd_init(void);
+
#endif /* _AO_H_ */
--- /dev/null
+/*
+ * 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();
+}
int
ao_sleep(__xdata void *wchan)
{
- ao_interrupt_disable();
+ __critical {
ao_cur_task->wchan = wchan;
- ao_interrupt_enable();
+ }
ao_yield();
}
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;
void
blink_1(void)
{
- static struct ao_adc adc;
+ static __xdata struct ao_adc adc;
for (;;) {
ao_sleep(&ao_adc_ring);
void
beep(void)
{
- static struct ao_adc adc;
+ static __xdata struct ao_adc adc;
for (;;) {
ao_delay(AO_SEC_TO_TICKS(1));
{
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();
}
}
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();
}
#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;
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;
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) {
}
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)
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;
USBINDEX = AO_USB_OUT_EP;
USBCSOL &= ~USBCSOL_OUTPKT_RDY;
}
- ao_interrupt_enable();
return c;
}