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:
commit
b08a86171f
353 changed files with 52170 additions and 0 deletions
121
Documentation/NuttxPortingGuide.html
Normal file
121
Documentation/NuttxPortingGuide.html
Normal file
|
@ -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>
|
||||
|
||||
|
4105
Documentation/NuttxUserGuide.html
Normal file
4105
Documentation/NuttxUserGuide.html
Normal file
File diff suppressed because it is too large
Load diff
139
Makefile
Normal file
139
Makefile
Normal file
|
@ -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
arch/README.txt
Normal file
189
arch/README.txt
Normal file
|
@ -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>
|
||||
|
||||
|
70
arch/c5471/Make.defs
Normal file
70
arch/c5471/Make.defs
Normal file
|
@ -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
|
||||
|
||||
|
157
arch/c5471/defconfig
Normal file
157
arch/c5471/defconfig
Normal file
|
@ -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
|
80
arch/c5471/include/arch.h
Normal file
80
arch/c5471/include/arch.h
Normal file
|
@ -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 */
|
||||
|
252
arch/c5471/include/irq.h
Normal file
252
arch/c5471/include/irq.h
Normal file
|
@ -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 */
|
||||
|
70
arch/c5471/include/types.h
Normal file
70
arch/c5471/include/types.h
Normal file
|
@ -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 */
|
107
arch/c5471/ld.script
Normal file
107
arch/c5471/ld.script
Normal file
|
@ -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) }
|
||||
}
|
46
arch/c5471/setenv.sh
Executable file
46
arch/c5471/setenv.sh
Executable file
|
@ -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}"
|
79
arch/c5471/src/Makefile
Normal file
79
arch/c5471/src/Makefile
Normal file
|
@ -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
|
376
arch/c5471/src/c5471.h
Normal file
376
arch/c5471/src/c5471.h
Normal file
|
@ -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 */
|
82
arch/c5471/src/up_assert.c
Normal file
82
arch/c5471/src/up_assert.c
Normal file
|
@ -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);
|
||||
}
|
168
arch/c5471/src/up_blocktask.c
Normal file
168
arch/c5471/src/up_blocktask.c
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
75
arch/c5471/src/up_copystate.c
Normal file
75
arch/c5471/src/up_copystate.c
Normal file
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
126
arch/c5471/src/up_createstack.c
Normal file
126
arch/c5471/src/up_createstack.c
Normal file
|
@ -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;
|
||||
}
|
68
arch/c5471/src/up_dataabort.c
Normal file
68
arch/c5471/src/up_dataabort.c
Normal file
|
@ -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);
|
||||
}
|
111
arch/c5471/src/up_exit.c
Normal file
111
arch/c5471/src/up_exit.c
Normal file
|
@ -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);
|
||||
}
|
||||
|
115
arch/c5471/src/up_fullcontextrestore.S
Normal file
115
arch/c5471/src/up_fullcontextrestore.S
Normal file
|
@ -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
|
||||
|
125
arch/c5471/src/up_head.S
Normal file
125
arch/c5471/src/up_head.S
Normal file
|
@ -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
|
||||
|
79
arch/c5471/src/up_idle.c
Normal file
79
arch/c5471/src/up_idle.c
Normal file
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
93
arch/c5471/src/up_initialize.c
Normal file
93
arch/c5471/src/up_initialize.c
Normal file
|
@ -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);
|
||||
}
|
85
arch/c5471/src/up_initialstate.c
Normal file
85
arch/c5471/src/up_initialstate.c
Normal file
|
@ -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;
|
||||
}
|
99
arch/c5471/src/up_internal.h
Normal file
99
arch/c5471/src/up_internal.h
Normal file
|
@ -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 */
|
68
arch/c5471/src/up_interruptcontext.c
Normal file
68
arch/c5471/src/up_interruptcontext.c
Normal file
|
@ -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;
|
||||
}
|
243
arch/c5471/src/up_irq.c
Normal file
243
arch/c5471/src/up_irq.c
Normal file
|
@ -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. */
|
||||
}
|
69
arch/c5471/src/up_prefetchabort.c
Normal file
69
arch/c5471/src/up_prefetchabort.c
Normal file
|
@ -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);
|
||||
}
|
131
arch/c5471/src/up_releasepending.c
Normal file
131
arch/c5471/src/up_releasepending.c
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
78
arch/c5471/src/up_releasestack.c
Normal file
78
arch/c5471/src/up_releasestack.c
Normal file
|
@ -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;
|
||||
}
|
178
arch/c5471/src/up_reprioritizertr.c
Normal file
178
arch/c5471/src/up_reprioritizertr.c
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
121
arch/c5471/src/up_saveusercontext.S
Normal file
121
arch/c5471/src/up_saveusercontext.S
Normal file
|
@ -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
|
||||
|
186
arch/c5471/src/up_schedulesigaction.c
Normal file
186
arch/c5471/src/up_schedulesigaction.c
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
117
arch/c5471/src/up_sigdeliver.c
Normal file
117
arch/c5471/src/up_sigdeliver.c
Normal file
|
@ -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);
|
||||
}
|
82
arch/c5471/src/up_syscall.c
Normal file
82
arch/c5471/src/up_syscall.c
Normal file
|
@ -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);
|
||||
}
|
93
arch/c5471/src/up_timerisr.c
Normal file
93
arch/c5471/src/up_timerisr.c
Normal file
|
@ -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;
|
||||
}
|
160
arch/c5471/src/up_unblocktask.c
Normal file
160
arch/c5471/src/up_unblocktask.c
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
68
arch/c5471/src/up_undefinedinsn.c
Normal file
68
arch/c5471/src/up_undefinedinsn.c
Normal file
|
@ -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);
|
||||
}
|
118
arch/c5471/src/up_usestack.c
Normal file
118
arch/c5471/src/up_usestack.c
Normal file
|
@ -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;
|
||||
}
|
449
arch/c5471/src/up_vectors.S
Normal file
449
arch/c5471/src/up_vectors.S
Normal file
|
@ -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
|
69
arch/sim/Make.defs
Normal file
69
arch/sim/Make.defs
Normal file
|
@ -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
|
||||
|
||||
|
154
arch/sim/defconfig
Normal file
154
arch/sim/defconfig
Normal file
|
@ -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=
|
80
arch/sim/include/arch.h
Normal file
80
arch/sim/include/arch.h
Normal file
|
@ -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 */
|
||||
|
106
arch/sim/include/irq.h
Normal file
106
arch/sim/include/irq.h
Normal file
|
@ -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 */
|
||||
|
70
arch/sim/include/types.h
Normal file
70
arch/sim/include/types.h
Normal file
|
@ -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 */
|
45
arch/sim/setenv.sh
Executable file
45
arch/sim/setenv.sh
Executable file
|
@ -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}"
|
76
arch/sim/src/Makefile
Normal file
76
arch/sim/src/Makefile
Normal file
|
@ -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
|
81
arch/sim/src/up_allocateheap.c
Normal file
81
arch/sim/src/up_allocateheap.c
Normal file
|
@ -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;
|
||||
}
|
157
arch/sim/src/up_blocktask.c
Normal file
157
arch/sim/src/up_blocktask.c
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
109
arch/sim/src/up_createstack.c
Normal file
109
arch/sim/src/up_createstack.c
Normal file
|
@ -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;
|
||||
}
|
136
arch/sim/src/up_devconsole.c
Normal file
136
arch/sim/src/up_devconsole.c
Normal file
|
@ -0,0 +1,136 @@
|
|||
/************************************************************
|
||||
* up_devconsole.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 <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
#define READ 3
|
||||
#define WRITE 4
|
||||
|
||||
/************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
static ssize_t devconsole_read(struct file *, char *, size_t);
|
||||
static ssize_t devconsole_write(struct file *, const char *, size_t);
|
||||
|
||||
/************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
static struct file_operations devconsole_fops =
|
||||
{
|
||||
.read = devconsole_read,
|
||||
.write = devconsole_write,
|
||||
};
|
||||
|
||||
/************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
static inline int up_read(int fd, void* buf, size_t count)
|
||||
{
|
||||
uint32 result;
|
||||
|
||||
__asm__ volatile ("int $0x80" \
|
||||
: "=a" (result) \
|
||||
: "0" (READ), "b" ((uint32)(fd)), "c" ((uint32)(buf)), "d" ((uint32)(count)) \
|
||||
: "memory");
|
||||
|
||||
return (int)result;
|
||||
}
|
||||
|
||||
static inline int up_write(int fd, const void* buf, size_t count)
|
||||
{
|
||||
uint32 result;
|
||||
|
||||
__asm__ volatile ("int $0x80" \
|
||||
: "=a" (result) \
|
||||
: "0" (WRITE), "b" ((uint32)(fd)), "c" ((uint32)(buf)), "d" ((uint32)(count)) \
|
||||
: "memory");
|
||||
|
||||
return (int)result;
|
||||
}
|
||||
|
||||
static inline int up_check_result(int result)
|
||||
{
|
||||
if (result >= (uint32)(-(128 + 1)))
|
||||
{
|
||||
*get_errno_ptr() = -result;
|
||||
result = ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static ssize_t devconsole_read(struct file *filp, char *buffer, size_t len)
|
||||
{
|
||||
return up_check_result(up_read(1, buffer, len));
|
||||
}
|
||||
|
||||
static ssize_t devconsole_write(struct file *filp, const char *buffer, size_t len)
|
||||
{
|
||||
return up_check_result(up_write(1, buffer, len));
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Public Funtions
|
||||
************************************************************/
|
||||
|
||||
void up_devconsole(void)
|
||||
{
|
||||
(void)register_inode("/dev/console", &devconsole_fops, 0666, NULL);
|
||||
}
|
||||
|
||||
int up_putc(int ch)
|
||||
{
|
||||
char b = ch;
|
||||
(void)up_write(1, &b, 1);
|
||||
return ch;
|
||||
}
|
123
arch/sim/src/up_exit.c
Normal file
123
arch/sim/src/up_exit.c
Normal file
|
@ -0,0 +1,123 @@
|
|||
/************************************************************
|
||||
* 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);
|
||||
|
||||
/* 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 (tcb->xcp.sigdeliver)
|
||||
{
|
||||
dbg("Delivering signals TCB=%p\n", tcb);
|
||||
((sig_deliver_t)tcb->xcp.sigdeliver)(tcb);
|
||||
tcb->xcp.sigdeliver = NULL;
|
||||
}
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_longjmp(tcb->xcp.regs, 1);
|
||||
}
|
||||
|
77
arch/sim/src/up_head.c
Normal file
77
arch/sim/src/up_head.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/************************************************************
|
||||
* up_head.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 <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <setjmp.h>
|
||||
#include <assert.h>
|
||||
#include <nuttx/os_external.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
/************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
static jmp_buf sim_abort;
|
||||
|
||||
/************************************************************
|
||||
* Global Funtions
|
||||
************************************************************/
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
if (setjmp(sim_abort) == 0)
|
||||
{
|
||||
os_start();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void up_assert(const ubyte *filename, uint32 line)
|
||||
{
|
||||
fprintf(stderr, "Assertion failed at file:%s line: %d\n", filename, line);
|
||||
longjmp(sim_abort, 1);
|
||||
}
|
||||
|
||||
void up_assert_code(const ubyte *filename, uint32 line, uint16 code)
|
||||
{
|
||||
fprintf(stderr, "Assertion failed at file:%s line: %d error code: %d\n", filename, line, code);
|
||||
longjmp(sim_abort, 1);
|
||||
}
|
84
arch/sim/src/up_idle.c
Normal file
84
arch/sim/src/up_idle.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/************************************************************
|
||||
* 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)
|
||||
{
|
||||
/* If the system, then process timer interrupts. Hopefully
|
||||
* something will wake up.
|
||||
*/
|
||||
|
||||
sched_process_timer();
|
||||
}
|
||||
|
88
arch/sim/src/up_initialize.c
Normal file
88
arch/sim/src/up_initialize.c
Normal file
|
@ -0,0 +1,88 @@
|
|||
/************************************************************
|
||||
* 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 <nuttx/arch.h>
|
||||
#include <nuttx/fs.h>
|
||||
#include "up_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Private Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Funtions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Funtions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* 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)
|
||||
{
|
||||
/* Register devices */
|
||||
|
||||
devnull_register(); /* Standard /dev/null */
|
||||
up_devconsole(); /* Our private /dev/console */
|
||||
}
|
81
arch/sim/src/up_initialstate.c
Normal file
81
arch/sim/src/up_initialstate.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/************************************************************
|
||||
* 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)
|
||||
{
|
||||
memset(&tcb->xcp, 0, sizeof(struct xcptcontext));
|
||||
tcb->xcp.regs[JB_SP] = (uint32)tcb->adj_stack_ptr;
|
||||
tcb->xcp.regs[JB_PC] = (uint32)tcb->start;
|
||||
}
|
91
arch/sim/src/up_internal.h
Normal file
91
arch/sim/src/up_internal.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
/**************************************************************************
|
||||
* 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 __ARCH_UP_INTERNAL_H
|
||||
#define __ARCH_UP_INTERNAL_H
|
||||
|
||||
/**************************************************************************
|
||||
* Included Files
|
||||
**************************************************************************/
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
/**************************************************************************
|
||||
* Public Definitions
|
||||
**************************************************************************/
|
||||
|
||||
/* Storage order: %ebx, $esi, %edi, %ebp, sp, and return PC */
|
||||
#ifdef __ASSEMBLY__
|
||||
# define JB_EBX (0*4)
|
||||
# define JB_ESI (1*4)
|
||||
# define JB_EDI (2*4)
|
||||
# define JB_EBP (3*4)
|
||||
# define JB_SP (4*4)
|
||||
# define JB_PC (5*4)
|
||||
#else
|
||||
# define JB_EBX (0)
|
||||
# define JB_ESI (1)
|
||||
# define JB_EDI (2)
|
||||
# define JB_EBP (3)
|
||||
# define JB_SP (4)
|
||||
# define JB_PC (5)
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
#define SIM_HEAP_SIZE (4*1024*1024)
|
||||
|
||||
/**************************************************************************
|
||||
* Public Types
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Public Variables
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Public Function Prototypes
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
/* up_setjmp.S ************************************************************/
|
||||
|
||||
extern int up_setjmp(int *jb);
|
||||
extern void up_longjmp(int *jb, int val) __attribute__ ((noreturn));
|
||||
|
||||
/* up_devconsole **********************************************************/
|
||||
|
||||
extern void up_devconsole(void);
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_UP_INTERNAL_H */
|
74
arch/sim/src/up_interruptcontext.c
Normal file
74
arch/sim/src/up_interruptcontext.c
Normal file
|
@ -0,0 +1,74 @@
|
|||
/************************************************************
|
||||
* 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 "up_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Private Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Funtions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Funtions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Name: up_interrupt_context
|
||||
*
|
||||
* Description:
|
||||
* Return TRUE is we are currently executing in
|
||||
* the interrupt handler context.
|
||||
************************************************************/
|
||||
|
||||
boolean up_interrupt_context(void)
|
||||
{
|
||||
/* The simulation is never in the interrupt state */
|
||||
return FALSE;
|
||||
}
|
||||
|
118
arch/sim/src/up_releasepending.c
Normal file
118
arch/sim/src/up_releasepending.c
Normal file
|
@ -0,0 +1,118 @@
|
|||
/************************************************************
|
||||
* 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! Copy the exception context
|
||||
* into the TCB of the task that was currently active. 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);
|
||||
}
|
||||
}
|
||||
}
|
81
arch/sim/src/up_releasestack.c
Normal file
81
arch/sim/src/up_releasestack.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/************************************************************
|
||||
* 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 <stdlib.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include "up_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Private Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Funtions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Funtions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* 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)
|
||||
{
|
||||
free(dtcb->stack_alloc_ptr);
|
||||
}
|
||||
|
||||
dtcb->stack_alloc_ptr = NULL;
|
||||
dtcb->adj_stack_size = 0;
|
||||
dtcb->adj_stack_ptr = NULL;
|
||||
}
|
169
arch/sim/src/up_reprioritizertr.c
Normal file
169
arch/sim/src/up_reprioritizertr.c
Normal file
|
@ -0,0 +1,169 @@
|
|||
/************************************************************
|
||||
* 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();
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
109
arch/sim/src/up_schedulesigaction.c
Normal file
109
arch/sim/src/up_schedulesigaction.c
Normal file
|
@ -0,0 +1,109 @@
|
|||
/************************************************************
|
||||
* 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"
|
||||
|
||||
/************************************************************
|
||||
* 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)
|
||||
{
|
||||
/* We don't have to anything complex of the simulated target */
|
||||
|
||||
if (tcb == (_TCB*)g_readytorun.head)
|
||||
{
|
||||
sigdeliver(tcb);
|
||||
}
|
||||
else
|
||||
{
|
||||
tcb->xcp.sigdeliver = sigdeliver;
|
||||
}
|
||||
}
|
129
arch/sim/src/up_setjmp.S
Normal file
129
arch/sim/src/up_setjmp.S
Normal file
|
@ -0,0 +1,129 @@
|
|||
/**************************************************************************
|
||||
* up_setjmp.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.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Conditional Compilation Options
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Included Files
|
||||
**************************************************************************/
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/**************************************************************************
|
||||
* Private Definitions
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Private Types
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Private Function Prototypes
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Global Variables
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Private Variables
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Private Functions
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Public Functions
|
||||
**************************************************************************/
|
||||
|
||||
.text
|
||||
.globl up_setjmp
|
||||
.type up_setjmp, @function
|
||||
up_setjmp:
|
||||
|
||||
/* %ebx, %esi, %edi, and %ebp must be preserved.
|
||||
* save %ebx, $esi, and %edi now... */
|
||||
|
||||
movl 4(%esp), %eax
|
||||
movl %ebx, (JB_EBX)(%eax)
|
||||
movl %esi, (JB_ESI)(%eax)
|
||||
movl %edi, (JB_EDI)(%eax)
|
||||
|
||||
/* Save the value of SP as will be after we return */
|
||||
|
||||
leal 4(%esp), %ecx
|
||||
movl %ecx, (JB_SP)(%eax)
|
||||
|
||||
/* Save the return PC */
|
||||
|
||||
movl 0(%esp), %ecx
|
||||
movl %ecx, (JB_PC)(%eax)
|
||||
|
||||
/* Save the framepointer */
|
||||
|
||||
movl %ebp, (JB_EBP)(%eax)
|
||||
|
||||
/* And return 0 */
|
||||
|
||||
xorl %eax, %eax
|
||||
ret
|
||||
.size up_setjmp, . - up_setjmp
|
||||
|
||||
.globl up_longjmp
|
||||
.type up_longjmp, @function
|
||||
up_longjmp:
|
||||
movl 4(%esp), %ecx /* U_pthread_jmpbuf in %ecx. */
|
||||
movl 8(%esp), %eax /* Second argument is return value. */
|
||||
|
||||
/* Save the return address now. */
|
||||
|
||||
movl (JB_PC)(%ecx), %edx
|
||||
|
||||
/* Restore registers. */
|
||||
|
||||
movl (JB_EBX)(%ecx), %ebx
|
||||
movl (JB_ESI)(%ecx), %esi
|
||||
movl (JB_EDI)(%ecx), %edi
|
||||
movl (JB_EBP)(%ecx), %ebp
|
||||
movl (JB_SP)(%ecx), %esp
|
||||
|
||||
/* Jump to saved PC. */
|
||||
|
||||
jmp *%edx
|
||||
.size up_longjmp, . - up_longjmp
|
||||
|
146
arch/sim/src/up_unblocktask.c
Normal file
146
arch/sim/src/up_unblocktask.c
Normal file
|
@ -0,0 +1,146 @@
|
|||
/************************************************************
|
||||
* 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! Copy the exception context
|
||||
* into the TCB of the task that was previously active. 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 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);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
100
arch/sim/src/up_usestack.c
Normal file
100
arch/sim/src/up_usestack.c
Normal file
|
@ -0,0 +1,100 @@
|
|||
/************************************************************
|
||||
* 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 <debug.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include "os_internal.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Private Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Funtions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Funtions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* 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)
|
||||
{
|
||||
/* Move up to next even word boundary if necessary */
|
||||
|
||||
uint32 adj_stack_size = stack_size & ~3;
|
||||
uint32 adj_stack_words = adj_stack_size >> 2;
|
||||
|
||||
/* This is the address of the last word in the allocation */
|
||||
|
||||
uint32 *adj_stack_ptr = &stack[adj_stack_words - 1];
|
||||
|
||||
/* Save the values in the TCB */
|
||||
tcb->adj_stack_size = adj_stack_size;
|
||||
tcb->stack_alloc_ptr = stack;
|
||||
tcb->adj_stack_ptr = adj_stack_ptr;
|
||||
return OK;
|
||||
}
|
74
drivers/Makefile
Normal file
74
drivers/Makefile
Normal file
|
@ -0,0 +1,74 @@
|
|||
############################################################
|
||||
# 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
|
||||
|
||||
ASRCS =
|
||||
AOBJS = $(ASRCS:.S=.o)
|
||||
|
||||
CSRCS = dev_null.c
|
||||
COBJS = $(CSRCS:.c=.o)
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
BIN = libdrivers.a
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
$(AOBJS): %.o: %.S
|
||||
$(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@
|
||||
|
||||
$(cOBJS): %.o: %.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(BIN): $(OBJS)
|
||||
$(AR) rcs $@ $(OBJS)
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
rm -f $(BIN) *.o *~
|
||||
|
||||
distclean: clean
|
||||
rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
89
drivers/dev_null.c
Normal file
89
drivers/dev_null.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
/************************************************************
|
||||
* dev_null.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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/fs.h>
|
||||
|
||||
/************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
static ssize_t devnull_read(struct file *, char *, size_t);
|
||||
static ssize_t devnull_write(struct file *, const char *, size_t);
|
||||
|
||||
/************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
static struct file_operations devnull_fops =
|
||||
{
|
||||
.read = devnull_read,
|
||||
.write = devnull_write,
|
||||
};
|
||||
|
||||
/************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
static ssize_t devnull_read(struct file *filp, char *buffer, size_t len)
|
||||
{
|
||||
return 0; /* Return EOF */
|
||||
}
|
||||
|
||||
static ssize_t devnull_write(struct file *filp, const char *buffer, size_t len)
|
||||
{
|
||||
return len; /* Say that everything was written */
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
|
||||
void devnull_register(void)
|
||||
{
|
||||
(void)register_inode("/dev/null", &devnull_fops, 0666, NULL);
|
||||
}
|
75
examples/ostest/Makefile
Normal file
75
examples/ostest/Makefile
Normal file
|
@ -0,0 +1,75 @@
|
|||
############################################################
|
||||
# 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)/.config
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
MKDEP = $(TOPDIR)/tools/mkdeps.sh
|
||||
|
||||
ASRCS =
|
||||
AOBJS = $(ASRCS:.S=.o)
|
||||
CSRCS = main.c dev_null.c mutex.c cancel.c sem.c cond.c \
|
||||
timedwait.c mqueue.c sighand.c
|
||||
COBJS = $(CSRCS:.c=.o)
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
BIN = lib$(CONFIG_EXAMPLE).a
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
$(AOBJS): %.o: %.S
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(COBJS): %.o: %.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(BIN): $(OBJS)
|
||||
$(AR) rcs $@ $(OBJS)
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
rm -f $(BIN) *.o *~
|
||||
|
||||
distclean: clean
|
||||
rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
308
examples/ostest/cancel.c
Normal file
308
examples/ostest/cancel.c
Normal file
|
@ -0,0 +1,308 @@
|
|||
/***********************************************************************
|
||||
* cancel.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.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include "ostest.h"
|
||||
|
||||
static pthread_mutex_t mutex;
|
||||
static pthread_cond_t cond;
|
||||
|
||||
static void *thread_waiter(void *parameter)
|
||||
{
|
||||
int status;
|
||||
|
||||
/* Take the mutex */
|
||||
|
||||
printf("%s: Taking mutex\n", __FUNCTION__);
|
||||
status = pthread_mutex_lock(&mutex);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_lock failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
printf("%s: Starting wait for condition\n", __FUNCTION__);
|
||||
|
||||
/* Are we a non-cancelable thread? Yes, set the non-cancelable state */
|
||||
|
||||
if (!parameter)
|
||||
{
|
||||
printf("%s: Setting non-cancelable\n", __FUNCTION__);
|
||||
status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_setcancelstate failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
}
|
||||
|
||||
/* The wait -- we will never awaken from this. */
|
||||
|
||||
status = pthread_cond_wait(&cond, &mutex);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_cond_wait failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Release the mutex */
|
||||
|
||||
printf("%s: Releasing mutex\n", __FUNCTION__);
|
||||
status = pthread_mutex_unlock(&mutex);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_unlock failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Set the cancelable state */
|
||||
|
||||
printf("%s: Setting cancelable\n", __FUNCTION__);
|
||||
status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_setcancelstate failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
printf("%s: Exit with status 0x12345678\n", __FUNCTION__);
|
||||
pthread_exit((void*)0x12345678);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void start_thread(pthread_t *waiter, int cancelable)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
int status;
|
||||
|
||||
/* Initialize the mutex */
|
||||
|
||||
printf("%s: Initializing mutex\n", __FUNCTION__);
|
||||
status = pthread_mutex_init(&mutex, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Initialize the condition variable */
|
||||
|
||||
printf("%s: Initializing cond\n", __FUNCTION__);
|
||||
status = pthread_cond_init(&cond, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_cond_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Set up attributes */
|
||||
|
||||
status = pthread_attr_init(&attr);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
status = pthread_attr_setstacksize(&attr, 16384);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_setstacksize failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Start the waiter thread */
|
||||
|
||||
printf("%s: Starting thread\n", __FUNCTION__);
|
||||
status = pthread_create(waiter, NULL, thread_waiter, (void*)cancelable);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_create failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Make sure that the waiter thread gets a chance to run */
|
||||
|
||||
printf("%s: Yielding\n", __FUNCTION__);
|
||||
pthread_yield();
|
||||
|
||||
}
|
||||
|
||||
static void restart_thread(pthread_t *waiter, int cancelable)
|
||||
{
|
||||
int status;
|
||||
|
||||
/* Destroy the condition variable */
|
||||
|
||||
printf("%s: Destroying cond\n", __FUNCTION__);
|
||||
status = pthread_cond_destroy(&cond);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_cond_destroy failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Destroy the mutex */
|
||||
|
||||
printf("%s: Destroying mutex\n", __FUNCTION__);
|
||||
status = pthread_cond_destroy(&cond);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_destroy failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Then restart the thread */
|
||||
|
||||
printf("%s: Re-starting thread\n", __FUNCTION__);
|
||||
start_thread(waiter, cancelable);
|
||||
}
|
||||
|
||||
void cancel_test(void)
|
||||
{
|
||||
pthread_t waiter;
|
||||
void *result;
|
||||
int status;
|
||||
|
||||
/* Test 1: Normal Cancel *********************************************/
|
||||
/* Start the waiter thread */
|
||||
|
||||
printf("%s: Test 1: Normal Cancelation\n", __FUNCTION__);
|
||||
printf("%s: Starting thread\n", __FUNCTION__);
|
||||
start_thread(&waiter, 1);
|
||||
|
||||
/* Then cancel it. It should be in the pthread_cond_wait now */
|
||||
|
||||
printf("%s: Canceling thread\n", __FUNCTION__);
|
||||
status = pthread_cancel(waiter);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_cancel failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Then join to the thread to pick up the result */
|
||||
|
||||
printf("%s: Joining\n", __FUNCTION__);
|
||||
status = pthread_join(waiter, &result);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_join failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: waiter exited with result=%p\n", __FUNCTION__, result);
|
||||
if (result != PTHREAD_CANCELED)
|
||||
{
|
||||
printf("%s: ERROR expected result=%p\n", __FUNCTION__, PTHREAD_CANCELED);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: PASS thread terminated with PTHREAD_CANCELED\n", __FUNCTION__);
|
||||
}
|
||||
}
|
||||
|
||||
/* Test 2: Cancel Detached Thread ************************************/
|
||||
|
||||
printf("%s: Test 2: Cancelation of detached thread\n", __FUNCTION__);
|
||||
printf("%s: Re-starting thread\n", __FUNCTION__);
|
||||
restart_thread(&waiter, 1);
|
||||
|
||||
/* Detach the thread */
|
||||
|
||||
status = pthread_detach(waiter);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_detach, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Then cancel it. It should be in the pthread_cond_wait now */
|
||||
|
||||
printf("%s: Canceling thread\n", __FUNCTION__);
|
||||
status = pthread_cancel(waiter);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_cancel failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Join should now fail */
|
||||
|
||||
printf("%s: Joining\n", __FUNCTION__);
|
||||
status = pthread_join(waiter, &result);
|
||||
if (status == 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_join succeeded\n", __FUNCTION__);
|
||||
}
|
||||
else if (status != ESRCH)
|
||||
{
|
||||
printf("%s: ERROR pthread_join failed but with wrong status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: PASS pthread_join failed with status=ESRCH\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
/* Test 3: Non-cancelable threads ************************************/
|
||||
|
||||
printf("%s: Test 3: Non-cancelable threads\n", __FUNCTION__);
|
||||
printf("%s: Re-starting thread (non-cancelable)\n", __FUNCTION__);
|
||||
restart_thread(&waiter, 0);
|
||||
|
||||
/* Then cancel it. It should be in the pthread_cond_wait now. The
|
||||
* behavior here is non-standard: when the thread is at a cancelation
|
||||
* point, it should be cancelable, even when cancelation is disable.
|
||||
*
|
||||
* The cancelation should succeed, because the cancelation is pending.
|
||||
*/
|
||||
|
||||
printf("%s: Canceling thread\n", __FUNCTION__);
|
||||
status = pthread_cancel(waiter);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_cancel failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Signal the thread. It should wake up an restore the cancelable state.
|
||||
* When the cancelable state is re-enabled, the thread should be canceled.
|
||||
*/
|
||||
|
||||
status = pthread_mutex_lock(&mutex);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_lock failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
status = pthread_cond_signal(&cond);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_cond_signal failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
status = pthread_mutex_unlock(&mutex);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_unlock failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
}
|
284
examples/ostest/cond.c
Normal file
284
examples/ostest/cond.c
Normal file
|
@ -0,0 +1,284 @@
|
|||
/***********************************************************************
|
||||
* cond.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.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include "ostest.h"
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL (void*)0
|
||||
#endif
|
||||
|
||||
static volatile enum { RUNNING, MUTEX_WAIT, COND_WAIT} waiter_state;
|
||||
|
||||
static pthread_mutex_t mutex;
|
||||
static pthread_cond_t cond;
|
||||
static volatile int data_available = 0;
|
||||
static int waiter_nloops = 0;
|
||||
static int waiter_waits = 0;
|
||||
static int waiter_nerrors = 0;
|
||||
static int signaler_nloops = 0;
|
||||
static int signaler_already = 0;
|
||||
static int signaler_state = 0;
|
||||
static int signaler_nerrors = 0;
|
||||
|
||||
static void *thread_waiter(void *parameter)
|
||||
{
|
||||
int status;
|
||||
|
||||
printf("%s: Started\n", __FUNCTION__);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
/* Take the mutex */
|
||||
|
||||
waiter_state = MUTEX_WAIT;
|
||||
status = pthread_mutex_lock(&mutex);
|
||||
waiter_state = RUNNING;
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_lock failed, status=%d\n", __FUNCTION__, status);
|
||||
waiter_nerrors++;
|
||||
}
|
||||
|
||||
/* Check if data is available -- if data is not available then
|
||||
* wait for it
|
||||
*/
|
||||
|
||||
if (!data_available)
|
||||
{
|
||||
/* We are higher priority than the signaler thread so the
|
||||
* only time that the signaler thread will have a chance to run is when
|
||||
* we are waiting for the condition variable. In this case, pthread_cond_wait
|
||||
* will automatically release the mutex for the signaler (then re-acquire
|
||||
* the mutex before returning.
|
||||
*/
|
||||
|
||||
waiter_state = COND_WAIT;
|
||||
status = pthread_cond_wait(&cond, &mutex);
|
||||
waiter_state = RUNNING;
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_cond_wait failed, status=%d\n", __FUNCTION__, status);
|
||||
waiter_nerrors++;
|
||||
}
|
||||
waiter_waits++;
|
||||
}
|
||||
|
||||
/* Now data should be available */
|
||||
|
||||
if (!data_available)
|
||||
{
|
||||
printf("%s: ERROR data not available after wait\n", __FUNCTION__);
|
||||
waiter_nerrors++;
|
||||
}
|
||||
|
||||
/* Clear data available */
|
||||
|
||||
data_available = 0;
|
||||
|
||||
/* Release the mutex */
|
||||
|
||||
status = pthread_mutex_unlock(&mutex);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR waiter: pthread_mutex_unlock failed, status=%d\n", __FUNCTION__, status);
|
||||
waiter_nerrors++;
|
||||
}
|
||||
|
||||
waiter_nloops++;
|
||||
}
|
||||
}
|
||||
|
||||
static void *thread_signaler(void *parameter)
|
||||
{
|
||||
int status;
|
||||
int i;
|
||||
|
||||
printf("%s: Started\n", __FUNCTION__);
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
/* Take the mutex. The waiter is higher priority and should
|
||||
* run until it waits for the condition. So, at this point
|
||||
* signaler should be waiting for the condition.
|
||||
*/
|
||||
|
||||
status = pthread_mutex_lock(&mutex);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_lock failed, status=%d\n", __FUNCTION__, status);
|
||||
signaler_nerrors++;
|
||||
}
|
||||
|
||||
/* Verify the state */
|
||||
|
||||
if (waiter_state != COND_WAIT)
|
||||
{
|
||||
printf("%s: ERROR waiter state = %d != COND_WAITING\n", __FUNCTION__, waiter_state);
|
||||
signaler_state++;
|
||||
}
|
||||
|
||||
if (data_available)
|
||||
{
|
||||
printf("%s: ERROR data already available, waiter_state=%d\n", __FUNCTION__, waiter_state);
|
||||
signaler_already++;
|
||||
}
|
||||
|
||||
/* Set data available and signal the waiter */
|
||||
|
||||
data_available = 1;
|
||||
status = pthread_cond_signal(&cond);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_cond_signal failed, status=%d\n", __FUNCTION__, status);
|
||||
signaler_nerrors++;
|
||||
}
|
||||
|
||||
/* Release the mutex */
|
||||
|
||||
status = pthread_mutex_unlock(&mutex);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_unlock failed, status=%d\n", __FUNCTION__, status);
|
||||
signaler_nerrors++;
|
||||
}
|
||||
|
||||
signaler_nloops++;
|
||||
}
|
||||
|
||||
printf("%s: Terminating\n", __FUNCTION__);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
void cond_test(void)
|
||||
{
|
||||
pthread_t waiter;
|
||||
pthread_t signaler;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param sparam;
|
||||
int prio_min;
|
||||
int prio_max;
|
||||
int prio_mid;
|
||||
int status;
|
||||
|
||||
/* Initialize the mutex */
|
||||
|
||||
printf("%s: Initializing mutex\n", __FUNCTION__);
|
||||
status = pthread_mutex_init(&mutex, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Initialize the condition variable */
|
||||
|
||||
printf("%s: Initializing cond\n", __FUNCTION__);
|
||||
status = pthread_cond_init(&cond, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_condinit failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Start the waiter thread at higher priority */
|
||||
|
||||
printf("%s: Starting waiter\n", __FUNCTION__);
|
||||
status = pthread_attr_init(&attr);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
prio_min = sched_get_priority_min(SCHED_FIFO);
|
||||
prio_max = sched_get_priority_max(SCHED_FIFO);
|
||||
prio_mid = (prio_min + prio_max) / 2;
|
||||
|
||||
sparam.sched_priority = prio_mid;
|
||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: pthread_attr_setschedparam failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Set thread 1 priority to %d\n", __FUNCTION__, sparam.sched_priority);
|
||||
}
|
||||
|
||||
status = pthread_create(&waiter, &attr, thread_waiter, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_create failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
printf("%s: Starting signaler\n", __FUNCTION__);
|
||||
status = pthread_attr_init(&attr);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
sparam.sched_priority = (prio_min + prio_mid) / 2;
|
||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: pthread_attr_setschedparam failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Set thread 2 priority to %d\n", __FUNCTION__, sparam.sched_priority);
|
||||
}
|
||||
|
||||
status = pthread_create(&signaler, &attr, thread_signaler, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_create failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Wait for the threads to stop */
|
||||
|
||||
pthread_join(signaler, NULL);
|
||||
printf("%s: signaler terminated, now cancel the waiter\n", __FUNCTION__);
|
||||
pthread_detach(waiter);
|
||||
pthread_cancel(waiter);
|
||||
|
||||
printf("%s: \tWaiter\tSignaler\n", __FUNCTION__);
|
||||
printf("%s: Loops\t%d\t%d\n", __FUNCTION__, waiter_nloops, signaler_nloops);
|
||||
printf("%s: Errors\t%d\t%d\n", __FUNCTION__, waiter_nerrors, signaler_nerrors);
|
||||
printf("%s: \n%d times, waiter did not have to wait for data\n", __FUNCTION__, waiter_nloops - waiter_waits);
|
||||
printf("%s: %d times, data was already available when the signaler run\n", __FUNCTION__, signaler_already);
|
||||
printf("%s: %d times, the waiter was in an unexpected state when the signaler ran\n", __FUNCTION__, signaler_state);
|
||||
}
|
91
examples/ostest/dev_null.c
Normal file
91
examples/ostest/dev_null.c
Normal file
|
@ -0,0 +1,91 @@
|
|||
/************************************************************
|
||||
* dev_null.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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
#include <nuttx/os_external.h>
|
||||
#include "ostest.h"
|
||||
|
||||
/************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
static char buffer[1024];
|
||||
|
||||
/************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
|
||||
int dev_null(void)
|
||||
{
|
||||
int nbytes;
|
||||
int fd;
|
||||
|
||||
fd = open("/dev/null", O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: Failed to open /dev/null\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
nbytes = read(fd, buffer, 1024);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: Failed to read from /dev/null\n", __FUNCTION__);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
printf("%s: Read %d bytes from /dev/null\n", __FUNCTION__, nbytes);
|
||||
|
||||
nbytes = write(fd, buffer, 1024);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: Failed to write to /dev/null\n", __FUNCTION__);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
printf("%s: Wrote %d bytes to /dev/null\n", __FUNCTION__, nbytes);
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
178
examples/ostest/main.c
Normal file
178
examples/ostest/main.c
Normal file
|
@ -0,0 +1,178 @@
|
|||
/************************************************************
|
||||
* main.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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/os_external.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sched.h>
|
||||
#include "ostest.h"
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
#define PRIORITY 100
|
||||
#define STACKSIZE 8192
|
||||
#define NARGS 4
|
||||
|
||||
#define ARG1 "Arg1"
|
||||
#define ARG2 "Arg2"
|
||||
#define ARG3 "Arg3"
|
||||
#define ARG4 "Arg4"
|
||||
|
||||
/************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
static char write_data1[] = "Standard I/O Check: write fd=1\n";
|
||||
static char write_data2[] = "Standard I/O Check: write fd=2\n";
|
||||
static char *args[NARGS] = { ARG1, ARG2, ARG3, ARG4 };
|
||||
|
||||
/************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
static int user_main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("%s: Started with argc=%d\n", __FUNCTION__, argc);
|
||||
|
||||
/* Verify passed arguments */
|
||||
|
||||
if (argc != NARGS + 1)
|
||||
{
|
||||
fprintf(stderr, "%s: Error expected argc=%d got argc=%d\n",
|
||||
__FUNCTION__, NARGS+1, argc);
|
||||
}
|
||||
|
||||
for (i = 0; i <= NARGS; i++)
|
||||
{
|
||||
printf("%s: argv[%d]=\"%s\"\n", __FUNCTION__, i, argv[i]);
|
||||
}
|
||||
|
||||
for (i = 1; i <= NARGS; i++)
|
||||
{
|
||||
if (strcmp(argv[i], args[i-1]) != 0)
|
||||
{
|
||||
fprintf(stderr, "%s: ERROR argv[%d]: Expected \"%s\" found \"%s\"\n",
|
||||
__FUNCTION__, i, argv[i], args[i-1]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Checkout /dev/null */
|
||||
|
||||
dev_null();
|
||||
|
||||
/* Verify pthreads and pthread mutex */
|
||||
|
||||
mutex_test();
|
||||
|
||||
/* Verify pthread cancellation */
|
||||
|
||||
cancel_test();
|
||||
|
||||
/* Verify pthreads and semaphores */
|
||||
|
||||
sem_test();
|
||||
|
||||
/* Verify pthreads and condition variables */
|
||||
|
||||
cond_test();
|
||||
|
||||
/* Verify pthreads and condition variable timed waits */
|
||||
|
||||
timedwait_test();
|
||||
|
||||
/* Verify pthreads and message queues */
|
||||
|
||||
mqueue_test();
|
||||
|
||||
/* Verify signal handlers */
|
||||
|
||||
sighand_test();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* user_initialize
|
||||
************************************************************/
|
||||
|
||||
void user_initialize(void)
|
||||
{
|
||||
/* stub */
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* user_start
|
||||
************************************************************/
|
||||
|
||||
int user_start(int parm1, int parm2, int parm3, int parm4)
|
||||
{
|
||||
int result;
|
||||
|
||||
/* Verify that we can communicate */
|
||||
|
||||
write(1, write_data1, sizeof(write_data1));
|
||||
printf("%s: Standard I/O Check: printf\n", __FUNCTION__);
|
||||
write(2, write_data2, sizeof(write_data2));
|
||||
fprintf(stderr, "%s: Standard I/O Check: fprintf to stderr\n", __FUNCTION__);
|
||||
|
||||
/* Verify that we can spawn a new task */
|
||||
|
||||
result = task_create("ostest", PRIORITY, STACKSIZE, user_main,
|
||||
ARG1, ARG2, ARG3, ARG4);
|
||||
if (result == ERROR)
|
||||
{
|
||||
fprintf(stderr, "%s: Failed to start user_main\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Started user_main at PID=%d\n", __FUNCTION__, result);
|
||||
}
|
||||
return 0;
|
||||
}
|
333
examples/ostest/mqueue.c
Normal file
333
examples/ostest/mqueue.c
Normal file
|
@ -0,0 +1,333 @@
|
|||
/**************************************************************************
|
||||
* mqueue.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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <mqueue.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include "ostest.h"
|
||||
|
||||
/**************************************************************************
|
||||
* Private Definitions
|
||||
**************************************************************************/
|
||||
|
||||
#define TEST_MESSAGE "This is a test and only a test"
|
||||
#define TEST_MSGLEN (strlen(TEST_MESSAGE)+1)
|
||||
|
||||
/**************************************************************************
|
||||
* Private Types
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Private Function Prototypes
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Global Variables
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Private Variables
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Private Functions
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Public Functions
|
||||
**************************************************************************/
|
||||
|
||||
static void *sender_thread(void *arg)
|
||||
{
|
||||
mqd_t mqfd;
|
||||
char msg_buffer[TEST_MSGLEN];
|
||||
struct mq_attr attr;
|
||||
int status = 0;
|
||||
int nerrors = 0;
|
||||
int i;
|
||||
|
||||
printf("%s: Starting\n", __FUNCTION__);
|
||||
|
||||
/* Fill in attributes for message queue */
|
||||
|
||||
attr.mq_maxmsg = 20;
|
||||
attr.mq_msgsize = TEST_MSGLEN;
|
||||
attr.mq_flags = 0;
|
||||
|
||||
/* Set the flags for the open of the queue.
|
||||
* Make it a blocking open on the queue, meaning it will block if
|
||||
* this process tries to send to the queue and the queue is full.
|
||||
*
|
||||
* O_CREAT - the queue will get created if it does not already exist.
|
||||
* O_WRONLY - we are only planning to write to the queue.
|
||||
*
|
||||
* Open the queue, and create it if the receiving process hasn't
|
||||
* already created it.
|
||||
*/
|
||||
|
||||
mqfd = mq_open("testmq", O_WRONLY|O_CREAT, 0666, &attr);
|
||||
if (mqfd < 0)
|
||||
{
|
||||
printf("%s: ERROR mq_open failed\n", __FUNCTION__);
|
||||
pthread_exit((void*)1);
|
||||
}
|
||||
|
||||
/* Fill in a test message buffer to send */
|
||||
|
||||
memcpy(msg_buffer, TEST_MESSAGE, TEST_MSGLEN);
|
||||
|
||||
/* Perform the send 10 times */
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
status = mq_send(mqfd, msg_buffer, TEST_MSGLEN, 42);
|
||||
if (status < 0)
|
||||
{
|
||||
printf("%s: ERROR mq_send failure=%d on msg %d\n", __FUNCTION__, status, i);
|
||||
nerrors++;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: mq_send succeeded on msg %d\n", __FUNCTION__, i);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close the queue and return success */
|
||||
|
||||
if (mq_close(mqfd) < 0)
|
||||
{
|
||||
printf("%s: ERROR mq_close failed\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
printf("%s: returning nerrors=%d\n", __FUNCTION__, nerrors);
|
||||
return (void*)nerrors;
|
||||
}
|
||||
|
||||
static void *receiver_thread(void *arg)
|
||||
{
|
||||
mqd_t mqfd;
|
||||
char msg_buffer[TEST_MSGLEN];
|
||||
struct mq_attr attr;
|
||||
int nbytes;
|
||||
int nerrors = 0;
|
||||
int i;
|
||||
|
||||
printf("%s: Starting\n", __FUNCTION__);
|
||||
|
||||
/* Fill in attributes for message queue */
|
||||
|
||||
attr.mq_maxmsg = 20;
|
||||
attr.mq_msgsize = TEST_MSGLEN;
|
||||
attr.mq_flags = 0;
|
||||
|
||||
/* Set the flags for the open of the queue.
|
||||
* Make it a blocking open on the queue, meaning it will block if
|
||||
* this process tries to* send to the queue and the queue is full.
|
||||
*
|
||||
* O_CREAT - the queue will get created if it does not already exist.
|
||||
* O_RDONLY - we are only planning to write to the queue.
|
||||
*
|
||||
* Open the queue, and create it if the sending process hasn't
|
||||
* already created it.
|
||||
*/
|
||||
|
||||
mqfd = mq_open("testmq", O_RDONLY|O_CREAT, 0666, &attr);
|
||||
if (mqfd < 0)
|
||||
{
|
||||
printf("%s: ERROR mq_open failed\n", __FUNCTION__);
|
||||
pthread_exit((void*)1);
|
||||
}
|
||||
|
||||
/* Perform the receive 10 times */
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
nbytes = mq_receive(mqfd, msg_buffer, TEST_MSGLEN, 0);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
printf("%s: ERROR mq_receive failure on msg %d\n", __FUNCTION__, i);
|
||||
nerrors++;
|
||||
}
|
||||
else if (nbytes != TEST_MSGLEN)
|
||||
{
|
||||
printf("%s: mq_receive return bad size %d on msg %d\n", __FUNCTION__, nbytes, i);
|
||||
nerrors++;
|
||||
}
|
||||
else if (memcmp(TEST_MESSAGE, msg_buffer, nbytes) != 0)
|
||||
{
|
||||
int j;
|
||||
|
||||
printf("%s: mq_receive returned corrupt message on msg %d\n", __FUNCTION__, i);
|
||||
printf("%s: i Expected Received\n", __FUNCTION__);
|
||||
|
||||
for (j = 0; j < TEST_MSGLEN-1; j++)
|
||||
{
|
||||
printf("%s: %2d %02x (%c) %02x\n",
|
||||
__FUNCTION__,
|
||||
j, TEST_MESSAGE[j], TEST_MESSAGE[j], msg_buffer[j] & 0x0ff);
|
||||
}
|
||||
printf("%s: %2d 00 %02x\n",
|
||||
__FUNCTION__, j, msg_buffer[j] & 0xff);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: mq_receive succeeded on msg %d\n", __FUNCTION__, i);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close the queue and return success */
|
||||
|
||||
if (mq_close(mqfd) < 0)
|
||||
{
|
||||
printf("%s: ERROR mq_close failed\n", __FUNCTION__);
|
||||
nerrors++;
|
||||
}
|
||||
|
||||
pthread_exit((void*)nerrors);
|
||||
|
||||
/* Destroy the queue */
|
||||
|
||||
if (mq_unlink("testmq") < 0)
|
||||
{
|
||||
printf("%s: ERROR mq_close failed\n", __FUNCTION__);
|
||||
nerrors++;
|
||||
}
|
||||
|
||||
printf("%s: returning nerrors=%d\n", __FUNCTION__, nerrors);
|
||||
return (void*)nerrors;
|
||||
}
|
||||
|
||||
void mqueue_test(void)
|
||||
{
|
||||
pthread_t sender;
|
||||
pthread_t receiver;
|
||||
void *result;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param sparam;
|
||||
int prio_min;
|
||||
int prio_max;
|
||||
int prio_mid;
|
||||
int status;
|
||||
|
||||
/* Start the sending thread at higher priority */
|
||||
|
||||
printf("%s: Starting receiver\n", __FUNCTION__);
|
||||
status = pthread_attr_init(&attr);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
status = pthread_attr_setstacksize(&attr, 16384);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_setstacksize failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
prio_min = sched_get_priority_min(SCHED_FIFO);
|
||||
prio_max = sched_get_priority_max(SCHED_FIFO);
|
||||
prio_mid = (prio_min + prio_max) / 2;
|
||||
|
||||
sparam.sched_priority = prio_mid;
|
||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: pthread_attr_setschedparam failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Set receiver priority to %d\n", __FUNCTION__, sparam.sched_priority);
|
||||
}
|
||||
|
||||
status = pthread_create(&receiver, &attr, receiver_thread, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_create failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Start the sending thread at lower priority */
|
||||
|
||||
printf("%s: Starting sender\n", __FUNCTION__);
|
||||
status = pthread_attr_init(&attr);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
status = pthread_attr_setstacksize(&attr, 16384);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_setstacksize failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
sparam.sched_priority = (prio_min + prio_mid) / 2;
|
||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: pthread_attr_setschedparam failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Set sender thread priority to %d\n", __FUNCTION__, sparam.sched_priority);
|
||||
}
|
||||
|
||||
status = pthread_create(&sender, &attr, sender_thread, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_create failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
pthread_join(sender, &result);
|
||||
if (result != (void*)0)
|
||||
{
|
||||
printf("%s: ERROR sender thread exited with %d errors\n", __FUNCTION__, (int)result);
|
||||
}
|
||||
|
||||
pthread_cancel(receiver);
|
||||
pthread_join(receiver, &result);
|
||||
if (result != (void*)0)
|
||||
{
|
||||
printf("%s: ERROR receiver thread exited with %d errors\n", __FUNCTION__, (int)result);
|
||||
}
|
||||
}
|
||||
|
||||
|
120
examples/ostest/mutex.c
Normal file
120
examples/ostest/mutex.c
Normal file
|
@ -0,0 +1,120 @@
|
|||
/***********************************************************************
|
||||
* mutex.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.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include "ostest.h"
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL (void*)0
|
||||
#endif
|
||||
|
||||
#define NLOOPS 32
|
||||
|
||||
static pthread_mutex_t mut;
|
||||
static volatile int my_mutex = 0;
|
||||
static unsigned long nloops[2] = {0, 0};
|
||||
static unsigned long nerrors[2] = {0, 0};
|
||||
|
||||
static void *thread_func(void *parameter)
|
||||
{
|
||||
int id = (int)parameter;
|
||||
int ndx = id - 1;
|
||||
int i;
|
||||
|
||||
for (nloops[ndx] = 0; nloops[ndx] < NLOOPS; nloops[ndx]++)
|
||||
{
|
||||
int status = pthread_mutex_lock(&mut);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("ERROR thread %d: pthread_mutex_lock failed, status=%d\n",
|
||||
id, status);
|
||||
}
|
||||
|
||||
if (my_mutex == 1)
|
||||
{
|
||||
printf("ERROR thread=%d: "
|
||||
"my_mutex should be zero, instead my_mutex=%d\n",
|
||||
id, my_mutex);
|
||||
nerrors[ndx]++;
|
||||
}
|
||||
|
||||
my_mutex = 1;
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
pthread_yield();
|
||||
}
|
||||
my_mutex = 0;
|
||||
|
||||
status = pthread_mutex_unlock(&mut);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("ERROR thread %d: pthread_mutex_unlock failed, status=%d\n",
|
||||
id, status);
|
||||
}
|
||||
}
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
void mutex_test(void)
|
||||
{
|
||||
pthread_t thread1, thread2;
|
||||
|
||||
/* Initialize the mutex */
|
||||
|
||||
printf("Initializing mutex\n");
|
||||
pthread_mutex_init(&mut, NULL);
|
||||
|
||||
/* Start two thread instances */
|
||||
|
||||
printf("Starting thread 1\n");
|
||||
if ((pthread_create(&thread1, NULL, thread_func, (void*)1)) != 0)
|
||||
{
|
||||
printf("Error in thread#1 creation\n");
|
||||
}
|
||||
|
||||
printf("Starting thread 2\n");
|
||||
if ((pthread_create(&thread2, NULL, thread_func, (void*)2)) != 0)
|
||||
{
|
||||
printf("Error in thread#2 creation\n");
|
||||
}
|
||||
|
||||
pthread_join(thread1, NULL);
|
||||
pthread_join(thread2, NULL);
|
||||
|
||||
printf("%s:\t\tThread1\tThread2\n", __FUNCTION__);
|
||||
printf("%s:\tLoops\t%ld\t%ld\n", __FUNCTION__, nloops[0], nloops[1]);
|
||||
printf("%s:\tErrors\t%ld\t%ld\n", __FUNCTION__, nerrors[0], nerrors[1]);
|
||||
}
|
91
examples/ostest/ostest.h
Normal file
91
examples/ostest/ostest.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
/************************************************************
|
||||
* ostest.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 __OSTEST_H
|
||||
#define __OSTEST_H
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Types
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Variables
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
/* dev_null.c ***********************************************/
|
||||
|
||||
extern int dev_null(void);
|
||||
|
||||
/* mutex.c **************************************************/
|
||||
|
||||
extern void mutex_test(void);
|
||||
|
||||
/* sem.c ****************************************************/
|
||||
|
||||
extern void sem_test(void);
|
||||
|
||||
/* cond.c ***************************************************/
|
||||
|
||||
extern void cond_test(void);
|
||||
|
||||
/* queue.c **************************************************/
|
||||
|
||||
extern void mqueue_test(void);
|
||||
|
||||
/* cancel.c *************************************************/
|
||||
|
||||
extern void cancel_test(void);
|
||||
|
||||
/* timedwait.c **********************************************/
|
||||
|
||||
extern void timedwait_test(void);
|
||||
|
||||
#endif /* __OSTEST_H */
|
238
examples/ostest/sem.c
Normal file
238
examples/ostest/sem.c
Normal file
|
@ -0,0 +1,238 @@
|
|||
/***********************************************************************
|
||||
* sem.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.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <sched.h>
|
||||
#include "ostest.h"
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL (void*)0
|
||||
#endif
|
||||
|
||||
static sem_t sem;
|
||||
|
||||
static void *waiter_func(void *parameter)
|
||||
{
|
||||
int id = (int)parameter;
|
||||
int status;
|
||||
int value;
|
||||
|
||||
printf("%s: Thread %d Started\n", __FUNCTION__, id);
|
||||
|
||||
/* Take the semaphore */
|
||||
|
||||
status = sem_getvalue(&sem, &value);
|
||||
if (status < 0)
|
||||
{
|
||||
printf("%s: ERROR thread %d could not get semaphore value\n", __FUNCTION__, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Thread %d initial semaphore value = %d\n", __FUNCTION__, id, value);
|
||||
}
|
||||
|
||||
printf("%s: Thread %d aiting on semaphore\n", __FUNCTION__, id);
|
||||
status = sem_wait(&sem);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR thread %d sem_wait failed\n", __FUNCTION__, id);
|
||||
}
|
||||
printf("%s: Thread %d awakened\n", __FUNCTION__, id);
|
||||
|
||||
status = sem_getvalue(&sem, &value);
|
||||
if (status < 0)
|
||||
{
|
||||
printf("%s: ERROR thread %d could not get semaphore value\n", __FUNCTION__, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Thread %d new semaphore value = %d\n", __FUNCTION__, id, value);
|
||||
}
|
||||
|
||||
printf("%s: Thread %d done\n", __FUNCTION__, id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *poster_func(void *parameter)
|
||||
{
|
||||
int id = (int)parameter;
|
||||
int status;
|
||||
int value;
|
||||
|
||||
printf("%s: Thread %d started\n", __FUNCTION__, id);
|
||||
|
||||
/* Take the semaphore */
|
||||
|
||||
do
|
||||
{
|
||||
status = sem_getvalue(&sem, &value);
|
||||
if (status < 0)
|
||||
{
|
||||
printf("%s: ERROR thread %d could not get semaphore value\n", __FUNCTION__, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Thread %d semaphore value = %d\n", __FUNCTION__, id, value);
|
||||
}
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
printf("%s: Thread %d posting semaphore\n", __FUNCTION__, id);
|
||||
status = sem_post(&sem);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR thread %d sem_wait failed\n", __FUNCTION__, id);
|
||||
}
|
||||
|
||||
pthread_yield();
|
||||
|
||||
status = sem_getvalue(&sem, &value);
|
||||
if (status < 0)
|
||||
{
|
||||
printf("%s: ERROR thread %d could not get semaphore value\n", __FUNCTION__, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Thread %d new semaphore value = %d\n", __FUNCTION__, id, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (value < 0);
|
||||
|
||||
printf("%s: Thread %d done\n", __FUNCTION__, id);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void sem_test(void)
|
||||
{
|
||||
pthread_t waiter_thread1;
|
||||
pthread_t waiter_thread2;
|
||||
pthread_t poster_thread;
|
||||
struct sched_param sparam;
|
||||
int prio_min;
|
||||
int prio_max;
|
||||
int prio_mid;
|
||||
pthread_attr_t attr;
|
||||
int status;
|
||||
|
||||
printf("%s: Initializing semaphore to 0\n", __FUNCTION__);
|
||||
sem_init(&sem, 0, 0);
|
||||
|
||||
/* Start two waiter thread instances */
|
||||
|
||||
printf("%s: Starting waiter thread 1\n", __FUNCTION__);
|
||||
status = pthread_attr_init(&attr);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: pthread_attr_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
prio_min = sched_get_priority_min(SCHED_FIFO);
|
||||
prio_max = sched_get_priority_max(SCHED_FIFO);
|
||||
prio_mid = (prio_min + prio_max) / 2;
|
||||
|
||||
sparam.sched_priority = (prio_mid + prio_max) / 2;
|
||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: pthread_attr_setschedparam failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Set thread 1 priority to %d\n", __FUNCTION__, sparam.sched_priority);
|
||||
}
|
||||
|
||||
status = pthread_create(&waiter_thread1, &attr, waiter_func, (void*)1);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: Error in thread 1 creation, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
printf("%s: Starting waiter thread 2\n", __FUNCTION__);
|
||||
status = pthread_attr_init(&attr);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
sparam.sched_priority = prio_mid;
|
||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: pthread_attr_setschedparam failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Set thread 2 priority to %d\n", __FUNCTION__, sparam.sched_priority);
|
||||
}
|
||||
|
||||
status = pthread_create(&waiter_thread2, &attr, waiter_func, (void*)2);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: Error in thread 2 creation, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
printf("%s: Starting poster thread 3\n", __FUNCTION__);
|
||||
status = pthread_attr_init(&attr);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
sparam.sched_priority = (prio_min + prio_mid) / 2;
|
||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: pthread_attr_setschedparam failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Set thread 3 priority to %d\n", __FUNCTION__, sparam.sched_priority);
|
||||
}
|
||||
|
||||
status = pthread_create(&poster_thread, &attr, poster_func, (void*)3);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: Error in thread 3 creation, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
pthread_join(waiter_thread1, NULL);
|
||||
pthread_join(waiter_thread2, NULL);
|
||||
pthread_join(poster_thread, NULL);
|
||||
}
|
254
examples/ostest/sighand.c
Normal file
254
examples/ostest/sighand.c
Normal file
|
@ -0,0 +1,254 @@
|
|||
/***********************************************************************
|
||||
* sighand.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.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include "ostest.h"
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL (void*)0
|
||||
#endif
|
||||
|
||||
#define WAKEUP_SIGNAL 17
|
||||
#define SIGVALUE_INT 42
|
||||
|
||||
static sem_t sem;
|
||||
static boolean sigreceived = FALSE;
|
||||
static boolean threadexited = FALSE;
|
||||
|
||||
static void wakeup_action(int signo, siginfo_t *info, void *ucontext)
|
||||
{
|
||||
sigset_t oldset;
|
||||
sigset_t allsigs;
|
||||
int status;
|
||||
|
||||
printf("%s: Received signal %d\n", __FUNCTION__, signo);
|
||||
|
||||
sigreceived = TRUE;
|
||||
|
||||
/* Check signo */
|
||||
|
||||
if (signo != WAKEUP_SIGNAL)
|
||||
{
|
||||
printf("%s: ERROR expected signo=%d\n", __FUNCTION__, WAKEUP_SIGNAL);
|
||||
}
|
||||
|
||||
/* Check siginfo */
|
||||
|
||||
if (info->si_value.sival_int != SIGVALUE_INT)
|
||||
{
|
||||
printf("%s: ERROR sival_int=%d expected %d\n",
|
||||
__FUNCTION__, info->si_value.sival_int, SIGVALUE_INT);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: sival_int=%d\n", __FUNCTION__, info->si_value.sival_int);
|
||||
}
|
||||
|
||||
if (info->si_signo != WAKEUP_SIGNAL)
|
||||
{
|
||||
printf("%s: ERROR expected si_signo=%d, got=%d\n",
|
||||
__FUNCTION__, WAKEUP_SIGNAL, info->si_signo);
|
||||
}
|
||||
|
||||
printf("%s: si_code=%d\n", __FUNCTION__, info->si_code);
|
||||
|
||||
/* Check ucontext_t */
|
||||
|
||||
printf("%s: ucontext=%p\n", __FUNCTION__, ucontext);
|
||||
|
||||
/* Check sigprocmask */
|
||||
|
||||
(void)sigfillset(&allsigs);
|
||||
status = sigprocmask(SIG_SETMASK, NULL, &oldset);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: ERROR sigprocmask failed, status=%d\n",
|
||||
__FUNCTION__, status);
|
||||
}
|
||||
|
||||
if (oldset != allsigs)
|
||||
{
|
||||
printf("%s: ERROR sigprocmask=%x expected=%x\n",
|
||||
__FUNCTION__, oldset, allsigs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int waiter_main(int argc, char *argv[])
|
||||
{
|
||||
sigset_t sigset;
|
||||
struct sigaction act;
|
||||
struct sigaction oact;
|
||||
int status;
|
||||
|
||||
printf("%s: Waiter started\n", __FUNCTION__);
|
||||
|
||||
printf("%s: Unmasking signal %d\n", __FUNCTION__, WAKEUP_SIGNAL);
|
||||
(void)sigemptyset(&sigset);
|
||||
(void)sigaddset(&sigset, WAKEUP_SIGNAL);
|
||||
status = sigprocmask(SIG_UNBLOCK, &sigset, NULL);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: ERROR sigprocmask failed, status=%d\n",
|
||||
__FUNCTION__, status);
|
||||
}
|
||||
|
||||
printf("%s: Registering signal handler\n", __FUNCTION__);
|
||||
act.sa_sigaction = wakeup_action;
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
|
||||
(void)sigfillset(&act.sa_mask);
|
||||
(void)sigdelset(&act.sa_mask, WAKEUP_SIGNAL);
|
||||
|
||||
status = sigaction(WAKEUP_SIGNAL, &act, &oact);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: ERROR sigaction failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
printf("%s: oact.sigaction=%p oact.sa_flags=%x oact.sa_mask=%x\n",
|
||||
__FUNCTION__, oact.sa_sigaction, oact.sa_flags, oact.sa_mask);
|
||||
|
||||
/* Take the semaphore */
|
||||
|
||||
printf("%s: Waiting on semaphore\n", __FUNCTION__);
|
||||
fflush(stdout);
|
||||
status = sem_wait(&sem);
|
||||
if (status != 0)
|
||||
{
|
||||
int error = *get_errno_ptr();
|
||||
if (error == EINTR)
|
||||
{
|
||||
printf("%s: sem_wait() successfully interrupted by signal\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: ERROR sem_wait failed, errno=%d\n", __FUNCTION__, error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: ERROR awakened with no error!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
printf("%s: done\n", __FUNCTION__);
|
||||
fflush(stdout);
|
||||
threadexited = TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sighand_test(void)
|
||||
{
|
||||
struct sched_param param;
|
||||
union sigval sigvalue;
|
||||
pid_t waiterpid;
|
||||
int policy;
|
||||
int status;
|
||||
|
||||
printf("%s: Initializing semaphore to 0\n", __FUNCTION__);
|
||||
sem_init(&sem, 0, 0);
|
||||
|
||||
/* Start waiter thread */
|
||||
|
||||
printf("%s: Starting waiter task\n", __FUNCTION__);
|
||||
|
||||
|
||||
status = sched_getparam (0, ¶m);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: ERROR sched_getparam() failed\n", __FUNCTION__);
|
||||
param.sched_priority = PTHREAD_DEFAULT_PRIORITY;
|
||||
}
|
||||
|
||||
policy = sched_getscheduler(0);
|
||||
if (policy == ERROR)
|
||||
{
|
||||
printf("%s: ERROR sched_getscheduler() failed\n", __FUNCTION__);
|
||||
policy = SCHED_FIFO;
|
||||
}
|
||||
|
||||
waiterpid = task_create("waiter", param.sched_priority,
|
||||
PTHREAD_STACK_DEFAULT, waiter_main, 0, 0, 0, 0);
|
||||
if (waiterpid == ERROR)
|
||||
{
|
||||
printf("%s: ERROR failed to start waiter_main\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Started waiter_main pid=%d\n", __FUNCTION__, waiterpid);
|
||||
}
|
||||
|
||||
/* Wait a bit */
|
||||
|
||||
fflush(stdout);
|
||||
usleep(500*1000);
|
||||
|
||||
/* Then signal the waiter thread. */
|
||||
|
||||
sigvalue.sival_int = SIGVALUE_INT;
|
||||
status = sigqueue(waiterpid, WAKEUP_SIGNAL, sigvalue);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: ERROR sigqueue failed\n", __FUNCTION__);
|
||||
task_delete(waiterpid);
|
||||
}
|
||||
|
||||
/* Wait a bit */
|
||||
|
||||
fflush(stdout);
|
||||
usleep(500*1000);
|
||||
|
||||
/* Then check the result */
|
||||
|
||||
if (!threadexited)
|
||||
{
|
||||
printf("%s: ERROR waiter task did not exit\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
if (!sigreceived)
|
||||
{
|
||||
printf("%s: ERROR signal handler did not run\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
printf("%s: done\n", __FUNCTION__);
|
||||
fflush(stdout);
|
||||
}
|
161
examples/ostest/timedwait.c
Normal file
161
examples/ostest/timedwait.c
Normal file
|
@ -0,0 +1,161 @@
|
|||
/***********************************************************************
|
||||
* timedwait.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.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include "ostest.h"
|
||||
|
||||
static pthread_mutex_t mutex;
|
||||
static pthread_cond_t cond;
|
||||
|
||||
static void *thread_waiter(void *parameter)
|
||||
{
|
||||
struct timespec time;
|
||||
int status;
|
||||
|
||||
/* Take the mutex */
|
||||
|
||||
printf("%s: Taking mutex\n", __FUNCTION__);
|
||||
status = pthread_mutex_lock(&mutex);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_lock failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
printf("%s: Starting 5 second wait for condition\n", __FUNCTION__);
|
||||
|
||||
status = clock_gettime(CLOCK_REALTIME, &time);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR clock_gettime failed\n", __FUNCTION__);
|
||||
}
|
||||
time.tv_sec += 5;
|
||||
|
||||
/* The wait -- no-one is ever going to awaken us */
|
||||
|
||||
status = pthread_cond_timedwait(&cond, &mutex, &time);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_cond_timedwait failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Release the mutex */
|
||||
|
||||
printf("%s: Releasing mutex\n", __FUNCTION__);
|
||||
status = pthread_mutex_unlock(&mutex);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_unlock failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
printf("%s: Exit with status 0x12345678\n", __FUNCTION__);
|
||||
pthread_exit((void*)0x12345678);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void timedwait_test(void)
|
||||
{
|
||||
pthread_t waiter;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param sparam;
|
||||
void *result;
|
||||
int prio_max;
|
||||
int status;
|
||||
|
||||
/* Initialize the mutex */
|
||||
|
||||
printf("%s: Initializing mutex\n", __FUNCTION__);
|
||||
status = pthread_mutex_init(&mutex, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_mutex_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Initialize the condition variable */
|
||||
|
||||
printf("%s: Initializing cond\n", __FUNCTION__);
|
||||
status = pthread_cond_init(&cond, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_condinit failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
/* Start the waiter thread at higher priority */
|
||||
|
||||
printf("%s: Starting waiter\n", __FUNCTION__);
|
||||
status = pthread_attr_init(&attr);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_attr_init failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
prio_max = sched_get_priority_max(SCHED_FIFO);
|
||||
status = sched_getparam (getpid(), &sparam);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: sched_getparam failed\n", __FUNCTION__);
|
||||
sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY;
|
||||
}
|
||||
|
||||
sparam.sched_priority = (prio_max + sparam.sched_priority) / 2;
|
||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
||||
if (status != OK)
|
||||
{
|
||||
printf("%s: pthread_attr_setschedparam failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: Set thread 2 priority to %d\n", __FUNCTION__, sparam.sched_priority);
|
||||
}
|
||||
|
||||
status = pthread_create(&waiter, &attr, thread_waiter, NULL);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: pthread_create failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
printf("%s: Joining\n", __FUNCTION__);
|
||||
status = pthread_join(waiter, &result);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("%s: ERROR pthread_join failed, status=%d\n", __FUNCTION__, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: waiter exited with result=%p\n", __FUNCTION__, result);
|
||||
}
|
||||
}
|
75
fs/Makefile
Normal file
75
fs/Makefile
Normal file
|
@ -0,0 +1,75 @@
|
|||
############################################################
|
||||
# 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
|
||||
|
||||
ASRCS =
|
||||
AOBJS = $(ASRCS:.S=.o)
|
||||
|
||||
CSRCS = fs_open.c fs_close.c fs_read.c fs_write.c fs_ioctl.c fs_dup.c \
|
||||
fs_files.c fs_inode.c
|
||||
COBJS = $(CSRCS:.c=.o)
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
BIN = libfs.a
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
$(AOBJS): %.o: %.S
|
||||
$(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@
|
||||
|
||||
$(cOBJS): %.o: %.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(BIN): $(OBJS)
|
||||
$(AR) rcs $@ $(OBJS)
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
rm -f $(BIN) *.o *~
|
||||
|
||||
distclean: clean
|
||||
rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
88
fs/fs_close.c
Normal file
88
fs/fs_close.c
Normal file
|
@ -0,0 +1,88 @@
|
|||
/************************************************************
|
||||
* fs_close.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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS >0
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs.h>
|
||||
|
||||
#include "fs_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Global Functions
|
||||
************************************************************/
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
struct filelist *list;
|
||||
|
||||
/* Get the thread-specific file list */
|
||||
|
||||
list = sched_getfiles();
|
||||
if (!list)
|
||||
{
|
||||
*get_errno_ptr() = EMFILE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
|
||||
{
|
||||
struct inode *inode = list->fl_files[fd].f_inode;
|
||||
if (inode)
|
||||
{
|
||||
files_release(fd);
|
||||
inode_release(inode);
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
*get_errno_ptr() = EBADF;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS */
|
158
fs/fs_dup.c
Normal file
158
fs/fs_dup.c
Normal file
|
@ -0,0 +1,158 @@
|
|||
/************************************************************
|
||||
* fs_dup.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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include "fs_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
static inline boolean dup_isopen(int fd, struct filelist *list)
|
||||
{
|
||||
if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS ||
|
||||
list->fl_files[fd].f_inode == NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Global Functions
|
||||
************************************************************/
|
||||
|
||||
int dup(int fildes)
|
||||
{
|
||||
struct filelist *list;
|
||||
int fildes2;
|
||||
|
||||
/* Get the thread-specific file list */
|
||||
|
||||
list = sched_getfiles();
|
||||
if (!list)
|
||||
{
|
||||
*get_errno_ptr() = EMFILE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Verify that fildes is a valid, open file descriptor */
|
||||
|
||||
if (!dup_isopen(fildes, list))
|
||||
{
|
||||
*get_errno_ptr() = EBADF;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Increment the reference count on the contained inode */
|
||||
|
||||
inode_addref(list->fl_files[fildes].f_inode);
|
||||
|
||||
/* Then allocate a new file descriptor for the inode */
|
||||
|
||||
fildes2 = files_allocate(list->fl_files[fildes].f_inode,
|
||||
list->fl_files[fildes].f_oflags,
|
||||
list->fl_files[fildes].f_pos);
|
||||
if (fildes2 < 0)
|
||||
{
|
||||
*get_errno_ptr() = EMFILE;
|
||||
inode_release(list->fl_files[fildes].f_inode);
|
||||
return ERROR;
|
||||
}
|
||||
return fildes2;
|
||||
}
|
||||
|
||||
int dup2(int fildes1, int fildes2)
|
||||
{
|
||||
struct filelist *list;
|
||||
|
||||
/* Get the thread-specific file list */
|
||||
|
||||
list = sched_getfiles();
|
||||
if (!list)
|
||||
{
|
||||
*get_errno_ptr() = EMFILE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Verify that fildes is a valid, open file descriptor */
|
||||
|
||||
if (!dup_isopen(fildes1, list))
|
||||
{
|
||||
*get_errno_ptr() = EBADF;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Handle a special case */
|
||||
|
||||
if (fildes1 == fildes2)
|
||||
{
|
||||
return fildes1;
|
||||
}
|
||||
|
||||
/* Verify fildes2 */
|
||||
|
||||
if ((unsigned int)fildes2 >= CONFIG_NFILE_DESCRIPTORS)
|
||||
{
|
||||
*get_errno_ptr() = EBADF;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return files_dup(&list->fl_files[fildes1], &list->fl_files[fildes2]);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS */
|
273
fs/fs_files.c
Normal file
273
fs/fs_files.c
Normal file
|
@ -0,0 +1,273 @@
|
|||
/************************************************************
|
||||
* fs_files.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>
|
||||
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS >0
|
||||
|
||||
#include <string.h>
|
||||
#include <semaphore.h>
|
||||
#include <assert.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/fs.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include "fs_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Types
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Variables
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Variables
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
static void _files_semtake(struct filelist *list)
|
||||
{
|
||||
/* Take the semaphore (perhaps waiting) */
|
||||
|
||||
while (sem_wait(&list->fl_sem) != 0)
|
||||
{
|
||||
/* The only case that an error should occr here is if
|
||||
* the wait was awakened by a signal.
|
||||
*/
|
||||
|
||||
ASSERT(*get_errno_ptr() == EINTR);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void _files_semgive(struct filelist *list)
|
||||
{
|
||||
sem_post(&list->fl_sem);
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Pulblic Functions
|
||||
************************************************************/
|
||||
|
||||
/* This is called from the FS initialization logic to configure
|
||||
* the files.
|
||||
*/
|
||||
|
||||
void files_initialize(void)
|
||||
{
|
||||
}
|
||||
|
||||
/* Allocate a list of files for a new task */
|
||||
|
||||
struct filelist *files_alloclist(void)
|
||||
{
|
||||
struct filelist *list;
|
||||
list = (struct filelist*)kzmalloc(sizeof(struct filelist));
|
||||
if (list)
|
||||
{
|
||||
/* Start with a reference count of one */
|
||||
|
||||
list->fl_crefs = 1;
|
||||
|
||||
/* Initialize the list access mutex */
|
||||
|
||||
(void)sem_init(&list->fl_sem, 0, 1);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/* Increase the reference count on a file list */
|
||||
|
||||
int files_addreflist(struct filelist *list)
|
||||
{
|
||||
if (list)
|
||||
{
|
||||
/* Increment the reference count on the list */
|
||||
|
||||
_files_semtake(list);
|
||||
list->fl_crefs++;
|
||||
_files_semgive(list);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Release a reference to the file list */
|
||||
|
||||
int files_releaselist(struct filelist *list)
|
||||
{
|
||||
int crefs;
|
||||
if (list)
|
||||
{
|
||||
/* Decrement the reference count */
|
||||
|
||||
_files_semtake(list);
|
||||
crefs = --list->fl_crefs;
|
||||
_files_semgive(list);
|
||||
|
||||
/* If the count decrements to zero, then there is no reference
|
||||
* to the structure and it should be deallocated.
|
||||
*/
|
||||
|
||||
if (crefs <= 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* close each file descriptor */
|
||||
|
||||
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
|
||||
{
|
||||
struct inode *inode = list->fl_files[i].f_inode;
|
||||
if (inode)
|
||||
{
|
||||
inode_release(inode);
|
||||
}
|
||||
}
|
||||
|
||||
/* Destroy the semaphore and release the filelist */
|
||||
|
||||
(void)sem_destroy(&list->fl_sem);
|
||||
sched_free(list);
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Assign an inode to a specific files structure. this is the
|
||||
* heart of dup2.
|
||||
*/
|
||||
|
||||
int files_dup(struct file *filep1, struct file *filep2)
|
||||
{
|
||||
struct filelist *list;
|
||||
|
||||
if (!filep1 || !filep1->f_inode || !filep2)
|
||||
{
|
||||
*get_errno_ptr() = EBADF;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
list = sched_getfiles();
|
||||
if (!list)
|
||||
{
|
||||
*get_errno_ptr() = EMFILE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
_files_semtake(list);
|
||||
|
||||
/* If there is already an inode contained in the new file structure,
|
||||
* release it (effectively closing the file).
|
||||
*/
|
||||
|
||||
if (filep2->f_inode)
|
||||
{
|
||||
inode_release(filep2->f_inode);
|
||||
}
|
||||
|
||||
/* Increment the reference count on the contained inode */
|
||||
|
||||
inode_addref(filep1->f_inode);
|
||||
|
||||
/* Then clone the file structure */
|
||||
|
||||
filep2->f_oflags = filep1->f_oflags;
|
||||
filep2->f_pos = filep1->f_pos;
|
||||
filep2->f_inode = filep1->f_inode;
|
||||
_files_semgive(list);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Allocate a struct files instance and associate it with an
|
||||
* inode instance. Returns the file descriptor == index into
|
||||
* the files array.
|
||||
*/
|
||||
|
||||
int files_allocate(struct inode *inode, int oflags, off_t pos)
|
||||
{
|
||||
struct filelist *list;
|
||||
int i;
|
||||
|
||||
list = sched_getfiles();
|
||||
if (list)
|
||||
{
|
||||
_files_semtake(list);
|
||||
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
|
||||
{
|
||||
if (!list->fl_files[i].f_inode)
|
||||
{
|
||||
list->fl_files[i].f_oflags = oflags;
|
||||
list->fl_files[i].f_pos = pos;
|
||||
list->fl_files[i].f_inode = inode;
|
||||
_files_semgive(list);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
_files_semgive(list);
|
||||
}
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
void files_release(int filedes)
|
||||
{
|
||||
struct filelist *list;
|
||||
|
||||
list = sched_getfiles();
|
||||
if (list)
|
||||
{
|
||||
if (filedes >=0 && filedes < CONFIG_NFILE_DESCRIPTORS)
|
||||
{
|
||||
_files_semtake(list);
|
||||
list->fl_files[filedes].f_oflags = 0;
|
||||
list->fl_files[filedes].f_pos = 0;
|
||||
list->fl_files[filedes].f_inode = NULL;
|
||||
_files_semgive(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS */
|
568
fs/fs_inode.c
Normal file
568
fs/fs_inode.c
Normal file
|
@ -0,0 +1,568 @@
|
|||
/************************************************************
|
||||
* fs_inode.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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs.h>
|
||||
#include "fs_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Private types
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Variables
|
||||
************************************************************/
|
||||
|
||||
static sem_t tree_sem;
|
||||
|
||||
/************************************************************
|
||||
* Public Variables
|
||||
************************************************************/
|
||||
|
||||
struct inode *root_inode = NULL;
|
||||
|
||||
/************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
static void _inode_semtake(void)
|
||||
{
|
||||
/* Take the semaphore (perhaps waiting) */
|
||||
|
||||
while (sem_wait(&tree_sem) != 0)
|
||||
{
|
||||
/* The only case that an error should occr here is if
|
||||
* the wait was awakened by a signal.
|
||||
*/
|
||||
|
||||
ASSERT(*get_errno_ptr() == EINTR);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void _inode_semgive(void)
|
||||
{
|
||||
sem_post(&tree_sem);
|
||||
}
|
||||
|
||||
static int _inode_compare(const char *fname,
|
||||
struct inode *node)
|
||||
{
|
||||
char *nname = node->i_name;
|
||||
|
||||
if (!nname)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!fname)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* At end of node name? */
|
||||
if (!*nname)
|
||||
{
|
||||
/* Yes.. also end of find name? */
|
||||
if (!*fname || *fname == '/')
|
||||
{
|
||||
/* Yes.. return match */
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No... return find name > node name */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* At end of find name?*/
|
||||
else if (!*fname || *fname == '/')
|
||||
{
|
||||
/* Yes... return find name < node name */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* check for non-matching characters */
|
||||
else if (*fname > *nname)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (*fname < *nname)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Not at the end of either string and all of the
|
||||
* characters still match. keep looking.
|
||||
*/
|
||||
else
|
||||
{
|
||||
fname++;
|
||||
nname++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline int _inode_namelen(const char *name)
|
||||
{
|
||||
const char *tmp = name;
|
||||
while(*tmp && *tmp != '/') tmp++;
|
||||
return tmp - name;
|
||||
}
|
||||
|
||||
static inline void _inode_namecpy(char *dest, const char *src)
|
||||
{
|
||||
while(*src && *src != '/') *dest++ = *src++;
|
||||
*dest='\0';
|
||||
}
|
||||
|
||||
static inline const char *_inode_nextname(const char *name)
|
||||
{
|
||||
while (*name && *name != '/') name++;
|
||||
if (*name) name++;
|
||||
return name;
|
||||
}
|
||||
|
||||
static struct inode *_inode_alloc(const char *name,
|
||||
struct file_operations *fops,
|
||||
mode_t mode, void *private)
|
||||
{
|
||||
int namelen = _inode_namelen(name);
|
||||
struct inode *node = malloc(FSNODE_SIZE(namelen));
|
||||
if (node)
|
||||
{
|
||||
node->i_peer = NULL;
|
||||
node->i_child = NULL;
|
||||
node->i_ops = fops;
|
||||
#ifdef CONFIG_FILE_MODE
|
||||
node->i_mode = mode;
|
||||
#endif
|
||||
node->i_private = private;
|
||||
_inode_namecpy(node->i_name, name);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
static struct inode *_inode_find(const char **path,
|
||||
struct inode **peer,
|
||||
struct inode **parent)
|
||||
{
|
||||
const char *name = *path + 1; /* Skip over leading '/' */
|
||||
struct inode *node = root_inode;
|
||||
struct inode *left = NULL;
|
||||
struct inode *above = NULL;
|
||||
|
||||
while (node)
|
||||
{
|
||||
int result = _inode_compare(name, node);
|
||||
|
||||
/* Case 1: The name is less than the name of the node.
|
||||
* Since the names are ordered, these means that there
|
||||
* is no peer node with this name and that there can be
|
||||
* no match in the fileystem.
|
||||
*/
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
node = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Case 2: the name is greater than the name of the node.
|
||||
* In this case, the name may still be in the list to the
|
||||
* "right"
|
||||
*/
|
||||
|
||||
else if (result > 0)
|
||||
{
|
||||
left = node;
|
||||
node = node->i_peer;
|
||||
}
|
||||
|
||||
/* The names match */
|
||||
|
||||
else
|
||||
{
|
||||
/* Now there are two more possibilities:
|
||||
* (1) This is the node that we are looking for or,
|
||||
* (2) the node we are looking for is "blow" this one.
|
||||
*/
|
||||
|
||||
name = _inode_nextname(name);
|
||||
if (!*name)
|
||||
{
|
||||
/* We are at the end of the path, so this must be
|
||||
* the node we are looking for.
|
||||
*/
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* More to go, keep looking at the next level "down" */
|
||||
|
||||
above = node;
|
||||
left = NULL;
|
||||
node = node->i_child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* node is null. This can happen in one of four cases:
|
||||
* With node = NULL
|
||||
* (1) We went left past the final peer: The new node
|
||||
* name is larger than any existing node name at
|
||||
* that level.
|
||||
* (2) We broke out in the middle of the list of peers
|
||||
* because the name was not found in the ordered
|
||||
* list.
|
||||
* (3) We went down past the final parent: The new node
|
||||
* name is "deeper" than anything that we currently
|
||||
* have in the tree.
|
||||
* with node != NULL
|
||||
* (4) When the node matching the full path is found
|
||||
*/
|
||||
|
||||
if (peer) *peer = left;
|
||||
if (parent) *parent = above;
|
||||
*path = name;
|
||||
return node;
|
||||
}
|
||||
|
||||
static void _inode_insert(struct inode *node,
|
||||
struct inode *peer,
|
||||
struct inode *parent)
|
||||
{
|
||||
/* If peer is non-null, then new node simply goes to the right
|
||||
* of that peer node.
|
||||
*/
|
||||
|
||||
if (peer)
|
||||
{
|
||||
node->i_peer = peer->i_peer;
|
||||
peer->i_peer = node;
|
||||
}
|
||||
|
||||
/* If parent is non-null, then it must go at the head of its
|
||||
* list of children.
|
||||
*/
|
||||
|
||||
else if (parent)
|
||||
{
|
||||
node->i_peer = parent->i_child;
|
||||
parent->i_child = node;
|
||||
}
|
||||
|
||||
/* Otherwise, this must be the new root_inode */
|
||||
|
||||
else
|
||||
{
|
||||
node->i_peer = root_inode;
|
||||
root_inode = node;
|
||||
}
|
||||
}
|
||||
|
||||
static void _inode_remove(struct inode *node,
|
||||
struct inode *peer,
|
||||
struct inode *parent)
|
||||
{
|
||||
/* If peer is non-null, then remove the node from the right of
|
||||
* of that peer node.
|
||||
*/
|
||||
|
||||
if (peer)
|
||||
{
|
||||
peer->i_peer = node->i_peer;
|
||||
}
|
||||
|
||||
/* If parent is non-null, then remove the node from head of
|
||||
* of the list of children.
|
||||
*/
|
||||
|
||||
else if (parent)
|
||||
{
|
||||
parent->i_child = node->i_peer;
|
||||
}
|
||||
|
||||
/* Otherwise, we must be removing the root inode. */
|
||||
|
||||
else
|
||||
{
|
||||
root_inode = node->i_peer;
|
||||
}
|
||||
node->i_peer = NULL;
|
||||
}
|
||||
|
||||
static void _inode_free(struct inode *node)
|
||||
{
|
||||
if (node)
|
||||
{
|
||||
_inode_free(node->i_peer);
|
||||
_inode_free(node->i_child);
|
||||
free(node);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
|
||||
/* This is called from the OS initialization logic to configure
|
||||
* the file system.
|
||||
*/
|
||||
|
||||
void fs_initialize(void)
|
||||
{
|
||||
/* Initialize the semaphore to one (to support one-at-
|
||||
* a-time access to the inode tree).
|
||||
*/
|
||||
|
||||
(void)sem_init(&tree_sem, 0, 1);
|
||||
|
||||
/* Initialize files array (if it is used) */
|
||||
|
||||
if (files_initialize != NULL)
|
||||
{
|
||||
files_initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/* This is called from the open() logic to get a reference
|
||||
* to the inode associatged with a path.
|
||||
*/
|
||||
|
||||
struct inode *inode_find(const char *path)
|
||||
{
|
||||
struct inode *node;
|
||||
|
||||
if (!*path || path[0] != '/')
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Find the node matching the path. If found,
|
||||
* increment the count of references on the node.
|
||||
*/
|
||||
|
||||
_inode_semtake();
|
||||
node = _inode_find(&path, NULL, NULL);
|
||||
if (node) node->i_crefs++;
|
||||
_inode_semgive();
|
||||
return node;
|
||||
}
|
||||
|
||||
/* Increment the reference count on an inode (as when a file
|
||||
* descriptor is dup'ed.
|
||||
*/
|
||||
|
||||
void inode_addref(struct inode *inode)
|
||||
{
|
||||
if (inode)
|
||||
{
|
||||
_inode_semtake();
|
||||
inode->i_crefs++;
|
||||
_inode_semgive();
|
||||
}
|
||||
}
|
||||
|
||||
/* This is called from close() logic when it no longer refers
|
||||
* to the inode.
|
||||
*/
|
||||
|
||||
void inode_release(struct inode *node)
|
||||
{
|
||||
if (node)
|
||||
{
|
||||
/* Decrement the references of the inode */
|
||||
|
||||
_inode_semtake();
|
||||
if (node->i_crefs) node->i_crefs--;
|
||||
|
||||
/* If the subtree was previously deleted and the reference
|
||||
* count has decrement to zero, then delete the inode
|
||||
* now.
|
||||
*/
|
||||
|
||||
if (node->i_crefs <= 0 && (node->i_flags & FSNODEFLAG_DELETED) != 0)
|
||||
{
|
||||
_inode_semgive();
|
||||
_inode_free(node->i_child);
|
||||
free(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
_inode_semgive();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
STATUS register_inode(const char *path,
|
||||
struct file_operations *fops,
|
||||
mode_t mode, void *private)
|
||||
{
|
||||
const char *name = path;
|
||||
struct inode *left;
|
||||
struct inode *parent;
|
||||
|
||||
if (!*path || path[0] != '/')
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Find the location to insert the new subtree */
|
||||
|
||||
_inode_semtake();
|
||||
if (_inode_find(&name, &left, &parent) != NULL)
|
||||
{
|
||||
/* Is is an error if the node already exists in the tree */
|
||||
|
||||
_inode_semgive();
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Now we now where to insert the subtree */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
struct inode *node;
|
||||
|
||||
/* Create a new node -- we need to know if this is the
|
||||
* the leaf node or some intermediary. We can find this
|
||||
* by looking at the next name.
|
||||
*/
|
||||
|
||||
const char *next_name = _inode_nextname(name);
|
||||
if (*next_name)
|
||||
{
|
||||
/* Insert an operationless node */
|
||||
|
||||
node = _inode_alloc(name, NULL, mode, NULL);
|
||||
if (node)
|
||||
{
|
||||
_inode_insert(node, left, parent);
|
||||
|
||||
/* Set up for the next time through the loop */
|
||||
|
||||
name = next_name;
|
||||
left = NULL;
|
||||
parent = node;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
node = _inode_alloc(name, fops, mode, private);
|
||||
if (node)
|
||||
{
|
||||
_inode_insert(node, left, parent);
|
||||
_inode_semgive();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* We get here on failures to allocate node memory */
|
||||
|
||||
_inode_semgive();
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
STATUS unregister_inode(const char *path)
|
||||
{
|
||||
const char *name = path;
|
||||
struct inode *node;
|
||||
struct inode *left;
|
||||
struct inode *parent;
|
||||
|
||||
if (*path && path[0] == '/')
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Find the node to delete */
|
||||
|
||||
_inode_semtake();
|
||||
node = _inode_find(&name, &left, &parent);
|
||||
if (node)
|
||||
{
|
||||
/* Found it, now remove it from the tree */
|
||||
|
||||
_inode_remove(node, left, parent);
|
||||
|
||||
/* We cannot delete it if there reference to the inode */
|
||||
|
||||
if (node->i_crefs)
|
||||
{
|
||||
/* In that case, we will mark it deleted, when the FS
|
||||
* releases the inode, we will then, finally delete
|
||||
* the subtree.
|
||||
*/
|
||||
|
||||
node->i_flags |= FSNODEFLAG_DELETED;
|
||||
_inode_semgive();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* And delete it now -- recursively to delete all of its children */
|
||||
|
||||
_inode_semgive();
|
||||
_inode_free(node->i_child);
|
||||
free(node);
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* The node does not exist or it has references */
|
||||
_inode_semgive();
|
||||
return ERROR;
|
||||
}
|
103
fs/fs_internal.h
Normal file
103
fs/fs_internal.h
Normal file
|
@ -0,0 +1,103 @@
|
|||
/************************************************************
|
||||
* fs_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 __FS_INTERNAL_H
|
||||
#define __FS_INTERNAL_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/fs.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
#define FSNODEFLAG_DELETED 0x00000001
|
||||
|
||||
/************************************************************
|
||||
* Public Types
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Variables
|
||||
************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS >0
|
||||
extern struct file files[CONFIG_NFILE_DESCRIPTORS];
|
||||
#endif
|
||||
extern struct inode *root_inode;
|
||||
|
||||
/************************************************************
|
||||
* Inline Functions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Pulblic Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* fs_inode.c ***********************************************/
|
||||
|
||||
EXTERN struct inode *inode_find(const char *path);
|
||||
EXTERN void inode_addref(struct inode *inode);
|
||||
EXTERN void inode_release(struct inode *inode);
|
||||
|
||||
/* fs_files.c ***********************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS >0
|
||||
EXTERN void weak_function files_initialize(void);
|
||||
EXTERN int files_allocate(struct inode *inode, int oflags, off_t pos);
|
||||
EXTERN void files_release(int filedes);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* __FS_INTERNAL_H */
|
75
fs/fs_ioctl.c
Normal file
75
fs/fs_ioctl.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
/************************************************************
|
||||
* fs_ioctl.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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "fs_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Global Functions
|
||||
************************************************************/
|
||||
|
||||
int ioctl(int fd, int req, unsigned long arg)
|
||||
{
|
||||
int ret = EBADF;
|
||||
|
||||
/* We we give a valid file descriptor? */
|
||||
|
||||
if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
|
||||
{
|
||||
struct file *this_file = &files[fd];
|
||||
struct inode *inode = this_file->f_inode;
|
||||
|
||||
/* Is a driver registered? Does it support the ioctl method? */
|
||||
|
||||
if (inode && inode->i_ops && inode->i_ops->ioctl)
|
||||
{
|
||||
/* Yes, then let it perform the ioctl */
|
||||
|
||||
ret = (int)inode->i_ops->ioctl(this_file, req, arg);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
167
fs/fs_open.c
Normal file
167
fs/fs_open.c
Normal file
|
@ -0,0 +1,167 @@
|
|||
/************************************************************
|
||||
* fs_open.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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS >0
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef CONFIG_FILE_MODE
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
|
||||
#include <nuttx/fs.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "fs_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
|
||||
int inode_checkflags(struct inode *inode, int oflags)
|
||||
{
|
||||
if (((oflags & O_RDOK) != 0 && !inode->i_ops->read) ||
|
||||
((oflags & O_WROK) != 0 && !inode->i_ops->write))
|
||||
{
|
||||
*get_errno_ptr() = EACCES;
|
||||
return ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
int open(const char *path, int oflags, ...)
|
||||
{
|
||||
struct filelist *list;
|
||||
struct inode *inode;
|
||||
int status;
|
||||
int fd;
|
||||
|
||||
/* Get the thread-specific file list */
|
||||
|
||||
list = sched_getfiles();
|
||||
if (!list)
|
||||
{
|
||||
*get_errno_ptr() = EMFILE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FILE_MODE
|
||||
# warning "File creation not implemented"
|
||||
mode_t mode = 0;
|
||||
|
||||
/* If the file is opened for creation, then get the mode bits */
|
||||
|
||||
if (oflags & (O_WRONLY|O_CREAT) != 0)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, oflags);
|
||||
mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Get an inode for this file */
|
||||
|
||||
inode = inode_find(path);
|
||||
if (!inode)
|
||||
{
|
||||
/* "O_CREAT is not set and the named file does not exist. Or,
|
||||
* a directory component in pathname does not exist or is a
|
||||
* dangling symbolic link.
|
||||
*/
|
||||
|
||||
*get_errno_ptr() = ENOENT;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Make sure that the inode supports the requested access */
|
||||
|
||||
if (inode_checkflags(inode, oflags) != OK)
|
||||
{
|
||||
inode_release(inode);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Associate the inode with a file structure */
|
||||
|
||||
fd = files_allocate(inode, oflags, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
inode_release(inode);
|
||||
*get_errno_ptr() = EMFILE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Perform the driver open operation */
|
||||
|
||||
status = OK;
|
||||
if (inode->i_ops && inode->i_ops->open)
|
||||
{
|
||||
status = inode->i_ops->open(&list->fl_files[fd]);
|
||||
}
|
||||
|
||||
if (status != OK || !inode->i_ops)
|
||||
{
|
||||
files_release(fd);
|
||||
inode_release(inode);
|
||||
*get_errno_ptr() = ENODEV;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS */
|
97
fs/fs_read.c
Normal file
97
fs/fs_read.c
Normal file
|
@ -0,0 +1,97 @@
|
|||
/************************************************************
|
||||
* fs_read.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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS >0
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include "fs_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Global Functions
|
||||
************************************************************/
|
||||
|
||||
int read(int fd, void *buf, unsigned int nbytes)
|
||||
{
|
||||
struct filelist *list;
|
||||
int ret = EBADF;
|
||||
|
||||
/* Get the thread-specific file list */
|
||||
|
||||
list = sched_getfiles();
|
||||
if (!list)
|
||||
{
|
||||
*get_errno_ptr() = EMFILE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Were we given a valid file descriptor? */
|
||||
|
||||
if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
|
||||
{
|
||||
struct file *this_file = &list->fl_files[fd];
|
||||
|
||||
/* Was this file opened for read access? */
|
||||
|
||||
if ((this_file->f_oflags & O_RDOK) != 0)
|
||||
{
|
||||
struct inode *inode = this_file->f_inode;
|
||||
|
||||
/* Is a driver registered? Does it support the read method? */
|
||||
|
||||
if (inode && inode->i_ops && inode->i_ops->read)
|
||||
{
|
||||
/* Yes, then let it perform the read */
|
||||
|
||||
ret = (int)inode->i_ops->read(this_file, (char*)buf, (size_t)nbytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS */
|
98
fs/fs_write.c
Normal file
98
fs/fs_write.c
Normal file
|
@ -0,0 +1,98 @@
|
|||
/************************************************************
|
||||
* fs_write.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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS >0
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include "fs_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Global Functions
|
||||
************************************************************/
|
||||
|
||||
int write(int fd, const void *buf, unsigned int nbytes)
|
||||
{
|
||||
struct filelist *list;
|
||||
int ret = EBADF;
|
||||
|
||||
/* Get the thread-specific file list */
|
||||
|
||||
list = sched_getfiles();
|
||||
if (!list)
|
||||
{
|
||||
*get_errno_ptr() = EMFILE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Did we get a valid file descriptor? */
|
||||
|
||||
if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
|
||||
{
|
||||
struct file *this_file = &list->fl_files[fd];
|
||||
|
||||
/* Was this file opened for write access? */
|
||||
|
||||
if ((this_file->f_oflags & O_WROK) != 0)
|
||||
{
|
||||
struct inode *inode = this_file->f_inode;
|
||||
|
||||
/* Is a driver registered? Does it support the write method? */
|
||||
|
||||
if (inode && inode->i_ops && inode->i_ops->write)
|
||||
{
|
||||
/* Yes, then let it perform the write */
|
||||
|
||||
ret = inode->i_ops->write(this_file, buf, nbytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS */
|
||||
|
96
include/assert.h
Normal file
96
include/assert.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
/************************************************************
|
||||
* assert.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 __ASSERT_H
|
||||
#define __ASSERT_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/* Macro Name: ASSERT, ASSERTCODE, et al. */
|
||||
|
||||
#undef ASSERT
|
||||
#undef ASSERTFILE
|
||||
#undef ASSERTCODE
|
||||
#undef DEBUGASSERT
|
||||
|
||||
#define ASSERT(f) \
|
||||
{ if (!(f)) up_assert((const ubyte *)__FILE__, (uint32)__LINE__); }
|
||||
|
||||
#define ASSERTCODE(f, errCode) \
|
||||
{ if (!(f)) up_assert_code((const ubyte *)__FILE__, (uint32)__LINE__, errCode); }
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
#define DEBUGASSERT(f) \
|
||||
{ if (!(f)) up_assert((const ubyte *)__FILE__, (uint32)__LINE__); }
|
||||
#else
|
||||
#define DEBUGASSERT(f)
|
||||
#endif /* CONFIG_DEBUG */
|
||||
|
||||
#define PANIC(errCode) \
|
||||
up_assert_code((const ubyte *)__FILE__, (uint32)__LINE__, ((errCode)|(0x8000)))
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
EXTERN void up_assert(const ubyte *fileName, uint32 lineNum);
|
||||
EXTERN void up_assert_code(const ubyte *fileName, uint32 lineNum,
|
||||
uint16 errorCode);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSERT_H */
|
187
include/ctype.h
Normal file
187
include/ctype.h
Normal file
|
@ -0,0 +1,187 @@
|
|||
/************************************************************
|
||||
* ctype.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 __CTYPE_H
|
||||
#define __CTYPE_H
|
||||
|
||||
/* There is no consistent ctype implementation, just a
|
||||
* smattering of functions. Individually, they are okay, but
|
||||
* a more standard, data lookup approach would make more sense
|
||||
* if used extensively.
|
||||
*/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/************************************************************
|
||||
* Public Type Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Function: isspace
|
||||
*
|
||||
* Description:
|
||||
* Checks for white-space characters. In the "C" and "POSIX"
|
||||
* locales, these are: space, form-feed ('\f'), newline ('\n'),
|
||||
* carriage return ('\r'), horizontal tab ('\t'), and vertical
|
||||
* tab ('\v').
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static inline int isspace(int c)
|
||||
{
|
||||
if (c == ' ' || c == '\t' || c == '\n' || \
|
||||
c == '\r' || c == '\f' || c == '\v')
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Function: isdigit
|
||||
*
|
||||
* Description:
|
||||
* ANSI standard isdigit implementation.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static inline int isdigit(int c)
|
||||
{
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Function: isascii
|
||||
*
|
||||
* Description:
|
||||
* Checks whether c is a 7-bit unsigned char value that
|
||||
* fits into the ASCII character set.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static inline int isascii(int c)
|
||||
{
|
||||
return (c >= 0 && c <= 0177);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************
|
||||
* Function: isascii
|
||||
*
|
||||
* Description:
|
||||
* isxdigit() checks for a hexadecimal digits, i.e. one of
|
||||
* {0-9,a-f,A-F}
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static inline int isxdigit(int c)
|
||||
{
|
||||
if ((c >= '0' && c <= '9') ||
|
||||
(c >= 'a' && c <= 'f') ||
|
||||
(c >= 'A' && c <= 'F'))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Function: isascii
|
||||
*
|
||||
* Description:
|
||||
* toupper() converts the letter c to upper case, if possible.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static inline int toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
{
|
||||
return c - 'a' + 'A';
|
||||
}
|
||||
else
|
||||
{
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Function: isascii
|
||||
*
|
||||
* Description:
|
||||
* tolower() converts the letter c to lower case, if possible.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
static inline int tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
{
|
||||
return c - 'A' + 'a';
|
||||
}
|
||||
else
|
||||
{
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CTYPE_H */
|
103
include/debug.h
Normal file
103
include/debug.h
Normal file
|
@ -0,0 +1,103 @@
|
|||
/************************************************************
|
||||
* debug.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 __DEBUG_H
|
||||
#define __DEBUG_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/* Debug macros to runtime filter the opsys debug messages */
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
# define dbg(format, arg...) lib_rawprintf(format, ##arg)
|
||||
|
||||
# ifdef CONFIG_ARCH_LOWPUTC
|
||||
# define lldbg(format, arg...) lib_lowprintf(format, ##arg)
|
||||
# else
|
||||
# define lldbg(x...)
|
||||
# endif
|
||||
|
||||
# ifdef CONFIG_DEBUG_VERBOSE
|
||||
# define vdbg(format, arg...) lib_rawprintf(format, ##arg)
|
||||
# else
|
||||
# define vdbg(x...)
|
||||
# endif
|
||||
|
||||
#else
|
||||
# define dbg(x...)
|
||||
# define lldbg(x...)
|
||||
# define vdbg(x...)
|
||||
#endif
|
||||
|
||||
/************************************************************
|
||||
* Public Type Declarations
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Variables
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
EXTERN int lib_rawprintf(const char *format, ...);
|
||||
|
||||
#ifdef CONFIG_ARCH_LOWPUTC
|
||||
EXTERN int lib_lowprintf(const char *format, ...);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DEBUG_H */
|
198
include/errno.h
Normal file
198
include/errno.h
Normal file
|
@ -0,0 +1,198 @@
|
|||
/************************************************************
|
||||
* errno.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 __ERRNO_H
|
||||
#define __ERRNO_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
#define EPERM 1 /* Operation not permitted */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define E2BIG 7 /* Arg list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define ECHILD 10 /* No child processes */
|
||||
#define EAGAIN 11 /* Try again */
|
||||
#define ENOMEM 12 /* Out of memory */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#define ENOTBLK 15 /* Block device required */
|
||||
#define EBUSY 16 /* Device or resource busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* No such device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENFILE 23 /* File table overflow */
|
||||
#define EMFILE 24 /* Too many open files */
|
||||
#define ENOTTY 25 /* Not a typewriter */
|
||||
#define ETXTBSY 26 /* Text file busy */
|
||||
#define EFBIG 27 /* File too large */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define ESPIPE 29 /* Illegal seek */
|
||||
#define EROFS 30 /* Read-only file system */
|
||||
#define EMLINK 31 /* Too many links */
|
||||
#define EPIPE 32 /* Broken pipe */
|
||||
#define EDOM 33 /* Math argument out of domain of func */
|
||||
#define ERANGE 34 /* Math result not representable */
|
||||
#define EDEADLK 35 /* Resource deadlock would occur */
|
||||
#define ENAMETOOLONG 36 /* File name too long */
|
||||
#define ENOLCK 37 /* No record locks available */
|
||||
#define ENOSYS 38 /* Function not implemented */
|
||||
#define ENOTEMPTY 39 /* Directory not empty */
|
||||
#define ELOOP 40 /* Too many symbolic links encountered */
|
||||
#define EWOULDBLOCK EAGAIN /* Operation would block */
|
||||
#define ENOMSG 42 /* No message of desired type */
|
||||
#define EIDRM 43 /* Identifier removed */
|
||||
#define ECHRNG 44 /* Channel number out of range */
|
||||
#define EL2NSYNC 45 /* Level 2 not synchronized */
|
||||
#define EL3HLT 46 /* Level 3 halted */
|
||||
#define EL3RST 47 /* Level 3 reset */
|
||||
#define ELNRNG 48 /* Link number out of range */
|
||||
#define EUNATCH 49 /* Protocol driver not attached */
|
||||
#define ENOCSI 50 /* No CSI structure available */
|
||||
#define EL2HLT 51 /* Level 2 halted */
|
||||
#define EBADE 52 /* Invalid exchange */
|
||||
#define EBADR 53 /* Invalid request descriptor */
|
||||
#define EXFULL 54 /* Exchange full */
|
||||
#define ENOANO 55 /* No anode */
|
||||
#define EBADRQC 56 /* Invalid request code */
|
||||
#define EBADSLT 57 /* Invalid slot */
|
||||
|
||||
#define EDEADLOCK EDEADLK
|
||||
|
||||
#define EBFONT 59 /* Bad font file format */
|
||||
#define ENOSTR 60 /* Device not a stream */
|
||||
#define ENODATA 61 /* No data available */
|
||||
#define ETIME 62 /* Timer expired */
|
||||
#define ENOSR 63 /* Out of streams resources */
|
||||
#define ENONET 64 /* Machine is not on the network */
|
||||
#define ENOPKG 65 /* Package not installed */
|
||||
#define EREMOTE 66 /* Object is remote */
|
||||
#define ENOLINK 67 /* Link has been severed */
|
||||
#define EADV 68 /* Advertise error */
|
||||
#define ESRMNT 69 /* Srmount error */
|
||||
#define ECOMM 70 /* Communication error on send */
|
||||
#define EPROTO 71 /* Protocol error */
|
||||
#define EMULTIHOP 72 /* Multihop attempted */
|
||||
#define EDOTDOT 73 /* RFS specific error */
|
||||
#define EBADMSG 74 /* Not a data message */
|
||||
#define EOVERFLOW 75 /* Value too large for defined data type */
|
||||
#define ENOTUNIQ 76 /* Name not unique on network */
|
||||
#define EBADFD 77 /* File descriptor in bad state */
|
||||
#define EREMCHG 78 /* Remote address changed */
|
||||
#define ELIBACC 79 /* Can not access a needed shared library */
|
||||
#define ELIBBAD 80 /* Accessing a corrupted shared library */
|
||||
#define ELIBSCN 81 /* .lib section in a.out corrupted */
|
||||
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
|
||||
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
|
||||
#define EILSEQ 84 /* Illegal byte sequence */
|
||||
#define ERESTART 85 /* Interrupted system call should be restarted */
|
||||
#define ESTRPIPE 86 /* Streams pipe error */
|
||||
#define EUSERS 87 /* Too many users */
|
||||
#define ENOTSOCK 88 /* Socket operation on non-socket */
|
||||
#define EDESTADDRREQ 89 /* Destination address required */
|
||||
#define EMSGSIZE 90 /* Message too long */
|
||||
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
|
||||
#define ENOPROTOOPT 92 /* Protocol not available */
|
||||
#define EPROTONOSUPPORT 93 /* Protocol not supported */
|
||||
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
|
||||
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
||||
#define EPFNOSUPPORT 96 /* Protocol family not supported */
|
||||
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
||||
#define EADDRINUSE 98 /* Address already in use */
|
||||
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
|
||||
#define ENETDOWN 100 /* Network is down */
|
||||
#define ENETUNREACH 101 /* Network is unreachable */
|
||||
#define ENETRESET 102 /* Network dropped connection because of reset */
|
||||
#define ECONNABORTED 103 /* Software caused connection abort */
|
||||
#define ECONNRESET 104 /* Connection reset by peer */
|
||||
#define ENOBUFS 105 /* No buffer space available */
|
||||
#define EISCONN 106 /* Transport endpoint is already connected */
|
||||
#define ENOTCONN 107 /* Transport endpoint is not connected */
|
||||
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
|
||||
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
|
||||
#define ETIMEDOUT 110 /* Connection timed out */
|
||||
#define ECONNREFUSED 111 /* Connection refused */
|
||||
#define EHOSTDOWN 112 /* Host is down */
|
||||
#define EHOSTUNREACH 113 /* No route to host */
|
||||
#define EALREADY 114 /* Operation already in progress */
|
||||
#define EINPROGRESS 115 /* Operation now in progress */
|
||||
#define ESTALE 116 /* Stale NFS file handle */
|
||||
#define EUCLEAN 117 /* Structure needs cleaning */
|
||||
#define ENOTNAM 118 /* Not a XENIX named type file */
|
||||
#define ENAVAIL 119 /* No XENIX semaphores available */
|
||||
#define EISNAM 120 /* Is a named type file */
|
||||
#define EREMOTEIO 121 /* Remote I/O error */
|
||||
#define EDQUOT 122 /* Quota exceeded */
|
||||
|
||||
#define ENOMEDIUM 123 /* No medium found */
|
||||
#define EMEDIUMTYPE 124 /* Wrong medium type */
|
||||
|
||||
/************************************************************
|
||||
* Type Declarations
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
extern int *get_errno_ptr(void);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ERRNO_H */
|
120
include/mqueue.h
Normal file
120
include/mqueue.h
Normal file
|
@ -0,0 +1,120 @@
|
|||
/************************************************************
|
||||
* mqueue.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 __MQUEUE_H
|
||||
#define __MQUEUE_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include "queue.h"
|
||||
|
||||
/************************************************************
|
||||
* Compilations Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Type Declarations
|
||||
************************************************************/
|
||||
|
||||
/* Message queue attributes */
|
||||
|
||||
struct mq_attr
|
||||
{
|
||||
size_t mq_maxmsg; /* Max number of messages in queue */
|
||||
size_t mq_msgsize; /* Max message size */
|
||||
unsigned mq_flags; /* Queue flags */
|
||||
size_t mq_curmsgs; /* Number of messages currently in queue */
|
||||
};
|
||||
|
||||
/* The following is used to attach a signal to a message queue
|
||||
* to notify a task when a message is available on a queue
|
||||
*/
|
||||
|
||||
struct sigevent {
|
||||
int sigev_signo;
|
||||
union sigval sigev_value;
|
||||
int sigev_notify;
|
||||
};
|
||||
|
||||
/* Message queue descriptor */
|
||||
|
||||
typedef struct mq_des *mqd_t;
|
||||
|
||||
/************************************************************
|
||||
* Global Variables
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
EXTERN mqd_t mq_open(const char *mq_name,
|
||||
int oflags, ... );
|
||||
EXTERN int mq_close(mqd_t mqdes );
|
||||
EXTERN int mq_unlink(const char *mq_name );
|
||||
EXTERN int mq_send(mqd_t mqdes, const void *msg,
|
||||
size_t msglen, int prio );
|
||||
EXTERN int mq_receive(mqd_t mqdes, void *msg,
|
||||
size_t msglen, int *prio );
|
||||
EXTERN int mq_notify(mqd_t mqdes,
|
||||
const struct sigevent *notification );
|
||||
EXTERN int mq_setattr(mqd_t mqdes,
|
||||
const struct mq_attr *mq_stat,
|
||||
struct mq_attr *oldstat);
|
||||
EXTERN int mq_getattr(mqd_t mqdes,
|
||||
struct mq_attr *mq_stat);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MQUEUE_H */
|
||||
|
433
include/nuttx/arch.h
Normal file
433
include/nuttx/arch.h
Normal file
|
@ -0,0 +1,433 @@
|
|||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
#ifndef __ARCH_H
|
||||
#define __ARCH_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <sched.h>
|
||||
#include <arch/arch.h>
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Inline functions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Types
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Variables
|
||||
************************************************************/
|
||||
|
||||
typedef void (*sig_deliver_t)(_TCB *tcb);
|
||||
|
||||
/************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/************************************************************
|
||||
* These are standard interfaces that must be exported to the
|
||||
* scheduler from architecture-specific code.
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_initialize(void);
|
||||
|
||||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_idle(void);
|
||||
|
||||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_initial_state(_TCB *tcb);
|
||||
|
||||
/************************************************************
|
||||
* 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.
|
||||
************************************************************/
|
||||
|
||||
EXTERN STATUS up_create_stack(_TCB *tcb, uint32 stack_size);
|
||||
|
||||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN STATUS up_use_stack(_TCB *tcb, uint32 *stack, uint32 stack_size);
|
||||
|
||||
/************************************************************
|
||||
* Name: up_release_stack
|
||||
*
|
||||
* Description:
|
||||
* A task has been stopped. Free all stack
|
||||
* related resources retained int the defunct TCB.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_release_stack(_TCB *dtcb);
|
||||
|
||||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_unblock_task(_TCB *tcb);
|
||||
|
||||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_block_task(_TCB *tcb, tstate_t task_state);
|
||||
|
||||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_release_pending(void);
|
||||
|
||||
/************************************************************
|
||||
* 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
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_reprioritize_rtr(_TCB *tcb, ubyte priority);
|
||||
|
||||
/************************************************************
|
||||
* Name: _exit
|
||||
*
|
||||
* Description:
|
||||
* This function causes the currently executing task to cease
|
||||
* to exist. This is a special case of task_delete().
|
||||
*
|
||||
************************************************************/
|
||||
/* Prototype is in unistd.h */
|
||||
|
||||
/************************************************************
|
||||
* Name: ip_assert and up_assert_code
|
||||
*
|
||||
* Description:
|
||||
* Assertions may be handled in an architecture-specific
|
||||
* way.
|
||||
*
|
||||
************************************************************/
|
||||
/* Prototype is in assert.h */
|
||||
|
||||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver);
|
||||
|
||||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
#ifndef CONFIG_HEAP_BASE
|
||||
EXTERN void up_allocate_heap(void **heap_start, size_t *heap_size);
|
||||
#endif
|
||||
|
||||
/************************************************************
|
||||
* Name: up_interrupt_context
|
||||
*
|
||||
* Description:
|
||||
* Return TRUE is we are currently executing in
|
||||
* the interrupt handler context.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN boolean up_interrupt_context(void);
|
||||
|
||||
/************************************************************
|
||||
* Name: up_disable_irq
|
||||
*
|
||||
* Description:
|
||||
* Disable the IRQ specified by 'irq'
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_disable_irq(int irq);
|
||||
|
||||
/************************************************************
|
||||
* Name: up_enable_irq
|
||||
*
|
||||
* Description:
|
||||
* Enable the IRQ specified by 'irq'
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_enable_irq(int irq);
|
||||
|
||||
/************************************************************
|
||||
* Name: up_acknowledge_irq
|
||||
*
|
||||
* Description:
|
||||
* Disable the IRQ specified by 'irq'
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void up_disable_irq(int irq);
|
||||
|
||||
/************************************************************
|
||||
* These are standard interfaces that are exported by the OS
|
||||
* for use by the architecture specific logic
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Name: sched_process_timer
|
||||
*
|
||||
* Description:
|
||||
* This function handles system timer events.
|
||||
* The timer interrupt logic itself is implemented in the
|
||||
* architecture specific code, but must call the following OS
|
||||
* function periodically -- the calling interval must be
|
||||
* MSEC_PER_TICK.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
EXTERN void sched_process_timer(void);
|
||||
|
||||
/************************************************************
|
||||
* Name: irq_dispatch
|
||||
*
|
||||
* Description:
|
||||
* This function must be called from the achitecture-
|
||||
* specific logic in order to dispaly an interrupt to
|
||||
* the appropriate, registered handling logic.
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
EXTERN void irq_dispatch(int irq, struct xcptcontext *xcp);
|
||||
|
||||
/************************************************************
|
||||
* Debug interfaces exported by the architecture-specific
|
||||
* logic
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Name: up_putc
|
||||
*
|
||||
* Description:
|
||||
* Output one character on the console
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
# ifdef CONFIG_ARCH_LOWPUTC
|
||||
EXTERN int up_putc(int ch);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ARCH_H */
|
||||
|
73
include/nuttx/compiler.h
Normal file
73
include/nuttx/compiler.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/************************************************************
|
||||
* compiler.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 __COMPILER_H
|
||||
#define __COMPILER_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
#define weak_alias(name, aliasname) \
|
||||
extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
|
||||
#define weak_function __attribute__ ((weak))
|
||||
#define weak_const_function __attribute__ ((weak, __const__))
|
||||
|
||||
/************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __COMPILER_H */
|
215
include/nuttx/fs.h
Normal file
215
include/nuttx/fs.h
Normal file
|
@ -0,0 +1,215 @@
|
|||
/************************************************************
|
||||
* fs.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 __FS_H
|
||||
#define __FS_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <semaphore.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Type Definitions
|
||||
************************************************************/
|
||||
|
||||
/* This structure is provided by filesystems when they are
|
||||
* registered with the system. It is used to call back to
|
||||
* perform fs/device specific operations.
|
||||
*/
|
||||
|
||||
struct file;
|
||||
struct file_operations
|
||||
{
|
||||
int (*open)(struct file *);
|
||||
int (*close)(struct file *);
|
||||
// off_t (*llseek)(struct file *, off_t, int);
|
||||
ssize_t (*read)(struct file *, char *, size_t);
|
||||
ssize_t (*write)(struct file *, const char *, size_t);
|
||||
// unsigned int (*poll)(struct file *, struct poll_table_struct *);
|
||||
int (*ioctl)(struct file *, int, unsigned long);
|
||||
};
|
||||
|
||||
/* This structure represents one inode in the Nuttx psuedo-file system */
|
||||
|
||||
struct inode
|
||||
{
|
||||
struct inode *i_peer; /* Pointer to inode at same level */
|
||||
struct inode *i_child; /* Pointer to inode at lower level */
|
||||
struct file_operations *i_ops; /* Driver file operations for inode */
|
||||
sint16 i_crefs; /* References to inode */
|
||||
uint16 i_flags; /* flags for inode */
|
||||
#ifdef CONFIG_FILE_MODE
|
||||
mode_t i_mode; /* Access mode flags */
|
||||
#endif
|
||||
void *i_private; /* Driver private data */
|
||||
char i_name[1]; /* Name of inode (variable length) */
|
||||
};
|
||||
#define FSNODE_SIZE(n) (sizeof(struct inode) + (n))
|
||||
|
||||
/* This is the underlying representation of a ropen file.
|
||||
* A file descriptor is an index into an array of such types.
|
||||
* The type associates the file descriptor to the file state
|
||||
* and to a set of inode operations.
|
||||
*/
|
||||
|
||||
struct file
|
||||
{
|
||||
int f_oflags; /* Open mode flags */
|
||||
off_t f_pos; /* File position */
|
||||
struct inode *f_inode; /* Driver interface */
|
||||
};
|
||||
|
||||
/* This defines a list of files indexed by the file descriptor */
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
struct filelist
|
||||
{
|
||||
sem_t fl_sem; /* Manage access to the file list */
|
||||
sint16 fl_crefs; /* Reference count */
|
||||
struct file fl_files[CONFIG_NFILE_DESCRIPTORS];
|
||||
};
|
||||
#endif
|
||||
|
||||
/* This defines the list of files used for standard C I/O
|
||||
* We can support the standard C APIs without or without buffering
|
||||
*/
|
||||
|
||||
/* Buffered file I/O structure */
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
struct file_struct
|
||||
{
|
||||
int fs_filedes; /* File descriptor associated with stream */
|
||||
mode_t fs_oflags; /* Open mode flags */
|
||||
#if CONFIG_NUNGET_CHARS > 0
|
||||
uint8 fs_nungotten; /* The number of characters buffered for ungetc */
|
||||
unsigned char fs_ungotten[CONFIG_NUNGET_CHARS];
|
||||
#endif
|
||||
#if CONFIG_STDIO_BUFFER_SIZE > 0
|
||||
sem_t fs_sem; /* For thread safety */
|
||||
pid_t fs_holder; /* Holder of sem */
|
||||
int fs_counts; /* Number of times sem is held */
|
||||
unsigned char *fs_bufstart; /* Pointer to start of buffer */
|
||||
unsigned char *fs_bufend; /* Pointer to 1 past end of buffer */
|
||||
unsigned char *fs_bufpos; /* Current position in buffer */
|
||||
unsigned char *fs_bufread; /* Pointer to 1 past last buffered read char. */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct streamlist
|
||||
{
|
||||
int sl_crefs; /* Reference count */
|
||||
sem_t sl_sem; /* For thread safety */
|
||||
struct file_struct sl_streams[CONFIG_NFILE_STREAMS];
|
||||
};
|
||||
#endif /* CONFIG_NFILE_STREAMS */
|
||||
|
||||
/************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* fs_inode.c ***********************************************/
|
||||
|
||||
/* These interfaces are used by drivers to register their
|
||||
* inodes in the inode tree.
|
||||
*/
|
||||
|
||||
EXTERN void weak_function fs_initialize(void);
|
||||
EXTERN STATUS register_inode(const char *path,
|
||||
struct file_operations *fops,
|
||||
mode_t mode, void *private);
|
||||
EXTERN STATUS unregister_inode(const char *path);
|
||||
|
||||
/* fs_open.c ************************************************/
|
||||
|
||||
EXTERN int inode_checkflags(struct inode *inode, int oflags);
|
||||
|
||||
/* fs_files.c ***********************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS >0
|
||||
EXTERN struct filelist *files_alloclist(void);
|
||||
EXTERN int files_addreflist(struct filelist *list);
|
||||
EXTERN int files_releaselist(struct filelist *list);
|
||||
EXTERN int files_dup(struct file *filep1, struct file *filep2);
|
||||
#endif
|
||||
|
||||
/* lib_fopen.c **********************************************/
|
||||
|
||||
/* Used by the OS to clone stdin, stdout, stderr */
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
EXTERN struct file_struct *lib_fdopen(int fd,
|
||||
const char *mode,
|
||||
struct filelist *flist,
|
||||
struct streamlist *slist);
|
||||
#endif
|
||||
|
||||
/* lib_fflush.c *********************************************/
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
EXTERN void lib_flushall(struct streamlist *list);
|
||||
#endif
|
||||
|
||||
/* drivers **************************************************/
|
||||
|
||||
/* Call in of these to register the corresponding default
|
||||
* default drivers in the drivers/ subdirectory
|
||||
*/
|
||||
|
||||
EXTERN void devnull_register(void);
|
||||
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FS_H */
|
107
include/nuttx/irq.h
Normal file
107
include/nuttx/irq.h
Normal file
|
@ -0,0 +1,107 @@
|
|||
/************************************************************
|
||||
* 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.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
#ifndef __IRQ_H
|
||||
#define __IRQ_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
# include <sys/types.h>
|
||||
# include <assert.h>
|
||||
#endif
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
# define irq_detach(isr) irq_attach(isr, NULL)
|
||||
#endif
|
||||
|
||||
/************************************************************
|
||||
* Public Types
|
||||
************************************************************/
|
||||
|
||||
/* This struct defines the way the registers are stored */
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
struct xcptcontext; /* forward reference */
|
||||
|
||||
typedef int (*xcpt_t)(int irq, struct xcptcontext *xcp);
|
||||
typedef int (*swint_t)(uint32 code, uint32 parm2, uint32 parm3,
|
||||
struct xcptcontext *xcp);
|
||||
#endif
|
||||
|
||||
/* Now include architecture-specific types */
|
||||
|
||||
#include <arch/irq.h>
|
||||
|
||||
/************************************************************
|
||||
* Inline functions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Variables
|
||||
************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
struct xcptcontext *current_xcp;
|
||||
#endif
|
||||
|
||||
/************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
EXTERN int irq_attach(int irq, xcpt_t isr);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* __IRQ_H */
|
||||
|
94
include/nuttx/kmalloc.h
Normal file
94
include/nuttx/kmalloc.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/************************************************************
|
||||
* kmalloc.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 __KMALLOC_H
|
||||
#define __KMALLOC_H
|
||||
|
||||
/************************************************************
|
||||
* Included Functions
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/************************************************************
|
||||
* Public Types
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Pulblic Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#undef KMALLOC_EXTERN
|
||||
#if defined(__cplusplus)
|
||||
# define KMALLOC_EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
# define KMALLOC_EXTERN extern
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ARCH_KMALLOC
|
||||
# include <stdlib.h>
|
||||
# define kmalloc(s) malloc(s)
|
||||
#else
|
||||
KMALLOC_EXTERN void *kmalloc(size_t);
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ARCH_KZMALLOC
|
||||
# include <stdlib.h>
|
||||
# define kzmalloc(s) zalloc(s)
|
||||
#else
|
||||
KMALLOC_EXTERN void *kzalloc(size_t);
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ARCH_KFREE
|
||||
# include <stdlib.h>
|
||||
# define kfree(p) free(p)
|
||||
#else
|
||||
KMALLOC_EXTERN void kfree(void*);
|
||||
#endif
|
||||
|
||||
/* Functions defined in os_list.c ***************************/
|
||||
|
||||
/* Handles memory freed from an interrupt handler */
|
||||
|
||||
KMALLOC_EXTERN void sched_free(void *address);
|
||||
|
||||
#undef KMALLOC_EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __KMALLOC_H */
|
79
include/nuttx/lib.h
Normal file
79
include/nuttx/lib.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
/************************************************************
|
||||
* lib.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 __LIB_H
|
||||
#define __LIB_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/fs.h>
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Functions contained in lib_init.c ************************/
|
||||
|
||||
EXTERN void weak_function lib_initialize(void);
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
EXTERN struct streamlist *lib_alloclist(void);
|
||||
EXTERN void lib_addreflist(struct streamlist *list);
|
||||
EXTERN void lib_releaselist(struct streamlist *list);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __LIB_H */
|
85
include/nuttx/os_external.h
Normal file
85
include/nuttx/os_external.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/************************************************************
|
||||
* os_external.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 __OS_EXTERNAL_H
|
||||
#define __OS_EXTERNAL_H
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* These are functions that must be supplied by the application */
|
||||
|
||||
EXTERN void weak_function user_initialize(void);
|
||||
EXTERN int user_start(int parm1, int parm2, int parm3, int parm4);
|
||||
|
||||
/* Functions contained in os_task.c *************************/
|
||||
|
||||
EXTERN void os_start(void); /* OS entry point called by boot logic */
|
||||
|
||||
/* Functions contained in mm_init.c *************************/
|
||||
|
||||
EXTERN void mm_initialize(void *heap_start, size_t heap_size);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OS_EXTERNAL_H */
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue