mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
NuttX RTOS
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -0,0 +1,121 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Nuttx Porting Manual</title>
|
||||||
|
<meta name="author" content="Gregory Nutt">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<center>
|
||||||
|
<big><b>
|
||||||
|
<p>Nuttx Operating System</p>
|
||||||
|
<p>Porting Guide</p>
|
||||||
|
</b></big>
|
||||||
|
<p><small>by</small></p>
|
||||||
|
<p>Gregory Nutt</p>
|
||||||
|
<p><small>Last Update: February 8, 2007</small></p>
|
||||||
|
</center>
|
||||||
|
|
||||||
|
<center><h1>Table of Contents</h1></center>
|
||||||
|
<li>1.0 <a href="#Introduction">1.0 Introduction</a></li>
|
||||||
|
<li>2.0 <a href="#DirectoryStructure">Directory Structure</a></li>
|
||||||
|
<ul>
|
||||||
|
<li>2.1 <a href="#DirStructDocumentation">Documentation</a></li>
|
||||||
|
<l1>2.2 <a href="#DirStructArch">arch</a></li>
|
||||||
|
<li>2.3 <a href="#DirStructDrivers">drivers</a></li>
|
||||||
|
<li>2.4 <a href="#DirStructExamples">examples</a></li>
|
||||||
|
<li>2.5 <a href="#DirStructFs">fs</a></li>
|
||||||
|
<li>2.6 <a href="#DirStructInclude">include</a></li>
|
||||||
|
<li>2.7 <a href="#DirStructLib">lib</a></li>
|
||||||
|
<li>2.8 <a href="#DirStructMm">mm</a></li>
|
||||||
|
<li>2.9 <a href="#DirStructSched">sched</a></li>
|
||||||
|
<li>2.10 <a href="#DirStructDrivers">tools</a></li>
|
||||||
|
</ul>
|
||||||
|
<li>3.0 <a href="#DirectoryConfiAndBuild">Configuring and Building</a></li>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<h1>1.0 <a name="Introduction">Introduction</a></h1>
|
||||||
|
|
||||||
|
<p><b>Overview</b>
|
||||||
|
This document provides and overview of the Nuttx build and configuration
|
||||||
|
logic and provides hints for the incorporation of new processor/board archectures
|
||||||
|
into the build.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
See also arch/README.txt.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p><b>General Philosophy</b>.
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<h1>2.0 <a name="DirectoryStructure">Directory Structure</a></h1>
|
||||||
|
|
||||||
|
<p>The general directly layout for Nuttx is very similar to the directory structure
|
||||||
|
of the Linux kernel -- at least at the most superficial layers.
|
||||||
|
At the top level is the main makefile and a series of sub-directories identified
|
||||||
|
below and discussed in the following paragraphs:</p>
|
||||||
|
|
||||||
|
<ul><pre>
|
||||||
|
.
|
||||||
|
|-- Makefile
|
||||||
|
|-- <a href="#DirStructDocumentation">Documentation</a>
|
||||||
|
| `-- <i>(documentation files)</i>
|
||||||
|
|-- <a href="#DirStructArch">arch</a>
|
||||||
|
| |-- <i>(architecture)</i>
|
||||||
|
| | |-- Make.defs
|
||||||
|
| | |-- defconfig
|
||||||
|
| | |-- include
|
||||||
|
| | |-- setenv.sh
|
||||||
|
| | `-- src
|
||||||
|
| `-- <i>(other architectures)</i>
|
||||||
|
|-- <a href="#DirStructDrivers">drivers</a>
|
||||||
|
| |-- Makefile
|
||||||
|
| `-- <i>(driver source files)</i>
|
||||||
|
|-- <a href="#DirStructExamples">examples</a>
|
||||||
|
| `-- <i>(example)</i>
|
||||||
|
| |-- Makefile
|
||||||
|
| `-- <i>(example source files)</i>
|
||||||
|
|-- <a href="#DirStructFs">fs</a>
|
||||||
|
| |-- Makefile
|
||||||
|
| `-- <i>(fs source files)</i>
|
||||||
|
|-- <a href="#DirStructInclude">include</a>
|
||||||
|
| |-- <i>(standard header files)</i>
|
||||||
|
| |-- nuttx
|
||||||
|
| | `-- <i>(nuttx specific header files)</i>
|
||||||
|
| `- sys
|
||||||
|
| | `-- <i>(more standard header files)</i>
|
||||||
|
|-- <a href="#DirStructLib">lib</a>
|
||||||
|
| |-- Makefile
|
||||||
|
| `-- <i>(lib source files)</i>
|
||||||
|
|-- <a href="#DirStructMm">mm</a>
|
||||||
|
| |-- Makefile
|
||||||
|
| `-- <i>(mm source files)</i>
|
||||||
|
|-- <a href="#DirStructSched">sched</a>
|
||||||
|
| |-- Makefile
|
||||||
|
| `-- <i>(sched source files)</i>
|
||||||
|
`-- <a href="#DirStructDrivers">tools</a>
|
||||||
|
|-- Makefile.mkconfig
|
||||||
|
|-- configure.sh
|
||||||
|
|-- mkconfig.c
|
||||||
|
|-- mkdeps.sh
|
||||||
|
`-- zipme
|
||||||
|
</pre></ul>
|
||||||
|
|
||||||
|
<h2>2.1 <a name="DirStructDocumentation">Documentation</a></h2>
|
||||||
|
<h2>2.2 <a name="DirStructArch">arch</a></h2>
|
||||||
|
<h2>2.3 <a name="DirStructDrivers">drivers</a></h2>
|
||||||
|
<h2>2.4 <a name="DirStructExamples">examples</a></h2>
|
||||||
|
<h2>2.5 <a name="DirStructFs">fs</a></h2>
|
||||||
|
<h2>2.6 <a name="DirStructInclude">include</a></h2>
|
||||||
|
<h2>2.7 <a name="DirStructLib">lib</a></h2>
|
||||||
|
<h2>2.8 <a name="DirStructMm">mm</a></h2>
|
||||||
|
<h2>2.9 <a name="DirStructSched">sched</a></h2>
|
||||||
|
<h2>2.10 <a name="DirStructDrivers">tools</a></h2>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<h1>3.0 <a name="DirectoryConfiAndBuild">Configuring and Building</a></h1>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,139 @@
|
|||||||
|
############################################################
|
||||||
|
# Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
TOPDIR = ${shell pwd}
|
||||||
|
-include ${TOPDIR}/.config
|
||||||
|
-include ${TOPDIR}/Make.defs
|
||||||
|
|
||||||
|
ARCH_DIR = arch/$(CONFIG_ARCH)
|
||||||
|
ARCH_SRC = $(ARCH_DIR)/src
|
||||||
|
|
||||||
|
SUBDIRS = sched lib $(ARCH_SRC) mm fs drivers examples/$(CONFIG_EXAMPLE)
|
||||||
|
|
||||||
|
OBJS = $(ARCH_SRC)/up_head.o
|
||||||
|
LIBGCC = ${shell $(CC) -print-libgcc-file-name}
|
||||||
|
LIBS = sched/libsched.a $(ARCH_SRC)/libarch.a mm/libmm.a \
|
||||||
|
fs/libfs.a drivers/libdrivers.a lib/liblib.a \
|
||||||
|
examples/$(CONFIG_EXAMPLE)/lib$(CONFIG_EXAMPLE).a
|
||||||
|
LDLIBS = -lsched -larch -lmm -lfs -ldrivers -llib -l$(CONFIG_EXAMPLE) $(LIBGCC) $(EXTRA_LIBS)
|
||||||
|
|
||||||
|
BIN = nuttx
|
||||||
|
|
||||||
|
LDFLAGS += -Lsched -Llib -L$(ARCH_SRC) -Lmm -Lfs -Ldrivers -Lexamples/$(CONFIG_EXAMPLE)
|
||||||
|
|
||||||
|
all: $(BIN)
|
||||||
|
.PHONY: clean context clean_context distclean
|
||||||
|
|
||||||
|
tools/mkconfig:
|
||||||
|
$(MAKE) -C tools -f Makefile.mkconfig TOPDIR=$(TOPDIR) mkconfig
|
||||||
|
|
||||||
|
include/nuttx/config.h: $(ARCH_DIR)/defconfig tools/mkconfig
|
||||||
|
tools/mkconfig $(ARCH_DIR) > include/nuttx/config.h
|
||||||
|
|
||||||
|
include/arch: include/nuttx/config.h
|
||||||
|
ln -sf $(TOPDIR)/$(ARCH_DIR)/include include/arch
|
||||||
|
|
||||||
|
context: check_context include/nuttx/config.h include/arch
|
||||||
|
|
||||||
|
clean_context:
|
||||||
|
rm -f include/nuttx/config.h
|
||||||
|
rm -f include/arch
|
||||||
|
|
||||||
|
check_context:
|
||||||
|
@if [ ! -e ${TOPDIR}/.config -o ! -e ${TOPDIR}/Make.defs ]; then \
|
||||||
|
echo "" ; echo "Nuttx has not been configured:" ; \
|
||||||
|
echo " cd tools; ./configure.sh <target>\n" ; echo "" ;\
|
||||||
|
exit 1 ; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
sched/libsched.a: context
|
||||||
|
$(MAKE) -C sched TOPDIR=$(TOPDIR) libsched.a
|
||||||
|
|
||||||
|
lib/liblib.a: context
|
||||||
|
$(MAKE) -C lib TOPDIR=$(TOPDIR) liblib.a
|
||||||
|
|
||||||
|
$(ARCH_SRC)/libarch.a: context
|
||||||
|
$(MAKE) -C $(ARCH_SRC) TOPDIR=$(TOPDIR) libarch.a
|
||||||
|
|
||||||
|
$(ARCH_SRC)/up_head.o: context
|
||||||
|
$(MAKE) -C $(ARCH_SRC) TOPDIR=$(TOPDIR) up_head.o
|
||||||
|
|
||||||
|
mm/libmm.a: context
|
||||||
|
$(MAKE) -C mm TOPDIR=$(TOPDIR) libmm.a
|
||||||
|
|
||||||
|
fs/libfs.a: context
|
||||||
|
$(MAKE) -C fs TOPDIR=$(TOPDIR) libfs.a
|
||||||
|
|
||||||
|
drivers/libdrivers.a: context
|
||||||
|
$(MAKE) -C drivers TOPDIR=$(TOPDIR) libdrivers.a
|
||||||
|
|
||||||
|
examples/$(CONFIG_EXAMPLE)/lib$(CONFIG_EXAMPLE).a: context
|
||||||
|
$(MAKE) -C examples/$(CONFIG_EXAMPLE) TOPDIR=$(TOPDIR) lib$(CONFIG_EXAMPLE).a
|
||||||
|
|
||||||
|
$(BIN): context depend $(OBJS) $(LIBS)
|
||||||
|
ifeq ($(CONFIG_ARCH),sim)
|
||||||
|
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(LDLIBS)
|
||||||
|
$(NM) $(BIN) | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
|
||||||
|
else
|
||||||
|
$(LD) --entry=__start $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(LDLIBS)
|
||||||
|
$(NM) $(BIN) | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
|
||||||
|
@export vflashstart=`$(OBJDUMP) --all-headers $(BIN) | grep _vflashstart | cut -d' ' -f1`; \
|
||||||
|
if [ ! -z "$$vflashstart" ]; then \
|
||||||
|
$(OBJCOPY) --adjust-section-vma=.vector=0x$$vflashstart $(BIN) $(BIN).flashimage; \
|
||||||
|
mv $(BIN).flashimage $(BIN); \
|
||||||
|
fi
|
||||||
|
endif
|
||||||
|
|
||||||
|
depend:
|
||||||
|
@for dir in $(SUBDIRS) ; do \
|
||||||
|
$(MAKE) -C $$dir TOPDIR=$(TOPDIR) depend ; \
|
||||||
|
done
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@for dir in $(SUBDIRS) ; do \
|
||||||
|
$(MAKE) -C $$dir TOPDIR=$(TOPDIR) clean ; \
|
||||||
|
done
|
||||||
|
$(MAKE) -C tools -f Makefile.mkconfig TOPDIR=$(TOPDIR) clean
|
||||||
|
$(MAKE) -C mm -f Makefile.test TOPDIR=$(TOPDIR) clean
|
||||||
|
rm -f $(BIN) context mm_test System.map *~ *.flashimage
|
||||||
|
|
||||||
|
distclean: clean clean_context
|
||||||
|
@for dir in $(SUBDIRS) ; do \
|
||||||
|
$(MAKE) -C $$dir TOPDIR=$(TOPDIR) distclean ; \
|
||||||
|
done
|
||||||
|
$(MAKE) -C examples/$(CONFIG_EXAMPLE) TOPDIR=$(TOPDIR) distclean
|
||||||
|
rm -f Make.defs setenv.sh .config
|
||||||
|
|
||||||
|
|
||||||
+189
@@ -0,0 +1,189 @@
|
|||||||
|
Architecture-Specific Code
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
The file include/nuttx/arch.h identifies all of the APIs that must
|
||||||
|
be provided by the architecture specific logic. (It also includes
|
||||||
|
arch/<arch-name>/arch.h as described below).
|
||||||
|
|
||||||
|
Directory Structure
|
||||||
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Thie arch directory contains architecture specific logic. Each aructure
|
||||||
|
provide a a subdirectory <arch-name>under arch/ with the folling characteristics:
|
||||||
|
|
||||||
|
|
||||||
|
<arch-name>
|
||||||
|
|-- Make.defs
|
||||||
|
|-- defconfig
|
||||||
|
|-- setenv.sh
|
||||||
|
|-- include
|
||||||
|
| |-- arch.h
|
||||||
|
| |-- irq.h
|
||||||
|
| `-- types.h
|
||||||
|
`-- src
|
||||||
|
|-- Makefile
|
||||||
|
`-- (architecture-specific source files)
|
||||||
|
|
||||||
|
Summary of Files
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Make.defs -- This makefile fragment provides architecture and
|
||||||
|
tool-specific build options. It will be included by all other
|
||||||
|
makefiles in the build (once it is installed). This make fragment
|
||||||
|
should define:
|
||||||
|
|
||||||
|
Tools: CC, LD, AR, NM, OBJCOPY, OBJDUMP
|
||||||
|
Tool options: CFLAGS, LDFLAGS
|
||||||
|
|
||||||
|
When this makefile fragment runs, it will be passed TOPDIR which
|
||||||
|
is the path to the root directory of the build. This makefile
|
||||||
|
fragment may include ${TOPDIR}/.config to perform configuration
|
||||||
|
specific settings. For example, the CFLAGS will most likely be
|
||||||
|
different if CONFIG_DEBUG=y.
|
||||||
|
|
||||||
|
defconfig -- This is a configuration file similar to the Linux
|
||||||
|
configuration file. In contains varialble/value pairs like:
|
||||||
|
|
||||||
|
CONFIG_VARIABLE=value
|
||||||
|
|
||||||
|
This configuration file will be used at build time:
|
||||||
|
|
||||||
|
(1) as a makefile fragment included in other makefiles, and
|
||||||
|
(2) to generate include/nuttx/config.h which is included by
|
||||||
|
most C files in the system.
|
||||||
|
|
||||||
|
The following variables are recognized by the build (you may
|
||||||
|
also include architecture-specific settings).
|
||||||
|
|
||||||
|
Architecture selection:
|
||||||
|
|
||||||
|
CONFIG_ARCH - identifies the arch subdirectory
|
||||||
|
CONFIG_ARCH_name - for use in C code
|
||||||
|
|
||||||
|
General OS setup
|
||||||
|
|
||||||
|
CONFIG_EXAMPLE - identifies the subdirectgory in examples
|
||||||
|
that will be used in the build
|
||||||
|
CONFIG_DEBUG - enables built-in debug options
|
||||||
|
CONFIG_DEBUG_VERBOSE - enables verbose debug output
|
||||||
|
CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot
|
||||||
|
time console output
|
||||||
|
CONFIG_RR_INTERVAL - The round robin timeslice will be set
|
||||||
|
this number of milliseconds; Round robin scheduling can
|
||||||
|
be disabled by setting this value to zero.
|
||||||
|
CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in
|
||||||
|
scheduler to monitor system performance
|
||||||
|
CONFIG_TASK_NAME_SIZE - Spcifies that maximum size of a
|
||||||
|
task name to save in the TCB. Useful if scheduler
|
||||||
|
instrumentation is selected. Set to zero to disable.
|
||||||
|
CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
|
||||||
|
Used to initialize the internal time logic.
|
||||||
|
CONFIG_JULIAN_TIME - Enables Julian time conversions
|
||||||
|
CONFIG_DEV_CONSOLE - Set if architecture-specific logic
|
||||||
|
provides /dev/console. Enables stdout, stderr, stdin.
|
||||||
|
|
||||||
|
Allow for artchitecture optimized implementations
|
||||||
|
|
||||||
|
The architecture can provide optimized versions of the
|
||||||
|
following to improve sysem performance
|
||||||
|
|
||||||
|
CONFIG_ARCH_MEMCPY, CONFIG_ARCH_MEMCMP, CONFIG_ARCH_MEMMOVE
|
||||||
|
CONFIG_ARCH_MEMSET, CONFIG_ARCH_STRCMP, CONFIG_ARCH_STRCPY
|
||||||
|
CONFIG_ARCH_STRNCPY, CONFIG_ARCH_STRLEN, CONFIG_ARCH_BZERO
|
||||||
|
CONFIG_ARCH_KMALLOC, CONFIG_ARCH_KZMALLOC, CONFIG_ARCH_KFREE
|
||||||
|
|
||||||
|
General Compile environment setup
|
||||||
|
|
||||||
|
CONFIG_HAVE_LONG_LONG - enable if your architecture supports
|
||||||
|
long long types and if you plan to use them
|
||||||
|
|
||||||
|
Sizes of configurable things (0 disables)
|
||||||
|
|
||||||
|
CONFIG_NPTHREAD_KEYS - The number of items of thread-
|
||||||
|
specific data that can be retained
|
||||||
|
CONFIG_NFILE_DESCRIPTORS - The maximum number of file
|
||||||
|
descriptors (one for each open)
|
||||||
|
CONFIG_NFILE_STREAMS - The maximum number of streams that
|
||||||
|
can be fopen'ed
|
||||||
|
CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate
|
||||||
|
on fopen. (Only if CONFIG_NFILE_STREAMS > 0)
|
||||||
|
CONFIG_NUNGET_CHARS - Number of characters that can be
|
||||||
|
buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0)
|
||||||
|
CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message
|
||||||
|
structures. The system manages a pool of preallocated
|
||||||
|
message structures to minimize dynamic allocations
|
||||||
|
CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
|
||||||
|
a fixed payload size given by this settin (does not include
|
||||||
|
other message structure overhead.
|
||||||
|
CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
|
||||||
|
structures. The system manages a pool of preallocated
|
||||||
|
watchdog structures to minimize dynamic allocations
|
||||||
|
|
||||||
|
Stack and heap information
|
||||||
|
|
||||||
|
CONFIG_BOOT_FROM_FLASH - Some configurations support XIP
|
||||||
|
operation from FLASH.
|
||||||
|
CONFIG_STACK_POINTER - The initial stack pointer
|
||||||
|
CONFIG_PROC_STACK_SIZE - The size of the initial stack
|
||||||
|
CONFIG_PTHREAD_STACK_MIN - Minimum pthread stack size
|
||||||
|
CONFIG_PTHREAD_STACK_DEFAULT - Default pthread stack size
|
||||||
|
CONFIG_HEAP_BASE - The beginning of the heap
|
||||||
|
CONFIG_HEAP_SIZE - The size of the heap
|
||||||
|
|
||||||
|
setenv.sh -- This is a script that you can include that will be installed at
|
||||||
|
the toplevel of the directory structure and can be sourced to set any
|
||||||
|
necessary environment variables.
|
||||||
|
|
||||||
|
include/arch.h
|
||||||
|
This is a hook for any architecture specific definitions that may
|
||||||
|
be needed by the system. It is included by include/nuttx/arch.h
|
||||||
|
|
||||||
|
include/types.h
|
||||||
|
This provides architecture/toolchain-specific definitions for
|
||||||
|
standard types. This file should typedef:
|
||||||
|
|
||||||
|
sbyte, ubyte, uint8, boolean, sint16, uint16, sint32, uint32, sint64, uint64
|
||||||
|
|
||||||
|
This file will be included by include/sys/types.h and be made
|
||||||
|
available to all files.
|
||||||
|
|
||||||
|
include/irq.h
|
||||||
|
This file needs to define some architecture specific functions (usually
|
||||||
|
inline) and structure. These include:
|
||||||
|
|
||||||
|
- struct xcptcontext. This structures represents the saved context
|
||||||
|
of a thread.
|
||||||
|
|
||||||
|
- static inline uint32 irqsave(void) -- Used to disable
|
||||||
|
all interrupts.
|
||||||
|
|
||||||
|
- static inline void irqrestore(uint32 flags) -- Used to
|
||||||
|
restore interrupts enables to the same state as before irqsave
|
||||||
|
was called.
|
||||||
|
|
||||||
|
This file must also define NR_IRQS, the total number of IRQs supported
|
||||||
|
by the board.
|
||||||
|
|
||||||
|
src/Makefile
|
||||||
|
This makefile will be executed to build the targets src/libup.a and
|
||||||
|
src/up_head.o. The up_head.o file holds the entry point into the system
|
||||||
|
(power-on reset entry point, for example). It will be used in
|
||||||
|
the final link with libup.a and other system archives to generate the
|
||||||
|
final executable.
|
||||||
|
|
||||||
|
Configuring NuttX
|
||||||
|
^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Configuring NuttX requires only copying
|
||||||
|
|
||||||
|
arch/<arch-name>/Make.def to ${TOPDIR}/Make.defs
|
||||||
|
arch/<arch-name>/setenv.sh to ${TOPDIR}/setenv.sh
|
||||||
|
arch/<arch-name>/defconfig to ${TOPDIR}/.config
|
||||||
|
|
||||||
|
There is a script that automates these steps. The following steps will
|
||||||
|
accomplish the same configuration:
|
||||||
|
|
||||||
|
cd tools
|
||||||
|
./configure.sh <arch-name>
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
############################################################
|
||||||
|
# Make.defs
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
include ${TOPDIR}/.config
|
||||||
|
|
||||||
|
ifeq ("${CONFIG_DEBUG}","y")
|
||||||
|
ARCHOPTIMIZATION = -g
|
||||||
|
else
|
||||||
|
ARCHOPTIMIZATION = -Os -fno-strict-aliasing -fno-strength-reduce \
|
||||||
|
-fomit-frame-pointer
|
||||||
|
endif
|
||||||
|
|
||||||
|
ARCHCPUFLAGS = -mapcs-32 -mcpu=arm7tdmi -msoft-float
|
||||||
|
ARCHPICFLAGS = -fpic
|
||||||
|
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow
|
||||||
|
ARCHDEFINES =
|
||||||
|
ARCHINCLUDES = -I. -isystem $(TOPDIR)/include
|
||||||
|
ARCHSCRIPT = -T$(TOPDIR)/arch/$(CONFIG_ARCH)/ld.script
|
||||||
|
|
||||||
|
CROSSDEV = arm-elf-
|
||||||
|
CC = $(CROSSDEV)gcc
|
||||||
|
LD = $(CROSSDEV)ld
|
||||||
|
AR = $(CROSSDEV)ar
|
||||||
|
NM = $(CROSSDEV)nm
|
||||||
|
OBJCOPY = $(CROSSDEV)objcopy
|
||||||
|
OBJDUMP = $(CROSSDEV)objdump
|
||||||
|
|
||||||
|
CFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \
|
||||||
|
$(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) -pipe
|
||||||
|
|
||||||
|
LDFLAGS = $(ARCHSCRIPT)
|
||||||
|
EXTRA_LIBS =
|
||||||
|
|
||||||
|
ifeq ("${CONFIG_DEBUG}","y")
|
||||||
|
LDFLAGS += -g
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
############################################################
|
||||||
|
# defconfig
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
#
|
||||||
|
# architecture selection
|
||||||
|
#
|
||||||
|
# CONFIG_ARCH - identifies the arch subdirectory
|
||||||
|
# CONFIG_ARCH_name - for use in C code
|
||||||
|
# CONFIG_ROM_VECTORS - unique to arm7tdmi
|
||||||
|
#
|
||||||
|
CONFIG_ARCH=c5471
|
||||||
|
CONFIG_ARCH_C5471=y
|
||||||
|
CONFIG_ROM_VECTORS=n
|
||||||
|
|
||||||
|
#
|
||||||
|
# General OS setup
|
||||||
|
#
|
||||||
|
# CONFIG_EXAMPLE - identifies the subdirectgory in examples
|
||||||
|
# that will be used in the build
|
||||||
|
# CONFIG_DEBUG - enables built-in debug options
|
||||||
|
# CONFIG_DEBUG_VERBOSE - enables verbose debug output
|
||||||
|
# CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot
|
||||||
|
# time console output
|
||||||
|
# CONFIG_RR_INTERVAL - The round robin timeslice will be set
|
||||||
|
# this number of milliseconds; Round robin scheduling can
|
||||||
|
# be disabled by setting this value to zero.
|
||||||
|
# CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in
|
||||||
|
# scheduler to monitor system performance
|
||||||
|
# CONFIG_TASK_NAME_SIZE - Spcifies that maximum size of a
|
||||||
|
# task name to save in the TCB. Useful if scheduler
|
||||||
|
# instrumentation is selected. Set to zero to disable.
|
||||||
|
# CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
|
||||||
|
# Used to initialize the internal time logic.
|
||||||
|
# CONFIG_JULIAN_TIME - Enables Julian time conversions
|
||||||
|
# CONFIG_DEV_CONSOLE - Set if architecture-specific logic
|
||||||
|
# provides /dev/console. Enables stdout, stderr, stdin.
|
||||||
|
#
|
||||||
|
CONFIG_EXAMPLE=ostest
|
||||||
|
CONFIG_DEBUG=y
|
||||||
|
CONFIG_DEBUG_VERBOSE=n
|
||||||
|
CONFIG_ARCH_LOWPUTC=n
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_SCHED_INSTRUMENTATION=n
|
||||||
|
CONFIG_TASK_NAME_SIZE=0
|
||||||
|
CONFIG_START_YEAR=2007
|
||||||
|
CONFIG_START_MONTH=2
|
||||||
|
CONFIG_START_DAY=13
|
||||||
|
CONFIG_JULIAN_TIME=n
|
||||||
|
CONFIG_DEV_CONSOLE=n
|
||||||
|
|
||||||
|
#
|
||||||
|
# Allow for artchitecture optimized implementations
|
||||||
|
#
|
||||||
|
# The architecture can provide optimized versions of the
|
||||||
|
# following to improve sysem performance
|
||||||
|
#
|
||||||
|
CONFIG_ARCH_MEMCPY=n
|
||||||
|
CONFIG_ARCH_MEMCMP=n
|
||||||
|
CONFIG_ARCH_MEMMOVE=n
|
||||||
|
CONFIG_ARCH_MEMSET=n
|
||||||
|
CONFIG_ARCH_STRCMP=n
|
||||||
|
CONFIG_ARCH_STRCPY=n
|
||||||
|
CONFIG_ARCH_STRNCPY=n
|
||||||
|
CONFIG_ARCH_STRLEN=n
|
||||||
|
CONFIG_ARCH_BZERO=n
|
||||||
|
CONFIG_ARCH_KMALLOC=n
|
||||||
|
CONFIG_ARCH_KZMALLOC=n
|
||||||
|
CONFIG_ARCH_KFREE=n
|
||||||
|
|
||||||
|
# General Compile environment setup
|
||||||
|
#
|
||||||
|
# CONFIG_HAVE_LONG_LONG - enable if your architecture supports
|
||||||
|
# long long types and if you plan to use them
|
||||||
|
CONFIG_HAVE_LONG_LONG=n
|
||||||
|
|
||||||
|
#
|
||||||
|
# Sizes of configurable things (0 disables)
|
||||||
|
#
|
||||||
|
# CONFIG_NPTHREAD_KEYS - The number of items of thread-
|
||||||
|
# specific data that can be retained
|
||||||
|
# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
|
||||||
|
# descriptors (one for each open)
|
||||||
|
# CONFIG_NFILE_STREAMS - The maximum number of streams that
|
||||||
|
# can be fopen'ed
|
||||||
|
# CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate
|
||||||
|
# on fopen. (Only if CONFIG_NFILE_STREAMS > 0)
|
||||||
|
# CONFIG_NUNGET_CHARS - Number of characters that can be
|
||||||
|
# buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0)
|
||||||
|
# CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message
|
||||||
|
# structures. The system manages a pool of preallocated
|
||||||
|
# message structures to minimize dynamic allocations
|
||||||
|
# CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
|
||||||
|
# a fixed payload size given by this settin (does not include
|
||||||
|
# other message structure overhead.
|
||||||
|
# CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
|
||||||
|
# structures. The system manages a pool of preallocated
|
||||||
|
# watchdog structures to minimize dynamic allocations
|
||||||
|
#
|
||||||
|
CONFIG_NPTHREAD_KEYS=4
|
||||||
|
CONFIG_NFILE_DESCRIPTORS=32
|
||||||
|
CONFIG_NFILE_STREAMS=16
|
||||||
|
CONFIG_STDIO_BUFFER_SIZE=1024
|
||||||
|
CONFIG_NUNGET_CHARS=2
|
||||||
|
CONFIG_PREALLOC_MQ_MSGS=32
|
||||||
|
CONFIG_MQ_MAXMSGSIZE=32
|
||||||
|
CONFIG_PREALLOC_WDOGS=32
|
||||||
|
|
||||||
|
#
|
||||||
|
# Stack and heap information
|
||||||
|
#
|
||||||
|
# CONFIG_BOOT_FROM_FLASH - Some configurations support XIP
|
||||||
|
# operation from FLASH.
|
||||||
|
# CONFIG_STACK_POINTER - The initial stack pointer (arm7tdmi only)
|
||||||
|
# CONFIG_PROC_STACK_SIZE - The size of the initial stack
|
||||||
|
# CONFIG_PTHREAD_STACK_MIN - Minimum pthread stack size
|
||||||
|
# CONFIG_PTHREAD_STACK_DEFAULT - Default pthread stack size
|
||||||
|
# CONFIG_HEAP_BASE - The beginning of the heap
|
||||||
|
# CONFIG_HEAP_SIZE - The size of the heap
|
||||||
|
#
|
||||||
|
CONFIG_BOOT_FROM_FLASH=n
|
||||||
|
CONFIG_STACK_POINTER=0x02100000
|
||||||
|
CONFIG_PROC_STACK_SIZE=0x00001000
|
||||||
|
CONFIG_PTHREAD_STACK_MIN=256
|
||||||
|
CONFIG_PTHREAD_STACK_DEFAULT=4096
|
||||||
|
CONFIG_HEAP_BASE=0x02100000
|
||||||
|
CONFIG_HEAP_SIZE=0x00100000
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/************************************************************
|
||||||
|
* arch.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* This file should never be included directed but, rather,
|
||||||
|
* only indirectly through nuttx/arch.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ARCH_C5471_ARCH_H
|
||||||
|
#define __ARCH_C5471_ARCH_H
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Inline functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Types
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Variables
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C" {
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ARCH_C5471_ARCH_H */
|
||||||
|
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
/************************************************************
|
||||||
|
* irq.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* This file should never be included directed but, rather,
|
||||||
|
* only indirectly through nuttx/irq.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ARCH_C5471_IRQ_H
|
||||||
|
#define __ARCH_C5471_IRQ_H
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* IRQ Stack Frame Format:
|
||||||
|
*
|
||||||
|
* Context is always saved/restored in the same way:
|
||||||
|
*
|
||||||
|
* (1) stmia rx, {r0-r3, r12}
|
||||||
|
* (2) stmia rx, (cpsr, r4-r11, r13-r14}
|
||||||
|
*
|
||||||
|
* This results in the following set of indices that
|
||||||
|
* can be used to access individual registers in the
|
||||||
|
* xcp.regs array:
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define JB_R0 (0)
|
||||||
|
#define JB_R1 (1)
|
||||||
|
#define JB_R2 (2)
|
||||||
|
#define JB_R3 (3)
|
||||||
|
#define JB_R12 (4)
|
||||||
|
|
||||||
|
#define XCPTCONTEXT_IRQ_REGS (5)
|
||||||
|
#define XCPTCONTEXT_UOFFSET (4 * XCPTCONTEXT_IRQ_REGS)
|
||||||
|
|
||||||
|
#define JB_CPSR (0 + XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define JB_R4 (1 + XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define JB_R5 (2 + XCPTCONTEXT_IRQ_REGS
|
||||||
|
#define JB_R6 (3 + XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define JB_R7 (4 + XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define JB_R8 (5 + XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define JB_R9 (6 + XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define JB_R10 (7 + XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define JB_R11 (8 + XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define JB_R13 (9 + XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define JB_R14 (10 + XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define JB_R15 /* Not saved */
|
||||||
|
|
||||||
|
#define XCPTCONTEXT_USER_REG (11)
|
||||||
|
#define XCPTCONTEST_REGS (XCPTCONTEXT_USER_REG+XCPTCONTEXT_IRQ_REGS)
|
||||||
|
#define XCPTCONTEXT_SIZE (4 * XCPTCONTEST_REGS)
|
||||||
|
|
||||||
|
#define JB_A1 JB_R0
|
||||||
|
#define JB_A2 JB_R1
|
||||||
|
#define JB_A3 JB_R2
|
||||||
|
#define JB_A4 JB_R3
|
||||||
|
#define JB_V1 JB_R4
|
||||||
|
#define JB_V2 JB_R5
|
||||||
|
#define JB_V3 JB_R6
|
||||||
|
#define JB_V4 JB_R7
|
||||||
|
#define JB_V5 JB_R8
|
||||||
|
#define JB_V6 JB_R9
|
||||||
|
#define JB_V7 JB_R10
|
||||||
|
#define JB_SB JB_R9
|
||||||
|
#define JB_SL JB_R10
|
||||||
|
#define JB_FP JB_R11
|
||||||
|
#define JB_IP JB_R12
|
||||||
|
#define JB_SP JB_R13
|
||||||
|
#define JB_LR JB_R14
|
||||||
|
#define JB_PC JB_R15
|
||||||
|
|
||||||
|
/* C5471 Interrupts */
|
||||||
|
|
||||||
|
#define C5471_IRQ_TIMER0 0
|
||||||
|
#define C5471_IRQ_TIMER1 1
|
||||||
|
#define C5471_IRQ_TIMER2 2
|
||||||
|
#define C5471_IRQ_GPIO0 3
|
||||||
|
#define C5471_IRQ_ETHER 4
|
||||||
|
#define C5471_IRQ_KBGPIO_0_7 5
|
||||||
|
#define C5471_IRQ_UART 6
|
||||||
|
#define C5471_IRQ_UART_IRDA 7
|
||||||
|
#define C5471_IRQ_KBGPIO_8_15 8
|
||||||
|
#define C5471_IRQ_GPIO3 9
|
||||||
|
#define C5471_IRQ_GPIO2 10
|
||||||
|
#define C5471_IRQ_I2C 11
|
||||||
|
#define C5471_IRQ_GPIO1 12
|
||||||
|
#define C5471_IRQ_SPI 13
|
||||||
|
#define C5471_IRQ_GPIO_4_19 14
|
||||||
|
#define C5471_IRQ_API 15
|
||||||
|
|
||||||
|
#define C5471_IRQ_WATCHDOG C5471_IRQ_TIMER0
|
||||||
|
#define C5471_IRQ_SYSTIMER C5471_IRQ_TIMER1
|
||||||
|
#define NR_IRQS (C5471_IRQ_API+1)
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Types
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* This struct defines the way the registers are stored. We
|
||||||
|
* need to save:
|
||||||
|
*
|
||||||
|
* 1 CPSR
|
||||||
|
* 7 Static registers, v1-v7 (aka r4-r10)
|
||||||
|
* 1 Frame pointer, fp (aka r11)
|
||||||
|
* 1 Stack pointer, sp (aka r13)
|
||||||
|
* 1 Return address, lr (aka r14)
|
||||||
|
* ---
|
||||||
|
* 11 (XCPTCONTEXT_USER_REG)
|
||||||
|
*
|
||||||
|
* On interrupts, we also need to save:
|
||||||
|
* 4 Volatile registers, a1-a4 (aka r0-r3)
|
||||||
|
* 1 Scratch Register, ip (aka r12)
|
||||||
|
*---
|
||||||
|
* 5 (XCPTCONTEXT_IRQ_REGS)
|
||||||
|
*
|
||||||
|
* For a total of 17 (XCPTCONTEST_REGS)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
struct xcptcontext
|
||||||
|
{
|
||||||
|
/* The following function pointer is non-zero if there
|
||||||
|
* are pending signals to be processed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void *sigdeliver; /* Actual type is sig_deliver_t */
|
||||||
|
|
||||||
|
/* These are saved copies of LR and CPSR used during
|
||||||
|
* signal processing.
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint32 saved_lr;
|
||||||
|
uint32 saved_cpsr;
|
||||||
|
|
||||||
|
/* Register save area */
|
||||||
|
|
||||||
|
uint32 regs[XCPTCONTEST_REGS];
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Inline functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
|
/* Save the current interrupt enable state & disable IRQs */
|
||||||
|
|
||||||
|
static inline uint32 irqsave(void)
|
||||||
|
{
|
||||||
|
unsigned long flags;
|
||||||
|
unsigned long temp;
|
||||||
|
__asm__ __volatile__
|
||||||
|
(
|
||||||
|
"\tmrs %0, cpsr\n"
|
||||||
|
"\torr %1, %0, #128\n"
|
||||||
|
"\tmsr cpsr_c, %1"
|
||||||
|
: "=r" (flags), "=r" (temp)
|
||||||
|
:
|
||||||
|
: "memory");
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Restore saved IRQ & FIQ state */
|
||||||
|
|
||||||
|
static inline void irqrestore(uint32 flags)
|
||||||
|
{
|
||||||
|
__asm__ __volatile__
|
||||||
|
(
|
||||||
|
"msr cpsr_c, %0"
|
||||||
|
:
|
||||||
|
: "r" (flags)
|
||||||
|
: "memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void system_call(swint_t func, uint32 parm1,
|
||||||
|
uint32 parm2, uint32 parm3)
|
||||||
|
{
|
||||||
|
__asm__ __volatile__
|
||||||
|
(
|
||||||
|
"mov\tr0,%0\n\t"
|
||||||
|
"mov\tr1,%1\n\t"
|
||||||
|
"mov\tr2,%2\n\t"
|
||||||
|
"mov\tr2,%3\n\t"
|
||||||
|
"swi\t0x900001\n\t"
|
||||||
|
:
|
||||||
|
: "r" ((long)(func)), "r" ((long)(parm1)),
|
||||||
|
"r" ((long)(parm2)), "r" ((long)(parm3))
|
||||||
|
: "r0", "r1", "r2", "r3", "lr");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Variables
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C" {
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ARCH_C5471_IRQ_H */
|
||||||
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/************************************************************
|
||||||
|
* types.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* This file should never be included directed but, rather,
|
||||||
|
* only indirectly through sys/types.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ARCH_C5471_TYPES_H
|
||||||
|
#define __ARCH_C5471_TYPES_H
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Type Declarations
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
typedef char sbyte;
|
||||||
|
typedef unsigned char ubyte;
|
||||||
|
typedef unsigned char uint8;
|
||||||
|
typedef unsigned char boolean;
|
||||||
|
typedef short sint16;
|
||||||
|
typedef unsigned short uint16;
|
||||||
|
typedef int sint32;
|
||||||
|
typedef unsigned int uint32;
|
||||||
|
typedef long long sint64;
|
||||||
|
typedef unsigned long long uint64;
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Global Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#endif /* __ARCH_C5471_TYPES_H */
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/************************************************************
|
||||||
|
* ld.script
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
OUTPUT_ARCH(arm)
|
||||||
|
ENTRY(_stext)
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
/* Interrupt vector trampoline and command line parameters
|
||||||
|
* are provided in IRAM by the rrload bootloader. Vectors will be
|
||||||
|
* copied into _svectors from _vflashstart.
|
||||||
|
*/
|
||||||
|
|
||||||
|
. = 0xffc00000;
|
||||||
|
_svectors = ABSOLUTE(.);
|
||||||
|
|
||||||
|
/* These are locations in IRAM where the rrload bootloader passes
|
||||||
|
* information to the running program
|
||||||
|
*/
|
||||||
|
|
||||||
|
. = 0xffc00020;
|
||||||
|
__KernCommandLineMagicStr = .; /* magic pattern string == "kcmdline-->" */
|
||||||
|
. = 0xffc0002C; /* advance to .+strlen("kcmdline-->")+1 */
|
||||||
|
__KernCommandLineOverride = .; /* location of kernel command line string */
|
||||||
|
|
||||||
|
. = 0xffc00100;
|
||||||
|
__EtherMACMagicStr = .; /* magic pattern string == "etherMAC-->" */
|
||||||
|
. = 0xffc0010C; /* advance to .+strlen("etherMAC-->")+1 */
|
||||||
|
__EtherMAC = .;
|
||||||
|
|
||||||
|
|
||||||
|
/* The OS entry point is here */
|
||||||
|
|
||||||
|
. = 0x01030000;
|
||||||
|
.text : {
|
||||||
|
_stext = ABSOLUTE(.);
|
||||||
|
*(.text)
|
||||||
|
*(.fixup)
|
||||||
|
*(.gnu.warning)
|
||||||
|
*(.rodata)
|
||||||
|
*(.glue_7)
|
||||||
|
*(.glue_7t)
|
||||||
|
*(.got) /* Global offset table */
|
||||||
|
_etext = ABSOLUTE(.);
|
||||||
|
}
|
||||||
|
|
||||||
|
_eronly = ABSOLUTE(.); /* See below */
|
||||||
|
. = ALIGN(4096);
|
||||||
|
|
||||||
|
.data : {
|
||||||
|
_sdata = ABSOLUTE(.);
|
||||||
|
*(.data)
|
||||||
|
CONSTRUCTORS
|
||||||
|
_edata = ABSOLUTE(.);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bss : { /* BSS */
|
||||||
|
_sbss = ABSOLUTE(.);
|
||||||
|
*(.bss)
|
||||||
|
*(COMMON)
|
||||||
|
_ebss = ABSOLUTE(.);
|
||||||
|
}
|
||||||
|
/* Stabs debugging sections. */
|
||||||
|
.stab 0 : { *(.stab) }
|
||||||
|
.stabstr 0 : { *(.stabstr) }
|
||||||
|
.stab.excl 0 : { *(.stab.excl) }
|
||||||
|
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||||
|
.stab.index 0 : { *(.stab.index) }
|
||||||
|
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||||
|
.comment 0 : { *(.comment) }
|
||||||
|
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||||
|
.debug_info 0 : { *(.debug_info) }
|
||||||
|
.debug_line 0 : { *(.debug_line) }
|
||||||
|
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||||
|
.debug_aranges 0 : { *(.debug_aranges) }
|
||||||
|
}
|
||||||
Executable
+46
@@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# setenv.sh
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ "$(basename $0)" = "setenv" ] ; then
|
||||||
|
echo "You must source this script, not run it!" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z ${PATH_ORIG} ]; then export PATH_ORIG=${PATH}; fi
|
||||||
|
|
||||||
|
WD=`pwd`
|
||||||
|
export BUILDROOT_BIN=${WD}/../buildroot/build_arm_nofpu/staging_dir/bin
|
||||||
|
export PATH=${BUILDROOT_BIN}:/sbin:/usr/sbin:${PATH_ORIG}
|
||||||
|
|
||||||
|
echo "PATH : ${PATH}"
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
############################################################
|
||||||
|
# Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
-include $(TOPDIR)/Make.defs
|
||||||
|
|
||||||
|
MKDEP = $(TOPDIR)/tools/mkdeps.sh
|
||||||
|
CFLAGS += -I$(TOPDIR)/sched
|
||||||
|
|
||||||
|
ASRCS = up_vectors.S up_saveusercontext.S up_fullcontextrestore.S
|
||||||
|
AOBJS = $(ASRCS:.S=.o)
|
||||||
|
|
||||||
|
CSRCS = up_initialize.c up_initialstate.c up_idle.c \
|
||||||
|
up_irq.c up_syscall.c up_dataabort.c up_prefetchabort.c \
|
||||||
|
up_undefinedinsn.c up_interruptcontext.c up_timerisr.c \
|
||||||
|
up_createstack.c up_usestack.c up_releasestack.c \
|
||||||
|
up_exit.c up_assert.c up_blocktask.c up_unblocktask.c \
|
||||||
|
up_releasepending.c up_reprioritizertr.c up_copystate.c \
|
||||||
|
up_schedulesigaction.c up_sigdeliver.c
|
||||||
|
COBJS = $(CSRCS:.c=.o)
|
||||||
|
|
||||||
|
SRCS = $(ASRCS) $(CSRCS)
|
||||||
|
OBJS = $(AOBJS) $(COBJS)
|
||||||
|
|
||||||
|
all: up_head.o libarch.a
|
||||||
|
|
||||||
|
$(AOBJS) up_head.o: %.o: %.S
|
||||||
|
$(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@
|
||||||
|
|
||||||
|
$(COBJS): %.o: %.c
|
||||||
|
$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
libarch.a: $(OBJS)
|
||||||
|
$(AR) rcs $@ $(OBJS)
|
||||||
|
|
||||||
|
.depend: Makefile $(SRCS)
|
||||||
|
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
depend: .depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f libarch.a *.o *~
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
rm -f Make.dep .depend
|
||||||
|
|
||||||
|
-include Make.dep
|
||||||
@@ -0,0 +1,376 @@
|
|||||||
|
/************************************************************
|
||||||
|
* c5471.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifndef __C5471_H
|
||||||
|
#define __C5471_H
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
# include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* Arm7Tdmi *************************************************/
|
||||||
|
|
||||||
|
/* CPSR bits */
|
||||||
|
|
||||||
|
#define USR26_MODE 0x00
|
||||||
|
#define FIQ26_MODE 0x01
|
||||||
|
#define IRQ26_MODE 0x02
|
||||||
|
#define SVC26_MODE 0x03
|
||||||
|
#define USR_MODE 0x10
|
||||||
|
#define FIQ_MODE 0x11
|
||||||
|
#define IRQ_MODE 0x12
|
||||||
|
#define SVC_MODE 0x13
|
||||||
|
#define ABT_MODE 0x17
|
||||||
|
#define UND_MODE 0x1b
|
||||||
|
#define SYSTEM_MODE 0x1f
|
||||||
|
#define MODE_MASK 0x1f
|
||||||
|
#define T_BIT 0x20
|
||||||
|
#define F_BIT 0x40
|
||||||
|
#define I_BIT 0x80
|
||||||
|
#define CC_V_BIT (1 << 28)
|
||||||
|
#define CC_C_BIT (1 << 29)
|
||||||
|
#define CC_Z_BIT (1 << 30)
|
||||||
|
#define CC_N_BIT (1 << 31)
|
||||||
|
|
||||||
|
/* UARTs ****************************************************/
|
||||||
|
|
||||||
|
#define UART_IRDA_BASE 0xffff0800
|
||||||
|
#define UART_MODEM_BASE 0xffff1000
|
||||||
|
#define UARTn_IO_RANGE 0x00000800
|
||||||
|
|
||||||
|
/* Common UART Registers. Expressed as offsets from the BASE address */
|
||||||
|
|
||||||
|
#define UART_RHR_OFFS 0x00000000 /* Rcv Holding Register */
|
||||||
|
#define UART_THR_OFFS 0x00000004 /* Xmit Holding Register */
|
||||||
|
#define UART_FCR_OFFS 0x00000008 /* FIFO Control Register */
|
||||||
|
#define UART_RFCR_OFFS 0x00000008 /* Rcv FIFO Control Register */
|
||||||
|
#define UART_TFCR_OFFS 0x00000008 /* Xmit FIFO Control Register */
|
||||||
|
#define UART_SCR_OFFS 0x0000000c /* Status Control Register */
|
||||||
|
#define UART_LCR_OFFS 0x00000010 /* Line Control Register */
|
||||||
|
#define UART_LSR_OFFS 0x00000014 /* Line Status Register */
|
||||||
|
#define UART_SSR_OFFS 0x00000018 /* Supplementary Status Register */
|
||||||
|
#define UART_MCR_OFFS 0x0000001c /* Modem Control Register */
|
||||||
|
#define UART_MSR_OFFS 0x00000020 /* Modem Status Register */
|
||||||
|
#define UART_IER_OFFS 0x00000024 /* Interrupt Enable Register */
|
||||||
|
#define UART_ISR_OFFS 0x00000028 /* Interrupt Status Register */
|
||||||
|
#define UART_EFR_OFFS 0x0000002c /* Enhanced Feature Register */
|
||||||
|
#define UART_XON1_OFFS 0x00000030 /* XON1 Character Register */
|
||||||
|
#define UART_XON2_OFFS 0x00000034 /* XON2 Character Register */
|
||||||
|
#define UART_XOFF1_OFFS 0x00000038 /* XOFF1 Character Register */
|
||||||
|
#define UART_XOFF2_OFFS 0x0000003c /* XOFF2 Character Register */
|
||||||
|
#define UART_SPR_OFFS 0x00000040 /* Scratch-pad Register */
|
||||||
|
#define UART_DIV_115K_OFFS 0x00000044 /* Divisor for baud generation */
|
||||||
|
#define UART_DIV_BIT_RATE_OFFS 0x00000048 /* For baud rate generation */
|
||||||
|
#define UART_TCR_OFFS 0x0000004c /* Transmission Control Register */
|
||||||
|
#define UART_TLR_OFFS 0x00000050 /* Trigger Level Register */
|
||||||
|
#define UART_MDR_OFFS 0x00000054 /* Mode Definition Register */
|
||||||
|
|
||||||
|
/* Registers available only for the IrDA UART (absolute address). */
|
||||||
|
|
||||||
|
#define UART_IRDA_MDR1 0xffff0854 /* Mode Definition Register 1 */
|
||||||
|
#define UART_IRDA_MDR2 0xffff0858 /* Mode Definition Register 2 */
|
||||||
|
#define UART_IRDA_TXFLL 0xffff085c /* LS Xmit Frame Length Register */
|
||||||
|
#define UART_IRDA_TXFLH 0xffff0860 /* MS Xmit Frame Length Register */
|
||||||
|
#define UART_IRDA_RXFLL 0xffff0864 /* LS Rcvd Frame Length Register */
|
||||||
|
#define UART_IRDA_RXFLH 0xffff0868 /* MS Rcvd Frame Length Register */
|
||||||
|
#define UART_IRDA_SFLSR 0xffff086c /* Status FIFO Line Status Reg */
|
||||||
|
#define UART_IRDA_SFREGL 0xffff0870 /* LS Status FIFO Register */
|
||||||
|
#define UART_IRDA_SFREGH 0xffff0874 /* MS Status FIFO Register */
|
||||||
|
#define UART_IRDA_BLR 0xffff0878 /* Begin of File Length Register */
|
||||||
|
#define UART_IRDA_PULSE_WIDTH 0xffff087c /* Pulse Width Register */
|
||||||
|
#define UART_IRDA_ACREG 0xffff0880 /* Auxiliary Control Register */
|
||||||
|
#define UART_IRDA_PULSE_START 0xffff0884 /* Start time of pulse */
|
||||||
|
#define UART_IRDA_RX_W_PTR 0xffff0888 /* RX FIFO write pointer */
|
||||||
|
#define UART_IRDA_RX_R_PTR 0xffff088c /* RX FIFO read pointer */
|
||||||
|
#define UART_IRDA_TX_W_PTR 0xffff0890 /* TX FIFO write pointer */
|
||||||
|
#define UART_IRDA_TX_R_PTR 0xffff0894 /* TX FIFO read pointer */
|
||||||
|
#define UART_IRDA_STATUS_W_PTR 0xffff0898 /* Write pointer of status FIFO */
|
||||||
|
#define UART_IRDA_STATUS_R_PTR 0xffff089c /* Read pointer of status FIFO */
|
||||||
|
#define UART_IRDA_RESUME 0xffff08a0 /* Resume register */
|
||||||
|
#define UART_IRDA_MUX 0xffff08a4 /* Selects UART_IRDA output mux */
|
||||||
|
|
||||||
|
/* Registers available for the Modem UART (absolute addresses) */
|
||||||
|
|
||||||
|
#define UART_MODEM_MDR 0xffff1054 /* Mode Definition Register */
|
||||||
|
#define UART_MODEM_UASR 0xffff1058 /* UART Auto-baud Status Register */
|
||||||
|
#define UART_MODEM_RDPTR_URX 0xffff105c /* RX FIFO Read Pointer Register */
|
||||||
|
#define UART_MODEM_WRPTR_URX 0xffff1060 /* RX FIFO Write Pointer Register */
|
||||||
|
#define UART_MODEM_RDPTR_UTX 0xffff1064 /* TX FIFO Read Pointer Register */
|
||||||
|
#define UART_MODEM_WRPTR_UTX 0xffff1068 /* TX FIFO Write Pointer Register */
|
||||||
|
|
||||||
|
/* UART Settings ********************************************/
|
||||||
|
|
||||||
|
/* Miscellaneous UART settings. */
|
||||||
|
|
||||||
|
#define UART_RX_FIFO_NOEMPTY 0x00000001
|
||||||
|
#define UART_SSR_TXFULL 0x00000001
|
||||||
|
#define UART_LSR_TREF 0x00000020
|
||||||
|
|
||||||
|
#define UART_XMIT_FIFO_SIZE 64
|
||||||
|
#define UART_IRDA_XMIT_FIFO_SIZE 64
|
||||||
|
|
||||||
|
/* UART_LCR Register */
|
||||||
|
/* Bits 31-7: Reserved */
|
||||||
|
#define UART_LCR_BOC 0x00000040 /* Bit 6: Break Control */
|
||||||
|
/* Bit 5: Parity Type 2 */
|
||||||
|
#define UART_LCR_ParEven 0x00000010 /* Bit 4: Parity Type 1 */
|
||||||
|
#define UART_LCR_ParOdd 0x00000000
|
||||||
|
#define UART_LCR_ParEn 0x00000008 /* Bit 3: Paity Enable */
|
||||||
|
#define UART_LCR_ParDis 0x00000000
|
||||||
|
#define UART_LCR_2stop 0x00000004 /* Bit 2: Number of stop bits */
|
||||||
|
#define UART_LCR_1stop 0x00000000
|
||||||
|
#define UART_LCR_5bits 0x00000000 /* Bits 0-1: Word-length */
|
||||||
|
#define UART_LCR_6bits 0x00000001
|
||||||
|
#define UART_LCR_7bits 0x00000002
|
||||||
|
#define UART_LCR_8bits 0x00000003
|
||||||
|
|
||||||
|
#define UART_FCR_FTL 0x00000000
|
||||||
|
#define UART_FCR_FIFO_EN 0x00000001
|
||||||
|
#define UART_FCR_TX_CLR 0x00000002
|
||||||
|
#define UART_FCR_RX_CLR 0x00000004
|
||||||
|
|
||||||
|
#define UART_IER_RecvInt 0x00000001
|
||||||
|
#define UART_IER_XmitInt 0x00000002
|
||||||
|
#define UART_IER_LineStsInt 0x00000004
|
||||||
|
#define UART_IER_ModemStsInt 0x00000008 /* IrDA UART only */
|
||||||
|
#define UART_IER_XoffInt 0x00000020
|
||||||
|
#define UART_IER_RtsInt 0x00000040 /* IrDA UART only */
|
||||||
|
#define UART_IER_CtsInt 0x00000080 /* IrDA UART only */
|
||||||
|
#define UART_IER_AllInts 0x000000ff
|
||||||
|
|
||||||
|
#define BAUD_115200 0x00000001
|
||||||
|
#define BAUD_57600 0x00000002
|
||||||
|
#define BAUD_38400 0x00000003
|
||||||
|
#define BAUD_19200 0x00000006
|
||||||
|
#define BAUD_9600 0x0000000C
|
||||||
|
#define BAUD_4800 0x00000018
|
||||||
|
#define BAUD_2400 0x00000030
|
||||||
|
#define BAUD_1200 0x00000060
|
||||||
|
|
||||||
|
#define MDR_UART_MODE 0x00000000 /* Both IrDA and Modem UARTs */
|
||||||
|
#define MDR_SIR_MODE 0x00000001 /* IrDA UART only */
|
||||||
|
#define MDR_AUTOBAUDING_MODE 0x00000002 /* Modem UART only */
|
||||||
|
#define MDR_RESET_MODE 0x00000007 /* Both IrDA and Modem UARTs */
|
||||||
|
|
||||||
|
/* SPI ******************************************************/
|
||||||
|
|
||||||
|
#define MAX_SPI 3
|
||||||
|
|
||||||
|
#define SPI_REGISTER_BASE 0xffff2000
|
||||||
|
|
||||||
|
/* GIO ******************************************************/
|
||||||
|
|
||||||
|
#define MAX_GIO (35)
|
||||||
|
|
||||||
|
#define GIO_REGISTER_BASE 0xffff2800
|
||||||
|
|
||||||
|
#define GPIO_IO 0xffff2800 /* Writeable when I/O is configured
|
||||||
|
* as an output; reads value on I/O
|
||||||
|
* pin when I/O is configured as an
|
||||||
|
* input */
|
||||||
|
#define GPIO_CIO 0xffff2804 /* GPIO configuration register */
|
||||||
|
#define GPIO_IRQA 0xffff2808 /* In conjunction with GPIO_IRQB
|
||||||
|
* determines the behavior when GPIO
|
||||||
|
* pins configured as input IRQ */
|
||||||
|
#define GPIO_IRQB 0xffff280c /* Determines the behavior when GPIO
|
||||||
|
* pins configured as input IRQ */
|
||||||
|
#define GPIO_DDIO 0xffff2810 /* Delta Detect Register
|
||||||
|
* (detects changes in the I/O pins) */
|
||||||
|
#define GPIO_EN 0xffff2814 /* Selects register for muxed GPIOs */
|
||||||
|
|
||||||
|
#define KGIO_REGISTER_BASE 0xffff2900
|
||||||
|
|
||||||
|
#define KBGPIO_IO 0xffff2900 /* Keyboard I/O bits: Writeable
|
||||||
|
* when KBGPIO is configured as an
|
||||||
|
* output; reads value on I/O pin
|
||||||
|
* when KBGPIO is configured as an
|
||||||
|
* input */
|
||||||
|
#define KBGPIO_CIO 0xffff2904 /* KBGPIO configuration register */
|
||||||
|
#define KBGPIO_IRQA 0xffff2908 /* In conjunction with KBGPIO_IRQB
|
||||||
|
* determines the behavior when
|
||||||
|
* KBGPIO pins configured as input
|
||||||
|
* IRQ */
|
||||||
|
#define KBGPIO_IRQB 0xffff290c /* In conjunction with KBGPIO_IRQA
|
||||||
|
* determines the behavior when
|
||||||
|
* KBGPIO pins configured as input
|
||||||
|
* IRQ */
|
||||||
|
#define KBGPIO_DDIO 0xffff2910 /* Delta Detect Register (detects
|
||||||
|
* changes in the KBGPIO pins) */
|
||||||
|
#define KBGPIO_EN 0xffff2914 /* Selects register for muxed
|
||||||
|
* KBGPIOs */
|
||||||
|
|
||||||
|
/* Timers ***************************************************/
|
||||||
|
|
||||||
|
#define C5471_TIMER0_CTRL 0xffff2a00
|
||||||
|
#define C5471_TIMER0_CNT 0xffff2a04
|
||||||
|
#define C5471_TIMER1_CTRL 0xffff2b00
|
||||||
|
#define C5471_TIMER1_CNT 0xffff2b04
|
||||||
|
#define C5471_TIMER2_CTRL 0xffff2c00
|
||||||
|
|
||||||
|
#define C5471_TIMER2_CNT 0xffff2c04
|
||||||
|
|
||||||
|
/* Interrupts */
|
||||||
|
|
||||||
|
#define HAVE_SRC_IRQ_BIN_REG 0
|
||||||
|
|
||||||
|
#define INT_FIRST_IO 0xffff2d00
|
||||||
|
#define INT_IO_RANGE 0x5C
|
||||||
|
|
||||||
|
#define IT_REG 0xffff2d00
|
||||||
|
#define MASK_IT_REG 0xffff2d04
|
||||||
|
#define SRC_IRQ_REG 0xffff2d08
|
||||||
|
#define SRC_FIQ_REG 0xffff2d0c
|
||||||
|
#define SRC_IRQ_BIN_REG 0xffff2d10
|
||||||
|
#define INT_CTRL_REG 0xffff2d18
|
||||||
|
|
||||||
|
#define ILR_IRQ0_REG 0xffff2d1C /* 0-Timer 0 */
|
||||||
|
#define ILR_IRQ1_REG 0xffff2d20 /* 1-Timer 1 */
|
||||||
|
#define ILR_IRQ2_REG 0xffff2d24 /* 2-Timer 2 */
|
||||||
|
#define ILR_IRQ3_REG 0xffff2d28 /* 3-GPIO0 */
|
||||||
|
#define ILR_IRQ4_REG 0xffff2d2c /* 4-Ethernet */
|
||||||
|
#define ILR_IRQ5_REG 0xffff2d30 /* 5-KBGPIO[7:0] */
|
||||||
|
#define ILR_IRQ6_REG 0xffff2d34 /* 6-Uart serial */
|
||||||
|
#define ILR_IRQ7_REG 0xffff2d38 /* 7-Uart IRDA */
|
||||||
|
#define ILR_IRQ8_REG 0xffff2d3c /* 8-KBGPIO[15:8] */
|
||||||
|
#define ILR_IRQ9_REG 0xffff2d40 /* 9-GPIO3 */
|
||||||
|
#define ILR_IRQ10_REG 0xffff2d44 /* 10-GPIO2 */
|
||||||
|
#define ILR_IRQ11_REG 0xffff2d48 /* 11-I2C */
|
||||||
|
#define ILR_IRQ12_REG 0xffff2d4c /* 12-GPIO1 */
|
||||||
|
#define ILR_IRQ13_REG 0xffff2d50 /* 13-SPI */
|
||||||
|
#define ILR_IRQ14_REG 0xffff2d54 /* 14-GPIO[19:4] */
|
||||||
|
#define ILR_IRQ15_REG 0xffff2d58 /* 15-API */
|
||||||
|
|
||||||
|
/* I2C ******************************************************/
|
||||||
|
|
||||||
|
#define MAX_I2C 1
|
||||||
|
|
||||||
|
/* API ******************************************************/
|
||||||
|
|
||||||
|
#define DSPRAM_BASE 0xffe00000 /* DSPRAM base address */
|
||||||
|
#define DSPRAM_END 0xffe03fff
|
||||||
|
|
||||||
|
/* This is the API address range in the DSP address space. */
|
||||||
|
|
||||||
|
#define DSPMEM_DSP_START 0x2000
|
||||||
|
#define DSPMEM_DSP_END 0x3fff
|
||||||
|
|
||||||
|
/* This is the API address range in the ARM address space. */
|
||||||
|
|
||||||
|
#define DSPMEM_ARM_START DSPRAM_BASE /* Defined in hardware.h */
|
||||||
|
#define DSPMEM_ARM_END DSPRAM_END
|
||||||
|
|
||||||
|
/* DSPMEM_IN_RANGE is a generic macro to test is a value is within
|
||||||
|
* a range of values.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DSPMEM_IN_RANGE(addr, start, end) \
|
||||||
|
((((__u32)(addr)) >= (start)) && (((__u32)(addr)) <= (end)))
|
||||||
|
|
||||||
|
/* DSPMEM_ADDR_ALIGNED verifies that a potential DSP address is
|
||||||
|
* properly word aligned.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DSPMEM_ADDR_ALIGNED(addr, cpu) ((((__u32)(addr)) & 1) == 0)
|
||||||
|
|
||||||
|
/* DSPMEM_DSP_ADDR checks if a DSP address lies in within the
|
||||||
|
* DSP's API address range.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DSPMEM_DSP_ADDR(addr, cpu) \
|
||||||
|
DSPMEM_IN_RANGE(addr, DSPMEM_DSP_START, DSPMEM_DSP_END)
|
||||||
|
|
||||||
|
/* DSPMEM_ARM_ADDR checks if a ARM address lies in within the
|
||||||
|
* ARM's API address range.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DSPMEM_ARM_ADDR(addr) \
|
||||||
|
DSPMEM_IN_RANGE(addr, DSPMEM_ARM_START, DSPMEM_ARM_END)
|
||||||
|
|
||||||
|
/* DSPMEM_DSP_TO_ARM maps a DSP API address into an ARM API address */
|
||||||
|
|
||||||
|
#define DSPMEM_DSP_TO_ARM(addr, cpu) \
|
||||||
|
((((__u32)(addr) - DSPMEM_DSP_START) << 1) + DSPMEM_ARM_START)
|
||||||
|
|
||||||
|
/* DSPMEM_ARM_TO_DSP maps an ARM API address into a DSP API address */
|
||||||
|
|
||||||
|
#define DSPMEM_ARM_TO_DSP(addr) \
|
||||||
|
((((__u32)(addr) - DSPMEM_ARM_START) >> 1) + DSPMEM_DSP_START)
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Inline Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
|
# define getreg8(a) (*(volatile ubyte *)(a))
|
||||||
|
# define putreg8(v,a) (*(volatile ubyte *)(a) = (v))
|
||||||
|
# define getreg32(a) (*(volatile uint32 *)(a))
|
||||||
|
# define putreg32(v,a) (*(volatile uint32 *)(a) = (v))
|
||||||
|
|
||||||
|
|
||||||
|
/* Some compiler options will convert short loads and stores into byte loads
|
||||||
|
* and stores. We don't want this to happen for IO reads and writes!
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* # define getreg16(a) (*(volatile uint16 *)(a)) */
|
||||||
|
static inline unsigned short getreg16(unsigned int addr)
|
||||||
|
{
|
||||||
|
unsigned short retval;
|
||||||
|
__asm__ __volatile__("\tldrh %0, [%1]\n\t" : "=r"(retval) : "r"(addr));
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* define putreg16(v,a) (*(volatile uint16 *)(a) = (v)) */
|
||||||
|
static inline void putreg16(uint16 val, unsigned int addr)
|
||||||
|
{
|
||||||
|
__asm__ __volatile__("\tstrh %0, [%1]\n\t": : "r"(val), "r"(addr));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Most C5471 registers are 16-bits wide */
|
||||||
|
|
||||||
|
#define getreg(a) getreg16(1)
|
||||||
|
#define putreg(v,a) putreg16(v,a)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __C5471_H */
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_assert.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_assert
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_assert(const ubyte *filename, uint32 lineno)
|
||||||
|
{
|
||||||
|
dbg("Assertion failed at file:%s line: %d\n",
|
||||||
|
filename, lineno);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_assert_code
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_assert_code(const ubyte *filename, uint32 lineno, uint16 errorcode)
|
||||||
|
{
|
||||||
|
dbg("Assertion failed at file:%s line: %d error code: %d\n",
|
||||||
|
filename, lineno, errorcode);
|
||||||
|
exit(errorcode);
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_blocktask.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_block_task
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* The currently executing task at the head of
|
||||||
|
* the ready to run list must be stopped. Save its context
|
||||||
|
* and move it to the inactive list specified by task_state.
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* tcb: Refers to a task in the ready-to-run list (normally
|
||||||
|
* the task at the 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(_TCB *tcb, tstate_t task_state)
|
||||||
|
{
|
||||||
|
/* Verify that the context switch can be performed */
|
||||||
|
|
||||||
|
if ((tcb->task_state < FIRST_READY_TO_RUN_STATE) ||
|
||||||
|
(tcb->task_state > LAST_READY_TO_RUN_STATE))
|
||||||
|
{
|
||||||
|
PANIC(OSERR_BADBLOCKSTATE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_TCB *rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
boolean switch_needed;
|
||||||
|
|
||||||
|
dbg("Blocking TCB=%p\n", tcb);
|
||||||
|
|
||||||
|
/* Remove the tcb task from the ready-to-run list. If we
|
||||||
|
* are blocking the task at the head of the task list (the
|
||||||
|
* most likely case), then a context switch to the next
|
||||||
|
* ready-to-run task is needed. In this case, it should
|
||||||
|
* also be true that rtcb == tcb.
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch_needed = sched_removereadytorun(tcb);
|
||||||
|
|
||||||
|
/* Add the task to the specified blocked task list */
|
||||||
|
|
||||||
|
sched_addblocked(tcb, (tstate_t)task_state);
|
||||||
|
|
||||||
|
/* If there are any pending tasks, then add them to the g_readytorun
|
||||||
|
* task list now
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (g_pendingtasks.head)
|
||||||
|
{
|
||||||
|
switch_needed |= sched_mergepending();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now, perform the context switch if one is needed */
|
||||||
|
|
||||||
|
if (switch_needed)
|
||||||
|
{
|
||||||
|
/* Are we in an interrupt handler? */
|
||||||
|
|
||||||
|
if (current_regs)
|
||||||
|
{
|
||||||
|
/* Yes, then we have to do things differently.
|
||||||
|
* Just copy the current_regs into the OLD rtcb.
|
||||||
|
*/
|
||||||
|
|
||||||
|
up_copystate(rtcb->xcp.regs, current_regs);
|
||||||
|
|
||||||
|
/* Restore the exception context of the rtcb at the (new) head
|
||||||
|
* of the g_readytorun task list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
dbg("New Active Task TCB=%p\n", rtcb);
|
||||||
|
|
||||||
|
/* Then switch contexts */
|
||||||
|
|
||||||
|
up_copystate(current_regs, rtcb->xcp.regs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy the user C context into the TCB at the (old) head of the
|
||||||
|
* g_readytorun Task list. if up_saveusercontext returns a non-zero
|
||||||
|
* value, then this is really the previously running task restarting!
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (!up_saveusercontext(rtcb->xcp.regs))
|
||||||
|
{
|
||||||
|
/* Restore the exception context of the rtcb at the (new) head
|
||||||
|
* of the g_readytorun task list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
dbg("New Active Task TCB=%p\n", rtcb);
|
||||||
|
|
||||||
|
/* Then switch contexts */
|
||||||
|
|
||||||
|
up_fullcontextrestore(rtcb->xcp.regs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_copystate.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_undefinedinsn
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* A little faster than most memcpy's */
|
||||||
|
|
||||||
|
void up_copystate(uint32 *dest, uint32 *src)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < XCPTCONTEST_REGS; i++)
|
||||||
|
{
|
||||||
|
*dest++ = *src++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_createstack.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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/kmalloc.h>
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Types
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Global Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_create_stack
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Allocate a stack for a new thread and setup
|
||||||
|
* up stack-related information in the TCB.
|
||||||
|
*
|
||||||
|
* The following TCB fields must be initialized:
|
||||||
|
* adj_stack_size: Stack size after adjustment for hardware,
|
||||||
|
* processor, etc. This value is retained only for debug
|
||||||
|
* purposes.
|
||||||
|
* stack_alloc_ptr: Pointer to allocated stack
|
||||||
|
* adj_stack_ptr: Adjusted StatckAllocPtr for HW. The
|
||||||
|
* initial value of the stack pointer.
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* tcb: The TCB of new task
|
||||||
|
* stack_size: The requested stack size. At least this much
|
||||||
|
* must be allocated.
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
STATUS up_create_stack(_TCB *tcb, uint32 stack_size)
|
||||||
|
{
|
||||||
|
if (tcb->stack_alloc_ptr &&
|
||||||
|
tcb->adj_stack_size != stack_size)
|
||||||
|
{
|
||||||
|
sched_free(tcb->stack_alloc_ptr);
|
||||||
|
tcb->stack_alloc_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tcb->stack_alloc_ptr)
|
||||||
|
{
|
||||||
|
tcb->stack_alloc_ptr = (uint32 *)kzmalloc(stack_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tcb->stack_alloc_ptr)
|
||||||
|
{
|
||||||
|
uint32 top_of_stack;
|
||||||
|
uint32 size_of_stack;
|
||||||
|
|
||||||
|
/* The Arm7Tdmi uses a push-down stack: the stack grows
|
||||||
|
* toward loweraddresses in memory. The stack pointer
|
||||||
|
* register, points to the lowest, valid work address
|
||||||
|
* (the "top" of the stack). Items on the stack are
|
||||||
|
* referenced as positive word offsets from sp.
|
||||||
|
*/
|
||||||
|
|
||||||
|
top_of_stack = (uint32)tcb->stack_alloc_ptr + stack_size - 4;
|
||||||
|
|
||||||
|
/* The Arm7Tdmi stack must be aligned at word (4 byte)
|
||||||
|
* boundaries. If necessary top_of_stack must be rounded
|
||||||
|
* down to the next boundary
|
||||||
|
*/
|
||||||
|
|
||||||
|
top_of_stack &= ~3;
|
||||||
|
size_of_stack = top_of_stack - (uint32)tcb->stack_alloc_ptr + 4;
|
||||||
|
|
||||||
|
/* Save the adjusted stack values in the _TCB */
|
||||||
|
|
||||||
|
tcb->adj_stack_size = top_of_stack;
|
||||||
|
tcb->adj_stack_size = size_of_stack;
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_dataabort.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_dataabort
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_dataabort(uint32 *regs)
|
||||||
|
{
|
||||||
|
PANIC(OSERR_ERREXCEPTION);
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_exit.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: _exit
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This function causes the currently executing task to cease
|
||||||
|
* to exist. This is a special case of task_delete().
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void _exit(int status)
|
||||||
|
{
|
||||||
|
_TCB* tcb = (_TCB*)g_readytorun.head;
|
||||||
|
|
||||||
|
dbg("TCB=%p exitting\n", tcb);
|
||||||
|
|
||||||
|
/* Remove the tcb task from the ready-to-run list. We can
|
||||||
|
* ignore the return value because we know that a context
|
||||||
|
* switch is needed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
(void)sched_removereadytorun(tcb);
|
||||||
|
|
||||||
|
/* Move the TCB to the specified blocked task list and delete it */
|
||||||
|
|
||||||
|
sched_addblocked(tcb, TSTATE_TASK_INACTIVE);
|
||||||
|
task_delete(tcb->pid);
|
||||||
|
|
||||||
|
/* If there are any pending tasks, then add them to the g_readytorun
|
||||||
|
* task list now
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (g_pendingtasks.head)
|
||||||
|
{
|
||||||
|
(void)sched_mergepending();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now, perform the context switch to the new ready-to-run task at the
|
||||||
|
* head of the list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
tcb = (_TCB*)g_readytorun.head;
|
||||||
|
dbg("New Active Task TCB=%p\n", tcb);
|
||||||
|
|
||||||
|
/* Then switch contexts */
|
||||||
|
|
||||||
|
up_fullcontextrestore(tcb->xcp.regs);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
* up_fullcontextrestore.S
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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/irq.h>
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Types
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Global Variables
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Variables
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Name: up_fullcontextrestore
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
.globl up_fullcontextrestore
|
||||||
|
.type up_fullcontextrestore, function
|
||||||
|
up_fullcontextrestore:
|
||||||
|
|
||||||
|
/* On entry, a1 (r0) holds address of the register save area */
|
||||||
|
|
||||||
|
/* Restore the volatile registers. This is not necessary for
|
||||||
|
* normally task-to-task context switches (where the context
|
||||||
|
* was saved by up_saveusercontext()), but is necesary when
|
||||||
|
* the full context was saved through interrupt handling.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Recover the user context (we will then have a new stack pointer) */
|
||||||
|
|
||||||
|
add r1, r0, #XCPTCONTEXT_UOFFSET
|
||||||
|
ldmia r1, {r3-r11, r13-r14}
|
||||||
|
|
||||||
|
/* Save the CSPR value and one scratch register on the stack */
|
||||||
|
|
||||||
|
sub sp, sp, #2*4 /* Create a frame to hold two regs */
|
||||||
|
stmia sp, {r3, r4} /* Save the CPSR (r3) and scratch (r4) */
|
||||||
|
|
||||||
|
/* Then recover the remaining registers */
|
||||||
|
|
||||||
|
ldmia r0, {r0-r3, r12} /* Recover volatile regs */
|
||||||
|
|
||||||
|
/* Now we can restore the CPSR (probably re-enabling interrupts) */
|
||||||
|
|
||||||
|
ldr r4, [sp]
|
||||||
|
msr cpsr, r4
|
||||||
|
|
||||||
|
/* Then recover the correct r4 value */
|
||||||
|
|
||||||
|
ldr r4, [sp, #4]
|
||||||
|
|
||||||
|
/* Destroy the temporary stack frame and return */
|
||||||
|
|
||||||
|
add sp, sp, #2*4
|
||||||
|
movs pc, lr
|
||||||
|
.size up_fullcontextrestore, . - up_fullcontextrestore
|
||||||
|
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_head.S
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "c5471.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* OS Entry Point
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* We assume the bootloader has already initialized most of the h/w for
|
||||||
|
* us and that only leaves us having to do some os specific things
|
||||||
|
* below.
|
||||||
|
*/
|
||||||
|
.global __start
|
||||||
|
.type __start, #function
|
||||||
|
__start:
|
||||||
|
|
||||||
|
/* First, setup initial processor mode */
|
||||||
|
|
||||||
|
mov r0, #(SVC_MODE | I_BIT | F_BIT )
|
||||||
|
msr cpsr, r0
|
||||||
|
|
||||||
|
/* Setup system stack (and get the BSS range) */
|
||||||
|
|
||||||
|
adr r0, LC0
|
||||||
|
ldmia r0, {r4, r5, sp}
|
||||||
|
|
||||||
|
/* Clear system BSS section */
|
||||||
|
|
||||||
|
mov r0, #0
|
||||||
|
1: cmp r4, r5
|
||||||
|
strcc r0, [r4], #4
|
||||||
|
bcc 1b
|
||||||
|
|
||||||
|
/* Copy system .data sections to new home in RAM. */
|
||||||
|
|
||||||
|
#ifdef CONFIG_BOOT_FROM_FLASH
|
||||||
|
|
||||||
|
adr r3, LC2
|
||||||
|
ldmia r3, {r0, r1, r2}
|
||||||
|
|
||||||
|
1: ldmia r0!, {r3 - r10}
|
||||||
|
stmia r1!, {r3 - r10}
|
||||||
|
cmp r1, r2
|
||||||
|
blt 1b
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Initialize Kernel Stack Contents */
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
mov r1, sp
|
||||||
|
sub r1, r1, #INITIAL_STACK_SIZE
|
||||||
|
ldr r0, L_STACK_MAGIC
|
||||||
|
str r0, [r1], #4
|
||||||
|
ldr r0, L_STACK_UNTOUCHED_MAGIC
|
||||||
|
1: cmp r1, sp
|
||||||
|
strcc r0, [r1], #4
|
||||||
|
bcc 1b
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Jump to OS entry */
|
||||||
|
|
||||||
|
mov fp, #0
|
||||||
|
b os_start
|
||||||
|
|
||||||
|
/* Variables */
|
||||||
|
|
||||||
|
LC0: .long _sbss
|
||||||
|
.long _ebss
|
||||||
|
.long CONFIG_STACK_POINTER+CONFIG_PROC_STACK_SIZE-4
|
||||||
|
|
||||||
|
#ifdef CONFIG_BOOT_FROM_FLASH
|
||||||
|
LC2: .long _eronly @ Where .data defaults are stored in Flash.
|
||||||
|
.long _sdata @ Where .data needs to reside in SDRAM.
|
||||||
|
.long _edata
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
L_STACK_UNTOUCHED_MAGIC: .long 0xfeef1ef0
|
||||||
|
L_STACK_MAGIC: .long 0xdeadbeef
|
||||||
|
#endif
|
||||||
|
.end
|
||||||
|
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_idle.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 <nuttx/arch.h>
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_initialize.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 <debug.h>
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Types
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Global 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 */
|
||||||
|
|
||||||
|
current_regs = NULL;
|
||||||
|
|
||||||
|
/* Initialize the interrupt subsystem */
|
||||||
|
|
||||||
|
up_irqinitialize();
|
||||||
|
|
||||||
|
/* Attach and enable the timer interrupt */
|
||||||
|
|
||||||
|
up_disable_irq(C5471_IRQ_SYSTIMER);
|
||||||
|
irq_attach(C5471_IRQ_SYSTIMER, (xcpt_t)up_timerisr);
|
||||||
|
up_enable_irq(C5471_IRQ_SYSTIMER);
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_initialstate.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 <string.h>
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* 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(_TCB *tcb)
|
||||||
|
{
|
||||||
|
struct xcptcontext *xcp = &tcb->xcp;
|
||||||
|
|
||||||
|
/* Initialize the initial exception register context structure */
|
||||||
|
|
||||||
|
memset(xcp, 0, sizeof(struct xcptcontext));
|
||||||
|
xcp->regs[JB_SP] = (uint32)tcb->adj_stack_ptr;
|
||||||
|
xcp->regs[JB_LR] = (uint32)tcb->start;
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_internal.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifndef __UP_INTERNAL_H
|
||||||
|
#define __UP_INTERNAL_H
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Types
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
typedef void (*up_vector_t)(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Variables
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
extern uint32 *current_regs;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Inline Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
|
/* Defined in files with the same name as the function */
|
||||||
|
|
||||||
|
extern void up_copystate(uint32 *dest, uint32 *src);
|
||||||
|
extern void up_dataabort(uint32 *regs);
|
||||||
|
extern void up_fullcontextrestore(uint32 *regs) __attribute__ ((noreturn));
|
||||||
|
extern void up_irqinitialize(void);
|
||||||
|
extern void up_prefetchabort(uint32 *regs);
|
||||||
|
extern int up_saveusercontext(uint32 *regs);
|
||||||
|
extern void up_sigdeliver(void);
|
||||||
|
extern void up_syscall(uint32 *regs);
|
||||||
|
extern int up_timerisr(int irq, uint32 *regs);
|
||||||
|
extern void up_undefinedinsn(uint32 *regs);
|
||||||
|
|
||||||
|
/* Defined in up_vectors.S */
|
||||||
|
|
||||||
|
extern void up_vectorundefinsn(void);
|
||||||
|
extern void up_vectorswi(void);
|
||||||
|
extern void up_vectorprefetch(void);
|
||||||
|
extern void up_vectordata(void);
|
||||||
|
extern void up_vectoraddrexcptn(void);
|
||||||
|
extern void up_vectorirq(void);
|
||||||
|
extern void up_vectorfiq(void);
|
||||||
|
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
|
||||||
|
#endif /* __UP_INTERNAL_H */
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_interruptcontext.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 <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.
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
boolean up_interrupt_context(void)
|
||||||
|
{
|
||||||
|
return current_regs != NULL;
|
||||||
|
}
|
||||||
@@ -0,0 +1,243 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_irq.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 <nuttx/irq.h>
|
||||||
|
#include "c5471.h"
|
||||||
|
#include "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#define EdgeSensitive 0x00000020
|
||||||
|
#define Priority 0x0000001E
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
uint32 *current_regs;
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* The value of _vflashstart is defined in ld.script. It
|
||||||
|
* could be hard-coded because we know that correct IRAM
|
||||||
|
* area is 0xffc00000.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int _svectors; /* Type does not matter */
|
||||||
|
|
||||||
|
/* The C5471 has FLASH at the low end of memory. The
|
||||||
|
* rrload bootloaer will catch all interrupts and re-vector
|
||||||
|
* them to vectors stored in IRAM. The following table is
|
||||||
|
* used to initialize those vectors.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static up_vector_t g_vectorinittab[] =
|
||||||
|
{
|
||||||
|
(up_vector_t)NULL,
|
||||||
|
up_vectorundefinsn,
|
||||||
|
up_vectorswi,
|
||||||
|
up_vectorprefetch,
|
||||||
|
up_vectordata,
|
||||||
|
up_vectoraddrexcptn,
|
||||||
|
up_vectorirq,
|
||||||
|
up_vectorfiq
|
||||||
|
};
|
||||||
|
#define NVECTORS ((sizeof(g_vectorinittab)) / sizeof(up_vector_t))
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_ackirq
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Acknowlede the IRQ.Bit 0 of the Interrupt Control
|
||||||
|
* Register == New IRQ agreement (NEW_IRQ_AGR). Reset IRQ
|
||||||
|
* output. Clear source IRQ register. Enables a new IRQ
|
||||||
|
* generation. Reset by internal logic.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
static inline void up_ackirq(unsigned int irq)
|
||||||
|
{
|
||||||
|
uint32 reg;
|
||||||
|
reg = getreg32(SRC_IRQ_REG); /* Insure appropriate IT_REG bit clears */
|
||||||
|
putreg32(reg | 0x00000001, INT_CTRL_REG); /* write the NEW_IRQ_AGR bit. */
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_ackfiq
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Acknowledge the FIQ. Bit 1 of the Interrupt Control
|
||||||
|
* Register == New FIQ agreement (NEW_FIQ_AGR). Reset FIQ
|
||||||
|
* output. Clear source FIQ register. Enables a new FIQ
|
||||||
|
* generation. Reset by internal logic.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
static inline void up_ackfiq(unsigned int irq)
|
||||||
|
{
|
||||||
|
uint32 reg;
|
||||||
|
reg = getreg32(SRC_FIQ_REG); /* Insure appropriate IT_REG bit clears */
|
||||||
|
putreg32(reg | 0x00000002, INT_CTRL_REG); /* write the NEW_FIQ_AGR bit. */
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_vectorinitialize
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
static inline void up_vectorinitialize(void)
|
||||||
|
{
|
||||||
|
up_vector_t *src = g_vectorinittab;
|
||||||
|
up_vector_t *dest = (up_vector_t*)&_svectors;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < NVECTORS; i++)
|
||||||
|
{
|
||||||
|
*dest++ = *src++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: irq_initialize
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_irqinitialize(void)
|
||||||
|
{
|
||||||
|
/* Disable all interrupts. */
|
||||||
|
|
||||||
|
putreg32(0x0000ffff, MASK_IT_REG);
|
||||||
|
|
||||||
|
/* Clear any pending interrupts */
|
||||||
|
|
||||||
|
up_ackirq(0);
|
||||||
|
up_ackfiq(0);
|
||||||
|
putreg32(0x00000000, IT_REG);
|
||||||
|
|
||||||
|
/* Override hardware defaults */
|
||||||
|
|
||||||
|
putreg32(EdgeSensitive | Priority, ILR_IRQ2_REG);
|
||||||
|
putreg32(EdgeSensitive | Priority, ILR_IRQ4_REG);
|
||||||
|
putreg32(Priority, ILR_IRQ6_REG);
|
||||||
|
putreg32(EdgeSensitive | Priority, ILR_IRQ15_REG);
|
||||||
|
|
||||||
|
/* Initialize hardware interrupt vectors */
|
||||||
|
|
||||||
|
up_vectorinitialize();
|
||||||
|
current_regs = NULL;
|
||||||
|
|
||||||
|
/* And finally, enable interrupts */
|
||||||
|
|
||||||
|
irqrestore(SVC_MODE | F_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_disable_irq
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Disable the IRQ specified by 'irq'
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_disable_irq(int irq)
|
||||||
|
{
|
||||||
|
if (irq < NR_IRQS)
|
||||||
|
{
|
||||||
|
uint32 reg = getreg32(MASK_IT_REG);
|
||||||
|
putreg32(reg | (1 << irq), MASK_IT_REG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_enable_irq
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Enable the IRQ specified by 'irq'
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_enable_irq(int irq)
|
||||||
|
{
|
||||||
|
if (irq < NR_IRQS)
|
||||||
|
{
|
||||||
|
uint32 reg = getreg32(MASK_IT_REG);
|
||||||
|
putreg32(reg & ~(1 << irq), MASK_IT_REG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_acknowledge_irq
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Disable the IRQ specified by 'irq'
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* Bit 0 of the Interrupt Control Rigster == New IRQ
|
||||||
|
* agreement (NEW_IRQ_AGR). Reset IRQ output. Clear source
|
||||||
|
* IRQ register. Enables a new IRQ generation. Reset by
|
||||||
|
* internal logic.
|
||||||
|
*
|
||||||
|
* IRQ (FIQ) output and SRC_IRQ_REG and SRC_IRQ_BIN_REG
|
||||||
|
* (SRC_FIQ_REG) registers are reset only if the bit in the
|
||||||
|
* Interrupt register (IT_REG) corresponding to the interrupt
|
||||||
|
* having requested MCU action is already cleared or masked.
|
||||||
|
*
|
||||||
|
* For an edge-sensitive interrupt, the Interrupt register bit is
|
||||||
|
* deactivated when reading the SRC_IRQ_REG or SRC_IRQ_BIN_REG
|
||||||
|
* (SRC_FIQ_REG) registers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void up_acknowledge_irq(int irq)
|
||||||
|
{
|
||||||
|
uint32 reg = getreg32(INT_CTRL_REG);
|
||||||
|
putreg32(reg | 0x00000001, INT_CTRL_REG); /* write the NEW_IRQ_AGR bit. */
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_prefetchabort.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 <nuttx/irq.h>
|
||||||
|
#include "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_prefetchabort
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_prefetchabort(uint32 *regs)
|
||||||
|
{
|
||||||
|
PANIC(OSERR_ERREXCEPTION);
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_releasepending.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_release_pending
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Release and ready-to-run tasks that have
|
||||||
|
* collected in the pending task list. This can call a
|
||||||
|
* context switch if a new task is placed at the head of
|
||||||
|
* the ready to run list.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_release_pending(void)
|
||||||
|
{
|
||||||
|
_TCB *rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
|
||||||
|
dbg("From TCB=%p\n", rtcb);
|
||||||
|
|
||||||
|
/* Merge the g_pendingtasks list into the g_readytorun task list */
|
||||||
|
|
||||||
|
/* sched_lock(); */
|
||||||
|
if (sched_mergepending())
|
||||||
|
{
|
||||||
|
/* The currently active task has changed! We will need to
|
||||||
|
* switch contexts. First check if we are operating in
|
||||||
|
* interrupt context:
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (current_regs)
|
||||||
|
{
|
||||||
|
/* Yes, then we have to do things differently.
|
||||||
|
* Just copy the current_regs into the OLD rtcb.
|
||||||
|
*/
|
||||||
|
|
||||||
|
up_copystate(rtcb->xcp.regs, current_regs);
|
||||||
|
|
||||||
|
/* Restore the exception context of the rtcb at the (new) head
|
||||||
|
* of the g_readytorun task list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
dbg("New Active Task TCB=%p\n", rtcb);
|
||||||
|
|
||||||
|
/* Then switch contexts */
|
||||||
|
|
||||||
|
up_copystate(current_regs, rtcb->xcp.regs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy the exception context into the TCB of the task that
|
||||||
|
* was currently active. if up_saveusercontext returns a non-zero
|
||||||
|
* value, then this is really the previously running task
|
||||||
|
* restarting!
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (!up_saveusercontext(rtcb->xcp.regs))
|
||||||
|
{
|
||||||
|
/* Restore the exception context of the rtcb at the (new) head
|
||||||
|
* of the g_readytorun task list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
dbg("New Active Task TCB=%p\n", rtcb);
|
||||||
|
|
||||||
|
/* Then switch contexts */
|
||||||
|
|
||||||
|
up_fullcontextrestore(rtcb->xcp.regs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_releasestack.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Types
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Global Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_release_stack
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* A task has been stopped. Free all stack
|
||||||
|
* related resources retained int the defunct TCB.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_release_stack(_TCB *dtcb)
|
||||||
|
{
|
||||||
|
if (dtcb->stack_alloc_ptr)
|
||||||
|
{
|
||||||
|
sched_free(dtcb->stack_alloc_ptr);
|
||||||
|
dtcb->stack_alloc_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dtcb->adj_stack_size = 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_reprioritizertr.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_reprioritize_rtr
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Called when the priority of a running or
|
||||||
|
* ready-to-run task changes and the reprioritization will
|
||||||
|
* cause a context switch. Two cases:
|
||||||
|
*
|
||||||
|
* 1) The priority of the currently running task drops and the next
|
||||||
|
* task in the ready to run list has priority.
|
||||||
|
* 2) An idle, ready to run task's priority has been raised above the
|
||||||
|
* the priority of the current, running task and it now has the
|
||||||
|
* priority.
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* tcb: The TCB of the task that has been reprioritized
|
||||||
|
* priority: The new task priority
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_reprioritize_rtr(_TCB *tcb, ubyte priority)
|
||||||
|
{
|
||||||
|
/* Verify that the caller is sane */
|
||||||
|
|
||||||
|
if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
|
||||||
|
tcb->task_state > LAST_READY_TO_RUN_STATE ||
|
||||||
|
priority < SCHED_PRIORITY_MIN ||
|
||||||
|
priority > SCHED_PRIORITY_MAX)
|
||||||
|
{
|
||||||
|
PANIC(OSERR_BADREPRIORITIZESTATE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_TCB *rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
boolean 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 = (ubyte)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 (current_regs)
|
||||||
|
{
|
||||||
|
/* Yes, then we have to do things differently.
|
||||||
|
* Just copy the current_regs into the OLD rtcb.
|
||||||
|
*/
|
||||||
|
|
||||||
|
up_copystate(rtcb->xcp.regs, current_regs);
|
||||||
|
|
||||||
|
/* Restore the exception context of the rtcb at the (new) head
|
||||||
|
* of the g_readytorun task list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
dbg("New Active Task TCB=%p\n", rtcb);
|
||||||
|
|
||||||
|
/* Then switch contexts */
|
||||||
|
|
||||||
|
up_copystate(current_regs, rtcb->xcp.regs);
|
||||||
|
}
|
||||||
|
/* Copy the exception context into the TCB at the (old) head of the
|
||||||
|
* g_readytorun Task list. if up_saveusercontext returns a non-zero
|
||||||
|
* value, then this is really the previously running task restarting!
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!up_saveusercontext(rtcb->xcp.regs))
|
||||||
|
{
|
||||||
|
/* Restore the exception context of the rtcb at the (new) head
|
||||||
|
* of the g_readytorun task list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
dbg("New Active Task TCB=%p\n", rtcb);
|
||||||
|
|
||||||
|
/* Then switch contexts */
|
||||||
|
|
||||||
|
up_fullcontextrestore(rtcb->xcp.regs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
* up_saveusercontext.S
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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/irq.h>
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Types
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Global Variables
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Variables
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Name: up_saveusercontext
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
.text
|
||||||
|
.globl up_saveusercontext
|
||||||
|
.type up_saveusercontext, function
|
||||||
|
up_saveusercontext:
|
||||||
|
/* On entry, a1 (r0) holds address of struct xcptcontext.
|
||||||
|
* Offset to the user region.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Make sure that the return value will be non-zero (the
|
||||||
|
* value of the other volatile registers don't matter --
|
||||||
|
* r1-r3, ip). This function is called throught the
|
||||||
|
* noraml C calling conventions and the values of these
|
||||||
|
* registers cannot be assumed at the point of setjmp
|
||||||
|
* return.
|
||||||
|
*/
|
||||||
|
|
||||||
|
mov ip, #1
|
||||||
|
str ip, [r0, #JB_R0]
|
||||||
|
|
||||||
|
/* Get the offset to the user save area */
|
||||||
|
|
||||||
|
add r0, r0, #XCPTCONTEXT_UOFFSET
|
||||||
|
|
||||||
|
/* Get the current cpsr as well */
|
||||||
|
|
||||||
|
mrs r3, cpsr /* R3 = CPSR value */
|
||||||
|
|
||||||
|
/* We need to save:
|
||||||
|
*
|
||||||
|
* Volatile register: r3 (holds the cpsr value)
|
||||||
|
* Static registers: v1-v7 (aka r4-r10)
|
||||||
|
* Frame pointer: fp (aka r11)
|
||||||
|
* Stack pointer: sp (aka r13)
|
||||||
|
* Return address: lr (aka r14)
|
||||||
|
*
|
||||||
|
* These have to be save in the same order as is done
|
||||||
|
* by the interrupt handling logic.
|
||||||
|
*/
|
||||||
|
|
||||||
|
stmia r0, {r3-r11, r13-r14}
|
||||||
|
|
||||||
|
/* Return 0 */
|
||||||
|
|
||||||
|
mov r0, #0 /* Return value == 0 */
|
||||||
|
mov pc, lr /* Return */
|
||||||
|
.size up_saveusercontext, . - up_saveusercontext
|
||||||
|
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_schedulesigaction.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
#include "c5471.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_schedule_sigaction
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This function is called by the OS when one or more
|
||||||
|
* signal handling actions have been queued for execution.
|
||||||
|
* The architecture specific code must configure things so
|
||||||
|
* that the 'igdeliver' callback is executed on the thread
|
||||||
|
* specified by 'tcb' as soon as possible.
|
||||||
|
*
|
||||||
|
* This function may be called from interrupt handling logic.
|
||||||
|
*
|
||||||
|
* This operation should not cause the task to be unblocked
|
||||||
|
* nor should it cause any immediate execution of sigdeliver.
|
||||||
|
* Typically, a few cases need to be considered:
|
||||||
|
*
|
||||||
|
* (1) This function may be called from an interrupt handler
|
||||||
|
* During interrupt processing, all xcptcontext structures
|
||||||
|
* should be valid for all tasks. That structure should
|
||||||
|
* be modified to invoke sigdeliver() either on return
|
||||||
|
* from (this) interrupt or on some subsequent context
|
||||||
|
* switch to the recipient task.
|
||||||
|
* (2) If not in an interrupt handler and the tcb is NOT
|
||||||
|
* the currently executing task, then again just modify
|
||||||
|
* the saved xcptcontext structure for the recipient
|
||||||
|
* task so it will invoke sigdeliver when that task is
|
||||||
|
* later resumed.
|
||||||
|
* (3) If not in an interrupt handler and the tcb IS the
|
||||||
|
* currently executing task -- just call the signal
|
||||||
|
* handler now.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver)
|
||||||
|
{
|
||||||
|
/* Refuse to handle nested signal actions */
|
||||||
|
|
||||||
|
if (!tcb->xcp.sigdeliver)
|
||||||
|
{
|
||||||
|
uint32 flags;
|
||||||
|
|
||||||
|
/* Make sure that interrupts are disabled */
|
||||||
|
|
||||||
|
flags = irqsave();
|
||||||
|
|
||||||
|
/* First, handle some special cases when the signal is
|
||||||
|
* being delivered to the currently executing task.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (tcb == (_TCB*)g_readytorun.head)
|
||||||
|
{
|
||||||
|
/* CASE 1: We are not in an interrupt handler and
|
||||||
|
* a task is signalling itself for some reason.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!current_regs)
|
||||||
|
{
|
||||||
|
/* In this case just deliver the signal now. */
|
||||||
|
|
||||||
|
sigdeliver(tcb);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CASE 2: We are in an interrupt handler AND the
|
||||||
|
* interrupted task is the same as the one that
|
||||||
|
* must receive the signal, then we will have to modify
|
||||||
|
* the return state as well as the state in the TCB.
|
||||||
|
*/
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Save the return lr and cpsr and one scratch register
|
||||||
|
* These will be restored by the signal trampoline after
|
||||||
|
* the signals have been delivered.
|
||||||
|
*/
|
||||||
|
|
||||||
|
tcb->xcp.sigdeliver = sigdeliver;
|
||||||
|
tcb->xcp.saved_lr = current_regs[JB_LR];
|
||||||
|
tcb->xcp.saved_cpsr = current_regs[JB_CPSR];
|
||||||
|
|
||||||
|
/* Then set up to vector to the trampoline with interrupts
|
||||||
|
* disabled
|
||||||
|
*/
|
||||||
|
|
||||||
|
current_regs[JB_LR] = (uint32)up_sigdeliver;
|
||||||
|
current_regs[JB_CPSR] = SVC_MODE | I_BIT | F_BIT;
|
||||||
|
|
||||||
|
/* And make sure that the saved context in the TCB
|
||||||
|
* is the same as the interrupt return context.
|
||||||
|
*/
|
||||||
|
|
||||||
|
up_copystate(tcb->xcp.regs, current_regs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, we are (1) signaling a task is not running
|
||||||
|
* from an interrupt handler or (2) we are not in an
|
||||||
|
* interrupt handler and the running task is signalling
|
||||||
|
* some non-running task.
|
||||||
|
*/
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Save the return lr and cpsr and one scratch register
|
||||||
|
* These will be restored by the signal trampoline after
|
||||||
|
* the signals have been delivered.
|
||||||
|
*/
|
||||||
|
|
||||||
|
tcb->xcp.sigdeliver = sigdeliver;
|
||||||
|
tcb->xcp.saved_lr = tcb->xcp.regs[JB_LR];
|
||||||
|
tcb->xcp.saved_cpsr = tcb->xcp.regs[JB_CPSR];
|
||||||
|
|
||||||
|
/* Then set up to vector to the trampoline with interrupts
|
||||||
|
* disabled
|
||||||
|
*/
|
||||||
|
|
||||||
|
tcb->xcp.regs[JB_LR] = (uint32)up_sigdeliver;
|
||||||
|
tcb->xcp.regs[JB_CPSR] = SVC_MODE | I_BIT | F_BIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
irqrestore(flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_sigdeliver.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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/irq.h>
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
#include "c5471.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_sigdeliver
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This is the a signal handling trampoline. When a
|
||||||
|
* signal action was posted. The task context was mucked
|
||||||
|
* with and forced to branch to this location with interrupts
|
||||||
|
* disabled.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_sigdeliver(void)
|
||||||
|
{
|
||||||
|
_TCB *rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
uint32 regs[XCPTCONTEST_REGS];
|
||||||
|
sig_deliver_t sigdeliver;
|
||||||
|
|
||||||
|
ASSERT(rtcb->xcp.sigdeliver);
|
||||||
|
|
||||||
|
/* Save the real return state on the stack. */
|
||||||
|
|
||||||
|
up_copystate(regs, rtcb->xcp.regs);
|
||||||
|
regs[JB_LR] = rtcb->xcp.saved_lr;
|
||||||
|
regs[JB_CPSR] = rtcb->xcp.saved_cpsr;
|
||||||
|
|
||||||
|
/* Get a local copy of the sigdeliver function pointer.
|
||||||
|
* we do this so that we can nullify the sigdeliver
|
||||||
|
* function point in the TCB and accept more signal
|
||||||
|
* deliveries while processing the current pending
|
||||||
|
* signals.
|
||||||
|
*/
|
||||||
|
|
||||||
|
sigdeliver = rtcb->xcp.sigdeliver;
|
||||||
|
rtcb->xcp.sigdeliver = NULL;
|
||||||
|
|
||||||
|
/* Then enable interrupts. We should still be safe from
|
||||||
|
* any further signal handling actions until we also
|
||||||
|
* nullify tcb->xcp.sigdeliver.
|
||||||
|
*/
|
||||||
|
|
||||||
|
irqrestore(SVC_MODE | F_BIT);
|
||||||
|
|
||||||
|
/* Deliver the signals */
|
||||||
|
|
||||||
|
sigdeliver(rtcb);
|
||||||
|
|
||||||
|
/* Then restore the correct state for this thread of
|
||||||
|
* execution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
up_fullcontextrestore(regs);
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_syscall.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "c5471.h"
|
||||||
|
#include "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* vectors
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_syscall
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* SWI interrupts will vection here with insn=the SWI
|
||||||
|
* instruction and xcp=the interrupt context
|
||||||
|
*
|
||||||
|
* The handler may get the SWI number be de-referencing
|
||||||
|
* the return address saved in the xcp and decoding
|
||||||
|
* the SWI instruction
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_syscall(uint32 *regs)
|
||||||
|
{
|
||||||
|
PANIC(OSERR_ERREXCEPTION);
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_timerisr.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 <debug.h>
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Types
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Global Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Function: timer_isr
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* The timer ISR will perform a variety of services for
|
||||||
|
* various portions of the systems.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
int up_timerisr(int irq, uint32 *regs)
|
||||||
|
{
|
||||||
|
uint32 *saved_regs;
|
||||||
|
|
||||||
|
/* Save the pointer to the interrupted context (exercising some
|
||||||
|
* logic for the unexpected case of nested interrupts).
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!current_regs)
|
||||||
|
{
|
||||||
|
saved_regs = NULL;
|
||||||
|
current_regs = regs;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saved_regs = current_regs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process timer interrupt */
|
||||||
|
|
||||||
|
sched_process_timer();
|
||||||
|
|
||||||
|
/* Restore the previous context */
|
||||||
|
|
||||||
|
current_regs = saved_regs;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_unblocktask.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_unblock_task
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* A task is currently in an inactive task list
|
||||||
|
* but has been prepped to execute. Move the TCB to the
|
||||||
|
* ready-to-run list, restore its context, and start execution.
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* tcb: Refers to the tcb to be unblocked. This tcb is
|
||||||
|
* in one of the waiting tasks lists. It must be moved to
|
||||||
|
* the ready-to-run list and, if it is the highest priority
|
||||||
|
* ready to run taks, executed.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_unblock_task(_TCB *tcb)
|
||||||
|
{
|
||||||
|
/* Verify that the context switch can be performed */
|
||||||
|
if ((tcb->task_state < FIRST_BLOCKED_STATE) ||
|
||||||
|
(tcb->task_state > LAST_BLOCKED_STATE))
|
||||||
|
{
|
||||||
|
PANIC(OSERR_BADUNBLOCKSTATE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_TCB *rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
|
||||||
|
dbg("Unblocking TCB=%p\n", tcb);
|
||||||
|
|
||||||
|
/* Remove the task from the blocked task list */
|
||||||
|
|
||||||
|
sched_removeblocked(tcb);
|
||||||
|
|
||||||
|
/* Reset its timeslice. This is only meaningful for round
|
||||||
|
* robin tasks but it doesn't here to do it for everything
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if CONFIG_RR_INTERVAL > 0
|
||||||
|
tcb->timeslice = CONFIG_RR_INTERVAL;
|
||||||
|
#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 (current_regs)
|
||||||
|
{
|
||||||
|
/* Yes, then we have to do things differently.
|
||||||
|
* Just copy the current_regs into the OLD rtcb.
|
||||||
|
*/
|
||||||
|
|
||||||
|
up_copystate(rtcb->xcp.regs, current_regs);
|
||||||
|
|
||||||
|
/* Restore the exception context of the rtcb at the (new) head
|
||||||
|
* of the g_readytorun task list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
dbg("New Active Task TCB=%p\n", rtcb);
|
||||||
|
|
||||||
|
/* Then switch contexts */
|
||||||
|
|
||||||
|
up_copystate(current_regs, rtcb->xcp.regs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We are not in an interrupt andler. Copy the user C context
|
||||||
|
* into the TCB of the task that was previously active. if
|
||||||
|
* up_saveusercontext returns a non-zero value, then this is really the
|
||||||
|
* previously running task restarting!
|
||||||
|
*/
|
||||||
|
|
||||||
|
else if (!up_saveusercontext(rtcb->xcp.regs))
|
||||||
|
{
|
||||||
|
/* 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 = (_TCB*)g_readytorun.head;
|
||||||
|
dbg("New Active Task TCB=%p\n", rtcb);
|
||||||
|
|
||||||
|
/* Then switch contexts */
|
||||||
|
|
||||||
|
up_fullcontextrestore(rtcb->xcp.regs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_undefinedinsn.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_undefinedinsn
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_undefinedinsn(uint32 *regs)
|
||||||
|
{
|
||||||
|
PANIC(OSERR_UNDEFINEDINSN);
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_usestack.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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/kmalloc.h>
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Types
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Global Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_use_stack
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Setup up stack-related information in the TCB
|
||||||
|
* using pre-allocated stack memory
|
||||||
|
*
|
||||||
|
* The following TCB fields must be initialized:
|
||||||
|
* adj_stack_size: Stack size after adjustment for hardware,
|
||||||
|
* processor, etc. This value is retained only for debug
|
||||||
|
* purposes.
|
||||||
|
* stack_alloc_ptr: Pointer to allocated stack
|
||||||
|
* adj_stack_ptr: Adjusted StatckAllocPtr for HW. The
|
||||||
|
* initial value of the stack pointer.
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* tcb: The TCB of new task
|
||||||
|
* stack_size: The allocated stack size.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
STATUS up_use_stack(_TCB *tcb, uint32 *stack, uint32 stack_size)
|
||||||
|
{
|
||||||
|
uint32 top_of_stack;
|
||||||
|
uint32 size_of_stack;
|
||||||
|
|
||||||
|
if (tcb->stack_alloc_ptr)
|
||||||
|
{
|
||||||
|
sched_free(tcb->stack_alloc_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save the stack allocation */
|
||||||
|
|
||||||
|
tcb->stack_alloc_ptr = stack;
|
||||||
|
|
||||||
|
/* The Arm7Tdmi uses a push-down stack: the stack grows
|
||||||
|
* toward loweraddresses in memory. The stack pointer
|
||||||
|
* register, points to the lowest, valid work address
|
||||||
|
* (the "top" of the stack). Items on the stack are
|
||||||
|
* referenced as positive word offsets from sp.
|
||||||
|
*/
|
||||||
|
|
||||||
|
top_of_stack = (uint32)tcb->stack_alloc_ptr + stack_size - 4;
|
||||||
|
|
||||||
|
/* The Arm7Tdmi stack must be aligned at word (4 byte)
|
||||||
|
* boundaries. If necessary top_of_stack must be rounded
|
||||||
|
* down to the next boundary
|
||||||
|
*/
|
||||||
|
|
||||||
|
top_of_stack &= ~3;
|
||||||
|
size_of_stack = top_of_stack - (uint32)tcb->stack_alloc_ptr + 4;
|
||||||
|
|
||||||
|
/* Save the adjusted stack values in the _TCB */
|
||||||
|
|
||||||
|
tcb->adj_stack_size = top_of_stack;
|
||||||
|
tcb->adj_stack_size = size_of_stack;
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
@@ -0,0 +1,449 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_vectors.S
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "c5471.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Global Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
.data
|
||||||
|
up_irqtmp:
|
||||||
|
.word 0 /* Saved lr */
|
||||||
|
.word 0 /* Saved spsr */
|
||||||
|
up_undeftmp:
|
||||||
|
.word 0 /* Saved lr */
|
||||||
|
.word 0 /* Saved spsr */
|
||||||
|
up_aborttmp:
|
||||||
|
.word 0 /* Saved lr */
|
||||||
|
.word 0 /* Saved spsr */
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Macros
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
.text
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
.text
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_vectorirq
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Interrupt excetpion. Entered in IRQ mode with spsr = SVC
|
||||||
|
* CPSR, lr = SVC PC
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
.global up_vectorirq
|
||||||
|
.type up_vectorirq, %function
|
||||||
|
up_vectorirq:
|
||||||
|
/* On entry, we are in IRQ mode. We are free to use
|
||||||
|
* the IRQ mode r13 and r14.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
ldr r13, .Lirqtmp
|
||||||
|
sub lr, lr, #4
|
||||||
|
str lr, [r13] @ save lr_IRQ
|
||||||
|
mrs lr, spsr
|
||||||
|
str lr, [r13, #4] @ save spsr_IRQ
|
||||||
|
|
||||||
|
/* Then switch back to SVC mode */
|
||||||
|
|
||||||
|
bic lr, lr, #MODE_MASK /* Keep F and T bits */
|
||||||
|
orr lr, lr, #I_BIT | SVC_MODE
|
||||||
|
msr spsr_c, lr /* Swith to SVC mode */
|
||||||
|
|
||||||
|
/* Create a context structure */
|
||||||
|
|
||||||
|
sub sp, sp, #XCPTCONTEXT_SIZE
|
||||||
|
stmia sp, {r0-r3, r12} /* Save volatile regs */
|
||||||
|
ldr r0, .Lirqtmp /* Points to temp storage */
|
||||||
|
ldr lr, [r0] /* Recover lr */
|
||||||
|
ldr r3, [r0, $4] /* Recover SPSR */
|
||||||
|
add r1, sp, #XCPTCONTEXT_UOFFSET
|
||||||
|
stmia r1, {r3-r11, r13-r14} /* Save SPSR+r4-r11+lr+sp */
|
||||||
|
|
||||||
|
/* Now decode the interrupt */
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
ldr lr, =SRC_IRQ_BIN_REG /* Fetch encoded IRQ */
|
||||||
|
ldr r0, [lr]
|
||||||
|
and r0, r0, #0x0f /* Valid range is 0..15 */
|
||||||
|
|
||||||
|
/* Problems here... cannot read SRC_IRQ_BIN_REQ (and/or
|
||||||
|
* SRC_IRQ_REQ because this will clear edge triggered
|
||||||
|
* interrupts. Plus, no way to validate spurious
|
||||||
|
* interrupt.
|
||||||
|
*/
|
||||||
|
#else
|
||||||
|
ldr r6, =SRC_IRQ_REG
|
||||||
|
ldr r6, [r6] /* Get source IRQ reg */
|
||||||
|
mov r0, #0 /* Assume IRQ0_IRQ set */
|
||||||
|
.Lmorebits:
|
||||||
|
tst r6, #1 /* Is IRQ set? */
|
||||||
|
bne .Lhaveirq /* Yes... we have the IRQ */
|
||||||
|
add r0, r0, #1 /* Setup next IRQ */
|
||||||
|
mov r6, r6, lsr #1 /* Shift right one */
|
||||||
|
cmp r0, #16 /* Only 16 valid bits */
|
||||||
|
bcc .Lmorebits /* Keep until we have looked
|
||||||
|
* at all bits */
|
||||||
|
b .Lnoirqset /* If we get here, there is
|
||||||
|
* no pending interrupt */
|
||||||
|
.Lhaveirq:
|
||||||
|
#endif
|
||||||
|
/* Then call the data abort handler with interrupt disabled.
|
||||||
|
* rq_dispatch(int irq, struct xcptcontext *xcp)
|
||||||
|
*/
|
||||||
|
|
||||||
|
mov fp, #0 /* Init frame pointer */
|
||||||
|
mov r1, sp /* Get r1=xcp */
|
||||||
|
bl up_prefetchabort /* Call the handler */
|
||||||
|
|
||||||
|
/* Recover the SVC_MODE registers */
|
||||||
|
.Lnoirqset:
|
||||||
|
add r0, sp, #XCPTCONTEXT_UOFFSET
|
||||||
|
ldmia r0, {r3-r11, r13-r14}
|
||||||
|
msr spsr, r3
|
||||||
|
ldmia sp, {r0-r3, r12} /* recover volatile regs */
|
||||||
|
add sp, sp, #XCPTCONTEXT_SIZE
|
||||||
|
movs pc, lr /* return & move spsr into cpsr */
|
||||||
|
|
||||||
|
@
|
||||||
|
@ now branch to the relevent MODE handling routine
|
||||||
|
@
|
||||||
|
|
||||||
|
and lr, lr, #15
|
||||||
|
ldr lr, [pc, lr, lsl #2]
|
||||||
|
movs pc, lr @ Changes mode and branches
|
||||||
|
|
||||||
|
.Lirqtmp:
|
||||||
|
.word up_irqtmp
|
||||||
|
|
||||||
|
.align 5
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Function: up_vectorswi
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* SWI interrupt. We enter the SWI in SVC mode
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
.align 5
|
||||||
|
.global up_vectorswi
|
||||||
|
.type up_vectorswi, %function
|
||||||
|
up_vectorswi:
|
||||||
|
|
||||||
|
/* The c547x rrload bootloader intemediates all
|
||||||
|
* interrupts. For the* case of the SWI, it mucked
|
||||||
|
* with the stack to create some temporary registers.
|
||||||
|
* We'll have to recover from this mucking here.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ldr r14, [sp,#-0x4] /* rrload workaround */
|
||||||
|
|
||||||
|
/* Create a context structure */
|
||||||
|
|
||||||
|
sub sp, sp, #XCPTCONTEXT_SIZE
|
||||||
|
stmia sp, {r0-r3, r12} /* Save volatile regs */
|
||||||
|
mrs r3, spsr /* Get r3=interrupted CPSR */
|
||||||
|
add r0, sp, #XCPTCONTEXT_UOFFSET
|
||||||
|
stmia r0, {r3-r11, r13-r14} /* Save CPSR+r4-r11+lr+sp */
|
||||||
|
|
||||||
|
/* Then call the SWI handler with interrupt disabled.
|
||||||
|
* void up_syscall(struct xcptcontext *xcp)
|
||||||
|
*/
|
||||||
|
|
||||||
|
mov fp, #0 /* Init frame pointer */
|
||||||
|
mov r0, sp /* Get r0=xcp */
|
||||||
|
bl up_syscall /* Call the handler */
|
||||||
|
|
||||||
|
.LignoreSWI:
|
||||||
|
/* Recover the SVC_MODE registers */
|
||||||
|
|
||||||
|
add r0, sp, #XCPTCONTEXT_UOFFSET
|
||||||
|
ldmia r0, {r3-r11, r13-r14}
|
||||||
|
msr spsr, r3
|
||||||
|
ldmia sp, {r0-r3, r12} /* recover volatile regs */
|
||||||
|
add sp, sp, #XCPTCONTEXT_SIZE
|
||||||
|
movs pc, lr /* return & move spsr into cpsr */
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_vectordata
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Data abort Exception dispatcher. Give control to data
|
||||||
|
* abort handler. This function is entered in ABORT mode
|
||||||
|
* with spsr = SVC CPSR, lr = SVC PC
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
.text
|
||||||
|
.global up_vectordata
|
||||||
|
.type up_vectordata, %function
|
||||||
|
up_vectordata:
|
||||||
|
/* On entry we are free to use the ABORT mode registers
|
||||||
|
* r13 and r14
|
||||||
|
*/
|
||||||
|
|
||||||
|
ldr r13, .Ldaborttmp /* Points to temp storage */
|
||||||
|
sub lr, lr, #8 /* Fixup return */
|
||||||
|
str lr, [r13] /* Save in temp storage */
|
||||||
|
mrs lr, spsr /* Get SPSR */
|
||||||
|
str lr, [r13, #4] /* Save in temp storage */
|
||||||
|
|
||||||
|
/* Then switch back to SVC mode */
|
||||||
|
|
||||||
|
bic lr, lr, #MODE_MASK /* Keep F and T bits */
|
||||||
|
orr lr, lr, #I_BIT | SVC_MODE
|
||||||
|
msr spsr_c, lr /* Swith to SVC mode */
|
||||||
|
|
||||||
|
/* Create a context structure */
|
||||||
|
|
||||||
|
sub sp, sp, #XCPTCONTEXT_SIZE
|
||||||
|
stmia sp, {r0-r3, r12} /* Save volatile regs */
|
||||||
|
ldr r0, .Ldaborttmp /* Points to temp storage */
|
||||||
|
ldr lr, [r0] /* Recover lr */
|
||||||
|
ldr r3, [r0, $4] /* Recover SPSR */
|
||||||
|
add r1, sp, #XCPTCONTEXT_UOFFSET
|
||||||
|
stmia r1, {r3-r11, r13-r14} /* Save SPSR+r4-r11+lr+sp */
|
||||||
|
|
||||||
|
/* Then call the data abort handler with interrupt disabled.
|
||||||
|
* void up_dataabort(struct xcptcontext *xcp)
|
||||||
|
*/
|
||||||
|
|
||||||
|
mov fp, #0 /* Init frame pointer */
|
||||||
|
mov r0, sp /* Get r0=xcp */
|
||||||
|
bl up_dataabort /* Call the handler */
|
||||||
|
|
||||||
|
/* Recover the SVC_MODE registers */
|
||||||
|
|
||||||
|
add r0, sp, #XCPTCONTEXT_UOFFSET
|
||||||
|
ldmia r0, {r3-r11, r13-r14}
|
||||||
|
msr spsr, r3
|
||||||
|
ldmia sp, {r0-r3, r12} /* recover volatile regs */
|
||||||
|
add sp, sp, #XCPTCONTEXT_SIZE
|
||||||
|
movs pc, lr /* return & move spsr into cpsr */
|
||||||
|
|
||||||
|
@
|
||||||
|
@ now branch to the relevent MODE handling routine
|
||||||
|
@
|
||||||
|
|
||||||
|
and lr, lr, #15
|
||||||
|
ldr lr, [pc, lr, lsl #2]
|
||||||
|
movs pc, lr @ Changes mode and branches
|
||||||
|
|
||||||
|
.Ldaborttmp:
|
||||||
|
.word up_aborttmp
|
||||||
|
|
||||||
|
.align 5
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_vectorprefetch
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Prefetch abort exception. Entered in ABT mode with
|
||||||
|
* spsr = SVC CPSR, lr = SVC PC
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
.global up_vectorprefetch
|
||||||
|
.type up_vectorprefetch, %function
|
||||||
|
up_vectorprefetch:
|
||||||
|
/* On entry we are free to use the ABORT mode registers
|
||||||
|
* r13 and r14
|
||||||
|
*/
|
||||||
|
|
||||||
|
ldr r13, .Lpaborttmp /* Points to temp storage */
|
||||||
|
sub lr, lr, #4 /* Fixup return */
|
||||||
|
str lr, [r13] /* Save in temp storage */
|
||||||
|
mrs lr, spsr /* Get SPSR */
|
||||||
|
str lr, [r13, #4] /* Save in temp storage */
|
||||||
|
|
||||||
|
/* Then switch back to SVC mode */
|
||||||
|
|
||||||
|
bic lr, lr, #MODE_MASK /* Keep F and T bits */
|
||||||
|
orr lr, lr, #I_BIT | SVC_MODE
|
||||||
|
msr spsr_c, lr /* Swith to SVC mode */
|
||||||
|
|
||||||
|
/* Create a context structure */
|
||||||
|
|
||||||
|
sub sp, sp, #XCPTCONTEXT_SIZE
|
||||||
|
stmia sp, {r0-r3, r12} /* Save volatile regs */
|
||||||
|
ldr r0, .Lpaborttmp /* Points to temp storage */
|
||||||
|
ldr lr, [r0] /* Recover lr */
|
||||||
|
ldr r3, [r0, $4] /* Recover SPSR */
|
||||||
|
add r1, sp, #XCPTCONTEXT_UOFFSET
|
||||||
|
stmia r1, {r3-r11, r13-r14} /* Save SPSR+r4-r11+lr+sp */
|
||||||
|
|
||||||
|
/* Then call the data abort handler with interrupt disabled.
|
||||||
|
* void up_prefetchabort(struct xcptcontext *xcp)
|
||||||
|
*/
|
||||||
|
|
||||||
|
mov fp, #0 /* Init frame pointer */
|
||||||
|
mov r0, sp /* Get r0=xcp */
|
||||||
|
bl up_prefetchabort /* Call the handler */
|
||||||
|
|
||||||
|
/* Recover the SVC_MODE registers */
|
||||||
|
|
||||||
|
add r0, sp, #XCPTCONTEXT_UOFFSET
|
||||||
|
ldmia r0, {r3-r11, r13-r14}
|
||||||
|
msr spsr, r3
|
||||||
|
ldmia sp, {r0-r3, r12} /* recover volatile regs */
|
||||||
|
add sp, sp, #XCPTCONTEXT_SIZE
|
||||||
|
movs pc, lr /* return & move spsr into cpsr */
|
||||||
|
|
||||||
|
@
|
||||||
|
@ now branch to the relevent MODE handling routine
|
||||||
|
@
|
||||||
|
|
||||||
|
and lr, lr, #15
|
||||||
|
ldr lr, [pc, lr, lsl #2]
|
||||||
|
movs pc, lr @ Changes mode and branches
|
||||||
|
|
||||||
|
.Lpaborttmp:
|
||||||
|
.word up_aborttmp
|
||||||
|
|
||||||
|
.align 5
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_vectorundefinsn
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Undefined instruction entry exception. Entered in
|
||||||
|
* UND mode, spsr = SVC CPSR, lr = SVC PC
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
.global up_vectorundefinsn
|
||||||
|
.type up_vectorundefinsn, %function
|
||||||
|
up_vectorundefinsn:
|
||||||
|
/* On entry we are free to use the UND mode registers
|
||||||
|
* r13 and r14
|
||||||
|
*/
|
||||||
|
|
||||||
|
ldr r13, .Lundeftmp /* Points to temp storage */
|
||||||
|
str lr, [r13] /* Save in temp storage */
|
||||||
|
mrs lr, spsr /* Get SPSR */
|
||||||
|
str lr, [r13, #4] /* Save in temp storage */
|
||||||
|
|
||||||
|
/* Then switch back to SVC mode */
|
||||||
|
|
||||||
|
bic lr, lr, #MODE_MASK /* Keep F and T bits */
|
||||||
|
orr lr, lr, #I_BIT | SVC_MODE
|
||||||
|
msr spsr_c, lr /* Swith to SVC mode */
|
||||||
|
|
||||||
|
/* Create a context structure */
|
||||||
|
|
||||||
|
sub sp, sp, #XCPTCONTEXT_SIZE
|
||||||
|
stmia sp, {r0-r3, r12} /* Save volatile regs */
|
||||||
|
ldr r0, .Lundeftmp /* Points to temp storage */
|
||||||
|
ldr lr, [r0] /* Recover lr */
|
||||||
|
ldr r3, [r0, $4] /* Recover SPSR */
|
||||||
|
add r1, sp, #XCPTCONTEXT_UOFFSET
|
||||||
|
stmia r1, {r3-r11, r13-r14} /* Save SPSR+r4-r11+lr+sp */
|
||||||
|
|
||||||
|
/* Then call the data abort handler with interrupt disabled.
|
||||||
|
* void up_undefinedinsn(struct xcptcontext *xcp)
|
||||||
|
*/
|
||||||
|
|
||||||
|
mov fp, #0 /* Init frame pointer */
|
||||||
|
mov r0, sp /* Get r0=xcp */
|
||||||
|
bl up_undefinedinsn /* Call the handler */
|
||||||
|
|
||||||
|
/* Recover the SVC_MODE registers */
|
||||||
|
|
||||||
|
add r0, sp, #XCPTCONTEXT_UOFFSET
|
||||||
|
ldmia r0, {r3-r11, r13-r14}
|
||||||
|
msr spsr, r3
|
||||||
|
ldmia sp, {r0-r3, r12} /* recover volatile regs */
|
||||||
|
add sp, sp, #XCPTCONTEXT_SIZE
|
||||||
|
movs pc, lr /* return & move spsr into cpsr */
|
||||||
|
|
||||||
|
@
|
||||||
|
@ now branch to the relevent MODE handling routine
|
||||||
|
@
|
||||||
|
|
||||||
|
and lr, lr, #15
|
||||||
|
ldr lr, [pc, lr, lsl #2]
|
||||||
|
movs pc, lr @ Changes mode and branches
|
||||||
|
|
||||||
|
.Lundeftmp:
|
||||||
|
.word up_undeftmp
|
||||||
|
|
||||||
|
.align 5
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_vectorfiq
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Shouldn't happen
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
.global up_vectorfiq
|
||||||
|
.type up_vectorfiq, %function
|
||||||
|
up_vectorfiq:
|
||||||
|
subs pc, lr, #4
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_vectoraddrexcption
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Shouldn't happen
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
.global up_vectoraddrexcptn
|
||||||
|
.type up_vectoraddrexcptn, %function
|
||||||
|
up_vectoraddrexcptn:
|
||||||
|
b up_vectoraddrexcptn
|
||||||
|
.end
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
############################################################
|
||||||
|
# Make.defs
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
include ${TOPDIR}/.config
|
||||||
|
|
||||||
|
ifeq ("${CONFIG_DEBUG}","y")
|
||||||
|
ARCHOPTIMIZATION = -g
|
||||||
|
else
|
||||||
|
ARCHOPTIMIZATION = -O2
|
||||||
|
endif
|
||||||
|
|
||||||
|
ARCHCPUFLAGS =
|
||||||
|
ARCHPICFLAGS = -fpic
|
||||||
|
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow
|
||||||
|
ARCHDEFINES =
|
||||||
|
ARCHINCLUDES = -I. -isystem $(TOPDIR)/include
|
||||||
|
ARCHSCRIPT =
|
||||||
|
|
||||||
|
CROSSDEV =
|
||||||
|
CC = $(CROSSDEV)gcc
|
||||||
|
LD = $(CROSSDEV)ld
|
||||||
|
AR = $(CROSSDEV)ar
|
||||||
|
NM = $(CROSSDEV)nm
|
||||||
|
OBJCOPY = $(CROSSDEV)objcopy
|
||||||
|
OBJDUMP = $(CROSSDEV)objdump
|
||||||
|
|
||||||
|
CFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \
|
||||||
|
$(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) -pipe
|
||||||
|
|
||||||
|
LDFLAGS = $(ARCHSCRIPT)
|
||||||
|
EXTRA_LIBS = -lc
|
||||||
|
|
||||||
|
ifeq ("${CONFIG_DEBUG}","y")
|
||||||
|
LDFLAGS += -g
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
############################################################
|
||||||
|
# defconfig
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
#
|
||||||
|
# architecture selection
|
||||||
|
#
|
||||||
|
# CONFIG_ARCH - identifies the arch subdirectory
|
||||||
|
# CONFIG_ARCH_name - for use in C code
|
||||||
|
#
|
||||||
|
CONFIG_ARCH=sim
|
||||||
|
CONFIG_ARCH_SIM=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# General OS setup
|
||||||
|
#
|
||||||
|
# CONFIG_EXAMPLE - identifies the subdirectgory in examples
|
||||||
|
# that will be used in the build
|
||||||
|
# CONFIG_DEBUG - enables built-in debug options
|
||||||
|
# CONFIG_DEBUG_VERBOSE - enables verbose debug output
|
||||||
|
# CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot
|
||||||
|
# time console output
|
||||||
|
# CONFIG_RR_INTERVAL - The round robin timeslice will be set
|
||||||
|
# this number of milliseconds; Round robin scheduling can
|
||||||
|
# be disabled by setting this value to zero.
|
||||||
|
# CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in
|
||||||
|
# scheduler to monitor system performance
|
||||||
|
# CONFIG_TASK_NAME_SIZE - Spcifies that maximum size of a
|
||||||
|
# task name to save in the TCB. Useful if scheduler
|
||||||
|
# instrumentation is selected. Set to zero to disable.
|
||||||
|
# CONFIG_JULIAN_TIME - Enables Julian time conversions
|
||||||
|
# CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
|
||||||
|
# Used to initialize the internal time logic.
|
||||||
|
# CONFIG_DEV_CONSOLE - Set if architecture-specific logic
|
||||||
|
# provides /dev/console. Enables stdout, stderr, stdin.
|
||||||
|
#
|
||||||
|
CONFIG_EXAMPLE=ostest
|
||||||
|
CONFIG_DEBUG=y
|
||||||
|
CONFIG_DEBUG_VERBOSE=y
|
||||||
|
CONFIG_ARCH_LOWPUTC=y
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_SCHED_INSTRUMENTATION=n
|
||||||
|
CONFIG_TASK_NAME_SIZE=32
|
||||||
|
CONFIG_START_YEAR=2007
|
||||||
|
CONFIG_START_MONTH=2
|
||||||
|
CONFIG_START_DAY=13
|
||||||
|
CONFIG_JULIAN_TIME=n
|
||||||
|
CONFIG_DEV_CONSOLE=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# Allow for artchitecture optimized implementations
|
||||||
|
#
|
||||||
|
# The architecture can provide optimized versions of the
|
||||||
|
# following to improve sysem performance
|
||||||
|
#
|
||||||
|
CONFIG_ARCH_MEMCPY=n
|
||||||
|
CONFIG_ARCH_MEMCMP=n
|
||||||
|
CONFIG_ARCH_MEMMOVE=n
|
||||||
|
CONFIG_ARCH_MEMSET=n
|
||||||
|
CONFIG_ARCH_STRCMP=n
|
||||||
|
CONFIG_ARCH_STRCPY=n
|
||||||
|
CONFIG_ARCH_STRNCPY=n
|
||||||
|
CONFIG_ARCH_STRLEN=n
|
||||||
|
CONFIG_ARCH_BZERO=n
|
||||||
|
CONFIG_ARCH_KMALLOC=n
|
||||||
|
CONFIG_ARCH_KZMALLOC=n
|
||||||
|
CONFIG_ARCH_KFREE=n
|
||||||
|
|
||||||
|
# General Compile environment setup
|
||||||
|
#
|
||||||
|
# CONFIG_HAVE_LONG_LONG - enable if your architecture supports
|
||||||
|
# long long types and if you plan to use them
|
||||||
|
CONFIG_HAVE_LONG_LONG=n
|
||||||
|
|
||||||
|
#
|
||||||
|
# Sizes of configurable things (0 disables)
|
||||||
|
#
|
||||||
|
# CONFIG_NPTHREAD_KEYS - The number of items of thread-
|
||||||
|
# specific data that can be retained
|
||||||
|
# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
|
||||||
|
# descriptors (one for each open)
|
||||||
|
# CONFIG_NFILE_STREAMS - The maximum number of streams that
|
||||||
|
# can be fopen'ed
|
||||||
|
# CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate
|
||||||
|
# on fopen. (Only if CONFIG_NFILE_STREAMS > 0)
|
||||||
|
# CONFIG_NUNGET_CHARS - Number of characters that can be
|
||||||
|
# buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0)
|
||||||
|
# CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message
|
||||||
|
# structures. The system manages a pool of preallocated
|
||||||
|
# message structures to minimize dynamic allocations
|
||||||
|
# CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
|
||||||
|
# a fixed payload size given by this settin (does not include
|
||||||
|
# other message structure overhead.
|
||||||
|
# CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
|
||||||
|
# structures. The system manages a pool of preallocated
|
||||||
|
# watchdog structures to minimize dynamic allocations
|
||||||
|
#
|
||||||
|
CONFIG_NPTHREAD_KEYS=4
|
||||||
|
CONFIG_NFILE_DESCRIPTORS=32
|
||||||
|
CONFIG_NFILE_STREAMS=16
|
||||||
|
CONFIG_STDIO_BUFFER_SIZE=1024
|
||||||
|
CONFIG_NUNGET_CHARS=2
|
||||||
|
CONFIG_PREALLOC_MQ_MSGS=32
|
||||||
|
CONFIG_MQ_MAXMSGSIZE=32
|
||||||
|
CONFIG_PREALLOC_WDOGS=32
|
||||||
|
|
||||||
|
#
|
||||||
|
# Stack and heap information
|
||||||
|
#
|
||||||
|
# CONFIG_BOOT_FROM_FLASH - Some configurations support XIP
|
||||||
|
# operation from FLASH.
|
||||||
|
# CONFIG_STACK_POINTER - The initial stack pointer
|
||||||
|
# CONFIG_PROC_STACK_SIZE - The size of the initial stack
|
||||||
|
# CONFIG_PTHREAD_STACK_MIN - Minimum pthread stack size
|
||||||
|
# CONFIG_PTHREAD_STACK_DEFAULT - Default pthread stack size
|
||||||
|
# CONFIG_HEAP_BASE - The beginning of the heap
|
||||||
|
# CONFIG_HEAP_SIZE - The size of the heap
|
||||||
|
#
|
||||||
|
CONFIG_BOOT_FROM_FLASH=n
|
||||||
|
CONFIG_PROC_STACK_SIZE=0x00001000
|
||||||
|
CONFIG_PTHREAD_STACK_MIN=256
|
||||||
|
CONFIG_PTHREAD_STACK_DEFAULT=8192
|
||||||
|
CONFIG_HEAP_BASE=
|
||||||
|
CONFIG_HEAP_SIZE=
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/************************************************************
|
||||||
|
* arch.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* This file should never be included directed but, rather,
|
||||||
|
* only indirectly through nuttx/arch.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ARCH_ARCH_H
|
||||||
|
#define __ARCH_ARCH_H
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Inline functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Types
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Variables
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C" {
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ARCH_ARCH_H */
|
||||||
|
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/************************************************************
|
||||||
|
* irq.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* This file should never be included directed but, rather,
|
||||||
|
* only indirectly through nuttx/irq.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ARCH_IRQ_H
|
||||||
|
#define __ARCH_IRQ_H
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#define NR_IRQS 0
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Types
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* This struct defines the way the registers are stored */
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
struct xcptcontext
|
||||||
|
{
|
||||||
|
void *sigdeliver; /* Actual type is sig_deliver_t */
|
||||||
|
|
||||||
|
/* Storage order: %ebx, $esi, %edi, %ebp, sp, and return PC */
|
||||||
|
|
||||||
|
int regs[6];
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Inline functions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
static inline uint32 irqsave(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void irqrestore(uint32 flags)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Variables
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C" {
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ARCH_IRQ_H */
|
||||||
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/************************************************************
|
||||||
|
* types.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* This file should never be included directed but, rather,
|
||||||
|
* only indirectly through sys/types.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ARCH_TYPES_H
|
||||||
|
#define __ARCH_TYPES_H
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Type Declarations
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
typedef char sbyte;
|
||||||
|
typedef unsigned char ubyte;
|
||||||
|
typedef unsigned char uint8;
|
||||||
|
typedef unsigned char boolean;
|
||||||
|
typedef short sint16;
|
||||||
|
typedef unsigned short uint16;
|
||||||
|
typedef int sint32;
|
||||||
|
typedef unsigned int uint32;
|
||||||
|
typedef long long sint64;
|
||||||
|
typedef unsigned long long uint64;
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Global Function Prototypes
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
#endif /* __ARCH_TYPES_H */
|
||||||
Executable
+45
@@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# setenv.sh
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ "$(basename $0)" = "setenv" ] ; then
|
||||||
|
echo "You must source this script, not run it!" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z ${PATH_ORIG} ]; then export PATH_ORIG=${PATH}; fi
|
||||||
|
|
||||||
|
#export NUTTX_BIN=
|
||||||
|
#export PATH=${NUTTX_BIN}:/sbin:/usr/sbin:${PATH_ORIG}
|
||||||
|
|
||||||
|
echo "PATH : ${PATH}"
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
############################################################
|
||||||
|
# Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
-include $(TOPDIR)/Make.defs
|
||||||
|
|
||||||
|
MKDEP = $(TOPDIR)/tools/mkdeps.sh
|
||||||
|
CFLAGS += -I$(TOPDIR)/sched
|
||||||
|
|
||||||
|
ASRCS = up_setjmp.S
|
||||||
|
AOBJS = $(ASRCS:.S=.o)
|
||||||
|
CSRCS = up_initialize.c up_idle.c up_interruptcontext.c up_initialstate.c \
|
||||||
|
up_createstack.c up_usestack.c up_releasestack.c \
|
||||||
|
up_unblocktask.c up_blocktask.c up_releasepending.c up_reprioritizertr.c \
|
||||||
|
up_exit.c up_schedulesigaction.c up_allocateheap.c up_devconsole.c
|
||||||
|
COBJS = $(CSRCS:.c=.o)
|
||||||
|
|
||||||
|
SRCS = $(ASRCS) $(CSRCS)
|
||||||
|
OBJS = $(AOBJS) $(COBJS)
|
||||||
|
|
||||||
|
all: up_head.o libarch.a
|
||||||
|
|
||||||
|
$(AOBJS): %.o: %.S
|
||||||
|
$(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@
|
||||||
|
|
||||||
|
$(COBJS) up_head.o: %.o: %.c
|
||||||
|
$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
libarch.a: $(OBJS)
|
||||||
|
$(AR) rcs $@ $(OBJS)
|
||||||
|
|
||||||
|
.depend: Makefile $(SRCS)
|
||||||
|
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
depend: .depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f libarch.a *.o *~
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
rm -f Make.dep .depend
|
||||||
|
|
||||||
|
|
||||||
|
-include Make.dep
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_allocateheap.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
static ubyte sim_heap[SIM_HEAP_SIZE];
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_allocate_heap
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* The heap may be statically allocated by
|
||||||
|
* defining CONFIG_HEAP_BASE and CONFIG_HEAP_SIZE. If these
|
||||||
|
* are not defined, then this function will be called to
|
||||||
|
* dynamically set aside the heap region.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
void up_allocate_heap(void **heap_start, size_t *heap_size)
|
||||||
|
{
|
||||||
|
*heap_start = sim_heap;
|
||||||
|
*heap_size = SIM_HEAP_SIZE;
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_blocktask.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 "os_internal.h"
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_block_task
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* The currently executing task at the head of
|
||||||
|
* the ready to run list must be stopped. Save its context
|
||||||
|
* and move it to the inactive list specified by task_state.
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* tcb: Refers to a task in the ready-to-run list (normally
|
||||||
|
* the task at the 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(_TCB *tcb, tstate_t task_state)
|
||||||
|
{
|
||||||
|
/* Verify that the context switch can be performed */
|
||||||
|
if ((tcb->task_state < FIRST_READY_TO_RUN_STATE) ||
|
||||||
|
(tcb->task_state > LAST_READY_TO_RUN_STATE))
|
||||||
|
{
|
||||||
|
PANIC(OSERR_BADBLOCKSTATE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_TCB *rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
boolean switch_needed;
|
||||||
|
|
||||||
|
dbg("Blocking TCB=%p\n", tcb);
|
||||||
|
|
||||||
|
/* Remove the tcb task from the ready-to-run list. If we
|
||||||
|
* are blocking the task at the head of the task list (the
|
||||||
|
* most likely case), then a context switch to the next
|
||||||
|
* ready-to-run task is needed. In this case, it should
|
||||||
|
* also be true that rtcb == tcb.
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch_needed = sched_removereadytorun(tcb);
|
||||||
|
|
||||||
|
/* Add the task to the specified blocked task list */
|
||||||
|
|
||||||
|
sched_addblocked(tcb, (tstate_t)task_state);
|
||||||
|
|
||||||
|
/* If there are any pending tasks, then add them to the g_readytorun
|
||||||
|
* task list now
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (g_pendingtasks.head)
|
||||||
|
{
|
||||||
|
switch_needed |= sched_mergepending();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now, perform the context switch if one is needed */
|
||||||
|
|
||||||
|
if (switch_needed)
|
||||||
|
{
|
||||||
|
/* Copy the exception context into the TCB at the (old) head of the
|
||||||
|
* g_readytorun Task list. if up_setjmp returns a non-zero
|
||||||
|
* value, then this is really the previously running task restarting!
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!up_setjmp(rtcb->xcp.regs))
|
||||||
|
{
|
||||||
|
/* Restore the exception context of the rtcb at the (new) head
|
||||||
|
* of the g_readytorun task list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rtcb = (_TCB*)g_readytorun.head;
|
||||||
|
dbg("New Active Task TCB=%p\n", rtcb);
|
||||||
|
|
||||||
|
/* The way that we handle signals in the simulation is kind of
|
||||||
|
* a kludge. This would be unsafe in a truly multi-threaded, interrupt
|
||||||
|
* driven environment.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (rtcb->xcp.sigdeliver)
|
||||||
|
{
|
||||||
|
dbg("Delivering signals TCB=%p\n", rtcb);
|
||||||
|
((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
|
||||||
|
rtcb->xcp.sigdeliver = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Then switch contexts */
|
||||||
|
|
||||||
|
up_longjmp(rtcb->xcp.regs, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
/************************************************************
|
||||||
|
* up_createstack.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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 <nuttx/arch.h>
|
||||||
|
#include <nuttx/kmalloc.h>
|
||||||
|
#include "up_internal.h"
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Data
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Private Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Public Funtions
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/************************************************************
|
||||||
|
* Name: up_create_stack
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Allocate a stack for a new thread and setup
|
||||||
|
* up stack-related information in the TCB.
|
||||||
|
*
|
||||||
|
* The following TCB fields must be initialized:
|
||||||
|
* adj_stack_size: Stack size after adjustment for hardware,
|
||||||
|
* processor, etc. This value is retained only for debug
|
||||||
|
* purposes.
|
||||||
|
* stack_alloc_ptr: Pointer to allocated stack
|
||||||
|
* adj_stack_ptr: Adjusted StatckAllocPtr for HW. The
|
||||||
|
* initial value of the stack pointer.
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* tcb: The TCB of new task
|
||||||
|
* stack_size: The requested stack size. At least this much
|
||||||
|
* must be allocated.
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
STATUS up_create_stack(_TCB *tcb, uint32 stack_size)
|
||||||
|
{
|
||||||
|
STATUS ret = ERROR;
|
||||||
|
|
||||||
|
/* Move up to next even word boundary if necessary */
|
||||||
|
|
||||||
|
uint32 adj_stack_size = (stack_size + 3) & ~3;
|
||||||
|
uint32 adj_stack_words = adj_stack_size >> 2;
|
||||||
|
|
||||||
|
/* Allocate the memory for the stack */
|
||||||
|
|
||||||
|
uint32 *stack_alloc_ptr = (uint32*)kmalloc(adj_stack_size);
|
||||||
|
if (stack_alloc_ptr)
|
||||||
|
{
|
||||||
|
/* This is the address of the last word in the allocation */
|
||||||
|
|
||||||
|
uint32 *adj_stack_ptr = &stack_alloc_ptr[adj_stack_words - 1];
|
||||||
|
|
||||||
|
/* Save the values in the TCB */
|
||||||
|
tcb->adj_stack_size = adj_stack_size;
|
||||||
|
tcb->stack_alloc_ptr = stack_alloc_ptr;
|
||||||
|
tcb->adj_stack_ptr = adj_stack_ptr;
|
||||||
|
ret = OK;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user