From d7ddd75cbe92d10263edaf505f8569834bf35c6a Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 25 Feb 2011 00:00:04 +0000 Subject: Rename arch/pjrc-8051 to arch/8051 git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3315 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/8051/include/arch.h | 85 +++++ nuttx/arch/8051/include/irq.h | 206 +++++++++++ nuttx/arch/8051/include/limits.h | 79 +++++ nuttx/arch/8051/include/types.h | 98 +++++ nuttx/arch/8051/src/Makefile | 223 ++++++++++++ nuttx/arch/8051/src/up_allocateheap.c | 89 +++++ nuttx/arch/8051/src/up_assert.c | 141 ++++++++ nuttx/arch/8051/src/up_blocktask.c | 172 +++++++++ nuttx/arch/8051/src/up_debug.c | 255 +++++++++++++ nuttx/arch/8051/src/up_delay.c | 93 +++++ nuttx/arch/8051/src/up_exit.c | 105 ++++++ nuttx/arch/8051/src/up_head.S | 471 +++++++++++++++++++++++++ nuttx/arch/8051/src/up_idle.c | 96 +++++ nuttx/arch/8051/src/up_initialize.c | 144 ++++++++ nuttx/arch/8051/src/up_initialstate.c | 119 +++++++ nuttx/arch/8051/src/up_internal.h | 152 ++++++++ nuttx/arch/8051/src/up_interruptcontext.c | 70 ++++ nuttx/arch/8051/src/up_irq.c | 152 ++++++++ nuttx/arch/8051/src/up_irqtest.c | 273 ++++++++++++++ nuttx/arch/8051/src/up_putc.c | 81 +++++ nuttx/arch/8051/src/up_releasepending.c | 135 +++++++ nuttx/arch/8051/src/up_reprioritizertr.c | 185 ++++++++++ nuttx/arch/8051/src/up_restorecontext.c | 296 ++++++++++++++++ nuttx/arch/8051/src/up_savecontext.c | 362 +++++++++++++++++++ nuttx/arch/8051/src/up_timerisr.c | 147 ++++++++ nuttx/arch/8051/src/up_unblocktask.c | 166 +++++++++ nuttx/arch/README.txt | 2 +- nuttx/arch/pjrc-8051/include/arch.h | 85 ----- nuttx/arch/pjrc-8051/include/irq.h | 206 ----------- nuttx/arch/pjrc-8051/include/limits.h | 79 ----- nuttx/arch/pjrc-8051/include/types.h | 98 ----- nuttx/arch/pjrc-8051/src/Makefile | 223 ------------ nuttx/arch/pjrc-8051/src/up_allocateheap.c | 89 ----- nuttx/arch/pjrc-8051/src/up_assert.c | 141 -------- nuttx/arch/pjrc-8051/src/up_blocktask.c | 172 --------- nuttx/arch/pjrc-8051/src/up_debug.c | 255 ------------- nuttx/arch/pjrc-8051/src/up_delay.c | 93 ----- nuttx/arch/pjrc-8051/src/up_exit.c | 105 ------ nuttx/arch/pjrc-8051/src/up_head.S | 471 ------------------------- nuttx/arch/pjrc-8051/src/up_idle.c | 96 ----- nuttx/arch/pjrc-8051/src/up_initialize.c | 144 -------- nuttx/arch/pjrc-8051/src/up_initialstate.c | 119 ------- nuttx/arch/pjrc-8051/src/up_internal.h | 152 -------- nuttx/arch/pjrc-8051/src/up_interruptcontext.c | 70 ---- nuttx/arch/pjrc-8051/src/up_irq.c | 152 -------- nuttx/arch/pjrc-8051/src/up_irqtest.c | 273 -------------- nuttx/arch/pjrc-8051/src/up_putc.c | 81 ----- nuttx/arch/pjrc-8051/src/up_releasepending.c | 135 ------- nuttx/arch/pjrc-8051/src/up_reprioritizertr.c | 185 ---------- nuttx/arch/pjrc-8051/src/up_restorecontext.c | 296 ---------------- nuttx/arch/pjrc-8051/src/up_savecontext.c | 362 ------------------- nuttx/arch/pjrc-8051/src/up_timerisr.c | 147 -------- nuttx/arch/pjrc-8051/src/up_unblocktask.c | 166 --------- 53 files changed, 4396 insertions(+), 4396 deletions(-) create mode 100644 nuttx/arch/8051/include/arch.h create mode 100644 nuttx/arch/8051/include/irq.h create mode 100644 nuttx/arch/8051/include/limits.h create mode 100644 nuttx/arch/8051/include/types.h create mode 100644 nuttx/arch/8051/src/Makefile create mode 100644 nuttx/arch/8051/src/up_allocateheap.c create mode 100644 nuttx/arch/8051/src/up_assert.c create mode 100644 nuttx/arch/8051/src/up_blocktask.c create mode 100644 nuttx/arch/8051/src/up_debug.c create mode 100644 nuttx/arch/8051/src/up_delay.c create mode 100644 nuttx/arch/8051/src/up_exit.c create mode 100644 nuttx/arch/8051/src/up_head.S create mode 100644 nuttx/arch/8051/src/up_idle.c create mode 100644 nuttx/arch/8051/src/up_initialize.c create mode 100644 nuttx/arch/8051/src/up_initialstate.c create mode 100644 nuttx/arch/8051/src/up_internal.h create mode 100644 nuttx/arch/8051/src/up_interruptcontext.c create mode 100644 nuttx/arch/8051/src/up_irq.c create mode 100644 nuttx/arch/8051/src/up_irqtest.c create mode 100644 nuttx/arch/8051/src/up_putc.c create mode 100644 nuttx/arch/8051/src/up_releasepending.c create mode 100644 nuttx/arch/8051/src/up_reprioritizertr.c create mode 100644 nuttx/arch/8051/src/up_restorecontext.c create mode 100644 nuttx/arch/8051/src/up_savecontext.c create mode 100644 nuttx/arch/8051/src/up_timerisr.c create mode 100644 nuttx/arch/8051/src/up_unblocktask.c delete mode 100644 nuttx/arch/pjrc-8051/include/arch.h delete mode 100644 nuttx/arch/pjrc-8051/include/irq.h delete mode 100644 nuttx/arch/pjrc-8051/include/limits.h delete mode 100644 nuttx/arch/pjrc-8051/include/types.h delete mode 100644 nuttx/arch/pjrc-8051/src/Makefile delete mode 100644 nuttx/arch/pjrc-8051/src/up_allocateheap.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_assert.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_blocktask.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_debug.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_delay.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_exit.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_head.S delete mode 100644 nuttx/arch/pjrc-8051/src/up_idle.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_initialize.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_initialstate.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_internal.h delete mode 100644 nuttx/arch/pjrc-8051/src/up_interruptcontext.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_irq.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_irqtest.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_putc.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_releasepending.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_reprioritizertr.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_restorecontext.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_savecontext.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_timerisr.c delete mode 100644 nuttx/arch/pjrc-8051/src/up_unblocktask.c (limited to 'nuttx/arch') diff --git a/nuttx/arch/8051/include/arch.h b/nuttx/arch/8051/include/arch.h new file mode 100644 index 000000000..1ca504fb8 --- /dev/null +++ b/nuttx/arch/8051/include/arch.h @@ -0,0 +1,85 @@ +/************************************************************************ + * arch.h + * + * Copyright (C) 2007, 2009 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 NuttX 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. + * + ************************************************************************/ + +/* This file should never be included directed but, rather, + * only indirectly through nuttx/arch.h + */ + +#ifndef __ARCH_ARCH_H +#define __ARCH_ARCH_H + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Public Types + ************************************************************************/ + +/************************************************************************ + * Public Variables + ************************************************************************/ + +/************************************************************************ + * Public Function Prototypes + ************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/* The 805x family has a tiny, 256 stack and can be easily + * overflowed. The following macro can be used to instrument + * code to dump the stack pointer at critical locations. + */ + +EXTERN void up_showsp(uint8_t ch) __naked; + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __ARCH_ARCH_H */ + diff --git a/nuttx/arch/8051/include/irq.h b/nuttx/arch/8051/include/irq.h new file mode 100644 index 000000000..29b19d280 --- /dev/null +++ b/nuttx/arch/8051/include/irq.h @@ -0,0 +1,206 @@ +/************************************************************************ + * irq.h + * + * Copyright (C) 2007, 2009 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 NuttX 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. + * + ************************************************************************/ + +/* This file should never be included directed but, rather, + * only indirectly through nuttx/irq.h + */ + +#ifndef __ARCH_IRQ_H +#define __ARCH_IRQ_H + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#ifndef __ASSEMBLY__ +# include +#endif + +/************************************************************************ + * Definitions + ************************************************************************/ + +#define EXT_INT0_IRQ 0 +#define TIMER0_IRQ 1 +#define EXT_INT1_IRQ 2 +#define TIMER1_IRQ 3 +#define UART_IRQ 4 +#define TIMER2_IRQ 5 + +#define NR_IRQS 6 + +/* The stack for all tasks/threads lie at the same position + * in IRAM. On context switches, the STACK contents will be + * copied into the TCB. + */ + +#define IRAM_BASE 0x0000 +#ifdef CONFIG_ARCH_8052 +# define IRAM_SIZE 0x0100 +#else +# define IRAM_SIZE 0x0080 +#endif + +#define STACK_BASE 0x0024 +#define STACK_SIZE (IRAM_SIZE - STACK_BASE) + +/* This is the form of initial stack frame + * + * This initial stack frame will be configured to hold. + * (1) The 16-bit return address of either: + * + * void task_start(void); + * void pthread_start(void) + * + * The return address is stored at the top of stack. + * so that the RETI instruction will work: + * + * PC15-8 <- ((SP)) + * (SP) <- (SP) -1 + * PC7-0 <- ((SP)) + * (SP) <- (SP) -1 + */ + +#define FRAME_RETLS 0 +#define FRAME_RETMS 1 + +/* Then a partial context context save area that can be + * indexed with the following definitions (relative to the + * beginning of the initial frame. + */ + +#define FRAME_ACC 2 +#define FRAME_IE 3 +#define FRAME_DPL 4 +#define FRAME_DPH 5 + +#define FRAME_SIZE 6 + +/* The remaining registers are not saved on the stack (due + * to the limited stack size of the 8051/2) but in an array + * in the TCB: + */ + +#define REGS_B 0 +#define REGS_R2 1 +#define REGS_R3 2 +#define REGS_R4 3 +#define REGS_R5 4 +#define REGS_R6 5 +#define REGS_R7 6 +#define REGS_R0 7 +#define REGS_R1 8 +#define REGS_PSW 9 +#define REGS_BP 10 + +#define REGS_SIZE 11 + +/* Note that the stack pointer is not saved. Rather, the + * size of the saved stack frame is saved in the 'nbytes' + * field. Since that stack begins at a fixed location, the + * top-of-stack pointer can be derived from the saved size. + */ + +/* These are offsets into struct xcptcontext that can be + * used from assembly language to access the structure. + */ + +#define XCPT_NBYTES 0 +#define XCPT_STACK 1 +#define XCPT_REGS (STACK_SIZE+1) + +#define XCPT_SIZE (STACK_SIZE+REGS_SIZE+1) + +/************************************************************************ + * Public Types + ************************************************************************/ + +/* This struct defines the way the registers are stored */ + +#ifndef __ASSEMBLY__ +struct xcptcontext +{ + /* This is the number of valid bytes currently saved in + * stack[]. Since that stack begins at a fixed location, + * the top-of-stack pointer can be derived from this size. + */ + + uint8_t nbytes; + + /* This is the saved stack. Space is allocated for the + * entire 256 byte IRAM (minus register and bit usage at + * the beginning). + */ + + uint8_t stack[STACK_SIZE]; + + /* These are save 8051/2 registers. These are saved + * separately from the stack to increase the effective + * stack size. + */ + + uint8_t regs[REGS_SIZE]; +}; +#endif /* __ASSEMBLY */ + +/************************************************************************ + * Public Variables + ************************************************************************/ + +/************************************************************************ + * Public Function Prototypes + ************************************************************************/ + +#ifndef __ASSEMBLY__ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +EXTERN irqstate_t irqsave(void); +EXTERN void irqrestore(irqstate_t flags); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __ASSEMBLY */ +#endif /* __ARCH_IRQ_H */ + diff --git a/nuttx/arch/8051/include/limits.h b/nuttx/arch/8051/include/limits.h new file mode 100644 index 000000000..3344a8d2d --- /dev/null +++ b/nuttx/arch/8051/include/limits.h @@ -0,0 +1,79 @@ +/************************************************************ + * arch/8051/include/limits.h + * + * Copyright (C) 2007, 2009, 2011 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. + * + ************************************************************/ + +#ifndef __ARCH_8051_INCLUDE_LIMITS_H +#define __ARCH_8051_INCLUDE_LIMITS_H + +/************************************************************ + * Included Files + ************************************************************/ + +/************************************************************ + * Definitions + ************************************************************/ + +#define CHAR_BIT 8 +#define SCHAR_MIN 0x80 +#define SCHAR_MAX 0x7f +#define UCHAR_MAX 0xff + +/* These could be different on machines where char is unsigned */ + +#define CHAR_MIN SCHAR_MIN +#define CHAR_MAX SCHAR_MAX + +#define SHRT_MIN 0x8000 +#define SHRT_MAX 0x7fff +#define USHRT_MAX 0xffff + +#define INT_MIN 0x8000 +#define INT_MAX 0x7fff +#define UINT_MAX 0xffff + +/* These change on 32-bit and 64-bit platforms */ + +#define LONG_MAX 0x80000000 +#define LONG_MIN 0x7fffffff +#define ULONG_MAX 0xffffffff + +/* For SDCC, a Generic pointer is 3 bytes in length with the + * first byte holding data space information. + */ + +#define PTR_MIN 0x800000 +#define PTR_MAX 0x7fffff +#define UPTR_MAX 0xffffff + +#endif /* __ARCH_8051_INCLUDE_LIMITS_H */ diff --git a/nuttx/arch/8051/include/types.h b/nuttx/arch/8051/include/types.h new file mode 100644 index 000000000..7495513b2 --- /dev/null +++ b/nuttx/arch/8051/include/types.h @@ -0,0 +1,98 @@ +/************************************************************************ + * arch/8051/include/types.h + * + * Copyright (C) 2007, 2009, 2011 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 NuttX 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. + * + ************************************************************************/ + +/* This file should never be included directed but, rather, + * only indirectly through sys/types.h + */ + +#ifndef __ARCH_8051_INCLUDE_TYPES_H +#define __ARCH_8051_INCLUDE_TYPES_H + +/************************************************************************ + * Included Files + ************************************************************************/ + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Type Declarations + ************************************************************************/ + +#ifndef __ASSEMBLY__ + +/* These are the sizes of the standard integer types. NOTE that these type + * names have a leading underscore character. This file will be included + * (indirectly) by include/stdint.h and typedef'ed to the final name without + * the underscore character. This roundabout way of doings things allows + * the stdint.h to be removed from the include/ directory in the event that + * the user prefers to use the definitions provided by their toolchain header + * files + * + * + * For SDCC, sizeof(int) is 16 and sizeof(long) is 32. + * long long and double are not supported. + */ + +typedef char _int8_t; +typedef unsigned char _uint8_t; + +typedef int _int16_t; +typedef unsigned int _uint16_t; + +typedef long _int32_t; +typedef unsigned long _uint32_t; + +/* For SDCC, a Generic pointer is 3 bytes in length with the + * first byte holding data space information. + */ + +typedef long _intptr_t; +typedef unsigned long _uintptr_t; + +/* This is the size of the interrupt state save returned by + * irqsave() + */ + +typedef unsigned char irqstate_t; + +#endif /* __ASSEMBLY__ */ + +/************************************************************************ + * Global Function Prototypes + ************************************************************************/ + +#endif /* __ARCH_8051_INCLUDE_TYPES_H */ diff --git a/nuttx/arch/8051/src/Makefile b/nuttx/arch/8051/src/Makefile new file mode 100644 index 000000000..9152bfa36 --- /dev/null +++ b/nuttx/arch/8051/src/Makefile @@ -0,0 +1,223 @@ +############################################################################ +# arch/8051/src/Makefile +# +# Copyright (C) 2007, 2008, 2011 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 NuttX 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. +# +############################################################################ + +-include $(TOPDIR)/Make.defs + +CFLAGS += -I$(TOPDIR)/sched +ASFLAGS = -x -j -g -l -s -p +CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) -D__ASSEMBLY__ + +SSRCS = +ASRCS = $(SSRCS:.S=$(ASMEXT)) +AOBJS = $(ASRCS:$(ASMEXT)=$(OBJEXT)) +CSRCS = up_initialize.c up_idle.c up_interruptcontext.c \ + up_initialstate.c up_unblocktask.c up_blocktask.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_delay.c +COBJS = $(CSRCS:.c=$(OBJEXT)) +SRCS = $(SSRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +SDCCLIBDIR = /usr/local/share/sdcc/lib/large-stack-auto +SDCCPATH = -L$(SDCCLIBDIR) +SDCCLIBS = -llibfloat.lib -llibint.lib -lliblong.lib -llibmysdcc.lib -lmcs51.lib + +LINKSSRCS = up_head.S +LINKASRCS = $(LINKSSRCS:.S=$(ASMEXT)) +LINKOBJS = $(LINKASRCS:$(ASMEXT)=$(OBJEXT)) +LINKLIBS = +LDPATHES = $(addprefix -L$(TOPDIR)/,$(dir $(LINKLIBS))) +LDLIBS = $(addprefix -l,$(notdir $(LINKLIBS))) + +TESTSRCS = up_irqtest.c +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 \ + --data-loc $(DEF_STACK_BASE) --iram-size $(IRAM_SIZE) \ + --code-loc 0x2100 --code-size 0x5f40 \ + --xram-loc $(IRAM_SIZE) --xram-size 0x1f00 + +DEPSRCS = $(SRCS) $(LINKSSRCS) + +HEAP1_BASE = ${shell \ + if [ -e pass1.mem ]; then \ + cat pass1.mem | grep "EXTERNAL RAM" | \ + sed -e "s/[ ][ ]*/ /g" | cut -d' ' -f5 ; \ + else \ + echo $(IRAM_SIZE) ; \ + fi \ + } +DEF_HEAP2_BASE = 0x6000 +HEAP2_BASE = ${shell \ + if [ -e pass1.mem ]; then \ + cat pass1.mem | grep "ROM/EPROM/FLASH" | \ + sed -e "s/[ ][ ]*/ /g" | cut -d' ' -f4 ; \ + else \ + echo $(DEF_HEAP2_BASE) ; \ + fi \ + } +STACK_BASE = ${shell \ + if [ -e pass1.mem ]; then \ + cat pass1.mem | grep "Stack starts" | \ + cut -d' ' -f4 ; \ + else \ + echo $(DEF_STACK_BASE) ; \ + fi \ + } + +all: up_head$(OBJEXT) libarch$(LIBEXT) + +$(ASRCS) $(LINKASRCS): %$(ASMEXT): %.S + $(CPP) -P $(CPPFLAGS) $< -o $@ + +$(AOBJS) $(LINKOBJS): $(ASRCS) $(LINKASRCS) + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(TESTOBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +# Create a header file that contains addressing information needed by the code + +pass1.mem: + +up_mem.h: pass1.mem + @echo "#ifndef __ARCH_MEM_H" >up_mem.h + @echo "#define __ARCH_MEM_H" >>up_mem.h + @echo "" >>up_mem.h + @echo "#define UP_DEFAULT_STACK_BASE $(DEF_STACK_BASE)" >>up_mem.h + @echo "#define UP_DEFAULT_HEAP1_BASE $(IRAM_SIZE)" >> up_mem.h + @echo "#define UP_DEFAULT_HEAP2_BASE $(DEF_HEAP2_BASE)" >> up_mem.h + @echo "" >>up_mem.h + @echo "#define UP_STACK_BASE $(STACK_BASE)" >>up_mem.h + @echo "#if UP_STACK_BASE > UP_DEFAULT_STACK_BASE" >>up_mem.h + @echo "# error \"Stack overlap: $(DEF_STACK_BASE) < $(STACK_BASE)\"" >>up_mem.h + @echo "#elif UP_STACK_BASE < UP_DEFAULT_STACK_BASE" >>up_mem.h + @echo "# warning \"Wasted stack: $(DEF_STACK_BASE) > $(STACK_BASE)\"" >>up_mem.h + @echo "#endif" >>up_mem.h + @echo "" >>up_mem.h + @echo "#define UP_HEAP1_BASE $(HEAP1_BASE)" >> up_mem.h + @echo "#define UP_HEAP1_END 0x2000" >> up_mem.h + @echo "" >>up_mem.h + @echo "#define UP_HEAP2_BASE $(HEAP2_BASE)" >> up_mem.h + @echo "#define UP_HEAP2_END 0x8000" >> up_mem.h + @echo "" >>up_mem.h + @echo "#endif /* __ARCH_MEM_H */" >>up_mem.h + +# Combine all objects in this directory into a library + +libarch$(LIBEXT): up_mem.h $(OBJS) + @( for obj in $(OBJS) ; do \ + $(call ARCHIVE, $@, $${obj}); \ + done ; ) + +# This is a kludge to work around some conflicting symbols in libsdcc.liXqueb + +$(SDCCLIBDIR)/libmysdcc.lib: $(SDCCLIBDIR)/libsdcc.lib + @cat $(SDCCLIBDIR)/libsdcc.lib | \ + grep -v calloc | grep -v malloc | grep -v realloc | \ + grep -v free | grep -v vprintf | grep -v _strncpy | \ + grep -v _strchr | grep -v _strlen | grep -v _strcmp | \ + grep -v _strcpy | grep -v _memcmp | grep -v _memcpy | \ + grep -v _memset \ + > 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) board/libboard$(LIBEXT) + @echo "LD: $@" + @$(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) + @echo "LD: $@" + @$(CC) $(LDFLAGS) $(LDPATHES) -L$(BOARDDIR) $(SDCCPATH) $(LINKOBJS) \ + $(LDLIBS) -llibboard$(LIBEXT) $(SDCCLIBS) -o $@ + +nuttx$(EXEEXT): pass1.ihx nuttx.ihx + @rm -f pass1.* + @packihx nuttx.ihx > $(TOPDIR)/nuttx$(EXEEXT) + @cp -f nuttx.map $(TOPDIR)/. + +# This target builds a test program to verify interrupt context switching. irqtest is +# a PHONY target that just sets upt the up_irqtest build correctly + +up_irqtest.ihx: $(TESTOBJS) + $(CC) $(LDFLAGS) -L. $(SDCCPATH) $(TESTLINKOBJS) $(TESTOBJS) $(TESTEXTRAOBJS) $(SDCCLIBS) -o $@ + +irqtest: + $(MAKE) TOPDIR=../../.. up_irqtest.ihx + +# Build dependencies + +.depend: Makefile up_mem.h $(DEPSRCS) + @if [ -e board/Makefile ]; then \ + $(MAKE) -C board TOPDIR=$(TOPDIR) depend ; \ + fi + @$(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 *~ .*.swp + $(call CLEAN) + +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/nuttx/arch/8051/src/up_allocateheap.c b/nuttx/arch/8051/src/up_allocateheap.c new file mode 100644 index 000000000..6ef1a77da --- /dev/null +++ b/nuttx/arch/8051/src/up_allocateheap.c @@ -0,0 +1,89 @@ +/************************************************************ + * up_allocateheap.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 +#include +#include +#include +#include "os_internal.h" +#include "up_internal.h" +#include "up_mem.h" + +/************************************************************ + * Private Definitions + ************************************************************/ + +/************************************************************ + * Private Data + ************************************************************/ + +/************************************************************ + * Private Functions + ************************************************************/ + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: up_allocate_heap + * + * Description: + * The heap may be statically allocated by + * defining CONFIG_HEAP_BASE and CONFIG_HEAP_SIZE. If these + * are not defined, then this function will be called to + * dynamically set aside the heap region. + * + ************************************************************/ + +void up_allocate_heap(FAR void **heap_start, size_t *heap_size) +{ + *heap_start = (FAR void*)UP_HEAP1_BASE; + *heap_size = UP_HEAP1_END - UP_HEAP1_BASE; + up_ledon(LED_HEAPALLOCATE); +} + +#if CONFIG_MM_REGIONS > 1 +void up_addregion(void) +{ + mm_addregion((FAR void*)UP_HEAP2_BASE, UP_HEAP2_END - UP_HEAP2_BASE); +} +#endif diff --git a/nuttx/arch/8051/src/up_assert.c b/nuttx/arch/8051/src/up_assert.c new file mode 100644 index 000000000..157b18ae5 --- /dev/null +++ b/nuttx/arch/8051/src/up_assert.c @@ -0,0 +1,141 @@ +/************************************************************************ + * up_assert.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 +#include +#include + +#include <8052.h> +#include "os_internal.h" +#include "up_internal.h" +#include "up_mem.h" + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Name: _up_assert + ************************************************************************/ + +static void _up_assert(int errorcode) /* __attribute__ ((noreturn)) */ +{ + /* Are we in an interrupt handler or the idle task? */ + + if (g_irqtos || ((FAR _TCB*)g_readytorun.head)->pid == 0) + { + (void)irqsave(); + for(;;) + { +#ifdef CONFIG_ARCH_LEDS + up_ledon(LED_PANIC); + up_delay(250); + up_ledoff(LED_PANIC); + up_delay(250); +#endif + } + } + else + { + exit(errorcode); + } +} + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: up_assert + ************************************************************************/ + +void up_assert(const uint8_t *filename, int lineno) +{ +#if CONFIG_TASK_NAME_SIZE > 0 + _TCB *rtcb = (_TCB*)g_readytorun.head; +#endif + + up_ledon(LED_ASSERTION); + +#if CONFIG_TASK_NAME_SIZE > 0 + lldbg("Assertion failed at file:%s line: %d task: %s\n", + filename, lineno, rtcb->name); +#else + lldbg("Assertion failed at file:%s line: %d\n", + filename, lineno); +#endif + + up_dumpstack(); + _up_assert(EXIT_FAILURE); +} + +/************************************************************************ + * Name: up_assert_code + ************************************************************************/ + +void up_assert_code(const uint8_t *filename, int lineno, int errorcode) +{ +#if CONFIG_TASK_NAME_SIZE > 0 + _TCB *rtcb = (_TCB*)g_readytorun.head; +#endif + + up_ledon(LED_ASSERTION); + +#if CONFIG_TASK_NAME_SIZE > 0 + lldbg("Assertion failed at file:%s line: %d task: %s error code: %d\n", + filename, lineno, rtcb->name, errorcode); +#else + lldbg("Assertion failed at file:%s line: %d error code: %d\n", + filename, lineno, errorcode); +#endif + + up_dumpstack(); + _up_assert(errorcode); +} diff --git a/nuttx/arch/8051/src/up_blocktask.c b/nuttx/arch/8051/src/up_blocktask.c new file mode 100644 index 000000000..811955efa --- /dev/null +++ b/nuttx/arch/8051/src/up_blocktask.c @@ -0,0 +1,172 @@ +/************************************************************************ + * up_blocktask.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 +#include +#include + +#include "os_internal.h" +#include "up_internal.h" + +/************************************************************************ + * Private Definitions + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +/************************************************************************ + * Private Funtions + ************************************************************************/ + +/************************************************************************ + * Public Funtions + ************************************************************************/ + +/************************************************************************ + * Name: up_block_task + * + * Description: + * The currently executing task at the head of + * the ready to run list must be stopped. Save its context + * and move it to the inactive list specified by task_state. + * + * Inputs: + * tcb: Refers to a task in the ready-to-run list (normally + * the task at the head of the list). It most be + * stopped, its context saved and moved into one of the + * waiting task lists. It it was the task at the head + * of the ready-to-run list, then a context to the new + * ready to run task must be performed. + * task_state: Specifies which waiting task list should be + * hold the blocked task TCB. + * + ************************************************************************/ + +void up_block_task(FAR _TCB *tcb, tstate_t task_state) +{ + /* Verify that the context switch can be performed */ + + if ((tcb->task_state < FIRST_READY_TO_RUN_STATE) || + (tcb->task_state > LAST_READY_TO_RUN_STATE)) + { + PANIC(OSERR_BADBLOCKSTATE); + } + else + { + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + bool switch_needed; + + dbg("Blocking TCB=%p\n", tcb); + + /* Remove the tcb task from the ready-to-run list. If we + * are blocking the task at the head of the task list (the + * most likely case), then a context switch to the next + * ready-to-run task is needed. In this case, it should + * also be true that rtcb == tcb. + */ + + switch_needed = sched_removereadytorun(tcb); + + /* Add the task to the specified blocked task list */ + + sched_addblocked(tcb, (tstate_t)task_state); + + /* If there are any pending tasks, then add them to the g_readytorun + * task list now + */ + + if (g_pendingtasks.head) + { + switch_needed |= sched_mergepending(); + } + + /* Now, perform the context switch if one is needed */ + + if (switch_needed) + { + /* Are we in an interrupt handler? */ + + if (g_irqtos) + { + /* Yes, then we have to do things differently. + * Just copy the current registers into the OLD rtcb. + */ + + up_saveirqcontext(&tcb->xcp); + + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. + */ + + rtcb = (FAR _TCB*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then setup so that the context will be performed on exit + * from the interrupt. + */ + + g_irqcontext = &rtcb->xcp; + } + + /* Copy the user C context into the TCB at the (old) head of the + * g_readytorun Task list. if up_savecontext returns a non-zero + * value, then this is really the previously running task restarting! + */ + + else if (!up_savecontext(&rtcb->xcp)) + { + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. + */ + + rtcb = (FAR _TCB*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then switch contexts */ + + up_restorecontext(&rtcb->xcp); + } + } + } +} diff --git a/nuttx/arch/8051/src/up_debug.c b/nuttx/arch/8051/src/up_debug.c new file mode 100644 index 000000000..9d9bce2a0 --- /dev/null +++ b/nuttx/arch/8051/src/up_debug.c @@ -0,0 +1,255 @@ +/************************************************************************ + * up_assert.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 +#include + +#include <8052.h> +#include +#include + +#include "up_internal.h" +#include "up_mem.h" + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +#if defined(CONFIG_FRAME_DUMP) && defined(CONFIG_ARCH_BRINGUP) +static void up_putspace(void) __naked +{ + _asm + mov a, #0x20 + ljmp PM2_ENTRY_COUT + _endasm; +} + +static void _up_putcolon(void) __naked +{ + _asm + mov a, #0x3a + ljmp PM2_ENTRY_COUT + _endasm; +} + +static void _up_dump16(__code char *ptr, uint8_t msb, uint8_t lsb) +{ + up_puts(ptr); + up_puthex(msb); + up_puthex(lsb); + up_putnl(); +} + +static void _up_dump8(__code char *ptr, uint8_t b) +{ + up_puts(ptr); + up_puthex(b); + up_putnl(); +} +#endif + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: up_puthex, up_puthex16, up_putnl, up_puts + ************************************************************************/ + +#if defined(CONFIG_ARCH_BRINGUP) +void up_puthex(uint8_t hex) __naked +{ + hex; /* To avoid unreferenced argument warning */ + _asm + mov a, dpl + ljmp PM2_ENTRY_PHEX + _endasm; +} + +void up_puthex16(int hex) __naked +{ + hex; /* To avoid unreferenced argument warning */ + _asm + ljmp PM2_ENTRY_PHEX16 + _endasm; +} + +void up_putnl(void) __naked +{ + _asm + ljmp PM2_ENTRY_NEWLINE + _endasm; +} + +void up_puts(__code char *ptr) +{ + for (; *ptr; ptr++) + { + up_putc(*ptr); + } +} +#endif + +/************************************************************************ + * Name: up_dumpstack + ************************************************************************/ + +#if defined(CONFIG_FRAME_DUMP) && defined(CONFIG_ARCH_BRINGUP) +void up_dumpstack(void) +{ + NEAR uint8_t *start = (NEAR uint8_t *)(STACK_BASE & 0xf0); + NEAR uint8_t *end = (NEAR uint8_t *)SP; + uint8_t i; + + while (start < end) + { + up_puthex((uint8_t)start); + _up_putcolon(); + + for (i = 0; i < 8; i++) + { + up_putspace(); + if (start < (NEAR uint8_t *)(STACK_BASE) || + start > end) + { + up_putspace(); + up_putspace(); + } + else + { + up_puthex(*start); + } + start++; + } + up_putnl(); + } +} +#endif + +/************************************************************************ + * Name: up_dumpframe + ************************************************************************/ + +#if defined(CONFIG_FRAME_DUMP) && defined(CONFIG_ARCH_BRINGUP) +void up_dumpframe(FAR struct xcptcontext *context) +{ +#ifdef CONFIG_FRAME_DUMP_SHORT + FAR uint8_t *stack = &context->stack[context->nbytes - FRAME_SIZE]; + FAR uint8_t *regs = context->regs; + + _up_dump16(" RET ", stack[FRAME_RETMS], stack[FRAME_RETLS]); + _up_dump8 (" IE ", stack[FRAME_IE]); + _up_dump16(" DPTR ", stack[FRAME_DPH], stack[FRAME_DPL]); + _up_dump8 (" PSW ", regs[REGS_PSW]); + _up_dump8 (" SP ", context->nbytes + (STACK_BASE-1)); +#else + FAR uint8_t *stack = &context->stack[context->nbytes - FRAME_SIZE]; + FAR uint8_t *regs = context->regs; + uint8_t i, j, k; + + _up_dump8 (" NBYTES ", context->nbytes); + + for (i = 0; i < context->nbytes; i += 8) + { + up_puthex(i); + _up_putcolon(); + + for (j = 0; j < 8; j++) + { + k = i + j; + up_putspace(); + if (k >= context->nbytes) + { + up_putspace(); + up_putspace(); + } + else + { + up_puthex(context->stack[k]); + } + } + up_putnl(); + } + + up_puts(" REGS:"); + for (i = 0; i < REGS_SIZE; i++) + { + up_putspace(); + up_puthex(context->regs[i]); + } + up_putnl(); +#endif +} +#endif + +/************************************************************************ + * Name: up_dumpframe + ************************************************************************/ + +/* The 805x family has a tiny, 256 stack and can be easily + * overflowed. The following macro can be used to instrument + * code to dump the stack pointer at critical locations. + */ + +#ifdef CONFIG_ARCH_PJRC +void up_showsp(uint8_t ch) __naked +{ + ch; + _asm + mov a, dpl + lcall PM2_ENTRY_COUT + mov a, sp + lcall PM2_ENTRY_PHEX + lcall PM2_ENTRY_NEWLINE + _endasm; +} +#endif + + diff --git a/nuttx/arch/8051/src/up_delay.c b/nuttx/arch/8051/src/up_delay.c new file mode 100644 index 000000000..3403c69cc --- /dev/null +++ b/nuttx/arch/8051/src/up_delay.c @@ -0,0 +1,93 @@ +/************************************************************************ + * up_delay.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 + ************************************************************************/ + +/************************************************************************ + * Private Types + ************************************************************************/ + +/************************************************************************ + * Private Function Prototypes + ************************************************************************/ + +/************************************************************************ + * Private Variables + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + + +/************************************************************************ + * Public Funtions + ************************************************************************/ + +/************************************************************************ + * Name: up_delay + * + * Description: + * Delay inline for the requested number of milliseconds. + * NOT multi-tasking friendly. + * + ************************************************************************/ + +void up_delay(uint8_t milliseconds) __naked +{ + _asm + mov r0, dpl +00001$: mov r1, #230 +00002$: nop + nop + nop + nop + nop + nop + djnz r1, 00002$ + djnz r0, 00001$ + ret + _endasm; +} diff --git a/nuttx/arch/8051/src/up_exit.c b/nuttx/arch/8051/src/up_exit.c new file mode 100644 index 000000000..736fc71d5 --- /dev/null +++ b/nuttx/arch/8051/src/up_exit.c @@ -0,0 +1,105 @@ +/**************************************************************************************** + * up_exit.c + * + * Copyright (C) 2007-2009 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 NuttX 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 + +#include <8052.h> +#include + +#include "os_internal.h" +#include "up_internal.h" + +/**************************************************************************************** + * Private Definitions + ****************************************************************************************/ + +/**************************************************************************************** + * Private Data + ****************************************************************************************/ + +/**************************************************************************************** + * Private Functions + ****************************************************************************************/ + +/**************************************************************************************** + * Public Functions + ****************************************************************************************/ + +/**************************************************************************************** + * Name: _exit + * + * Description: + * This function causes the currently executing task to cease + * to exist. This is a special case of task_delete() where the task to + * be deleted is the currently executing task. It is more complex because + * a context switch must be perform to the next ready to run task. + * + ****************************************************************************************/ + +void _exit(int status) +{ + FAR _TCB* tcb; + + dbg("TCB=%p exitting\n", tcb); + + /* Disable interrupts. Interrupts will remain disabled until + * the new task is resumed below when the save IE is restored. + */ + + EA = 0; + + /* Destroy the task at the head of the ready to run list. */ + + (void)task_deletecurrent(); + + /* Now, perform the context switch to the new ready-to-run task at the + * head of the list. + */ + + tcb = (FAR _TCB*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", tcb); + + /* Then switch contexts */ + + up_restorecontext(&tcb->xcp); +} + diff --git a/nuttx/arch/8051/src/up_head.S b/nuttx/arch/8051/src/up_head.S new file mode 100644 index 000000000..44f8038c9 --- /dev/null +++ b/nuttx/arch/8051/src/up_head.S @@ -0,0 +1,471 @@ +/************************************************************ + * up_head.S + * + * 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" + + .module up_head + .optsdcc -mmcs51 --model-large + +/************************************************************ + * Private Data + ************************************************************/ + + .area REG_BANK_0 (REL,OVR,DATA) + .ds 8 + +#ifndef CONFIG_8052_TIMER2 + .area XSEG +_g_timer0tick: + .ds 1 +#endif + +/************************************************************ + * Public Data + ************************************************************/ + + .globl _g_irqtos + .globl _g_irqcontext + .globl _g_irqregs + +/************************************************************ + * Public Functions + ************************************************************/ + + .globl _irq_dispatch + .globl _up_restoreregisters + +/************************************************************ + * Program entry points + ************************************************************/ + +/* Program entry is through PROGRAM_BASE. This is just a + * branch to our start up logic. + */ + + .area CODE1 (ABS) + .org PROGRAM_BASE + ljmp start + +/* These are indirect interrupt vectors. Logic in PAULMON2, + * captures the interrupt vectors (near address 0x0000) and + * re-routes them through the following entry points. + * + * Each of these saves acc and ie then passes the IRQ number + * to higher level logic in a + */ + + .org PM2_VECTOR_EXTINT0 + push acc + mov a, #EXT_INT0_IRQ + ljmp _up_interrupt + + .org PM2_VECTOR_TIMER0 + push acc +#ifdef CONFIG_8052_TIMER2 + mov a, #TIMER0_IRQ + ljmp _up_interrupt +#else + ljmp _up_timer0 +#endif + .org PM2_VECTOR_EXTINT1 + push acc + mov a, #EXT_INT1_IRQ + ljmp _up_interrupt + + .org PM2_VECTOR_TIMER1 + push acc + mov a, #TIMER1_IRQ + ljmp _up_interrupt + + .org PM2_VECTOR_UART + push acc + mov a, #UART_IRQ + ljmp _up_interrupt + + .org PM2_VECTOR_TIMER2 + push acc + mov a, #TIMER2_IRQ + ljmp _up_interrupt + +/************************************************************ + * Name: start + * + * Description: + * This is the initial entry point into NuttX + * + ************************************************************/ + +start: + mov sp, #(STACK_BASE-1) + +#ifdef CONFIG_ARCH_LEDS + lcall _up_ledinit +#endif + + ljmp _os_start + +/************************************************************ + * Name: up_timer0 + * + * Description: + * Timer 0, mode 0 can be used as a system timer. In that + * mode, the 1.8432 MHz clock is divided by 32. A single + * 8-bit value is incremented at 57600 Hz, which results + * in 225 Timer 0 overflow interrupts per second. + * + * The Timer0 interrupt vectors to this point which then + * does a software divide by 2 to get a system timer of + * 112.5Hz. + * + * On Entry: + * + * (1) acc on the stack and + * (2) the IRQ number(TIMER0_IRQ) in the accumulator + * + ************************************************************/ + +#ifndef CONFIG_8052_TIMER2 +_up_timer0: + ar2 = 0x02 + ar3 = 0x03 + ar4 = 0x04 + ar5 = 0x05 + ar6 = 0x06 + ar7 = 0x07 + ar0 = 0x00 + ar1 = 0x01 + + /* ACC already on the stack; push IE. Then disable interrupts */ + + push ie + clr ea + + /* Save the remaining registers with interrupts disabled + * + * a, ie, and dptr go on the stack. + */ + + push dpl + push dph + + /* Increment the tick counter */ + + mov dptr, #_g_timer0tick + movx a, @dptr + inc a + movx @dptr, a + + /* If bit 0 is '0', then just return from the interrupt */ + + anl a, #0x01 + jnz 00101$ + ljmp _up_timer0exit + + /* If bit 0 is '1', then process the interrupt */ + +00101$: + mov a, #TIMER0_IRQ + sjmp _up_timer0join +#endif + +/************************************************************ + * Name: up_interrupt + * + * Description: + * All interrupts vector to this point with: + * + * (1) acc on the stack and + * (2) the IRQ number in the accumulator + * + ************************************************************/ + +_up_interrupt: + ar2 = 0x02 + ar3 = 0x03 + ar4 = 0x04 + ar5 = 0x05 + ar6 = 0x06 + ar7 = 0x07 + ar0 = 0x00 + ar1 = 0x01 + + /* ACC already on the stack; push IE. Then disable interrupts */ + + push ie + clr ea + + /* Save the remaining registers with interrupts disabled + * + * a, ie, and dptr go on the stack. + */ + + push dpl + push dph + +_up_timer0join: + /* Other registers go into the IRQ register save area */ + + push acc + mov dptr, #_g_irqregs + lcall _up_saveregisters + + /* Show interrupt status on the LEDs */ + +#ifdef CONFIG_ARCH_LEDS + mov dpl, #LED_INIRQ + lcall _up_ledon +#endif + + /* Save the IRQ number in r2 */ + + pop ar2 + + /* Mark that we are in an interrupt and provide the top + * of stack pointer to the context switching logic. + */ + + mov dptr, #_g_irqtos + mov a, sp + movx @dptr, a + + /* Nullify the context pointer. If a context switch is + * needed, this will be set to the address of the context + * structure. + */ + + mov dptr, #_g_irqcontext + clr a + movx @dptr,a + inc dptr + movx @dptr,a + + /* Now call void irq_dispatch(int irq, FAR void *context) + * + * First, create the first argument as (int)irqno + */ + + mov dpl, r2 + mov dph, #0 + + /* Create the second argument (void *context) on the stack */ + + push sp + clr a + push acc + + /* Then dispatch the IRQ. */ + + lcall _irq_dispatch + pop acc + pop acc + + /* Indicate that we are no longer in an interrupt */ + + mov dptr, #_g_irqtos + clr a + movx @dptr, a + + /* Check if a context switch is pending */ + + mov dptr,#_g_irqcontext + movx a, @dptr + mov r2, a + inc dptr + movx a, @dptr + mov r3, a + + orl a, r2 + jnz 00001$ + + /* No context switch is pending. Restore registers + * from the interrupt register save area. + */ + + mov dptr, #_g_irqregs + sjmp 00004$ + +00001$: /****************************************************/ + + /* A context switch is pending, clear g_irqcontext */ + + mov dpl, r2 + mov dph, r3 + clr a + movx @dptr, a + inc dptr + movx @dptr, a + +#ifdef CONFIG_INTERRUPT_FRAME_DUMP + mov dpl, r2 + mov dph, r3 + push ar2 + push ar3 + lcall _up_dumpframe + pop ar3 + pop ar2 +#endif + + /* Register usage in the following: + * + * R0 - Holds working the 8-bit IRAM pointer + * R1 - Not used + * R2-3 - Holds the working 16-bit XRAM pointer + * R4 - Holds the working byte count + * R5 - Holds the new stack pointer + * R6-7 - Not used + */ + + /* Fetch r4 = context->nbytes */ + + mov dpl, r2 + mov dph, r3 + movx a, @dptr + mov r4, a + + /* Save the new stack pointer in r5 */ + + add a, #(STACK_BASE-1) + mov r5, a + + /* Save r2-3 = &context->stack */ + + inc dptr + push dpl + push dph + mov r2, dpl + mov r3, dph + + /* Set r0 = stack base address */ + + mov r0, #STACK_BASE + + /* Top of the copy loop */ +00002$: + mov a, r4 /* a = bytes left to transfer */ + dec r4 /* (for next time through the loop) */ + jz 00003$ /* Jump if a = 0 (done) */ + + /* Fetch the next byte from context->stack */ + + mov dpl, r2 + mov dph, r3 + movx a,@dptr + + /* Increment the XRAM pointer */ + + inc dptr + mov r2, dpl + mov r3, dph + + /* Save the next byte into IRAM */ + + mov @r0, a + + /* Increment the IRAM pointer */ + + inc r0 + sjmp 00002$ + + /* The entire stack has been copied from XRAM into + * IRAM. Set the new stack pointer + */ + +00003$: + pop dph + pop dpl + mov sp, r5 + +#ifdef CONFIG_INTERRUPT_FRAME_DUMP + push dpl + push dph + lcall _up_dumpstack + pop dph + pop dpl +#endif + /* Get the pointer to the register save area */ + + mov a, #STACK_SIZE + add a, dpl + mov dpl, a + clr a + addc a, dph + mov dph, a + +00004$: /****************************************************/ + + /* Restore the context from the register save area + * and return from the interrupt. At this point, dptr + * holds the pointer to the memory region that holds + * the register save area. This could be either + * g_irqregs (no context switch) or &g_irqcontext->regs + * (context switch). + */ + +#ifdef CONFIG_ARCH_LEDS + push dpl + push dph + mov dpl, #LED_INIRQ + lcall _up_ledoff + pop dph + pop dpl +#endif + /* Restore registers from the register save area */ + + lcall _up_restoreregisters + +_up_timer0exit: + /* Restore registers from the stack and return */ + + pop dph + pop dpl + + /* Restore the interrupt state per the stored IE value */ + + pop acc + jb acc.7,00005$ + clr ie.7 + sjmp 00006$ +00005$: + setb ie.7 + +00006$: + pop acc + reti diff --git a/nuttx/arch/8051/src/up_idle.c b/nuttx/arch/8051/src/up_idle.c new file mode 100644 index 000000000..802e684be --- /dev/null +++ b/nuttx/arch/8051/src/up_idle.c @@ -0,0 +1,96 @@ +/************************************************************ + * up_idle.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 + +#include "up_internal.h" + +/************************************************************ + * Private Definitions + ************************************************************************/ + +/************************************************************ + * Private Data + ************************************************************************/ + +#if defined(CONFIG_ARCH_LEDS) && defined(CONFIG_ARCH_BRINGUP) +static /**************** g_ledtoggle = 0; +#endif + +/************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************ + * Name: up_idle + * + * Description: + * up_idle() is the logic that will be executed when their + * is no other ready-to-run task. This is processor idle + * time and will continue until some interrupt occurs to + * cause a context switch from the idle task. + * + * Processing in this state may be processor-specific. e.g., + * this is where power management operations might be + * performed. + * + ************************************************************************/ + +void up_idle(void) +{ +#if defined(CONFIG_ARCH_LEDS) && defined(CONFIG_ARCH_BRINGUP) + g_ledtoggle++; + if (g_ledtoggle == 0x80) + { + up_ledon(LED_IDLE); + } + else if (g_ledtoggle == 0x00) + { + up_ledoff(LED_IDLE); + } +#endif +} + diff --git a/nuttx/arch/8051/src/up_initialize.c b/nuttx/arch/8051/src/up_initialize.c new file mode 100644 index 000000000..3f0bc4027 --- /dev/null +++ b/nuttx/arch/8051/src/up_initialize.c @@ -0,0 +1,144 @@ +/************************************************************************ + * up_initialize.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 +#include + +#include "up_internal.h" + +/************************************************************************ + * Private Definitions + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +/* This is the top of the stack containing the interrupt + * stack frame. It is set when processing an interrupt. It + * is also cleared when the interrupt returns so this can + * also be used like a boolean indication that we are in an + * interrupt. + */ + +uint8_t g_irqtos; + +/* Registers are saved in the following global array during + * interrupt processing. If a context switch is performed + * during the interrupt handling, these registers will be + * copied into the TCB again (NOTE: We could save a copy + * if the interrupt handling logic saved the registers + * directly into (_TCB*)g_readytorun.head->xcp.regs). + */ + +uint8_t g_irqregs[REGS_SIZE]; + +/* If during execution of an interrup handler, a context + * switch must be performed, the follwing will be set to + * to that address of the relevant context structure. The + * actual switch will be deferred until the time that the + * the interrupt exits. + */ + +FAR struct xcptcontext *g_irqcontext; + +/* It is faster to look up 8-bit shifts in this table than + * to comput them. + */ + +const uint8_t g_ntobit[8] = + { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: up_initialize + * + * Description: + * up_initialize will be called once during OS + * initialization after the basic OS services have been + * initialized. The architecture specific details of + * initializing the OS will be handled here. Such things as + * setting up interrupt service routines, starting the + * clock, and registering device drivers are some of the + * things that are different for each processor and hardware + * platform. + * + * up_initialize is called after the OS initialized but + * before the init process has been started and before the + * libraries have been initialized. OS services and driver + * services are available. + * + ************************************************************************/ + +void up_initialize(void) +{ + /* Initialize global variables */ + + g_irqtos = 0; + + /* Add extra memory fragments to the memory manager */ + +#if CONFIG_MM_REGIONS > 1 + up_addregion(); +#endif + + /* Initialize the interrupt subsystem */ + + up_irqinitialize(); + + /* Initialize the system timer interrupt */ + +#ifndef CONFIG_SUPPRESS_INTERRUPTS + up_timerinit(); +#endif + + up_ledon(LED_IRQSENABLED); +} + diff --git a/nuttx/arch/8051/src/up_initialstate.c b/nuttx/arch/8051/src/up_initialstate.c new file mode 100644 index 000000000..5289d867c --- /dev/null +++ b/nuttx/arch/8051/src/up_initialstate.c @@ -0,0 +1,119 @@ +/************************************************************************ + * up_initialstate.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 + +#include "up_internal.h" + +/************************************************************************ + * Private Definitions + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: up_initial_state + * + * Description: + * A new thread is being started and a new TCB + * has been created. This function is called to initialize + * the processor specific portions of the new TCB. + * + * This function must setup the intial architecture registers + * and/or stack so that execution will begin at tcb->start + * on the next context switch. + * + ************************************************************************/ + +void up_initial_state(FAR _TCB *tcb) +{ + FAR uint8_t *frame = tcb->xcp.stack; + FAR uint8_t *regs = tcb->xcp.regs; + + /* This is the form of initial stack frame + * + * This initial stack frame will be configured to hold. + * (1) The 16-bit return address of either: + * + * void task_start(void); + * void pthread_start(void) + * + * The return address is stored at the top of stack. + * so that the RETI instruction will work: + * + * PC15-8 <- ((SP)) + * (SP) <- (SP) -1 + * PC7-0 <- ((SP)) + * (SP) <- (SP) -1 + */ + + frame[FRAME_RETLS] = (((uint16_t)tcb->start) & 0xff); + frame[FRAME_RETMS] = (((uint16_t)tcb->start) >> 8); + + /* The context save area for registers a, ie, and dpstr + * follows the return address in the stack frame. + */ + + frame[FRAME_IE] = 0x80; + + /* Save the number of bytes in the frame (which will be used + * to intialize the stack pointer when the task is started). + */ + + tcb->xcp.nbytes = FRAME_SIZE; + + /* Initialize the remaining register save area which is + * outside of the stack save area. + */ + + tcb->xcp.regs[REGS_PSW] = 0; +} diff --git a/nuttx/arch/8051/src/up_internal.h b/nuttx/arch/8051/src/up_internal.h new file mode 100644 index 000000000..d49c757a6 --- /dev/null +++ b/nuttx/arch/8051/src/up_internal.h @@ -0,0 +1,152 @@ +/************************************************************************** + * up_internal.h + * + * Copyright (C) 2007, 2009 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 NuttX 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. + * + **************************************************************************/ + +#ifndef __ARCH_UP_INTERNAL_H +#define __ARCH_UP_INTERNAL_H + +/************************************************************************** + * Included Files + **************************************************************************/ + +#include +#include +#include +#include + +#if defined(CONFIG_ARCH_BOARD_PJRC_87C52) +# include +#else +# warning "805x board not recognized" +#endif + +/************************************************************************** + * Public Definitions + **************************************************************************/ + +/************************************************************************** + * Public Types + **************************************************************************/ + +/************************************************************************** + * Public Variables + **************************************************************************/ + +#ifndef __ASSEMBLY__ + +/* This is the top of the stack containing the interrupt + * stack frame. It is set when processing an interrupt. It + * is also cleared when the interrupt returns so this can + * also be used like a boolean indication that we are in an + * interrupt. + */ + +extern uint8_t g_irqtos; + +/* Registers are saved in the following global array during + * interrupt processing. If a context switch is performed + * during the interrupt handling, these registers will be + * copied into the TCB again (NOTE: We could save a copy + * if the interrupt handling logic saved the registers + * directly into (_TCB*)g_readytorun.head->xcp.regs). + */ + +extern uint8_t g_irqregs[REGS_SIZE]; + +/* If during execution of an interrup handler, a context + * switch must be performed, the follwing will be set to + * to that address of the relevant context structure. The + * actual switch will be deferred until the time that the + * the interrupt exits. + */ + +extern FAR struct xcptcontext *g_irqcontext; + +/* It is faster to look up 8-bit shifts in this table than + * to comput them. + */ + +extern const uint8_t g_ntobit[8]; + +#endif /* __ASSEMBLY */ + +/************************************************************************** + * Public Function Prototypes + **************************************************************************/ + +#ifndef __ASSEMBLY__ + +#if CONFIG_MM_REGIONS > 1 +extern void up_addregion(void); +#endif +extern void up_delay(uint8_t milliseconds) __naked; +extern void up_irqinitialize(void); +extern void up_restorecontext(FAR struct xcptcontext *context) _naked; +extern void up_restoreregisters(FAR uint8_t *regs) _naked; +extern uint8_t up_savecontext(FAR struct xcptcontext *context) __naked; +extern void up_saveregisters(FAR uint8_t *regs) _naked; +extern void up_saveirqcontext(FAR struct xcptcontext *context); +extern void up_timerinit(void); + +/* Defined in up_debug.c */ + +#if defined(CONFIG_ARCH_BRINGUP) +extern void up_puthex(uint8_t hex) __naked; +extern void up_puthex16(int hex) __naked; +extern void up_putnl(void) __naked; +extern void up_puts(__code char *ptr); +#endif + +#if defined(CONFIG_FRAME_DUMP) && defined(CONFIG_ARCH_BRINGUP) +extern void up_dumpstack(void); +extern void up_dumpframe(FAR struct xcptcontext *context); +#else +# define up_dumpstack() +# define up_dumpframe(x) +#endif + +/* Defined in board/up_leds.c */ + +#ifdef CONFIG_ARCH_LEDS +extern void up_ledinit(void); +extern void up_ledon(uint8_t led); +extern void up_ledoff(uint8_t led); +#else +# define up_ledinit() +# define up_ledon(led) +# define up_ledoff(led) +#endif + +#endif /* __ASSEMBLY */ +#endif /* __ARCH_UP_INTERNAL_H */ diff --git a/nuttx/arch/8051/src/up_interruptcontext.c b/nuttx/arch/8051/src/up_interruptcontext.c new file mode 100644 index 000000000..81426a94e --- /dev/null +++ b/nuttx/arch/8051/src/up_interruptcontext.c @@ -0,0 +1,70 @@ +/************************************************************************ + * up_interruptcontext.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 +#include + +#include "up_internal.h" + +/************************************************************************ + * Private Types + ************************************************************************/ + +/************************************************************************ + * Private Function Prototypes + ************************************************************************/ + +/************************************************************************ + * Global Functions + ************************************************************************/ + +/************************************************************************ + * Name: up_interrupt_context + * + * Description: Return true is we are currently executing in + * the interrupt handler context. + ************************************************************************/ + +bool up_interrupt_context(void) +{ + return g_irqtos != 0; +} diff --git a/nuttx/arch/8051/src/up_irq.c b/nuttx/arch/8051/src/up_irq.c new file mode 100644 index 000000000..f40bdbf31 --- /dev/null +++ b/nuttx/arch/8051/src/up_irq.c @@ -0,0 +1,152 @@ +/************************************************************************ + * up_irq.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 + +#include <8052.h> + +#include "up_internal.h" + +extern int g_nints; + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Public Data + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Funtions + ************************************************************************/ + +/************************************************************************ + * Name: irq_initialize + ************************************************************************/ + +void up_irqinitialize(void) +{ + /* Set interrupt priorities (all low) */ + + IP = 0; + +#ifdef CONFIG_SUPPRESS_INTERRUPTS + /* Disable all interrupts */ + + IE = 0; +#else + /* Enable interrupts globally, but disable all interrupt + * sources. + */ + + IE = 0x80; +#endif +} + +/************************************************************************ + * Name: irqsave + * + * Description: + * Disable all IRQs + * + ************************************************************************/ + +irqstate_t irqsave(void) +{ + irqstate_t ret = IE; + EA = 0; + return ret; +} + +/************************************************************************ + * Name: irqrestore + * + * Description: + * Restore a previous interrupt state + * + ************************************************************************/ + +void irqrestore(irqstate_t flags) +{ + IE = flags; +} + +/************************************************************************ + * Name: up_disable_irq + * + * Description: + * Disable the IRQ specified by 'irq' + * + ************************************************************************/ + +void up_disable_irq(int irq) +{ + if ((unsigned)irq < NR_IRQS) + { + IE &= ~(g_ntobit[irq]); + } +} + +/************************************************************************ + * Name: up_enable_irq + * + * Description: + * Enable the IRQ specified by 'irq' + * + ************************************************************************/ + +void up_enable_irq(int irq) +{ + if ((unsigned)irq < NR_IRQS) + { + IE |= g_ntobit[irq]; + } +} diff --git a/nuttx/arch/8051/src/up_irqtest.c b/nuttx/arch/8051/src/up_irqtest.c new file mode 100644 index 000000000..b0bdc8464 --- /dev/null +++ b/nuttx/arch/8051/src/up_irqtest.c @@ -0,0 +1,273 @@ +/************************************************************************ + * up_irqtest.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 NuttX 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 + +#include +#include <8052.h> + +#include "up_internal.h" + +/************************************************************************ + * Definitions + ************************************************************************/ + +#define up_extint0 ((vector_t)PM2_VECTOR_EXTINT0) +#define up_timer0 ((vector_t)PM2_VECTOR_TIMER0) +#define up_extint1 ((vector_t)PM2_VECTOR_EXTINT1) +#define up_timer1 ((vector_t)PM2_VECTOR_TIMER1) +#define up_uart ((vector_t)PM2_VECTOR_UART) +#define up_timer2 ((vector_t)PM2_VECTOR_TIMER2) + +/************************************************************************ + * Private Types + ************************************************************************/ + +typedef void (*vector_t)(void); + +/************************************************************************ + * Public Variables + ************************************************************************/ + +bool g_irqtest; +uint8_t g_irqtos; +uint8_t g_irqregs[REGS_SIZE]; +int g_nirqs; +FAR struct xcptcontext *g_irqcontext; + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Name: utility functions + ************************************************************************/ + +static void _up_putc(uint8_t ch) __naked +{ + ch; /* To avoid unreferenced argument warning */ + _asm + mov a, dpl + ljmp PM2_ENTRY_COUT + _endasm; +} + +void _up_puthex(uint8_t hex) __naked +{ + hex; /* To avoid unreferenced argument warning */ + _asm + mov a, dpl + ljmp PM2_ENTRY_PHEX + _endasm; +} + +void _up_puthex16(int hex) __naked +{ + hex; /* To avoid unreferenced argument warning */ + _asm + ljmp PM2_ENTRY_PHEX16 + _endasm; +} + +void _up_putnl(void) __naked +{ + _asm + ljmp PM2_ENTRY_NEWLINE + _endasm; +} + +void _up_puts(__code char *ptr) +{ + for (; *ptr; ptr++) + { + _up_putc(*ptr); + } +} + +void _up_delay(uint8_t milliseconds) __naked +{ + _asm + mov r0, dpl +00001$: mov r1, #230 +00002$: nop + nop + nop + nop + nop + nop + djnz r1, 00002$ + djnz r0, 00001$ + ret + _endasm; +} + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: os_start + * + * Description: + * "Fake" OS entry point. + * + ************************************************************************/ + +void os_start(void) +{ + int i; + + /* Disable all interrupts */ + + IE = 0; + + /* Then verify all of the interrupt */ + + g_irqtest = false; + + up_extint0(); + up_timer0(); +#ifndef CONFIG_8052_TIMER2 + up_timer0(); +#endif + up_extint1(); + up_timer1(); + up_uart(); + up_timer2(); + + /* Now a real interrupt ... */ + + /* Configure timer 0 */ + + TR0 = 0; /* Make sure timer 0 is stopped */ + TF0 = 0; /* Clear the overflow flag */ + TMOD &= 0xF0; /* Set to mode 0 (without changing timer1) */ + TL0 = 0; /* Clear timer 0 value */ + TH0 = 0; + TR0 = 1; /* Start the timer */ + + /* Start timer interrupts */ + + g_irqtest = true; + g_nirqs = 0; + IE = 0x82; /* Enable interrupts */ + + /* Wait a about 500 MS */ + + _up_delay(500); + + /* Disable the timer */ + + TR0 = 0; /* Stop timer 0 */ + IE = 0; /* Disable interrupts */ + + _up_puts("IRQs in 500 MS="); + _up_puthex16(g_nirqs); + _up_putnl(); + + /* end of test */ + + _up_puts("Test complete"); + _up_putnl(); + for(;;); +} + +/************************************************************************ + * Name: irq_dispatch + * + * Description: + * "Fake" IRQ dispatcher + * + ***********************************************************************/ + +void irq_dispatch(int irq, FAR void *context) +{ + context; + if (g_irqtest) + { + g_nirqs++; + } + else + { + _up_puts("Dispatch IRQ="); + _up_puthex(irq); + _up_putnl(); + } +} + +/************************************************************************ + * Name: up_dumpstack / up_dumpframe + * + * Description: + * "Fake" debug routines if needed. + * + ************************************************************************/ + +void up_dumpstack(void) +{ +} + +void up_dumpframe(FAR struct xcptcontext *context) +{ +} + +/************************************************************************ + * Name: up_ledinit, up_ledon, up_ledoff + * + * Description: + * "Fake" LED routines if needed + * + ************************************************************************/ + +void up_ledinit(void) +{ +} + +void up_ledon(uint8_t led) +{ + led; +} + +void up_ledoff(uint8_t led) +{ + led; +} diff --git a/nuttx/arch/8051/src/up_putc.c b/nuttx/arch/8051/src/up_putc.c new file mode 100644 index 000000000..a4b96e23f --- /dev/null +++ b/nuttx/arch/8051/src/up_putc.c @@ -0,0 +1,81 @@ +/************************************************************************ + * up_putc.c + * + * Copyright (C) 2007, 2009 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 NuttX 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" + +/************************************************************************ + * Private Functions + ************************************************************************/ + +static void _up_putc(int ch) __naked +{ +#if 1 + ch; /* To avoid unreferenced argument warning */ + _asm + mov a, dpl + ljmp PM2_ENTRY_COUT + _endasm; +#else + ch; /* To avoid unreferenced argument warning */ + _asm + mov a, dpl +cout: jnb ti, cout + clr ti + mov sbuf, a + ret + _endasm; +#endif +} + +/************************************************************************ + * Public Functions + ************************************************************************/ + +int up_putc(int ch) +{ + _up_putc(ch); + if (ch == '\n') + { + _up_putc('\r'); + } + return ch; +} + diff --git a/nuttx/arch/8051/src/up_releasepending.c b/nuttx/arch/8051/src/up_releasepending.c new file mode 100644 index 000000000..c35199bd5 --- /dev/null +++ b/nuttx/arch/8051/src/up_releasepending.c @@ -0,0 +1,135 @@ +/************************************************************************ + * up_releasepending.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 + +#include + +#include "os_internal.h" +#include "up_internal.h" + +/************************************************************************ + * Private Definitions + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +/************************************************************************ + * Private Funtions + ************************************************************************/ + +/************************************************************************ + * Public Funtions + ************************************************************************/ + +/************************************************************************ + * Name: up_release_pending + * + * Description: + * Release and ready-to-run tasks that have + * collected in the pending task list. This can call a + * context switch if a new task is placed at the head of + * the ready to run list. + * + ************************************************************************/ + +void up_release_pending(void) +{ + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + + dbg("From TCB=%p\n", rtcb); + + /* Merge the g_pendingtasks list into the g_readytorun task list */ + + /* sched_lock(); */ + if (sched_mergepending()) + { + /* The currently active task has changed! We will need to + * switch contexts. First check if we are operating in + * interrupt context: + */ + + if (g_irqtos) + { + /* Yes, then we have to do things differently. + * Just copy the current registers into the OLD rtcb. + */ + + up_saveirqcontext(&rtcb->xcp); + + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. + */ + + rtcb = (FAR _TCB*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then setup so that the context will be performed on exit + * from the interrupt. + */ + + g_irqcontext = &rtcb->xcp; + } + + /* Copy the exception context into the TCB of the task that + * was currently active. if up_savecontext returns a non-zero + * value, then this is really the previously running task + * restarting! + */ + + else if (!up_savecontext(&rtcb->xcp)) + { + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. + */ + + rtcb = (FAR _TCB*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then switch contexts */ + + up_restorecontext(&rtcb->xcp); + } + } +} diff --git a/nuttx/arch/8051/src/up_reprioritizertr.c b/nuttx/arch/8051/src/up_reprioritizertr.c new file mode 100644 index 000000000..8810a8fe1 --- /dev/null +++ b/nuttx/arch/8051/src/up_reprioritizertr.c @@ -0,0 +1,185 @@ +/**************************************************************************** + * up_reprioritizertr.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 +#include +#include + +#include + +#include "os_internal.h" +#include "up_internal.h" + +/**************************************************************************** + * Private Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Funtions + ****************************************************************************/ + +/**************************************************************************** + * Public Funtions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_reprioritize_rtr + * + * Description: + * Called when the priority of a running or + * ready-to-run task changes and the reprioritization will + * cause a context switch. Two cases: + * + * 1) The priority of the currently running task drops and the next + * task in the ready to run list has priority. + * 2) An idle, ready to run task's priority has been raised above the + * the priority of the current, running task and it now has the + * priority. + * + * Inputs: + * tcb: The TCB of the task that has been reprioritized + * priority: The new task priority + * + ****************************************************************************/ + +void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority) +{ + /* Verify that the caller is sane */ + + if (tcb->task_state < FIRST_READY_TO_RUN_STATE || + tcb->task_state > LAST_READY_TO_RUN_STATE || + priority < SCHED_PRIORITY_MIN || + priority > SCHED_PRIORITY_MAX) + { + PANIC(OSERR_BADREPRIORITIZESTATE); + } + else + { + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + bool switch_needed; + + dbg("TCB=%p PRI=%d\n", tcb, priority); + + /* Remove the tcb task from the ready-to-run list. + * sched_removereadytorun will return true if we just + * remove the head of the ready to run list. + */ + + switch_needed = sched_removereadytorun(tcb); + + /* Setup up the new task priority */ + + tcb->sched_priority = (uint8_t)priority; + + /* Return the task to the specified blocked task list. + * sched_addreadytorun will return true if the task was + * added to the new list. We will need to perform a context + * switch only if the EXCLUSIVE or of the two calls is non-zero + * (i.e., one and only one the calls changes the head of the + * ready-to-run list). + */ + + switch_needed ^= sched_addreadytorun(tcb); + + /* Now, perform the context switch if one is needed */ + + if (switch_needed) + { + /* If we are going to do a context switch, then now is the right + * time to add any pending tasks back into the ready-to-run list. + * task list now + */ + + if (g_pendingtasks.head) + { + sched_mergepending(); + } + + /* Are we in an interrupt handler? */ + + if (g_irqtos) + { + /* Yes, then we have to do things differently. + * Just copy the current registers into the OLD rtcb. + */ + + up_saveirqcontext(&tcb->xcp); + + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. + */ + + rtcb = (FAR _TCB*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then setup so that the context will be performed on exit + * from the interrupt. + */ + + g_irqcontext = &tcb->xcp; + } + + /* Copy the exception context into the TCB at the (old) head of the + * g_readytorun Task list. if up_savecontext returns a non-zero + * value, then this is really the previously running task restarting! + */ + + else if (!up_savecontext(&rtcb->xcp)) + { + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. + */ + + rtcb = (FAR _TCB*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then switch contexts */ + + up_restorecontext(&rtcb->xcp); + } + } + } +} diff --git a/nuttx/arch/8051/src/up_restorecontext.c b/nuttx/arch/8051/src/up_restorecontext.c new file mode 100644 index 000000000..cf7fc1039 --- /dev/null +++ b/nuttx/arch/8051/src/up_restorecontext.c @@ -0,0 +1,296 @@ +/************************************************************************** + * up_restorecontext.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 +#include "up_internal.h" + +/************************************************************************** + * Private Definitions + **************************************************************************/ + +/************************************************************************** + * Private Types + **************************************************************************/ + +/************************************************************************** + * Private Function Prototypes + **************************************************************************/ + +/************************************************************************** + * Global Variables + **************************************************************************/ + +/************************************************************************** + * Private Variables + **************************************************************************/ + +/************************************************************************** + * Private Functions + **************************************************************************/ + +/************************************************************************** + * Public Functions + **************************************************************************/ + +/************************************************************************** + * Name: up_restoreregisters + * + * Description: + * Restore the saved registers from the context save area. This function + * is called from up_restorecontext (below) and also from interrupt + * handling logic. + * + * Note that this function does not restore: + * a, dptr, ie - these are saved in the stack area + * sp - this can be inferred from g_irqtos or struct xcptontext.nbytes. + * + * Inputs: + * context - the context register array from which to restore the + * register values + * + * Return: + * None + * + **************************************************************************/ + +void up_restoreregisters(FAR uint8_t *regs) _naked +{ + _asm + movx a, @dptr + mov b, a + inc dptr + movx a, @dptr + mov r2, a + inc dptr + movx a, @dptr + mov r3, a + inc dptr + movx a, @dptr + mov r4, a + inc dptr + movx a, @dptr + mov r5, a + inc dptr + movx a, @dptr + mov r6, a + inc dptr + movx a, @dptr + mov r7, a + inc dptr + movx a, @dptr + mov r0, a + inc dptr + movx a, @dptr + mov r1, a + inc dptr + movx a, @dptr + mov psw, a + inc dptr + movx a, @dptr + mov _bp, a + ret + _endasm; +} + +/************************************************************************** + * Name: up_restorecontext + * + * Description: + * Restore the stack specified in the context structure and return to + * that context + * + * Inputs: + * context - Holds the stack content of the context to return to + * + * Return: + * This function does not return. + * + **************************************************************************/ + +void up_restorecontext(FAR struct xcptcontext *context) __naked +{ + _asm + ar2 = 0x02 + ar3 = 0x03 + ar4 = 0x04 + ar5 = 0x05 + ar6 = 0x06 + ar7 = 0x07 + ar0 = 0x00 + ar1 = 0x01 + + /* Dump the contents of the saved frame before it is copied back + * to memory/registers. + */ + +#ifdef CONFIG_SWITCH_FRAME_DUMP + push dpl + push dph + lcall _up_dumpframe + pop dph + pop dpl +#endif + + /* Interrupts should be disabled for the following. up_popcontext() will + * set the new interrupt state correctly. + */ + + clr ea + + /* The following logic will copy the stack from the + * context save structure into IRAM. We cannot use + * the stack in anyway during this copy. Instead, + * we will use registers as follows: + * + * R0 - Holds the working 8-bit IRAM pointer + * R1 - Not used + * R2-3 - Holds the working 16-bit XRAM pointer + * R4 - Holds the working byte count + * R5 - Holds the new stack pointer + * R6-7 - Saved context pointer + */ + + /* Fetch r4 = context->nbytes */ + + movx a, @dptr + mov r4, a + + /* Save the new stack pointer in r5 */ + + add a, #(STACK_BASE-1) + mov r5, a + + /* Save r2-3 and r6-r7 = &context->stack */ + + inc dptr + mov r2, dpl + mov r3, dph + mov r6, dpl + mov r7, dph + + /* Set r0 = stack base address */ + + mov r0, #STACK_BASE + + /* Top of the copy loop -- we cannot use the stack + * again until we finish the copy and set the new + * stack pointer (saved in r5) + */ +00001$: + mov a, r4 /* a = bytes left to transfer */ + dec r4 /* (for next time through the loop) */ + jz 00002$ /* Jump if a = 0 (done) */ + + /* Fetch the next byte from context->stack */ + + mov dpl, r2 + mov dph, r3 + movx a, @dptr + + /* Increment the XRAM pointer */ + + inc dptr + mov r2, dpl + mov r3, dph + + /* Save the next byte into IRAM */ + + mov @r0, a + + /* Increment the IRAM pointer */ + + inc r0 + sjmp 00001$ +00002$: + + /* Set the new stack pointer and recover the + * context->stack pointer. + */ + + mov sp, r5 + mov dpl, r6 + mov dph, r7 + + /* Dump the stack contents after they have + * been restored to IRAM + */ + +#ifdef CONFIG_SWITCH_FRAME_DUMP + push dpl + push dph + lcall _up_dumpstack + pop dph + pop dpl +#endif + /* Get the pointer to the register save area */ + + mov a, #STACK_SIZE + add a, dpl + mov dpl, a + clr a + addc a, dph + mov dph, a + + /* Restore registers from the register save area */ + + lcall _up_restoreregisters + + /* Restore registers from the new stack */ + + pop dph + pop dpl + + /* Restore the interrupt state per the stored IE value */ + + pop acc + jb acc.7,00003$ + clr ie.7 + sjmp 00004$ + 00003$: + setb ie.7 + + 00004$: + pop acc + ret + _endasm; +} + + diff --git a/nuttx/arch/8051/src/up_savecontext.c b/nuttx/arch/8051/src/up_savecontext.c new file mode 100644 index 000000000..9a86faa94 --- /dev/null +++ b/nuttx/arch/8051/src/up_savecontext.c @@ -0,0 +1,362 @@ +/************************************************************************** + * up_savecontext.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 +#include "up_internal.h" + +/************************************************************************** + * Private Definitions + **************************************************************************/ + +/************************************************************************** + * Private Types + **************************************************************************/ + +/************************************************************************** + * Private Function Prototypes + **************************************************************************/ + +/************************************************************************** + * Global Variables + **************************************************************************/ + +/************************************************************************** + * Private Variables + **************************************************************************/ + +/************************************************************************** + * Private Functions + **************************************************************************/ + +/************************************************************************** + * Name: up_savestack + * + * Description: + * Save the entire interrupt stack contents in the provided context + * structure. + * + * Inputs: + * context - the context structure in which to save the stack info + * + * Return: + * None + * + * Assumptions: + * - Interrupts are disabled + * + **************************************************************************/ + +static void up_savestack(FAR struct xcptcontext *context, uint8_t tos) +{ + /* Copy the current stack frame from internal RAM to XRAM. */ + + uint8_t nbytes = tos - (STACK_BASE-1); + NEAR uint8_t *src = (NEAR uint8_t*)STACK_BASE; + FAR uint8_t *dest = context->stack; + + context->nbytes = nbytes; + while (nbytes--) + { + *dest++ = *src++; + } +} + +/************************************************************************** + * Name: up_saveregs + * + * Description: + * Save the interrupt registers into the TCB. + * + * Inputs: + * context - the context structure in which to save the register info + * + * Return: + * None + * + * Assumptions: + * - Interrupts are disabled + * + **************************************************************************/ + +static void up_saveregs(FAR struct xcptcontext *context, uint8_t tos) +{ + /* Copy the irq register save area into the TCB */ + + FAR uint8_t *src = g_irqregs; + FAR uint8_t *dest = context->regs; + uint8_t nbytes = REGS_SIZE; + + while (nbytes--) + { + *dest++ = *src++; + } +} + +/************************************************************************** + * Public Functions + **************************************************************************/ + +/************************************************************************** + * Name: up_saveregisters + * + * Description: + * Save the current registers in the context save area. This function + * is called from up_savecontext (below) and also from interrupt + * handling logic. + * + * Note that this function does not save: + * a, dptr, ie - these are saved in the stack area + * sp - this can be inferred from g_irqtos or struct xcptontext.nbytes. + * + * Inputs: + * regs - the context register array in which to save the register info + * + * Return: + * None + * + **************************************************************************/ + +void up_saveregisters(FAR uint8_t *regs) _naked +{ + _asm + mov a, b + movx @dptr, a + inc dptr + mov a, r2 + movx @dptr, a + inc dptr + mov a, r3 + movx @dptr, a + inc dptr + mov a, r4 + movx @dptr, a + inc dptr + mov a, r5 + movx @dptr, a + inc dptr + mov a, r6 + movx @dptr, a + inc dptr + mov a, r7 + movx @dptr, a + inc dptr + mov a, r0 + movx @dptr, a + inc dptr + mov a, r1 + movx @dptr, a + inc dptr + mov a, psw + movx @dptr, a + clr psw + inc dptr + mov a, _bp + movx @dptr, a + ret + _endasm; +} + +/************************************************************************** + * Name: up_savecontext + * + * Description: + * Push the current execution context onto the stack, then save the + * entire stack contents in the provided context structure. + * + * Inputs: + * context - the context structure in which to save the stack info + * + * Return: + * 0 = Normal state save return + * 1 = This is the matching return from up_restorecontext() + * + **************************************************************************/ + +uint8_t up_savecontext(FAR struct xcptcontext *context) _naked +{ + _asm + /* Create the stack frame that we want when it is time to restore + * this context. The return address will be the return address + * of this function, the return value will be zero. + * + * ... + * return address (2 bytes, already on the stack) + * register a=0 (1 byte) + * register ie (1 byte) + * register dptr (2 bytes) + */ + + clr a + push acc /* ACC = 0 */ + push ie + mov a, #1 + push acc /* DPL = 1 */ + clr a + push acc /* DPH = 0 */ + + /* Dump the stack contents before they are occupied into XRAM */ + +#ifdef CONFIG_SWITCH_FRAME_DUMP + push dpl + push dph + lcall _up_dumpstack + pop dph + pop dpl +#endif + /* Disable interrupts while we create a snapshot of the stack + * and registers. At this point, we have 5 bytes on the stack + * to account for. + */ + + push ie + mov ea, 0 + + /* Save the registers in the context save area */ + + push dpl + push dph + mov a, #XCPT_REGS + add a, dpl + mov dpl, a + clr a + addc a, dph + mov dph, a + lcall _up_saveregisters + pop dph + pop dpl + +#ifdef CONFIG_SWITCH_FRAME_DUMP + /* Save the address of the context structure. We will + * need this later to dump the saved frame. Now we have + * 7 bytes on the stack to account for. + */ + + push dpl + push dph + + /* Push the top of frame stack pointer. We need to + * decrement the current SP value by three to account + * for dptr+IE on the stack above the end of the frame. + */ + + mov a, sp + subb a, #3 +#else + /* Push the top of frame stack pointer. We need to + * decrement the current stack pointer by one to account + * for IE that we saved on the stack. + */ + + mov a, sp + dec a +#endif + push acc + + /* Copy the current stack frame from internal RAM to XRAM. */ + + lcall _up_savestack + pop acc + + /* Dump the contents of the saved frame after it has been + * copied from memory/registers. + */ + +#ifdef CONFIG_SWITCH_FRAME_DUMP + pop dph + pop dpl + push dpl + push dph + lcall _up_dumpframe + pop dph + pop dpl + lcall _up_dumpstack +#endif + + /* Restore the interrupt state */ + + pop ie + + /* Now that we have a snapshot of the desired stack frame saved, + * we can release the stack frame (all but the return address) + */ + + mov a, sp + subb a, #4 + mov sp, a + mov dpl,#0 + ret + _endasm; +} + +/************************************************************************** + * Name: up_saveirqcontext + * + * Description: + * The interrupt context was saved in g_irqtos and g_irqregs when the + * interrupt was taken. If a context switch from the interrupted task + * will be made at the interrupt level, then these saved values must be + * copied into the TCB. + * + * Inputs: + * context - the structure in which to save the context info + * + * Return: + * None + * + * Assumptions: + * - Interrupts are disabled + * + **************************************************************************/ + +void up_saveirqcontext(FAR struct xcptcontext *context) +{ + /* Save the number of bytes in the stack */ + + context->nbytes = g_irqtos - (STACK_BASE-1); + + /* Copy the current stack frame from internal RAM to XRAM. */ + + up_savestack(context, g_irqtos); + + /* Copy the saved registers into the TCB */ + + up_saveregisters(context->regs); +} diff --git a/nuttx/arch/8051/src/up_timerisr.c b/nuttx/arch/8051/src/up_timerisr.c new file mode 100644 index 000000000..3ca2faad6 --- /dev/null +++ b/nuttx/arch/8051/src/up_timerisr.c @@ -0,0 +1,147 @@ +/************************************************************************ + * up_timerisr.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 + +#include +#include <8052.h> + +#include "clock_internal.h" +#include "up_internal.h" + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Private Types + ************************************************************************/ + +/************************************************************************ + * Private Function Prototypes + ************************************************************************/ + +/************************************************************************ + * Global Functions + ************************************************************************/ + +/************************************************************************ + * Function: up_timerisr + * + * Description: + * The timer ISR will perform a variety of services for + * various portions of the systems. + * + ************************************************************************/ + +int up_timerisr(int irq, FAR uint8_t *frame) +{ + /* Process timer interrupt */ + + sched_process_timer(); + return 0; +} + +/************************************************************************ + * Function: up_timerinit + * + * Description: + * This function is called during start-up to initialize + * the timer interrupt. + * + ************************************************************************/ + +void up_timerinit(void) +{ +#ifdef CONFIG_8052_TIMER2 + up_disable_irq(TIMER2_IRQ); + + /* Set up timer 2 -- See pjrc.h for details */ + + T2MOD = 0; + + /* Set up the capture count to generate 100Hz system + * interrupts. + */ + + RCAP2L = TIMER2_CAPTURE_LOW; + RCAP2H = TIMER2_CAPTURE_HIGH; + + TL2 = TIMER2_CAPTURE_LOW; + TH2 = TIMER2_CAPTURE_HIGH; + + /* Configure for interrupts */ + + T2CON = 0x04; + + /* Attach and enable the timer interrupt */ + + irq_attach(TIMER2_IRQ, (xcpt_t)up_timerisr); + up_enable_irq(TIMER2_IRQ); + +#else + /* Timer 0, mode 0 can be used as a system timer. In that mode, the + * 1.8432 MHz clock is divided by 32. A single 8-bit value is incremented + * at 57600 Hz, which results in 225 Timer 0 overflow interrupts per + * second. + */ + + up_disable_irq(TIMER0_IRQ); + + /* Initialize timer 0 */ + + TR0 = 0; /* Make sure timer 0 is stopped */ + TF0 = 0; /* Clear the overflow flag */ + TMOD &= 0xF0; /* Set to mode 0 (without changing timer1) */ + TL0 = 0; /* Clear timer 0 value */ + TH0 = 0; + + /* Attach and enable the timer interrupt */ + + irq_attach(TIMER0_IRQ, (xcpt_t)up_timerisr); + + TR0 = 1; /* Start the timer */ + up_enable_irq(TIMER0_IRQ); + +#endif +} + diff --git a/nuttx/arch/8051/src/up_unblocktask.c b/nuttx/arch/8051/src/up_unblocktask.c new file mode 100644 index 000000000..9152eae0a --- /dev/null +++ b/nuttx/arch/8051/src/up_unblocktask.c @@ -0,0 +1,166 @@ +/************************************************************************ + * up_unblocktask.c + * + * Copyright (C) 2007, 2009 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 NuttX 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 + +#include + +#include "clock_internal.h" +#include "os_internal.h" +#include "up_internal.h" + +/************************************************************************ + * Private Definitions + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +/************************************************************************ + * Private Funtions + ************************************************************************/ + +/************************************************************************ + * Public Funtions + ************************************************************************/ + +/************************************************************************ + * Name: up_unblock_task + * + * Description: + * A task is currently in an inactive task list + * but has been prepped to execute. Move the TCB to the + * ready-to-run list, restore its context, and start execution. + * + * Inputs: + * tcb: Refers to the tcb to be unblocked. This tcb is + * in one of the waiting tasks lists. It must be moved to + * the ready-to-run list and, if it is the highest priority + * ready to run taks, executed. + * + ************************************************************************/ + +void up_unblock_task(FAR _TCB *tcb) +{ + /* Verify that the context switch can be performed */ + + if ((tcb->task_state < FIRST_BLOCKED_STATE) || + (tcb->task_state > LAST_BLOCKED_STATE)) + { + PANIC(OSERR_BADUNBLOCKSTATE); + } + else + { + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + + dbg("Unblocking TCB=%p\n", tcb); + + /* Remove the task from the blocked task list */ + + sched_removeblocked(tcb); + + /* Reset its timeslice. This is only meaningful for round + * robin tasks but it doesn't here to do it for everything + */ + +#if CONFIG_RR_INTERVAL > 0 + tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; +#endif + + /* Add the task in the correct location in the prioritized + * g_readytorun task list + */ + + if (sched_addreadytorun(tcb)) + { + /* The currently active task has changed! We need to do + * a context switch to the new task. + * + * Are we in an interrupt handler? + */ + + if (g_irqtos) + { + /* Yes, then we have to do things differently. + * Just copy the current stack into the OLD rtcb. + */ + + up_saveirqcontext(&rtcb->xcp); + + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. + */ + + rtcb = (FAR _TCB*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then setup so that the context will be performed on exit + * from the interrupt. + */ + + g_irqcontext = &rtcb->xcp; + } + + /* We are not in an interrupt andler. Copy the user C context + * into the TCB of the task that was previously active. if + * up_savecontext returns a non-zero value, then this is really the + * previously running task restarting! + */ + + else if (!up_savecontext(&rtcb->xcp)) + { + /* Restore the exception context of the new task that is ready to + * run (probably tcb). This is the new rtcb at the head of the + * g_readytorun task list. + */ + + rtcb = (FAR _TCB*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then switch contexts */ + + up_restorecontext(&rtcb->xcp); + } + } + } +} diff --git a/nuttx/arch/README.txt b/nuttx/arch/README.txt index 21296e994..7ef23b3d3 100644 --- a/nuttx/arch/README.txt +++ b/nuttx/arch/README.txt @@ -253,7 +253,7 @@ arch/sh - SuperH and related Hitachi/Renesas microcontrollers arch/sh/include/shs and arch/sh/src/sh1 Support for the SH-1 processor. -arch/pjrc-8051 - 8051/52 microcontrollers +arch/8051 - 8051/52 microcontrollers 8051 Microcontroller. This port is not quite ready for prime time. arch/z16 - ZiLOG 16-bit processors diff --git a/nuttx/arch/pjrc-8051/include/arch.h b/nuttx/arch/pjrc-8051/include/arch.h deleted file mode 100644 index 1ca504fb8..000000000 --- a/nuttx/arch/pjrc-8051/include/arch.h +++ /dev/null @@ -1,85 +0,0 @@ -/************************************************************************ - * arch.h - * - * Copyright (C) 2007, 2009 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 NuttX 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. - * - ************************************************************************/ - -/* This file should never be included directed but, rather, - * only indirectly through nuttx/arch.h - */ - -#ifndef __ARCH_ARCH_H -#define __ARCH_ARCH_H - -/************************************************************************ - * Included Files - ************************************************************************/ - -#include - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Public Types - ************************************************************************/ - -/************************************************************************ - * Public Variables - ************************************************************************/ - -/************************************************************************ - * Public Function Prototypes - ************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/* The 805x family has a tiny, 256 stack and can be easily - * overflowed. The following macro can be used to instrument - * code to dump the stack pointer at critical locations. - */ - -EXTERN void up_showsp(uint8_t ch) __naked; - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __ARCH_ARCH_H */ - diff --git a/nuttx/arch/pjrc-8051/include/irq.h b/nuttx/arch/pjrc-8051/include/irq.h deleted file mode 100644 index 29b19d280..000000000 --- a/nuttx/arch/pjrc-8051/include/irq.h +++ /dev/null @@ -1,206 +0,0 @@ -/************************************************************************ - * irq.h - * - * Copyright (C) 2007, 2009 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 NuttX 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. - * - ************************************************************************/ - -/* This file should never be included directed but, rather, - * only indirectly through nuttx/irq.h - */ - -#ifndef __ARCH_IRQ_H -#define __ARCH_IRQ_H - -/************************************************************************ - * Included Files - ************************************************************************/ - -#include -#ifndef __ASSEMBLY__ -# include -#endif - -/************************************************************************ - * Definitions - ************************************************************************/ - -#define EXT_INT0_IRQ 0 -#define TIMER0_IRQ 1 -#define EXT_INT1_IRQ 2 -#define TIMER1_IRQ 3 -#define UART_IRQ 4 -#define TIMER2_IRQ 5 - -#define NR_IRQS 6 - -/* The stack for all tasks/threads lie at the same position - * in IRAM. On context switches, the STACK contents will be - * copied into the TCB. - */ - -#define IRAM_BASE 0x0000 -#ifdef CONFIG_ARCH_8052 -# define IRAM_SIZE 0x0100 -#else -# define IRAM_SIZE 0x0080 -#endif - -#define STACK_BASE 0x0024 -#define STACK_SIZE (IRAM_SIZE - STACK_BASE) - -/* This is the form of initial stack frame - * - * This initial stack frame will be configured to hold. - * (1) The 16-bit return address of either: - * - * void task_start(void); - * void pthread_start(void) - * - * The return address is stored at the top of stack. - * so that the RETI instruction will work: - * - * PC15-8 <- ((SP)) - * (SP) <- (SP) -1 - * PC7-0 <- ((SP)) - * (SP) <- (SP) -1 - */ - -#define FRAME_RETLS 0 -#define FRAME_RETMS 1 - -/* Then a partial context context save area that can be - * indexed with the following definitions (relative to the - * beginning of the initial frame. - */ - -#define FRAME_ACC 2 -#define FRAME_IE 3 -#define FRAME_DPL 4 -#define FRAME_DPH 5 - -#define FRAME_SIZE 6 - -/* The remaining registers are not saved on the stack (due - * to the limited stack size of the 8051/2) but in an array - * in the TCB: - */ - -#define REGS_B 0 -#define REGS_R2 1 -#define REGS_R3 2 -#define REGS_R4 3 -#define REGS_R5 4 -#define REGS_R6 5 -#define REGS_R7 6 -#define REGS_R0 7 -#define REGS_R1 8 -#define REGS_PSW 9 -#define REGS_BP 10 - -#define REGS_SIZE 11 - -/* Note that the stack pointer is not saved. Rather, the - * size of the saved stack frame is saved in the 'nbytes' - * field. Since that stack begins at a fixed location, the - * top-of-stack pointer can be derived from the saved size. - */ - -/* These are offsets into struct xcptcontext that can be - * used from assembly language to access the structure. - */ - -#define XCPT_NBYTES 0 -#define XCPT_STACK 1 -#define XCPT_REGS (STACK_SIZE+1) - -#define XCPT_SIZE (STACK_SIZE+REGS_SIZE+1) - -/************************************************************************ - * Public Types - ************************************************************************/ - -/* This struct defines the way the registers are stored */ - -#ifndef __ASSEMBLY__ -struct xcptcontext -{ - /* This is the number of valid bytes currently saved in - * stack[]. Since that stack begins at a fixed location, - * the top-of-stack pointer can be derived from this size. - */ - - uint8_t nbytes; - - /* This is the saved stack. Space is allocated for the - * entire 256 byte IRAM (minus register and bit usage at - * the beginning). - */ - - uint8_t stack[STACK_SIZE]; - - /* These are save 8051/2 registers. These are saved - * separately from the stack to increase the effective - * stack size. - */ - - uint8_t regs[REGS_SIZE]; -}; -#endif /* __ASSEMBLY */ - -/************************************************************************ - * Public Variables - ************************************************************************/ - -/************************************************************************ - * Public Function Prototypes - ************************************************************************/ - -#ifndef __ASSEMBLY__ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -EXTERN irqstate_t irqsave(void); -EXTERN void irqrestore(irqstate_t flags); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __ASSEMBLY */ -#endif /* __ARCH_IRQ_H */ - diff --git a/nuttx/arch/pjrc-8051/include/limits.h b/nuttx/arch/pjrc-8051/include/limits.h deleted file mode 100644 index fa93f188c..000000000 --- a/nuttx/arch/pjrc-8051/include/limits.h +++ /dev/null @@ -1,79 +0,0 @@ -/************************************************************ - * arch/pjrc-8051/include/limits.h - * - * Copyright (C) 2007, 2009 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. - * - ************************************************************/ - -#ifndef __ARCH_PJRC8051_INCLUDE_LIMITS_H -#define __ARCH_PJRC8051_INCLUDE_LIMITS_H - -/************************************************************ - * Included Files - ************************************************************/ - -/************************************************************ - * Definitions - ************************************************************/ - -#define CHAR_BIT 8 -#define SCHAR_MIN 0x80 -#define SCHAR_MAX 0x7f -#define UCHAR_MAX 0xff - -/* These could be different on machines where char is unsigned */ - -#define CHAR_MIN SCHAR_MIN -#define CHAR_MAX SCHAR_MAX - -#define SHRT_MIN 0x8000 -#define SHRT_MAX 0x7fff -#define USHRT_MAX 0xffff - -#define INT_MIN 0x8000 -#define INT_MAX 0x7fff -#define UINT_MAX 0xffff - -/* These change on 32-bit and 64-bit platforms */ - -#define LONG_MAX 0x80000000 -#define LONG_MIN 0x7fffffff -#define ULONG_MAX 0xffffffff - -/* For SDCC, a Generic pointer is 3 bytes in length with the - * first byte holding data space information. - */ - -#define PTR_MIN 0x800000 -#define PTR_MAX 0x7fffff -#define UPTR_MAX 0xffffff - -#endif /* __ARCH_PJRC8051_INCLUDE_LIMITS_H */ diff --git a/nuttx/arch/pjrc-8051/include/types.h b/nuttx/arch/pjrc-8051/include/types.h deleted file mode 100644 index 45141634c..000000000 --- a/nuttx/arch/pjrc-8051/include/types.h +++ /dev/null @@ -1,98 +0,0 @@ -/************************************************************************ - * arch/pjrc-8051/include/types.h - * - * Copyright (C) 2007, 2009 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 NuttX 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. - * - ************************************************************************/ - -/* This file should never be included directed but, rather, - * only indirectly through sys/types.h - */ - -#ifndef __ARCH_PJRC8051_INCLUDE_TYPES_H -#define __ARCH_PJRC8051_INCLUDE_TYPES_H - -/************************************************************************ - * Included Files - ************************************************************************/ - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Type Declarations - ************************************************************************/ - -#ifndef __ASSEMBLY__ - -/* These are the sizes of the standard integer types. NOTE that these type - * names have a leading underscore character. This file will be included - * (indirectly) by include/stdint.h and typedef'ed to the final name without - * the underscore character. This roundabout way of doings things allows - * the stdint.h to be removed from the include/ directory in the event that - * the user prefers to use the definitions provided by their toolchain header - * files - * - * - * For SDCC, sizeof(int) is 16 and sizeof(long) is 32. - * long long and double are not supported. - */ - -typedef char _int8_t; -typedef unsigned char _uint8_t; - -typedef int _int16_t; -typedef unsigned int _uint16_t; - -typedef long _int32_t; -typedef unsigned long _uint32_t; - -/* For SDCC, a Generic pointer is 3 bytes in length with the - * first byte holding data space information. - */ - -typedef long _intptr_t; -typedef unsigned long _uintptr_t; - -/* This is the size of the interrupt state save returned by - * irqsave() - */ - -typedef unsigned char irqstate_t; - -#endif /* __ASSEMBLY__ */ - -/************************************************************************ - * Global Function Prototypes - ************************************************************************/ - -#endif /* __ARCH_PJRC8051_INCLUDE_TYPES_H */ diff --git a/nuttx/arch/pjrc-8051/src/Makefile b/nuttx/arch/pjrc-8051/src/Makefile deleted file mode 100644 index d77bf546d..000000000 --- a/nuttx/arch/pjrc-8051/src/Makefile +++ /dev/null @@ -1,223 +0,0 @@ -############################################################################ -# arch/pjrc-8051/src/Makefile -# -# Copyright (C) 2007, 2008 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 NuttX 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. -# -############################################################################ - --include $(TOPDIR)/Make.defs - -CFLAGS += -I$(TOPDIR)/sched -ASFLAGS = -x -j -g -l -s -p -CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) -D__ASSEMBLY__ - -SSRCS = -ASRCS = $(SSRCS:.S=$(ASMEXT)) -AOBJS = $(ASRCS:$(ASMEXT)=$(OBJEXT)) -CSRCS = up_initialize.c up_idle.c up_interruptcontext.c \ - up_initialstate.c up_unblocktask.c up_blocktask.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_delay.c -COBJS = $(CSRCS:.c=$(OBJEXT)) -SRCS = $(SSRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -SDCCLIBDIR = /usr/local/share/sdcc/lib/large-stack-auto -SDCCPATH = -L$(SDCCLIBDIR) -SDCCLIBS = -llibfloat.lib -llibint.lib -lliblong.lib -llibmysdcc.lib -lmcs51.lib - -LINKSSRCS = up_head.S -LINKASRCS = $(LINKSSRCS:.S=$(ASMEXT)) -LINKOBJS = $(LINKASRCS:$(ASMEXT)=$(OBJEXT)) -LINKLIBS = -LDPATHES = $(addprefix -L$(TOPDIR)/,$(dir $(LINKLIBS))) -LDLIBS = $(addprefix -l,$(notdir $(LINKLIBS))) - -TESTSRCS = up_irqtest.c -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 \ - --data-loc $(DEF_STACK_BASE) --iram-size $(IRAM_SIZE) \ - --code-loc 0x2100 --code-size 0x5f40 \ - --xram-loc $(IRAM_SIZE) --xram-size 0x1f00 - -DEPSRCS = $(SRCS) $(LINKSSRCS) - -HEAP1_BASE = ${shell \ - if [ -e pass1.mem ]; then \ - cat pass1.mem | grep "EXTERNAL RAM" | \ - sed -e "s/[ ][ ]*/ /g" | cut -d' ' -f5 ; \ - else \ - echo $(IRAM_SIZE) ; \ - fi \ - } -DEF_HEAP2_BASE = 0x6000 -HEAP2_BASE = ${shell \ - if [ -e pass1.mem ]; then \ - cat pass1.mem | grep "ROM/EPROM/FLASH" | \ - sed -e "s/[ ][ ]*/ /g" | cut -d' ' -f4 ; \ - else \ - echo $(DEF_HEAP2_BASE) ; \ - fi \ - } -STACK_BASE = ${shell \ - if [ -e pass1.mem ]; then \ - cat pass1.mem | grep "Stack starts" | \ - cut -d' ' -f4 ; \ - else \ - echo $(DEF_STACK_BASE) ; \ - fi \ - } - -all: up_head$(OBJEXT) libarch$(LIBEXT) - -$(ASRCS) $(LINKASRCS): %$(ASMEXT): %.S - $(CPP) -P $(CPPFLAGS) $< -o $@ - -$(AOBJS) $(LINKOBJS): $(ASRCS) $(LINKASRCS) - $(call ASSEMBLE, $<, $@) - -$(COBJS) $(TESTOBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -# Create a header file that contains addressing information needed by the code - -pass1.mem: - -up_mem.h: pass1.mem - @echo "#ifndef __ARCH_MEM_H" >up_mem.h - @echo "#define __ARCH_MEM_H" >>up_mem.h - @echo "" >>up_mem.h - @echo "#define UP_DEFAULT_STACK_BASE $(DEF_STACK_BASE)" >>up_mem.h - @echo "#define UP_DEFAULT_HEAP1_BASE $(IRAM_SIZE)" >> up_mem.h - @echo "#define UP_DEFAULT_HEAP2_BASE $(DEF_HEAP2_BASE)" >> up_mem.h - @echo "" >>up_mem.h - @echo "#define UP_STACK_BASE $(STACK_BASE)" >>up_mem.h - @echo "#if UP_STACK_BASE > UP_DEFAULT_STACK_BASE" >>up_mem.h - @echo "# error \"Stack overlap: $(DEF_STACK_BASE) < $(STACK_BASE)\"" >>up_mem.h - @echo "#elif UP_STACK_BASE < UP_DEFAULT_STACK_BASE" >>up_mem.h - @echo "# warning \"Wasted stack: $(DEF_STACK_BASE) > $(STACK_BASE)\"" >>up_mem.h - @echo "#endif" >>up_mem.h - @echo "" >>up_mem.h - @echo "#define UP_HEAP1_BASE $(HEAP1_BASE)" >> up_mem.h - @echo "#define UP_HEAP1_END 0x2000" >> up_mem.h - @echo "" >>up_mem.h - @echo "#define UP_HEAP2_BASE $(HEAP2_BASE)" >> up_mem.h - @echo "#define UP_HEAP2_END 0x8000" >> up_mem.h - @echo "" >>up_mem.h - @echo "#endif /* __ARCH_MEM_H */" >>up_mem.h - -# Combine all objects in this directory into a library - -libarch$(LIBEXT): up_mem.h $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ - done ; ) - -# This is a kludge to work around some conflicting symbols in libsdcc.liXqueb - -$(SDCCLIBDIR)/libmysdcc.lib: $(SDCCLIBDIR)/libsdcc.lib - @cat $(SDCCLIBDIR)/libsdcc.lib | \ - grep -v calloc | grep -v malloc | grep -v realloc | \ - grep -v free | grep -v vprintf | grep -v _strncpy | \ - grep -v _strchr | grep -v _strlen | grep -v _strcmp | \ - grep -v _strcpy | grep -v _memcmp | grep -v _memcpy | \ - grep -v _memset \ - > 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) board/libboard$(LIBEXT) - @echo "LD: $@" - @$(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) - @echo "LD: $@" - @$(CC) $(LDFLAGS) $(LDPATHES) -L$(BOARDDIR) $(SDCCPATH) $(LINKOBJS) \ - $(LDLIBS) -llibboard$(LIBEXT) $(SDCCLIBS) -o $@ - -nuttx$(EXEEXT): pass1.ihx nuttx.ihx - @rm -f pass1.* - @packihx nuttx.ihx > $(TOPDIR)/nuttx$(EXEEXT) - @cp -f nuttx.map $(TOPDIR)/. - -# This target builds a test program to verify interrupt context switching. irqtest is -# a PHONY target that just sets upt the up_irqtest build correctly - -up_irqtest.ihx: $(TESTOBJS) - $(CC) $(LDFLAGS) -L. $(SDCCPATH) $(TESTLINKOBJS) $(TESTOBJS) $(TESTEXTRAOBJS) $(SDCCLIBS) -o $@ - -irqtest: - $(MAKE) TOPDIR=../../.. up_irqtest.ihx - -# Build dependencies - -.depend: Makefile up_mem.h $(DEPSRCS) - @if [ -e board/Makefile ]; then \ - $(MAKE) -C board TOPDIR=$(TOPDIR) depend ; \ - fi - @$(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 *~ .*.swp - $(call CLEAN) - -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/nuttx/arch/pjrc-8051/src/up_allocateheap.c b/nuttx/arch/pjrc-8051/src/up_allocateheap.c deleted file mode 100644 index 6ef1a77da..000000000 --- a/nuttx/arch/pjrc-8051/src/up_allocateheap.c +++ /dev/null @@ -1,89 +0,0 @@ -/************************************************************ - * up_allocateheap.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 -#include -#include -#include -#include "os_internal.h" -#include "up_internal.h" -#include "up_mem.h" - -/************************************************************ - * Private Definitions - ************************************************************/ - -/************************************************************ - * Private Data - ************************************************************/ - -/************************************************************ - * Private Functions - ************************************************************/ - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: up_allocate_heap - * - * Description: - * The heap may be statically allocated by - * defining CONFIG_HEAP_BASE and CONFIG_HEAP_SIZE. If these - * are not defined, then this function will be called to - * dynamically set aside the heap region. - * - ************************************************************/ - -void up_allocate_heap(FAR void **heap_start, size_t *heap_size) -{ - *heap_start = (FAR void*)UP_HEAP1_BASE; - *heap_size = UP_HEAP1_END - UP_HEAP1_BASE; - up_ledon(LED_HEAPALLOCATE); -} - -#if CONFIG_MM_REGIONS > 1 -void up_addregion(void) -{ - mm_addregion((FAR void*)UP_HEAP2_BASE, UP_HEAP2_END - UP_HEAP2_BASE); -} -#endif diff --git a/nuttx/arch/pjrc-8051/src/up_assert.c b/nuttx/arch/pjrc-8051/src/up_assert.c deleted file mode 100644 index 157b18ae5..000000000 --- a/nuttx/arch/pjrc-8051/src/up_assert.c +++ /dev/null @@ -1,141 +0,0 @@ -/************************************************************************ - * up_assert.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 -#include -#include - -#include <8052.h> -#include "os_internal.h" -#include "up_internal.h" -#include "up_mem.h" - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Private Data - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Name: _up_assert - ************************************************************************/ - -static void _up_assert(int errorcode) /* __attribute__ ((noreturn)) */ -{ - /* Are we in an interrupt handler or the idle task? */ - - if (g_irqtos || ((FAR _TCB*)g_readytorun.head)->pid == 0) - { - (void)irqsave(); - for(;;) - { -#ifdef CONFIG_ARCH_LEDS - up_ledon(LED_PANIC); - up_delay(250); - up_ledoff(LED_PANIC); - up_delay(250); -#endif - } - } - else - { - exit(errorcode); - } -} - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: up_assert - ************************************************************************/ - -void up_assert(const uint8_t *filename, int lineno) -{ -#if CONFIG_TASK_NAME_SIZE > 0 - _TCB *rtcb = (_TCB*)g_readytorun.head; -#endif - - up_ledon(LED_ASSERTION); - -#if CONFIG_TASK_NAME_SIZE > 0 - lldbg("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, rtcb->name); -#else - lldbg("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - - up_dumpstack(); - _up_assert(EXIT_FAILURE); -} - -/************************************************************************ - * Name: up_assert_code - ************************************************************************/ - -void up_assert_code(const uint8_t *filename, int lineno, int errorcode) -{ -#if CONFIG_TASK_NAME_SIZE > 0 - _TCB *rtcb = (_TCB*)g_readytorun.head; -#endif - - up_ledon(LED_ASSERTION); - -#if CONFIG_TASK_NAME_SIZE > 0 - lldbg("Assertion failed at file:%s line: %d task: %s error code: %d\n", - filename, lineno, rtcb->name, errorcode); -#else - lldbg("Assertion failed at file:%s line: %d error code: %d\n", - filename, lineno, errorcode); -#endif - - up_dumpstack(); - _up_assert(errorcode); -} diff --git a/nuttx/arch/pjrc-8051/src/up_blocktask.c b/nuttx/arch/pjrc-8051/src/up_blocktask.c deleted file mode 100644 index 811955efa..000000000 --- a/nuttx/arch/pjrc-8051/src/up_blocktask.c +++ /dev/null @@ -1,172 +0,0 @@ -/************************************************************************ - * up_blocktask.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 -#include -#include - -#include "os_internal.h" -#include "up_internal.h" - -/************************************************************************ - * Private Definitions - ************************************************************************/ - -/************************************************************************ - * Private Data - ************************************************************************/ - -/************************************************************************ - * Private Funtions - ************************************************************************/ - -/************************************************************************ - * Public Funtions - ************************************************************************/ - -/************************************************************************ - * Name: up_block_task - * - * Description: - * The currently executing task at the head of - * the ready to run list must be stopped. Save its context - * and move it to the inactive list specified by task_state. - * - * Inputs: - * tcb: Refers to a task in the ready-to-run list (normally - * the task at the head of the list). It most be - * stopped, its context saved and moved into one of the - * waiting task lists. It it was the task at the head - * of the ready-to-run list, then a context to the new - * ready to run task must be performed. - * task_state: Specifies which waiting task list should be - * hold the blocked task TCB. - * - ************************************************************************/ - -void up_block_task(FAR _TCB *tcb, tstate_t task_state) -{ - /* Verify that the context switch can be performed */ - - if ((tcb->task_state < FIRST_READY_TO_RUN_STATE) || - (tcb->task_state > LAST_READY_TO_RUN_STATE)) - { - PANIC(OSERR_BADBLOCKSTATE); - } - else - { - FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - bool switch_needed; - - dbg("Blocking TCB=%p\n", tcb); - - /* Remove the tcb task from the ready-to-run list. If we - * are blocking the task at the head of the task list (the - * most likely case), then a context switch to the next - * ready-to-run task is needed. In this case, it should - * also be true that rtcb == tcb. - */ - - switch_needed = sched_removereadytorun(tcb); - - /* Add the task to the specified blocked task list */ - - sched_addblocked(tcb, (tstate_t)task_state); - - /* If there are any pending tasks, then add them to the g_readytorun - * task list now - */ - - if (g_pendingtasks.head) - { - switch_needed |= sched_mergepending(); - } - - /* Now, perform the context switch if one is needed */ - - if (switch_needed) - { - /* Are we in an interrupt handler? */ - - if (g_irqtos) - { - /* Yes, then we have to do things differently. - * Just copy the current registers into the OLD rtcb. - */ - - up_saveirqcontext(&tcb->xcp); - - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ - - rtcb = (FAR _TCB*)g_readytorun.head; - dbg("New Active Task TCB=%p\n", rtcb); - - /* Then setup so that the context will be performed on exit - * from the interrupt. - */ - - g_irqcontext = &rtcb->xcp; - } - - /* Copy the user C context into the TCB at the (old) head of the - * g_readytorun Task list. if up_savecontext returns a non-zero - * value, then this is really the previously running task restarting! - */ - - else if (!up_savecontext(&rtcb->xcp)) - { - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ - - rtcb = (FAR _TCB*)g_readytorun.head; - dbg("New Active Task TCB=%p\n", rtcb); - - /* Then switch contexts */ - - up_restorecontext(&rtcb->xcp); - } - } - } -} diff --git a/nuttx/arch/pjrc-8051/src/up_debug.c b/nuttx/arch/pjrc-8051/src/up_debug.c deleted file mode 100644 index 9d9bce2a0..000000000 --- a/nuttx/arch/pjrc-8051/src/up_debug.c +++ /dev/null @@ -1,255 +0,0 @@ -/************************************************************************ - * up_assert.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 -#include - -#include <8052.h> -#include -#include - -#include "up_internal.h" -#include "up_mem.h" - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Private Data - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -#if defined(CONFIG_FRAME_DUMP) && defined(CONFIG_ARCH_BRINGUP) -static void up_putspace(void) __naked -{ - _asm - mov a, #0x20 - ljmp PM2_ENTRY_COUT - _endasm; -} - -static void _up_putcolon(void) __naked -{ - _asm - mov a, #0x3a - ljmp PM2_ENTRY_COUT - _endasm; -} - -static void _up_dump16(__code char *ptr, uint8_t msb, uint8_t lsb) -{ - up_puts(ptr); - up_puthex(msb); - up_puthex(lsb); - up_putnl(); -} - -static void _up_dump8(__code char *ptr, uint8_t b) -{ - up_puts(ptr); - up_puthex(b); - up_putnl(); -} -#endif - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: up_puthex, up_puthex16, up_putnl, up_puts - ************************************************************************/ - -#if defined(CONFIG_ARCH_BRINGUP) -void up_puthex(uint8_t hex) __naked -{ - hex; /* To avoid unreferenced argument warning */ - _asm - mov a, dpl - ljmp PM2_ENTRY_PHEX - _endasm; -} - -void up_puthex16(int hex) __naked -{ - hex; /* To avoid unreferenced argument warning */ - _asm - ljmp PM2_ENTRY_PHEX16 - _endasm; -} - -void up_putnl(void) __naked -{ - _asm - ljmp PM2_ENTRY_NEWLINE - _endasm; -} - -void up_puts(__code char *ptr) -{ - for (; *ptr; ptr++) - { - up_putc(*ptr); - } -} -#endif - -/************************************************************************ - * Name: up_dumpstack - ************************************************************************/ - -#if defined(CONFIG_FRAME_DUMP) && defined(CONFIG_ARCH_BRINGUP) -void up_dumpstack(void) -{ - NEAR uint8_t *start = (NEAR uint8_t *)(STACK_BASE & 0xf0); - NEAR uint8_t *end = (NEAR uint8_t *)SP; - uint8_t i; - - while (start < end) - { - up_puthex((uint8_t)start); - _up_putcolon(); - - for (i = 0; i < 8; i++) - { - up_putspace(); - if (start < (NEAR uint8_t *)(STACK_BASE) || - start > end) - { - up_putspace(); - up_putspace(); - } - else - { - up_puthex(*start); - } - start++; - } - up_putnl(); - } -} -#endif - -/************************************************************************ - * Name: up_dumpframe - ************************************************************************/ - -#if defined(CONFIG_FRAME_DUMP) && defined(CONFIG_ARCH_BRINGUP) -void up_dumpframe(FAR struct xcptcontext *context) -{ -#ifdef CONFIG_FRAME_DUMP_SHORT - FAR uint8_t *stack = &context->stack[context->nbytes - FRAME_SIZE]; - FAR uint8_t *regs = context->regs; - - _up_dump16(" RET ", stack[FRAME_RETMS], stack[FRAME_RETLS]); - _up_dump8 (" IE ", stack[FRAME_IE]); - _up_dump16(" DPTR ", stack[FRAME_DPH], stack[FRAME_DPL]); - _up_dump8 (" PSW ", regs[REGS_PSW]); - _up_dump8 (" SP ", context->nbytes + (STACK_BASE-1)); -#else - FAR uint8_t *stack = &context->stack[context->nbytes - FRAME_SIZE]; - FAR uint8_t *regs = context->regs; - uint8_t i, j, k; - - _up_dump8 (" NBYTES ", context->nbytes); - - for (i = 0; i < context->nbytes; i += 8) - { - up_puthex(i); - _up_putcolon(); - - for (j = 0; j < 8; j++) - { - k = i + j; - up_putspace(); - if (k >= context->nbytes) - { - up_putspace(); - up_putspace(); - } - else - { - up_puthex(context->stack[k]); - } - } - up_putnl(); - } - - up_puts(" REGS:"); - for (i = 0; i < REGS_SIZE; i++) - { - up_putspace(); - up_puthex(context->regs[i]); - } - up_putnl(); -#endif -} -#endif - -/************************************************************************ - * Name: up_dumpframe - ************************************************************************/ - -/* The 805x family has a tiny, 256 stack and can be easily - * overflowed. The following macro can be used to instrument - * code to dump the stack pointer at critical locations. - */ - -#ifdef CONFIG_ARCH_PJRC -void up_showsp(uint8_t ch) __naked -{ - ch; - _asm - mov a, dpl - lcall PM2_ENTRY_COUT - mov a, sp - lcall PM2_ENTRY_PHEX - lcall PM2_ENTRY_NEWLINE - _endasm; -} -#endif - - diff --git a/nuttx/arch/pjrc-8051/src/up_delay.c b/nuttx/arch/pjrc-8051/src/up_delay.c deleted file mode 100644 index 3403c69cc..000000000 --- a/nuttx/arch/pjrc-8051/src/up_delay.c +++ /dev/null @@ -1,93 +0,0 @@ -/************************************************************************ - * up_delay.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 - ************************************************************************/ - -/************************************************************************ - * Private Types - ************************************************************************/ - -/************************************************************************ - * Private Function Prototypes - ************************************************************************/ - -/************************************************************************ - * Private Variables - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - - -/************************************************************************ - * Public Funtions - ************************************************************************/ - -/************************************************************************ - * Name: up_delay - * - * Description: - * Delay inline for the requested number of milliseconds. - * NOT multi-tasking friendly. - * - ************************************************************************/ - -void up_delay(uint8_t milliseconds) __naked -{ - _asm - mov r0, dpl -00001$: mov r1, #230 -00002$: nop - nop - nop - nop - nop - nop - djnz r1, 00002$ - djnz r0, 00001$ - ret - _endasm; -} diff --git a/nuttx/arch/pjrc-8051/src/up_exit.c b/nuttx/arch/pjrc-8051/src/up_exit.c deleted file mode 100644 index 736fc71d5..000000000 --- a/nuttx/arch/pjrc-8051/src/up_exit.c +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************************** - * up_exit.c - * - * Copyright (C) 2007-2009 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 NuttX 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 - -#include <8052.h> -#include - -#include "os_internal.h" -#include "up_internal.h" - -/**************************************************************************************** - * Private Definitions - ****************************************************************************************/ - -/**************************************************************************************** - * Private Data - ****************************************************************************************/ - -/**************************************************************************************** - * Private Functions - ****************************************************************************************/ - -/**************************************************************************************** - * Public Functions - ****************************************************************************************/ - -/**************************************************************************************** - * Name: _exit - * - * Description: - * This function causes the currently executing task to cease - * to exist. This is a special case of task_delete() where the task to - * be deleted is the currently executing task. It is more complex because - * a context switch must be perform to the next ready to run task. - * - ****************************************************************************************/ - -void _exit(int status) -{ - FAR _TCB* tcb; - - dbg("TCB=%p exitting\n", tcb); - - /* Disable interrupts. Interrupts will remain disabled until - * the new task is resumed below when the save IE is restored. - */ - - EA = 0; - - /* Destroy the task at the head of the ready to run list. */ - - (void)task_deletecurrent(); - - /* Now, perform the context switch to the new ready-to-run task at the - * head of the list. - */ - - tcb = (FAR _TCB*)g_readytorun.head; - dbg("New Active Task TCB=%p\n", tcb); - - /* Then switch contexts */ - - up_restorecontext(&tcb->xcp); -} - diff --git a/nuttx/arch/pjrc-8051/src/up_head.S b/nuttx/arch/pjrc-8051/src/up_head.S deleted file mode 100644 index 44f8038c9..000000000 --- a/nuttx/arch/pjrc-8051/src/up_head.S +++ /dev/null @@ -1,471 +0,0 @@ -/************************************************************ - * up_head.S - * - * 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" - - .module up_head - .optsdcc -mmcs51 --model-large - -/************************************************************ - * Private Data - ************************************************************/ - - .area REG_BANK_0 (REL,OVR,DATA) - .ds 8 - -#ifndef CONFIG_8052_TIMER2 - .area XSEG -_g_timer0tick: - .ds 1 -#endif - -/************************************************************ - * Public Data - ************************************************************/ - - .globl _g_irqtos - .globl _g_irqcontext - .globl _g_irqregs - -/************************************************************ - * Public Functions - ************************************************************/ - - .globl _irq_dispatch - .globl _up_restoreregisters - -/************************************************************ - * Program entry points - ************************************************************/ - -/* Program entry is through PROGRAM_BASE. This is just a - * branch to our start up logic. - */ - - .area CODE1 (ABS) - .org PROGRAM_BASE - ljmp start - -/* These are indirect interrupt vectors. Logic in PAULMON2, - * captures the interrupt vectors (near address 0x0000) and - * re-routes them through the following entry points. - * - * Each of these saves acc and ie then passes the IRQ number - * to higher level logic in a - */ - - .org PM2_VECTOR_EXTINT0 - push acc - mov a, #EXT_INT0_IRQ - ljmp _up_interrupt - - .org PM2_VECTOR_TIMER0 - push acc -#ifdef CONFIG_8052_TIMER2 - mov a, #TIMER0_IRQ - ljmp _up_interrupt -#else - ljmp _up_timer0 -#endif - .org PM2_VECTOR_EXTINT1 - push acc - mov a, #EXT_INT1_IRQ - ljmp _up_interrupt - - .org PM2_VECTOR_TIMER1 - push acc - mov a, #TIMER1_IRQ - ljmp _up_interrupt - - .org PM2_VECTOR_UART - push acc - mov a, #UART_IRQ - ljmp _up_interrupt - - .org PM2_VECTOR_TIMER2 - push acc - mov a, #TIMER2_IRQ - ljmp _up_interrupt - -/************************************************************ - * Name: start - * - * Description: - * This is the initial entry point into NuttX - * - ************************************************************/ - -start: - mov sp, #(STACK_BASE-1) - -#ifdef CONFIG_ARCH_LEDS - lcall _up_ledinit -#endif - - ljmp _os_start - -/************************************************************ - * Name: up_timer0 - * - * Description: - * Timer 0, mode 0 can be used as a system timer. In that - * mode, the 1.8432 MHz clock is divided by 32. A single - * 8-bit value is incremented at 57600 Hz, which results - * in 225 Timer 0 overflow interrupts per second. - * - * The Timer0 interrupt vectors to this point which then - * does a software divide by 2 to get a system timer of - * 112.5Hz. - * - * On Entry: - * - * (1) acc on the stack and - * (2) the IRQ number(TIMER0_IRQ) in the accumulator - * - ************************************************************/ - -#ifndef CONFIG_8052_TIMER2 -_up_timer0: - ar2 = 0x02 - ar3 = 0x03 - ar4 = 0x04 - ar5 = 0x05 - ar6 = 0x06 - ar7 = 0x07 - ar0 = 0x00 - ar1 = 0x01 - - /* ACC already on the stack; push IE. Then disable interrupts */ - - push ie - clr ea - - /* Save the remaining registers with interrupts disabled - * - * a, ie, and dptr go on the stack. - */ - - push dpl - push dph - - /* Increment the tick counter */ - - mov dptr, #_g_timer0tick - movx a, @dptr - inc a - movx @dptr, a - - /* If bit 0 is '0', then just return from the interrupt */ - - anl a, #0x01 - jnz 00101$ - ljmp _up_timer0exit - - /* If bit 0 is '1', then process the interrupt */ - -00101$: - mov a, #TIMER0_IRQ - sjmp _up_timer0join -#endif - -/************************************************************ - * Name: up_interrupt - * - * Description: - * All interrupts vector to this point with: - * - * (1) acc on the stack and - * (2) the IRQ number in the accumulator - * - ************************************************************/ - -_up_interrupt: - ar2 = 0x02 - ar3 = 0x03 - ar4 = 0x04 - ar5 = 0x05 - ar6 = 0x06 - ar7 = 0x07 - ar0 = 0x00 - ar1 = 0x01 - - /* ACC already on the stack; push IE. Then disable interrupts */ - - push ie - clr ea - - /* Save the remaining registers with interrupts disabled - * - * a, ie, and dptr go on the stack. - */ - - push dpl - push dph - -_up_timer0join: - /* Other registers go into the IRQ register save area */ - - push acc - mov dptr, #_g_irqregs - lcall _up_saveregisters - - /* Show interrupt status on the LEDs */ - -#ifdef CONFIG_ARCH_LEDS - mov dpl, #LED_INIRQ - lcall _up_ledon -#endif - - /* Save the IRQ number in r2 */ - - pop ar2 - - /* Mark that we are in an interrupt and provide the top - * of stack pointer to the context switching logic. - */ - - mov dptr, #_g_irqtos - mov a, sp - movx @dptr, a - - /* Nullify the context pointer. If a context switch is - * needed, this will be set to the address of the context - * structure. - */ - - mov dptr, #_g_irqcontext - clr a - movx @dptr,a - inc dptr - movx @dptr,a - - /* Now call void irq_dispatch(int irq, FAR void *context) - * - * First, create the first argument as (int)irqno - */ - - mov dpl, r2 - mov dph, #0 - - /* Create the second argument (void *context) on the stack */ - - push sp - clr a - push acc - - /* Then dispatch the IRQ. */ - - lcall _irq_dispatch - pop acc - pop acc - - /* Indicate that we are no longer in an interrupt */ - - mov dptr, #_g_irqtos - clr a - movx @dptr, a - - /* Check if a context switch is pending */ - - mov dptr,#_g_irqcontext - movx a, @dptr - mov r2, a - inc dptr - movx a, @dptr - mov r3, a - - orl a, r2 - jnz 00001$ - - /* No context switch is pending. Restore registers - * from the interrupt register save area. - */ - - mov dptr, #_g_irqregs - sjmp 00004$ - -00001$: /****************************************************/ - - /* A context switch is pending, clear g_irqcontext */ - - mov dpl, r2 - mov dph, r3 - clr a - movx @dptr, a - inc dptr - movx @dptr, a - -#ifdef CONFIG_INTERRUPT_FRAME_DUMP - mov dpl, r2 - mov dph, r3 - push ar2 - push ar3 - lcall _up_dumpframe - pop ar3 - pop ar2 -#endif - - /* Register usage in the following: - * - * R0 - Holds working the 8-bit IRAM pointer - * R1 - Not used - * R2-3 - Holds the working 16-bit XRAM pointer - * R4 - Holds the working byte count - * R5 - Holds the new stack pointer - * R6-7 - Not used - */ - - /* Fetch r4 = context->nbytes */ - - mov dpl, r2 - mov dph, r3 - movx a, @dptr - mov r4, a - - /* Save the new stack pointer in r5 */ - - add a, #(STACK_BASE-1) - mov r5, a - - /* Save r2-3 = &context->stack */ - - inc dptr - push dpl - push dph - mov r2, dpl - mov r3, dph - - /* Set r0 = stack base address */ - - mov r0, #STACK_BASE - - /* Top of the copy loop */ -00002$: - mov a, r4 /* a = bytes left to transfer */ - dec r4 /* (for next time through the loop) */ - jz 00003$ /* Jump if a = 0 (done) */ - - /* Fetch the next byte from context->stack */ - - mov dpl, r2 - mov dph, r3 - movx a,@dptr - - /* Increment the XRAM pointer */ - - inc dptr - mov r2, dpl - mov r3, dph - - /* Save the next byte into IRAM */ - - mov @r0, a - - /* Increment the IRAM pointer */ - - inc r0 - sjmp 00002$ - - /* The entire stack has been copied from XRAM into - * IRAM. Set the new stack pointer - */ - -00003$: - pop dph - pop dpl - mov sp, r5 - -#ifdef CONFIG_INTERRUPT_FRAME_DUMP - push dpl - push dph - lcall _up_dumpstack - pop dph - pop dpl -#endif - /* Get the pointer to the register save area */ - - mov a, #STACK_SIZE - add a, dpl - mov dpl, a - clr a - addc a, dph - mov dph, a - -00004$: /****************************************************/ - - /* Restore the context from the register save area - * and return from the interrupt. At this point, dptr - * holds the pointer to the memory region that holds - * the register save area. This could be either - * g_irqregs (no context switch) or &g_irqcontext->regs - * (context switch). - */ - -#ifdef CONFIG_ARCH_LEDS - push dpl - push dph - mov dpl, #LED_INIRQ - lcall _up_ledoff - pop dph - pop dpl -#endif - /* Restore registers from the register save area */ - - lcall _up_restoreregisters - -_up_timer0exit: - /* Restore registers from the stack and return */ - - pop dph - pop dpl - - /* Restore the interrupt state per the stored IE value */ - - pop acc - jb acc.7,00005$ - clr ie.7 - sjmp 00006$ -00005$: - setb ie.7 - -00006$: - pop acc - reti diff --git a/nuttx/arch/pjrc-8051/src/up_idle.c b/nuttx/arch/pjrc-8051/src/up_idle.c deleted file mode 100644 index 802e684be..000000000 --- a/nuttx/arch/pjrc-8051/src/up_idle.c +++ /dev/null @@ -1,96 +0,0 @@ -/************************************************************ - * up_idle.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 - -#include "up_internal.h" - -/************************************************************ - * Private Definitions - ************************************************************************/ - -/************************************************************ - * Private Data - ************************************************************************/ - -#if defined(CONFIG_ARCH_LEDS) && defined(CONFIG_ARCH_BRINGUP) -static /**************** g_ledtoggle = 0; -#endif - -/************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************ - * Name: up_idle - * - * Description: - * up_idle() is the logic that will be executed when their - * is no other ready-to-run task. This is processor idle - * time and will continue until some interrupt occurs to - * cause a context switch from the idle task. - * - * Processing in this state may be processor-specific. e.g., - * this is where power management operations might be - * performed. - * - ************************************************************************/ - -void up_idle(void) -{ -#if defined(CONFIG_ARCH_LEDS) && defined(CONFIG_ARCH_BRINGUP) - g_ledtoggle++; - if (g_ledtoggle == 0x80) - { - up_ledon(LED_IDLE); - } - else if (g_ledtoggle == 0x00) - { - up_ledoff(LED_IDLE); - } -#endif -} - diff --git a/nuttx/arch/pjrc-8051/src/up_initialize.c b/nuttx/arch/pjrc-8051/src/up_initialize.c deleted file mode 100644 index 3f0bc4027..000000000 --- a/nuttx/arch/pjrc-8051/src/up_initialize.c +++ /dev/null @@ -1,144 +0,0 @@ -/************************************************************************ - * up_initialize.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 -#include - -#include "up_internal.h" - -/************************************************************************ - * Private Definitions - ************************************************************************/ - -/************************************************************************ - * Private Data - ************************************************************************/ - -/* This is the top of the stack containing the interrupt - * stack frame. It is set when processing an interrupt. It - * is also cleared when the interrupt returns so this can - * also be used like a boolean indication that we are in an - * interrupt. - */ - -uint8_t g_irqtos; - -/* Registers are saved in the following global array during - * interrupt processing. If a context switch is performed - * during the interrupt handling, these registers will be - * copied into the TCB again (NOTE: We could save a copy - * if the interrupt handling logic saved the registers - * directly into (_TCB*)g_readytorun.head->xcp.regs). - */ - -uint8_t g_irqregs[REGS_SIZE]; - -/* If during execution of an interrup handler, a context - * switch must be performed, the follwing will be set to - * to that address of the relevant context structure. The - * actual switch will be deferred until the time that the - * the interrupt exits. - */ - -FAR struct xcptcontext *g_irqcontext; - -/* It is faster to look up 8-bit shifts in this table than - * to comput them. - */ - -const uint8_t g_ntobit[8] = - { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: up_initialize - * - * Description: - * up_initialize will be called once during OS - * initialization after the basic OS services have been - * initialized. The architecture specific details of - * initializing the OS will be handled here. Such things as - * setting up interrupt service routines, starting the - * clock, and registering device drivers are some of the - * things that are different for each processor and hardware - * platform. - * - * up_initialize is called after the OS initialized but - * before the init process has been started and before the - * libraries have been initialized. OS services and driver - * services are available. - * - ************************************************************************/ - -void up_initialize(void) -{ - /* Initialize global variables */ - - g_irqtos = 0; - - /* Add extra memory fragments to the memory manager */ - -#if CONFIG_MM_REGIONS > 1 - up_addregion(); -#endif - - /* Initialize the interrupt subsystem */ - - up_irqinitialize(); - - /* Initialize the system timer interrupt */ - -#ifndef CONFIG_SUPPRESS_INTERRUPTS - up_timerinit(); -#endif - - up_ledon(LED_IRQSENABLED); -} - diff --git a/nuttx/arch/pjrc-8051/src/up_initialstate.c b/nuttx/arch/pjrc-8051/src/up_initialstate.c deleted file mode 100644 index 5289d867c..000000000 --- a/nuttx/arch/pjrc-8051/src/up_initialstate.c +++ /dev/null @@ -1,119 +0,0 @@ -/************************************************************************ - * up_initialstate.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 - -#include "up_internal.h" - -/************************************************************************ - * Private Definitions - ************************************************************************/ - -/************************************************************************ - * Private Data - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: up_initial_state - * - * Description: - * A new thread is being started and a new TCB - * has been created. This function is called to initialize - * the processor specific portions of the new TCB. - * - * This function must setup the intial architecture registers - * and/or stack so that execution will begin at tcb->start - * on the next context switch. - * - ************************************************************************/ - -void up_initial_state(FAR _TCB *tcb) -{ - FAR uint8_t *frame = tcb->xcp.stack; - FAR uint8_t *regs = tcb->xcp.regs; - - /* This is the form of initial stack frame - * - * This initial stack frame will be configured to hold. - * (1) The 16-bit return address of either: - * - * void task_start(void); - * void pthread_start(void) - * - * The return address is stored at the top of stack. - * so that the RETI instruction will work: - * - * PC15-8 <- ((SP)) - * (SP) <- (SP) -1 - * PC7-0 <- ((SP)) - * (SP) <- (SP) -1 - */ - - frame[FRAME_RETLS] = (((uint16_t)tcb->start) & 0xff); - frame[FRAME_RETMS] = (((uint16_t)tcb->start) >> 8); - - /* The context save area for registers a, ie, and dpstr - * follows the return address in the stack frame. - */ - - frame[FRAME_IE] = 0x80; - - /* Save the number of bytes in the frame (which will be used - * to intialize the stack pointer when the task is started). - */ - - tcb->xcp.nbytes = FRAME_SIZE; - - /* Initialize the remaining register save area which is - * outside of the stack save area. - */ - - tcb->xcp.regs[REGS_PSW] = 0; -} diff --git a/nuttx/arch/pjrc-8051/src/up_internal.h b/nuttx/arch/pjrc-8051/src/up_internal.h deleted file mode 100644 index d49c757a6..000000000 --- a/nuttx/arch/pjrc-8051/src/up_internal.h +++ /dev/null @@ -1,152 +0,0 @@ -/************************************************************************** - * up_internal.h - * - * Copyright (C) 2007, 2009 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 NuttX 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. - * - **************************************************************************/ - -#ifndef __ARCH_UP_INTERNAL_H -#define __ARCH_UP_INTERNAL_H - -/************************************************************************** - * Included Files - **************************************************************************/ - -#include -#include -#include -#include - -#if defined(CONFIG_ARCH_BOARD_PJRC_87C52) -# include -#else -# warning "805x board not recognized" -#endif - -/************************************************************************** - * Public Definitions - **************************************************************************/ - -/************************************************************************** - * Public Types - **************************************************************************/ - -/************************************************************************** - * Public Variables - **************************************************************************/ - -#ifndef __ASSEMBLY__ - -/* This is the top of the stack containing the interrupt - * stack frame. It is set when processing an interrupt. It - * is also cleared when the interrupt returns so this can - * also be used like a boolean indication that we are in an - * interrupt. - */ - -extern uint8_t g_irqtos; - -/* Registers are saved in the following global array during - * interrupt processing. If a context switch is performed - * during the interrupt handling, these registers will be - * copied into the TCB again (NOTE: We could save a copy - * if the interrupt handling logic saved the registers - * directly into (_TCB*)g_readytorun.head->xcp.regs). - */ - -extern uint8_t g_irqregs[REGS_SIZE]; - -/* If during execution of an interrup handler, a context - * switch must be performed, the follwing will be set to - * to that address of the relevant context structure. The - * actual switch will be deferred until the time that the - * the interrupt exits. - */ - -extern FAR struct xcptcontext *g_irqcontext; - -/* It is faster to look up 8-bit shifts in this table than - * to comput them. - */ - -extern const uint8_t g_ntobit[8]; - -#endif /* __ASSEMBLY */ - -/************************************************************************** - * Public Function Prototypes - **************************************************************************/ - -#ifndef __ASSEMBLY__ - -#if CONFIG_MM_REGIONS > 1 -extern void up_addregion(void); -#endif -extern void up_delay(uint8_t milliseconds) __naked; -extern void up_irqinitialize(void); -extern void up_restorecontext(FAR struct xcptcontext *context) _naked; -extern void up_restoreregisters(FAR uint8_t *regs) _naked; -extern uint8_t up_savecontext(FAR struct xcptcontext *context) __naked; -extern void up_saveregisters(FAR uint8_t *regs) _naked; -extern void up_saveirqcontext(FAR struct xcptcontext *context); -extern void up_timerinit(void); - -/* Defined in up_debug.c */ - -#if defined(CONFIG_ARCH_BRINGUP) -extern void up_puthex(uint8_t hex) __naked; -extern void up_puthex16(int hex) __naked; -extern void up_putnl(void) __naked; -extern void up_puts(__code char *ptr); -#endif - -#if defined(CONFIG_FRAME_DUMP) && defined(CONFIG_ARCH_BRINGUP) -extern void up_dumpstack(void); -extern void up_dumpframe(FAR struct xcptcontext *context); -#else -# define up_dumpstack() -# define up_dumpframe(x) -#endif - -/* Defined in board/up_leds.c */ - -#ifdef CONFIG_ARCH_LEDS -extern void up_ledinit(void); -extern void up_ledon(uint8_t led); -extern void up_ledoff(uint8_t led); -#else -# define up_ledinit() -# define up_ledon(led) -# define up_ledoff(led) -#endif - -#endif /* __ASSEMBLY */ -#endif /* __ARCH_UP_INTERNAL_H */ diff --git a/nuttx/arch/pjrc-8051/src/up_interruptcontext.c b/nuttx/arch/pjrc-8051/src/up_interruptcontext.c deleted file mode 100644 index 81426a94e..000000000 --- a/nuttx/arch/pjrc-8051/src/up_interruptcontext.c +++ /dev/null @@ -1,70 +0,0 @@ -/************************************************************************ - * up_interruptcontext.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 -#include - -#include "up_internal.h" - -/************************************************************************ - * Private Types - ************************************************************************/ - -/************************************************************************ - * Private Function Prototypes - ************************************************************************/ - -/************************************************************************ - * Global Functions - ************************************************************************/ - -/************************************************************************ - * Name: up_interrupt_context - * - * Description: Return true is we are currently executing in - * the interrupt handler context. - ************************************************************************/ - -bool up_interrupt_context(void) -{ - return g_irqtos != 0; -} diff --git a/nuttx/arch/pjrc-8051/src/up_irq.c b/nuttx/arch/pjrc-8051/src/up_irq.c deleted file mode 100644 index f40bdbf31..000000000 --- a/nuttx/arch/pjrc-8051/src/up_irq.c +++ /dev/null @@ -1,152 +0,0 @@ -/************************************************************************ - * up_irq.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 - -#include <8052.h> - -#include "up_internal.h" - -extern int g_nints; - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Public Data - ************************************************************************/ - -/************************************************************************ - * Private Data - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Funtions - ************************************************************************/ - -/************************************************************************ - * Name: irq_initialize - ************************************************************************/ - -void up_irqinitialize(void) -{ - /* Set interrupt priorities (all low) */ - - IP = 0; - -#ifdef CONFIG_SUPPRESS_INTERRUPTS - /* Disable all interrupts */ - - IE = 0; -#else - /* Enable interrupts globally, but disable all interrupt - * sources. - */ - - IE = 0x80; -#endif -} - -/************************************************************************ - * Name: irqsave - * - * Description: - * Disable all IRQs - * - ************************************************************************/ - -irqstate_t irqsave(void) -{ - irqstate_t ret = IE; - EA = 0; - return ret; -} - -/************************************************************************ - * Name: irqrestore - * - * Description: - * Restore a previous interrupt state - * - ************************************************************************/ - -void irqrestore(irqstate_t flags) -{ - IE = flags; -} - -/************************************************************************ - * Name: up_disable_irq - * - * Description: - * Disable the IRQ specified by 'irq' - * - ************************************************************************/ - -void up_disable_irq(int irq) -{ - if ((unsigned)irq < NR_IRQS) - { - IE &= ~(g_ntobit[irq]); - } -} - -/************************************************************************ - * Name: up_enable_irq - * - * Description: - * Enable the IRQ specified by 'irq' - * - ************************************************************************/ - -void up_enable_irq(int irq) -{ - if ((unsigned)irq < NR_IRQS) - { - IE |= g_ntobit[irq]; - } -} diff --git a/nuttx/arch/pjrc-8051/src/up_irqtest.c b/nuttx/arch/pjrc-8051/src/up_irqtest.c deleted file mode 100644 index b0bdc8464..000000000 --- a/nuttx/arch/pjrc-8051/src/up_irqtest.c +++ /dev/null @@ -1,273 +0,0 @@ -/************************************************************************ - * up_irqtest.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 NuttX 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 - -#include -#include <8052.h> - -#include "up_internal.h" - -/************************************************************************ - * Definitions - ************************************************************************/ - -#define up_extint0 ((vector_t)PM2_VECTOR_EXTINT0) -#define up_timer0 ((vector_t)PM2_VECTOR_TIMER0) -#define up_extint1 ((vector_t)PM2_VECTOR_EXTINT1) -#define up_timer1 ((vector_t)PM2_VECTOR_TIMER1) -#define up_uart ((vector_t)PM2_VECTOR_UART) -#define up_timer2 ((vector_t)PM2_VECTOR_TIMER2) - -/************************************************************************ - * Private Types - ************************************************************************/ - -typedef void (*vector_t)(void); - -/************************************************************************ - * Public Variables - ************************************************************************/ - -bool g_irqtest; -uint8_t g_irqtos; -uint8_t g_irqregs[REGS_SIZE]; -int g_nirqs; -FAR struct xcptcontext *g_irqcontext; - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Name: utility functions - ************************************************************************/ - -static void _up_putc(uint8_t ch) __naked -{ - ch; /* To avoid unreferenced argument warning */ - _asm - mov a, dpl - ljmp PM2_ENTRY_COUT - _endasm; -} - -void _up_puthex(uint8_t hex) __naked -{ - hex; /* To avoid unreferenced argument warning */ - _asm - mov a, dpl - ljmp PM2_ENTRY_PHEX - _endasm; -} - -void _up_puthex16(int hex) __naked -{ - hex; /* To avoid unreferenced argument warning */ - _asm - ljmp PM2_ENTRY_PHEX16 - _endasm; -} - -void _up_putnl(void) __naked -{ - _asm - ljmp PM2_ENTRY_NEWLINE - _endasm; -} - -void _up_puts(__code char *ptr) -{ - for (; *ptr; ptr++) - { - _up_putc(*ptr); - } -} - -void _up_delay(uint8_t milliseconds) __naked -{ - _asm - mov r0, dpl -00001$: mov r1, #230 -00002$: nop - nop - nop - nop - nop - nop - djnz r1, 00002$ - djnz r0, 00001$ - ret - _endasm; -} - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: os_start - * - * Description: - * "Fake" OS entry point. - * - ************************************************************************/ - -void os_start(void) -{ - int i; - - /* Disable all interrupts */ - - IE = 0; - - /* Then verify all of the interrupt */ - - g_irqtest = false; - - up_extint0(); - up_timer0(); -#ifndef CONFIG_8052_TIMER2 - up_timer0(); -#endif - up_extint1(); - up_timer1(); - up_uart(); - up_timer2(); - - /* Now a real interrupt ... */ - - /* Configure timer 0 */ - - TR0 = 0; /* Make sure timer 0 is stopped */ - TF0 = 0; /* Clear the overflow flag */ - TMOD &= 0xF0; /* Set to mode 0 (without changing timer1) */ - TL0 = 0; /* Clear timer 0 value */ - TH0 = 0; - TR0 = 1; /* Start the timer */ - - /* Start timer interrupts */ - - g_irqtest = true; - g_nirqs = 0; - IE = 0x82; /* Enable interrupts */ - - /* Wait a about 500 MS */ - - _up_delay(500); - - /* Disable the timer */ - - TR0 = 0; /* Stop timer 0 */ - IE = 0; /* Disable interrupts */ - - _up_puts("IRQs in 500 MS="); - _up_puthex16(g_nirqs); - _up_putnl(); - - /* end of test */ - - _up_puts("Test complete"); - _up_putnl(); - for(;;); -} - -/************************************************************************ - * Name: irq_dispatch - * - * Description: - * "Fake" IRQ dispatcher - * - ***********************************************************************/ - -void irq_dispatch(int irq, FAR void *context) -{ - context; - if (g_irqtest) - { - g_nirqs++; - } - else - { - _up_puts("Dispatch IRQ="); - _up_puthex(irq); - _up_putnl(); - } -} - -/************************************************************************ - * Name: up_dumpstack / up_dumpframe - * - * Description: - * "Fake" debug routines if needed. - * - ************************************************************************/ - -void up_dumpstack(void) -{ -} - -void up_dumpframe(FAR struct xcptcontext *context) -{ -} - -/************************************************************************ - * Name: up_ledinit, up_ledon, up_ledoff - * - * Description: - * "Fake" LED routines if needed - * - ************************************************************************/ - -void up_ledinit(void) -{ -} - -void up_ledon(uint8_t led) -{ - led; -} - -void up_ledoff(uint8_t led) -{ - led; -} diff --git a/nuttx/arch/pjrc-8051/src/up_putc.c b/nuttx/arch/pjrc-8051/src/up_putc.c deleted file mode 100644 index a4b96e23f..000000000 --- a/nuttx/arch/pjrc-8051/src/up_putc.c +++ /dev/null @@ -1,81 +0,0 @@ -/************************************************************************ - * up_putc.c - * - * Copyright (C) 2007, 2009 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 NuttX 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" - -/************************************************************************ - * Private Functions - ************************************************************************/ - -static void _up_putc(int ch) __naked -{ -#if 1 - ch; /* To avoid unreferenced argument warning */ - _asm - mov a, dpl - ljmp PM2_ENTRY_COUT - _endasm; -#else - ch; /* To avoid unreferenced argument warning */ - _asm - mov a, dpl -cout: jnb ti, cout - clr ti - mov sbuf, a - ret - _endasm; -#endif -} - -/************************************************************************ - * Public Functions - ************************************************************************/ - -int up_putc(int ch) -{ - _up_putc(ch); - if (ch == '\n') - { - _up_putc('\r'); - } - return ch; -} - diff --git a/nuttx/arch/pjrc-8051/src/up_releasepending.c b/nuttx/arch/pjrc-8051/src/up_releasepending.c deleted file mode 100644 index c35199bd5..000000000 --- a/nuttx/arch/pjrc-8051/src/up_releasepending.c +++ /dev/null @@ -1,135 +0,0 @@ -/************************************************************************ - * up_releasepending.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 - -#include - -#include "os_internal.h" -#include "up_internal.h" - -/************************************************************************ - * Private Definitions - ************************************************************************/ - -/************************************************************************ - * Private Data - ************************************************************************/ - -/************************************************************************ - * Private Funtions - ************************************************************************/ - -/************************************************************************ - * Public Funtions - ************************************************************************/ - -/************************************************************************ - * Name: up_release_pending - * - * Description: - * Release and ready-to-run tasks that have - * collected in the pending task list. This can call a - * context switch if a new task is placed at the head of - * the ready to run list. - * - ************************************************************************/ - -void up_release_pending(void) -{ - FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - - dbg("From TCB=%p\n", rtcb); - - /* Merge the g_pendingtasks list into the g_readytorun task list */ - - /* sched_lock(); */ - if (sched_mergepending()) - { - /* The currently active task has changed! We will need to - * switch contexts. First check if we are operating in - * interrupt context: - */ - - if (g_irqtos) - { - /* Yes, then we have to do things differently. - * Just copy the current registers into the OLD rtcb. - */ - - up_saveirqcontext(&rtcb->xcp); - - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ - - rtcb = (FAR _TCB*)g_readytorun.head; - dbg("New Active Task TCB=%p\n", rtcb); - - /* Then setup so that the context will be performed on exit - * from the interrupt. - */ - - g_irqcontext = &rtcb->xcp; - } - - /* Copy the exception context into the TCB of the task that - * was currently active. if up_savecontext returns a non-zero - * value, then this is really the previously running task - * restarting! - */ - - else if (!up_savecontext(&rtcb->xcp)) - { - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ - - rtcb = (FAR _TCB*)g_readytorun.head; - dbg("New Active Task TCB=%p\n", rtcb); - - /* Then switch contexts */ - - up_restorecontext(&rtcb->xcp); - } - } -} diff --git a/nuttx/arch/pjrc-8051/src/up_reprioritizertr.c b/nuttx/arch/pjrc-8051/src/up_reprioritizertr.c deleted file mode 100644 index 8810a8fe1..000000000 --- a/nuttx/arch/pjrc-8051/src/up_reprioritizertr.c +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** - * up_reprioritizertr.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 -#include -#include - -#include - -#include "os_internal.h" -#include "up_internal.h" - -/**************************************************************************** - * Private Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Funtions - ****************************************************************************/ - -/**************************************************************************** - * Public Funtions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_reprioritize_rtr - * - * Description: - * Called when the priority of a running or - * ready-to-run task changes and the reprioritization will - * cause a context switch. Two cases: - * - * 1) The priority of the currently running task drops and the next - * task in the ready to run list has priority. - * 2) An idle, ready to run task's priority has been raised above the - * the priority of the current, running task and it now has the - * priority. - * - * Inputs: - * tcb: The TCB of the task that has been reprioritized - * priority: The new task priority - * - ****************************************************************************/ - -void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority) -{ - /* Verify that the caller is sane */ - - if (tcb->task_state < FIRST_READY_TO_RUN_STATE || - tcb->task_state > LAST_READY_TO_RUN_STATE || - priority < SCHED_PRIORITY_MIN || - priority > SCHED_PRIORITY_MAX) - { - PANIC(OSERR_BADREPRIORITIZESTATE); - } - else - { - FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - bool switch_needed; - - dbg("TCB=%p PRI=%d\n", tcb, priority); - - /* Remove the tcb task from the ready-to-run list. - * sched_removereadytorun will return true if we just - * remove the head of the ready to run list. - */ - - switch_needed = sched_removereadytorun(tcb); - - /* Setup up the new task priority */ - - tcb->sched_priority = (uint8_t)priority; - - /* Return the task to the specified blocked task list. - * sched_addreadytorun will return true if the task was - * added to the new list. We will need to perform a context - * switch only if the EXCLUSIVE or of the two calls is non-zero - * (i.e., one and only one the calls changes the head of the - * ready-to-run list). - */ - - switch_needed ^= sched_addreadytorun(tcb); - - /* Now, perform the context switch if one is needed */ - - if (switch_needed) - { - /* If we are going to do a context switch, then now is the right - * time to add any pending tasks back into the ready-to-run list. - * task list now - */ - - if (g_pendingtasks.head) - { - sched_mergepending(); - } - - /* Are we in an interrupt handler? */ - - if (g_irqtos) - { - /* Yes, then we have to do things differently. - * Just copy the current registers into the OLD rtcb. - */ - - up_saveirqcontext(&tcb->xcp); - - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ - - rtcb = (FAR _TCB*)g_readytorun.head; - dbg("New Active Task TCB=%p\n", rtcb); - - /* Then setup so that the context will be performed on exit - * from the interrupt. - */ - - g_irqcontext = &tcb->xcp; - } - - /* Copy the exception context into the TCB at the (old) head of the - * g_readytorun Task list. if up_savecontext returns a non-zero - * value, then this is really the previously running task restarting! - */ - - else if (!up_savecontext(&rtcb->xcp)) - { - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ - - rtcb = (FAR _TCB*)g_readytorun.head; - dbg("New Active Task TCB=%p\n", rtcb); - - /* Then switch contexts */ - - up_restorecontext(&rtcb->xcp); - } - } - } -} diff --git a/nuttx/arch/pjrc-8051/src/up_restorecontext.c b/nuttx/arch/pjrc-8051/src/up_restorecontext.c deleted file mode 100644 index cf7fc1039..000000000 --- a/nuttx/arch/pjrc-8051/src/up_restorecontext.c +++ /dev/null @@ -1,296 +0,0 @@ -/************************************************************************** - * up_restorecontext.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 -#include "up_internal.h" - -/************************************************************************** - * Private Definitions - **************************************************************************/ - -/************************************************************************** - * Private Types - **************************************************************************/ - -/************************************************************************** - * Private Function Prototypes - **************************************************************************/ - -/************************************************************************** - * Global Variables - **************************************************************************/ - -/************************************************************************** - * Private Variables - **************************************************************************/ - -/************************************************************************** - * Private Functions - **************************************************************************/ - -/************************************************************************** - * Public Functions - **************************************************************************/ - -/************************************************************************** - * Name: up_restoreregisters - * - * Description: - * Restore the saved registers from the context save area. This function - * is called from up_restorecontext (below) and also from interrupt - * handling logic. - * - * Note that this function does not restore: - * a, dptr, ie - these are saved in the stack area - * sp - this can be inferred from g_irqtos or struct xcptontext.nbytes. - * - * Inputs: - * context - the context register array from which to restore the - * register values - * - * Return: - * None - * - **************************************************************************/ - -void up_restoreregisters(FAR uint8_t *regs) _naked -{ - _asm - movx a, @dptr - mov b, a - inc dptr - movx a, @dptr - mov r2, a - inc dptr - movx a, @dptr - mov r3, a - inc dptr - movx a, @dptr - mov r4, a - inc dptr - movx a, @dptr - mov r5, a - inc dptr - movx a, @dptr - mov r6, a - inc dptr - movx a, @dptr - mov r7, a - inc dptr - movx a, @dptr - mov r0, a - inc dptr - movx a, @dptr - mov r1, a - inc dptr - movx a, @dptr - mov psw, a - inc dptr - movx a, @dptr - mov _bp, a - ret - _endasm; -} - -/************************************************************************** - * Name: up_restorecontext - * - * Description: - * Restore the stack specified in the context structure and return to - * that context - * - * Inputs: - * context - Holds the stack content of the context to return to - * - * Return: - * This function does not return. - * - **************************************************************************/ - -void up_restorecontext(FAR struct xcptcontext *context) __naked -{ - _asm - ar2 = 0x02 - ar3 = 0x03 - ar4 = 0x04 - ar5 = 0x05 - ar6 = 0x06 - ar7 = 0x07 - ar0 = 0x00 - ar1 = 0x01 - - /* Dump the contents of the saved frame before it is copied back - * to memory/registers. - */ - -#ifdef CONFIG_SWITCH_FRAME_DUMP - push dpl - push dph - lcall _up_dumpframe - pop dph - pop dpl -#endif - - /* Interrupts should be disabled for the following. up_popcontext() will - * set the new interrupt state correctly. - */ - - clr ea - - /* The following logic will copy the stack from the - * context save structure into IRAM. We cannot use - * the stack in anyway during this copy. Instead, - * we will use registers as follows: - * - * R0 - Holds the working 8-bit IRAM pointer - * R1 - Not used - * R2-3 - Holds the working 16-bit XRAM pointer - * R4 - Holds the working byte count - * R5 - Holds the new stack pointer - * R6-7 - Saved context pointer - */ - - /* Fetch r4 = context->nbytes */ - - movx a, @dptr - mov r4, a - - /* Save the new stack pointer in r5 */ - - add a, #(STACK_BASE-1) - mov r5, a - - /* Save r2-3 and r6-r7 = &context->stack */ - - inc dptr - mov r2, dpl - mov r3, dph - mov r6, dpl - mov r7, dph - - /* Set r0 = stack base address */ - - mov r0, #STACK_BASE - - /* Top of the copy loop -- we cannot use the stack - * again until we finish the copy and set the new - * stack pointer (saved in r5) - */ -00001$: - mov a, r4 /* a = bytes left to transfer */ - dec r4 /* (for next time through the loop) */ - jz 00002$ /* Jump if a = 0 (done) */ - - /* Fetch the next byte from context->stack */ - - mov dpl, r2 - mov dph, r3 - movx a, @dptr - - /* Increment the XRAM pointer */ - - inc dptr - mov r2, dpl - mov r3, dph - - /* Save the next byte into IRAM */ - - mov @r0, a - - /* Increment the IRAM pointer */ - - inc r0 - sjmp 00001$ -00002$: - - /* Set the new stack pointer and recover the - * context->stack pointer. - */ - - mov sp, r5 - mov dpl, r6 - mov dph, r7 - - /* Dump the stack contents after they have - * been restored to IRAM - */ - -#ifdef CONFIG_SWITCH_FRAME_DUMP - push dpl - push dph - lcall _up_dumpstack - pop dph - pop dpl -#endif - /* Get the pointer to the register save area */ - - mov a, #STACK_SIZE - add a, dpl - mov dpl, a - clr a - addc a, dph - mov dph, a - - /* Restore registers from the register save area */ - - lcall _up_restoreregisters - - /* Restore registers from the new stack */ - - pop dph - pop dpl - - /* Restore the interrupt state per the stored IE value */ - - pop acc - jb acc.7,00003$ - clr ie.7 - sjmp 00004$ - 00003$: - setb ie.7 - - 00004$: - pop acc - ret - _endasm; -} - - diff --git a/nuttx/arch/pjrc-8051/src/up_savecontext.c b/nuttx/arch/pjrc-8051/src/up_savecontext.c deleted file mode 100644 index 9a86faa94..000000000 --- a/nuttx/arch/pjrc-8051/src/up_savecontext.c +++ /dev/null @@ -1,362 +0,0 @@ -/************************************************************************** - * up_savecontext.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 -#include "up_internal.h" - -/************************************************************************** - * Private Definitions - **************************************************************************/ - -/************************************************************************** - * Private Types - **************************************************************************/ - -/************************************************************************** - * Private Function Prototypes - **************************************************************************/ - -/************************************************************************** - * Global Variables - **************************************************************************/ - -/************************************************************************** - * Private Variables - **************************************************************************/ - -/************************************************************************** - * Private Functions - **************************************************************************/ - -/************************************************************************** - * Name: up_savestack - * - * Description: - * Save the entire interrupt stack contents in the provided context - * structure. - * - * Inputs: - * context - the context structure in which to save the stack info - * - * Return: - * None - * - * Assumptions: - * - Interrupts are disabled - * - **************************************************************************/ - -static void up_savestack(FAR struct xcptcontext *context, uint8_t tos) -{ - /* Copy the current stack frame from internal RAM to XRAM. */ - - uint8_t nbytes = tos - (STACK_BASE-1); - NEAR uint8_t *src = (NEAR uint8_t*)STACK_BASE; - FAR uint8_t *dest = context->stack; - - context->nbytes = nbytes; - while (nbytes--) - { - *dest++ = *src++; - } -} - -/************************************************************************** - * Name: up_saveregs - * - * Description: - * Save the interrupt registers into the TCB. - * - * Inputs: - * context - the context structure in which to save the register info - * - * Return: - * None - * - * Assumptions: - * - Interrupts are disabled - * - **************************************************************************/ - -static void up_saveregs(FAR struct xcptcontext *context, uint8_t tos) -{ - /* Copy the irq register save area into the TCB */ - - FAR uint8_t *src = g_irqregs; - FAR uint8_t *dest = context->regs; - uint8_t nbytes = REGS_SIZE; - - while (nbytes--) - { - *dest++ = *src++; - } -} - -/************************************************************************** - * Public Functions - **************************************************************************/ - -/************************************************************************** - * Name: up_saveregisters - * - * Description: - * Save the current registers in the context save area. This function - * is called from up_savecontext (below) and also from interrupt - * handling logic. - * - * Note that this function does not save: - * a, dptr, ie - these are saved in the stack area - * sp - this can be inferred from g_irqtos or struct xcptontext.nbytes. - * - * Inputs: - * regs - the context register array in which to save the register info - * - * Return: - * None - * - **************************************************************************/ - -void up_saveregisters(FAR uint8_t *regs) _naked -{ - _asm - mov a, b - movx @dptr, a - inc dptr - mov a, r2 - movx @dptr, a - inc dptr - mov a, r3 - movx @dptr, a - inc dptr - mov a, r4 - movx @dptr, a - inc dptr - mov a, r5 - movx @dptr, a - inc dptr - mov a, r6 - movx @dptr, a - inc dptr - mov a, r7 - movx @dptr, a - inc dptr - mov a, r0 - movx @dptr, a - inc dptr - mov a, r1 - movx @dptr, a - inc dptr - mov a, psw - movx @dptr, a - clr psw - inc dptr - mov a, _bp - movx @dptr, a - ret - _endasm; -} - -/************************************************************************** - * Name: up_savecontext - * - * Description: - * Push the current execution context onto the stack, then save the - * entire stack contents in the provided context structure. - * - * Inputs: - * context - the context structure in which to save the stack info - * - * Return: - * 0 = Normal state save return - * 1 = This is the matching return from up_restorecontext() - * - **************************************************************************/ - -uint8_t up_savecontext(FAR struct xcptcontext *context) _naked -{ - _asm - /* Create the stack frame that we want when it is time to restore - * this context. The return address will be the return address - * of this function, the return value will be zero. - * - * ... - * return address (2 bytes, already on the stack) - * register a=0 (1 byte) - * register ie (1 byte) - * register dptr (2 bytes) - */ - - clr a - push acc /* ACC = 0 */ - push ie - mov a, #1 - push acc /* DPL = 1 */ - clr a - push acc /* DPH = 0 */ - - /* Dump the stack contents before they are occupied into XRAM */ - -#ifdef CONFIG_SWITCH_FRAME_DUMP - push dpl - push dph - lcall _up_dumpstack - pop dph - pop dpl -#endif - /* Disable interrupts while we create a snapshot of the stack - * and registers. At this point, we have 5 bytes on the stack - * to account for. - */ - - push ie - mov ea, 0 - - /* Save the registers in the context save area */ - - push dpl - push dph - mov a, #XCPT_REGS - add a, dpl - mov dpl, a - clr a - addc a, dph - mov dph, a - lcall _up_saveregisters - pop dph - pop dpl - -#ifdef CONFIG_SWITCH_FRAME_DUMP - /* Save the address of the context structure. We will - * need this later to dump the saved frame. Now we have - * 7 bytes on the stack to account for. - */ - - push dpl - push dph - - /* Push the top of frame stack pointer. We need to - * decrement the current SP value by three to account - * for dptr+IE on the stack above the end of the frame. - */ - - mov a, sp - subb a, #3 -#else - /* Push the top of frame stack pointer. We need to - * decrement the current stack pointer by one to account - * for IE that we saved on the stack. - */ - - mov a, sp - dec a -#endif - push acc - - /* Copy the current stack frame from internal RAM to XRAM. */ - - lcall _up_savestack - pop acc - - /* Dump the contents of the saved frame after it has been - * copied from memory/registers. - */ - -#ifdef CONFIG_SWITCH_FRAME_DUMP - pop dph - pop dpl - push dpl - push dph - lcall _up_dumpframe - pop dph - pop dpl - lcall _up_dumpstack -#endif - - /* Restore the interrupt state */ - - pop ie - - /* Now that we have a snapshot of the desired stack frame saved, - * we can release the stack frame (all but the return address) - */ - - mov a, sp - subb a, #4 - mov sp, a - mov dpl,#0 - ret - _endasm; -} - -/************************************************************************** - * Name: up_saveirqcontext - * - * Description: - * The interrupt context was saved in g_irqtos and g_irqregs when the - * interrupt was taken. If a context switch from the interrupted task - * will be made at the interrupt level, then these saved values must be - * copied into the TCB. - * - * Inputs: - * context - the structure in which to save the context info - * - * Return: - * None - * - * Assumptions: - * - Interrupts are disabled - * - **************************************************************************/ - -void up_saveirqcontext(FAR struct xcptcontext *context) -{ - /* Save the number of bytes in the stack */ - - context->nbytes = g_irqtos - (STACK_BASE-1); - - /* Copy the current stack frame from internal RAM to XRAM. */ - - up_savestack(context, g_irqtos); - - /* Copy the saved registers into the TCB */ - - up_saveregisters(context->regs); -} diff --git a/nuttx/arch/pjrc-8051/src/up_timerisr.c b/nuttx/arch/pjrc-8051/src/up_timerisr.c deleted file mode 100644 index 3ca2faad6..000000000 --- a/nuttx/arch/pjrc-8051/src/up_timerisr.c +++ /dev/null @@ -1,147 +0,0 @@ -/************************************************************************ - * up_timerisr.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 - -#include -#include <8052.h> - -#include "clock_internal.h" -#include "up_internal.h" - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Private Types - ************************************************************************/ - -/************************************************************************ - * Private Function Prototypes - ************************************************************************/ - -/************************************************************************ - * Global Functions - ************************************************************************/ - -/************************************************************************ - * Function: up_timerisr - * - * Description: - * The timer ISR will perform a variety of services for - * various portions of the systems. - * - ************************************************************************/ - -int up_timerisr(int irq, FAR uint8_t *frame) -{ - /* Process timer interrupt */ - - sched_process_timer(); - return 0; -} - -/************************************************************************ - * Function: up_timerinit - * - * Description: - * This function is called during start-up to initialize - * the timer interrupt. - * - ************************************************************************/ - -void up_timerinit(void) -{ -#ifdef CONFIG_8052_TIMER2 - up_disable_irq(TIMER2_IRQ); - - /* Set up timer 2 -- See pjrc.h for details */ - - T2MOD = 0; - - /* Set up the capture count to generate 100Hz system - * interrupts. - */ - - RCAP2L = TIMER2_CAPTURE_LOW; - RCAP2H = TIMER2_CAPTURE_HIGH; - - TL2 = TIMER2_CAPTURE_LOW; - TH2 = TIMER2_CAPTURE_HIGH; - - /* Configure for interrupts */ - - T2CON = 0x04; - - /* Attach and enable the timer interrupt */ - - irq_attach(TIMER2_IRQ, (xcpt_t)up_timerisr); - up_enable_irq(TIMER2_IRQ); - -#else - /* Timer 0, mode 0 can be used as a system timer. In that mode, the - * 1.8432 MHz clock is divided by 32. A single 8-bit value is incremented - * at 57600 Hz, which results in 225 Timer 0 overflow interrupts per - * second. - */ - - up_disable_irq(TIMER0_IRQ); - - /* Initialize timer 0 */ - - TR0 = 0; /* Make sure timer 0 is stopped */ - TF0 = 0; /* Clear the overflow flag */ - TMOD &= 0xF0; /* Set to mode 0 (without changing timer1) */ - TL0 = 0; /* Clear timer 0 value */ - TH0 = 0; - - /* Attach and enable the timer interrupt */ - - irq_attach(TIMER0_IRQ, (xcpt_t)up_timerisr); - - TR0 = 1; /* Start the timer */ - up_enable_irq(TIMER0_IRQ); - -#endif -} - diff --git a/nuttx/arch/pjrc-8051/src/up_unblocktask.c b/nuttx/arch/pjrc-8051/src/up_unblocktask.c deleted file mode 100644 index 9152eae0a..000000000 --- a/nuttx/arch/pjrc-8051/src/up_unblocktask.c +++ /dev/null @@ -1,166 +0,0 @@ -/************************************************************************ - * up_unblocktask.c - * - * Copyright (C) 2007, 2009 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 NuttX 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 - -#include - -#include "clock_internal.h" -#include "os_internal.h" -#include "up_internal.h" - -/************************************************************************ - * Private Definitions - ************************************************************************/ - -/************************************************************************ - * Private Data - ************************************************************************/ - -/************************************************************************ - * Private Funtions - ************************************************************************/ - -/************************************************************************ - * Public Funtions - ************************************************************************/ - -/************************************************************************ - * Name: up_unblock_task - * - * Description: - * A task is currently in an inactive task list - * but has been prepped to execute. Move the TCB to the - * ready-to-run list, restore its context, and start execution. - * - * Inputs: - * tcb: Refers to the tcb to be unblocked. This tcb is - * in one of the waiting tasks lists. It must be moved to - * the ready-to-run list and, if it is the highest priority - * ready to run taks, executed. - * - ************************************************************************/ - -void up_unblock_task(FAR _TCB *tcb) -{ - /* Verify that the context switch can be performed */ - - if ((tcb->task_state < FIRST_BLOCKED_STATE) || - (tcb->task_state > LAST_BLOCKED_STATE)) - { - PANIC(OSERR_BADUNBLOCKSTATE); - } - else - { - FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - - dbg("Unblocking TCB=%p\n", tcb); - - /* Remove the task from the blocked task list */ - - sched_removeblocked(tcb); - - /* Reset its timeslice. This is only meaningful for round - * robin tasks but it doesn't here to do it for everything - */ - -#if CONFIG_RR_INTERVAL > 0 - tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK; -#endif - - /* Add the task in the correct location in the prioritized - * g_readytorun task list - */ - - if (sched_addreadytorun(tcb)) - { - /* The currently active task has changed! We need to do - * a context switch to the new task. - * - * Are we in an interrupt handler? - */ - - if (g_irqtos) - { - /* Yes, then we have to do things differently. - * Just copy the current stack into the OLD rtcb. - */ - - up_saveirqcontext(&rtcb->xcp); - - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ - - rtcb = (FAR _TCB*)g_readytorun.head; - dbg("New Active Task TCB=%p\n", rtcb); - - /* Then setup so that the context will be performed on exit - * from the interrupt. - */ - - g_irqcontext = &rtcb->xcp; - } - - /* We are not in an interrupt andler. Copy the user C context - * into the TCB of the task that was previously active. if - * up_savecontext returns a non-zero value, then this is really the - * previously running task restarting! - */ - - else if (!up_savecontext(&rtcb->xcp)) - { - /* Restore the exception context of the new task that is ready to - * run (probably tcb). This is the new rtcb at the head of the - * g_readytorun task list. - */ - - rtcb = (FAR _TCB*)g_readytorun.head; - dbg("New Active Task TCB=%p\n", rtcb); - - /* Then switch contexts */ - - up_restorecontext(&rtcb->xcp); - } - } - } -} -- cgit v1.2.3