diff --git a/arch/pjrc-8051/src/Makefile b/arch/pjrc-8051/src/Makefile index 51eaf269bf..9a270a895a 100644 --- a/arch/pjrc-8051/src/Makefile +++ b/arch/pjrc-8051/src/Makefile @@ -48,8 +48,7 @@ CSRCS = up_initialize.c up_idle.c up_interruptcontext.c \ up_releasepending.c up_reprioritizertr.c \ up_exit.c up_assert.c up_allocateheap.c \ up_irq.c up_savecontext.c up_restorecontext.c \ - up_timerisr.c up_putc.c up_debug.c up_leds.c \ - up_delay.c + up_timerisr.c up_putc.c up_debug.c up_delay.c COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(SSRCS) $(CSRCS) OBJS = $(AOBJS) $(COBJS) @@ -70,6 +69,8 @@ TESTOBJS = $(TESTSRCS:.c=$(OBJEXT)) TESTLINKOBJS = up_head$(OBJEXT) TESTEXTRAOBJS = up_savecontext$(OBJEXT) up_restorecontext$(OBJEXT) +BOARDDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src/board + IRAM_SIZE = 0x100 DEF_STACK_BASE = 0x24 LDFLAGS = --model-large --nostdlib \ @@ -163,16 +164,23 @@ $(SDCCLIBDIR)/libmysdcc.lib: $(SDCCLIBDIR)/libsdcc.lib > libmysdcc.lib @sudo mv -f libmysdcc.lib $(SDCCLIBDIR)/libmysdcc.lib +# This builds the libboard library in the board/ subdirectory + +board/libboard$(LIBEXT): + $(MAKE) -C board TOPDIR=$(TOPDIR) libboard$(LIBEXT) + # This target builds the final executable -pass1.ihx: up_mem.h $(SDCCLIBDIR)/libmysdcc.lib $(LINKOBJS) - $(CC) $(LDFLAGS) $(LDPATHES) $(SDCCPATH) $(LINKOBJS) $(LDLIBS) $(SDCCLIBS) -o $@ +pass1.ihx: up_mem.h $(SDCCLIBDIR)/libmysdcc.lib $(LINKOBJS) board/libboard$(LIBEXT) + $(CC) $(LDFLAGS) $(LDPATHES) -L$(BOARDDIR) $(SDCCPATH) $(LINKOBJS) \ + $(LDLIBS) -llibboard$(LIBEXT) $(SDCCLIBS) -o $@ @rm -f up_mem.h @rm -f up_allocateheap$(OBJEXT) libarch$(LIBEXT) @$(MAKE) TOPDIR=$(TOPDIR) libarch$(LIBEXT) nuttx.ihx: up_mem.h $(SDCCLIBDIR)/libmysdcc.lib $(LINKOBJS) - $(CC) $(LDFLAGS) $(LDPATHES) $(SDCCPATH) $(LINKOBJS) $(LDLIBS) $(SDCCLIBS) -o $@ + $(CC) $(LDFLAGS) $(LDPATHES) -L$(BOARDDIR) $(SDCCPATH) $(LINKOBJS) \ + $(LDLIBS) -llibboard$(LIBEXT) $(SDCCLIBS) -o $@ nuttx$(EXEEXT): pass1.ihx nuttx.ihx @rm -f pass1.* @@ -191,17 +199,26 @@ irqtest: # Build dependencies .depend: Makefile up_mem.h $(DEPSRCS) + @if [ -e board/Makefile ]; then \ + $(MAKE) -C board TOPDIR=$(TOPDIR) depend ; \ + if $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep touch $@ depend: .depend clean: + @if [ -e board/Makefile ]; then \ + $(MAKE) -C board TOPDIR=$(TOPDIR) clean ; \ + fi rm -f libarch$(LIBEXT) up_mem.h rm -f *.asm *.rel *.lst *.rst *.sym *.adb *.lnk *.map *.mem *.ihx *.hex *~ if [ ! -z "$(OBJEXT)" ]; then rm -f *$(OBJEXT); fi distclean: clean + @if [ -e board/Makefile ]; then \ + $(MAKE) -C board TOPDIR=$(TOPDIR) distclean ; \ + fi rm -f Make.dep .depend -include Make.dep diff --git a/arch/pjrc-8051/src/up_internal.h b/arch/pjrc-8051/src/up_internal.h index 760a0ff290..90ba556e96 100644 --- a/arch/pjrc-8051/src/up_internal.h +++ b/arch/pjrc-8051/src/up_internal.h @@ -134,7 +134,7 @@ extern void up_dumpframe(FAR struct xcptcontext *context); # define up_dumpframe(x) #endif -/* Defined in up_leds.c */ +/* Defined in board/up_leds.c */ #ifdef CONFIG_ARCH_LEDS extern void up_ledinit(void); diff --git a/configs/pjrc-8051/src/Makefile b/configs/pjrc-8051/src/Makefile index 5f2bd80831..c71e28cfb6 100644 --- a/configs/pjrc-8051/src/Makefile +++ b/configs/pjrc-8051/src/Makefile @@ -40,12 +40,14 @@ CFLAGS += -I$(TOPDIR)/sched ASRCS = AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = +CSRCS = up_leds.c COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) OBJS = $(AOBJS) $(COBJS) +CFLAGS += -I $(TOPDIR)/arch/$(CONFIG_ARCH)/src + all: libboard$(LIBEXT) $(AOBJS): %$(OBJEXT): %.S @@ -67,7 +69,8 @@ libboard$(LIBEXT): $(OBJS) depend: .depend clean: - rm -f libboard$(LIBEXT) *~ + rm -f libboard$(LIBEXT) + rm -f *.asm *.rel *.lst *.rst *.sym *.adb *.lnk *.map *.mem *.ihx *.hex *~ if [ ! -z "$(OBJEXT)" ]; then rm -f *$(OBJEXT); fi distclean: clean diff --git a/configs/pjrc-8051/src/up_leds.c b/configs/pjrc-8051/src/up_leds.c new file mode 100644 index 0000000000..c7730ac3ef --- /dev/null +++ b/configs/pjrc-8051/src/up_leds.c @@ -0,0 +1,207 @@ +/************************************************************ + * up_leds.c + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include +#include +#include "up_internal.h" + +/************************************************************ + * Definitions + ************************************************************/ + +#define RESET_KLUDGE_NEEDED 1 + +/************************************************************ + * Private Data + ************************************************************/ + +static ubyte g_ledstate; + +/************************************************************ + * Private Functions + ************************************************************/ + +#if defined(CONFIG_LED_DEBUG) && defined(CONFIG_ARCH_LEDS) +static void _up_puthex(ubyte hex) __naked +{ + hex; /* To avoid unreferenced argument warning */ + _asm + mov a, dpl + ljmp PM2_ENTRY_PHEX + _endasm; +} + +static void _up_putch(ubyte ch) __naked +{ + _asm + mov a, dpl + ljmp PM2_ENTRY_COUT + _endasm; +} + +static void _up_putnl(void) __naked +{ + _asm + ljmp PM2_ENTRY_NEWLINE + _endasm; +} + +# define _up_showledinit() \ + _up_putch('I'); \ + _up_puthex(g_ledstate); _up_putch(':'); \ + _up_puthex(p82c55_port_e); _up_putnl(); + +# define _up_showledreset() \ + _up_putch('R'); \ + _up_puthex(led); _up_putch(':'); \ + _up_puthex(g_ledstate); _up_putch(':'); \ + _up_puthex(p82c55_port_e); _up_putnl(); + +# define _up_showledon() \ + _up_putch('+'); \ + _up_puthex(led); _up_putch(':'); \ + _up_puthex(g_ledstate); _up_putch(':'); \ + _up_puthex(p82c55_port_e); _up_putnl(); + +# define _up_showledoff() \ + _up_putch('-'); \ + _up_puthex(led); _up_putch(':'); \ + _up_puthex(g_ledstate); _up_putch(':'); \ + _up_puthex(p82c55_port_e); _up_putnl(); + +#else + +# define _up_showledinit() +# define _up_showledreset() +# define _up_showledon() +# define _up_showledoff() + +#endif + +/************************************************************ + * Public Funtions + ************************************************************/ + +/************************************************************ + * Name: up_ledinit + ************************************************************/ + +#ifdef CONFIG_ARCH_LEDS +void up_ledinit(void) +{ + /* Set all ports as outputs */ + + p82c55_def_config = 128; + + /* Turn LED 1-7 off; turn LED 0 on */ + + g_ledstate = 0xfe; + p82c55_port_e = g_ledstate; + + _up_showledinit(); +} + +/************************************************************ + * Name: up_ledon + ************************************************************/ + +void up_ledon(ubyte led) +{ + /* This may be called from an interrupt handler */ + + irqstate_t flags = irqsave(); + +#ifdef RESET_KLUDGE_NEEDED + /* I don't understand why this happens yet, but sometimes + * it is necessary to reconfigure port E. + */ + + if (g_ledstate != p82c55_port_e) + { + _up_showledreset(); + p82c55_def_config = 128; + } +#endif + + /* Clear the bit in port E corresponding to LED to turn it on */ + + if (led < 8) + { + g_ledstate &= ~(g_ntobit[led]); + p82c55_port_e = g_ledstate; + } + + _up_showledon(); + irqrestore(flags); +} + +/************************************************************ + * Name: up_ledoff + ************************************************************/ + +void up_ledoff(ubyte led) +{ + /* This may be called from an interrupt handler */ + + irqstate_t flags = irqsave(); + +#ifdef RESET_KLUDGE_NEEDED + /* I don't understand why this happens yet, but sometimes + * it is necessary to reconfigure port E. + */ + + if (g_ledstate != p82c55_port_e) + { + _up_showledreset(); + p82c55_def_config = 128; + } +#endif + + /* Set the bit in port E corresponding to LED to turn it off */ + + if (led < 8) + { + g_ledstate |= g_ntobit[led]; + p82c55_port_e = g_ledstate; + } + + _up_showledoff(); + irqrestore(flags); +} +#endif /* CONFIG_ARCH_LEDS */