diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-09-01 12:27:17 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-09-01 12:27:17 -0600 |
commit | 9ee5cfaffa313949563fb37f7cd39a2b7620a4dd (patch) | |
tree | c4ac8ef00bbc20cd9d265d6fdc1e917f3a96eb37 /misc/Obsoleted/arch/8051/src | |
parent | e21b9a799cafb19d617995579d5b16739a34f2bb (diff) | |
download | px4-nuttx-9ee5cfaffa313949563fb37f7cd39a2b7620a4dd.tar.gz px4-nuttx-9ee5cfaffa313949563fb37f7cd39a2b7620a4dd.tar.bz2 px4-nuttx-9ee5cfaffa313949563fb37f7cd39a2b7620a4dd.zip |
Obsolete support for the 8051 family. Trying to maintain compatibility with this family is too much effort and there has never really been a successful NuttX impplementation on these parts
Diffstat (limited to 'misc/Obsoleted/arch/8051/src')
24 files changed, 4051 insertions, 0 deletions
diff --git a/misc/Obsoleted/arch/8051/src/.gitignore b/misc/Obsoleted/arch/8051/src/.gitignore new file mode 100644 index 000000000..63526d43f --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/.gitignore @@ -0,0 +1,16 @@ +Make.dep +.depend +up_mem.h +*.sym +*.asm +*.rel +*.lst +*.adb +*.rst +*.lib +*.lnk +*.map +*.mem +*.ihx +*.hex + diff --git a/misc/Obsoleted/arch/8051/src/Makefile b/misc/Obsoleted/arch/8051/src/Makefile new file mode 100644 index 000000000..867024b62 --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/Makefile @@ -0,0 +1,54 @@ +############################################################################ +# arch/8051/src/Makefile +# +# Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> +# +# 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. +# +############################################################################ + +# Makefile fragments + +-include $(TOPDIR)/Make.defs +-include chip/Make.defs +-include board/Make.defs + +# Check for SDCC native windows build + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + + # SDCC Windows native build + + include Makefile.sdccw +else + + # SDCC in a POSIX environment (Linux, OSX, or Cygwin/MSYS) + + include Makefile.sdccl +endif diff --git a/misc/Obsoleted/arch/8051/src/Makefile.sdccl b/misc/Obsoleted/arch/8051/src/Makefile.sdccl new file mode 100644 index 000000000..0e424924b --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/Makefile.sdccl @@ -0,0 +1,278 @@ +############################################################################ +# arch/8051/src/Makefile.sdccl +# +# Copyright (C) 2007, 2008, 2011-2012, 2014 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> +# +# 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 + +# Tools +# CFLAGS, CPPFLAGS, ASFLAGS, LDFLAGS are set in $(TOPDIR)/Make.defs + +CFLAGS += -I$(TOPDIR)/sched +CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -D__ASSEMBLY__ + +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 + +# Files and directories +# There should be one head source (.asm file) + +HEAD_SSRC = up_head.S +HEAD_ASRC = $(HEAD_SSRC:.S=$(ASMEXT)) +HEAD_OBJ = $(HEAD_ASRC:$(ASMEXT)=$(OBJEXT)) + +# Assembly sources and objects + +SSRCS = +ASRCS = $(SSRCS:.S=$(ASMEXT)) +AOBJS = $(ASRCS:$(ASMEXT)=$(OBJEXT)) + +# C sources and objects + +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_putc.c \ + up_debug.c up_delay.c + +ifneq ($(CONFIG_SCHED_TICKLESS),y) +CSRCS += up_timerisr.c +endif + +COBJS = $(CSRCS:.c=$(OBJEXT)) + +# All sources and objcts + +SRCS = $(SSRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +DEPSRCS = $(SRCS) $(HEAD_SSRC) + +# Board path + +BOARDDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src/board + +# Source path + +VPATH = chip:common:board + +# Libraries + +SDCCLIBS = -llibfloat.lib -llibint.lib -lliblong.lib -llibmysdcc.lib -lmcs51.lib + +LINKLIBS ?= +LIBPATHS = -L"$(TOPDIR)/lib" +LDLIBS = $(patsubst %.a,%,$(patsubst lib%,-l%,$(LINKLIBS))) + +# Test sources + +TESTSRCS = up_irqtest.c +TESTOBJS = $(TESTSRCS:.c=$(OBJEXT)) +TESTLINKOBJS = up_head$(OBJEXT) +TESTEXTRAOBJS = up_savecontext$(OBJEXT) up_restorecontext$(OBJEXT) + +# Memory + +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 \ + } + +# Targets + +all: up_head$(OBJEXT) libarch$(LIBEXT) + +.PHONY: board/libboard$(LIBEXT) + +$(ASRCS) $(HEAD_ASRC): %$(ASMEXT): %.S + $(CPP) -P $(CPPFLAGS) $< -o $@ + +$(AOBJS) $(HEAD_OBJ): $(ASRCS) $(HEAD_ASRC) + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(TESTOBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +# This is a kludge to work around some conflicting symbols in the SDCC libraries + +$(TOPDIR)/lib/$(SDCCLIB): $(SDCC_LIBDIR)/$(SDCCLIB) + $(Q) cp $(SDCC_LIBDIR)/$(SDCCLIB) $(TOPDIR)/lib/$(SDCCLIB) + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _calloc.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _malloc.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _realloc.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _free.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) printf_large.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) sprintf.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) vprintf.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) strcpy.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) strlen.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strcat.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strchr.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strcmp.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strcspn.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strncat.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strncmp.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strncpy.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strpbrk.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strrchr.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strspn.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strstr.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _strtok.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _memchr.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _memcmp.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _memcpy.rel + $(Q) sdar d $(TOPDIR)/lib/$(SDCCLIB) _memset.rel + +# Create a header file that contains addressing information needed by the code + +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) + $(call ARCHIVE, $@, $(OBJS)) + +# This builds the libboard library in the board/ subdirectory + +board/libboard$(LIBEXT): + $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" libboard$(LIBEXT) EXTRADEFINES=$(EXTRADEFINES) + +# This target builds the final executable + +pass1.hex: up_mem.h $(TOPDIR)/lib/$(SDCCLIB) $(HEAD_OBJ) board/libboard$(LIBEXT) + @echo "LD: $@" + $(Q) "$(CC)" $(LDFLAGS) $(LIBPATHS) -L$(BOARDDIR) $(SDCCPATH) $(HEAD_OBJ) \ + $(LDLIBS) -llibboard$(LIBEXT) $(SDCCLIBS) -o $@ + $(Q) rm -f up_mem.h + $(Q) rm -f up_allocateheap$(OBJEXT) libarch$(LIBEXT) + $(Q) $(MAKE) TOPDIR=$(TOPDIR) libarch$(LIBEXT) + +nuttx.hex: up_mem.h $(TOPDIR)/lib/$(SDCCLIB) $(HEAD_OBJ) + @echo "LD: $@" + $(Q) "$(CC)" $(LDFLAGS) $(LIBPATHS) -L$(BOARDDIR) $(SDCCPATH) $(HEAD_OBJ) \ + $(LDLIBS) -llibboard$(LIBEXT) $(SDCCLIBS) -o $@ + +nuttx$(EXEEXT): pass1.hex nuttx.hex + $(Q) rm -f pass1.* + $(Q) packihx nuttx.hex > $(TOPDIR)/nuttx$(EXEEXT) + $(Q) cp -f nuttx.map $(TOPDIR)/. + +# This is part of the top-level export target + +export_head: board/libboard$(LIBEXT) p_head$(OBJEXT) + $(Q) if [ -d "$(EXPORT_DIR)/startup" ]; then \ + cp -f up_head$(OBJEXT) "$(EXPORT_DIR)/startup"; \ + else \ + echo "$(EXPORT_DIR)/startup does not exist"; \ + exit 1; \ + fi + +# 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.hex: $(TESTOBJS) + $(Q) "$(CC)" $(LDFLAGS) -L. $(SDCCPATH) $(TESTLINKOBJS) $(TESTOBJS) $(TESTEXTRAOBJS) $(SDCCLIBS) -o $@ + +irqtest: + $(Q) $(MAKE) TOPDIR=../../.. up_irqtest.hex + +# Build dependencies + +.depend: Makefile up_mem.h $(DEPSRCS) + $(Q) if [ -e board/Makefile ]; then \ + $(MAKE) -C board TOPDIR=$(TOPDIR) depend ; \ + fi + $(Q) $(MKDEP) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ + +depend: .depend + +clean: + $(Q) if [ -e board/Makefile ]; then \ + $(MAKE) -C board TOPDIR=$(TOPDIR) clean ; \ + fi + $(call DELFILE, libarch$(LIBEXT)) + $(call DELFILE, up_mem.h) + $(call CLEAN) + +distclean: clean + $(Q) if [ -e board/Makefile ]; then \ + $(MAKE) -C board TOPDIR=$(TOPDIR) distclean ; \ + fi + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep diff --git a/misc/Obsoleted/arch/8051/src/up_allocateheap.c b/misc/Obsoleted/arch/8051/src/up_allocateheap.c new file mode 100644 index 000000000..0b00f88ec --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_allocateheap.c @@ -0,0 +1,89 @@ +/************************************************************ + * up_allocateheap.c + * + * Copyright (C) 2007, 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <sys/types.h> +#include <sched.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <nuttx/kmalloc.h> + +#include "up_internal.h" +#include "up_mem.h" + +/************************************************************ + * Private Definitions + ************************************************************/ + +/************************************************************ + * Private Data + ************************************************************/ + +/************************************************************ + * Private Functions + ************************************************************/ + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: up_allocate_heap + * + * Description: + * 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; + board_led_on(LED_HEAPALLOCATE); +} + +#if CONFIG_MM_REGIONS > 1 +void up_addregion(void) +{ + kmm_addregion((FAR void*)UP_HEAP2_BASE, UP_HEAP2_END - UP_HEAP2_BASE); +} +#endif diff --git a/misc/Obsoleted/arch/8051/src/up_assert.c b/misc/Obsoleted/arch/8051/src/up_assert.c new file mode 100644 index 000000000..ca0be70bb --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_assert.c @@ -0,0 +1,145 @@ +/************************************************************************ + * up_assert.c + * + * Copyright (C) 2007, 2009, 2012-2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdlib.h> +#include <assert.h> +#include <sched.h> +#include <debug.h> + +#include <nuttx/usb/usbdev_trace.h> + +#include <8052.h> + +#include "sched/sched.h" +#include "up_internal.h" +#include "up_mem.h" + +/************************************************************************ + * Pre-processor Definitions + ************************************************************************/ +/* USB trace dumping */ + +#ifndef CONFIG_USBDEV_TRACE +# undef CONFIG_ARCH_USBDUMP +#endif + +/************************************************************************ + * Private Data + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Name: _up_assert + ************************************************************************/ + +static void _up_assert(int errorcode) noreturn_function; +static void _up_assert(int errorcode) +{ + /* Are we in an interrupt handler or the idle task? */ + + if (g_irqtos || ((FAR struct tcb_s*)g_readytorun.head)->pid == 0) + { + (void)irqsave(); + for (;;) + { +#ifdef CONFIG_ARCH_LEDS + board_led_on(LED_PANIC); + up_delay(250); + board_led_off(LED_PANIC); + up_delay(250); +#endif + } + } + else + { + exit(errorcode); + } +} + +/**************************************************************************** + * Name: assert_tracecallback + ****************************************************************************/ + +#ifdef CONFIG_ARCH_USBDUMP +static int assert_tracecallback(struct usbtrace_s *trace, void *arg) +{ + usbtrace_trprintf((trprintf_t)lowsyslog, trace->event, trace->value); + return 0; +} +#endif + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: up_assert + ************************************************************************/ + +void up_assert(const uint8_t *filename, int lineno) +{ +#if CONFIG_TASK_NAME_SIZE > 0 + struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; +#endif + + board_led_on(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(); + +#ifdef CONFIG_ARCH_USBDUMP + /* Dump USB trace data */ + + (void)usbtrace_enumerate(assert_tracecallback, NULL); +#endif + + _up_assert(EXIT_FAILURE); +} diff --git a/misc/Obsoleted/arch/8051/src/up_blocktask.c b/misc/Obsoleted/arch/8051/src/up_blocktask.c new file mode 100644 index 000000000..72a519b2b --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_blocktask.c @@ -0,0 +1,167 @@ +/************************************************************************ + * up_blocktask.c + * + * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdbool.h> +#include <sched.h> +#include <debug.h> +#include <nuttx/arch.h> + +#include "sched/sched.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 struct tcb_s *tcb, tstate_t task_state) +{ + FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + bool switch_needed; + + /* Verify that the context switch can be performed */ + + ASSERT((tcb->task_state >= FIRST_READY_TO_RUN_STATE) && + (tcb->task_state <= LAST_READY_TO_RUN_STATE)); + + 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 struct tcb_s*)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 struct tcb_s*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then switch contexts */ + + up_restorecontext(&rtcb->xcp); + } + } +} diff --git a/misc/Obsoleted/arch/8051/src/up_debug.c b/misc/Obsoleted/arch/8051/src/up_debug.c new file mode 100644 index 000000000..35a5d1d50 --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_debug.c @@ -0,0 +1,255 @@ +/************************************************************************ + * arch/8051/src/up_debug.c + * + * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <sys/types.h> +#include <stdint.h> +#include <debug.h> + +#include <8052.h> +#include <nuttx/arch.h> +#include <arch/irq.h> + +#include "up_internal.h" +#include "up_mem.h" + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +#if defined(CONFIG_FRAME_DUMP) && defined(CONFIG_ARCH_8051_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_8051_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_8051_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_8051_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_8051_BRINGUP +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/misc/Obsoleted/arch/8051/src/up_delay.c b/misc/Obsoleted/arch/8051/src/up_delay.c new file mode 100644 index 000000000..ad8950e86 --- /dev/null +++ b/misc/Obsoleted/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 <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> +#include <stdint.h> +#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/misc/Obsoleted/arch/8051/src/up_exit.c b/misc/Obsoleted/arch/8051/src/up_exit.c new file mode 100644 index 000000000..29fe790fb --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_exit.c @@ -0,0 +1,106 @@ +/**************************************************************************************** + * up_exit.c + * + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <sched.h> +#include <debug.h> + +#include <8052.h> +#include <nuttx/arch.h> + +#include "task/task.h" +#include "sched/sched.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 struct tcb_s* tcb; + + dbg("TCB=%p exiting\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_exit(); + + /* Now, perform the context switch to the new ready-to-run task at the + * head of the list. + */ + + tcb = (FAR struct tcb_s*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", tcb); + + /* Then switch contexts */ + + up_restorecontext(&tcb->xcp); +} + diff --git a/misc/Obsoleted/arch/8051/src/up_head.S b/misc/Obsoleted/arch/8051/src/up_head.S new file mode 100644 index 000000000..d4e2ba6e7 --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_head.S @@ -0,0 +1,471 @@ +/************************************************************ + * arch/8051/src/up_head.S + * + * Copyright (C) 2007, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> +#include <nuttx/irq.h> +#include "up_internal.h" + + .module up_head + .optsdcc -mmcs51 --model-large + +/************************************************************ + * Private Data + ************************************************************/ + + .area REG_BANK_0 (REL,OVR,DATA) + .ds 8 + +#ifndef CONFIG_ARCH_8051_NOSYSTIMER + .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_ARCH_8051_NOSYSTIMER + 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 _board_led_initialize +#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_ARCH_8051_NOSYSTIMER +_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 _board_led_on +#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 _board_led_off + 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/misc/Obsoleted/arch/8051/src/up_idle.c b/misc/Obsoleted/arch/8051/src/up_idle.c new file mode 100644 index 000000000..a5d39bcfb --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_idle.c @@ -0,0 +1,95 @@ +/************************************************************************ + * arch/8051/src/up_idle.c + * + * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <nuttx/arch.h> + +#include "up_internal.h" + +/************************************************************************ + * Pre-processor Definitions + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +#if defined(CONFIG_ARCH_LEDS) && defined(CONFIG_ARCH_8051_BRINGUP) +static uint8_t 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_8051_BRINGUP) + g_ledtoggle++; + if (g_ledtoggle == 0x80) + { + board_led_on(LED_IDLE); + } + else if (g_ledtoggle == 0x00) + { + board_led_off(LED_IDLE); + } +#endif +} diff --git a/misc/Obsoleted/arch/8051/src/up_initialize.c b/misc/Obsoleted/arch/8051/src/up_initialize.c new file mode 100644 index 000000000..bf461a09c --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_initialize.c @@ -0,0 +1,144 @@ +/************************************************************************ + * arch/8051/src/up_initialize.c + * + * Copyright (C) 2007, 2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> + +#include <nuttx/arch.h> +#include <nuttx/fs/fs.h> + +#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. + */ + +volatile 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 (struct tcb_s*)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_ARCH_8051_SUPRESS_INTERRUPTS + up_timer_initialize(); +#endif + + board_led_on(LED_IRQSENABLED); +} + diff --git a/misc/Obsoleted/arch/8051/src/up_initialstate.c b/misc/Obsoleted/arch/8051/src/up_initialstate.c new file mode 100644 index 000000000..d0d568981 --- /dev/null +++ b/misc/Obsoleted/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 <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <sched.h> + +#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 struct tcb_s *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 initialize 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/misc/Obsoleted/arch/8051/src/up_internal.h b/misc/Obsoleted/arch/8051/src/up_internal.h new file mode 100644 index 000000000..d4bde5923 --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_internal.h @@ -0,0 +1,153 @@ +/************************************************************************** + * arch/8051/src/up_internal.h + * + * Copyright (C) 2007, 2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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_8051_SRC_UP_INTERNAL_H +#define __ARCH_8051_SRC_UP_INTERNAL_H + +/************************************************************************** + * Included Files + **************************************************************************/ + +#include <nuttx/config.h> +#include <stdint.h> +#include <stdbool.h> +#include <arch/irq.h> + +#if defined(CONFIG_ARCH_BOARD_PJRC_87C52) +# include <arch/board/pjrc.h> +#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 volatile 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 (struct tcb_s*)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 +void up_addregion(void); +#endif +void up_delay(uint8_t milliseconds) __naked; +void up_irqinitialize(void); +void up_restorecontext(FAR struct xcptcontext *context) _naked; +void up_restoreregisters(FAR uint8_t *regs) _naked; +uint8_t up_savecontext(FAR struct xcptcontext *context) __naked; +void up_saveregisters(FAR uint8_t *regs) _naked; +void up_saveirqcontext(FAR struct xcptcontext *context); +void up_timer_initialize(void); + +/* Defined in up_debug.c */ + +#if defined(CONFIG_ARCH_8051_BRINGUP) +void up_puthex(uint8_t hex) __naked; +void up_puthex16(int hex) __naked; +void up_putnl(void) __naked; +void up_puts(__code char *ptr); +void up_showsp(uint8_t ch) __naked; +#endif + +#if defined(CONFIG_FRAME_DUMP) && defined(CONFIG_ARCH_8051_BRINGUP) +void up_dumpstack(void); +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 +void board_led_initialize(void); +void board_led_on(uint8_t led); +void board_led_off(uint8_t led); +#else +# define board_led_initialize() +# define board_led_on(led) +# define board_led_off(led) +#endif + +#endif /* __ASSEMBLY */ +#endif /* __ARCH_8051_SRC_UP_INTERNAL_H */ diff --git a/misc/Obsoleted/arch/8051/src/up_interruptcontext.c b/misc/Obsoleted/arch/8051/src/up_interruptcontext.c new file mode 100644 index 000000000..bcc9e4cd9 --- /dev/null +++ b/misc/Obsoleted/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 <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdbool.h> +#include <nuttx/arch.h> +#include <nuttx/irq.h> + +#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/misc/Obsoleted/arch/8051/src/up_irq.c b/misc/Obsoleted/arch/8051/src/up_irq.c new file mode 100644 index 000000000..85b30aeaf --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_irq.c @@ -0,0 +1,152 @@ +/************************************************************************ + * arch/8051/src/up_irq.c + * + * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <nuttx/irq.h> +#include <debug.h> + +#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_ARCH_8051_SUPRESS_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/misc/Obsoleted/arch/8051/src/up_irqtest.c b/misc/Obsoleted/arch/8051/src/up_irqtest.c new file mode 100644 index 000000000..be8f6d00b --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_irqtest.c @@ -0,0 +1,272 @@ +/************************************************************************ + * arch/8051/src/up_irqtest.c + * + * Copyright (C) 2007, 2011, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <stdbool.h> + +#include <nuttx/arch.h> +#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; +volatile 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 interrupts */ + + g_irqtest = false; + + up_extint0(); +#ifdef CONFIG_ARCH_8051_NOSYSTIMER + 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: board_led_initialize, board_led_on, board_led_off + * + * Description: + * "Fake" LED routines if needed + * + ************************************************************************/ + +void board_led_initialize(void) +{ +} + +void board_led_on(uint8_t led) +{ + led; +} + +void board_led_off(uint8_t led) +{ + led; +} diff --git a/misc/Obsoleted/arch/8051/src/up_putc.c b/misc/Obsoleted/arch/8051/src/up_putc.c new file mode 100644 index 000000000..bf2edb5e1 --- /dev/null +++ b/misc/Obsoleted/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 <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> +#include <nuttx/arch.h> +#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/misc/Obsoleted/arch/8051/src/up_releasepending.c b/misc/Obsoleted/arch/8051/src/up_releasepending.c new file mode 100644 index 000000000..ebb5271a6 --- /dev/null +++ b/misc/Obsoleted/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 <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <sched.h> +#include <debug.h> + +#include <nuttx/arch.h> + +#include "sched/sched.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 struct tcb_s *rtcb = (FAR struct tcb_s*)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 struct tcb_s*)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 struct tcb_s*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then switch contexts */ + + up_restorecontext(&rtcb->xcp); + } + } +} diff --git a/misc/Obsoleted/arch/8051/src/up_reprioritizertr.c b/misc/Obsoleted/arch/8051/src/up_reprioritizertr.c new file mode 100644 index 000000000..7f28c711b --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_reprioritizertr.c @@ -0,0 +1,190 @@ +/**************************************************************************** + * up_reprioritizertr.c + * + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <stdbool.h> +#include <sched.h> +#include <debug.h> + +#include <nuttx/arch.h> + +#include "sched/sched.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 struct tcb_s *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 +#if SCHED_PRIORITY_MIN > 0 + || priority < SCHED_PRIORITY_MIN +#endif +#if SCHED_PRIORITY_MAX < UINT8_MAX + || priority > SCHED_PRIORITY_MAX +#endif + ) + { + PANIC(); + } + else + { + FAR struct tcb_s *rtcb = (FAR struct tcb_s*)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 struct tcb_s*)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 struct tcb_s*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then switch contexts */ + + up_restorecontext(&rtcb->xcp); + } + } + } +} diff --git a/misc/Obsoleted/arch/8051/src/up_restorecontext.c b/misc/Obsoleted/arch/8051/src/up_restorecontext.c new file mode 100644 index 000000000..6966866ee --- /dev/null +++ b/misc/Obsoleted/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 <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> +#include <stdint.h> +#include <nuttx/irq.h> +#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/misc/Obsoleted/arch/8051/src/up_savecontext.c b/misc/Obsoleted/arch/8051/src/up_savecontext.c new file mode 100644 index 000000000..c5d0ae1c7 --- /dev/null +++ b/misc/Obsoleted/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 <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> +#include <stdint.h> +#include <nuttx/irq.h> +#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/misc/Obsoleted/arch/8051/src/up_timerisr.c b/misc/Obsoleted/arch/8051/src/up_timerisr.c new file mode 100644 index 000000000..7abe5d2fe --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_timerisr.c @@ -0,0 +1,147 @@ +/************************************************************************ + * arch/8051/src/up_timerisr.c + * + * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <8052.h> + +#include "clock/clock.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_timer_initialize + * + * Description: + * This function is called during start-up to initialize + * the timer interrupt. + * + ************************************************************************/ + +void up_timer_initialize(void) +{ +#ifdef CONFIG_ARCH_8051_NOSYSTIMER + 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/misc/Obsoleted/arch/8051/src/up_unblocktask.c b/misc/Obsoleted/arch/8051/src/up_unblocktask.c new file mode 100644 index 000000000..36d6ed1ef --- /dev/null +++ b/misc/Obsoleted/arch/8051/src/up_unblocktask.c @@ -0,0 +1,161 @@ +/************************************************************************ + * up_unblocktask.c + * + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <sched.h> +#include <debug.h> + +#include <nuttx/arch.h> + +#include "clock/clock.h" +#include "sched/sched.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 struct tcb_s *tcb) +{ + FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; + + /* Verify that the context switch can be performed */ + + ASSERT((tcb->task_state >= FIRST_BLOCKED_STATE) && + (tcb->task_state <= LAST_BLOCKED_STATE)); + + 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 = MSEC2TICK(CONFIG_RR_INTERVAL); +#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 struct tcb_s*)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 struct tcb_s*)g_readytorun.head; + dbg("New Active Task TCB=%p\n", rtcb); + + /* Then switch contexts */ + + up_restorecontext(&rtcb->xcp); + } + } +} |