mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 01:53:33 +08:00
Resync new repository with old repo r5166
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5153 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -0,0 +1,221 @@
|
||||
############################################################################
|
||||
# arch/sim/src/Makefile
|
||||
#
|
||||
# Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
CFLAGS += -I$(TOPDIR)/sched
|
||||
|
||||
ASRCS = up_setjmp.S
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
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
|
||||
HOSTSRCS = up_stdio.c up_hostusleep.c
|
||||
|
||||
ifeq ($(CONFIG_NX_LCDDRIVER),y)
|
||||
CSRCS += up_lcd.c
|
||||
else
|
||||
CSRCS += up_framebuffer.c
|
||||
ifeq ($(CONFIG_SIM_X11FB),y)
|
||||
HOSTSRCS += up_x11framebuffer.c
|
||||
ifeq ($(CONFIG_SIM_TOUCHSCREEN),y)
|
||||
CSRCS += up_touchscreen.c
|
||||
HOSTSRCS += up_x11eventloop.c
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FS_FAT),y)
|
||||
CSRCS += up_blockdevice.c up_deviceimage.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ARCH_ROMGETC),y)
|
||||
CSRCS += up_romgetc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
CSRCS += up_uipdriver.c
|
||||
HOSTCFLAGS += -DNETDEV_BUFSIZE=$(CONFIG_NET_BUFSIZE)
|
||||
ifneq ($(HOSTOS),Cygwin)
|
||||
HOSTSRCS += up_tapdev.c up_netdev.c
|
||||
else
|
||||
HOSTSRCS += up_wpcap.c up_netdev.c
|
||||
DRVLIB = /lib/w32api/libws2_32.a /lib/w32api/libiphlpapi.a
|
||||
endif
|
||||
endif
|
||||
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
NUTTXOBJS = $(AOBJS) $(COBJS)
|
||||
HOSTOBJS = $(HOSTSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS) $(HOSTSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS) $(HOSTOBJS)
|
||||
|
||||
# Determine which standard libraries will need to be linked in
|
||||
|
||||
ifeq ($(CONFIG_SIM_X11FB),y)
|
||||
STDLIBS += -lX11 -lXext
|
||||
ifeq ($(CONFIG_SIM_TOUCHSCREEN),y)
|
||||
STDLIBS += -lpthread
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FS_FAT),y)
|
||||
STDLIBS += -lz
|
||||
endif
|
||||
|
||||
STDLIBS += -lc
|
||||
|
||||
# Determine which objects are required in the link. The
|
||||
# up_head object normally draws in all that is needed, but
|
||||
# there are a fews that must be included because they
|
||||
# are called only from the host OS-specific logic (HOSTOBJS)
|
||||
|
||||
LINKOBJS = up_head$(OBJEXT)
|
||||
REQUIREDOBJS = $(LINKOBJS)
|
||||
|
||||
ifeq ($(CONFIG_SIM_X11FB),y)
|
||||
ifeq ($(CONFIG_SIM_TOUCHSCREEN),y)
|
||||
REQUIREDOBJS += up_touchscreen.o
|
||||
endif
|
||||
endif
|
||||
|
||||
# Determine which NuttX libraries will need to be linked in
|
||||
# Most are provided by LINKLIBS on the MAKE command line
|
||||
|
||||
LINKLIBS =
|
||||
LDPATHS = $(addprefix -L$(TOPDIR)/,$(dir $(LINKLIBS)))
|
||||
LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(LINKLIBS))))
|
||||
|
||||
# Add the board-specific library and directory
|
||||
|
||||
LDPATHS += -L board
|
||||
LDLIBS += -lboard
|
||||
|
||||
# Make targets begin here
|
||||
|
||||
all: up_head$(OBJEXT) libarch$(LIBEXT)
|
||||
|
||||
.PHONY: board/libboard$(LIBEXT) export_head clean distclean cleanrel depend
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS) $(LINKOBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
$(HOSTOBJS): %$(OBJEXT): %.c
|
||||
@echo "CC: $<"
|
||||
@$(CC) -c $(HOSTCFLAGS) $< -o $@
|
||||
|
||||
# The architecture-specific library
|
||||
|
||||
libarch$(LIBEXT): $(NUTTXOBJS)
|
||||
@( for obj in $(NUTTXOBJS) ; do \
|
||||
$(call ARCHIVE, $@, $${obj}); \
|
||||
done ; )
|
||||
|
||||
# The "board"-specific library. Of course, there really are no boards in
|
||||
# the simulation. However, this is a good place to keep parts of the simulation
|
||||
# that are not hardware-related.
|
||||
|
||||
board/libboard$(LIBEXT):
|
||||
@$(MAKE) -C board TOPDIR="$(TOPDIR)" libboard$(LIBEXT) EXTRADEFINES=$(EXTRADEFINES)
|
||||
|
||||
# A partially linked object containing only NuttX code (no interface to host OS)
|
||||
# Change the names of most symbols that conflict with libc symbols.
|
||||
|
||||
GNU:
|
||||
@mkdir ./GNU
|
||||
|
||||
GNU/Linux-names.dat: GNU nuttx-names.dat
|
||||
@cp nuttx-names.dat $@
|
||||
|
||||
Cygwin-names.dat: nuttx-names.dat
|
||||
@cat $^ | sed -e "s/^/_/g" >$@
|
||||
|
||||
nuttx.rel : libarch$(LIBEXT) board/libboard$(LIBEXT) $(HOSTOS)-names.dat $(LINKOBJS)
|
||||
@echo "LD: nuttx.rel"
|
||||
@$(LD) -r $(LDLINKFLAGS) $(LDPATHS) -o $@ $(REQUIREDOBJS) --start-group $(LDLIBS) $(EXTRA_LIBS) --end-group
|
||||
@$(OBJCOPY) --redefine-syms=$(HOSTOS)-names.dat $@
|
||||
|
||||
# Generate the final NuttX binary by linking the host-specific objects with the NuttX
|
||||
# specific objects (with munged names)
|
||||
|
||||
nuttx$(EXEEXT): cleanrel nuttx.rel $(HOSTOBJS)
|
||||
@echo "LD: nuttx$(EXEEXT)"
|
||||
@$(CC) $(CCLINKFLAGS) $(LDPATHS) -o $(TOPDIR)/$@ nuttx.rel $(HOSTOBJS) $(DRVLIB) $(STDLIBS)
|
||||
@$(NM) $(TOPDIR)/$@ | \
|
||||
grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
|
||||
sort > $(TOPDIR)/System.map
|
||||
@rm -f nuttx.rel
|
||||
|
||||
# This is part of the top-level export target
|
||||
|
||||
export_head: board/libboard$(LIBEXT) up_head.o $(HOSTOBJS)
|
||||
cp up_head.o $(HOSTOBJS) ${EXPORT_DIR}/startup
|
||||
cp nuttx-names.dat ${EXPORT_DIR}/libs
|
||||
echo main NXmain >> ${EXPORT_DIR}/libs/nuttx-names.dat
|
||||
|
||||
# Dependencies
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
cleanrel:
|
||||
@rm -f nuttx.rel GNU/Linux-names.dat Cygwin-names.dat
|
||||
|
||||
clean: cleanrel
|
||||
@if [ -e board/Makefile ]; then \
|
||||
$(MAKE) -C board TOPDIR="$(TOPDIR)" clean ; \
|
||||
fi
|
||||
@rm -f nuttx.rel libarch$(LIBEXT) *~ .*.swp
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
@if [ -e board/Makefile ]; then \
|
||||
$(MAKE) -C board TOPDIR="$(TOPDIR)" distclean ; \
|
||||
fi
|
||||
@rm -f Make.dep .depend
|
||||
@rm -rf GNU
|
||||
|
||||
-include Make.dep
|
||||
@@ -0,0 +1,36 @@
|
||||
calloc NXcalloc
|
||||
close NXclose
|
||||
closedir NXclosedir
|
||||
dup NXdup
|
||||
free NXfree
|
||||
fclose NXfclose
|
||||
fopen NXfopen
|
||||
fputc NXfputc
|
||||
fread NXfread
|
||||
fwrite NXfwrite
|
||||
fsync NXfsync
|
||||
gettimeofday NXgettimeofday
|
||||
ioctl NXioctl
|
||||
lseek NXlseek
|
||||
malloc NXmalloc
|
||||
malloc_init NXmalloc_init
|
||||
mkdir NXmkdir
|
||||
mount NXmount
|
||||
open NXopen
|
||||
opendir NXopendir
|
||||
read NXread
|
||||
realloc NXrealloc
|
||||
rewinddir NXrewinddir
|
||||
rmdir NXrmdir
|
||||
seekdir NXseekdir
|
||||
select NXselect
|
||||
sleep NXsleep
|
||||
socket NXsocket
|
||||
stat NXstat
|
||||
statfs NXstatfs
|
||||
system NXsystem
|
||||
umount NXumount
|
||||
unlink NXunlink
|
||||
usleep NXusleep
|
||||
write NXwrite
|
||||
zmalloc NXzmalloc
|
||||
@@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
* up_allocateheap.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "os_internal.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static uint8_t sim_heap[SIM_HEAP_SIZE];
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_allocate_heap
|
||||
*
|
||||
* Description:
|
||||
* The heap may be statically allocated by
|
||||
* defining CONFIG_HEAP_BASE and CONFIG_HEAP_SIZE. If these
|
||||
* are not defined, then this function will be called to
|
||||
* dynamically set aside the heap region.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_allocate_heap(void **heap_start, size_t *heap_size)
|
||||
{
|
||||
*heap_start = sim_heap;
|
||||
*heap_size = SIM_HEAP_SIZE;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/****************************************************************************
|
||||
* up_blockdevice.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/ramdisk.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define NSECTORS 2048
|
||||
#define LOGICAL_SECTOR_SIZE 512
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_registerblockdevice
|
||||
*
|
||||
* Description: Register the FAT ramdisk
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_registerblockdevice(void)
|
||||
{
|
||||
ramdisk_register(0, (uint8_t*)up_deviceimage(), NSECTORS, LOGICAL_SECTOR_SIZE, true);
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/****************************************************************************
|
||||
* up_blocktask.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "os_internal.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_block_task
|
||||
*
|
||||
* Description:
|
||||
* The currently executing task at the head of
|
||||
* the ready to run list must be stopped. Save its context
|
||||
* and move it to the inactive list specified by task_state.
|
||||
*
|
||||
* Inputs:
|
||||
* tcb: Refers to a task in the ready-to-run list (normally
|
||||
* the task at the head of the list). It most be
|
||||
* stopped, its context saved and moved into one of the
|
||||
* waiting task lists. It it was the task at the head
|
||||
* of the ready-to-run list, then a context to the new
|
||||
* ready to run task must be performed.
|
||||
* task_state: Specifies which waiting task list should be
|
||||
* hold the blocked task TCB.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_block_task(_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;
|
||||
bool switch_needed;
|
||||
|
||||
sdbg("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;
|
||||
sdbg("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)
|
||||
{
|
||||
sdbg("Delivering signals TCB=%p\n", rtcb);
|
||||
((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
|
||||
rtcb->xcp.sigdeliver = NULL;
|
||||
}
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_longjmp(rtcb->xcp.regs, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_createstack.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public 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 stack_alloc_ptr 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_create_stack(_TCB *tcb, size_t stack_size)
|
||||
{
|
||||
int ret = ERROR;
|
||||
|
||||
/* Move up to next even word boundary if necessary */
|
||||
|
||||
size_t adj_stack_size = (stack_size + 3) & ~3;
|
||||
size_t adj_stack_words = adj_stack_size >> 2;
|
||||
|
||||
/* Allocate the memory for the stack */
|
||||
|
||||
uint32_t *stack_alloc_ptr = (uint32_t*)kmalloc(adj_stack_size);
|
||||
if (stack_alloc_ptr)
|
||||
{
|
||||
/* This is the address of the last word in the allocation */
|
||||
|
||||
size_t *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;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/****************************************************************************
|
||||
* up_devconsole.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t devconsole_read(struct file *, char *, size_t);
|
||||
static ssize_t devconsole_write(struct file *, const char *, size_t);
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
static int devconsole_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
bool setup);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct file_operations devconsole_fops =
|
||||
{
|
||||
.read = devconsole_read,
|
||||
.write = devconsole_write,
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
.poll = devconsole_poll,
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t devconsole_read(struct file *filp, char *buffer, size_t len)
|
||||
{
|
||||
return up_hostread(buffer, len);
|
||||
}
|
||||
|
||||
static ssize_t devconsole_write(struct file *filp, const char *buffer, size_t len)
|
||||
{
|
||||
return up_hostwrite(buffer, len);
|
||||
}
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
static int devconsole_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
bool setup)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void up_devconsole(void)
|
||||
{
|
||||
(void)register_driver("/dev/console", &devconsole_fops, 0666, NULL);
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
/****************************************************************************
|
||||
* up_deviceimage.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef VFAT_STANDALONE
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <zlib.h>
|
||||
#else
|
||||
# include <nuttx/config.h>
|
||||
# include <stdlib.h>
|
||||
# include <debug.h>
|
||||
# include <zlib.h>
|
||||
# include "up_internal.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef VFAT_STANDALONE
|
||||
# define sdbg(format, arg...) printf(format, ##arg)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This array holds a compressed VFAT file system created with:
|
||||
*
|
||||
* /sbin/mkdosfs -C -F 32 -I -n "NuttXTestVol" -S 512 -v nuttx-test.vfat 1024
|
||||
* sudo mkdir /mnt/loop
|
||||
* sudo mount -o loop nuttx-test.vfat /mnt/loop
|
||||
* mkdir /mnt/loop/TestDir
|
||||
* echo "This is a test" >/mnt/loop/TestDir/TestFile.txt
|
||||
* sudo umount /mnt/loop
|
||||
* gzip nuttx-test.vfat
|
||||
* xxd -g 1 nuttx-test.vfat.gz >some-file
|
||||
*
|
||||
* Then manually massaged from the gzip xxd output to zlib format. See
|
||||
* http://www.faqs.org/rfcs/rfc1952.html. This amounts to:
|
||||
*
|
||||
* Remove all of the leading bytes through the null terminator of the file name
|
||||
* Remove the last 8 bytes
|
||||
* Add 0x08, 0x1d to the beginning.
|
||||
*/
|
||||
|
||||
static const unsigned char g_vfatdata[] =
|
||||
{
|
||||
0x08, 0x1d, 0xed, 0xdd, 0xcf, 0x6a, 0x13, 0x41, 0x18, 0x00, 0xf0, 0xa9, 0x16, 0x5b, 0x2a, 0x6d,
|
||||
0x73, 0x12, 0x3c, 0x39, 0x78, 0xf3, 0xb2, 0x87, 0x0a, 0x3d, 0x78, 0x32, 0xd0, 0x06, 0x0a, 0xa2,
|
||||
0xa5, 0xa6, 0xa5, 0x17, 0x95, 0x2d, 0xd9, 0x6a, 0x68, 0x4c, 0xda, 0xec, 0x8a, 0x2d, 0x78, 0xf3,
|
||||
0x01, 0xf4, 0x39, 0x8a, 0xb7, 0x7a, 0x13, 0xc5, 0x17, 0xe8, 0x5b, 0x78, 0xcb, 0xc5, 0x63, 0x4f,
|
||||
0xc6, 0x8d, 0x69, 0x8b, 0x45, 0xc4, 0x3f, 0x20, 0x51, 0xfc, 0xfd, 0xd8, 0xe1, 0xdb, 0xd9, 0x8f,
|
||||
0x81, 0x59, 0xe6, 0x63, 0x59, 0xd8, 0x85, 0xe9, 0xad, 0xbf, 0x7c, 0xbc, 0xd5, 0xe8, 0xe4, 0x9b,
|
||||
0x79, 0x08, 0xe7, 0xc6, 0x62, 0x38, 0x17, 0x42, 0x98, 0x3c, 0x0a, 0x21, 0x86, 0x9b, 0xe1, 0x44,
|
||||
0xe5, 0x38, 0x0e, 0x72, 0x63, 0xe1, 0x42, 0x38, 0xeb, 0xda, 0xf2, 0xbd, 0x3b, 0xb5, 0xdb, 0x4f,
|
||||
0x8a, 0x62, 0xbd, 0x9e, 0xe5, 0xc5, 0x5a, 0xa7, 0x56, 0xad, 0x5f, 0x9f, 0x8b, 0x31, 0xce, 0x5c,
|
||||
0x79, 0xf7, 0xf4, 0xd9, 0xab, 0xab, 0xef, 0x8b, 0x8b, 0x6b, 0xaf, 0x67, 0xde, 0x4c, 0x84, 0xc3,
|
||||
0xca, 0xfd, 0xde, 0xc7, 0xb9, 0x0f, 0x87, 0x97, 0x0e, 0x2f, 0xf7, 0x3e, 0xd5, 0x1f, 0x35, 0xf3,
|
||||
0x58, 0x1e, 0xed, 0x4e, 0x11, 0xd3, 0xb8, 0xd1, 0xe9, 0x14, 0xe9, 0x46, 0x2b, 0x8b, 0x8d, 0x66,
|
||||
0xbe, 0x95, 0xc4, 0xb8, 0xdc, 0xca, 0xd2, 0x3c, 0x8b, 0xcd, 0x76, 0x9e, 0x75, 0xcf, 0xe4, 0x37,
|
||||
0x5b, 0x9d, 0xed, 0xed, 0xbd, 0x98, 0xb6, 0x1b, 0xd3, 0x53, 0xdb, 0xdd, 0x2c, 0xcf, 0xcb, 0xd3,
|
||||
0xbd, 0xb8, 0x95, 0xed, 0xc5, 0xa2, 0x13, 0x8b, 0x6e, 0x99, 0x79, 0x98, 0x36, 0xdb, 0x31, 0x49,
|
||||
0x92, 0x38, 0x3d, 0x15, 0xf8, 0x91, 0xd5, 0xfd, 0x95, 0x95, 0xb4, 0x3a, 0xea, 0x59, 0xf0, 0x67,
|
||||
0x75, 0xbb, 0xd5, 0xf4, 0xed, 0x44, 0x08, 0xe3, 0xdf, 0x64, 0x56, 0xf7, 0x47, 0x30, 0x1d, 0x00,
|
||||
0x60, 0xc4, 0x7a, 0xde, 0xff, 0xff, 0x63, 0xde, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x76, 0x47, 0xfd, 0xfe, 0x6c, 0xbf, 0x6c, 0x27, 0x71, 0xd0,
|
||||
0x46, 0x3d, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xd7, 0xf8, 0xfe, 0x0f, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xbe, 0xaf, 0x36, 0xee, 0x9c, 0x0c, 0xe1, 0xc6, 0xf3,
|
||||
0x83, 0xf9, 0x83, 0xf9, 0x61, 0x1c, 0xe6, 0xab, 0xf5, 0x90, 0x85, 0x3c, 0x14, 0x61, 0x21, 0xcc,
|
||||
0x86, 0x07, 0xcd, 0xd0, 0x2d, 0xaf, 0xf5, 0xbf, 0x18, 0xc6, 0xfa, 0xe2, 0xdd, 0xfa, 0xc2, 0xd2,
|
||||
0x4a, 0x2c, 0x55, 0x42, 0xe3, 0xc5, 0xf1, 0xf8, 0x41, 0x3c, 0x3f, 0xd2, 0xfb, 0xe2, 0xe7, 0x24,
|
||||
0xf1, 0x54, 0x25, 0x84, 0x9d, 0xe3, 0xf5, 0xdb, 0x39, 0x5d, 0xbf, 0x24, 0xf9, 0x5e, 0x7e, 0x38,
|
||||
0xfe, 0xb4, 0x3e, 0x6a, 0x65, 0x7d, 0xec, 0x36, 0x43, 0xab, 0xec, 0x26, 0x65, 0x77, 0xb7, 0xcc,
|
||||
0x15, 0x65, 0x1b, 0xd4, 0x47, 0x6d, 0xe9, 0xd6, 0x62, 0x7d, 0xbd, 0x1e, 0xcf, 0xd6, 0xc7, 0x78,
|
||||
0xf0, 0xa3, 0xc9, 0xe8, 0x9d, 0x6c, 0xc4, 0x9b, 0xc6, 0xa2, 0x7c, 0x08, 0xd8, 0x33, 0x17, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x77, 0x7d, 0x06
|
||||
};
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_deviceimage
|
||||
*
|
||||
* Description: Return an allocated buffer representing an in-memory VFAT
|
||||
* file system.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
char *up_deviceimage(void)
|
||||
{
|
||||
char *pbuffer;
|
||||
int bufsize = 1024*1024;
|
||||
int offset = 0;
|
||||
z_stream strm;
|
||||
int ret;
|
||||
|
||||
/* Ininitilize inflate state */
|
||||
|
||||
strm.zalloc = Z_NULL;
|
||||
strm.zfree = Z_NULL;
|
||||
strm.opaque = Z_NULL;
|
||||
strm.avail_in = 0;
|
||||
strm.next_in = Z_NULL;
|
||||
ret = inflateInit(&strm);
|
||||
if (ret != Z_OK)
|
||||
{
|
||||
sdbg("inflateInit FAILED: ret=%d msg=\"%s\"\n", ret, strm.msg ? strm.msg : "No message" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Allocate a buffer to hold the decompressed buffer. We may have
|
||||
* to reallocate this a few times to get the size right.
|
||||
*/
|
||||
pbuffer = (char*)malloc(bufsize);
|
||||
|
||||
/* Set up the input buffer */
|
||||
|
||||
strm.avail_in = sizeof(g_vfatdata);
|
||||
strm.next_in = (Bytef*)g_vfatdata;
|
||||
|
||||
/* Run inflate() on input until output buffer not full */
|
||||
|
||||
do {
|
||||
/* Set up to catch the next output chunk in the output buffer */
|
||||
|
||||
strm.avail_out = bufsize - offset;
|
||||
strm.next_out = (Bytef*)&pbuffer[offset];
|
||||
|
||||
/* inflate */
|
||||
|
||||
ret = inflate(&strm, Z_NO_FLUSH);
|
||||
|
||||
/* Handle inflate() error return values */
|
||||
|
||||
switch (ret)
|
||||
{
|
||||
case Z_NEED_DICT:
|
||||
case Z_DATA_ERROR:
|
||||
case Z_MEM_ERROR:
|
||||
case Z_STREAM_ERROR:
|
||||
sdbg("inflate FAILED: ret=%d msg=\"%s\"\n", ret, strm.msg ? strm.msg : "No message" );
|
||||
(void)inflateEnd(&strm);
|
||||
free(pbuffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If avail_out is zero, then inflate() returned only
|
||||
* because it is out of buffer space. In this case, we
|
||||
* will have to reallocate the buffer and try again.
|
||||
*/
|
||||
|
||||
if (strm.avail_out == 0)
|
||||
{
|
||||
int newbufsize = bufsize + 128*1024;
|
||||
char *newbuffer = realloc(pbuffer, newbufsize);
|
||||
if (!newbuffer)
|
||||
{
|
||||
free(pbuffer);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuffer = newbuffer;
|
||||
offset = bufsize;
|
||||
bufsize = newbufsize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There are unused bytes in the buffer, reallocate to
|
||||
* correct size.
|
||||
*/
|
||||
|
||||
int newbufsize = bufsize - strm.avail_out;
|
||||
char *newbuffer = realloc(pbuffer, newbufsize);
|
||||
if (!newbuffer)
|
||||
{
|
||||
free(pbuffer);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuffer = newbuffer;
|
||||
bufsize = newbufsize;
|
||||
}
|
||||
}
|
||||
} while (strm.avail_out == 0 && ret != Z_STREAM_END);
|
||||
|
||||
(void)inflateEnd(&strm);
|
||||
return pbuffer;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: main
|
||||
*
|
||||
* Description: Used to test decompression logic
|
||||
*
|
||||
* gcc -g -Wall -DVFAT_STANDALONE -lz -o vfat-test up_deviceimage.c
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef VFAT_STANDALONE
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
char *deviceimage;
|
||||
int cmf;
|
||||
int fdict;
|
||||
int flg;
|
||||
int check;
|
||||
|
||||
cmf = g_vfatdata[0];
|
||||
printf("CMF=%02x: CM=%d CINFO=%d\n", cmf, cmf &0x0f, cmf >> 4);
|
||||
|
||||
flg = g_vfatdata[1];
|
||||
fdict = (flg >> 5) & 1;
|
||||
|
||||
printf("FLG=%02x: FCHECK=%d FDICT=%d FLEVEL=%d\n", flg, flg &0x1f, fdict, flg >> 6);
|
||||
|
||||
/* The FCHECK value must be such that CMF and FLG, when viewed as
|
||||
* a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG),
|
||||
* is a multiple of 31.
|
||||
*/
|
||||
|
||||
check = cmf*256 + flg;
|
||||
if (check % 31 != 0)
|
||||
{
|
||||
printf("Fails check: %04x is not a multiple of 31\n", check);
|
||||
}
|
||||
|
||||
deviceimage = up_deviceimage();
|
||||
if (deviceimage)
|
||||
{
|
||||
printf("Inflate SUCCEEDED\n");
|
||||
free(deviceimage);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Inflate FAILED\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
/****************************************************************************
|
||||
* up_exit.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "os_internal.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: _exit
|
||||
*
|
||||
* Description:
|
||||
* This function causes the currently executing task to cease
|
||||
* to exist. This is a special case of task_delete() where the task to
|
||||
* be deleted is the currently executing task. It is more complex because
|
||||
* a context switch must be perform to the next ready to run task.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void _exit(int status)
|
||||
{
|
||||
_TCB* tcb;
|
||||
|
||||
sdbg("TCB=%p exitting\n", tcb);
|
||||
|
||||
/* Destroy the task at the head of the ready to run list. */
|
||||
|
||||
(void)task_deletecurrent();
|
||||
|
||||
/* Now, perform the context switch to the new ready-to-run task at the
|
||||
* head of the list.
|
||||
*/
|
||||
|
||||
tcb = (_TCB*)g_readytorun.head;
|
||||
sdbg("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)
|
||||
{
|
||||
sdbg("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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,399 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_framebuffer.c
|
||||
*
|
||||
* Copyright (C) 2008-2010 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/fb.h>
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_SIM_FBWIDTH
|
||||
# define CONFIG_SIM_FBWIDTH 480 /* Framebuffer width in pixels */
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SIM_FBHEIGHT
|
||||
# define CONFIG_SIM_FBHEIGHT 240 /* Framebuffer height in pixels */
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SIM_FBBPP
|
||||
# define CONFIG_SIM_FBBPP 16 /* Framebuffer bytes per pixel (RGB) */
|
||||
#endif
|
||||
|
||||
#undef FB_FMT
|
||||
#if CONFIG_SIM_FBBPP == 1
|
||||
# define FB_FMT FB_FMT_RGB1
|
||||
#elif CONFIG_SIM_FBBPP == 4
|
||||
# define FB_FMT FB_FMT_RGB4
|
||||
#elif CONFIG_SIM_FBBPP == 8
|
||||
# define FB_FMT FB_FMT_RGB8
|
||||
#elif CONFIG_SIM_FBBPP == 16
|
||||
# define FB_FMT FB_FMT_RGB16_565
|
||||
#elif CONFIG_SIM_FBBPP == 24
|
||||
# define FB_FMT FB_FMT_RGB24
|
||||
#elif CONFIG_SIM_FBBPP == 32
|
||||
# define FB_FMT FB_FMT_RGB32
|
||||
#else
|
||||
# error "Unsupported BPP"
|
||||
#endif
|
||||
|
||||
/* Framebuffer characteristics in bytes */
|
||||
|
||||
#define FB_WIDTH ((CONFIG_SIM_FBWIDTH * CONFIG_SIM_FBBPP + 7) / 8)
|
||||
#define FB_SIZE (FB_WIDTH * CONFIG_SIM_FBHEIGHT)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* Get information about the video controller configuration and the configuration
|
||||
* of each color plane.
|
||||
*/
|
||||
|
||||
static int up_getvideoinfo(FAR struct fb_vtable_s *vtable, FAR struct fb_videoinfo_s *vinfo);
|
||||
static int up_getplaneinfo(FAR struct fb_vtable_s *vtable, int planeno, FAR struct fb_planeinfo_s *pinfo);
|
||||
|
||||
/* The following is provided only if the video hardware supports RGB color mapping */
|
||||
|
||||
#ifdef CONFIG_FB_CMAP
|
||||
static int up_getcmap(FAR struct fb_vtable_s *vtable, FAR struct fb_cmap_s *cmap);
|
||||
static int up_putcmap(FAR struct fb_vtable_s *vtable, FAR const struct fb_cmap_s *cmap);
|
||||
#endif
|
||||
/* The following is provided only if the video hardware supports a hardware cursor */
|
||||
|
||||
#ifdef CONFIG_FB_HWCURSOR
|
||||
static int up_getcursor(FAR struct fb_vtable_s *vtable, FAR struct fb_cursorattrib_s *attrib);
|
||||
static int up_setcursor(FAR struct fb_vtable_s *vtable, FAR struct fb_setcursor_s *setttings);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* The simulated framebuffer memory */
|
||||
|
||||
#ifndef CONFIG_SIM_X11FB
|
||||
static uint8_t g_fb[FB_SIZE];
|
||||
#endif
|
||||
|
||||
/* This structure describes the simulated video controller */
|
||||
|
||||
static const struct fb_videoinfo_s g_videoinfo =
|
||||
{
|
||||
.fmt = FB_FMT,
|
||||
.xres = CONFIG_SIM_FBWIDTH,
|
||||
.yres = CONFIG_SIM_FBHEIGHT,
|
||||
.nplanes = 1,
|
||||
};
|
||||
|
||||
#ifndef CONFIG_SIM_X11FB
|
||||
/* This structure describes the single, simulated color plane */
|
||||
|
||||
static const struct fb_planeinfo_s g_planeinfo =
|
||||
{
|
||||
.fbmem = (FAR void *)&g_fb,
|
||||
.fblen = FB_SIZE,
|
||||
.stride = FB_WIDTH,
|
||||
.bpp = CONFIG_SIM_FBBPP,
|
||||
};
|
||||
#else
|
||||
/* This structure describes the single, X11 color plane */
|
||||
|
||||
static struct fb_planeinfo_s g_planeinfo;
|
||||
#endif
|
||||
|
||||
/* Current cursor position */
|
||||
|
||||
#ifdef CONFIG_FB_HWCURSOR
|
||||
static struct fb_cursorpos_s g_cpos;
|
||||
|
||||
/* Current cursor size */
|
||||
|
||||
#ifdef CONFIG_FB_HWCURSORSIZE
|
||||
static struct fb_cursorsize_s g_csize;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* The framebuffer object -- There is no private state information in this simple
|
||||
* framebuffer simulation.
|
||||
*/
|
||||
|
||||
struct fb_vtable_s g_fbobject =
|
||||
{
|
||||
.getvideoinfo = up_getvideoinfo,
|
||||
.getplaneinfo = up_getplaneinfo,
|
||||
#ifdef CONFIG_FB_CMAP
|
||||
.getcmap = up_getcmap,
|
||||
.putcmap = up_putcmap,
|
||||
#endif
|
||||
#ifdef CONFIG_FB_HWCURSOR
|
||||
.getcursor = up_getcursor,
|
||||
.setcursor = up_setcursor,
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_getvideoinfo
|
||||
****************************************************************************/
|
||||
|
||||
static int up_getvideoinfo(FAR struct fb_vtable_s *vtable,
|
||||
FAR struct fb_videoinfo_s *vinfo)
|
||||
{
|
||||
dbg("vtable=%p vinfo=%p\n", vtable, vinfo);
|
||||
if (vtable && vinfo)
|
||||
{
|
||||
memcpy(vinfo, &g_videoinfo, sizeof(struct fb_videoinfo_s));
|
||||
return OK;
|
||||
}
|
||||
dbg("Returning EINVAL\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_getplaneinfo
|
||||
****************************************************************************/
|
||||
|
||||
static int up_getplaneinfo(FAR struct fb_vtable_s *vtable, int planeno,
|
||||
FAR struct fb_planeinfo_s *pinfo)
|
||||
{
|
||||
dbg("vtable=%p planeno=%d pinfo=%p\n", vtable, planeno, pinfo);
|
||||
if (vtable && planeno == 0 && pinfo)
|
||||
{
|
||||
memcpy(pinfo, &g_planeinfo, sizeof(struct fb_planeinfo_s));
|
||||
return OK;
|
||||
}
|
||||
dbg("Returning EINVAL\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_getcmap
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_FB_CMAP
|
||||
static int up_getcmap(FAR struct fb_vtable_s *vtable, FAR struct fb_cmap_s *cmap)
|
||||
{
|
||||
int len;
|
||||
int i;
|
||||
|
||||
dbg("vtable=%p cmap=%p len=%d\n", vtable, cmap, cmap->len);
|
||||
if (vtable && cmap)
|
||||
{
|
||||
for (i = cmap->first, len = 0; i < 256 && len < cmap->len; i++, len++)
|
||||
{
|
||||
cmap->red[i] = i;
|
||||
cmap->green[i] = i;
|
||||
cmap->blue[i] = i;
|
||||
#ifdef CONFIG_FB_TRANSPARENCY
|
||||
cmap->transp[i] = i;
|
||||
#endif
|
||||
}
|
||||
|
||||
cmap->len = len;
|
||||
return OK;
|
||||
}
|
||||
dbg("Returning EINVAL\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_putcmap
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_FB_CMAP
|
||||
static int up_putcmap(FAR struct fb_vtable_s *vtable, FAR const struct fb_cmap_s *cmap)
|
||||
{
|
||||
#ifdef CONFIG_SIM_X11FB
|
||||
return up_x11cmap(cmap->first, cmap->len, cmap->red, cmap->green, cmap->blue, NULL);
|
||||
#else
|
||||
dbg("vtable=%p cmap=%p len=%d\n", vtable, cmap, cmap->len);
|
||||
if (vtable && cmap)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
dbg("Returning EINVAL\n");
|
||||
return -EINVAL;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_getcursor
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_FB_HWCURSOR
|
||||
static int up_getcursor(FAR struct fb_vtable_s *vtable,
|
||||
FAR struct fb_cursorattrib_s *attrib)
|
||||
{
|
||||
dbg("vtable=%p attrib=%p\n", vtable, attrib);
|
||||
if (vtable && attrib)
|
||||
{
|
||||
#ifdef CONFIG_FB_HWCURSORIMAGE
|
||||
attrib->fmt = FB_FMT;
|
||||
#endif
|
||||
dbg("pos: (x=%d, y=%d)\n", g_cpos.x, g_cpos.y);
|
||||
attrib->pos = g_cpos;
|
||||
#ifdef CONFIG_FB_HWCURSORSIZE
|
||||
attrib->mxsize.h = CONFIG_SIM_FBHEIGHT;
|
||||
attrib->mxsize.w = CONFIG_SIM_FBWIDTH;
|
||||
dbg("size: (h=%d, w=%d)\n", g_csize.h, g_csize.w);
|
||||
attrib->size = g_csize;
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
dbg("Returning EINVAL\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name:
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_FB_HWCURSOR
|
||||
static int up_setcursor(FAR struct fb_vtable_s *vtable,
|
||||
FAR struct fb_setcursor_s *setttings)
|
||||
{
|
||||
dbg("vtable=%p setttings=%p\n", vtable, setttings);
|
||||
if (vtable && setttings)
|
||||
{
|
||||
dbg("flags: %02x\n", settings->flags);
|
||||
if ((flags & FB_CUR_SETPOSITION) != 0)
|
||||
{
|
||||
g_cpos = settings->pos;
|
||||
dbg("pos: (h:%d, w:%d)\n", g_cpos.x, g_cpos.y);
|
||||
}
|
||||
#ifdef CONFIG_FB_HWCURSORSIZE
|
||||
if ((flags & FB_CUR_SETSIZE) != 0)
|
||||
{
|
||||
g_csize = settings->size;
|
||||
dbg("size: (h:%d, w:%d)\n", g_csize.h, g_csize.w);
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_FB_HWCURSORIMAGE
|
||||
if ((flags & FB_CUR_SETIMAGE) != 0)
|
||||
{
|
||||
dbg("image: (h:%d, w:%d) @ %p\n",
|
||||
settings->img.height, settings->img.width, settings->img.image);
|
||||
}
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
dbg("Returning EINVAL\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_fbinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the video hardware
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_fbinitialize(void)
|
||||
{
|
||||
#ifdef CONFIG_SIM_X11FB
|
||||
return up_x11initialize(CONFIG_SIM_FBWIDTH, CONFIG_SIM_FBHEIGHT,
|
||||
&g_planeinfo.fbmem, &g_planeinfo.fblen,
|
||||
&g_planeinfo.bpp, &g_planeinfo.stride);
|
||||
#else
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_fbgetvplane
|
||||
*
|
||||
* Description:
|
||||
* Return a a reference to the framebuffer object for the specified video plane.
|
||||
*
|
||||
* Input parameters:
|
||||
* None
|
||||
*
|
||||
* Returned value:
|
||||
* Reference to the framebuffer object (NULL on failure)
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
FAR struct fb_vtable_s *up_fbgetvplane(int vplane)
|
||||
{
|
||||
if (vplane == 0)
|
||||
{
|
||||
return &g_fbobject;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_fbteardown
|
||||
****************************************************************************/
|
||||
|
||||
void fb_uninitialize(void)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/****************************************************************************
|
||||
* up_head.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011-2112 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <setjmp.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/init.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/power/pm.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static jmp_buf sim_abort;
|
||||
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
/* Power management should be initialized early in the (simulated) boot
|
||||
* sequence.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
pm_initialize();
|
||||
#endif
|
||||
|
||||
/* Then start NuttX */
|
||||
|
||||
if (setjmp(sim_abort) == 0)
|
||||
{
|
||||
os_start();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void up_assert(const uint8_t *filename, int line)
|
||||
{
|
||||
fprintf(stderr, "Assertion failed at file:%s line: %d\n", filename, line);
|
||||
longjmp(sim_abort, 1);
|
||||
}
|
||||
|
||||
void up_assert_code(const uint8_t *filename, int line, int code)
|
||||
{
|
||||
fprintf(stderr, "Assertion failed at file:%s line: %d error code: %d\n", filename, line, code);
|
||||
longjmp(sim_abort, 1);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_hostusleep.c
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_hostusleep
|
||||
****************************************************************************/
|
||||
|
||||
int up_hostusleep(unsigned int usec)
|
||||
{
|
||||
return usleep(usec);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
/****************************************************************************
|
||||
* up_idle.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/power/pm.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SIM_X11FB
|
||||
static int g_x11refresh = 0;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_SIM_WALLTIME) || defined(CONFIG_SIM_X11FB)
|
||||
extern int up_hostusleep(unsigned int usec);
|
||||
#ifdef CONFIG_SIM_X11FB
|
||||
extern void up_x11update(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_idle
|
||||
*
|
||||
* Description:
|
||||
* up_idle() is the logic that will be executed when their
|
||||
* is no other ready-to-run task. This is processor idle
|
||||
* time and will continue until some interrupt occurs to
|
||||
* cause a context switch from the idle task.
|
||||
*
|
||||
* Processing in this state may be processor-specific. e.g.,
|
||||
* this is where power management operations might be
|
||||
* performed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_idle(void)
|
||||
{
|
||||
/* If the system is idle, then process "fake" timer interrupts.
|
||||
* Hopefully, something will wake up.
|
||||
*/
|
||||
|
||||
sched_process_timer();
|
||||
|
||||
/* Run the network if enabled */
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
uipdriver_loop();
|
||||
#endif
|
||||
|
||||
/* Fake some power management stuff for testing purposes */
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
{
|
||||
static enum pm_state_e state = PM_NORMAL;
|
||||
enum pm_state_e newstate;
|
||||
|
||||
newstate = pm_checkstate();
|
||||
if (newstate != state)
|
||||
{
|
||||
if (pm_changestate(newstate) == OK)
|
||||
{
|
||||
state = newstate;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Wait a bit so that the sched_process_timer() is called close to the
|
||||
* correct rate.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_SIM_WALLTIME) || defined(CONFIG_SIM_X11FB)
|
||||
(void)up_hostusleep(1000000 / CLK_TCK);
|
||||
|
||||
/* Handle X11-related events */
|
||||
|
||||
#ifdef CONFIG_SIM_X11FB
|
||||
if (g_x11initialized)
|
||||
{
|
||||
/* Drive the X11 event loop */
|
||||
|
||||
#ifdef CONFIG_SIM_TOUCHSCREEN
|
||||
if (g_eventloop)
|
||||
{
|
||||
up_x11events();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Update the display periodically */
|
||||
|
||||
g_x11refresh += 1000000 / CLK_TCK;
|
||||
if (g_x11refresh > 500000)
|
||||
{
|
||||
up_x11update();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/****************************************************************************
|
||||
* up_initialize.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/ramlog.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_initialize
|
||||
*
|
||||
* Description:
|
||||
* up_initialize will be called once during OS
|
||||
* initialization after the basic OS services have been
|
||||
* initialized. The architecture specific details of
|
||||
* initializing the OS will be handled here. Such things as
|
||||
* setting up interrupt service routines, starting the
|
||||
* clock, and registering device drivers are some of the
|
||||
* things that are different for each processor and hardware
|
||||
* platform.
|
||||
*
|
||||
* up_initialize is called after the OS initialized but
|
||||
* before the init process has been started and before the
|
||||
* libraries have been initialized. OS services and driver
|
||||
* services are available.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_initialize(void)
|
||||
{
|
||||
/* The real purpose of the following is to make sure that lib_rawprintf
|
||||
* is drawn into the link. It is needed by up_tapdev which is linked
|
||||
* separately.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
lib_rawprintf("SIM: Initializing");
|
||||
#endif
|
||||
|
||||
/* Register devices */
|
||||
|
||||
devnull_register(); /* Standard /dev/null */
|
||||
devzero_register(); /* Standard /dev/zero */
|
||||
|
||||
/* Register a console (or not) */
|
||||
|
||||
#if defined(USE_DEVCONSOLE)
|
||||
up_devconsole(); /* Our private /dev/console */
|
||||
#elif defined(CONFIG_RAMLOG_CONSOLE)
|
||||
ramlog_consoleinit();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SYSLOG_CHAR
|
||||
syslog_initialize();
|
||||
#endif
|
||||
#ifdef CONFIG_RAMLOG_SYSLOG
|
||||
ramlog_sysloginit(); /* System logging device */
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_FS_FAT) && !defined(CONFIG_DISABLE_MOUNTPOINT)
|
||||
up_registerblockdevice(); /* Our FAT ramdisk at /dev/ram0 */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
uipdriver_init(); /* Our "real" network driver */
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* up_initialstate.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_initial_state
|
||||
*
|
||||
* Description:
|
||||
* A new thread is being started and a new TCB
|
||||
* has been created. This function is called to initialize
|
||||
* the processor specific portions of the new TCB.
|
||||
*
|
||||
* This function must setup the intial architecture registers
|
||||
* and/or stack so that execution will begin at tcb->start
|
||||
* on the next context switch.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_initial_state(_TCB *tcb)
|
||||
{
|
||||
memset(&tcb->xcp, 0, sizeof(struct xcptcontext));
|
||||
tcb->xcp.regs[JB_SP] = (uint32_t)tcb->adj_stack_ptr;
|
||||
tcb->xcp.regs[JB_PC] = (uint32_t)tcb->start;
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
/**************************************************************************
|
||||
* up_internal.h
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef __ARCH_UP_INTERNAL_H
|
||||
#define __ARCH_UP_INTERNAL_H
|
||||
|
||||
/**************************************************************************
|
||||
* Included Files
|
||||
**************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
/**************************************************************************
|
||||
* Pre-processor Definitions
|
||||
**************************************************************************/
|
||||
/* Configuration **********************************************************/
|
||||
|
||||
#ifndef CONFIG_SIM_X11FB
|
||||
# ifdef CONFIG_SIM_TOUCHSCREEN
|
||||
# error "CONFIG_SIM_TOUCHSCREEN depends on CONFIG_SIM_X11FB"
|
||||
# undef CONFIG_SIM_TOUCHSCREEN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_INPUT
|
||||
# ifdef CONFIG_SIM_TOUCHSCREEN
|
||||
# error "CONFIG_SIM_TOUCHSCREEN depends on CONFIG_INPUT"
|
||||
# undef CONFIG_SIM_TOUCHSCREEN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Determine which (if any) console driver to use */
|
||||
|
||||
#if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS == 0
|
||||
# undef USE_DEVCONSOLE
|
||||
# undef CONFIG_RAMLOG_CONSOLE
|
||||
#else
|
||||
# if defined(CONFIG_RAMLOG_CONSOLE)
|
||||
# undef USE_DEVCONSOLE
|
||||
# else
|
||||
# define USE_DEVCONSOLE 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Determine which device to use as the system logging device */
|
||||
|
||||
#ifndef CONFIG_SYSLOG
|
||||
# undef CONFIG_SYSLOG_CHAR
|
||||
# undef CONFIG_RAMLOG_SYSLOG
|
||||
#endif
|
||||
|
||||
/* Context Switching 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__ */
|
||||
|
||||
/* Simulated Heap Definitions **********************************************/
|
||||
/* Size of the simulated heap */
|
||||
|
||||
#if CONFIG_MM_SMALL
|
||||
# define SIM_HEAP_SIZE (64*1024)
|
||||
#else
|
||||
# define SIM_HEAP_SIZE (4*1024*1024)
|
||||
#endif
|
||||
|
||||
/* File System Definitions **************************************************/
|
||||
/* These definitions characterize the compressed filesystem image */
|
||||
|
||||
#define BLOCK_COUNT 1024
|
||||
#define SECTOR_OF_BACKUPT 6
|
||||
#define NUMBER_OF_FATS 2
|
||||
#define FAT_SIZE 32
|
||||
#define NUM_HIDDEN_SECTORS 0
|
||||
#define VOLUME_NAME "NuttXTestVol"
|
||||
#define USE_WHOLE_DEVICE 1
|
||||
#define ROOT_DIR_ENTRIES 512
|
||||
#define RESERVED_SECTORS 32
|
||||
#define SECTORS_PER_CLUSTER 4
|
||||
#define LOGICAL_SECTOR_SIZE 512
|
||||
|
||||
/**************************************************************************
|
||||
* Public Types
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Public Variables
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#ifdef CONFIG_SIM_X11FB
|
||||
extern int g_x11initialized;
|
||||
#ifdef CONFIG_SIM_TOUCHSCREEN
|
||||
extern volatile int g_eventloop;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**************************************************************************
|
||||
* Public Function Prototypes
|
||||
**************************************************************************/
|
||||
|
||||
/* up_setjmp.S ************************************************************/
|
||||
|
||||
extern int up_setjmp(int *jb);
|
||||
extern void up_longjmp(int *jb, int val) __attribute__ ((noreturn));
|
||||
|
||||
/* up_devconsole.c ********************************************************/
|
||||
|
||||
extern void up_devconsole(void);
|
||||
extern void up_registerblockdevice(void);
|
||||
|
||||
/* up_deviceimage.c *******************************************************/
|
||||
|
||||
extern char *up_deviceimage(void);
|
||||
|
||||
/* up_stdio.c *************************************************************/
|
||||
|
||||
extern size_t up_hostread(void *buffer, size_t len);
|
||||
extern size_t up_hostwrite(const void *buffer, size_t len);
|
||||
|
||||
/* up_netdev.c ************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
extern unsigned long up_getwalltime( void );
|
||||
#endif
|
||||
|
||||
/* up_x11framebuffer.c ******************************************************/
|
||||
|
||||
#ifdef CONFIG_SIM_X11FB
|
||||
extern int up_x11initialize(unsigned short width, unsigned short height,
|
||||
void **fbmem, unsigned int *fblen, unsigned char *bpp,
|
||||
unsigned short *stride);
|
||||
#ifdef CONFIG_FB_CMAP
|
||||
extern int up_x11cmap(unsigned short first, unsigned short len,
|
||||
unsigned char *red, unsigned char *green,
|
||||
unsigned char *blue, unsigned char *transp);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* up_eventloop.c ***********************************************************/
|
||||
|
||||
#if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN)
|
||||
extern void up_x11events(void);
|
||||
#endif
|
||||
|
||||
/* up_eventloop.c ***********************************************************/
|
||||
|
||||
#if defined(CONFIG_SIM_X11FB) && defined(CONFIG_SIM_TOUCHSCREEN)
|
||||
extern int up_buttonevent(int x, int y, int buttons);
|
||||
#endif
|
||||
|
||||
/* up_tapdev.c ************************************************************/
|
||||
|
||||
#if defined(CONFIG_NET) && !defined(__CYGWIN__)
|
||||
extern void tapdev_init(void);
|
||||
extern unsigned int tapdev_read(unsigned char *buf, unsigned int buflen);
|
||||
extern void tapdev_send(unsigned char *buf, unsigned int buflen);
|
||||
|
||||
#define netdev_init() tapdev_init()
|
||||
#define netdev_read(buf,buflen) tapdev_read(buf,buflen)
|
||||
#define netdev_send(buf,buflen) tapdev_send(buf,buflen)
|
||||
#endif
|
||||
|
||||
/* up_wpcap.c *************************************************************/
|
||||
|
||||
#if defined(CONFIG_NET) && defined(__CYGWIN__)
|
||||
extern void wpcap_init(void);
|
||||
extern unsigned int wpcap_read(unsigned char *buf, unsigned int buflen);
|
||||
extern void wpcap_send(unsigned char *buf, unsigned int buflen);
|
||||
|
||||
#define netdev_init() wpcap_init()
|
||||
#define netdev_read(buf,buflen) wpcap_read(buf,buflen)
|
||||
#define netdev_send(buf,buflen) wpcap_send(buf,buflen)
|
||||
#endif
|
||||
|
||||
/* up_uipdriver.c *********************************************************/
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
extern int uipdriver_init(void);
|
||||
extern int uipdriver_setmacaddr(unsigned char *macaddr);
|
||||
extern void uipdriver_loop(void);
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_UP_INTERNAL_H */
|
||||
@@ -0,0 +1,76 @@
|
||||
/****************************************************************************
|
||||
* up_interruptcontext.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_interrupt_context
|
||||
*
|
||||
* Description:
|
||||
* Return true is we are currently executing in the interrupt handler
|
||||
* context.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool up_interrupt_context(void)
|
||||
{
|
||||
/* The simulation is never in the interrupt state */
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,428 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_lcd.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/lcd/lcd.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
/* Check contrast selection */
|
||||
|
||||
#if !defined(CONFIG_LCD_MAXCONTRAST)
|
||||
# define CONFIG_LCD_MAXCONTRAST 100
|
||||
#endif
|
||||
|
||||
/* Check power setting */
|
||||
|
||||
#if !defined(CONFIG_LCD_MAXPOWER)
|
||||
# define CONFIG_LCD_MAXPOWER 100
|
||||
#endif
|
||||
|
||||
/* Simulated LCD geometry and color format */
|
||||
|
||||
#ifndef CONFIG_SIM_FBWIDTH
|
||||
# define CONFIG_SIM_FBWIDTH 320 /* Framebuffer width in pixels */
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SIM_FBHEIGHT
|
||||
# define CONFIG_SIM_FBHEIGHT 240 /* Framebuffer height in pixels */
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SIM_FBBPP
|
||||
# define CONFIG_SIM_FBBPP 16 /* Framebuffer bytes per pixel (RGB) */
|
||||
#endif
|
||||
|
||||
#define FB_STRIDE ((CONFIG_SIM_FBBPP * CONFIG_SIM_FBWIDTH + 7) >> 3)
|
||||
|
||||
#undef FB_FMT
|
||||
#if CONFIG_SIM_FBBPP == 1
|
||||
# define FB_FMT FB_FMT_RGB1
|
||||
#elif CONFIG_SIM_FBBPP == 4
|
||||
# define FB_FMT FB_FMT_RGB4
|
||||
#elif CONFIG_SIM_FBBPP == 8
|
||||
# define FB_FMT FB_FMT_RGB8
|
||||
#elif CONFIG_SIM_FBBPP == 16
|
||||
# define FB_FMT FB_FMT_RGB16_565
|
||||
#elif CONFIG_SIM_FBBPP == 24
|
||||
# define FB_FMT FB_FMT_RGB24
|
||||
#elif CONFIG_SIM_FBBPP == 32
|
||||
# define FB_FMT FB_FMT_RGB32
|
||||
#else
|
||||
# error "Unsupported BPP"
|
||||
#endif
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
/* Define CONFIG_DEBUG_LCD to enable detailed LCD debug output. Verbose debug must
|
||||
* also be enabled.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DEBUG
|
||||
# undef CONFIG_DEBUG_VERBOSE
|
||||
# undef CONFIG_DEBUG_GRAPHICS
|
||||
# undef CONFIG_DEBUG_LCD
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_DEBUG_VERBOSE
|
||||
# undef CONFIG_DEBUG_LCD
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEBUG_LCD
|
||||
# define lcddbg(format, arg...) vdbg(format, ##arg)
|
||||
#else
|
||||
# define lcddbg(x...)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Definition
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the state of this driver */
|
||||
|
||||
struct sim_dev_s
|
||||
{
|
||||
/* Publically visible device structure */
|
||||
|
||||
struct lcd_dev_s dev;
|
||||
|
||||
/* Private LCD-specific information follows */
|
||||
|
||||
uint8_t power; /* Current power setting */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Protototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* LCD Data Transfer Methods */
|
||||
|
||||
static int sim_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffer,
|
||||
size_t npixels);
|
||||
static int sim_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer,
|
||||
size_t npixels);
|
||||
|
||||
/* LCD Configuration */
|
||||
|
||||
static int sim_getvideoinfo(FAR struct lcd_dev_s *dev,
|
||||
FAR struct fb_videoinfo_s *vinfo);
|
||||
static int sim_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno,
|
||||
FAR struct lcd_planeinfo_s *pinfo);
|
||||
|
||||
/* LCD RGB Mapping */
|
||||
|
||||
#ifdef CONFIG_FB_CMAP
|
||||
# error "RGB color mapping not supported by this driver"
|
||||
#endif
|
||||
|
||||
/* Cursor Controls */
|
||||
|
||||
#ifdef CONFIG_FB_HWCURSOR
|
||||
# error "Cursor control not supported by this driver"
|
||||
#endif
|
||||
|
||||
/* LCD Specific Controls */
|
||||
|
||||
static int sim_getpower(struct lcd_dev_s *dev);
|
||||
static int sim_setpower(struct lcd_dev_s *dev, int power);
|
||||
static int sim_getcontrast(struct lcd_dev_s *dev);
|
||||
static int sim_setcontrast(struct lcd_dev_s *dev, unsigned int contrast);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This is working memory allocated by the LCD driver for each LCD device
|
||||
* and for each color plane. This memory will hold one raster line of data.
|
||||
* The size of the allocated run buffer must therefore be at least
|
||||
* (bpp * xres / 8). Actual alignment of the buffer must conform to the
|
||||
* bitwidth of the underlying pixel type.
|
||||
*
|
||||
* If there are multiple planes, they may share the same working buffer
|
||||
* because different planes will not be operate on concurrently. However,
|
||||
* if there are multiple LCD devices, they must each have unique run buffers.
|
||||
*/
|
||||
|
||||
static uint8_t g_runbuffer[FB_STRIDE];
|
||||
|
||||
/* This structure describes the overall LCD video controller */
|
||||
|
||||
static const struct fb_videoinfo_s g_videoinfo =
|
||||
{
|
||||
.fmt = FB_FMT, /* Color format: RGB16-565: RRRR RGGG GGGB BBBB */
|
||||
.xres = CONFIG_SIM_FBWIDTH, /* Horizontal resolution in pixel columns */
|
||||
.yres = CONFIG_SIM_FBHEIGHT, /* Vertical resolution in pixel rows */
|
||||
.nplanes = 1, /* Number of color planes supported */
|
||||
};
|
||||
|
||||
/* This is the standard, NuttX Plane information object */
|
||||
|
||||
static const struct lcd_planeinfo_s g_planeinfo =
|
||||
{
|
||||
.putrun = sim_putrun, /* Put a run into LCD memory */
|
||||
.getrun = sim_getrun, /* Get a run from LCD memory */
|
||||
.buffer = (uint8_t*)g_runbuffer, /* Run scratch buffer */
|
||||
.bpp = CONFIG_SIM_FBBPP, /* Bits-per-pixel */
|
||||
};
|
||||
|
||||
/* This is the standard, NuttX LCD driver object */
|
||||
|
||||
static struct sim_dev_s g_lcddev =
|
||||
{
|
||||
.dev =
|
||||
{
|
||||
/* LCD Configuration */
|
||||
|
||||
.getvideoinfo = sim_getvideoinfo,
|
||||
.getplaneinfo = sim_getplaneinfo,
|
||||
|
||||
/* LCD RGB Mapping -- Not supported */
|
||||
/* Cursor Controls -- Not supported */
|
||||
|
||||
/* LCD Specific Controls */
|
||||
|
||||
.getpower = sim_getpower,
|
||||
.setpower = sim_setpower,
|
||||
.getcontrast = sim_getcontrast,
|
||||
.setcontrast = sim_setcontrast,
|
||||
},
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_putrun
|
||||
*
|
||||
* Description:
|
||||
* This method can be used to write a partial raster line to the LCD:
|
||||
*
|
||||
* row - Starting row to write to (range: 0 <= row < yres)
|
||||
* col - Starting column to write to (range: 0 <= col <= xres-npixels)
|
||||
* buffer - The buffer containing the run to be written to the LCD
|
||||
* npixels - The number of pixels to write to the LCD
|
||||
* (range: 0 < npixels <= xres-col)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffer,
|
||||
size_t npixels)
|
||||
{
|
||||
lcddbg("row: %d col: %d npixels: %d\n", row, col, npixels);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_getrun
|
||||
*
|
||||
* Description:
|
||||
* This method can be used to read a partial raster line from the LCD:
|
||||
*
|
||||
* row - Starting row to read from (range: 0 <= row < yres)
|
||||
* col - Starting column to read read (range: 0 <= col <= xres-npixels)
|
||||
* buffer - The buffer in which to return the run read from the LCD
|
||||
* npixels - The number of pixels to read from the LCD
|
||||
* (range: 0 < npixels <= xres-col)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer,
|
||||
size_t npixels)
|
||||
{
|
||||
lcddbg("row: %d col: %d npixels: %d\n", row, col, npixels);
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_getvideoinfo
|
||||
*
|
||||
* Description:
|
||||
* Get information about the LCD video controller configuration.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_getvideoinfo(FAR struct lcd_dev_s *dev,
|
||||
FAR struct fb_videoinfo_s *vinfo)
|
||||
{
|
||||
DEBUGASSERT(dev && vinfo);
|
||||
gvdbg("fmt: %d xres: %d yres: %d nplanes: %d\n",
|
||||
g_videoinfo.fmt, g_videoinfo.xres, g_videoinfo.yres, g_videoinfo.nplanes);
|
||||
memcpy(vinfo, &g_videoinfo, sizeof(struct fb_videoinfo_s));
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_getplaneinfo
|
||||
*
|
||||
* Description:
|
||||
* Get information about the configuration of each LCD color plane.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno,
|
||||
FAR struct lcd_planeinfo_s *pinfo)
|
||||
{
|
||||
DEBUGASSERT(dev && pinfo && planeno == 0);
|
||||
gvdbg("planeno: %d bpp: %d\n", planeno, g_planeinfo.bpp);
|
||||
memcpy(pinfo, &g_planeinfo, sizeof(struct lcd_planeinfo_s));
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_getpower
|
||||
*
|
||||
* Description:
|
||||
* Get the LCD panel power status (0: full off - CONFIG_LCD_MAXPOWER:
|
||||
* full on). On backlit LCDs, this setting may correspond to the backlight setting.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_getpower(struct lcd_dev_s *dev)
|
||||
{
|
||||
gvdbg("power: %d\n", 0);
|
||||
return g_lcddev.power;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_setpower
|
||||
*
|
||||
* Description:
|
||||
* Enable/disable LCD panel power (0: full off - CONFIG_LCD_MAXPOWER:
|
||||
* full on). On backlit LCDs, this setting may correspond to the backlight
|
||||
* setting.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_setpower(struct lcd_dev_s *dev, int power)
|
||||
{
|
||||
gvdbg("power: %d\n", power);
|
||||
DEBUGASSERT(power <= CONFIG_LCD_MAXPOWER);
|
||||
|
||||
/* Set new power level */
|
||||
|
||||
g_lcddev.power = power;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_getcontrast
|
||||
*
|
||||
* Description:
|
||||
* Get the current contrast setting (0-CONFIG_LCD_MAXCONTRAST).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_getcontrast(struct lcd_dev_s *dev)
|
||||
{
|
||||
gvdbg("Not implemented\n");
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_setcontrast
|
||||
*
|
||||
* Description:
|
||||
* Set LCD panel contrast (0-CONFIG_LCD_MAXCONTRAST).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_setcontrast(struct lcd_dev_s *dev, unsigned int contrast)
|
||||
{
|
||||
gvdbg("contrast: %d\n", contrast);
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_lcdinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the LCD video hardware. The initial state of the LCD is
|
||||
* fully initialized, display memory cleared, and the LCD ready to use,
|
||||
* but with the power setting at 0 (full off).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_lcdinitialize(void)
|
||||
{
|
||||
gvdbg("Initializing\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_lcdgetdev
|
||||
*
|
||||
* Description:
|
||||
* Return a a reference to the LCD object for the specified LCD. This
|
||||
* allows support for multiple LCD devices.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct lcd_dev_s *up_lcdgetdev(int lcddev)
|
||||
{
|
||||
DEBUGASSERT(lcddev == 0);
|
||||
return &g_lcddev.dev;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_lcduninitialize
|
||||
*
|
||||
* Description:
|
||||
* Unitialize the LCD support
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_lcduninitialize(void)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_tapdev.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL (void*)0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
unsigned long up_getwalltime( void )
|
||||
{
|
||||
struct timeval tm;
|
||||
(void)gettimeofday(&tm, NULL);
|
||||
return tm.tv_sec*1000 + tm.tv_usec/1000;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/****************************************************************************
|
||||
* up_releasepending.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "os_internal.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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;
|
||||
|
||||
sdbg("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;
|
||||
sdbg("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)
|
||||
{
|
||||
sdbg("Delivering signals TCB=%p\n", rtcb);
|
||||
((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
|
||||
rtcb->xcp.sigdeliver = NULL;
|
||||
}
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_longjmp(rtcb->xcp.regs, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
* up_releasestack.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public 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)
|
||||
{
|
||||
free(dtcb->stack_alloc_ptr);
|
||||
}
|
||||
|
||||
dtcb->stack_alloc_ptr = NULL;
|
||||
dtcb->adj_stack_size = 0;
|
||||
dtcb->adj_stack_ptr = NULL;
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
/****************************************************************************
|
||||
* up_reprioritizertr.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "os_internal.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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, uint8_t priority)
|
||||
{
|
||||
/* Verify that the caller is sane */
|
||||
|
||||
if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
|
||||
tcb->task_state > LAST_READY_TO_RUN_STATE
|
||||
#if SCHED_PRIORITY_MIN > UINT8_MIN
|
||||
|| priority < SCHED_PRIORITY_MIN
|
||||
#endif
|
||||
#if SCHED_PRIORITY_MAX < UINT8_MAX
|
||||
|| priority > SCHED_PRIORITY_MAX
|
||||
#endif
|
||||
)
|
||||
{
|
||||
PANIC(OSERR_BADREPRIORITIZESTATE);
|
||||
}
|
||||
else
|
||||
{
|
||||
_TCB *rtcb = (_TCB*)g_readytorun.head;
|
||||
bool switch_needed;
|
||||
|
||||
sdbg("TCB=%p PRI=%d\n", tcb, priority);
|
||||
|
||||
/* Remove the tcb task from the ready-to-run list.
|
||||
* sched_removereadytorun will return true if we just
|
||||
* remove the head of the ready to run list.
|
||||
*/
|
||||
|
||||
switch_needed = sched_removereadytorun(tcb);
|
||||
|
||||
/* Setup up the new task priority */
|
||||
|
||||
tcb->sched_priority = (uint8_t)priority;
|
||||
|
||||
/* Return the task to the specified blocked task list.
|
||||
* sched_addreadytorun will return true if the task was
|
||||
* added to the new list. We will need to perform a context
|
||||
* switch only if the EXCLUSIVE or of the two calls is non-zero
|
||||
* (i.e., one and only one the calls changes the head of the
|
||||
* ready-to-run list).
|
||||
*/
|
||||
|
||||
switch_needed ^= sched_addreadytorun(tcb);
|
||||
|
||||
/* Now, perform the context switch if one is needed */
|
||||
|
||||
if (switch_needed)
|
||||
{
|
||||
/* If we are going to do a context switch, then now is the right
|
||||
* time to add any pending tasks back into the ready-to-run list.
|
||||
* task list now
|
||||
*/
|
||||
|
||||
if (g_pendingtasks.head)
|
||||
{
|
||||
sched_mergepending();
|
||||
}
|
||||
|
||||
/* 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;
|
||||
sdbg("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)
|
||||
{
|
||||
sdbg("Delivering signals TCB=%p\n", rtcb);
|
||||
((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
|
||||
rtcb->xcp.sigdeliver = NULL;
|
||||
}
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_longjmp(rtcb->xcp.regs, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_romgetc.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#ifdef CONFIG_ARCH_ROMGETC
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_romgetc
|
||||
*
|
||||
* Description:
|
||||
* In Harvard architectures, data accesses and instruction accesses occur
|
||||
* on different busses, perhaps concurrently. All data accesses are
|
||||
* performed on the data bus unless special machine instructions are
|
||||
* used to read data from the instruction address space. Also, in the
|
||||
* typical MCU, the available SRAM data memory is much smaller that the
|
||||
* non-volatile FLASH instruction memory. So if the application requires
|
||||
* many constant strings, the only practical solution may be to store
|
||||
* those constant strings in FLASH memory where they can only be accessed
|
||||
* using architecture-specific machine instructions.
|
||||
*
|
||||
* A similar case is where strings are retained in "external" memory such
|
||||
* as EEPROM or serial FLASH. This case is similar only in that again
|
||||
* special operations are required to obtain the string data; it cannot
|
||||
* be accessed directly from a string pointer.
|
||||
*
|
||||
* If CONFIG_ARCH_ROMGETC is defined, then the architecture logic must
|
||||
* export the function up_romgetc(). up_romgetc() will simply read one
|
||||
* byte of data from the instruction space.
|
||||
*
|
||||
* If CONFIG_ARCH_ROMGETC, certain C stdio functions are effected: (1)
|
||||
* All format strings in printf, fprintf, sprintf, etc. are assumed to
|
||||
* lie in FLASH (string arguments for %s are still assumed to reside in
|
||||
* SRAM). And (2), the string argument to puts and fputs is assumed to
|
||||
* reside in FLASH. Clearly, these assumptions may have to modified for
|
||||
* the particular needs of your environment. There is no "one-size-fits-all"
|
||||
* solution for this problem.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
char up_romgetc(FAR const char *ptr)
|
||||
{
|
||||
/* This is basically a No-Op if enabled in the simulation environment */
|
||||
|
||||
return *ptr;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
/****************************************************************************
|
||||
* up_schedulesigaction.c
|
||||
*
|
||||
* Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "os_internal.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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 for the simulated target */
|
||||
|
||||
if (tcb == (_TCB*)g_readytorun.head)
|
||||
{
|
||||
sigdeliver(tcb);
|
||||
}
|
||||
else
|
||||
{
|
||||
tcb->xcp.sigdeliver = sigdeliver;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/**************************************************************************
|
||||
* up_setjmp.S
|
||||
*
|
||||
* Copyright (C) 2007, 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Conditional Compilation Options
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Included Files
|
||||
**************************************************************************/
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/**************************************************************************
|
||||
* Private Definitions
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
# define SYMBOL(s) _##s
|
||||
#else
|
||||
# define SYMBOL(s) s
|
||||
#endif
|
||||
|
||||
/**************************************************************************
|
||||
* Private Types
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Private Function Prototypes
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Global Variables
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Private Variables
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Private Functions
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Public Functions
|
||||
**************************************************************************/
|
||||
|
||||
.text
|
||||
.globl SYMBOL(up_setjmp)
|
||||
#ifndef __CYGWIN__
|
||||
.type SYMBOL(up_setjmp), @function
|
||||
#endif
|
||||
SYMBOL(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
|
||||
#ifndef __CYGWIN__
|
||||
.size SYMBOL(up_setjmp), . - SYMBOL(up_setjmp)
|
||||
#endif
|
||||
.globl SYMBOL(up_longjmp)
|
||||
#ifndef __CYGWIN__
|
||||
.type SYMBOL(up_longjmp), @function
|
||||
#endif
|
||||
SYMBOL(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
|
||||
#ifndef __CYGWIN__
|
||||
.size SYMBOL(up_longjmp), . - SYMBOL(up_longjmp)
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
* up_stdio.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
size_t up_hostread(void *buffer, size_t len)
|
||||
{
|
||||
/* Just map to the host fread() */
|
||||
|
||||
return fread(buffer, 1, len, stdin);
|
||||
}
|
||||
|
||||
size_t up_hostwrite(const void *buffer, size_t len)
|
||||
{
|
||||
/* Just map to the host fwrite() */
|
||||
|
||||
return fwrite(buffer, 1, len, stdout);
|
||||
}
|
||||
|
||||
int up_putc(int ch)
|
||||
{
|
||||
/* Just map to the host fputc routine */
|
||||
|
||||
return fputc(ch, stdout);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
/****************************************************************************
|
||||
* up_tapdev.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Based on code from uIP which also has a BSD-like license:
|
||||
*
|
||||
* Copyright (c) 2001, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CYGWIN__
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_tun.h>
|
||||
#include <linux/net.h>
|
||||
|
||||
extern int lib_rawprintf(const char *format, ...);
|
||||
extern int uipdriver_setmacaddr(unsigned char *macaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define TAPDEV_DEBUG 1
|
||||
|
||||
#define DEVTAP "/dev/net/tun"
|
||||
|
||||
#ifndef CONFIG_EXAMPLE_UIP_DHCPC
|
||||
# define UIP_IPADDR0 192
|
||||
# define UIP_IPADDR1 168
|
||||
# define UIP_IPADDR2 0
|
||||
# define UIP_IPADDR3 128
|
||||
#else
|
||||
# define UIP_IPADDR0 0
|
||||
# define UIP_IPADDR1 0
|
||||
# define UIP_IPADDR2 0
|
||||
# define UIP_IPADDR3 0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Warning: This is very much Linux version specific! */
|
||||
|
||||
struct sel_arg_struct
|
||||
{
|
||||
unsigned long n;
|
||||
fd_set *inp;
|
||||
fd_set *outp;
|
||||
fd_set *exp;
|
||||
struct timeval *tvp;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef TAPDEV_DEBUG
|
||||
static int gdrop = 0;
|
||||
#endif
|
||||
static int gtapdevfd;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef TAPDEV_DEBUG
|
||||
static inline void dump_ethhdr(const char *msg, unsigned char *buf, int buflen)
|
||||
{
|
||||
lib_rawprintf("TAPDEV: %s %d bytes\n", msg, buflen);
|
||||
lib_rawprintf(" %02x:%02x:%02x:%02x:%02x:%02x %02x:%02x:%02x:%02x:%02x:%02x %02x%02x\n",
|
||||
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
|
||||
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
|
||||
#ifdef CONFIG_ENDIAN_BIG
|
||||
buf[13], buf[12]);
|
||||
#else
|
||||
buf[12], buf[13]);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
# define dump_ethhdr(m,b,l)
|
||||
#endif
|
||||
|
||||
static int up_setmacaddr(void)
|
||||
{
|
||||
int sockfd;
|
||||
int ret = -1;
|
||||
|
||||
/* Get a socket (only so that we get access to the INET subsystem) */
|
||||
|
||||
sockfd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (sockfd >= 0)
|
||||
{
|
||||
struct ifreq req;
|
||||
memset(&req, 0, sizeof(struct ifreq));
|
||||
|
||||
/* Put the driver name into the request */
|
||||
|
||||
strncpy(req.ifr_name, "tap0", IFNAMSIZ);
|
||||
|
||||
/* Perform the ioctl to get the MAC address */
|
||||
|
||||
ret = ioctl(sockfd, SIOCGIFHWADDR, (unsigned long)&req);
|
||||
if (!ret)
|
||||
{
|
||||
/* Set the MAC address */
|
||||
|
||||
ret = uipdriver_setmacaddr(&req.ifr_hwaddr.sa_data);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void tapdev_init(void)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
char buf[1024];
|
||||
int ret;
|
||||
|
||||
/* Open the tap device */
|
||||
|
||||
gtapdevfd = open(DEVTAP, O_RDWR, 0644);
|
||||
if (gtapdevfd < 0)
|
||||
{
|
||||
lib_rawprintf("TAPDEV: open failed: %d\n", -gtapdevfd );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Configure the tap device */
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
|
||||
ret = ioctl(gtapdevfd, TUNSETIFF, (unsigned long) &ifr);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_rawprintf("TAPDEV: ioctl failed: %d\n", -ret );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Assign an IPv4 address to the tap device */
|
||||
|
||||
snprintf(buf, sizeof(buf), "/sbin/ifconfig tap0 inet %d.%d.%d.%d\n",
|
||||
UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3);
|
||||
system(buf);
|
||||
|
||||
/* Set the MAC address */
|
||||
|
||||
up_setmacaddr();
|
||||
}
|
||||
|
||||
unsigned int tapdev_read(unsigned char *buf, unsigned int buflen)
|
||||
{
|
||||
fd_set fdset;
|
||||
struct timeval tv;
|
||||
int ret;
|
||||
|
||||
/* We can't do anything if we failed to open the tap device */
|
||||
|
||||
if (gtapdevfd < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Wait for data on the tap device (or a timeout) */
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1000;
|
||||
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(gtapdevfd, &fdset);
|
||||
|
||||
ret = select(gtapdevfd + 1, &fdset, NULL, NULL, &tv);
|
||||
if(ret == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = read(gtapdevfd, buf, buflen);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_rawprintf("TAPDEV: read failed: %d\n", -ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dump_ethhdr("read", buf, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void tapdev_send(unsigned char *buf, unsigned int buflen)
|
||||
{
|
||||
int ret;
|
||||
#ifdef TAPDEV_DEBUG
|
||||
lib_rawprintf("tapdev_send: sending %d bytes\n", buflen);
|
||||
|
||||
gdrop++;
|
||||
if(gdrop % 8 == 7)
|
||||
{
|
||||
lib_rawprintf("Dropped a packet!\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = write(gtapdevfd, buf, buflen);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_rawprintf("TAPDEV: write failed: %d", -ret);
|
||||
exit(1);
|
||||
}
|
||||
dump_ethhdr("write", buf, buflen);
|
||||
}
|
||||
|
||||
#endif /* !__CYGWIN__ */
|
||||
|
||||
|
||||
@@ -0,0 +1,811 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_touchscreen.c
|
||||
*
|
||||
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <semaphore.h>
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/nx/nx.h>
|
||||
|
||||
#include <nuttx/input/touchscreen.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifdef CONFIG_DISABLE_POLL
|
||||
# undef CONFIG_SIM_TCNWAITERS
|
||||
#else
|
||||
# ifndef CONFIG_SIM_TCNWAITERS
|
||||
# define CONFIG_SIM_TCNWAITERS 4
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Driver support ***********************************************************/
|
||||
/* This format is used to construct the /dev/input[n] device driver path. It
|
||||
* defined here so that it will be used consistently in all places.
|
||||
*/
|
||||
|
||||
#define DEV_FORMAT "/dev/input%d"
|
||||
#define DEV_NAMELEN 16
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This describes the state of one contact */
|
||||
|
||||
enum up_contact_3
|
||||
{
|
||||
CONTACT_NONE = 0, /* No contact */
|
||||
CONTACT_DOWN, /* First contact */
|
||||
CONTACT_MOVE, /* Same contact, possibly different position */
|
||||
CONTACT_UP, /* Contact lost */
|
||||
};
|
||||
|
||||
/* This structure describes the results of one touchscreen sample */
|
||||
|
||||
struct up_sample_s
|
||||
{
|
||||
uint8_t id; /* Sampled touch point ID */
|
||||
uint8_t contact; /* Contact state (see enum up_contact_e) */
|
||||
uint16_t x; /* Measured X position */
|
||||
uint16_t y; /* Measured Y position */
|
||||
};
|
||||
|
||||
/* This structure describes the state of one touchscreen driver instance */
|
||||
|
||||
struct up_dev_s
|
||||
{
|
||||
volatile uint8_t nwaiters; /* Number of threads waiting for touchscreen data */
|
||||
uint8_t id; /* Current touch point ID */
|
||||
uint8_t minor; /* Minor device number */
|
||||
volatile bool penchange; /* An unreported event is buffered */
|
||||
sem_t devsem; /* Manages exclusive access to this structure */
|
||||
sem_t waitsem; /* Used to wait for the availability of data */
|
||||
|
||||
struct up_sample_s sample; /* Last sampled touch point data */
|
||||
|
||||
/* The following is a list if poll structures of threads waiting for
|
||||
* driver events. The 'struct pollfd' reference for each open is also
|
||||
* retained in the f_priv field of the 'struct file'.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
struct pollfd *fds[CONFIG_SIM_TCNWAITERS];
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void up_notify(FAR struct up_dev_s *priv);
|
||||
static int up_sample(FAR struct up_dev_s *priv,
|
||||
FAR struct up_sample_s *sample);
|
||||
static int up_waitsample(FAR struct up_dev_s *priv,
|
||||
FAR struct up_sample_s *sample);
|
||||
|
||||
/* Character driver methods */
|
||||
|
||||
static int up_open(FAR struct file *filep);
|
||||
static int up_close(FAR struct file *filep);
|
||||
static ssize_t up_read(FAR struct file *filep, FAR char *buffer, size_t len);
|
||||
static int up_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
static int up_poll(FAR struct file *filep, struct pollfd *fds, bool setup);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This the the vtable that supports the character driver interface */
|
||||
|
||||
static const struct file_operations up_fops =
|
||||
{
|
||||
up_open, /* open */
|
||||
up_close, /* close */
|
||||
up_read, /* read */
|
||||
0, /* write */
|
||||
0, /* seek */
|
||||
up_ioctl /* ioctl */
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
, up_poll /* poll */
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Only one simulated touchscreen is supported o the the driver state
|
||||
* structure may as well be pre-allocated.
|
||||
*/
|
||||
|
||||
static struct up_dev_s g_simtouchscreen;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_notify
|
||||
****************************************************************************/
|
||||
|
||||
static void up_notify(FAR struct up_dev_s *priv)
|
||||
{
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
int i;
|
||||
#endif
|
||||
|
||||
/* If there are threads waiting for read data, then signal one of them
|
||||
* that the read data is available.
|
||||
*/
|
||||
|
||||
ivdbg("contact=%d nwaiters=%d\n", priv->sample.contact, priv->nwaiters);
|
||||
if (priv->nwaiters > 0)
|
||||
{
|
||||
/* After posting this semaphore, we need to exit because the touchscreen
|
||||
* is no longer avaialable.
|
||||
*/
|
||||
|
||||
sem_post(&priv->waitsem);
|
||||
}
|
||||
|
||||
/* If there are threads waiting on poll() for touchscreen data to become availabe,
|
||||
* then wake them up now. NOTE: we wake up all waiting threads because we
|
||||
* do not know that they are going to do. If they all try to read the data,
|
||||
* then some make end up blocking after all.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
for (i = 0; i < CONFIG_SIM_TCNWAITERS; i++)
|
||||
{
|
||||
struct pollfd *fds = priv->fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= POLLIN;
|
||||
ivdbg("Report events: %02x\n", fds->revents);
|
||||
sem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_sample
|
||||
****************************************************************************/
|
||||
|
||||
static int up_sample(FAR struct up_dev_s *priv,
|
||||
FAR struct up_sample_s *sample)
|
||||
{
|
||||
int ret = -EAGAIN;
|
||||
|
||||
/* Is there new touchscreen sample data available? */
|
||||
|
||||
ivdbg("penchange=%d contact=%d id=%d\n",
|
||||
priv->penchange, sample->contact, priv->id);
|
||||
|
||||
if (priv->penchange)
|
||||
{
|
||||
/* Yes.. the state has changed in some way. Return a copy of the
|
||||
* sampled data.
|
||||
*/
|
||||
|
||||
memcpy(sample, &priv->sample, sizeof(struct up_sample_s ));
|
||||
|
||||
/* Now manage state transitions */
|
||||
|
||||
if (sample->contact == CONTACT_UP)
|
||||
{
|
||||
/* Next.. no contract. Increment the ID so that next contact ID will be unique */
|
||||
|
||||
priv->sample.contact = CONTACT_NONE;
|
||||
priv->id++;
|
||||
}
|
||||
else if (sample->contact == CONTACT_DOWN)
|
||||
{
|
||||
/* First report -- next report will be a movement */
|
||||
|
||||
priv->sample.contact = CONTACT_MOVE;
|
||||
}
|
||||
|
||||
priv->penchange = false;
|
||||
ivdbg("penchange=%d contact=%d id=%d\n",
|
||||
priv->penchange, priv->sample.contact, priv->id);
|
||||
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_waitsample
|
||||
****************************************************************************/
|
||||
|
||||
static int up_waitsample(FAR struct up_dev_s *priv,
|
||||
FAR struct up_sample_s *sample)
|
||||
{
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
/* Interrupts me be disabled when this is called to (1) prevent posting
|
||||
* of semphores from interrupt handlers, and (2) to prevent sampled data
|
||||
* from changing until it has been reported.
|
||||
*
|
||||
* In addition, we will also disable pre-emption to prevent other threads
|
||||
* from getting control while we muck with the semaphores.
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
flags = irqsave();
|
||||
|
||||
/* Now release the semaphore that manages mutually exclusive access to
|
||||
* the device structure. This may cause other tasks to become ready to
|
||||
* run, but they cannot run yet because pre-emption is disabled.
|
||||
*/
|
||||
|
||||
sem_post(&priv->devsem);
|
||||
|
||||
/* Try to get the a sample... if we cannot, then wait on the semaphore
|
||||
* that is posted when new sample data is available.
|
||||
*/
|
||||
|
||||
while (up_sample(priv, sample) < 0)
|
||||
{
|
||||
/* Wait for a change in the touchscreen state */
|
||||
|
||||
ivdbg("Waiting...\n");
|
||||
priv->nwaiters++;
|
||||
ret = sem_wait(&priv->waitsem);
|
||||
priv->nwaiters--;
|
||||
ivdbg("Awakened...\n");
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
/* If we are awakened by a signal, then we need to return
|
||||
* the failure now.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(errno == EINTR);
|
||||
ret = -EINTR;
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
|
||||
/* Re-acquire the the semaphore that manages mutually exclusive access to
|
||||
* the device structure. We may have to wait here. But we have our sample.
|
||||
* Interrupts and pre-emption will be re-enabled while we wait.
|
||||
*/
|
||||
|
||||
ret = sem_wait(&priv->devsem);
|
||||
|
||||
errout:
|
||||
/* Then re-enable interrupts. We might get interrupt here and there
|
||||
* could be a new sample. But no new threads will run because we still
|
||||
* have pre-emption disabled.
|
||||
*/
|
||||
|
||||
irqrestore(flags);
|
||||
|
||||
/* Restore pre-emption. We might get suspended here but that is okay
|
||||
* because we already have our sample. Note: this means that if there
|
||||
* were two threads reading from the touchscreen for some reason, the data
|
||||
* might be read out of order.
|
||||
*/
|
||||
|
||||
sched_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_open
|
||||
****************************************************************************/
|
||||
|
||||
static int up_open(FAR struct file *filep)
|
||||
{
|
||||
ivdbg("Opening...\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_close
|
||||
****************************************************************************/
|
||||
|
||||
static int up_close(FAR struct file *filep)
|
||||
{
|
||||
ivdbg("Closing...\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_read
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t up_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct up_dev_s *priv;
|
||||
FAR struct touch_sample_s *report;
|
||||
struct up_sample_s sample;
|
||||
int ret;
|
||||
|
||||
ivdbg("len=%d\n", len);
|
||||
|
||||
DEBUGASSERT(filep);
|
||||
inode = filep->f_inode;
|
||||
|
||||
DEBUGASSERT(inode && inode->i_private);
|
||||
priv = (FAR struct up_dev_s *)inode->i_private;
|
||||
|
||||
/* Verify that the caller has provided a buffer large enough to receive
|
||||
* the touch data.
|
||||
*/
|
||||
|
||||
if (len < SIZEOF_TOUCH_SAMPLE_S(1))
|
||||
{
|
||||
/* We could provide logic to break up a touch report into segments and
|
||||
* handle smaller reads... but why?
|
||||
*/
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/* Get exclusive access to the driver data structure */
|
||||
|
||||
ret = sem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was canceled by an signal */
|
||||
|
||||
DEBUGASSERT(errno == EINTR);
|
||||
return -EINTR;
|
||||
}
|
||||
|
||||
/* Try to read sample data. */
|
||||
|
||||
ret = up_sample(priv, &sample);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Sample data is not available now. We would ave to wait to get
|
||||
* receive sample data. If the user has specified the O_NONBLOCK
|
||||
* option, then just return an error.
|
||||
*/
|
||||
|
||||
if (filep->f_oflags & O_NONBLOCK)
|
||||
{
|
||||
ret = -EAGAIN;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Wait for sample data */
|
||||
|
||||
ret = up_waitsample(priv, &sample);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* We might have been awakened by a signal */
|
||||
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
|
||||
/* In any event, we now have sampled touchscreen data that we can report
|
||||
* to the caller.
|
||||
*/
|
||||
|
||||
report = (FAR struct touch_sample_s *)buffer;
|
||||
memset(report, 0, SIZEOF_TOUCH_SAMPLE_S(1));
|
||||
report->npoints = 1;
|
||||
report->point[0].id = priv->id;
|
||||
report->point[0].x = sample.x;
|
||||
report->point[0].y = sample.y;
|
||||
report->point[0].h = 1;
|
||||
report->point[0].w = 1;
|
||||
report->point[0].pressure = 42;
|
||||
|
||||
/* Report the appropriate flags */
|
||||
|
||||
if (sample.contact == CONTACT_UP)
|
||||
{
|
||||
/* Pen is now up */
|
||||
|
||||
report->point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
|
||||
}
|
||||
else if (sample.contact == CONTACT_DOWN)
|
||||
{
|
||||
/* First contact */
|
||||
|
||||
report->point[0].flags = TOUCH_DOWN | TOUCH_ID_VALID | TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
|
||||
}
|
||||
else /* if (sample->contact == CONTACT_MOVE) */
|
||||
{
|
||||
/* Movement of the same contact */
|
||||
|
||||
report->point[0].flags = TOUCH_MOVE | TOUCH_ID_VALID | TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
|
||||
}
|
||||
|
||||
ret = SIZEOF_TOUCH_SAMPLE_S(1);
|
||||
|
||||
errout:
|
||||
ivdbg("Returning %d\n", ret);
|
||||
sem_post(&priv->devsem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name:up_ioctl
|
||||
****************************************************************************/
|
||||
|
||||
static int up_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct up_dev_s *priv;
|
||||
int ret;
|
||||
|
||||
ivdbg("cmd: %d arg: %ld\n", cmd, arg);
|
||||
DEBUGASSERT(filep);
|
||||
inode = filep->f_inode;
|
||||
|
||||
DEBUGASSERT(inode && inode->i_private);
|
||||
priv = (FAR struct up_dev_s *)inode->i_private;
|
||||
|
||||
/* Get exclusive access to the driver data structure */
|
||||
|
||||
ret = sem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was canceled by an signal */
|
||||
|
||||
DEBUGASSERT(errno == EINTR);
|
||||
return -EINTR;
|
||||
}
|
||||
|
||||
/* Process the IOCTL by command */
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
default:
|
||||
ret = -ENOTTY;
|
||||
break;
|
||||
}
|
||||
|
||||
sem_post(&priv->devsem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_poll
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
static int up_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
bool setup)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct up_dev_s *priv;
|
||||
int ret = OK;
|
||||
int i;
|
||||
|
||||
ivdbg("setup: %d\n", (int)setup);
|
||||
DEBUGASSERT(filep && fds);
|
||||
inode = filep->f_inode;
|
||||
|
||||
DEBUGASSERT(inode && inode->i_private);
|
||||
priv = (FAR struct up_dev_s *)inode->i_private;
|
||||
|
||||
/* Are we setting up the poll? Or tearing it down? */
|
||||
|
||||
ret = sem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was canceled by an signal */
|
||||
|
||||
DEBUGASSERT(errno == EINTR);
|
||||
return -EINTR;
|
||||
}
|
||||
|
||||
if (setup)
|
||||
{
|
||||
/* Ignore waits that do not include POLLIN */
|
||||
|
||||
if ((fds->revents & POLLIN) == 0)
|
||||
{
|
||||
ret = -EDEADLK;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* This is a request to set up the poll. Find an available
|
||||
* slot for the poll structure reference
|
||||
*/
|
||||
|
||||
for (i = 0; i < CONFIG_SIM_TCNWAITERS; i++)
|
||||
{
|
||||
/* Find an available slot */
|
||||
|
||||
if (!priv->fds[i])
|
||||
{
|
||||
/* Bind the poll structure and this slot */
|
||||
|
||||
priv->fds[i] = fds;
|
||||
fds->priv = &priv->fds[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= CONFIG_SIM_TCNWAITERS)
|
||||
{
|
||||
fds->priv = NULL;
|
||||
ret = -EBUSY;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Should we immediately notify on any of the requested events? */
|
||||
|
||||
if (priv->penchange)
|
||||
{
|
||||
up_notify(priv);
|
||||
}
|
||||
}
|
||||
else if (fds->priv)
|
||||
{
|
||||
/* This is a request to tear down the poll. */
|
||||
|
||||
struct pollfd **slot = (struct pollfd **)fds->priv;
|
||||
DEBUGASSERT(slot != NULL);
|
||||
|
||||
/* Remove all memory of the poll setup */
|
||||
|
||||
*slot = NULL;
|
||||
fds->priv = NULL;
|
||||
}
|
||||
|
||||
errout:
|
||||
sem_post(&priv->devsem);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arch_tcinitialize
|
||||
*
|
||||
* Description:
|
||||
* Configure the simulated touchscreen. This will register the driver as
|
||||
* /dev/inputN where N is the minor device number
|
||||
*
|
||||
* Input Parameters:
|
||||
* minor - The input device minor number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int arch_tcinitialize(int minor)
|
||||
{
|
||||
FAR struct up_dev_s *priv = ( FAR struct up_dev_s *)&g_simtouchscreen;
|
||||
char devname[DEV_NAMELEN];
|
||||
int ret;
|
||||
|
||||
ivdbg("minor: %d\n", minor);
|
||||
|
||||
/* Debug-only sanity checks */
|
||||
|
||||
DEBUGASSERT(minor >= 0 && minor < 100);
|
||||
|
||||
/* Initialize the touchscreen device driver instance */
|
||||
|
||||
memset(priv, 0, sizeof(struct up_dev_s));
|
||||
sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
|
||||
sem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
|
||||
|
||||
priv->minor = minor;
|
||||
|
||||
/* Register the device as an input device */
|
||||
|
||||
(void)snprintf(devname, DEV_NAMELEN, DEV_FORMAT, minor);
|
||||
ivdbg("Registering %s\n", devname);
|
||||
|
||||
ret = register_driver(devname, &up_fops, 0666, priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
idbg("register_driver() failed: %d\n", ret);
|
||||
goto errout_with_priv;
|
||||
}
|
||||
|
||||
/* Enable X11 event processing from the IDLE loop */
|
||||
|
||||
g_eventloop = 1;
|
||||
|
||||
/* And return success */
|
||||
|
||||
return OK;
|
||||
|
||||
errout_with_priv:
|
||||
sem_destroy(&priv->waitsem);
|
||||
sem_destroy(&priv->devsem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arch_tcuninitialize
|
||||
*
|
||||
* Description:
|
||||
* Uninitialized the simulated touchscreen
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void arch_tcuninitialize(void)
|
||||
{
|
||||
FAR struct up_dev_s *priv = ( FAR struct up_dev_s *)&g_simtouchscreen;
|
||||
char devname[DEV_NAMELEN];
|
||||
int ret;
|
||||
|
||||
/* Get exclusive access */
|
||||
|
||||
do
|
||||
{
|
||||
ret = sem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was canceled by an signal */
|
||||
|
||||
DEBUGASSERT(errno == EINTR);
|
||||
}
|
||||
}
|
||||
while (ret != OK);
|
||||
|
||||
/* Stop the event loop (Hmm.. the caller must be sure that there are no
|
||||
* open references to the touchscreen driver. This might better be
|
||||
* done in close() using a reference count).
|
||||
*/
|
||||
|
||||
g_eventloop = 0;
|
||||
|
||||
/* Un-register the device*/
|
||||
|
||||
(void)snprintf(devname, DEV_NAMELEN, DEV_FORMAT, priv->minor);
|
||||
ivdbg("Un-registering %s\n", devname);
|
||||
|
||||
ret = unregister_driver(devname);
|
||||
if (ret < 0)
|
||||
{
|
||||
idbg("uregister_driver() failed: %d\n", ret);
|
||||
}
|
||||
|
||||
/* Clean up any resources. Ouch! While we are holding the semaphore? */
|
||||
|
||||
sem_destroy(&priv->waitsem);
|
||||
sem_destroy(&priv->devsem);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_buttonevent
|
||||
****************************************************************************/
|
||||
|
||||
int up_buttonevent(int x, int y, int buttons)
|
||||
{
|
||||
FAR struct up_dev_s *priv = (FAR struct up_dev_s *)&g_simtouchscreen;
|
||||
bool pendown; /* true: pen is down */
|
||||
|
||||
ivdbg("x=%d y=%d buttons=%02x\n", x, y, buttons);
|
||||
ivdbg("contact=%d nwaiters=%d\n", priv->sample.contact, priv->nwaiters);
|
||||
|
||||
/* Any button press will count as pendown. */
|
||||
|
||||
pendown = (buttons != 0);
|
||||
|
||||
/* Handle the change from pen down to pen up */
|
||||
|
||||
if (!pendown)
|
||||
{
|
||||
/* Ignore the pend up if the pen was already up (CONTACT_NONE == pen up and
|
||||
* already reported. CONTACT_UP == pen up, but not reported)
|
||||
*/
|
||||
|
||||
if (priv->sample.contact == CONTACT_NONE)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Not yet reported */
|
||||
|
||||
priv->sample.contact = CONTACT_UP;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Save the measurements */
|
||||
|
||||
priv->sample.x = x;
|
||||
priv->sample.y = y;
|
||||
|
||||
/* Note the availability of new measurements */
|
||||
/* If this is the first (acknowledged) pen down report, then report
|
||||
* this as the first contact. If contact == CONTACT_DOWN, it will be
|
||||
* set to set to CONTACT_MOVE after the contact is first sampled.
|
||||
*/
|
||||
|
||||
if (priv->sample.contact != CONTACT_MOVE)
|
||||
{
|
||||
/* First contact */
|
||||
|
||||
priv->sample.contact = CONTACT_DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/* Indicate the availability of new sample data for this ID */
|
||||
|
||||
priv->sample.id = priv->id;
|
||||
priv->penchange = true;
|
||||
|
||||
/* Notify any waiters that new touchscreen data is available */
|
||||
|
||||
up_notify(priv);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
/****************************************************************************
|
||||
* up_uipdriver.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Based on code from uIP which also has a BSD-like license:
|
||||
*
|
||||
* Copyright (c) 2001, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <sched.h>
|
||||
#include <nuttx/net/net.h>
|
||||
|
||||
#include <net/ethernet.h>
|
||||
#include <nuttx/net/uip/uip.h>
|
||||
#include <nuttx/net/uip/uip-arch.h>
|
||||
#include <nuttx/net/uip/uip-arp.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BUF ((struct ether_header*)g_sim_dev.d_buf)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct timer
|
||||
{
|
||||
uint32_t interval;
|
||||
uint32_t start;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct timer g_periodic_timer;
|
||||
static struct uip_driver_s g_sim_dev;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void timer_set(struct timer *t, unsigned int interval)
|
||||
{
|
||||
t->interval = interval;
|
||||
t->start = up_getwalltime();
|
||||
}
|
||||
|
||||
static bool timer_expired( struct timer *t )
|
||||
{
|
||||
return (up_getwalltime() - t->start) >= t->interval;
|
||||
}
|
||||
|
||||
void timer_reset(struct timer *t)
|
||||
{
|
||||
t->start += t->interval;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_PROMISCUOUS
|
||||
# define up_comparemac(a,b) (0)
|
||||
#else
|
||||
static inline int up_comparemac(uint8_t *paddr1, struct ether_addr *paddr2)
|
||||
{
|
||||
return memcmp(paddr1, paddr2->ether_addr_octet, ETHER_ADDR_LEN);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int sim_uiptxpoll(struct uip_driver_s *dev)
|
||||
{
|
||||
/* If the polling resulted in data that should be sent out on the network,
|
||||
* the field d_len is set to a value > 0.
|
||||
*/
|
||||
|
||||
if (g_sim_dev.d_len > 0)
|
||||
{
|
||||
uip_arp_out(&g_sim_dev);
|
||||
netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len);
|
||||
}
|
||||
|
||||
/* If zero is returned, the polling will continue until all connections have
|
||||
* been examined.
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void uipdriver_loop(void)
|
||||
{
|
||||
/* netdev_read will return 0 on a timeout event and >0 on a data received event */
|
||||
|
||||
g_sim_dev.d_len = netdev_read((unsigned char*)g_sim_dev.d_buf, CONFIG_NET_BUFSIZE);
|
||||
|
||||
/* Disable preemption through to the following so that it behaves a little more
|
||||
* like an interrupt (otherwise, the following logic gets pre-empted an behaves
|
||||
* oddly.
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
if (g_sim_dev.d_len > 0)
|
||||
{
|
||||
/* Data received event. Check for valid Ethernet header with destination == our
|
||||
* MAC address
|
||||
*/
|
||||
|
||||
if (g_sim_dev.d_len > UIP_LLH_LEN && up_comparemac(BUF->ether_dhost, &g_sim_dev.d_mac) == 0)
|
||||
{
|
||||
/* We only accept IP packets of the configured type and ARP packets */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
if (BUF->ether_type == htons(UIP_ETHTYPE_IP6))
|
||||
#else
|
||||
if (BUF->ether_type == htons(UIP_ETHTYPE_IP))
|
||||
#endif
|
||||
{
|
||||
uip_arp_ipin(&g_sim_dev);
|
||||
uip_input(&g_sim_dev);
|
||||
|
||||
/* If the above function invocation resulted in data that
|
||||
* should be sent out on the network, the global variable
|
||||
* d_len is set to a value > 0.
|
||||
*/
|
||||
|
||||
if (g_sim_dev.d_len > 0)
|
||||
{
|
||||
uip_arp_out(&g_sim_dev);
|
||||
netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len);
|
||||
}
|
||||
}
|
||||
else if (BUF->ether_type == htons(UIP_ETHTYPE_ARP))
|
||||
{
|
||||
uip_arp_arpin(&g_sim_dev);
|
||||
|
||||
/* If the above function invocation resulted in data that
|
||||
* should be sent out on the network, the global variable
|
||||
* d_len is set to a value > 0.
|
||||
*/
|
||||
|
||||
if (g_sim_dev.d_len > 0)
|
||||
{
|
||||
netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Otherwise, it must be a timeout event */
|
||||
|
||||
else if (timer_expired(&g_periodic_timer))
|
||||
{
|
||||
timer_reset(&g_periodic_timer);
|
||||
uip_timer(&g_sim_dev, sim_uiptxpoll, 1);
|
||||
}
|
||||
sched_unlock();
|
||||
}
|
||||
|
||||
int uipdriver_init(void)
|
||||
{
|
||||
/* Internal initalization */
|
||||
|
||||
timer_set(&g_periodic_timer, 500);
|
||||
netdev_init();
|
||||
|
||||
/* Register the device with the OS so that socket IOCTLs can be performed */
|
||||
|
||||
(void)netdev_register(&g_sim_dev);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int uipdriver_setmacaddr(unsigned char *macaddr)
|
||||
{
|
||||
(void)memcpy(g_sim_dev.d_mac.ether_addr_octet, macaddr, IFHWADDRLEN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET */
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
/****************************************************************************
|
||||
* up_unblocktask.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "clock_internal.h"
|
||||
#include "os_internal.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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;
|
||||
|
||||
sdbg("Unblocking TCB=%p\n", tcb);
|
||||
|
||||
/* Remove the task from the blocked task list */
|
||||
|
||||
sched_removeblocked(tcb);
|
||||
|
||||
/* Reset its timeslice. This is only meaningful for round
|
||||
* robin tasks but it doesn't here to do it for everything
|
||||
*/
|
||||
|
||||
#if CONFIG_RR_INTERVAL > 0
|
||||
tcb->timeslice = CONFIG_RR_INTERVAL / MSEC_PER_TICK;
|
||||
#endif
|
||||
|
||||
/* Add the task in the correct location in the prioritized
|
||||
* g_readytorun task list
|
||||
*/
|
||||
|
||||
if (sched_addreadytorun(tcb))
|
||||
{
|
||||
/* The currently active task has changed! 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;
|
||||
sdbg("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)
|
||||
{
|
||||
sdbg("Delivering signals TCB=%p\n", rtcb);
|
||||
((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
|
||||
rtcb->xcp.sigdeliver = NULL;
|
||||
}
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_longjmp(rtcb->xcp.regs, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_usestack.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <debug.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include "os_internal.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public 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 stack_alloc_ptr for HW. The
|
||||
* initial value of the stack pointer.
|
||||
*
|
||||
* Inputs:
|
||||
* tcb: The TCB of new task
|
||||
* stack_size: The allocated stack size.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_use_stack(_TCB *tcb, void *stack, size_t stack_size)
|
||||
{
|
||||
/* Move up to next even word boundary if necessary */
|
||||
|
||||
size_t adj_stack_size = stack_size & ~3;
|
||||
size_t adj_stack_words = adj_stack_size >> 2;
|
||||
|
||||
/* This is the address of the last word in the allocation */
|
||||
|
||||
size_t *adj_stack_ptr = &((size_t*)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;
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
/****************************************************************************
|
||||
* up_wcap.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Based on code from uIP which also has a BSD-like license:
|
||||
*
|
||||
* Copyright (c) 2007, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
|
||||
extern int uipdriver_setmacaddr(unsigned char *macaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
|
||||
#ifndef CONFIG_EXAMPLE_UIP_DHCPC
|
||||
# define UIP_IPADDR (10 << 24 | 0 << 16 | 0 << 8 | 1)
|
||||
#else
|
||||
# define UIP_IPADDR (0)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
__attribute__ ((dllimport)) extern char **__argv[];
|
||||
|
||||
struct pcap;
|
||||
|
||||
struct pcap_if
|
||||
{
|
||||
struct pcap_if *next;
|
||||
char *name;
|
||||
char *description;
|
||||
struct pcap_addr
|
||||
{
|
||||
struct pcap_addr *next;
|
||||
struct sockaddr *addr;
|
||||
struct sockaddr *netmask;
|
||||
struct sockaddr *broadaddr;
|
||||
struct sockaddr *dstaddr;
|
||||
} *addresses;
|
||||
DWORD flags;
|
||||
};
|
||||
|
||||
struct pcap_pkthdr
|
||||
{
|
||||
struct timeval ts;
|
||||
DWORD caplen;
|
||||
DWORD len;
|
||||
};
|
||||
|
||||
/* DLL function types (for casting) */
|
||||
|
||||
typedef int (*pcap_findalldevs_t)(struct pcap_if **, char *);
|
||||
typedef struct pcap *(*pcap_open_live_t)(char *, int, int, int, char *);
|
||||
typedef int (*pcap_next_ex_t)(struct pcap *, struct pcap_pkthdr **,
|
||||
unsigned char **);
|
||||
typedef int (*pcap_sendpacket_t)(struct pcap *, unsigned char *, int);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
HMODULE wpcap;
|
||||
static struct pcap *pcap;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static pcap_findalldevs_t pcap_findalldevs;
|
||||
static pcap_open_live_t pcap_open_live;
|
||||
static pcap_next_ex_t pcap_next_ex;
|
||||
static pcap_sendpacket_t pcap_sendpacket;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void error_exit(char *message)
|
||||
{
|
||||
printf("error_exit: %s", message);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void init_pcap(struct in_addr addr)
|
||||
{
|
||||
struct pcap_if *interfaces;
|
||||
char error[256];
|
||||
|
||||
if (pcap_findalldevs(&interfaces, error) == -1)
|
||||
{
|
||||
error_exit(error);
|
||||
}
|
||||
|
||||
while (interfaces != NULL)
|
||||
{
|
||||
printf("init_pcap: found interface: %s\n", interfaces->description);
|
||||
|
||||
if (interfaces->addresses != NULL &&
|
||||
interfaces->addresses->addr != NULL &&
|
||||
interfaces->addresses->addr->sa_family == AF_INET)
|
||||
{
|
||||
|
||||
struct in_addr interface_addr;
|
||||
interface_addr =
|
||||
((struct sockaddr_in *)interfaces->addresses->addr)->sin_addr;
|
||||
printf("init_pcap: with address: %s\n", inet_ntoa(interface_addr));
|
||||
|
||||
if (interface_addr.s_addr == addr.s_addr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
interfaces = interfaces->next;
|
||||
}
|
||||
|
||||
if (interfaces == NULL)
|
||||
{
|
||||
error_exit("No interface found with IP address\n");
|
||||
}
|
||||
|
||||
pcap = pcap_open_live(interfaces->name, NETDEV_BUFSIZE, 0, -1, error);
|
||||
if (pcap == NULL)
|
||||
{
|
||||
error_exit(error);
|
||||
}
|
||||
}
|
||||
|
||||
static void set_ethaddr(struct in_addr addr)
|
||||
{
|
||||
PIP_ADAPTER_ADDRESSES adapters;
|
||||
ULONG size = 0;
|
||||
|
||||
if (GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST |
|
||||
GAA_FLAG_SKIP_MULTICAST |
|
||||
GAA_FLAG_SKIP_DNS_SERVER,
|
||||
NULL, NULL, &size) != ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
error_exit("error on access to adapter list size\n");
|
||||
}
|
||||
adapters = alloca(size);
|
||||
if (GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST |
|
||||
GAA_FLAG_SKIP_MULTICAST |
|
||||
GAA_FLAG_SKIP_DNS_SERVER,
|
||||
NULL, adapters, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
error_exit("error on access to adapter list\n");
|
||||
}
|
||||
|
||||
while (adapters != NULL)
|
||||
{
|
||||
|
||||
char buffer[256];
|
||||
WideCharToMultiByte(CP_ACP, 0, adapters->Description, -1,
|
||||
buffer, sizeof(buffer), NULL, NULL);
|
||||
printf("set_ethaddr: found adapter: %s\n", buffer);
|
||||
|
||||
if (adapters->FirstUnicastAddress != NULL &&
|
||||
adapters->FirstUnicastAddress->Address.lpSockaddr != NULL &&
|
||||
adapters->FirstUnicastAddress->Address.lpSockaddr->sa_family ==
|
||||
AF_INET)
|
||||
{
|
||||
|
||||
struct in_addr adapter_addr;
|
||||
adapter_addr =
|
||||
((struct sockaddr_in *)adapters->FirstUnicastAddress->Address.
|
||||
lpSockaddr)->sin_addr;
|
||||
printf("set_ethaddr: with address: %s\n", inet_ntoa(adapter_addr));
|
||||
|
||||
if (adapter_addr.s_addr == addr.s_addr)
|
||||
{
|
||||
if (adapters->PhysicalAddressLength != 6)
|
||||
{
|
||||
error_exit
|
||||
("ip addr specified does not belong to an ethernet card\n");
|
||||
}
|
||||
printf
|
||||
("set_ethaddr: ethernetaddr: %02X-%02X-%02X-%02X-%02X-%02X\n",
|
||||
adapters->PhysicalAddress[0], adapters->PhysicalAddress[1],
|
||||
adapters->PhysicalAddress[2], adapters->PhysicalAddress[3],
|
||||
adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]);
|
||||
|
||||
(void)uipdriver_setmacaddr(adapters->PhysicalAddress);
|
||||
break;
|
||||
}
|
||||
}
|
||||
adapters = adapters->Next;
|
||||
}
|
||||
|
||||
if (adapters == NULL)
|
||||
{
|
||||
error_exit("No adaptor found with IP address\n");
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void wpcap_init(void)
|
||||
{
|
||||
struct in_addr addr;
|
||||
FARPROC dlladdr;
|
||||
|
||||
addr.s_addr = htonl(UIP_IPADDR);
|
||||
printf("wpcap_init: IP address: %s\n", inet_ntoa(addr));
|
||||
|
||||
wpcap = LoadLibrary("wpcap.dll");
|
||||
dlladdr = GetProcAddress(wpcap, "pcap_findalldevs");
|
||||
pcap_findalldevs = (pcap_findalldevs_t)dlladdr;
|
||||
|
||||
dlladdr = GetProcAddress(wpcap, "pcap_open_live");
|
||||
pcap_open_live = (pcap_open_live_t)dlladdr;
|
||||
|
||||
dlladdr = GetProcAddress(wpcap, "pcap_next_ex");
|
||||
pcap_next_ex = (pcap_next_ex_t)dlladdr;
|
||||
|
||||
dlladdr = GetProcAddress(wpcap, "pcap_sendpacket");
|
||||
pcap_sendpacket = (pcap_sendpacket_t)dlladdr;
|
||||
|
||||
if (pcap_findalldevs == NULL || pcap_open_live == NULL ||
|
||||
pcap_next_ex == NULL || pcap_sendpacket == NULL)
|
||||
{
|
||||
error_exit("error on access to winpcap library\n");
|
||||
}
|
||||
|
||||
init_pcap(addr);
|
||||
set_ethaddr(addr);
|
||||
}
|
||||
|
||||
unsigned int wpcap_read(unsigned char *buf, unsigned int buflen)
|
||||
{
|
||||
struct pcap_pkthdr *packet_header;
|
||||
unsigned char *packet;
|
||||
|
||||
switch (pcap_next_ex(pcap, &packet_header, &packet))
|
||||
{
|
||||
case -1:
|
||||
error_exit("error on read\n");
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (packet_header->caplen > buflen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(buf, packet, packet_header->caplen);
|
||||
return packet_header->caplen;
|
||||
}
|
||||
|
||||
void wpcap_send(unsigned char *buf, unsigned int buflen)
|
||||
{
|
||||
if (pcap_sendpacket(pcap, buf, buflen) == -1)
|
||||
{
|
||||
error_exit("error on send\n");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __CYGWIN__ */
|
||||
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_x11eventloop.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
***************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
extern int up_buttonevent(int x, int y, int buttons);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/* Defined in up_x11framebuffer.c */
|
||||
|
||||
extern Display *g_display;
|
||||
|
||||
volatile int g_eventloop;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
***************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_buttonmap
|
||||
***************************************************************************/
|
||||
|
||||
static int up_buttonmap(int state)
|
||||
{
|
||||
/* Remove any X11 dependencies. Just maps Button1Mask to bit 0. */
|
||||
|
||||
return ((state & Button1Mask) != 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
***************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11events
|
||||
*
|
||||
* Description:
|
||||
* Called periodically from the IDLE loop to check for queued X11 events.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
void up_x11events(void)
|
||||
{
|
||||
XEvent event;
|
||||
|
||||
/* Check if there are any pending, queue X11 events. */
|
||||
|
||||
if (XPending(g_display) > 0)
|
||||
{
|
||||
/* Yes, get the event (this should not block since we know there are
|
||||
* pending events)
|
||||
*/
|
||||
|
||||
XNextEvent(g_display, &event);
|
||||
|
||||
/* Then process the event */
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case MotionNotify : /* Enabled by ButtonMotionMask */
|
||||
{
|
||||
up_buttonevent(event.xmotion.x, event.xmotion.y,
|
||||
up_buttonmap(event.xmotion.state));
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonPress : /* Enabled by ButtonPressMask */
|
||||
case ButtonRelease : /* Enabled by ButtonReleaseMask */
|
||||
{
|
||||
up_buttonevent(event.xbutton.x, event.xbutton.y,
|
||||
up_buttonmap(event.xbutton.state));
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,477 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_x11framebuffer.c
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#define CONFIG_SIM_X11NOSHM 1
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <sys/ipc.h>
|
||||
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
# include <sys/shm.h>
|
||||
# include <X11/extensions/XShm.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
***************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/* Also used in up_x11eventloop */
|
||||
|
||||
Display *g_display;
|
||||
int g_x11initialized;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
static int g_screen;
|
||||
static Window g_window;
|
||||
static GC g_gc;
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
static XShmSegmentInfo g_xshminfo;
|
||||
static int g_xerror;
|
||||
#endif
|
||||
static XImage *g_image;
|
||||
static unsigned char *g_framebuffer;
|
||||
static unsigned short g_fbpixelwidth;
|
||||
static unsigned short g_fbpixelheight;
|
||||
static int g_shmcheckpoint = 0;
|
||||
static int b_useshm;
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11createframe
|
||||
***************************************************************************/
|
||||
|
||||
static inline int up_x11createframe(void)
|
||||
{
|
||||
XGCValues gcval;
|
||||
char *argv[2] = { "nuttx", NULL };
|
||||
char *winName = "NuttX";
|
||||
char *iconName = "NX";
|
||||
XTextProperty winprop;
|
||||
XTextProperty iconprop;
|
||||
XSizeHints hints;
|
||||
|
||||
g_display = XOpenDisplay(NULL);
|
||||
if (g_display == NULL)
|
||||
{
|
||||
printf("Unable to open display.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_screen = DefaultScreen(g_display);
|
||||
g_window = XCreateSimpleWindow(g_display, DefaultRootWindow(g_display),
|
||||
0, 0, g_fbpixelwidth, g_fbpixelheight, 2,
|
||||
BlackPixel(g_display, g_screen),
|
||||
BlackPixel(g_display, g_screen));
|
||||
|
||||
XStringListToTextProperty(&winName, 1, &winprop);
|
||||
XStringListToTextProperty(&iconName, 1, &iconprop);
|
||||
|
||||
hints.flags = PSize | PMinSize | PMaxSize;
|
||||
hints.width = hints.min_width = hints.max_width = g_fbpixelwidth;
|
||||
hints.height= hints.min_height = hints.max_height = g_fbpixelheight;
|
||||
|
||||
XSetWMProperties(g_display, g_window, &winprop, &iconprop, argv, 1,
|
||||
&hints, NULL, NULL);
|
||||
|
||||
XMapWindow(g_display, g_window);
|
||||
|
||||
/* Select window input events */
|
||||
|
||||
XSelectInput(g_display, g_window,
|
||||
ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|KeyPressMask);
|
||||
|
||||
/* Release queued events on the display */
|
||||
|
||||
#ifdef CONFIG_SIM_TOUCHSCREEN
|
||||
(void)XAllowEvents(g_display, AsyncBoth, CurrentTime);
|
||||
|
||||
/* Grab mouse button 1, enabling mouse-related events */
|
||||
|
||||
(void)XGrabButton(g_display, Button1, AnyModifier, g_window, 1,
|
||||
ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
|
||||
GrabModeAsync, GrabModeAsync, None, None);
|
||||
#endif
|
||||
|
||||
gcval.graphics_exposures = 0;
|
||||
g_gc = XCreateGC(g_display, g_window, GCGraphicsExposures, &gcval);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11errorhandler
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
static int up_x11errorhandler(Display *display, XErrorEvent *event)
|
||||
{
|
||||
g_xerror = 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11traperrors
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
static void up_x11traperrors(void)
|
||||
{
|
||||
g_xerror = 0;
|
||||
XSetErrorHandler(up_x11errorhandler);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11untraperrors
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
static int up_x11untraperrors(void)
|
||||
{
|
||||
XSync(g_display,0);
|
||||
XSetErrorHandler(NULL);
|
||||
return g_xerror;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11uninitX
|
||||
***************************************************************************/
|
||||
|
||||
static void up_x11uninitX(void)
|
||||
{
|
||||
fprintf(stderr, "Uninitalizing X\n");
|
||||
if (g_x11initialized)
|
||||
{
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
if (g_shmcheckpoint > 4)
|
||||
{
|
||||
XShmDetach(g_display, &g_xshminfo);
|
||||
}
|
||||
|
||||
if (g_shmcheckpoint > 3)
|
||||
{
|
||||
shmdt(g_xshminfo.shmaddr);
|
||||
}
|
||||
|
||||
if (g_shmcheckpoint > 2)
|
||||
{
|
||||
shmctl(g_xshminfo.shmid, IPC_RMID, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_shmcheckpoint > 1)
|
||||
{
|
||||
XDestroyImage(g_image);
|
||||
}
|
||||
|
||||
/* Un-grab the mouse buttons */
|
||||
|
||||
#ifdef CONFIG_SIM_TOUCHSCREEN
|
||||
XUngrabButton(g_display, Button1, AnyModifier, g_window);
|
||||
#endif
|
||||
g_x11initialized = 0;
|
||||
}
|
||||
|
||||
XCloseDisplay(g_display);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11uninitialize
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
static void up_x11uninitialize(void)
|
||||
{
|
||||
fprintf(stderr, "Uninitalizing\n");
|
||||
if (g_shmcheckpoint > 1)
|
||||
{
|
||||
if (!b_useshm && g_framebuffer)
|
||||
{
|
||||
free(g_framebuffer);
|
||||
g_framebuffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_shmcheckpoint > 0)
|
||||
{
|
||||
g_shmcheckpoint = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11mapsharedmem
|
||||
***************************************************************************/
|
||||
|
||||
static inline int up_x11mapsharedmem(int depth, unsigned int fblen)
|
||||
{
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
Status result;
|
||||
#endif
|
||||
|
||||
atexit(up_x11uninitX);
|
||||
g_shmcheckpoint = 1;
|
||||
b_useshm = 0;
|
||||
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
if (XShmQueryExtension(g_display))
|
||||
{
|
||||
b_useshm = 1;
|
||||
printf("Using shared memory.\n");
|
||||
|
||||
up_x11traperrors();
|
||||
g_image = XShmCreateImage(g_display, DefaultVisual(g_display, g_screen),
|
||||
depth, ZPixmap, NULL, &g_xshminfo,
|
||||
g_fbpixelwidth, g_fbpixelheight);
|
||||
if (up_x11untraperrors())
|
||||
{
|
||||
up_x11uninitialize();
|
||||
goto shmerror;
|
||||
}
|
||||
if (!g_image)
|
||||
{
|
||||
fprintf(stderr,"Unable to create g_image.");
|
||||
return -1;
|
||||
}
|
||||
g_shmcheckpoint++;
|
||||
|
||||
g_xshminfo.shmid = shmget(IPC_PRIVATE,
|
||||
g_image->bytes_per_line * g_image->height,
|
||||
IPC_CREAT | 0777);
|
||||
if (g_xshminfo.shmid < 0)
|
||||
{
|
||||
up_x11uninitialize();
|
||||
goto shmerror;
|
||||
}
|
||||
g_shmcheckpoint++;
|
||||
|
||||
g_image->data = (char *) shmat(g_xshminfo.shmid, 0, 0);
|
||||
if (g_image->data == ((char *) -1))
|
||||
{
|
||||
up_x11uninitialize();
|
||||
goto shmerror;
|
||||
}
|
||||
g_shmcheckpoint++;
|
||||
|
||||
g_xshminfo.shmaddr = g_image->data;
|
||||
g_xshminfo.readOnly = 0;
|
||||
|
||||
up_x11traperrors();
|
||||
result = XShmAttach(g_display, &g_xshminfo);
|
||||
if (up_x11untraperrors() || !result)
|
||||
{
|
||||
up_x11uninitialize();
|
||||
goto shmerror;
|
||||
}
|
||||
|
||||
g_shmcheckpoint++;
|
||||
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (!b_useshm)
|
||||
{
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
shmerror:
|
||||
#endif
|
||||
b_useshm = 0;
|
||||
|
||||
g_framebuffer = (unsigned char*)malloc(fblen);
|
||||
|
||||
g_image = XCreateImage(g_display, DefaultVisual(g_display,g_screen), depth,
|
||||
ZPixmap, 0, (char*)g_framebuffer, g_fbpixelwidth, g_fbpixelheight,
|
||||
8, 0);
|
||||
|
||||
if (g_image == NULL)
|
||||
{
|
||||
fprintf(stderr, "Unable to create g_image\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_shmcheckpoint++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
***************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11initialize
|
||||
*
|
||||
* Description:
|
||||
* Make an X11 window look like a frame buffer.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
int up_x11initialize(unsigned short width, unsigned short height,
|
||||
void **fbmem, unsigned int *fblen, unsigned char *bpp,
|
||||
unsigned short *stride)
|
||||
{
|
||||
XWindowAttributes windowAttributes;
|
||||
int depth;
|
||||
int ret;
|
||||
|
||||
/* Check if we are already initialized */
|
||||
|
||||
if (!g_x11initialized)
|
||||
{
|
||||
/* Save inputs */
|
||||
|
||||
g_fbpixelwidth = width;
|
||||
g_fbpixelheight = height;
|
||||
|
||||
/* Create the X11 window */
|
||||
|
||||
ret = up_x11createframe();
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Determine the supported pixel bpp of the current window */
|
||||
|
||||
XGetWindowAttributes(g_display, DefaultRootWindow(g_display), &windowAttributes);
|
||||
|
||||
/* Get the pixel depth. If the depth is 24-bits, use 32 because X expects
|
||||
* 32-bit aligment anyway.
|
||||
*/
|
||||
|
||||
depth = windowAttributes.depth;
|
||||
if (depth == 24)
|
||||
{
|
||||
depth = 32;
|
||||
}
|
||||
printf("Pixel bpp is %d bits (using %d)\n", windowAttributes.depth, depth);
|
||||
|
||||
*bpp = depth;
|
||||
*stride = (depth * width / 8);
|
||||
*fblen = (*stride * height);
|
||||
|
||||
/* Map the window to shared memory */
|
||||
|
||||
up_x11mapsharedmem(windowAttributes.depth, *fblen);
|
||||
g_x11initialized = 1;
|
||||
}
|
||||
|
||||
*fbmem = (void*)g_framebuffer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11cmap
|
||||
***************************************************************************/
|
||||
|
||||
int up_x11cmap(unsigned short first, unsigned short len,
|
||||
unsigned char *red, unsigned char *green,
|
||||
unsigned char *blue, unsigned char *transp)
|
||||
{
|
||||
Colormap cMap;
|
||||
int ndx;
|
||||
|
||||
printf("Creating Colormap\n");
|
||||
|
||||
/* Convert each color to X11 scaling */
|
||||
|
||||
cMap = DefaultColormap(g_display, g_screen);
|
||||
for (ndx = first; ndx < first + len; ndx++)
|
||||
{
|
||||
XColor color;
|
||||
|
||||
/* Convert to RGB. In the NuttX cmap, each component
|
||||
* ranges from 0-255; for X11 the range is 0-65536 */
|
||||
|
||||
color.red = (short)(*red++) << 8;
|
||||
color.green = (short)(*green++) << 8;
|
||||
color.blue = (short)(*blue++) << 8;
|
||||
color.flags = DoRed | DoGreen | DoBlue;
|
||||
|
||||
/* Then allocate a color for this selection */
|
||||
|
||||
if (!XAllocColor(g_display, cMap, &color))
|
||||
{
|
||||
fprintf(stderr, "Failed to allocate color%d\n", ndx);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_x11update
|
||||
***************************************************************************/
|
||||
|
||||
void up_x11update(void)
|
||||
{
|
||||
#ifndef CONFIG_SIM_X11NOSHM
|
||||
if (b_useshm)
|
||||
{
|
||||
XShmPutImage(g_display, g_window, g_gc, g_image, 0, 0, 0, 0,
|
||||
g_fbpixelwidth, g_fbpixelheight, 0);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
XPutImage(g_display, g_window, g_gc, g_image, 0, 0, 0, 0,
|
||||
g_fbpixelwidth, g_fbpixelheight);
|
||||
}
|
||||
XSync(g_display, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user