From ad65a046170ddff04e8257597197b3df758fa0a9 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 24 Jan 2013 14:14:44 +0000 Subject: Convert configs/olimex-lpc1766stk/nettest to use kconfig-frontends git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5555 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 2 + nuttx/configs/olimex-lpc1766stk/nettest/appconfig | 42 -- nuttx/configs/olimex-lpc1766stk/nettest/defconfig | 872 +++++++++++++--------- nuttx/sched/task_setup.c | 2 +- 4 files changed, 520 insertions(+), 398 deletions(-) delete mode 100644 nuttx/configs/olimex-lpc1766stk/nettest/appconfig diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 99f6d4a52..36286c77f 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4018,4 +4018,6 @@ CONFIG_SCHED_CHILD_STATUS * Add support for keyboard encode to the keypad test (from Denis Carikli). + * configs/olimex-lpc1766stk/nettest: Configuration converted to + use the kconfig-frontends tools. diff --git a/nuttx/configs/olimex-lpc1766stk/nettest/appconfig b/nuttx/configs/olimex-lpc1766stk/nettest/appconfig deleted file mode 100644 index a54371a1d..000000000 --- a/nuttx/configs/olimex-lpc1766stk/nettest/appconfig +++ /dev/null @@ -1,42 +0,0 @@ -############################################################################ -# configs/olimex-lpc1766stk/nettest/appconfig -# -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -# Path to example in apps/examples containing the user_start entry point - -CONFIGURED_APPS += examples/nettest - -# Networking support - -CONFIGURED_APPS += netutils/uiplib diff --git a/nuttx/configs/olimex-lpc1766stk/nettest/defconfig b/nuttx/configs/olimex-lpc1766stk/nettest/defconfig index 5b6b3d676..8b48cbac7 100755 --- a/nuttx/configs/olimex-lpc1766stk/nettest/defconfig +++ b/nuttx/configs/olimex-lpc1766stk/nettest/defconfig @@ -1,244 +1,293 @@ -############################################################################ -# configs/olimex-lpc1766stk/nettest/defconfig -# -# Copyright (C) 2010-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ -# -# Architecture Selection # -CONFIG_ARCH="arm" +# Automatically generated file; DO NOT EDIT. +# Nuttx/ Configuration +# +CONFIG_NUTTX_NEWCONFIG=y + +# +# Build Setup +# +# CONFIG_EXPERIMENTAL is not set +# CONFIG_HOST_LINUX=y +# CONFIG_HOST_OSX is not set +# CONFIG_HOST_WINDOWS is not set +# CONFIG_HOST_OTHER is not set + +# +# Build Configuration +# +CONFIG_APPS_DIR="../apps" +# CONFIG_BUILD_2PASS is not set + +# +# Binary Output Formats +# +# CONFIG_RRLOAD_BINARY is not set +CONFIG_INTELHEX_BINARY=y +# CONFIG_MOTOROLA_SREC is not set +# CONFIG_RAW_BINARY is not set + +# +# Customize Header Files +# +# CONFIG_ARCH_STDBOOL_H is not set +# CONFIG_ARCH_MATH_H is not set +# CONFIG_ARCH_FLOAT_H is not set +# CONFIG_ARCH_STDARG_H is not set + +# +# Debug Options +# +# CONFIG_DEBUG is not set +# CONFIG_DEBUG_SYMBOLS is not set + +# +# System Type +# +# CONFIG_ARCH_8051 is not set CONFIG_ARCH_ARM=y +# CONFIG_ARCH_AVR is not set +# CONFIG_ARCH_HC is not set +# CONFIG_ARCH_MIPS is not set +# CONFIG_ARCH_RGMP is not set +# CONFIG_ARCH_SH is not set +# CONFIG_ARCH_SIM is not set +# CONFIG_ARCH_X86 is not set +# CONFIG_ARCH_Z16 is not set +# CONFIG_ARCH_Z80 is not set +CONFIG_ARCH="arm" + +# +# ARM Options +# +# CONFIG_ARCH_CHIP_C5471 is not set +# CONFIG_ARCH_CHIP_CALYPSO is not set +# CONFIG_ARCH_CHIP_DM320 is not set +# CONFIG_ARCH_CHIP_IMX is not set +# CONFIG_ARCH_CHIP_KINETIS is not set +# CONFIG_ARCH_CHIP_LM is not set +CONFIG_ARCH_CHIP_LPC17XX=y +# CONFIG_ARCH_CHIP_LPC214X is not set +# CONFIG_ARCH_CHIP_LPC2378 is not set +# CONFIG_ARCH_CHIP_LPC31XX is not set +# CONFIG_ARCH_CHIP_LPC43XX is not set +# CONFIG_ARCH_CHIP_SAM3U is not set +# CONFIG_ARCH_CHIP_STM32 is not set +# CONFIG_ARCH_CHIP_STR71X is not set CONFIG_ARCH_CORTEXM3=y +CONFIG_ARCH_FAMILY="armv7-m" CONFIG_ARCH_CHIP="lpc17xx" -CONFIG_ARCH_CHIP_LPC17XX=y -CONFIG_ARCH_CHIP_LPC1766=y -CONFIG_ARCH_BOARD="olimex-lpc1766stk" -CONFIG_ARCH_BOARD_LPC1766STK=y +# CONFIG_ARMV7M_USEBASEPRI is not set +CONFIG_ARCH_HAVE_MPU=y +# CONFIG_ARMV7M_MPU is not set CONFIG_BOARD_LOOPSPERMSEC=8111 -CONFIG_DRAM_SIZE=32768 -CONFIG_DRAM_START=0x10000000 -CONFIG_ARCH_IRQPRIO=y -CONFIG_ARCH_INTERRUPTSTACK=0 -CONFIG_ARCH_STACKDUMP=y -CONFIG_ARCH_BOOTLOADER=n -CONFIG_ARCH_LEDS=y -CONFIG_ARCH_BUTTONS=n -CONFIG_ARCH_CALIBRATION=n -CONFIG_ARCH_DMA=n +# CONFIG_ARCH_CALIBRATION is not set # -# Identify toolchain and linker options +# ARMV7M Configuration Options # -CONFIG_LPC17_CODESOURCERYW=n -CONFIG_LPC17_CODESOURCERYL=n -CONFIG_LPC17_DEVKITARM=n -CONFIG_LPC17_BUILDROOT=y +CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y +# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set +# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABI is not set +CONFIG_ARMV7M_OABI_TOOLCHAIN=y # -# Individual subsystems can be enabled: +# LPC17xx Configuration Options # +# CONFIG_ARCH_CHIP_LPC1751 is not set +# CONFIG_ARCH_CHIP_LPC1752 is not set +# CONFIG_ARCH_CHIP_LPC1754 is not set +# CONFIG_ARCH_CHIP_LPC1756 is not set +# CONFIG_ARCH_CHIP_LPC1758 is not set +# CONFIG_ARCH_CHIP_LPC1759 is not set +# CONFIG_ARCH_CHIP_LPC1764 is not set +# CONFIG_ARCH_CHIP_LPC1765 is not set +CONFIG_ARCH_CHIP_LPC1766=y +# CONFIG_ARCH_CHIP_LPC1767 is not set +# CONFIG_ARCH_CHIP_LPC1768 is not set +# CONFIG_ARCH_CHIP_LPC1769 is not set +# CONFIG_ARCH_CHIP_LPC1773 is not set +# CONFIG_ARCH_CHIP_LPC1774 is not set +# CONFIG_ARCH_CHIP_LPC1776 is not set +# CONFIG_ARCH_CHIP_LPC1777 is not set +# CONFIG_ARCH_CHIP_LPC1778 is not set +# CONFIG_ARCH_CHIP_LPC1785 is not set +# CONFIG_ARCH_CHIP_LPC1786 is not set +# CONFIG_ARCH_CHIP_LPC1787 is not set +# CONFIG_ARCH_CHIP_LPC1788 is not set +CONFIG_ARCH_FAMILY_LPC176X=y + +# +# LPC17xx Peripheral Support +# +CONFIG_LPC17_MAINOSC=y +CONFIG_LPC17_PLL0=y +CONFIG_LPC17_PLL1=y CONFIG_LPC17_ETHERNET=y -CONFIG_LPC17_USBHOST=n -CONFIG_LPC17_USBOTG=n -CONFIG_LPC17_USBDEV=n +# CONFIG_LPC17_USBHOST is not set +# CONFIG_LPC17_USBDEV is not set CONFIG_LPC17_UART0=y -CONFIG_LPC17_UART1=n -CONFIG_LPC17_UART2=n -CONFIG_LPC17_UART3=n -CONFIG_LPC17_CAN1=n -CONFIG_LPC17_CAN2=n -CONFIG_LPC17_SPI=n -CONFIG_LPC17_SSP0=n -CONFIG_LPC17_SSP1=n -CONFIG_LPC17_I2C0=n -CONFIG_LPC17_I2C1=n -CONFIG_LPC17_I2S=n -CONFIG_LPC17_TMR0=n -CONFIG_LPC17_TMR1=n -CONFIG_LPC17_TMR2=n -CONFIG_LPC17_TMR3=n -CONFIG_LPC17_RIT=n -CONFIG_LPC17_PWM=n -CONFIG_LPC17_MCPWM=n -CONFIG_LPC17_QEI=n -CONFIG_LPC17_RTC=n -CONFIG_LPC17_WDT=n -CONFIG_LPC17_ADC=n -CONFIG_LPC17_DAC=n -CONFIG_LPC17_GPDMA=n - -# -# LPC17xx Button interrupt support -# -CONFIG_GPIO_IRQ=n -CONFIG_ARCH_IRQBUTTONS=n - -# -# LPC17xx specific serial device driver settings -# -CONFIG_UART0_SERIAL_CONSOLE=y -CONFIG_UART1_SERIAL_CONSOLE=n -CONFIG_UART2_SERIAL_CONSOLE=n -CONFIG_UART3_SERIAL_CONSOLE=n - -CONFIG_UART0_TXBUFSIZE=256 -CONFIG_UART1_TXBUFSIZE=256 -CONFIG_UART2_TXBUFSIZE=256 -CONFIG_UART3_TXBUFSIZE=256 +# CONFIG_LPC17_UART1 is not set +# CONFIG_LPC17_UART2 is not set +# CONFIG_LPC17_UART3 is not set +# CONFIG_LPC17_CAN1 is not set +# CONFIG_LPC17_CAN2 is not set +# CONFIG_LPC17_SPI is not set +# CONFIG_LPC17_SSP0 is not set +# CONFIG_LPC17_SSP1 is not set +# CONFIG_LPC17_I2C0 is not set +# CONFIG_LPC17_I2C1 is not set +# CONFIG_LPC17_I2C2 is not set +# CONFIG_LPC17_I2S is not set +# CONFIG_LPC17_TMR0 is not set +# CONFIG_LPC17_TMR1 is not set +# CONFIG_LPC17_TMR2 is not set +# CONFIG_LPC17_TMR3 is not set +# CONFIG_LPC17_RIT is not set +# CONFIG_LPC17_PWM is not set +# CONFIG_LPC17_MCPWM is not set +# CONFIG_LPC17_QEI is not set +# CONFIG_LPC17_RTC is not set +# CONFIG_LPC17_WDT is not set +# CONFIG_LPC17_ADC is not set +# CONFIG_LPC17_DAC is not set +# CONFIG_LPC17_GPDMA is not set +# CONFIG_LPC17_FLASH is not set -CONFIG_UART0_RXBUFSIZE=256 -CONFIG_UART1_RXBUFSIZE=256 -CONFIG_UART2_RXBUFSIZE=256 -CONFIG_UART3_RXBUFSIZE=256 - -CONFIG_UART0_BAUD=57600 -CONFIG_UART2_BAUD=57600 -CONFIG_UART3_BAUD=57600 -CONFIG_UART1_BAUD=57600 +# +# Serial driver options +# +# CONFIG_SERIAL_TERMIOS is not set +# CONFIG_UART0_FLOWCONTROL is not set -CONFIG_UART0_BITS=8 -CONFIG_UART1_BITS=8 -CONFIG_UART2_BITS=8 -CONFIG_UART3_BITS=8 +# +# ADC driver options +# -CONFIG_UART0_PARITY=0 -CONFIG_UART1_PARITY=0 -CONFIG_UART2_PARITY=0 -CONFIG_UART3_PARITY=0 +# +# CAN driver options +# +# CONFIG_GPIO_IRQ is not set -CONFIG_UART0_2STOP=0 -CONFIG_UART1_2STOP=0 -CONFIG_UART2_2STOP=0 -CONFIG_UART3_2STOP=0 +# +# I2C driver options +# # -# LPC17xx specific PHY/Ethernet device driver settings +# Ethernet driver options # -CONFIG_PHY_KS8721=y CONFIG_PHY_AUTONEG=y -CONFIG_PHY_SPEED100=n -CONFIG_PHY_FDUPLEX=y CONFIG_NET_EMACRAM_SIZE=8192 CONFIG_NET_NTXDESC=9 CONFIG_NET_NRXDESC=9 -CONFIG_NET_REGDEBUG=n +CONFIG_NET_PRIORITY=0 +# CONFIG_NET_WOL is not set +# CONFIG_NET_HASH is not set +# CONFIG_NET_MULTICAST is not set # -# General build options +# USB device driver options # -CONFIG_RRLOAD_BINARY=n -CONFIG_INTELHEX_BINARY=y -CONFIG_MOTOROLA_SREC=n -CONFIG_RAW_BINARY=n # -# General OS setup +# USB host driver options # -CONFIG_USER_ENTRYPOINT="nettest_main" -CONFIG_DEBUG=n -CONFIG_DEBUG_VERBOSE=n -CONFIG_DEBUG_SYMBOLS=n -CONFIG_DEBUG_NET=n -CONFIG_MM_REGIONS=2 -CONFIG_ARCH_LOWPUTC=y + +# +# External Memory Configuration +# + +# +# Architecture Options +# +# CONFIG_ARCH_NOINTC is not set +# CONFIG_ARCH_VECNOTIRQ is not set +# CONFIG_ARCH_DMA is not set +CONFIG_ARCH_IRQPRIO=y +# CONFIG_CUSTOM_STACK is not set +# CONFIG_ADDRENV is not set +CONFIG_ARCH_HAVE_VFORK=y +CONFIG_ARCH_STACKDUMP=y +# CONFIG_ENDIAN_BIG is not set +# CONFIG_ARCH_HAVE_RAMFUNCS is not set + +# +# Board Settings +# +CONFIG_DRAM_START=0x10000000 +CONFIG_DRAM_SIZE=32768 +CONFIG_ARCH_HAVE_INTERRUPTSTACK=y +CONFIG_ARCH_INTERRUPTSTACK=0 + +# +# Boot options +# +# CONFIG_BOOT_RUNFROMEXTSRAM is not set +CONFIG_BOOT_RUNFROMFLASH=y +# CONFIG_BOOT_RUNFROMISRAM is not set +# CONFIG_BOOT_RUNFROMSDRAM is not set +# CONFIG_BOOT_COPYTORAM is not set + +# +# Board Selection +# +CONFIG_ARCH_BOARD_LPC1766STK=y +# CONFIG_ARCH_BOARD_CUSTOM is not set +CONFIG_ARCH_BOARD="olimex-lpc1766stk" + +# +# Common Board Options +# +CONFIG_ARCH_HAVE_LEDS=y +CONFIG_ARCH_LEDS=y +CONFIG_ARCH_HAVE_BUTTONS=y +# CONFIG_ARCH_BUTTONS is not set +CONFIG_ARCH_HAVE_IRQBUTTONS=y + +# +# Board-Specific Options +# + +# +# RTOS Features +# +CONFIG_MSEC_PER_TICK=10 CONFIG_RR_INTERVAL=200 -CONFIG_SCHED_INSTRUMENTATION=n +# CONFIG_SCHED_INSTRUMENTATION is not set CONFIG_TASK_NAME_SIZE=0 +# CONFIG_SCHED_HAVE_PARENT is not set +# CONFIG_JULIAN_TIME is not set CONFIG_START_YEAR=2010 CONFIG_START_MONTH=11 CONFIG_START_DAY=10 -CONFIG_GREGORIAN_TIME=n -CONFIG_JULIAN_TIME=n CONFIG_DEV_CONSOLE=y -CONFIG_DEV_LOWCONSOLE=y -CONFIG_MUTEX_TYPES=n -CONFIG_PRIORITY_INHERITANCE=n -CONFIG_SEM_PREALLOCHOLDERS=0 -CONFIG_SEM_NNESTPRIO=0 -CONFIG_FDCLONE_DISABLE=n -CONFIG_FDCLONE_STDIO=n +# CONFIG_MUTEX_TYPES is not set +# CONFIG_PRIORITY_INHERITANCE is not set +# CONFIG_FDCLONE_DISABLE is not set +# CONFIG_FDCLONE_STDIO is not set CONFIG_SDCLONE_DISABLE=y -CONFIG_NXFLAT=n -CONFIG_SCHED_WORKQUEUE=n -CONFIG_SCHED_WORKPRIORITY=192 -CONFIG_SCHED_WORKPERIOD=50000 -CONFIG_SCHED_WORKSTACKSIZE=1024 -CONFIG_SIG_SIGWORK=17 - -# -# The following can be used to disable categories of -# APIs supported by the OS. If the compiler supports -# weak functions, then it should not be necessary to -# disable functions unless you want to restrict usage -# of those APIs. -# -# There are certain dependency relationships in these -# features. -# -# o mq_notify logic depends on signals to awaken tasks -# waiting for queues to become full or empty. -# o pthread_condtimedwait() depends on signals to wake -# up waiting tasks. -# -CONFIG_DISABLE_CLOCK=n -CONFIG_DISABLE_POSIX_TIMERS=n +# CONFIG_SCHED_WORKQUEUE is not set +# CONFIG_SCHED_WAITPID is not set +# CONFIG_SCHED_ATEXIT is not set +# CONFIG_SCHED_ONEXIT is not set +CONFIG_USER_ENTRYPOINT="nettest_main" +CONFIG_DISABLE_OS_API=y +# CONFIG_DISABLE_CLOCK is not set +# CONFIG_DISABLE_POSIX_TIMERS is not set CONFIG_DISABLE_PTHREAD=y -CONFIG_DISABLE_SIGNALS=n +# CONFIG_DISABLE_SIGNALS is not set CONFIG_DISABLE_MQUEUE=y CONFIG_DISABLE_MOUNTPOINT=y CONFIG_DISABLE_ENVIRON=y CONFIG_DISABLE_POLL=y # -# Misc libc settings -# -CONFIG_NOPRINTF_FIELDWIDTH=n - -# -# Allow for architecture optimized implementations -# -# The architecture can provide optimized versions of the -# following to improve system performance +# Signal Numbers # -CONFIG_ARCH_MEMCPY=n -CONFIG_ARCH_MEMCMP=n -CONFIG_ARCH_MEMMOVE=n -CONFIG_ARCH_MEMSET=n -CONFIG_ARCH_STRCMP=n -CONFIG_ARCH_STRCPY=n -CONFIG_ARCH_STRNCPY=n -CONFIG_ARCH_STRLEN=n -CONFIG_ARCH_STRNLEN=n -CONFIG_ARCH_BZERO=n +CONFIG_SIG_SIGUSR1=1 +CONFIG_SIG_SIGUSR2=2 +CONFIG_SIG_SIGALARM=3 # # Sizes of configurable things (0 disables) @@ -249,8 +298,6 @@ CONFIG_NPTHREAD_KEYS=0 CONFIG_NFILE_DESCRIPTORS=8 CONFIG_NFILE_STREAMS=8 CONFIG_NAME_MAX=32 -CONFIG_STDIO_BUFFER_SIZE=0 -CONFIG_NUNGET_CHARS=0 CONFIG_PREALLOC_MQ_MSGS=0 CONFIG_MQ_MAXMSGSIZE=0 CONFIG_MAX_WDOGPARMS=4 @@ -258,228 +305,343 @@ CONFIG_PREALLOC_WDOGS=8 CONFIG_PREALLOC_TIMERS=8 # -# Filesystem configuration +# Stack and heap information # -CONFIG_FS_FAT=n -CONFIG_FAT_LCNAMES=n -CONFIG_FAT_LFN=n -CONFIG_FAT_MAXFNAME=32 -CONFIG_FS_NXFFS=n -CONFIG_FS_ROMFS=n +CONFIG_IDLETHREAD_STACKSIZE=1024 +CONFIG_USERMAIN_STACKSIZE=2048 +CONFIG_PTHREAD_STACK_MIN=256 +CONFIG_PTHREAD_STACK_DEFAULT=2048 # -# Maintain legacy build behavior (revisit) -# - -CONFIG_MMCSD=y -CONFIG_MMCSD_SPI=y -CONFIG_MTD=y +# Device Drivers +# +CONFIG_DEV_NULL=y +# CONFIG_DEV_ZERO is not set +# CONFIG_LOOP is not set +# CONFIG_RAMDISK is not set +# CONFIG_CAN is not set +# CONFIG_PWM is not set +# CONFIG_I2C is not set +# CONFIG_SPI is not set +# CONFIG_RTC is not set +# CONFIG_WATCHDOG is not set +# CONFIG_ANALOG is not set +# CONFIG_BCH is not set +# CONFIG_INPUT is not set +# CONFIG_LCD is not set +# CONFIG_MMCSD is not set +# CONFIG_MTD is not set +# CONFIG_NETDEVICES is not set +# CONFIG_NET_SLIP is not set +# CONFIG_PIPES is not set +# CONFIG_PM is not set +# CONFIG_POWER is not set +# CONFIG_SENSORS is not set +# CONFIG_SERCOMM_CONSOLE is not set +CONFIG_SERIAL=y +CONFIG_DEV_LOWCONSOLE=y +# CONFIG_16550_UART is not set +CONFIG_ARCH_HAVE_UART0=y +CONFIG_MCU_SERIAL=y +CONFIG_UART0_SERIAL_CONSOLE=y +# CONFIG_NO_SERIAL_CONSOLE is not set # -# SPI-based MMC/SD driver +# UART0 Configuration # -CONFIG_MMCSD_NSLOTS=1 -CONFIG_MMCSD_READONLY=n -CONFIG_MMCSD_SPICLOCK=12500000 +CONFIG_UART0_RXBUFSIZE=256 +CONFIG_UART0_TXBUFSIZE=256 +CONFIG_UART0_BAUD=57600 +CONFIG_UART0_BITS=8 +CONFIG_UART0_PARITY=0 +CONFIG_UART0_2STOP=0 +# CONFIG_USBDEV is not set +# CONFIG_USBHOST is not set +# CONFIG_WIRELESS is not set # -# Block driver buffering +# System Logging Device Options # -CONFIG_FS_READAHEAD=n -CONFIG_FS_WRITEBUFFER=n # -# SDIO-based MMC/SD driver +# System Logging # -CONFIG_SDIO_DMA=n -CONFIG_MMCSD_MMCSUPPORT=n -CONFIG_MMCSD_HAVECARDDETECT=n +# CONFIG_RAMLOG is not set # -# TCP/IP and UDP support via uIP +# Networking Support # CONFIG_NET=y -CONFIG_NET_IPv6=n +CONFIG_ARCH_HAVE_PHY=y +CONFIG_PHY_KS8721=y +# CONFIG_PHY_DP83848C is not set +# CONFIG_PHY_LAN8720 is not set +# CONFIG_PHY_DM9161 is not set +# CONFIG_NET_NOINTS is not set +# CONFIG_NET_MULTIBUFFER is not set +# CONFIG_NET_IPv6 is not set CONFIG_NSOCKET_DESCRIPTORS=8 +CONFIG_NET_NACTIVESOCKETS=16 CONFIG_NET_SOCKOPTS=y CONFIG_NET_BUFSIZE=420 +# CONFIG_NET_TCPURGDATA is not set + +# +# TCP/IP Networking +# CONFIG_NET_TCP=y CONFIG_NET_TCP_CONNS=8 -CONFIG_NET_NTCP_READAHEAD_BUFFERS=8 -CONFIG_NET_TCPBACKLOG=n CONFIG_NET_MAX_LISTENPORTS=8 -CONFIG_NET_UDP=n -CONFIG_NET_UDP_CHECKSUMS=y -#CONFIG_NET_UDP_CONNS=10 +CONFIG_NET_TCP_READAHEAD_BUFSIZE=562 +CONFIG_NET_NTCP_READAHEAD_BUFFERS=8 +CONFIG_NET_TCP_RECVDELAY=0 +# CONFIG_NET_TCPBACKLOG is not set +# CONFIG_NET_TCP_SPLIT is not set + +# +# UDP Networking +# +# CONFIG_NET_UDP is not set CONFIG_NET_ICMP=y -CONFIG_NET_ICMP_PING=n -#CONFIG_NET_PINGADDRCONF=0 -CONFIG_NET_STATISTICS=n -#CONFIG_NET_RECEIVE_WINDOW= -#CONFIG_NET_ARPTAB_SIZE=8 -CONFIG_NET_BROADCAST=n +# CONFIG_NET_ICMP_PING is not set +# CONFIG_NET_PINGADDRCONF is not set +# CONFIG_NET_IGMP is not set +# CONFIG_NET_STATISTICS is not set +CONFIG_NET_RECEIVE_WINDOW=562 +CONFIG_NET_ARPTAB_SIZE=16 +# CONFIG_NET_ARP_IPIN is not set # -# UIP Network Utilities +# File Systems # -CONFIG_NET_DHCP_LIGHT=n -CONFIG_NET_RESOLV_ENTRIES=4 # -# USB Device Configuration +# File system configuration # -CONFIG_USBDEV=n -CONFIG_USBDEV_ISOCHRONOUS=n -CONFIG_USBDEV_DUALSPEED=n -CONFIG_USBDEV_SELFPOWERED=y -CONFIG_USBDEV_REMOTEWAKEUP=n -CONFIG_USBDEV_MAXPOWER=100 -CONFIG_USBDEV_TRACE=n -CONFIG_USBDEV_TRACE_NRECORDS=128 +# CONFIG_FS_RAMMAP is not set # -# LPC17xx USB Configuration +# System Logging # -CONFIG_LPC17_USBDEV_FRAME_INTERRUPT=n -CONFIG_LPC17_USBDEV_EPFAST_INTERRUPT=n -CONFIG_LPC17_USBDEV_DMA=n -CONFIG_LPC17_USBDEV_NDMADESCRIPTORS=0 -CONFIG_LPC17_USBDEV_DMAINTMASK=0 +# CONFIG_SYSLOG is not set # -# USB Serial Device Configuration +# Graphics Support # -CONFIG_PL2303=n -CONFIG_PL2303_EPINTIN=1 -CONFIG_PL2303_EPBULKOUT=2 -CONFIG_PL2303_EPBULKIN=5 -CONFIG_PL2303_NWRREQS=4 -CONFIG_PL2303_NRDREQS=4 -CONFIG_PL2303_VENDORID=0x067b -CONFIG_PL2303_PRODUCTID=0x2303 -CONFIG_PL2303_VENDORSTR="Nuttx" -CONFIG_PL2303_PRODUCTSTR="USBdev Serial" -CONFIG_PL2303_RXBUFSIZE=512 -CONFIG_PL2303_TXBUFSIZE=512 +# CONFIG_NX is not set # -# USB Storage Device Configuration +# Memory Management # -CONFIG_USBMSC=n -CONFIG_USBMSC_EP0MAXPACKET=64 -CONFIG_USBMSC_EPBULKOUT=2 -CONFIG_USBMSC_EPBULKIN=5 -CONFIG_USBMSC_NRDREQS=2 -CONFIG_USBMSC_NWRREQS=2 -CONFIG_USBMSC_BULKINREQLEN=256 -CONFIG_USBMSC_BULKOUTREQLEN=256 -CONFIG_USBMSC_VENDORID=0x584e -CONFIG_USBMSC_VENDORSTR="NuttX" -CONFIG_USBMSC_PRODUCTID=0x5342 -CONFIG_USBMSC_PRODUCTSTR="USBdev Storage" -CONFIG_USBMSC_VERSIONNO=0x0399 -CONFIG_USBMSC_REMOVABLE=y +# CONFIG_MM_SMALL is not set +CONFIG_MM_REGIONS=2 +# CONFIG_GRAN is not set # -# Settings for examples/uip +# Binary Formats # -CONFIG_EXAMPLES_UIP_IPADDR=0x0a000002 -CONFIG_EXAMPLES_UIP_DRIPADDR=0x0a000001 -CONFIG_EXAMPLES_UIP_NETMASK=0xffffff00 -CONFIG_EXAMPLES_UIP_DHCPC=n +# CONFIG_BINFMT_DISABLE is not set +# CONFIG_NXFLAT is not set +# CONFIG_ELF is not set +# CONFIG_BUILTIN is not set +# CONFIG_PIC is not set +# CONFIG_SYMTAB_ORDEREDBYNAME is not set # -# Settings for examples/nettest +# Library Routines +# + # -CONFIG_EXAMPLES_NETTEST_SERVER=n -CONFIG_EXAMPLES_NETTEST_PERFORMANCE=n +# Standard C Library Options +# +CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_LINEBUFFER=y +CONFIG_NUNGET_CHARS=0 +# CONFIG_LIBM is not set +# CONFIG_NOPRINTF_FIELDWIDTH is not set +# CONFIG_LIBC_FLOATINGPOINT is not set +# CONFIG_EOL_IS_CR is not set +# CONFIG_EOL_IS_LF is not set +# CONFIG_EOL_IS_BOTH_CRLF is not set +CONFIG_EOL_IS_EITHER_CRLF=y +# CONFIG_LIBC_EXECFUNCS is not set +# CONFIG_LIBC_STRERROR is not set +# CONFIG_LIBC_PERROR_STDOUT is not set +CONFIG_ARCH_LOWPUTC=y +CONFIG_LIB_SENDFILE_BUFSIZE=512 +# CONFIG_ARCH_ROMGETC is not set +# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set + +# +# Non-standard Helper Functions +# +# CONFIG_LIB_KBDCODEC is not set + +# +# Basic CXX Support +# +# CONFIG_C99_BOOL8 is not set +# CONFIG_HAVE_CXX is not set + +# +# Application Configuration +# + +# +# Built-In Applications +# + +# +# Examples +# +# CONFIG_EXAMPLES_BUTTONS is not set +# CONFIG_EXAMPLES_CAN is not set +# CONFIG_EXAMPLES_CDCACM is not set +# CONFIG_EXAMPLES_COMPOSITE is not set +# CONFIG_EXAMPLES_DHCPD is not set +# CONFIG_EXAMPLES_ELF is not set +# CONFIG_EXAMPLES_FTPC is not set +# CONFIG_EXAMPLES_FTPD is not set +# CONFIG_EXAMPLES_HELLO is not set +# CONFIG_EXAMPLES_HELLOXX is not set +# CONFIG_EXAMPLES_JSON is not set +# CONFIG_EXAMPLES_HIDKBD is not set +# CONFIG_EXAMPLES_KEYPADTEST is not set +# CONFIG_EXAMPLES_IGMP is not set +# CONFIG_EXAMPLES_LCDRW is not set +# CONFIG_EXAMPLES_MM is not set +# CONFIG_EXAMPLES_MOUNT is not set +# CONFIG_EXAMPLES_MODBUS is not set +CONFIG_EXAMPLES_NETTEST=y +# CONFIG_EXAMPLES_NETTEST_SERVER is not set +# CONFIG_EXAMPLES_NETTEST_PERFORMANCE is not set CONFIG_EXAMPLES_NETTEST_NOMAC=y CONFIG_EXAMPLES_NETTEST_IPADDR=0x0a000002 CONFIG_EXAMPLES_NETTEST_DRIPADDR=0x0a000001 CONFIG_EXAMPLES_NETTEST_NETMASK=0xffffff00 CONFIG_EXAMPLES_NETTEST_CLIENTIP=0x0a000001 +# CONFIG_EXAMPLES_NSH is not set +# CONFIG_EXAMPLES_NULL is not set +# CONFIG_EXAMPLES_NX is not set +# CONFIG_EXAMPLES_NXCONSOLE is not set +# CONFIG_EXAMPLES_NXFFS is not set +# CONFIG_EXAMPLES_NXFLAT is not set +# CONFIG_EXAMPLES_NXHELLO is not set +# CONFIG_EXAMPLES_NXIMAGE is not set +# CONFIG_EXAMPLES_NXLINES is not set +# CONFIG_EXAMPLES_NXTEXT is not set +# CONFIG_EXAMPLES_OSTEST is not set +# CONFIG_EXAMPLES_PASHELLO is not set +# CONFIG_EXAMPLES_PIPE is not set +# CONFIG_EXAMPLES_POLL is not set +# CONFIG_EXAMPLES_POSIXSPAWN is not set +# CONFIG_EXAMPLES_QENCODER is not set +# CONFIG_EXAMPLES_RGMP is not set +# CONFIG_EXAMPLES_ROMFS is not set +# CONFIG_EXAMPLES_SENDMAIL is not set +# CONFIG_EXAMPLES_SERLOOP is not set +# CONFIG_EXAMPLES_TELNETD is not set +# CONFIG_EXAMPLES_THTTPD is not set +# CONFIG_EXAMPLES_TIFF is not set +# CONFIG_EXAMPLES_TOUCHSCREEN is not set +# CONFIG_EXAMPLES_UDP is not set +# CONFIG_EXAMPLES_UIP is not set +# CONFIG_EXAMPLES_USBSERIAL is not set +# CONFIG_EXAMPLES_USBMSC is not set +# CONFIG_EXAMPLES_USBTERM is not set +# CONFIG_EXAMPLES_WATCHDOG is not set +# CONFIG_EXAMPLES_WGET is not set # -# Settings for examples/ostest +# Interpreters # -CONFIG_EXAMPLES_OSTEST_LOOPS=1 -CONFIG_EXAMPLES_OSTEST_STACKSIZE=2048 -CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS=3 # -# Settings for examples/buttons +# Interpreters # -CONFIG_EXAMPLES_BUTTONS_MIN=0 -CONFIG_EXAMPLES_BUTTONS_MAX=7 -CONFIG_EXAMPLES_IRQBUTTONS_MIN=0 -CONFIG_EXAMPLES_IRQBUTTONS_MAX=7 -CONFIG_EXAMPLES_BUTTONS_NAME0="BUT1" -CONFIG_EXAMPLES_BUTTONS_NAME1="BUT2" -CONFIG_EXAMPLES_BUTTONS_NAME2="WAKE-UP" -CONFIG_EXAMPLES_BUTTONS_NAME3="CENTER" -CONFIG_EXAMPLES_BUTTONS_NAME4="UP" -CONFIG_EXAMPLES_BUTTONS_NAME5="DOWN" -CONFIG_EXAMPLES_BUTTONS_NAME6="LEFT" -CONFIG_EXAMPLES_BUTTONS_NAME7="RIGHT" +# CONFIG_INTERPRETERS_FICL is not set +# CONFIG_INTERPRETERS_PCODE is not set # -# Settings for apps/nshlib +# Network Utilities # -CONFIG_NSH_FILEIOSIZE=512 -CONFIG_NSH_STRERROR=n -CONFIG_NSH_LINELEN=64 -CONFIG_NSH_NESTDEPTH=3 -CONFIG_NSH_DISABLESCRIPT=n -CONFIG_NSH_DISABLEBG=n -CONFIG_NSH_ROMFSETC=n -CONFIG_NSH_CONSOLE=y -CONFIG_NSH_TELNET=n -CONFIG_NSH_ARCHINIT=n -CONFIG_NSH_IOBUFFER_SIZE=512 -CONFIG_NSH_DHCPC=n -CONFIG_NSH_NOMAC=y -CONFIG_NSH_IPADDR=0x0a000002 -CONFIG_NSH_DRIPADDR=0x0a000001 -CONFIG_NSH_NETMASK=0xffffff00 -CONFIG_NSH_ROMFSMOUNTPT="/etc" -CONFIG_NSH_INITSCRIPT="init.d/rcS" -CONFIG_NSH_ROMFSDEVNO=0 -CONFIG_NSH_ROMFSSECTSIZE=64 -CONFIG_NSH_FATDEVNO=1 -CONFIG_NSH_FATSECTSIZE=512 -CONFIG_NSH_FATNSECTORS=1024 -CONFIG_NSH_FATMOUNTPT="/tmp" # -# Architecture-specific NSH options +# Networking Utilities # -CONFIG_NSH_MMCSDSPIPORTNO=0 -CONFIG_NSH_MMCSDSLOTNO=0 -CONFIG_NSH_MMCSDMINOR=0 +# CONFIG_NETUTILS_CODECS is not set +# CONFIG_NETUTILS_DHCPC is not set +# CONFIG_NETUTILS_DHCPD is not set +# CONFIG_NETUTILS_FTPC is not set +# CONFIG_NETUTILS_FTPD is not set +# CONFIG_NETUTILS_JSON is not set +# CONFIG_NETUTILS_RESOLV is not set +# CONFIG_NETUTILS_SMTP is not set +# CONFIG_NETUTILS_TELNETD is not set +# CONFIG_NETUTILS_TFTPC is not set +# CONFIG_NETUTILS_THTTPD is not set +CONFIG_NETUTILS_UIPLIB=y +# CONFIG_NETUTILS_WEBCLIENT is not set +# CONFIG_NETUTILS_WEBSERVER is not set +# CONFIG_NETUTILS_XMLRPC is not set # -# Settings for examples/usbserial +# ModBus # -CONFIG_EXAMPLES_USBSERIAL_INONLY=n -CONFIG_EXAMPLES_USBSERIAL_OUTONLY=n -CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL=n -CONFIG_EXAMPLES_USBSERIAL_ONLYBIG=n -CONFIG_EXAMPLES_USBSERIAL_TRACEINIT=n -CONFIG_EXAMPLES_USBSERIAL_TRACECLASS=n -CONFIG_EXAMPLES_USBSERIAL_TRACETRANSFERS=n -CONFIG_EXAMPLES_USBSERIAL_TRACECONTROLLER=n -CONFIG_EXAMPLES_USBSERIAL_TRACEINTERRUPTS=n +# +# FreeModbus +# +# CONFIG_MODBUS is not set # -# Stack and heap information +# NSH Library # -CONFIG_BOOT_RUNFROMFLASH=n -CONFIG_BOOT_COPYTORAM=n -CONFIG_CUSTOM_STACK=n -CONFIG_IDLETHREAD_STACKSIZE=1024 -CONFIG_USERMAIN_STACKSIZE=2048 -CONFIG_PTHREAD_STACK_MIN=256 -CONFIG_PTHREAD_STACK_DEFAULT=2048 -CONFIG_HEAP_BASE= -CONFIG_HEAP_SIZE= +# CONFIG_NSH_LIBRARY is not set + +# +# NxWidgets/NxWM +# + +# +# System NSH Add-Ons +# + +# +# Custom Free Memory Command +# +# CONFIG_SYSTEM_FREE is not set + +# +# I2C tool +# + +# +# FLASH Program Installation +# +# CONFIG_SYSTEM_INSTALL is not set + +# +# readline() +# +# CONFIG_SYSTEM_READLINE is not set + +# +# Power Off +# +# CONFIG_SYSTEM_POWEROFF is not set + +# +# RAMTRON +# +# CONFIG_SYSTEM_RAMTRON is not set + +# +# SD Card +# +# CONFIG_SYSTEM_SDCARD is not set + +# +# Sysinfo +# +# CONFIG_SYSTEM_SYSINFO is not set diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c index 80aefded3..8f54b2e93 100644 --- a/nuttx/sched/task_setup.c +++ b/nuttx/sched/task_setup.c @@ -219,7 +219,7 @@ static inline void task_saveparent(FAR _TCB *tcb, uint8_t ttype) } } #else -# define task_saveparent(tcb) +# define task_saveparent(tcb,ttype) #endif /**************************************************************************** -- cgit v1.2.3 From f914a905566ed97b414c4475a22ff8a7a6f222a0 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 24 Jan 2013 16:28:15 +0000 Subject: apps/examples/nettest and poll: Complete Kconfig files git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5556 42af7a65-404d-4744-a932-0658087f49c3 --- apps/ChangeLog.txt | 1 + apps/examples/README.txt | 4 ++-- apps/examples/nettest/Kconfig | 43 +++++++++++++++++++++++++++++++++++++++++ apps/examples/nettest/Makefile | 2 +- apps/examples/nettest/nettest.h | 4 ++-- apps/examples/poll/Kconfig | 18 +++++++++++++++++ nuttx/drivers/Kconfig | 8 ++++++++ nuttx/drivers/loop.c | 2 +- nuttx/fs/Kconfig | 4 ++++ nuttx/sched/Kconfig | 10 ---------- 10 files changed, 80 insertions(+), 16 deletions(-) diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index bcc0ac172..5f3440897 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -492,3 +492,4 @@ the entrypoint. Should be ftpd_main (from Yan T.) * apps/netutils/telnetd/telnetd_driver: Was stuck in a loop if recv[from]() ever returned a value <= 0. + * apps/examples/nettest and poll: Complete Kconfig files. diff --git a/apps/examples/README.txt b/apps/examples/README.txt index 5996cbb70..03d43f1a0 100644 --- a/apps/examples/README.txt +++ b/apps/examples/README.txt @@ -675,8 +675,8 @@ examples/mount when CONFIG_EXAMPLES_MOUNT_DEVNAME is not defined. The default is zero (meaning that "/dev/ram0" will be used). -examples/netttest -^^^^^^^^^^^^^^^^^ +examples/nettest +^^^^^^^^^^^^^^^^ This is a simple network test for verifying client- and server- functionality in a TCP/IP connection. diff --git a/apps/examples/nettest/Kconfig b/apps/examples/nettest/Kconfig index 63d34ec3f..613b8ea91 100644 --- a/apps/examples/nettest/Kconfig +++ b/apps/examples/nettest/Kconfig @@ -6,8 +6,51 @@ config EXAMPLES_NETTEST bool "Network test example" default n + depends on NET_TCP ---help--- Enable the network test example if EXAMPLES_NETTEST + +config EXAMPLES_NETTEST_SERVER + bool "Target is server" + default n + ---help--- + Select to use the host as the client side of the test. Default: The + target is the client side of the test + +config EXAMPLES_NETTEST_PERFORMANCE + bool "Test for Performance" + default n + ---help--- + Configure the example to test for network performance. Default: Test + is for network functionality. + +config EXAMPLES_NETTEST_NOMAC + bool "Use Canned MAC Address" + default n + +config EXAMPLES_NETTEST_IPADDR + hex "Target IP address" + default 0x0a000002 + +config EXAMPLES_NETTEST_DRIPADDR + hex "Default Router IP address (Gateway)" + default 0x0a000001 + +config EXAMPLES_NETTEST_NETMASK + hex "Network Mask" + default 0xffffff00 + +config EXAMPLES_NETTEST_CLIENTIP + hex "Client IP Address" + default 0x0a000001 if !EXAMPLES_NETTEST_SERVER + default 0x0a000002 if EXAMPLES_NETTEST_SERVER + ---help--- + IP address of the client. If the target is the client, then + EXAMPLES_NETTEST_CLIENTIP should be the same as + EXAMPLES_NETTEST_IPADDR (default). If the target is the server, + then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the + gateway address, EXAMPLES_NETTEST_DRIPADDR. + endif diff --git a/apps/examples/nettest/Makefile b/apps/examples/nettest/Makefile index 5368bdefc..c533c9dd5 100644 --- a/apps/examples/nettest/Makefile +++ b/apps/examples/nettest/Makefile @@ -64,7 +64,7 @@ else endif endif -HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_HOST=1 +HOSTCFLAGS += -DNETTEST_HOST=1 ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_CLIENTIP="$(CONFIG_EXAMPLES_NETTEST_CLIENTIP)" endif diff --git a/apps/examples/nettest/nettest.h b/apps/examples/nettest/nettest.h index f05038584..37ac470d1 100644 --- a/apps/examples/nettest/nettest.h +++ b/apps/examples/nettest/nettest.h @@ -40,7 +40,7 @@ * Included Files ****************************************************************************/ -#ifdef CONFIG_EXAMPLES_NETTEST_HOST +#ifdef NETTEST_HOST #else # include #endif @@ -49,7 +49,7 @@ * Definitions ****************************************************************************/ -#ifdef CONFIG_EXAMPLES_NETTEST_HOST +#ifdef NETTEST_HOST /* HTONS/L macros are unique to uIP */ # define HTONS(a) htons(a) diff --git a/apps/examples/poll/Kconfig b/apps/examples/poll/Kconfig index c52827496..f35a9200b 100644 --- a/apps/examples/poll/Kconfig +++ b/apps/examples/poll/Kconfig @@ -6,8 +6,26 @@ config EXAMPLES_POLL bool "Poll example" default n + depends on !NSH_BUILTIN_APPS ---help--- Enable the poll example if EXAMPLES_POLL + +config EXAMPLES_POLL_NOMAC + bool "Use Canned MAC Address" + default n + +config EXAMPLES_POLL_IPADDR + hex "Target IP address" + default 0x0a000002 + +config EXAMPLES_POLL_DRIPADDR + hex "Default Router IP address (Gateway)" + default 0x0a000001 + +config EXAMPLES_POLL_NETMASK + hex "Network Mask" + default 0xffffff00 + endif diff --git a/nuttx/drivers/Kconfig b/nuttx/drivers/Kconfig index 3ced01b58..f3d2c871a 100644 --- a/nuttx/drivers/Kconfig +++ b/nuttx/drivers/Kconfig @@ -3,6 +3,14 @@ # see misc/tools/kconfig-language.txt. # +config DISABLE_POLL + bool "Disable driver poll interfaces" + default n + ---help--- + The sizes of drivers can be reduced if the poll() method is not + supported. If you do not use poll() or select(), then you can + select DISABLE_POLL to reduce the code footprint by a small amount. + config DEV_NULL bool "Enable /dev/null" default y diff --git a/nuttx/drivers/loop.c b/nuttx/drivers/loop.c index b5b5d82d8..4744ae0dd 100644 --- a/nuttx/drivers/loop.c +++ b/nuttx/drivers/loop.c @@ -268,7 +268,7 @@ static ssize_t loop_write(FAR struct inode *inode, const unsigned char *buffer, size_t start_sector, unsigned int nsectors) { FAR struct loop_struct_s *dev; - size_t nbyteswritten; + ssize_t nbyteswritten; off_t offset; int ret; diff --git a/nuttx/fs/Kconfig b/nuttx/fs/Kconfig index dfbfda3fa..ab03a2b64 100644 --- a/nuttx/fs/Kconfig +++ b/nuttx/fs/Kconfig @@ -5,6 +5,10 @@ comment "File system configuration" +config DISABLE_MOUNTPOINT + bool "Disable support for mount points" + default n + source fs/mmap/Kconfig source fs/fat/Kconfig source fs/nfs/Kconfig diff --git a/nuttx/sched/Kconfig b/nuttx/sched/Kconfig index fe9a88085..7ea301600 100644 --- a/nuttx/sched/Kconfig +++ b/nuttx/sched/Kconfig @@ -379,21 +379,11 @@ config DISABLE_MQUEUE depends on DISABLE_OS_API default n -config DISABLE_MOUNTPOINT - bool "Disable support for mount points" - depends on DISABLE_OS_API - default n - config DISABLE_ENVIRON bool "Disable environment variable support" depends on DISABLE_OS_API default n -config DISABLE_POLL - bool "Disable driver poll interfaces" - depends on DISABLE_OS_API - default n - if !DISABLE_SIGNALS comment "Signal Numbers" -- cgit v1.2.3 From 888306f7280390e610544289429660d444a637c0 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 24 Jan 2013 18:39:53 +0000 Subject: Add psock_poll(); Fix some warnings reported by Lorenz Meier; lm4f logic from JP git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5557 42af7a65-404d-4744-a932-0658087f49c3 --- apps/nshlib/nsh_ddcmd.c | 2 +- nuttx/ChangeLog | 1 + nuttx/arch/arm/include/lm/chip.h | 26 +++++++++- nuttx/configs/lm3s6965-ek/tools/oocd.sh | 2 +- nuttx/include/nuttx/net/net.h | 85 ++++++++++++++++++--------------- nuttx/libc/stdio/lib_libfread.c | 4 +- nuttx/net/send.c | 2 +- nuttx/sched/mq_sndinternal.c | 2 +- 8 files changed, 78 insertions(+), 46 deletions(-) diff --git a/apps/nshlib/nsh_ddcmd.c b/apps/nshlib/nsh_ddcmd.c index 40a3710b1..e6ef2523c 100644 --- a/apps/nshlib/nsh_ddcmd.c +++ b/apps/nshlib/nsh_ddcmd.c @@ -545,7 +545,7 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif - if (dd.skip < 0 || dd.skip > dd.nsectors) + if (dd.skip > dd.nsectors) { nsh_output(vtbl, g_fmtarginvalid, g_dd); goto errout_with_paths; diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 36286c77f..ffd1b66ae 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4020,4 +4020,5 @@ Denis Carikli). * configs/olimex-lpc1766stk/nettest: Configuration converted to use the kconfig-frontends tools. + * net/net_poll.c: Split net_poll() to create psock_poll() too. diff --git a/nuttx/arch/arm/include/lm/chip.h b/nuttx/arch/arm/include/lm/chip.h index 6b49fe2ce..6214a50d0 100644 --- a/nuttx/arch/arm/include/lm/chip.h +++ b/nuttx/arch/arm/include/lm/chip.h @@ -3,6 +3,7 @@ * * Copyright (C) 2009-2010, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt + * Author: Jose Pablo Carballo * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -50,6 +51,7 @@ #if defined(CONFIG_ARCH_CHIP_LM3S6918) # define LM_NTIMERS 4 /* Four general purpose timers */ +# define LM_NWIDETIMERS 0 /* No general purpose wide timers */ # define LM_NETHCONTROLLERS 1 /* One Ethernet controller */ # undef LM_ETHTS /* No timestamp register */ # define LM_NSSI 2 /* Two SSI modules */ @@ -59,8 +61,10 @@ # define LM_NPWM 0 /* No PWM generator modules */ # define LM_NQEI 0 /* No quadrature encoders */ # define LM_NPORTS 8 /* 8 Ports (GPIOA-H) 5-38 GPIOs */ +# define LM_NCANCONTROLLER 0 /* No CAN controllers */ #elif defined(CONFIG_ARCH_CHIP_LM3S6432) # define LM_NTIMERS 3 /* Three general purpose timers */ +# define LM_NWIDETIMERS 0 /* No general purpose wide timers */ # define LM_NETHCONTROLLERS 1 /* One Ethernet controller */ # undef LM_ETHTS /* No timestamp register */ # define LM_NSSI 1 /* One SSI module */ @@ -70,8 +74,10 @@ # define LM_NPWM 1 /* One PWM generator module */ # define LM_NQEI 0 /* No quadrature encoders */ # define LM_NPORTS 7 /* 7 Ports (GPIOA-G), 0-42 GPIOs */ +# define LM_NCANCONTROLLER 0 /* No CAN controllers */ #elif defined(CONFIG_ARCH_CHIP_LM3S6965) # define LM_NTIMERS 4 /* Four general purpose timers */ +# define LM_NWIDETIMERS 0 /* No general purpose wide timers */ # define LM_NETHCONTROLLERS 1 /* One Ethernet controller */ # undef LM_ETHTS /* No timestamp register */ # define LM_NSSI 1 /* One SSI module */ @@ -81,8 +87,10 @@ # define LM_NPWM 3 /* Three PWM generator modules */ # define LM_NQEI 2 /* Two quadrature encoders */ # define LM_NPORTS 7 /* 7 Ports (GPIOA-G), 0-42 GPIOs */ +# define LM_NCANCONTROLLER 0 /* No CAN controllers */ #elif defined(CONFIG_ARCH_CHIP_LM3S9B96) # define LM_NTIMERS 4 /* Four general purpose timers */ +# define LM_NWIDETIMERS 0 /* No general purpose wide timers */ # define LM_NETHCONTROLLERS 1 /* One Ethernet controller */ # undef LM_ETHTS /* No timestamp register */ # define LM_NSSI 2 /* Two SSI modules */ @@ -93,8 +101,10 @@ # define LM_NPWM 4 /* Four PWM generator modules */ # define LM_NQEI 2 /* Two quadrature encoders */ # define LM_NPORTS 9 /* 9 Ports (GPIOA-H,J) 0-65 GPIOs */ +# define LM_NCANCONTROLLER 0 /* No CAN controllers */ #elif defined(CONFIG_ARCH_CHIP_LM3S8962) -# define LM_NTIMERS 4 /* Four general purpose timers */ +# define LM_NTIMERS 6 /* Four general purpose timers */ +# define LM_NWIDETIMERS 0 /* No general purpose wide timers */ # define LM_NETHCONTROLLERS 1 /* One Ethernet controller */ # define LM_NSSI 1 /* One SSI module */ # define LM_NUARTS 3 /* Two UART modules */ @@ -103,7 +113,19 @@ # define LM_NPWM 3 /* Three PWM generator modules */ # define LM_NQEI 2 /* Two quadrature encoders */ # define LM_NPORTS 7 /* 7 Ports (GPIOA-G), 5-42 GPIOs */ -# define LM_CANCONTROLLER 1 /* One CAN controller */ +# define LM_NCANCONTROLLER 1 /* One CAN controller */ +#elif defined(CONFIG_ARCH_CHIP_LM4F120) +# define LM_NTIMERS 6 /* Six general purpose timers */ +# define LM_NWIDETIMERS 6 /* Six general purpose wide timers */ +# define LM_NETHCONTROLLERS 0 /* No Ethernet controller */ +# define LM_NSSI 4 /* Four SSI module */ +# define LM_NUARTS 8 /* Eight UART modules */ +# define LM_NI2C 4 /* Four I2C modules */ +# define LM_NADC 2 /* Two ADC modules */ +# define LM_NPWM 0 /* No PWM generator modules */ +# define LM_NQEI 0 /* No quadrature encoders */ +# define LM_NPORTS 6 /* 6 Ports (GPIOA-F), 0-43 GPIOs */ +# define LM_NCANCONTROLLER 1 /* One CAN controller */ #else # error "Capabilities not specified for this Stellaris chip" #endif diff --git a/nuttx/configs/lm3s6965-ek/tools/oocd.sh b/nuttx/configs/lm3s6965-ek/tools/oocd.sh index 28bcc48a7..758d11450 100755 --- a/nuttx/configs/lm3s6965-ek/tools/oocd.sh +++ b/nuttx/configs/lm3s6965-ek/tools/oocd.sh @@ -22,7 +22,7 @@ TARGET_PATH="/usr/share/openocd/scripts" # like environment #OPENOCD_EXE=openocd.exe OPENOCD_EXE=openocd -OPENOCD_CFG="${TOPDIR}/configs/lm3s6965-ek/tools/ek-lm3s6965.cfg" +OPENOCD_CFG="${TOPDIR}/configs/lm3s6965-ek/tools/lm3s6965-ek.cfg" OPENOCD_ARGS="-f ${OPENOCD_CFG} -s ${TARGET_PATH}" if [ "X$2" = "X-d" ]; then diff --git a/nuttx/include/nuttx/net/net.h b/nuttx/include/nuttx/net/net.h index b79dda755..b625b2fbe 100644 --- a/nuttx/include/nuttx/net/net.h +++ b/nuttx/include/nuttx/net/net.h @@ -117,110 +117,115 @@ struct uip_driver_s; /* Forward reference. See nuttx/net/uip/uip-arch.h */ typedef int (*netdev_callback_t)(FAR struct uip_driver_s *dev, void *arg); /**************************************************************************** - * Public Function Prototypes + * Public Data ****************************************************************************/ #ifdef __cplusplus #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + /* net_checksd.c *************************************************************/ /* Check if the socket descriptor is valid for the provided TCB and if it * supports the requested access. */ -EXTERN int net_checksd(int fd, int oflags); +int net_checksd(int fd, int oflags); /* net_sockets.c *************************************************************/ /* There interfaces are called only from OS scheduling and iniialization logic * under sched/ */ -EXTERN void weak_function net_initialize(void); -EXTERN FAR struct socketlist *net_alloclist(void); -EXTERN int net_addreflist(FAR struct socketlist *list); -EXTERN int net_releaselist(FAR struct socketlist *list); +void weak_function net_initialize(void); +FAR struct socketlist *net_alloclist(void); +int net_addreflist(FAR struct socketlist *list); +int net_releaselist(FAR struct socketlist *list); /* Given a socket descriptor, return the underly NuttX-specific socket * structure. */ -EXTERN FAR struct socket *sockfd_socket(int sockfd); +FAR struct socket *sockfd_socket(int sockfd); /* socket.c ******************************************************************/ /* socket using underlying socket structure */ -EXTERN int psock_socket(int domain, int type, int protocol, - FAR struct socket *psock); +int psock_socket(int domain, int type, int protocol, FAR struct socket *psock); /* net_close.c ***************************************************************/ /* The standard close() operation redirects operations on socket descriptors * to this function. */ -EXTERN int net_close(int sockfd); +int net_close(int sockfd); /* Performs the close operation on a socket instance */ -EXTERN int psock_close(FAR struct socket *psock); +int psock_close(FAR struct socket *psock); /* net_close.c ***************************************************************/ /* Performs the bind() operation on a socket instance */ -EXTERN int psock_bind(FAR struct socket *psock, - FAR const struct sockaddr *addr, socklen_t addrlen); +int psock_bind(FAR struct socket *psock, FAR const struct sockaddr *addr, + socklen_t addrlen); /* connect.c *****************************************************************/ /* Performs the connect() operation on a socket instance */ -EXTERN int psock_connect(FAR struct socket *psock, - FAR const struct sockaddr *addr, socklen_t addrlen); +int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr, + socklen_t addrlen); /* send.c ********************************************************************/ /* Send using underlying socket structure */ -EXTERN ssize_t psock_send(FAR struct socket *psock, const void *buf, - size_t len, int flags); +ssize_t psock_send(FAR struct socket *psock, const void *buf, size_t len, + int flags); /* sendto.c ******************************************************************/ /* Sendto using underlying socket structure */ -EXTERN ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf, - size_t len, int flags, FAR const struct sockaddr *to, - socklen_t tolen); +ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf, + size_t len, int flags, FAR const struct sockaddr *to, + socklen_t tolen); /* recvfrom.c ****************************************************************/ /* recvfrom using the underlying socket structure */ -EXTERN ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, - size_t len, int flags,FAR struct sockaddr *from, - FAR socklen_t *fromlen); +ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, + int flags,FAR struct sockaddr *from, + FAR socklen_t *fromlen); /* recv using the underlying socket structure */ -#define psock_recv(psock,buf,len,flags) psock_recvfrom(psock,buf,len,flags,NULL,0) +#define psock_recv(psock,buf,len,flags) \ + psock_recvfrom(psock,buf,len,flags,NULL,0) /* getsockopt.c **************************************************************/ /* getsockopt using the underlying socket structure */ -EXTERN int psock_getsockopt(FAR struct socket *psock, int level, int option, - FAR void *value, FAR socklen_t *value_len); +int psock_getsockopt(FAR struct socket *psock, int level, int option, + FAR void *value, FAR socklen_t *value_len); /* setsockopt.c **************************************************************/ /* setsockopt using the underlying socket structure */ -EXTERN int psock_setsockopt(FAR struct socket *psock, int level, int option, - FAR const void *value, socklen_t value_len); +int psock_setsockopt(FAR struct socket *psock, int level, int option, + FAR const void *value, socklen_t value_len); /* net_ioctl.c ***************************************************************/ /* The standard ioctl() operation redirects operations on socket descriptors * to this function. */ -EXTERN int netdev_ioctl(int sockfd, int cmd, unsigned long arg); +int netdev_ioctl(int sockfd, int cmd, unsigned long arg); /* net_poll.c ****************************************************************/ /* The standard poll() operation redirects operations on socket descriptors @@ -229,7 +234,9 @@ EXTERN int netdev_ioctl(int sockfd, int cmd, unsigned long arg); #ifndef CONFIG_DISABLE_POLL struct pollfd; /* Forward reference -- see poll.h */ -EXTERN int net_poll(int sockfd, struct pollfd *fds, bool setup); + +int psock_poll(FAR struct socket *psock, struct pollfd *fds, bool setup); +int net_poll(int sockfd, struct pollfd *fds, bool setup); #endif /* net_dup.c *****************************************************************/ @@ -237,7 +244,7 @@ EXTERN int net_poll(int sockfd, struct pollfd *fds, bool setup); * this function */ -EXTERN int net_dup(int sockfd, int minsd); +int net_dup(int sockfd, int minsd); /* net_dup2.c ****************************************************************/ /* The standard dup2() operation redirects operations on socket descriptors to @@ -245,7 +252,7 @@ EXTERN int net_dup(int sockfd, int minsd); */ #if CONFIG_NFILE_DESCRIPTORS > 0 -EXTERN int net_dup2(int sockfd1, int sockfd2); +int net_dup2(int sockfd1, int sockfd2); #else # define net_dup2(sockfd1, sockfd2) dup2(sockfd1, sockfd2) #endif @@ -253,12 +260,12 @@ EXTERN int net_dup2(int sockfd1, int sockfd2); /* net_clone.c ***************************************************************/ /* Performs the low level, common portion of net_dup() and net_dup2() */ -EXTERN int net_clone(FAR struct socket *psock1, FAR struct socket *psock2); +int net_clone(FAR struct socket *psock1, FAR struct socket *psock2); /* net_vfcntl.c **************************************************************/ /* Performs fcntl operations on socket */ -EXTERN int net_vfcntl(int sockfd, int cmd, va_list ap); +int net_vfcntl(int sockfd, int cmd, va_list ap); /* netdev-register.c *********************************************************/ /* This function is called by network interface device drivers to inform the @@ -267,23 +274,23 @@ EXTERN int net_vfcntl(int sockfd, int cmd, va_list ap); * addresses */ -EXTERN int netdev_register(FAR struct uip_driver_s *dev); +int netdev_register(FAR struct uip_driver_s *dev); /* netdev-unregister.c *********************************************************/ /* Unregister a network device driver. */ -EXTERN int netdev_unregister(FAR struct uip_driver_s *dev); +int netdev_unregister(FAR struct uip_driver_s *dev); /* net_foreach.c ************************************************************/ /* Enumerates all registered network devices */ -EXTERN int netdev_foreach(netdev_callback_t callback, void *arg); +int netdev_foreach(netdev_callback_t callback, void *arg); /* drivers/net/slip.c ******************************************************/ /* Instantiate a SLIP network interface. */ #ifdef CONFIG_NET_SLIP -EXTERN int slip_initialize(int intf, const char *devname); +int slip_initialize(int intf, const char *devname); #endif #undef EXTERN diff --git a/nuttx/libc/stdio/lib_libfread.c b/nuttx/libc/stdio/lib_libfread.c index 3e851bf17..f8cf0f40a 100644 --- a/nuttx/libc/stdio/lib_libfread.c +++ b/nuttx/libc/stdio/lib_libfread.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_libfread.c * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -88,7 +88,9 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) { unsigned char *dest = (unsigned char*)ptr; ssize_t bytes_read; +#if CONFIG_STDIO_BUFFER_SIZE > 0 int ret; +#endif /* Make sure that reading from this stream is allowed */ diff --git a/nuttx/net/send.c b/nuttx/net/send.c index 79dfef4ec..b26a0e5bb 100644 --- a/nuttx/net/send.c +++ b/nuttx/net/send.c @@ -448,7 +448,7 @@ end_wait: * equivalent to sendto(sockfd,buf,len,flags,NULL,0). * * Parameters: - * psock And instance of the internal socket structure. + * psock An instance of the internal socket structure. * buf Data to send * len Length of data to send * flags Send flags diff --git a/nuttx/sched/mq_sndinternal.c b/nuttx/sched/mq_sndinternal.c index 51f898875..f16f7de1a 100644 --- a/nuttx/sched/mq_sndinternal.c +++ b/nuttx/sched/mq_sndinternal.c @@ -124,7 +124,7 @@ int mq_verifysend(mqd_t mqdes, const void *msg, size_t msglen, int prio) return ERROR; } - if (msglen < 0 || msglen > (size_t)mqdes->msgq->maxmsgsize) + if (msglen > (size_t)mqdes->msgq->maxmsgsize) { set_errno(EMSGSIZE); return ERROR; -- cgit v1.2.3 From 91504abf89988b25322cd04f416c44bfbfbc86c2 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 24 Jan 2013 18:41:46 +0000 Subject: Add psock_poll(); Fix some warnings reported by Lorenz Meier; lm4f logic from JP git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5558 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/include/lm/chip.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nuttx/arch/arm/include/lm/chip.h b/nuttx/arch/arm/include/lm/chip.h index 6214a50d0..6761e029e 100644 --- a/nuttx/arch/arm/include/lm/chip.h +++ b/nuttx/arch/arm/include/lm/chip.h @@ -2,8 +2,8 @@ * arch/arm/include/lm/chip.h * * Copyright (C) 2009-2010, 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * Author: Jose Pablo Carballo + * Authors: Gregory Nutt + * Jose Pablo Carballo * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions -- cgit v1.2.3 From 25e9b8d0846b68a18014c63146234193bfe539e8 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 24 Jan 2013 19:19:38 +0000 Subject: Fix poll/select issue reported by Qiang git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5559 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 5 +- nuttx/TODO | 19 +-- nuttx/arch/8051/src/up_reprioritizertr.c | 13 +- nuttx/arch/arm/src/armv7-m/up_reprioritizertr.c | 13 +- nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h | 85 +++++++++++++ nuttx/arch/avr/src/avr/up_reprioritizertr.c | 13 +- nuttx/arch/avr/src/avr32/up_reprioritizertr.c | 13 +- nuttx/arch/hc/src/common/up_reprioritizertr.c | 2 +- nuttx/arch/mips/src/mips32/up_reprioritizertr.c | 13 +- nuttx/arch/sh/src/common/up_reprioritizertr.c | 13 +- nuttx/arch/sim/src/up_reprioritizertr.c | 6 +- nuttx/arch/x86/src/common/up_reprioritizertr.c | 2 +- nuttx/arch/z16/src/common/up_reprioritizertr.c | 13 +- nuttx/arch/z80/src/common/up_reprioritizertr.c | 13 +- nuttx/net/net_poll.c | 156 +++++++++++++++++------- 15 files changed, 279 insertions(+), 100 deletions(-) create mode 100644 nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index ffd1b66ae..2eaa03b21 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4021,4 +4021,7 @@ * configs/olimex-lpc1766stk/nettest: Configuration converted to use the kconfig-frontends tools. * net/net_poll.c: Split net_poll() to create psock_poll() too. - + * net/net_poll.c: Fix poll/select issure reported by Qiang: + poll_interrupt() must cat call net_lostconnection() when a + loss of connection is reported. Otherwise, the system will + not know that the connection has been lost. diff --git a/nuttx/TODO b/nuttx/TODO index c302760ab..ed91515ba 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated January 23, 2013) +NuttX TODO List (Last updated January 24, 2013) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -12,7 +12,7 @@ nuttx/ (2) pthreads (sched/) (2) C++ Support (6) Binary loaders (binfmt/) - (17) Network (net/, drivers/net) + (16) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) (12) Libraries (libc/, ) (9) File system/Generic drivers (fs/, drivers/) @@ -667,21 +667,6 @@ o Network (net/, drivers/net) Status: Open Priority: Low... fix defconfig files as necessary. - Title: net_poll() DOES NOT HANDLE LOSS-OF-CONNECTION CORRECTLY - Description: When a loss of connection is detected by any logic waiting on the - networking events, the function net_lostconnection() must be called. - That function just sets some bits in the socket structure so that - it remembers that the connection is lost. - - That is currently done in recvfrom(), send(), and net_monitor.c. But - it is not done in the net_poll() logic; that logic correctly sets - the POLLHUP status, but it does not call net_lostconnection(). As a - result, if recv() is called after the poll() or select(), the system - will hang because the recv() does not know that the connection has - been lost. - Status: Open - Priority: High - o USB (drivers/usbdev, drivers/usbhost) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/nuttx/arch/8051/src/up_reprioritizertr.c b/nuttx/arch/8051/src/up_reprioritizertr.c index 6d4a72487..0d1941f66 100644 --- a/nuttx/arch/8051/src/up_reprioritizertr.c +++ b/nuttx/arch/8051/src/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * up_reprioritizertr.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -90,9 +90,14 @@ void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority) /* Verify that the caller is sane */ if (tcb->task_state < FIRST_READY_TO_RUN_STATE || - tcb->task_state > LAST_READY_TO_RUN_STATE || - priority < SCHED_PRIORITY_MIN || - priority > SCHED_PRIORITY_MAX) + tcb->task_state > LAST_READY_TO_RUN_STATE +#if SCHED_PRIORITY_MIN > 0 + || priority < SCHED_PRIORITY_MIN +#endif +#if SCHED_PRIORITY_MAX < UINT8_MAX + || priority > SCHED_PRIORITY_MAX +#endif + ) { PANIC(OSERR_BADREPRIORITIZESTATE); } diff --git a/nuttx/arch/arm/src/armv7-m/up_reprioritizertr.c b/nuttx/arch/arm/src/armv7-m/up_reprioritizertr.c index f1c961b15..9a971f064 100644 --- a/nuttx/arch/arm/src/armv7-m/up_reprioritizertr.c +++ b/nuttx/arch/arm/src/armv7-m/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/armv7-m/up_reprioritizertr.c * - * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -89,9 +89,14 @@ 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 || - priority < SCHED_PRIORITY_MIN || - priority > SCHED_PRIORITY_MAX) + tcb->task_state > LAST_READY_TO_RUN_STATE +#if SCHED_PRIORITY_MIN > 0 + || priority < SCHED_PRIORITY_MIN +#endif +#if SCHED_PRIORITY_MAX < UINT8_MAX + || priority > SCHED_PRIORITY_MAX +#endif + ) { PANIC(OSERR_BADREPRIORITIZESTATE); } diff --git a/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h b/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h new file mode 100644 index 000000000..6963545fe --- /dev/null +++ b/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h @@ -0,0 +1,85 @@ +/************************************************************************************ + * arch/arm/src/lm/chip/lm3s_memorymap.h + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * Jose Pablo Carballo + * + * 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_ARM_SRC_LM_CHIP_LM4F_MEMORYMAP_H +#define __ARCH_ARM_SRC_LM_CHIP_LM4F_MEMORYMAP_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/* Memory map ***********************************************************************/ + +#if defined(CONFIG_ARCH_CHIP_LM4F120) +# define LM_FLASH_BASE 0x00000000 /* -0x0003ffff: On-chip FLASH */ + /* -0x00ffffff: Reserved */ +# define LM_ROM_BASE 0x01000000 /* -0x1fffffff: Reserved for ROM */ +# define LM_SRAM_BASE 0x20000000 /* -0x20007fff: Bit-banded on-chip SRAM */ + /* -0x21ffffff: Reserved */ +/* @TODO */ +#endif + +#else +# error "Memory map not specified for this LM4F chip" +#endif + +/* Peripheral base addresses ********************************************************/ + +#if defined(CONFIG_ARCH_CHIP_LM4F120) +/* @TODO */ +#else +# error "Peripheral base addresses not specified for this Stellaris chip" +#endif + +/************************************************************************************ + * Public Types + ************************************************************************************/ + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +/************************************************************************************ + * Public Function Prototypes + ************************************************************************************/ + +#endif /* __ARCH_ARM_SRC_LM_CHIP_LM4F_MEMORYMAP_H */ diff --git a/nuttx/arch/avr/src/avr/up_reprioritizertr.c b/nuttx/arch/avr/src/avr/up_reprioritizertr.c index 14033a3bd..af329c13f 100644 --- a/nuttx/arch/avr/src/avr/up_reprioritizertr.c +++ b/nuttx/arch/avr/src/avr/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/avr/src/avr/up_reprioritizertr.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -89,9 +89,14 @@ 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 || - priority < SCHED_PRIORITY_MIN || - priority > SCHED_PRIORITY_MAX) + tcb->task_state > LAST_READY_TO_RUN_STATE +#if SCHED_PRIORITY_MIN > 0 + || priority < SCHED_PRIORITY_MIN +#endif +#if SCHED_PRIORITY_MAX < UINT8_MAX + || priority > SCHED_PRIORITY_MAX +#endif + ) { PANIC(OSERR_BADREPRIORITIZESTATE); } diff --git a/nuttx/arch/avr/src/avr32/up_reprioritizertr.c b/nuttx/arch/avr/src/avr32/up_reprioritizertr.c index e1712fed0..0aad214e8 100644 --- a/nuttx/arch/avr/src/avr32/up_reprioritizertr.c +++ b/nuttx/arch/avr/src/avr32/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/avr/src/avr32/up_reprioritizertr.c * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -89,9 +89,14 @@ 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 || - priority < SCHED_PRIORITY_MIN || - priority > SCHED_PRIORITY_MAX) + tcb->task_state > LAST_READY_TO_RUN_STATE +#if SCHED_PRIORITY_MIN > 0 + || priority < SCHED_PRIORITY_MIN +#endif +#if SCHED_PRIORITY_MAX < UINT8_MAX + || priority > SCHED_PRIORITY_MAX +#endif + ) { PANIC(OSERR_BADREPRIORITIZESTATE); } diff --git a/nuttx/arch/hc/src/common/up_reprioritizertr.c b/nuttx/arch/hc/src/common/up_reprioritizertr.c index ffd90bf1f..31c76a9f5 100644 --- a/nuttx/arch/hc/src/common/up_reprioritizertr.c +++ b/nuttx/arch/hc/src/common/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/hc/src/common/up_reprioritizertr.c * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/arch/mips/src/mips32/up_reprioritizertr.c b/nuttx/arch/mips/src/mips32/up_reprioritizertr.c index 66ce687e0..2e5f41d68 100644 --- a/nuttx/arch/mips/src/mips32/up_reprioritizertr.c +++ b/nuttx/arch/mips/src/mips32/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/mips/src/mips32/up_reprioritizertr.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -91,9 +91,14 @@ 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 || - priority < SCHED_PRIORITY_MIN || - priority > SCHED_PRIORITY_MAX) + tcb->task_state > LAST_READY_TO_RUN_STATE +#if SCHED_PRIORITY_MIN > 0 + || priority < SCHED_PRIORITY_MIN +#endif +#if SCHED_PRIORITY_MAX < UINT8_MAX + || priority > SCHED_PRIORITY_MAX +#endif + ) { PANIC(OSERR_BADREPRIORITIZESTATE); } diff --git a/nuttx/arch/sh/src/common/up_reprioritizertr.c b/nuttx/arch/sh/src/common/up_reprioritizertr.c index 728cafdf3..99d350b29 100644 --- a/nuttx/arch/sh/src/common/up_reprioritizertr.c +++ b/nuttx/arch/sh/src/common/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/sh/src/common/up_reprioritizertr.c * - * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -89,9 +89,14 @@ 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 || - priority < SCHED_PRIORITY_MIN || - priority > SCHED_PRIORITY_MAX) + tcb->task_state > LAST_READY_TO_RUN_STATE +#if SCHED_PRIORITY_MIN > 0 + || priority < SCHED_PRIORITY_MIN +#endif +#if SCHED_PRIORITY_MAX < UINT8_MAX + || priority > SCHED_PRIORITY_MAX +#endif + ) { PANIC(OSERR_BADREPRIORITIZESTATE); } diff --git a/nuttx/arch/sim/src/up_reprioritizertr.c b/nuttx/arch/sim/src/up_reprioritizertr.c index 913d8d5f5..15c1b26d5 100644 --- a/nuttx/arch/sim/src/up_reprioritizertr.c +++ b/nuttx/arch/sim/src/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * up_reprioritizertr.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -91,13 +91,13 @@ void up_reprioritize_rtr(_TCB *tcb, uint8_t priority) if (tcb->task_state < FIRST_READY_TO_RUN_STATE || tcb->task_state > LAST_READY_TO_RUN_STATE -#if SCHED_PRIORITY_MIN > UINT8_MIN +#if SCHED_PRIORITY_MIN > 0 || priority < SCHED_PRIORITY_MIN #endif #if SCHED_PRIORITY_MAX < UINT8_MAX || priority > SCHED_PRIORITY_MAX #endif - ) + ) { PANIC(OSERR_BADREPRIORITIZESTATE); } diff --git a/nuttx/arch/x86/src/common/up_reprioritizertr.c b/nuttx/arch/x86/src/common/up_reprioritizertr.c index ad8a748a8..53a0e4315 100644 --- a/nuttx/arch/x86/src/common/up_reprioritizertr.c +++ b/nuttx/arch/x86/src/common/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/arm/up_reprioritizertr.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/arch/z16/src/common/up_reprioritizertr.c b/nuttx/arch/z16/src/common/up_reprioritizertr.c index 0363184cd..6e76d6ce1 100644 --- a/nuttx/arch/z16/src/common/up_reprioritizertr.c +++ b/nuttx/arch/z16/src/common/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * common/up_reprioritizertr.c * - * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -91,9 +91,14 @@ void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority) /* Verify that the caller is sane */ if (tcb->task_state < FIRST_READY_TO_RUN_STATE || - tcb->task_state > LAST_READY_TO_RUN_STATE || - priority < SCHED_PRIORITY_MIN || - priority > SCHED_PRIORITY_MAX) + tcb->task_state > LAST_READY_TO_RUN_STATE +#if SCHED_PRIORITY_MIN > 0 + || priority < SCHED_PRIORITY_MIN +#endif +#if SCHED_PRIORITY_MAX < UINT8_MAX + || priority > SCHED_PRIORITY_MAX +#endif + ) { PANIC(OSERR_BADREPRIORITIZESTATE); } diff --git a/nuttx/arch/z80/src/common/up_reprioritizertr.c b/nuttx/arch/z80/src/common/up_reprioritizertr.c index 84cd3e1e1..b8102c99f 100644 --- a/nuttx/arch/z80/src/common/up_reprioritizertr.c +++ b/nuttx/arch/z80/src/common/up_reprioritizertr.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/common/up_reprioritizertr.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -92,9 +92,14 @@ void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority) /* Verify that the caller is sane */ if (tcb->task_state < FIRST_READY_TO_RUN_STATE || - tcb->task_state > LAST_READY_TO_RUN_STATE || - priority < SCHED_PRIORITY_MIN || - priority > SCHED_PRIORITY_MAX) + tcb->task_state > LAST_READY_TO_RUN_STATE +#if SCHED_PRIORITY_MIN > 0 + || priority < SCHED_PRIORITY_MIN +#endif +#if SCHED_PRIORITY_MAX < UINT8_MAX + || priority > SCHED_PRIORITY_MAX +#endif + ) { PANIC(OSERR_BADREPRIORITIZESTATE); } diff --git a/nuttx/net/net_poll.c b/nuttx/net/net_poll.c index 2e73bd73c..ea6f54a6b 100644 --- a/nuttx/net/net_poll.c +++ b/nuttx/net/net_poll.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/net_poll.c * - * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,11 +46,13 @@ #include #include #include +#include #include +#include +#include #include #include -#include #include @@ -75,6 +77,14 @@ /**************************************************************************** * Private Types ****************************************************************************/ +/* This is an allocated container that holds the poll-related information */ + +struct net_poll_s +{ + FAR struct socket *psock; /* Needed to handle loss of connection */ + struct pollfd *fds; /* Needed to handle poll events */ + FAR struct uip_callback_s *cb; /* Needed to teardown the poll */ +}; /**************************************************************************** * Private Functions @@ -101,16 +111,18 @@ ****************************************************************************/ #ifdef HAVE_NETPOLL -static uint16_t poll_interrupt(struct uip_driver_s *dev, FAR void *conn, +static uint16_t poll_interrupt(FAR struct uip_driver_s *dev, FAR void *conn, FAR void *pvpriv, uint16_t flags) { - FAR struct pollfd *fds = (FAR struct pollfd *)pvpriv; + FAR struct net_poll_s *info = (FAR struct net_poll_s *)pvpriv; nllvdbg("flags: %04x\n", flags); + DEBUGASSERT(info && info->psock && info->fds); + /* 'priv' might be null in some race conditions (?) */ - if (fds) + if (info->fds) { pollevent_t eventset = 0; @@ -118,24 +130,23 @@ static uint16_t poll_interrupt(struct uip_driver_s *dev, FAR void *conn, if ((flags & (UIP_NEWDATA|UIP_BACKLOG)) != 0) { - eventset |= POLLIN & fds->events; + eventset |= POLLIN & info->fds->events; } /* A poll is a sign that we are free to send data. */ if ((flags & UIP_POLL) != 0) { - eventset |= (POLLOUT & fds->events); + eventset |= (POLLOUT & info->fds->events); } - /* Check for a loss of connection events. - * - * REVISIT: Need to call net_lostconnection() here, but don't have - * the psock instance. What should we do? - */ + /* Check for a loss of connection events. */ if ((flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) { + /* Make the the connection has been lost */ + + net_lostconnection(info->psock, flags); eventset |= (POLLERR | POLLHUP); } @@ -143,8 +154,8 @@ static uint16_t poll_interrupt(struct uip_driver_s *dev, FAR void *conn, if (eventset) { - fds->revents |= eventset; - sem_post(fds->sem); + info->fds->revents |= eventset; + sem_post(info->fds->sem); } } @@ -169,9 +180,11 @@ static uint16_t poll_interrupt(struct uip_driver_s *dev, FAR void *conn, ****************************************************************************/ #ifdef HAVE_NETPOLL -static inline int net_pollsetup(FAR struct socket *psock, struct pollfd *fds) +static inline int net_pollsetup(FAR struct socket *psock, + FAR struct pollfd *fds) { FAR struct uip_conn *conn = psock->s_conn; + FAR struct net_poll_s *info; FAR struct uip_callback_s *cb; uip_lock_t flags; int ret; @@ -185,6 +198,14 @@ static inline int net_pollsetup(FAR struct socket *psock, struct pollfd *fds) } #endif + /* Allocate a container to hold the poll information */ + + info = (FAR struct net_poll_s *)kmalloc(sizeof(struct net_poll_s)); + if (!info) + { + return -ENOMEM; + } + /* Some of the following must be atomic */ flags = uip_lock(); @@ -195,18 +216,29 @@ static inline int net_pollsetup(FAR struct socket *psock, struct pollfd *fds) if (!cb) { ret = -EBUSY; - goto errout_with_irq; + goto errout_with_lock; } - /* Initialize the callback structure */ + /* Initialize the poll info container */ + + info->psock = psock; + info->fds = fds; + info->cb = cb; + + /* Initialize the callback structure. Save the reference to the info + * structure as callback private data so that it will be available during + * callback processing. + */ cb->flags = (UIP_NEWDATA|UIP_BACKLOG|UIP_POLL|UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT); - cb->priv = (FAR void *)fds; + cb->priv = (FAR void *)info; cb->event = poll_interrupt; - /* Save the nps reference in the poll structure for use at teardown as well */ + /* Save the reference in the poll info structure as fds private as well + * for use durring poll teardown as well. + */ - fds->priv = (FAR void *)cb; + fds->priv = (FAR void *)info; #ifdef CONFIG_NET_TCPBACKLOG /* Check for read data or backlogged connection availability now */ @@ -240,7 +272,8 @@ static inline int net_pollsetup(FAR struct socket *psock, struct pollfd *fds) uip_unlock(flags); return OK; -errout_with_irq: +errout_with_lock: + kfree(info); uip_unlock(flags); return ret; } @@ -261,10 +294,11 @@ errout_with_irq: ****************************************************************************/ #ifdef HAVE_NETPOLL -static inline int net_pollteardown(FAR struct socket *psock, struct pollfd *fds) +static inline int net_pollteardown(FAR struct socket *psock, + FAR struct pollfd *fds) { FAR struct uip_conn *conn = psock->s_conn; - FAR struct uip_callback_s *cb; + FAR struct net_poll_s *info; uip_lock_t flags; /* Sanity check */ @@ -278,18 +312,23 @@ static inline int net_pollteardown(FAR struct socket *psock, struct pollfd *fds) /* Recover the socket descriptor poll state info from the poll structure */ - cb = (FAR struct uip_callback_s *)fds->priv; - if (cb) + info = (FAR struct net_poll_s *)fds->priv; + DEBUGASSERT(info && info->fds && info->cb); + if (info) { /* Release the callback */ flags = uip_lock(); - uip_tcpcallbackfree(conn, cb); + uip_tcpcallbackfree(conn, info->cb); uip_unlock(flags); /* Release the poll/select data slot */ - fds->priv = NULL; + info->fds->priv = NULL; + + /* Then free the poll info container */ + + kfree(info); } return OK; @@ -308,7 +347,7 @@ static inline int net_pollteardown(FAR struct socket *psock, struct pollfd *fds) * to this function. * * Input Parameters: - * fd - The socket descriptor of interest + * psock - An instance of the internal socket structure. * fds - The structure describing the events to be monitored, OR NULL if * this is a request to stop monitoring events. * setup - true: Setup up the poll; false: Teardown the poll @@ -318,26 +357,11 @@ static inline int net_pollteardown(FAR struct socket *psock, struct pollfd *fds) * ****************************************************************************/ -#ifndef CONFIG_DISABLE_POLL -int net_poll(int sockfd, struct pollfd *fds, bool setup) +#if !defined(CONFIG_DISABLE_POLL) && defined(HAVE_NETPOLL) +int psock_poll(FAR struct socket *psock, FAR struct pollfd *fds, bool setup) { -#ifndef HAVE_NETPOLL - return -ENOSYS; -#else - FAR struct socket *psock; int ret; - /* Get the underlying socket structure and verify that the sockfd - * corresponds to valid, allocated socket - */ - - psock = sockfd_socket(sockfd); - if (!psock || psock->s_crefs <= 0) - { - ret = -EBADF; - goto errout; - } - #ifdef CONFIG_NET_UDP /* poll() not supported for UDP */ @@ -365,6 +389,48 @@ int net_poll(int sockfd, struct pollfd *fds, bool setup) errout: return ret; +} +#endif + +/**************************************************************************** + * Function: net_poll + * + * Description: + * The standard poll() operation redirects operations on socket descriptors + * to this function. + * + * Input Parameters: + * fd - The socket descriptor of interest + * fds - The structure describing the events to be monitored, OR NULL if + * this is a request to stop monitoring events. + * setup - true: Setup up the poll; false: Teardown the poll + * + * Returned Value: + * 0: Success; Negated errno on failure + * + ****************************************************************************/ + +#ifndef CONFIG_DISABLE_POLL +int net_poll(int sockfd, struct pollfd *fds, bool setup) +{ +#ifndef HAVE_NETPOLL + return -ENOSYS; +#else + FAR struct socket *psock; + + /* Get the underlying socket structure and verify that the sockfd + * corresponds to valid, allocated socket + */ + + psock = sockfd_socket(sockfd); + if (!psock || psock->s_crefs <= 0) + { + return -EBADF; + } + + /* Then let psock_poll() do the heavy lifting */ + + return psock_poll(psock, fds, setup); #endif /* HAVE_NETPOLL */ } #endif /* !CONFIG_DISABLE_POLL */ -- cgit v1.2.3 From a2ec48846f786e72a976038c9467b25a61ad5a9f Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 24 Jan 2013 23:18:32 +0000 Subject: Fix some missing logic and inconsistencies in child status logic; Fix a bug introduced into sigaction() git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5560 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/ostest/ostest_main.c | 28 ++++++++ nuttx/TODO | 15 +++- nuttx/net/net_poll.c | 4 +- nuttx/sched/Kconfig | 7 ++ nuttx/sched/os_internal.h | 1 + nuttx/sched/sched_waitid.c | 136 +++++++++++++++++++++++++++---------- nuttx/sched/sched_waitpid.c | 132 ++++++++++++++++++++++------------- nuttx/sched/sig_action.c | 22 +++--- nuttx/sched/task_childstatus.c | 36 ++++++++++ nuttx/sched/task_reparent.c | 24 ++++++- nuttx/sched/task_setup.c | 23 ++++--- 11 files changed, 322 insertions(+), 106 deletions(-) diff --git a/apps/examples/ostest/ostest_main.c b/apps/examples/ostest/ostest_main.c index aab1ff045..3e4197fdc 100644 --- a/apps/examples/ostest/ostest_main.c +++ b/apps/examples/ostest/ostest_main.c @@ -43,8 +43,11 @@ #include #include #include +#include #include #include +#include + #include #include "ostest.h" @@ -264,6 +267,31 @@ static int user_main(int argc, char *argv[]) } check_test_memory_usage(); + /* If retention of child status is enable, then suppress it for this task. + * This task may produce many, many children (especially if + * CONFIG_EXAMPLES_OSTEST_LOOPS) and it does not harvest their exit status. + * As a result, the test may fail inappropriately unless retention of + * child exit status is disabled. + * + * So basically, this tests that child status can be disabled, but cannot + * verify that status is retained correctly. + */ + +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) + { + struct sigaction sa; + int ret; + + sa.sa_handler = SIG_IGN; + sa.sa_flags = SA_NOCLDWAIT; + ret = sigaction(SIGCHLD, &sa, NULL); + if (ret < 0) + { + printf("user_main: ERROR: sigaction failed: %d\n", errno); + } + } +#endif + /* Check environment variables */ #ifndef CONFIG_DISABLE_ENVIRON show_environment(true, true, true); diff --git a/nuttx/TODO b/nuttx/TODO index ed91515ba..d6bd18d12 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -7,7 +7,7 @@ standards, things that could be improved, and ideas for enhancements. nuttx/ (11) Task/Scheduler (sched/) - (1) Memory Managment (mm/) + (2) Memory Managment (mm/) (3) Signals (sched/, arch/) (2) pthreads (sched/) (2) C++ Support @@ -278,6 +278,19 @@ o Memory Managment (mm/) Priority: Medium/Low, a good feature to prevent memory leaks but would have negative impact on memory usage and code size. + Title: CONTAINER ALLOCATOR + Description: There are several places where the logic requires allocation of + a tiny structure that just contains pointers to other things or + small amounts of data that needs to be bundled together. There + are examples net/net_poll.c and numerous other places. + + I am wondering if it would not be good create a pool of generic + containers (say void *[4]). There re-use these when we need + small containers. The code in sched/task_childstatus.c might + be generalized for this purpose. + Status: Open + Priority: Very low (I am not even sure that this is a good idea yet). + o Signals (sched/, arch/) ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/nuttx/net/net_poll.c b/nuttx/net/net_poll.c index ea6f54a6b..3021ac35e 100644 --- a/nuttx/net/net_poll.c +++ b/nuttx/net/net_poll.c @@ -367,8 +367,7 @@ int psock_poll(FAR struct socket *psock, FAR struct pollfd *fds, bool setup) if (psock->s_type != SOCK_STREAM) { - ret = -ENOSYS; - goto errout; + return -ENOSYS; } #endif @@ -387,7 +386,6 @@ int psock_poll(FAR struct socket *psock, FAR struct pollfd *fds, bool setup) ret = net_pollteardown(psock, fds); } -errout: return ret; } #endif diff --git a/nuttx/sched/Kconfig b/nuttx/sched/Kconfig index 7ea301600..7745c2c25 100644 --- a/nuttx/sched/Kconfig +++ b/nuttx/sched/Kconfig @@ -124,6 +124,13 @@ config PREALLOC_CHILDSTATUS sa.sa_flags = SA_NOCLDWAIT; int ret = sigaction(SIGCHLD, &sa, NULL); +config DEBUG_CHILDSTATUS + bool "Enable Child Status Debug Output" + default n + depends on SCHED_CHILD_STATUS && DEBUG + ---help--- + Very detailed... I am sure that you do not want this. + config JULIAN_TIME bool "Enables Julian time conversions" default n diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index 7d5095bad..dc87cb9a4 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -274,6 +274,7 @@ void weak_function task_initialize(void); FAR struct child_status_s *task_allocchild(void); void task_freechild(FAR struct child_status_s *status); void task_addchild(FAR _TCB *tcb, FAR struct child_status_s *child); +FAR struct child_status_s *task_exitchild(FAR _TCB *tcb); FAR struct child_status_s *task_findchild(FAR _TCB *tcb, pid_t pid); FAR struct child_status_s *task_removechild(FAR _TCB *tcb, pid_t pid); void task_removechildren(FAR _TCB *tcb); diff --git a/nuttx/sched/sched_waitid.c b/nuttx/sched/sched_waitid.c index 37ee26ce0..e73bc223c 100644 --- a/nuttx/sched/sched_waitid.c +++ b/nuttx/sched/sched_waitid.c @@ -53,6 +53,36 @@ * Private Functions *****************************************************************************/ +/***************************************************************************** + * Name: exitted_child + * + * Description: + * Handle the case where a child exitted properlay was we (apparently) lost + * the detch of child signal. + * + *****************************************************************************/ + +#ifdef CONFIG_SCHED_CHILD_STATUS +static void exitted_child(FAR _TCB *rtcb, FAR struct child_status_s *child, + FAR siginfo_t *info) +{ + /* The child has exited. Return the saved exit status (and some fudged + * information. + */ + + info->si_signo = SIGCHLD; + info->si_code = CLD_EXITED; + info->si_value.sival_ptr = NULL; + info->si_pid = child->ch_pid; + info->si_status = child->ch_status; + + /* Discard the child entry */ + + (void)task_removechild(rtcb, child->ch_pid); + task_freechild(child); +} +#endif + /***************************************************************************** * Public Functions *****************************************************************************/ @@ -120,9 +150,14 @@ * *****************************************************************************/ -int waitid(idtype_t idtype, id_t id, siginfo_t *info, int options) +int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) { FAR _TCB *rtcb = (FAR _TCB *)g_readytorun.head; + FAR _TCB *ctcb; +#ifdef CONFIG_SCHED_CHILD_STATUS + FAR struct child_status_s *child; + bool retains; +#endif sigset_t sigset; int err; int ret; @@ -160,7 +195,11 @@ int waitid(idtype_t idtype, id_t id, siginfo_t *info, int options) */ #ifdef CONFIG_SCHED_CHILD_STATUS - if (rtcb->children == NULL) + /* Does this task retain child status? */ + + retains = ((rtcb->flags && TCB_FLAG_NOCLDWAIT) == 0); + + if (rtcb->children == NULL && retains) { /* There are no children */ @@ -169,13 +208,29 @@ int waitid(idtype_t idtype, id_t id, siginfo_t *info, int options) } else if (idtype == P_PID) { - if (task_findchild(rtcb, (pid_t)id) == NULL) - { - /* This specific pid is not a child */ + /* Get the TCB corresponding to this PID and make sure it is our child. */ + ctcb = sched_gettcb((pid_t)id); + if (!ctcb || ctcb->parent != rtcb->pid) + { err = ECHILD; goto errout_with_errno; } + + /* Does this task retain child status? */ + + if (retains) + { + /* Check if this specific pid has allocated child status? */ + + if (task_findchild(rtcb, (pid_t)id) == NULL) + { + /* This specific pid is not a child */ + + err = ECHILD; + goto errout_with_errno; + } + } } #else if (rtcb->nchildren == 0) @@ -189,7 +244,7 @@ int waitid(idtype_t idtype, id_t id, siginfo_t *info, int options) { /* Get the TCB corresponding to this PID and make sure it is our child. */ - FAR _TCB *ctcb = sched_gettcb((pid_t)id); + ctcb = sched_gettcb((pid_t)id); if (!ctcb || ctcb->parent != rtcb->pid) { err = ECHILD; @@ -209,48 +264,61 @@ int waitid(idtype_t idtype, id_t id, siginfo_t *info, int options) * instead). */ - DEBUGASSERT(rtcb->children); - if (rtcb->children == NULL) + DEBUGASSERT(!retains || rtcb->children); + if (idtype == P_ALL) { - /* This should not happen. I am just wasting your FLASH. */ + /* We are waiting for any child to exit */ - err = ECHILD; - goto errout_with_errno; + if (retains && (child = task_exitchild(rtcb)) != NULL) + { + /* A child has exitted. Apparently we missed the signal. + * Return the exit status and break out of the loop. + */ + + exitted_child(rtcb, child, info); + break; + } } - else if (idtype == P_PID) - { - FAR struct child_status_s *child; - /* We are waiting for a specific PID. Get the current status - * of the child task. - */ + /* We are waiting for a specific PID. Does this task retain child status? */ + + else if (retains) + { + /* Yes ... Get the current status of the child task. */ child = task_findchild(rtcb, (pid_t)id); DEBUGASSERT(child); - if (!child) - { - /* Yikes! The child status entry just disappeared! */ - - err = ECHILD; - goto errout_with_errno; - } - + /* Did the child exit? */ if ((child->ch_flags & CHILD_FLAG_EXITED) != 0) { - /* The child has exited. Return the saved exit status */ + /* The child has exited. Return the exit status and break out + * of the loop. + */ - info->si_signo = SIGCHLD; - info->si_code = CLD_EXITED; - info->si_value.sival_ptr = NULL; - info->si_pid = (pid_t)id; - info->si_status = child->ch_status; + exitted_child(rtcb, child, info); + break; + } + } + else + { + /* We can use kill() with signal number 0 to determine if that + * task is still alive. + */ - /* Discard the child entry and break out of the loop */ + ret = kill((pid_t)id, 0); + if (ret < 0) + { + /* It is no longer running. We know that the child task + * was running okay when we started, so we must have lost + * the signal. In this case, we know that the task exit'ed, + * but we do not know its exit status. It would be better + * to reported ECHILD than bogus status. + */ - (void)task_removechild(rtcb, (pid_t)id); - task_freechild(child); + err = ECHILD; + goto errout_with_errno; } } #else diff --git a/nuttx/sched/sched_waitpid.c b/nuttx/sched/sched_waitpid.c index fe3f7167d..ecdc60a2c 100644 --- a/nuttx/sched/sched_waitpid.c +++ b/nuttx/sched/sched_waitpid.c @@ -185,7 +185,7 @@ #ifndef CONFIG_SCHED_HAVE_PARENT pid_t waitpid(pid_t pid, int *stat_loc, int options) { - _TCB *tcb; + _TCB *ctcb; bool mystat; int err; int ret; @@ -208,8 +208,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Get the TCB corresponding to this PID */ - tcb = sched_gettcb(pid); - if (!tcb) + ctcb = sched_gettcb(pid); + if (!ctcb) { err = ECHILD; goto errout_with_errno; @@ -221,15 +221,15 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) * others? */ - if (stat_loc != NULL && tcb->stat_loc == NULL) + if (stat_loc != NULL && ctcb->stat_loc == NULL) { - tcb->stat_loc = stat_loc; - mystat = true; + ctcb->stat_loc = stat_loc; + mystat = true; } /* Then wait for the task to exit */ - ret = sem_wait(&tcb->exitsem); + ret = sem_wait(&ctcb->exitsem); if (ret < 0) { /* Unlock pre-emption and return the ERROR (sem_wait has already set @@ -239,7 +239,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) if (mystat) { - tcb->stat_loc = NULL; + ctcb->stat_loc = NULL; } goto errout; @@ -274,8 +274,10 @@ errout: pid_t waitpid(pid_t pid, int *stat_loc, int options) { FAR _TCB *rtcb = (FAR _TCB *)g_readytorun.head; + FAR _TCB *ctcb; #ifdef CONFIG_SCHED_CHILD_STATUS FAR struct child_status_s *child; + bool retains; #endif FAR struct siginfo info; sigset_t sigset; @@ -303,27 +305,43 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) sched_lock(); - /* Verify that this task actually has children and that the the request - * TCB is actually a child of this task. + /* Verify that this task actually has children and that the requested PID + * is actually a child of this task. */ #ifdef CONFIG_SCHED_CHILD_STATUS - if (rtcb->children == NULL) - { - /* There are no children */ + /* Does this task retain child status? */ + retains = ((rtcb->flags && TCB_FLAG_NOCLDWAIT) == 0); + + if (rtcb->children == NULL && retains) + { err = ECHILD; goto errout_with_errno; } else if (pid != (pid_t)-1) { - /* This specific pid is not a child */ + /* Get the TCB corresponding to this PID and make sure it is our child. */ - if (task_findchild(rtcb, pid) == NULL) + ctcb = sched_gettcb(pid); + if (!ctcb || ctcb->parent != rtcb->pid) { err = ECHILD; goto errout_with_errno; } + + /* Does this task retain child status? */ + + if (retains) + { + /* Check if this specific pid has allocated child status? */ + + if (task_findchild(rtcb, pid) == NULL) + { + err = ECHILD; + goto errout_with_errno; + } + } } #else if (rtcb->nchildren == 0) @@ -337,7 +355,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) { /* Get the TCB corresponding to this PID and make sure it is our child. */ - FAR _TCB *ctcb = sched_gettcb(pid); + ctcb = sched_gettcb(pid); if (!ctcb || ctcb->parent != rtcb->pid) { err = ECHILD; @@ -350,6 +368,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) for (;;) { +#ifdef CONFIG_SCHED_CHILD_STATUS /* Check if the task has already died. Signals are not queued in * NuttX. So a possibility is that the child has died and we * missed the death of child signal (we got some other signal @@ -362,39 +381,33 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) * chilren. */ -#ifdef CONFIG_SCHED_CHILD_STATUS - DEBUGASSERT(rtcb->children); - if (rtcb->children == NULL) -#else - if (rtcb->nchildren == 0) -#endif + DEBUGASSERT(!retains || rtcb->children); + if (retains && (child = task_exitchild(rtcb)) != NULL) { - /* There were one or more children when we started so they - * must have exit'ed. There are just no bread crumbs left - * behind to tell us the PID(s) of the existed children. - * Reporting ECHLD is about all we can do in this case. + /* A child has exitted. Apparently we missed the signal. + * Return the saved exit status. */ - err = ECHILD; - goto errout_with_errno; + /* The child has exited. Return the saved exit status */ + + *stat_loc = child->ch_status; + + /* Discard the child entry and break out of the loop */ + + (void)task_removechild(rtcb, child->ch_pid); + task_freechild(child); + break; } } - else + + /* We are waiting for a specific PID. Does this task retain child status? */ + + else if (retains) { -#ifdef CONFIG_SCHED_CHILD_STATUS - /* We are waiting for a specific PID. Get the current status - * of the child task. - */ + /* Get the current status of the child task. */ child = task_findchild(rtcb, pid); DEBUGASSERT(child); - if (!child) - { - /* Yikes! The child status entry just disappeared! */ - - err = ECHILD; - goto errout_with_errno; - } /* Did the child exit? */ @@ -408,27 +421,48 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) (void)task_removechild(rtcb, pid); task_freechild(child); + break; } -#else - /* We are waiting for a specific PID. We can use kill() with - * signal number 0 to determine if that task is still alive. + } + else + { + /* We can use kill() with signal number 0 to determine if that + * task is still alive. */ ret = kill(pid, 0); if (ret < 0) { - /* It is no longer running. We know that the child task was - * running okay when we started, so we must have lost the - * signal. In this case, we know that the task exit'ed, but - * we do not know its exit status. It would be better to - * reported ECHILD that bogus status. + /* It is no longer running. We know that the child task + * was running okay when we started, so we must have lost + * the signal. In this case, we know that the task exit'ed, + * but we do not know its exit status. It would be better + * to reported ECHILD than bogus status. */ err = ECHILD; goto errout_with_errno; } -#endif } +#else + /* Check if the task has already died. Signals are not queued in + * NuttX. So a possibility is that the child has died and we + * missed the death of child signal (we got some other signal + * instead). + */ + + if (rtcb->nchildren == 0 || + (pid != (pid_t)-1 && (ret = kill((pid_t)id, 0)) < 0)) + { + /* We know that the child task was running okay we stared, + * so we must have lost the signal. What can we do? + * Let's claim we were interrupted by a signal. + */ + + err = EINTR; + goto errout_with_errno; + } +#endif /* Wait for any death-of-child signal */ diff --git a/nuttx/sched/sig_action.c b/nuttx/sched/sig_action.c index 708667993..7d84b6291 100644 --- a/nuttx/sched/sig_action.c +++ b/nuttx/sched/sig_action.c @@ -169,7 +169,6 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * { FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; FAR sigactq_t *sigact; - int ret; /* Since sigactions can only be installed from the running thread of * execution, no special precautions should be necessary. @@ -251,24 +250,31 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * if (act->sa_u._sa_handler == SIG_IGN) { - /* If there is a old sigaction, remove it from sigactionq */ + /* Do we still have a sigaction container from the previous setting? */ - sq_rem((FAR sq_entry_t*)sigact, &rtcb->sigactionq); + if (sigact) + { + /* Yes.. Remove it from sigactionq */ + + sq_rem((FAR sq_entry_t*)sigact, &rtcb->sigactionq); - /* And deallocate it */ + /* And deallocate it */ - sig_releaseaction(sigact); + sig_releaseaction(sigact); + } } /* A sigaction has been supplied */ else { - /* Check if a sigaction was found */ + /* Do we still have a sigaction container from the previous setting? + * If so, then re-use for the new signal action. + */ if (!sigact) { - /* No sigaction was found, but one is needed. Allocate one. */ + /* No.. Then we need to allocate one for the new action. */ sigact = sig_allocateaction(); @@ -294,7 +300,7 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * COPY_SIGACTION(&sigact->act, act); } - return ret; + return OK; } /**************************************************************************** diff --git a/nuttx/sched/task_childstatus.c b/nuttx/sched/task_childstatus.c index 0f6d36c29..09aa48135 100644 --- a/nuttx/sched/task_childstatus.c +++ b/nuttx/sched/task_childstatus.c @@ -297,6 +297,42 @@ FAR struct child_status_s *task_findchild(FAR _TCB *tcb, pid_t pid) return NULL; } +/***************************************************************************** + * Name: task_exitchild + * + * Description: + * Search for any child that has exitted. + * + * Parameters: + * tcb - The TCB of the parent task to containing the child status. + * + * Return Value: + * On success, a non-NULL pointer to a child status structure for the + * exited child. NULL is returned if not child has exited. + * + * Assumptions: + * Called during SIGCHLD processing in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +FAR struct child_status_s *task_exitchild(FAR _TCB *tcb) +{ + FAR struct child_status_s *child; + + /* Find the status structure with the matching PID */ + + for (child = tcb->children; child; child = child->flink) + { + if ((child->ch_flags & CHILD_FLAG_EXITED) != 0) + { + return child; + } + } + + return NULL; +} + /***************************************************************************** * Name: task_removechild * diff --git a/nuttx/sched/task_reparent.c b/nuttx/sched/task_reparent.c index 28d371bf1..3a7ece37d 100644 --- a/nuttx/sched/task_reparent.c +++ b/nuttx/sched/task_reparent.c @@ -138,14 +138,32 @@ int task_reparent(pid_t ppid, pid_t chpid) child = task_removechild(otcb, chpid); if (child) { - /* Add the child status entry to the new parent TCB */ + /* Has the new parent supressed child exit status? */ + + if ((ptcb->flags && TCB_FLAG_NOCLDWAIT) == 0) + { + /* No.. Add the child status entry to the new parent TCB */ + + task_addchild(ptcb, child); + } + else + { + /* Yes.. Discard the child status entry */ + + task_freechild(child); + } + + /* Either case is a success */ - task_addchild(ptcb, child); ret = OK; } else { - ret = -ENOENT; + /* This would not be an error if the original parent has + * suppressed child exit status. + */ + + ret = ((otcb->flags && TCB_FLAG_NOCLDWAIT) == 0) ? -ENOENT : OK; } #else DEBUGASSERT(otcb->nchildren > 0); diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c index 8f54b2e93..66c948cfd 100644 --- a/nuttx/sched/task_setup.c +++ b/nuttx/sched/task_setup.c @@ -150,7 +150,8 @@ static int task_assignpid(FAR _TCB *tcb) * Name: task_saveparent * * Description: - * Save the task ID of the parent task in the child task's TCB. + * Save the task ID of the parent task in the child task's TCB and allocate + * a child status structure to catch the child task's exit status. * * Parameters: * tcb - The TCB of the new, child task. @@ -177,11 +178,15 @@ static inline void task_saveparent(FAR _TCB *tcb, uint8_t ttype) tcb->parent = rtcb->pid; - /* Exit status only needs to be retained for the case of tasks, however */ +#ifdef CONFIG_SCHED_CHILD_STATUS + /* Exit status only needs to be retained for the case of tasks, however. + * Tasks can also suppress retention of their child status by applying + * the SA_NOCLDWAIT flag with sigaction()/ + */ - if (ttype == TCB_FLAG_TTYPE_TASK) + if (ttype == TCB_FLAG_TTYPE_TASK && + (rtcb->flags && TCB_FLAG_NOCLDWAIT) == 0) { -#ifdef CONFIG_SCHED_CHILD_STATUS FAR struct child_status_s *child; /* Make sure that there is not already a structure for this PID in the @@ -212,11 +217,11 @@ static inline void task_saveparent(FAR _TCB *tcb, uint8_t ttype) task_addchild(rtcb, child); } + } #else - DEBUGASSERT(rtcb->nchildren < UINT16_MAX); - rtcb->nchildren++; + DEBUGASSERT(rtcb->nchildren < UINT16_MAX); + rtcb->nchildren++; #endif - } } #else # define task_saveparent(tcb,ttype) @@ -318,7 +323,9 @@ int task_schedsetup(FAR _TCB *tcb, int priority, start_t start, main_t main, tcb->flags &= ~TCB_FLAG_TTYPE_MASK; tcb->flags |= ttype; - /* Save the task ID of the parent task in the TCB */ + /* Save the task ID of the parent task in the TCB and allocate + * a child status structure. + */ task_saveparent(tcb, ttype); -- cgit v1.2.3 From b6472b58dcce32d4ab2051f13cef89a6f0296c28 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 25 Jan 2013 00:01:08 +0000 Subject: Fix some compilation errors when child status disabled; new waitpid logic not encoding/decoding status properly git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5561 42af7a65-404d-4744-a932-0658087f49c3 --- apps/ChangeLog.txt | 2 ++ apps/examples/ostest/waitpid.c | 18 +++++++++--------- nuttx/sched/pthread_join.c | 2 +- nuttx/sched/sched_waitid.c | 12 ++++++------ nuttx/sched/sched_waitpid.c | 10 +++++----- nuttx/sched/task_childstatus.c | 4 ++-- nuttx/sched/timer_initialize.c | 2 +- 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 5f3440897..494ce34eb 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -493,3 +493,5 @@ * apps/netutils/telnetd/telnetd_driver: Was stuck in a loop if recv[from]() ever returned a value <= 0. * apps/examples/nettest and poll: Complete Kconfig files. + * apps/examples/ostest/waitpid.c: Need to use WEXITSTATUS() + to decode the correct exit status. diff --git a/apps/examples/ostest/waitpid.c b/apps/examples/ostest/waitpid.c index e53b49213..d45410265 100644 --- a/apps/examples/ostest/waitpid.c +++ b/apps/examples/ostest/waitpid.c @@ -113,14 +113,14 @@ static void waitpid_last(void) printf("waitpid_last: ERROR: PID %d waitpid failed: %d\n", g_waitpids[NCHILDREN-1], errcode); } - else if (stat_loc != RETURN_STATUS) + else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) { printf("waitpid_last: ERROR: PID %d return status is %d, expected %d\n", - g_waitpids[NCHILDREN-1], stat_loc, RETURN_STATUS); + g_waitpids[NCHILDREN-1], WEXITSTATUS(stat_loc), RETURN_STATUS); } else { - printf("waitpid_last: PID %d waitpid succeeded with stat_loc=%d\n", + printf("waitpid_last: PID %d waitpid succeeded with stat_loc=%04x\n", g_waitpids[NCHILDREN-1], stat_loc); } } @@ -155,14 +155,14 @@ int waitpid_test(void) printf("waitpid_test: ERROR: PID %d wait returned PID %d\n", g_waitpids[0], ret); } - else if (stat_loc != RETURN_STATUS) + else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) { printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n", - g_waitpids[0], stat_loc, RETURN_STATUS); + g_waitpids[0], WEXITSTATUS(stat_loc), RETURN_STATUS); } else { - printf("waitpid_test: PID %d waitpid succeeded with stat_loc=%d\n", + printf("waitpid_test: PID %d waitpid succeeded with stat_loc=%04x\n", g_waitpids[0], stat_loc); } @@ -246,14 +246,14 @@ int waitpid_test(void) int errcode = errno; printf("waitpid_test: ERROR: wait failed: %d\n", errcode); } - else if (stat_loc != RETURN_STATUS) + else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) { printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n", - ret, stat_loc, RETURN_STATUS); + ret, WEXITSTATUS(stat_loc), RETURN_STATUS); } else { - printf("waitpid_test: PID %d wait succeeded with stat_loc=%d\n", + printf("waitpid_test: PID %d wait succeeded with stat_loc=%04x\n", ret, stat_loc); } diff --git a/nuttx/sched/pthread_join.c b/nuttx/sched/pthread_join.c index 6a02af352..d3f648dc7 100644 --- a/nuttx/sched/pthread_join.c +++ b/nuttx/sched/pthread_join.c @@ -123,7 +123,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) * This can fail for one of three reasons: (1) There is no * thread associated with 'thread,' (2) the thread is a task * and does not have join information, or (3) the thread - * was detached and has exitted. + * was detached and has exited. */ pjoin = pthread_findjoininfo((pid_t)thread); diff --git a/nuttx/sched/sched_waitid.c b/nuttx/sched/sched_waitid.c index e73bc223c..56bfb36f0 100644 --- a/nuttx/sched/sched_waitid.c +++ b/nuttx/sched/sched_waitid.c @@ -54,16 +54,16 @@ *****************************************************************************/ /***************************************************************************** - * Name: exitted_child + * Name: exited_child * * Description: - * Handle the case where a child exitted properlay was we (apparently) lost + * Handle the case where a child exited properlay was we (apparently) lost * the detch of child signal. * *****************************************************************************/ #ifdef CONFIG_SCHED_CHILD_STATUS -static void exitted_child(FAR _TCB *rtcb, FAR struct child_status_s *child, +static void exited_child(FAR _TCB *rtcb, FAR struct child_status_s *child, FAR siginfo_t *info) { /* The child has exited. Return the saved exit status (and some fudged @@ -271,11 +271,11 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) if (retains && (child = task_exitchild(rtcb)) != NULL) { - /* A child has exitted. Apparently we missed the signal. + /* A child has exited. Apparently we missed the signal. * Return the exit status and break out of the loop. */ - exitted_child(rtcb, child, info); + exited_child(rtcb, child, info); break; } } @@ -297,7 +297,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) * of the loop. */ - exitted_child(rtcb, child, info); + exited_child(rtcb, child, info); break; } } diff --git a/nuttx/sched/sched_waitpid.c b/nuttx/sched/sched_waitpid.c index ecdc60a2c..d7484fca9 100644 --- a/nuttx/sched/sched_waitpid.c +++ b/nuttx/sched/sched_waitpid.c @@ -384,13 +384,13 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) DEBUGASSERT(!retains || rtcb->children); if (retains && (child = task_exitchild(rtcb)) != NULL) { - /* A child has exitted. Apparently we missed the signal. + /* A child has exited. Apparently we missed the signal. * Return the saved exit status. */ /* The child has exited. Return the saved exit status */ - *stat_loc = child->ch_status; + *stat_loc = child->ch_status << 8; /* Discard the child entry and break out of the loop */ @@ -415,7 +415,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) { /* The child has exited. Return the saved exit status */ - *stat_loc = child->ch_status; + *stat_loc = child->ch_status << 8; /* Discard the child entry and break out of the loop */ @@ -452,7 +452,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) */ if (rtcb->nchildren == 0 || - (pid != (pid_t)-1 && (ret = kill((pid_t)id, 0)) < 0)) + (pid != (pid_t)-1 && (ret = kill(pid, 0)) < 0)) { /* We know that the child task was running okay we stared, * so we must have lost the signal. What can we do? @@ -481,7 +481,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) { /* Yes... return the status and PID (in the event it was -1) */ - *stat_loc = info.si_status; + *stat_loc = info.si_status << 8; pid = info.si_pid; break; } diff --git a/nuttx/sched/task_childstatus.c b/nuttx/sched/task_childstatus.c index 09aa48135..6007f03e5 100644 --- a/nuttx/sched/task_childstatus.c +++ b/nuttx/sched/task_childstatus.c @@ -121,7 +121,7 @@ static void task_dumpchildren(FAR _TCB *tcb, FAR const char *msg) } } #else -# task_dumpchildren(t,m) +# define task_dumpchildren(t,m) #endif /***************************************************************************** @@ -320,7 +320,7 @@ FAR struct child_status_s *task_exitchild(FAR _TCB *tcb) { FAR struct child_status_s *child; - /* Find the status structure with the matching PID */ + /* Find the status structure of any child task that has exitted. */ for (child = tcb->children; child; child = child->flink) { diff --git a/nuttx/sched/timer_initialize.c b/nuttx/sched/timer_initialize.c index 05980bb1a..2651469ef 100644 --- a/nuttx/sched/timer_initialize.c +++ b/nuttx/sched/timer_initialize.c @@ -137,7 +137,7 @@ void weak_function timer_initialize(void) * resources are referenced. * * Parameters: - * pid - the task ID of the thread that exitted + * pid - the task ID of the thread that exited * * Return Value: * None -- cgit v1.2.3 From e95efd5d2a08dcb62c8c635089e4fe146965db45 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 25 Jan 2013 17:23:38 +0000 Subject: Add framework to support task groups git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5562 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/include/nuttx/sched.h | 80 ++++++++++++++++++++++++-- nuttx/net/net_poll.c | 4 +- nuttx/sched/Makefile | 7 ++- nuttx/sched/env_dup.c | 64 ++++++++++----------- nuttx/sched/group_create.c | 111 +++++++++++++++++++++++++++++++++++ nuttx/sched/group_join.c | 107 ++++++++++++++++++++++++++++++++++ nuttx/sched/group_leave.c | 127 +++++++++++++++++++++++++++++++++++++++++ nuttx/sched/os_internal.h | 15 ++++- nuttx/sched/os_start.c | 12 +++- nuttx/sched/pthread_create.c | 43 +++++++++----- nuttx/sched/sched_releasetcb.c | 7 ++- nuttx/sched/sched_waitid.c | 6 +- nuttx/sched/sched_waitpid.c | 6 +- nuttx/sched/sig_action.c | 2 +- nuttx/sched/task_childstatus.c | 27 +++++---- nuttx/sched/task_create.c | 20 ++++++- nuttx/sched/task_exithook.c | 106 ++++++++++++++++++++++------------ nuttx/sched/task_init.c | 54 ++++++++++++++---- nuttx/sched/task_reparent.c | 10 ++-- nuttx/sched/task_setup.c | 10 ++-- 20 files changed, 677 insertions(+), 141 deletions(-) create mode 100644 nuttx/sched/group_create.c create mode 100644 nuttx/sched/group_join.c create mode 100644 nuttx/sched/group_leave.c diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 1e75b5020..4a3bae5e4 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -57,6 +57,14 @@ /******************************************************************************** * Pre-processor Definitions ********************************************************************************/ +/* Configuration ****************************************************************/ +/* Task groups currently only supported for retention of child status */ + +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) +# define HAVE_TASK_GROUP 1 +#else +# undef HAVE_TASK_GROUP +#endif /* Task Management Definitins ***************************************************/ @@ -64,7 +72,7 @@ #define MAX_LOCK_COUNT 127 -/* Values for the _TCB flags flag bits */ +/* Values for the _TCB flags bits */ #define TCB_FLAG_TTYPE_SHIFT (0) /* Bits 0-1: thread type */ #define TCB_FLAG_TTYPE_MASK (3 << TCB_FLAG_TTYPE_SHIFT) @@ -74,7 +82,10 @@ #define TCB_FLAG_NONCANCELABLE (1 << 2) /* Bit 2: Pthread is non-cancelable */ #define TCB_FLAG_CANCEL_PENDING (1 << 3) /* Bit 3: Pthread cancel is pending */ #define TCB_FLAG_ROUND_ROBIN (1 << 4) /* Bit 4: Round robin sched enabled */ -#define TCB_FLAG_NOCLDWAIT (1 << 5) /* Bit 5: Do not retain child exit status */ + +/* Values for struct task_group tg_flags */ + +#define GROUP_FLAG_NOCLDWAIT (1 << 0) /* Bit 0: Do not retain child exit status */ /* Values for struct child_status_s ch_flags */ @@ -159,6 +170,7 @@ typedef CODE void (*onexitfunc_t)(int exitcode, FAR void *arg); typedef struct msgq_s msgq_t; +/* struct environ_s **************************************************************/ /* The structure used to maintain environment variables */ #ifndef CONFIG_DISABLE_ENVIRON @@ -173,6 +185,7 @@ typedef struct environ_s environ_t; # define SIZEOF_ENVIRON_T(alloc) (sizeof(environ_t) + alloc - 1) #endif +/* struct child_status_s *********************************************************/ /* This structure is used to maintin information about child tasks. * pthreads work differently, they have join information. This is * only for child tasks. @@ -189,6 +202,7 @@ struct child_status_s }; #endif +/* struct dspace_s ***************************************************************/ /* This structure describes a reference counted D-Space region. This must be a * separately allocated "break-away" structure that can be owned by a task and * any pthreads created by the task. @@ -214,6 +228,58 @@ struct dspace_s }; #endif +/* struct task_group_s ***********************************************************/ +/* All threads created by pthread_create belong in the same task group (along with + * the thread of the original task). struct task_group_s is a shared, "breakaway" + * structure referenced by each TCB. + * + * This structure should contain *all* resources shared by tasks and threads that + * belong to the same task group: + * + * Child exit status + * Environment varibles + * PIC data space and address environments + * File descriptors + * FILE streams + * Sockets + * + * Currenty, however, this implementation only applies to child exit status. + * + * Each instance of struct task_group_s is reference counted. Each instance is + * created with a reference count of one. The reference incremeneted when each + * thread joins the group and decremented when each thread exits, leaving the + * group. When the refernce count decrements to zero, the struc task_group_s + * is free. + */ + +#ifdef HAVE_TASK_GROUP +struct task_group_s +{ + uint16_t tg_crefs; /* Count of threads sharing this data */ + uint8_t tg_flags; /* See GROUP_FLAG_* definitions */ + + /* Child exit status **********************************************************/ + + FAR struct child_status_s *tg_children; /* Head of a list of child status */ + + /* Environment varibles *******************************************************/ + /* Not yet (see type environ_t) */ + + /* PIC data space and address environments */ + /* Not yet (see struct dspace_s) */ + + /* File descriptors */ + /* Not yet (see struct filelist) */ + + /* FILE streams */ + /* Not yet (see streamlist) */ + + /* Sockets */ + /* Not yet (see struct socketlist) */ +}; +#endif + +/* _TCB **************************************************************************/ /* This is the task control block (TCB). Each task or thread is represented by * a TCB. The TCB is the heart of the NuttX task-control logic. */ @@ -225,14 +291,18 @@ struct _TCB FAR struct _TCB *flink; /* Doubly linked list */ FAR struct _TCB *blink; + /* Task Group *****************************************************************/ + +#ifdef HAVE_TASK_GROUP + FAR struct task_group_s *group; /* Pointer to shared task group data */ +#endif + /* Task Management Fields *****************************************************/ pid_t pid; /* This is the ID of the thread */ #ifdef CONFIG_SCHED_HAVE_PARENT /* Support parent-child relationship */ pid_t parent; /* This is the ID of the parent thread */ -#ifdef CONFIG_SCHED_CHILD_STATUS /* Retain child thread status */ - FAR struct child_status_s *children; /* Head of a list of child status */ -#else +#ifndef CONFIG_SCHED_CHILD_STATUS /* Retain child thread status */ uint16_t nchildren; /* This is the number active children */ #endif #endif diff --git a/nuttx/net/net_poll.c b/nuttx/net/net_poll.c index 3021ac35e..1838f541e 100644 --- a/nuttx/net/net_poll.c +++ b/nuttx/net/net_poll.c @@ -118,11 +118,11 @@ static uint16_t poll_interrupt(FAR struct uip_driver_s *dev, FAR void *conn, nllvdbg("flags: %04x\n", flags); - DEBUGASSERT(info && info->psock && info->fds); + DEBUGASSERT(!info || (info->psock && info->fds)); /* 'priv' might be null in some race conditions (?) */ - if (info->fds) + if (info) { pollevent_t eventset = 0; diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index 1ad244450..6a710ff95 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -87,6 +87,8 @@ SCHED_SRCS += sched_waitid.c sched_wait.c endif endif +GRP_SRCS = group_create.c group_join.c group_leave.c + ENV_SRCS = env_getenvironptr.c env_dup.c env_share.c env_release.c ENV_SRCS += env_findvar.c env_removevar.c ENV_SRCS += env_clearenv.c env_getenv.c env_putenv.c env_setenv.c env_unsetenv.c @@ -169,8 +171,9 @@ IRQ_SRCS = irq_initialize.c irq_attach.c irq_dispatch.c irq_unexpectedisr.c KMM_SRCS = kmm_initialize.c kmm_addregion.c kmm_semaphore.c KMM_SRCS = kmm_kmalloc.c kmm_kzalloc.c kmm_krealloc.c kmm_kfree.c -CSRCS = $(MISC_SRCS) $(TSK_SRCS) $(SCHED_SRCS) $(WDOG_SRCS) $(TIME_SRCS) \ - $(SEM_SRCS) $(TIMER_SRCS) $(WORK_SRCS) $(PGFILL_SRCS) $(IRQ_SRCS) +CSRCS = $(MISC_SRCS) $(TSK_SRCS) $(GRP_SRCS) $(SCHED_SRCS) $(WDOG_SRCS) +CSRCS += $(TIME_SRCS) $(SEM_SRCS) $(TIMER_SRCS) $(WORK_SRCS) $(PGFILL_SRCS) +CSRCS += $(IRQ_SRCS) ifneq ($(CONFIG_DISABLE_CLOCK),y) CSRCS += $(CLOCK_SRCS) diff --git a/nuttx/sched/env_dup.c b/nuttx/sched/env_dup.c index 033348411..30c0b7773 100644 --- a/nuttx/sched/env_dup.c +++ b/nuttx/sched/env_dup.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/env_dup.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -68,7 +68,7 @@ * exact duplicate of the parent task's environment. * * Parameters: - * ptcb The tcb to receive the newly allocated copy of the parspecifiedent + * ptcb The tcb to receive the newly allocated copy of the parent * TCB's environment structure with reference count equal to one * * Return Value: @@ -81,48 +81,42 @@ int env_dup(FAR _TCB *ptcb) { + FAR _TCB *parent = (FAR _TCB*)g_readytorun.head; + environ_t *envp = NULL; int ret = OK; - if (!ptcb ) - { - ret = -EINVAL; - } - else - { - FAR _TCB *parent = (FAR _TCB*)g_readytorun.head; - environ_t *envp = NULL; - /* Pre-emption must be disabled throughout the following because the - * environment may be shared. - */ + DEBUGASSERT(ptcb); + + /* Pre-emption must be disabled throughout the following because the + * environment may be shared. + */ + + sched_lock(); - sched_lock(); + /* Does the parent task have an environment? */ - /* Does the parent task have an environment? */ + if (parent->envp) + { + /* Yes..The parent task has an environment, duplicate it */ - if (parent->envp) + size_t envlen = parent->envp->ev_alloc; + envp = (environ_t*)kmalloc(SIZEOF_ENVIRON_T(envlen)); + if (!envp) { - /* Yes..The parent task has an environment, duplicate it */ - - size_t envlen = parent->envp->ev_alloc; - envp = (environ_t*)kmalloc(SIZEOF_ENVIRON_T( envlen )); - if (!envp) - { - ret = -ENOMEM; - } - else - { - envp->ev_crefs = 1; - envp->ev_alloc = envlen; - memcpy( envp->ev_env, parent->envp->ev_env, envlen ); - } + ret = -ENOMEM; } + else + { + envp->ev_crefs = 1; + envp->ev_alloc = envlen; + memcpy(envp->ev_env, parent->envp->ev_env, envlen); + } + } - /* Save the cloned environment in the new TCB */ - - ptcb->envp = envp; - sched_unlock(); - } + /* Save the cloned environment in the new TCB */ + ptcb->envp = envp; + sched_unlock(); return ret; } diff --git a/nuttx/sched/group_create.c b/nuttx/sched/group_create.c new file mode 100644 index 000000000..d036b9084 --- /dev/null +++ b/nuttx/sched/group_create.c @@ -0,0 +1,111 @@ +/***************************************************************************** + * sched/group_create.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ + +/***************************************************************************** + * Included Files + *****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#ifdef HAVE_TASK_GROUP + +/***************************************************************************** + * Pre-processor Definitions + *****************************************************************************/ + +/***************************************************************************** + * Private Types + *****************************************************************************/ + +/***************************************************************************** + * Private Data + *****************************************************************************/ + +/***************************************************************************** + * Private Functions + *****************************************************************************/ + +/***************************************************************************** + * Public Functions + *****************************************************************************/ + +/***************************************************************************** + * Name: group_create + * + * Description: + * Create and initialize a new task group structure for the specified TCB. + * This function is called as part of the task creation sequence. + * + * Parameters: + * tcb - The tcb in need of the task group. + * + * Return Value: + * 0 (OK) on success; a negated errno value on failure. + * + * Assumptions: + * Called during task creation in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +int group_create(FAR _TCB *tcb) +{ + FAR struct task_group_s *group; + + DEBUGASSERT(tcb && !tcb->group); + + /* Allocate the group structure */ + + group = (FAR struct task_group_s *)kzalloc(sizeof(struct task_group_s)); + if (!group) + { + return -ENOMEM; + } + + /* Initialize the group structure and assign it to the tcb */ + + group->tg_crefs = 1; + tcb->group = group; + return OK; +} + +#endif /* HAVE_TASK_GROUP */ diff --git a/nuttx/sched/group_join.c b/nuttx/sched/group_join.c new file mode 100644 index 000000000..987c1ba87 --- /dev/null +++ b/nuttx/sched/group_join.c @@ -0,0 +1,107 @@ +/***************************************************************************** + * sched/group_join.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ + +/***************************************************************************** + * Included Files + *****************************************************************************/ + +#include + +#include +#include +#include + +#include "os_internal.h" + +#ifdef HAVE_TASK_GROUP + +/***************************************************************************** + * Pre-processor Definitions + *****************************************************************************/ + +/***************************************************************************** + * Private Types + *****************************************************************************/ + +/***************************************************************************** + * Private Data + *****************************************************************************/ + +/***************************************************************************** + * Private Functions + *****************************************************************************/ + +/***************************************************************************** + * Public Functions + *****************************************************************************/ + +/***************************************************************************** + * Name: group_join + * + * Description: + * Copy the group structure reference from one TCB to another, incrementing + * the refrence count on the group. This function is called when a pthread + * is produced within the task group so that the pthread can share the + * resources of the task group. + * + * Parameters: + * tcb - The TCB of the new "child" task that need to join the group. + * + * Return Value: + * None + * + * Assumptions: + * - The parent task from which the group will be inherited is the task at + * the thead of the ready to run list. + * - Called during thread creation in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +void group_join(FAR _TCB *tcb) +{ + FAR _TCB *ptcb = (FAR _TCB *)g_readytorun.head; + + DEBUGASSERT(ptcb && tcb && ptcb->group && !tcb->group); + + /* Copy the group reference from the parent to the child, incrementing the + * reference count. + */ + + tcb->group = ptcb->group; + ptcb->group->tg_crefs++; +} + +#endif /* HAVE_TASK_GROUP */ diff --git a/nuttx/sched/group_leave.c b/nuttx/sched/group_leave.c new file mode 100644 index 000000000..69a6ea8b2 --- /dev/null +++ b/nuttx/sched/group_leave.c @@ -0,0 +1,127 @@ +/***************************************************************************** + * sched/group_leave.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ + +/***************************************************************************** + * Included Files + *****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include "os_internal.h" + +#ifdef HAVE_TASK_GROUP + +/***************************************************************************** + * Pre-processor Definitions + *****************************************************************************/ + +/***************************************************************************** + * Private Types + *****************************************************************************/ + +/***************************************************************************** + * Private Data + *****************************************************************************/ + +/***************************************************************************** + * Private Functions + *****************************************************************************/ + +/***************************************************************************** + * Public Functions + *****************************************************************************/ + +/***************************************************************************** + * Name: group_leave + * + * Description: + * Release a reference on a group. This function is called when a task or + * thread exits. It decrements the reference count on the group. If the + * reference count decrements to zero, then it frees the group and all of + * resources contained in the group. + * + * Parameters: + * tcb - The TCB of the task that is exiting. + * + * Return Value: + * None. + * + * Assumptions: + * Called during task deletion in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +void group_leave(FAR _TCB *tcb) +{ + FAR struct task_group_s *group; + + DEBUGASSERT(tcb); + + /* Make sure that we have a group */ + + group = tcb->group; + if (group) + { + /* Would the reference count decrement to zero? */ + + if (group->tg_crefs > 1) + { + /* No.. just decrement the reference count and return */ + + group->tg_crefs--; + } + else + { + /* Yes.. Release all of the resource contained within the group */ + /* Free all un-reaped child exit status */ + + task_removechildren(tcb); + + /* Release the group container itself */ + + sched_free(group); + } + + tcb->group = NULL; + } +} + +#endif /* HAVE_TASK_GROUP */ diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index dc87cb9a4..ee5ada165 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -268,7 +268,20 @@ int task_schedsetup(FAR _TCB *tcb, int priority, start_t start, int task_argsetup(FAR _TCB *tcb, FAR const char *name, FAR const char *argv[]); void task_exithook(FAR _TCB *tcb, int status); int task_deletecurrent(void); + #ifdef CONFIG_SCHED_HAVE_PARENT +int task_reparent(pid_t ppid, pid_t chpid); + +#ifdef HAVE_TASK_GROUP +int group_create(FAR _TCB *tcb); +void group_join(FAR _TCB *tcb); +void group_leave(FAR _TCB *tcb); +#else +# define group_create(tcb) +# define group_join(tcb) +# define group_leave(tcb) +#endif + #ifdef CONFIG_SCHED_CHILD_STATUS void weak_function task_initialize(void); FAR struct child_status_s *task_allocchild(void); @@ -279,8 +292,8 @@ FAR struct child_status_s *task_findchild(FAR _TCB *tcb, pid_t pid); FAR struct child_status_s *task_removechild(FAR _TCB *tcb, pid_t pid); void task_removechildren(FAR _TCB *tcb); #endif -int task_reparent(pid_t ppid, pid_t chpid); #endif + #ifndef CONFIG_CUSTOM_STACK int kernel_thread(FAR const char *name, int priority, int stack_size, main_t entry, FAR const char *argv[]); diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c index a6d4e83b9..244aec967 100644 --- a/nuttx/sched/os_start.c +++ b/nuttx/sched/os_start.c @@ -202,6 +202,9 @@ const tasklist_t g_tasklisttable[NUM_TASK_STATES] = */ static FAR _TCB g_idletcb; +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) +static struct task_group_s g_idlegroup; +#endif /* This is the name of the idle task */ @@ -280,13 +283,20 @@ void os_start(void) g_idletcb.argv[0] = (char*)g_idlename; #endif /* CONFIG_TASK_NAME_SIZE */ + /* Join the IDLE group */ + +#ifdef HAVE_TASK_GROUP + g_idlegroup.tg_crefs = 1; + g_idlegroup.tg_flags = GROUP_FLAG_NOCLDWAIT; + g_idletcb.group = &g_idlegroup; +#endif + /* Then add the idle task's TCB to the head of the ready to run list */ dq_addfirst((FAR dq_entry_t*)&g_idletcb, (FAR dq_queue_t*)&g_readytorun); /* Initialize the processor-specific portion of the TCB */ - g_idletcb.flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_NOCLDWAIT); up_initial_state(&g_idletcb); /* Initialize the semaphore facility(if in link). This has to be done diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c index f4d0d8fdf..e37c06892 100644 --- a/nuttx/sched/pthread_create.c +++ b/nuttx/sched/pthread_create.c @@ -251,6 +251,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, #if CONFIG_RR_INTERVAL > 0 int policy; #endif + int errcode; pid_t pid; /* If attributes were not supplied, use the default attributes */ @@ -268,6 +269,12 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, return ENOMEM; } + /* Join the parent's task group */ + +#ifdef HAVE_TASK_GROUP + group_join(ptcb); +#endif + /* Share the address environment of the parent task. NOTE: Only tasks * created throught the nuttx/binfmt loaders may have an address * environment. @@ -277,8 +284,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, ret = up_addrenv_share((FAR const _TCB *)g_readytorun.head, ptcb); if (ret < 0) { - sched_releasetcb(ptcb); - return -ret; + errcode = -ret; + goto errout_with_tcb; } #endif @@ -287,8 +294,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, ret = sched_setuppthreadfiles(ptcb); if (ret != OK) { - sched_releasetcb(ptcb); - return ret; + errcode = ret; + goto errout_with_tcb; } /* Share the parent's envionment */ @@ -300,8 +307,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, pjoin = (FAR join_t*)kzalloc(sizeof(join_t)); if (!pjoin) { - sched_releasetcb(ptcb); - return ENOMEM; + errcode = ENOMEM; + goto errout_with_tcb; } /* Allocate the stack for the TCB */ @@ -309,9 +316,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, ret = up_create_stack(ptcb, attr->stacksize); if (ret != OK) { - sched_releasetcb(ptcb); - sched_free(pjoin); - return ENOMEM; + errcode = ENOMEM; + goto errout_with_join; } /* Should we use the priority and scheduler specified in the @@ -360,9 +366,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, TCB_FLAG_TTYPE_PTHREAD); if (ret != OK) { - sched_releasetcb(ptcb); - sched_free(pjoin); - return EBUSY; + errcode = EBUSY; + goto errout_with_join; } /* Configure the TCB for a pthread receiving on parameter @@ -440,10 +445,18 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, dq_rem((FAR dq_entry_t*)ptcb, (dq_queue_t*)&g_inactivetasks); (void)sem_destroy(&pjoin->data_sem); (void)sem_destroy(&pjoin->exit_sem); - sched_releasetcb(ptcb); - sched_free(pjoin); - ret = EIO; + + errcode = EIO; + goto errout_with_join; } return ret; + +errout_with_join: + sched_free(pjoin); + ptcb->joininfo = NULL; + +errout_with_tcb: + sched_releasetcb(ptcb); + return errcode; } diff --git a/nuttx/sched/sched_releasetcb.c b/nuttx/sched/sched_releasetcb.c index 0557c829b..50505f579 100644 --- a/nuttx/sched/sched_releasetcb.c +++ b/nuttx/sched/sched_releasetcb.c @@ -1,7 +1,7 @@ /************************************************************************ * sched/sched_releasetcb.c * - * Copyright (C) 2007, 2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -177,6 +177,11 @@ int sched_releasetcb(FAR _TCB *tcb) ret = up_addrenv_release(tcb); #endif + /* Leave the group (if we did not already leady in task_exithook.c) */ + +#ifdef HAVE_TASK_GROUP + group_leave(tcb); +#endif /* And, finally, release the TCB itself */ sched_free(tcb); diff --git a/nuttx/sched/sched_waitid.c b/nuttx/sched/sched_waitid.c index 56bfb36f0..e47e3c38c 100644 --- a/nuttx/sched/sched_waitid.c +++ b/nuttx/sched/sched_waitid.c @@ -197,9 +197,9 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) #ifdef CONFIG_SCHED_CHILD_STATUS /* Does this task retain child status? */ - retains = ((rtcb->flags && TCB_FLAG_NOCLDWAIT) == 0); + retains = ((rtcb->group->tg_flags && GROUP_FLAG_NOCLDWAIT) == 0); - if (rtcb->children == NULL && retains) + if (rtcb->group->tg_children == NULL && retains) { /* There are no children */ @@ -264,7 +264,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) * instead). */ - DEBUGASSERT(!retains || rtcb->children); + DEBUGASSERT(!retains || rtcb->group->tg_children); if (idtype == P_ALL) { /* We are waiting for any child to exit */ diff --git a/nuttx/sched/sched_waitpid.c b/nuttx/sched/sched_waitpid.c index d7484fca9..2d0fe2e48 100644 --- a/nuttx/sched/sched_waitpid.c +++ b/nuttx/sched/sched_waitpid.c @@ -312,9 +312,9 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) #ifdef CONFIG_SCHED_CHILD_STATUS /* Does this task retain child status? */ - retains = ((rtcb->flags && TCB_FLAG_NOCLDWAIT) == 0); + retains = ((rtcb->group->tg_flags && GROUP_FLAG_NOCLDWAIT) == 0); - if (rtcb->children == NULL && retains) + if (rtcb->group->tg_children == NULL && retains) { err = ECHILD; goto errout_with_errno; @@ -381,7 +381,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) * chilren. */ - DEBUGASSERT(!retains || rtcb->children); + DEBUGASSERT(!retains || rtcb->group->tg_children); if (retains && (child = task_exitchild(rtcb)) != NULL) { /* A child has exited. Apparently we missed the signal. diff --git a/nuttx/sched/sig_action.c b/nuttx/sched/sig_action.c index 7d84b6291..b307c1fb6 100644 --- a/nuttx/sched/sig_action.c +++ b/nuttx/sched/sig_action.c @@ -237,7 +237,7 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * /* Mark that status should be not be retained */ - rtcb->flags |= TCB_FLAG_NOCLDWAIT; + rtcb->group->tg_flags |= GROUP_FLAG_NOCLDWAIT; /* Free all pending exit status */ diff --git a/nuttx/sched/task_childstatus.c b/nuttx/sched/task_childstatus.c index 6007f03e5..aff2bdf3a 100644 --- a/nuttx/sched/task_childstatus.c +++ b/nuttx/sched/task_childstatus.c @@ -111,10 +111,11 @@ static struct child_pool_s g_child_pool; static void task_dumpchildren(FAR _TCB *tcb, FAR const char *msg) { FAR struct child_status_s *child; + FAR struct task_group_s *group = tcb->group; int i; - dbg("Parent TCB=%p: %s\n", tcb, msg); - for (i = 0, child = tcb->children; child; i++, child = child->flink) + dbg("Parent TCB=%p group=%p: %s\n", tcb, group, msg); + for (i = 0, child = group->tg_children; child; i++, child = child->flink) { dbg(" %d. ch_flags=%02x ch_pid=%d ch_status=%d\n", i, child->ch_flags, child->ch_pid, child->ch_status); @@ -250,10 +251,12 @@ void task_freechild(FAR struct child_status_s *child) void task_addchild(FAR _TCB *tcb, FAR struct child_status_s *child) { + FAR struct task_group_s *group = tcb->group; + /* Add the entry into the TCB list of children */ - child->flink = tcb->children; - tcb->children = child; + child->flink = group->tg_children; + group->tg_children = child; task_dumpchildren(tcb, "task_addchild"); } @@ -282,11 +285,12 @@ void task_addchild(FAR _TCB *tcb, FAR struct child_status_s *child) FAR struct child_status_s *task_findchild(FAR _TCB *tcb, pid_t pid) { + FAR struct task_group_s *group = tcb->group; FAR struct child_status_s *child; /* Find the status structure with the matching PID */ - for (child = tcb->children; child; child = child->flink) + for (child = group->tg_children; child; child = child->flink) { if (child->ch_pid == pid) { @@ -318,11 +322,12 @@ FAR struct child_status_s *task_findchild(FAR _TCB *tcb, pid_t pid) FAR struct child_status_s *task_exitchild(FAR _TCB *tcb) { + FAR struct task_group_s *group = tcb->group; FAR struct child_status_s *child; /* Find the status structure of any child task that has exitted. */ - for (child = tcb->children; child; child = child->flink) + for (child = group->tg_children; child; child = child->flink) { if ((child->ch_flags & CHILD_FLAG_EXITED) != 0) { @@ -357,12 +362,13 @@ FAR struct child_status_s *task_exitchild(FAR _TCB *tcb) FAR struct child_status_s *task_removechild(FAR _TCB *tcb, pid_t pid) { + FAR struct task_group_s *group = tcb->group; FAR struct child_status_s *curr; FAR struct child_status_s *prev; /* Find the status structure with the matching PID */ - for (prev = NULL, curr = tcb->children; + for (prev = NULL, curr = group->tg_children; curr; prev = curr, curr = curr->flink) { @@ -384,7 +390,7 @@ FAR struct child_status_s *task_removechild(FAR _TCB *tcb, pid_t pid) } else { - tcb->children = curr->flink; + group->tg_children = curr->flink; } curr->flink = NULL; @@ -414,18 +420,19 @@ FAR struct child_status_s *task_removechild(FAR _TCB *tcb, pid_t pid) void task_removechildren(FAR _TCB *tcb) { + FAR struct task_group_s *group = tcb->group; FAR struct child_status_s *curr; FAR struct child_status_s *next; /* Remove all child structures for the TCB and return them to the freelist */ - for (curr = tcb->children; curr; curr = next) + for (curr = group->tg_children; curr; curr = next) { next = curr->flink; task_freechild(curr); } - tcb->children = NULL; + group->tg_children = NULL; task_dumpchildren(tcb, "task_removechildren"); } diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c index 2ed929ab0..f2aeeeec0 100644 --- a/nuttx/sched/task_create.c +++ b/nuttx/sched/task_create.c @@ -108,6 +108,7 @@ static int thread_create(const char *name, uint8_t ttype, int priority, { FAR _TCB *tcb; pid_t pid; + int errcode; int ret; /* Allocate a TCB for the new task. */ @@ -115,15 +116,28 @@ static int thread_create(const char *name, uint8_t ttype, int priority, tcb = (FAR _TCB*)kzalloc(sizeof(_TCB)); if (!tcb) { + errcode = ENOMEM; goto errout; } + /* Create a new task group */ + +#ifdef HAVE_TASK_GROUP + ret = group_create(tcb); + if (ret < 0) + { + errcode = -ret; + goto errout_with_tcb; + } +#endif + /* Associate file descriptors with the new task */ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 ret = sched_setuptaskfiles(tcb); if (ret != OK) { + errcode = -ret; goto errout_with_tcb; } #endif @@ -138,6 +152,7 @@ static int thread_create(const char *name, uint8_t ttype, int priority, ret = up_create_stack(tcb, stack_size); if (ret != OK) { + errcode = -ret; goto errout_with_tcb; } #endif @@ -147,6 +162,7 @@ static int thread_create(const char *name, uint8_t ttype, int priority, ret = task_schedsetup(tcb, priority, task_start, entry, ttype); if (ret != OK) { + errcode = -ret; goto errout_with_tcb; } @@ -163,6 +179,8 @@ static int thread_create(const char *name, uint8_t ttype, int priority, ret = task_activate(tcb); if (ret != OK) { + errcode = get_errno(); + /* The TCB was added to the active task list by task_schedsetup() */ dq_rem((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); @@ -175,7 +193,7 @@ errout_with_tcb: sched_releasetcb(tcb); errout: - errno = ENOMEM; + set_errno(errcode); return ERROR; } diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index 1813c12ed..30ce41f71 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -197,39 +197,28 @@ static inline void task_onexit(FAR _TCB *tcb, int status) ****************************************************************************/ #ifdef CONFIG_SCHED_HAVE_PARENT -static inline void task_sigchild(FAR _TCB *tcb, int status) +static inline void task_sigchild(FAR _TCB *ptcb, FAR _TCB *ctcb, int status) { - FAR _TCB *ptcb; siginfo_t info; - /* Only exiting tasks should generate SIGCHLD. pthreads use other - * mechansims. + /* Only the final exiting thread in a task group should generate SIGCHLD. + * If task groups are not supported then we will report SIGCHLD when the + * task exits. */ - if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_TASK) +#ifdef CONFIG_SCHED_CHILD_STATUS + if (ctcb->group->tg_crefs == 1) +#else + if ((ctcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_TASK) +#endif { - /* Keep things stationary through the following */ - - sched_lock(); - - /* Get the TCB of the receiving task */ - - ptcb = sched_gettcb(tcb->parent); - if (!ptcb) - { - /* The parent no longer exists... bail */ - - sched_unlock(); - return; - } - #ifdef CONFIG_SCHED_CHILD_STATUS - /* Check if the parent task has suppressed retention of child exit + /* Check if the parent task group has suppressed retention of child exit * status information. Only 'tasks' report exit status, not pthreads. * pthreads have a different mechanism. */ - if ((ptcb->flags & TCB_FLAG_NOCLDWAIT) == 0) + if ((ptcb->group->tg_flags & GROUP_FLAG_NOCLDWAIT) == 0) { FAR struct child_status_s *child; @@ -255,15 +244,6 @@ static inline void task_sigchild(FAR _TCB *tcb, int status) ptcb->nchildren--; #endif - /* Set the parent to an impossible PID. We do this because under - * certain conditions, task_exithook() can be called multiple times. - * If this function is called again, sched_gettcb() will fail on the - * invalid parent PID above, nchildren will be decremented once and - * all will be well. - */ - - tcb->parent = INVALID_PROCESS_ID; - /* Create the siginfo structure. We don't actually know the cause. * That is a bug. Let's just say that the child task just exit-ted * for now. @@ -272,7 +252,7 @@ static inline void task_sigchild(FAR _TCB *tcb, int status) info.si_signo = SIGCHLD; info.si_code = CLD_EXITED; info.si_value.sival_ptr = NULL; - info.si_pid = tcb->pid; + info.si_pid = ctcb->pid; info.si_status = status; /* Send the signal. We need to use this internal interface so that we @@ -280,11 +260,59 @@ static inline void task_sigchild(FAR _TCB *tcb, int status) */ (void)sig_received(ptcb, &info); + } +} +#else +# define task_sigchild(ptct,ctcb,status) +#endif + +/**************************************************************************** + * Name: task_leavegroup + * + * Description: + * Send the SIGCHILD signal to the parent thread + * + ****************************************************************************/ + +#ifdef CONFIG_SCHED_HAVE_PARENT +static inline void task_leavegroup(FAR _TCB *ctcb, int status) +{ + FAR _TCB *ptcb; + + /* Keep things stationary throughout the following */ + + sched_lock(); + + /* Get the TCB of the receiving, parent task. We do this early to + * handle multiple calls to task_leavegroup. ctcb->parent is set to an + * invalid value below and the following call will fail if we are + * called again. + */ + + ptcb = sched_gettcb(ctcb->parent); + if (!ptcb) + { + /* The parent no longer exists... bail */ + sched_unlock(); + return; } + + /* Send SIGCHLD to all members of the parent's task group */ + + task_sigchild(ptcb, ctcb, status); + + /* Set the parent to an impossible PID. We do this because under certain + * conditions, task_exithook() can be called multiple times. If this + * function is called again, sched_gettcb() will fail on the invalid + * parent PID above and all will be well. + */ + + ctcb->parent = INVALID_PROCESS_ID; + sched_unlock(); } #else -# define task_sigchild(tcb,status) +# define task_leavegroup(ctcb,status) #endif /**************************************************************************** @@ -363,9 +391,9 @@ void task_exithook(FAR _TCB *tcb, int status) task_onexit(tcb, status); - /* Send SIGCHLD to the parent of the exit-ing task */ + /* Leave the task group */ - task_sigchild(tcb, status); + task_leavegroup(tcb, status); /* Wakeup any tasks waiting for this task to exit */ @@ -379,10 +407,12 @@ void task_exithook(FAR _TCB *tcb, int status) (void)lib_flushall(tcb->streams); #endif - /* Discard any un-reaped child status (no zombies here!) */ + /* Leave the task group. Perhaps discarding any un-reaped child + * status (no zombies here!) + */ -#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) - task_removechildren(tcb); +#ifdef HAVE_TASK_GROUP + group_leave(tcb); #endif /* Free all file-related resources now. This gets called again diff --git a/nuttx/sched/task_init.c b/nuttx/sched/task_init.c index 0f0fdc68e..5ba6b7e7d 100644 --- a/nuttx/sched/task_init.c +++ b/nuttx/sched/task_init.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task_init.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,6 +42,8 @@ #include #include #include +#include + #include #include "os_internal.h" @@ -102,10 +104,10 @@ * parameters are required, argv may be NULL. * * Return Value: - * OK on success; ERROR on failure. (See task_schedsetup() for possible - * failure conditions). On failure, the caller is responsible for freeing - * the stack memory and for calling sched_releasetcb() to free the TCB - * (which could be in most any state). + * OK on success; ERROR on failure with errno set appropriately. (See + * task_schedsetup() for possible failure conditions). On failure, the + * caller is responsible for freeing the stack memory and for calling + * sched_releasetcb() to free the TCB (which could be in most any state). * ****************************************************************************/ @@ -118,14 +120,28 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, main_t entry, const char *argv[]) #endif { + int errcode; int ret; + /* Create a new task group */ + +#ifdef HAVE_TASK_GROUP + ret = group_create(tcb); + if (ret < 0) + { + errcode = -ret; + goto errout; + } +#endif + /* Associate file descriptors with the new task */ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - if (sched_setuptaskfiles(tcb) != OK) + ret = sched_setuptaskfiles(tcb); + if (ret < 0) { - return ERROR; + errcode = -ret; + goto errout_with_group; } #endif @@ -143,13 +159,27 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, ret = task_schedsetup(tcb, priority, task_start, entry, TCB_FLAG_TTYPE_TASK); - if (ret == OK) + if (ret < OK) { - /* Setup to pass parameters to the new task */ - - (void)task_argsetup(tcb, name, argv); + errcode = -ret; + goto errout_with_env; } - return ret; + /* Setup to pass parameters to the new task */ + + (void)task_argsetup(tcb, name, argv); + return OK; + +errout_with_env: + env_release(tcb); + +errout_with_group: +#ifdef HAVE_TASK_GROUP + group_leave(tcb); + +errout: +#endif + set_errno(errcode); + return ERROR; } diff --git a/nuttx/sched/task_reparent.c b/nuttx/sched/task_reparent.c index 3a7ece37d..0b502dcce 100644 --- a/nuttx/sched/task_reparent.c +++ b/nuttx/sched/task_reparent.c @@ -138,11 +138,11 @@ int task_reparent(pid_t ppid, pid_t chpid) child = task_removechild(otcb, chpid); if (child) { - /* Has the new parent supressed child exit status? */ + /* Has the new parent's task group supressed child exit status? */ - if ((ptcb->flags && TCB_FLAG_NOCLDWAIT) == 0) + if ((ptcb->group->tg_flags && GROUP_FLAG_NOCLDWAIT) == 0) { - /* No.. Add the child status entry to the new parent TCB */ + /* No.. Add the child status entry to the new parent's task group */ task_addchild(ptcb, child); } @@ -159,11 +159,11 @@ int task_reparent(pid_t ppid, pid_t chpid) } else { - /* This would not be an error if the original parent has + /* This would not be an error if the original parent's task group has * suppressed child exit status. */ - ret = ((otcb->flags && TCB_FLAG_NOCLDWAIT) == 0) ? -ENOENT : OK; + ret = ((otcb->group->tg_flags && GROUP_FLAG_NOCLDWAIT) == 0) ? -ENOENT : OK; } #else DEBUGASSERT(otcb->nchildren > 0); diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c index 66c948cfd..7675c7481 100644 --- a/nuttx/sched/task_setup.c +++ b/nuttx/sched/task_setup.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task_setup.c * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -179,13 +179,11 @@ static inline void task_saveparent(FAR _TCB *tcb, uint8_t ttype) tcb->parent = rtcb->pid; #ifdef CONFIG_SCHED_CHILD_STATUS - /* Exit status only needs to be retained for the case of tasks, however. - * Tasks can also suppress retention of their child status by applying - * the SA_NOCLDWAIT flag with sigaction()/ + /* Tasks can also suppress retention of their child status by applying + * the SA_NOCLDWAIT flag with sigaction(). */ - if (ttype == TCB_FLAG_TTYPE_TASK && - (rtcb->flags && TCB_FLAG_NOCLDWAIT) == 0) + if ((rtcb->group->tg_flags && GROUP_FLAG_NOCLDWAIT) == 0) { FAR struct child_status_s *child; -- cgit v1.2.3 From 80904539e63681b2dca74e3978effb17f0c071b0 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 25 Jan 2013 19:15:05 +0000 Subject: Add logic to keep track of members of a task group git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5563 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/include/nuttx/sched.h | 24 +++++++--- nuttx/sched/group_create.c | 74 ++++++++++++++++++++++++++----- nuttx/sched/group_join.c | 103 ++++++++++++++++++++++++++++++++++++++----- nuttx/sched/group_leave.c | 68 +++++++++++++++++++++++++--- nuttx/sched/os_internal.h | 10 +++-- nuttx/sched/os_start.c | 19 ++++---- nuttx/sched/pthread_create.c | 24 ++++++++-- nuttx/sched/task_create.c | 17 +++++-- nuttx/sched/task_exithook.c | 2 +- nuttx/sched/task_init.c | 13 +++++- 10 files changed, 298 insertions(+), 56 deletions(-) diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 4a3bae5e4..a29f8dfeb 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -60,10 +60,18 @@ /* Configuration ****************************************************************/ /* Task groups currently only supported for retention of child status */ +#undef HAVE_TASK_GROUP +#undef HAVE_GROUP_MEMBERS + #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) -# define HAVE_TASK_GROUP 1 -#else -# undef HAVE_TASK_GROUP +# define HAVE_TASK_GROUP 1 +# define HAVE_GROUP_MEMBERS 1 +#endif + +/* In any event, we don't need group members if support for pthreads is disabled */ + +#ifdef CONFIG_PTHREADS_DISABLE +# undef HAVE_GROUP_MEMBERS #endif /* Task Management Definitins ***************************************************/ @@ -255,12 +263,18 @@ struct dspace_s #ifdef HAVE_TASK_GROUP struct task_group_s { - uint16_t tg_crefs; /* Count of threads sharing this data */ - uint8_t tg_flags; /* See GROUP_FLAG_* definitions */ + uint8_t tg_flags; /* See GROUP_FLAG_* definitions */ + uint8_t tg_nmembers; /* Number of members in the group */ +#ifdef HAVE_GROUP_MEMBERS + uint8_t tg_mxmembers; /* Number of members in allocation */ + FAR pid_t *tg_members; /* Members of the group */ +#endif /* Child exit status **********************************************************/ +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) FAR struct child_status_s *tg_children; /* Head of a list of child status */ +#endif /* Environment varibles *******************************************************/ /* Not yet (see type environ_t) */ diff --git a/nuttx/sched/group_create.c b/nuttx/sched/group_create.c index d036b9084..4612ae8c5 100644 --- a/nuttx/sched/group_create.c +++ b/nuttx/sched/group_create.c @@ -1,5 +1,5 @@ /***************************************************************************** - * sched/group_create.c + * sched/group_allocate.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -51,6 +51,9 @@ /***************************************************************************** * Pre-processor Definitions *****************************************************************************/ +/* Is this worth making a configuration option? */ + +#define GROUP_INITIAL_MEMBERS 4 /***************************************************************************** * Private Types @@ -69,11 +72,16 @@ *****************************************************************************/ /***************************************************************************** - * Name: group_create + * Name: group_allocate * * Description: - * Create and initialize a new task group structure for the specified TCB. - * This function is called as part of the task creation sequence. + * Create and a new task group structure for the specified TCB. This + * function is called as part of the task creation sequence. The structure + * allocated and zered, but otherwise uninitialized. The full creation + * of the group of a two step process: (1) First, this function allocates + * group structure early in the task creation sequence in order to provide a + * group container, then (2) group_initialize() is called to set up the + * group membership. * * Parameters: * tcb - The tcb in need of the task group. @@ -87,24 +95,66 @@ * *****************************************************************************/ -int group_create(FAR _TCB *tcb) +int group_allocate(FAR _TCB *tcb) { + DEBUGASSERT(tcb && !tcb->group); + + /* Allocate the group structure and assign it to the TCB */ + + tcb->group = (FAR struct task_group_s *)kzalloc(sizeof(struct task_group_s)); + return tcb->group ? OK : -ENOMEM; +} + +/***************************************************************************** + * Name: group_initialize + * + * Description: + * Add the task as the initial member of the group. The full creation of + * the group of a two step process: (1) First, this group structure is + * allocated by group_allocate() early in the task creation sequence, then + * (2) this function is called to set up the initial group membership. + * + * Parameters: + * tcb - The tcb in need of the task group. + * + * Return Value: + * 0 (OK) on success; a negated errno value on failure. + * + * Assumptions: + * Called during task creation in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +int group_initialize(FAR _TCB *tcb) +{ +#ifdef HAVE_GROUP_MEMBERS FAR struct task_group_s *group; - DEBUGASSERT(tcb && !tcb->group); + DEBUGASSERT(tcb && tcb->group); + group = tcb->group; - /* Allocate the group structure */ + /* Allocate space to hold GROUP_INITIAL_MEMBERS members of the group */ - group = (FAR struct task_group_s *)kzalloc(sizeof(struct task_group_s)); - if (!group) + group->tg_members = (FAR pid_t *)kmalloc(GROUP_INITIAL_MEMBERS*sizeof(pid_t)); + if (!group->tg_members) { + free(group); return -ENOMEM; } - /* Initialize the group structure and assign it to the tcb */ + /* Assign the PID of this new task as a member of the group*/ + + group->tg_members[0] = tcb->pid; + + /* Initialize the non-zero elements of group structure and assign it to + * the tcb. + */ + + group->tg_mxmembers = GROUP_INITIAL_MEMBERS; /* Number of members in allocation */ +#endif - group->tg_crefs = 1; - tcb->group = group; + group->tg_nmembers = 1; /* Number of members in the group */ return OK; } diff --git a/nuttx/sched/group_join.c b/nuttx/sched/group_join.c index 987c1ba87..9dcea6599 100644 --- a/nuttx/sched/group_join.c +++ b/nuttx/sched/group_join.c @@ -41,8 +41,11 @@ #include #include +#include #include +#include + #include "os_internal.h" #ifdef HAVE_TASK_GROUP @@ -50,6 +53,9 @@ /***************************************************************************** * Pre-processor Definitions *****************************************************************************/ +/* Is this worth making a configuration option? */ + +#define GROUP_REALLOC_MEMBERS 4 /***************************************************************************** * Private Types @@ -68,19 +74,21 @@ *****************************************************************************/ /***************************************************************************** - * Name: group_join + * Name: group_bind * * Description: - * Copy the group structure reference from one TCB to another, incrementing - * the refrence count on the group. This function is called when a pthread - * is produced within the task group so that the pthread can share the - * resources of the task group. + * A thread joins the group when it is created. This is a two step process, + * first, the group must bound to the new threads TCB. group_bind() does + * this (at the return from group_join, things are a little unstable: The + * group has been bound, but tg_nmembers hs not yet been incremented). + * Then, after the new thread is initialized and has a PID assigned to it, + * group_join() is called, incrementing the tg_nmembers count on the group. * * Parameters: * tcb - The TCB of the new "child" task that need to join the group. * * Return Value: - * None + * 0 (OK) on success; a negated errno value on failure. * * Assumptions: * - The parent task from which the group will be inherited is the task at @@ -90,18 +98,91 @@ * *****************************************************************************/ -void group_join(FAR _TCB *tcb) +int group_bind(FAR _TCB *tcb) { FAR _TCB *ptcb = (FAR _TCB *)g_readytorun.head; DEBUGASSERT(ptcb && tcb && ptcb->group && !tcb->group); - /* Copy the group reference from the parent to the child, incrementing the - * reference count. - */ + /* Copy the group reference from the parent to the child */ tcb->group = ptcb->group; - ptcb->group->tg_crefs++; + return OK; +} + +/***************************************************************************** + * Name: group_join + * + * Description: + * A thread joins the group when it is created. This is a two step process, + * first, the group must bound to the new threads TCB. group_bind() does + * this (at the return from group_join, things are a little unstable: The + * group has been bound, but tg_nmembers hs not yet been incremented). + * Then, after the new thread is initialized and has a PID assigned to it, + * group_join() is called, incrementing the tg_nmembers count on the group. + * + * Parameters: + * tcb - The TCB of the new "child" task that need to join the group. + * + * Return Value: + * 0 (OK) on success; a negated errno value on failure. + * + * Assumptions: + * - The parent task from which the group will be inherited is the task at + * the thead of the ready to run list. + * - Called during thread creation in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +int group_join(FAR _TCB *tcb) +{ +#ifdef HAVE_GROUP_MEMBERS + FAR struct task_group_s *group; + + DEBUGASSERT(tcb && tcb->group && + tcb->group->tg_nmembers < UINT8_MAX); + + /* Get the group from the TCB */ + + group = tcb->group; + + /* Will we need to extend the size of the array of groups? */ + + if (group->tg_nmembers >= group->tg_mxmembers) + { + FAR pid_t *newmembers; + unsigned int newmax; + + /* Yes... reallocate the array of members */ + + newmax = group->tg_mxmembers + GROUP_REALLOC_MEMBERS; + if (newmax > UINT8_MAX) + { + newmax = UINT8_MAX; + } + + newmembers = (FAR pid_t *) + krealloc(group->tg_members, sizeof(pid_t) * newmax); + + if (!newmembers) + { + return -ENOMEM; + } + + /* Save the new number of members in the reallocated members array */ + + group->tg_members = newmembers; + group->tg_mxmembers = newmax; + } + + /* Assign this new pid to the group. */ + + group->tg_members[group->tg_nmembers] = tcb->pid; +#endif + + group->tg_nmembers++; + return OK; } #endif /* HAVE_TASK_GROUP */ diff --git a/nuttx/sched/group_leave.c b/nuttx/sched/group_leave.c index 69a6ea8b2..223af1556 100644 --- a/nuttx/sched/group_leave.c +++ b/nuttx/sched/group_leave.c @@ -92,6 +92,7 @@ void group_leave(FAR _TCB *tcb) { FAR struct task_group_s *group; + int i; DEBUGASSERT(tcb); @@ -100,17 +101,69 @@ void group_leave(FAR _TCB *tcb) group = tcb->group; if (group) { - /* Would the reference count decrement to zero? */ +#ifdef HAVE_GROUP_MEMBERS + /* Find the member in the array of members and remove it */ - if (group->tg_crefs > 1) + for (i = 0; i < group->tg_nmembers; i++) { - /* No.. just decrement the reference count and return */ + /* Does this member have the matching pid */ + + if (group->tg_members[i] == tcb->pid) + { + /* Yes.. break out of the loop. We don't do the actual + * removal here, instead we re-test i and do the adjustments + * outside of the loop. We do this because we want the + * DEBUGASSERT to work properly. + */ + + break; + } + } + + /* Now, test if we found the task in the array of members. */ + + DEBUGASSERT(i < group->tg_nmembers); + if (i < group->tg_nmembers) + { + /* Yes..Is this the last member of the group? */ + + if (group->tg_nmembers > 1) + { + /* No.. remove the member from the array of members */ + + group->tg_members[i] = group->tg_members[group->tg_nmembers - 1]; + group->tg_nmembers--; + } + + /* Yes.. that was the last member remaining in the group */ + + else + { + /* Release all of the resource contained within the group */ + /* Free all un-reaped child exit status */ + + task_removechildren(tcb); - group->tg_crefs--; + /* Release the group container itself */ + + sched_free(group); + } + } +#else + /* Yes..Is this the last member of the group? */ + + if (group->tg_nmembers > 1) + { + /* No.. just decrement the number of members in the group */ + + group->tg_nmembers--; } + + /* Yes.. that was the last member remaining in the group */ + else { - /* Yes.. Release all of the resource contained within the group */ + /* Release all of the resource contained within the group */ /* Free all un-reaped child exit status */ task_removechildren(tcb); @@ -119,6 +172,11 @@ void group_leave(FAR _TCB *tcb) sched_free(group); } +#endif + + /* In any event, we can detach the group from the TCB so we won't do + * this again. + */ tcb->group = NULL; } diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index ee5ada165..8ce99bc44 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -273,12 +273,14 @@ int task_deletecurrent(void); int task_reparent(pid_t ppid, pid_t chpid); #ifdef HAVE_TASK_GROUP -int group_create(FAR _TCB *tcb); -void group_join(FAR _TCB *tcb); +int group_allocate(FAR _TCB *tcb); +int group_initialize(FAR _TCB *tcb); +int group_join(FAR _TCB *tcb); void group_leave(FAR _TCB *tcb); #else -# define group_create(tcb) -# define group_join(tcb) +# define group_allocate(tcb) (0) +# define group_initialize(tcb) (0) +# define group_join(tcb) (0) # define group_leave(tcb) #endif diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c index 244aec967..3aecc7efb 100644 --- a/nuttx/sched/os_start.c +++ b/nuttx/sched/os_start.c @@ -202,9 +202,6 @@ const tasklist_t g_tasklisttable[NUM_TASK_STATES] = */ static FAR _TCB g_idletcb; -#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) -static struct task_group_s g_idlegroup; -#endif /* This is the name of the idle task */ @@ -283,14 +280,6 @@ void os_start(void) g_idletcb.argv[0] = (char*)g_idlename; #endif /* CONFIG_TASK_NAME_SIZE */ - /* Join the IDLE group */ - -#ifdef HAVE_TASK_GROUP - g_idlegroup.tg_crefs = 1; - g_idlegroup.tg_flags = GROUP_FLAG_NOCLDWAIT; - g_idletcb.group = &g_idlegroup; -#endif - /* Then add the idle task's TCB to the head of the ready to run list */ dq_addfirst((FAR dq_entry_t*)&g_idletcb, (FAR dq_queue_t*)&g_readytorun); @@ -447,6 +436,14 @@ void os_start(void) lib_initialize(); } + /* Create the IDLE group and suppress child status */ + +#ifdef HAVE_TASK_GROUP + (void)group_allocate(&g_idletcb); + (void)group_initialize(&g_idletcb); + g_idletcb.group->tg_flags = GROUP_FLAG_NOCLDWAIT; +#endif + /* Create stdout, stderr, stdin on the IDLE task. These will be * inherited by all of the threads created by the IDLE task. */ diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c index e37c06892..89a2feb00 100644 --- a/nuttx/sched/pthread_create.c +++ b/nuttx/sched/pthread_create.c @@ -246,13 +246,13 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, { FAR _TCB *ptcb; FAR join_t *pjoin; - int ret; int priority; #if CONFIG_RR_INTERVAL > 0 int policy; #endif int errcode; pid_t pid; + int ret; /* If attributes were not supplied, use the default attributes */ @@ -269,10 +269,17 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, return ENOMEM; } - /* Join the parent's task group */ + /* Bind the parent's group to the new TCB (we have not yet joined the + * group). + */ #ifdef HAVE_TASK_GROUP - group_join(ptcb); + ret = group_bind(ptcb); + if (ret < 0) + { + errcode = ENOMEM; + goto errout_with_tcb; + } #endif /* Share the address environment of the parent task. NOTE: Only tasks @@ -376,6 +383,17 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, pthread_argsetup(ptcb, arg); + /* Join the parent's task group */ + +#ifdef HAVE_TASK_GROUP + ret = group_join(ptcb); + if (ret < 0) + { + errcode = ENOMEM; + goto errout_with_join; + } +#endif + /* Attach the join info to the TCB. */ ptcb->joininfo = (void*)pjoin; diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c index f2aeeeec0..bb309444b 100644 --- a/nuttx/sched/task_create.c +++ b/nuttx/sched/task_create.c @@ -120,10 +120,10 @@ static int thread_create(const char *name, uint8_t ttype, int priority, goto errout; } - /* Create a new task group */ + /* Allocate a new task group */ #ifdef HAVE_TASK_GROUP - ret = group_create(tcb); + ret = group_allocate(tcb); if (ret < 0) { errcode = -ret; @@ -160,7 +160,7 @@ static int thread_create(const char *name, uint8_t ttype, int priority, /* Initialize the task control block */ ret = task_schedsetup(tcb, priority, task_start, entry, ttype); - if (ret != OK) + if (ret < OK) { errcode = -ret; goto errout_with_tcb; @@ -170,6 +170,17 @@ static int thread_create(const char *name, uint8_t ttype, int priority, (void)task_argsetup(tcb, name, argv); + /* Now we have enough in place that we can join the group */ + +#ifdef HAVE_TASK_GROUP + ret = group_initialize(tcb); + if (ret < 0) + { + errcode = -ret; + goto errout_with_tcb; + } +#endif + /* Get the assigned pid before we start the task */ pid = (int)tcb->pid; diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index 30ce41f71..36836301c 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -207,7 +207,7 @@ static inline void task_sigchild(FAR _TCB *ptcb, FAR _TCB *ctcb, int status) */ #ifdef CONFIG_SCHED_CHILD_STATUS - if (ctcb->group->tg_crefs == 1) + if (ctcb->group->tg_nmembers == 1) #else if ((ctcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_TASK) #endif diff --git a/nuttx/sched/task_init.c b/nuttx/sched/task_init.c index 5ba6b7e7d..6ae643948 100644 --- a/nuttx/sched/task_init.c +++ b/nuttx/sched/task_init.c @@ -126,7 +126,7 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, /* Create a new task group */ #ifdef HAVE_TASK_GROUP - ret = group_create(tcb); + ret = group_allocate(tcb); if (ret < 0) { errcode = -ret; @@ -168,6 +168,17 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, /* Setup to pass parameters to the new task */ (void)task_argsetup(tcb, name, argv); + + /* Now we have enough in place that we can join the group */ + +#ifdef HAVE_TASK_GROUP + ret = group_initialize(tcb); + if (ret < 0) + { + errcode = -ret; + goto errout_with_env; + } +#endif return OK; errout_with_env: -- cgit v1.2.3 From fdaa22ed2d565e49983e956bc056f1e0797bd9a9 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 25 Jan 2013 20:00:37 +0000 Subject: Add logic to send SIGCHLD to all members of a task group git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5564 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 5 ++ nuttx/include/nuttx/sched.h | 2 +- nuttx/sched/Makefile | 6 +- nuttx/sched/group_signal.c | 135 ++++++++++++++++++++++++++++++++++++++++++++ nuttx/sched/os_internal.h | 14 ++++- nuttx/sched/task_exithook.c | 4 ++ 6 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 nuttx/sched/group_signal.c diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 2eaa03b21..f033fc9ba 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4025,3 +4025,8 @@ poll_interrupt() must cat call net_lostconnection() when a loss of connection is reported. Otherwise, the system will not know that the connection has been lost. + * sched/group_create.c, group_join.c, and group_leave.c: Add + support for task groups. + * sched/group_signal.c and task_exithook.c: Send signal to all + members for the parent task group. + diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index a29f8dfeb..2795751ab 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -70,7 +70,7 @@ /* In any event, we don't need group members if support for pthreads is disabled */ -#ifdef CONFIG_PTHREADS_DISABLE +#ifdef CONFIG_DISABLE_PTHREAD # undef HAVE_GROUP_MEMBERS #endif diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index 6a710ff95..bbf513f34 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -87,7 +87,11 @@ SCHED_SRCS += sched_waitid.c sched_wait.c endif endif -GRP_SRCS = group_create.c group_join.c group_leave.c +GRP_SRCS = group_create.c group_join.c group_leave.c + +ifneq ($(CONFIG_DISABLE_SIGNALS),y) +GRP_SRCS += group_signal.c +endif ENV_SRCS = env_getenvironptr.c env_dup.c env_share.c env_release.c ENV_SRCS += env_findvar.c env_removevar.c diff --git a/nuttx/sched/group_signal.c b/nuttx/sched/group_signal.c new file mode 100644 index 000000000..68912fe00 --- /dev/null +++ b/nuttx/sched/group_signal.c @@ -0,0 +1,135 @@ +/***************************************************************************** + * sched/group_signal.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ + +/***************************************************************************** + * Included Files + *****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include "sig_internal.h" + +#if defined(HAVE_TASK_GROUP) && !defined(CONFIG_DISABLE_SIGNALS) + +/***************************************************************************** + * Pre-processor Definitions + *****************************************************************************/ + +/***************************************************************************** + * Private Types + *****************************************************************************/ + +/***************************************************************************** + * Private Data + *****************************************************************************/ + +/***************************************************************************** + * Private Functions + *****************************************************************************/ + +/***************************************************************************** + * Public Functions + *****************************************************************************/ + +/***************************************************************************** + * Name: group_signal + * + * Description: + * Send a signal to every member of the group to which task belongs. + * + * Parameters: + * tcb - The tcb of one task in the task group that needs to be signalled. + * + * Return Value: + * 0 (OK) on success; a negated errno value on failure. + * + * Assumptions: + * Called during task terminatino in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +int group_signal(FAR _TCB *tcb, FAR siginfo_t *info) +{ +#ifdef HAVE_GROUP_MEMBERS + FAR struct task_group_s *group; + FAR _TCB *gtcb; + int i; + + DEBUGASSERT(tcb && tcb->group && info); + group = tcb->group; + + /* Make sure that pre-emption is disabled to that we signal all of teh + * members of the group before any of them actually run. + */ + + sched_lock(); + + /* Send the signal to each member of the group */ + + for (i = 0; i < group->tg_nmembers; i++) + { + gtcb = sched_gettcb(group->tg_members[i]); + DEBUGASSERT(gtcb); + if (gtcb) + { + /* Use the sig_received interface so that it does not muck with + * the siginfo_t. + */ + +#ifdef CONFIG_DEBUG + int ret = sig_received(gtcb, info); + DEBUGASSERT(ret == 0); +#else + (void)sig_received(gtcb, info); +#endif + } + } + + /* Re-enable pre-emption an return success */ + + sched_unlock(); + return OK; +#else + return sig_received(tcb, info); +#endif +} + +#endif /* HAVE_TASK_GROUP && !CONFIG_DISABLE_SIGNALS */ diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index 8ce99bc44..599be25bb 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -275,13 +275,21 @@ int task_reparent(pid_t ppid, pid_t chpid); #ifdef HAVE_TASK_GROUP int group_allocate(FAR _TCB *tcb); int group_initialize(FAR _TCB *tcb); +int group_bind(FAR _TCB *tcb); int group_join(FAR _TCB *tcb); void group_leave(FAR _TCB *tcb); +#ifndef CONFIG_DISABLE_SIGNALS +int group_signal(FAR _TCB *tcb, FAR siginfo_t *info); +#else +# define group_signal(tcb,info) (0) +#endif #else -# define group_allocate(tcb) (0) -# define group_initialize(tcb) (0) -# define group_join(tcb) (0) +# define group_allocate(tcb) (0) +# define group_initialize(tcb) (0) +# define group_bind(tcb) (0) +# define group_join(tcb) (0) # define group_leave(tcb) +# define group_signal(tcb,info) (0) #endif #ifdef CONFIG_SCHED_CHILD_STATUS diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index 36836301c..2d596978f 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -259,7 +259,11 @@ static inline void task_sigchild(FAR _TCB *ptcb, FAR _TCB *ctcb, int status) * can provide the correct si_code value with the signal. */ +#ifdef HAVE_GROUP_MEMBERS + (void)group_signal(ptcb, &info); +#else (void)sig_received(ptcb, &info); +#endif } } #else -- cgit v1.2.3 From 239e2808cca6ee4c356d087bc83889fc57e64307 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 25 Jan 2013 23:21:27 +0000 Subject: Move environment variables in the task group structure git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5565 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 2 + nuttx/include/nuttx/sched.h | 43 +++++++-------- nuttx/sched/Makefile | 2 +- nuttx/sched/env_clearenv.c | 5 +- nuttx/sched/env_dup.c | 26 +++++---- nuttx/sched/env_dupenv.c | 112 --------------------------------------- nuttx/sched/env_findvar.c | 33 +++++------- nuttx/sched/env_getenv.c | 14 ++--- nuttx/sched/env_internal.h | 32 ++++++----- nuttx/sched/env_release.c | 68 +++++++++--------------- nuttx/sched/env_removevar.c | 56 ++++++++++---------- nuttx/sched/env_setenv.c | 59 ++++++++++----------- nuttx/sched/env_share.c | 117 ----------------------------------------- nuttx/sched/env_unsetenv.c | 62 +++++++++------------- nuttx/sched/group_create.c | 24 ++++++++- nuttx/sched/group_internal.h | 104 ++++++++++++++++++++++++++++++++++++ nuttx/sched/group_join.c | 5 +- nuttx/sched/group_leave.c | 20 +++++-- nuttx/sched/group_signal.c | 2 + nuttx/sched/os_internal.h | 38 ++----------- nuttx/sched/os_start.c | 5 +- nuttx/sched/pthread_create.c | 6 +-- nuttx/sched/sched_releasetcb.c | 6 +-- nuttx/sched/sched_waitid.c | 1 + nuttx/sched/sched_waitpid.c | 1 + nuttx/sched/sig_action.c | 1 + nuttx/sched/task_childstatus.c | 1 + nuttx/sched/task_create.c | 6 +-- nuttx/sched/task_exithook.c | 1 + nuttx/sched/task_init.c | 13 ++--- nuttx/sched/task_posixspawn.c | 1 + nuttx/sched/task_reparent.c | 1 + nuttx/sched/task_setup.c | 1 + nuttx/sched/task_vfork.c | 6 +-- 34 files changed, 347 insertions(+), 527 deletions(-) delete mode 100644 nuttx/sched/env_dupenv.c delete mode 100644 nuttx/sched/env_share.c create mode 100644 nuttx/sched/group_internal.h diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index f033fc9ba..f23a3ed73 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4029,4 +4029,6 @@ support for task groups. * sched/group_signal.c and task_exithook.c: Send signal to all members for the parent task group. + * include/nuttx/sched.h and sched/env_*.c: Move environment + variables into task group structure. diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 2795751ab..dd33b4570 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -68,6 +68,11 @@ # define HAVE_GROUP_MEMBERS 1 #endif +#if !defined(CONFIG_DISABLE_ENVIRON) +# undef HAVE_TASK_GROUP +# define HAVE_TASK_GROUP 1 +#endif + /* In any event, we don't need group members if support for pthreads is disabled */ #ifdef CONFIG_DISABLE_PTHREAD @@ -178,21 +183,6 @@ typedef CODE void (*onexitfunc_t)(int exitcode, FAR void *arg); typedef struct msgq_s msgq_t; -/* struct environ_s **************************************************************/ -/* The structure used to maintain environment variables */ - -#ifndef CONFIG_DISABLE_ENVIRON -struct environ_s -{ - unsigned int ev_crefs; /* Reference count used when environment - * is shared by threads */ - size_t ev_alloc; /* Number of bytes allocated in environment */ - char ev_env[1]; /* Environment strings */ -}; -typedef struct environ_s environ_t; -# define SIZEOF_ENVIRON_T(alloc) (sizeof(environ_t) + alloc - 1) -#endif - /* struct child_status_s *********************************************************/ /* This structure is used to maintin information about child tasks. * pthreads work differently, they have join information. This is @@ -263,11 +253,14 @@ struct dspace_s #ifdef HAVE_TASK_GROUP struct task_group_s { - uint8_t tg_flags; /* See GROUP_FLAG_* definitions */ - uint8_t tg_nmembers; /* Number of members in the group */ + uint8_t tg_flags; /* See GROUP_FLAG_* definitions */ + + /* Group membership ***********************************************************/ + + uint8_t tg_nmembers; /* Number of members in the group */ #ifdef HAVE_GROUP_MEMBERS - uint8_t tg_mxmembers; /* Number of members in allocation */ - FAR pid_t *tg_members; /* Members of the group */ + uint8_t tg_mxmembers; /* Number of members in allocation */ + FAR pid_t *tg_members; /* Members of the group */ #endif /* Child exit status **********************************************************/ @@ -276,8 +269,12 @@ struct task_group_s FAR struct child_status_s *tg_children; /* Head of a list of child status */ #endif - /* Environment varibles *******************************************************/ - /* Not yet (see type environ_t) */ + /* Environment variables ******************************************************/ + +#ifndef CONFIG_DISABLE_ENVIRON + size_t tg_envsize; /* Size of environment string allocation */ + FAR char *tg_envp; /* Allocated environment strings */ +#endif /* PIC data space and address environments */ /* Not yet (see struct dspace_s) */ @@ -373,10 +370,6 @@ struct _TCB uint8_t init_priority; /* Initial priority of the task */ char *argv[CONFIG_MAX_TASK_ARGS+1]; /* Name+start-up parameters */ -#ifndef CONFIG_DISABLE_ENVIRON - FAR environ_t *envp; /* Environment variables */ -#endif - /* Stack-Related Fields *******************************************************/ #ifndef CONFIG_CUSTOM_STACK diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index bbf513f34..6a0b99144 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -93,7 +93,7 @@ ifneq ($(CONFIG_DISABLE_SIGNALS),y) GRP_SRCS += group_signal.c endif -ENV_SRCS = env_getenvironptr.c env_dup.c env_share.c env_release.c +ENV_SRCS = env_getenvironptr.c env_dup.c env_release.c ENV_SRCS += env_findvar.c env_removevar.c ENV_SRCS += env_clearenv.c env_getenv.c env_putenv.c env_setenv.c env_unsetenv.c diff --git a/nuttx/sched/env_clearenv.c b/nuttx/sched/env_clearenv.c index 75890f3bc..a9e9f5efd 100644 --- a/nuttx/sched/env_clearenv.c +++ b/nuttx/sched/env_clearenv.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/env_clearenv.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -74,7 +74,8 @@ int clearenv(void) { - return env_release((FAR _TCB*)g_readytorun.head); + env_release((FAR _TCB*)g_readytorun.head); + return OK; } #endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/nuttx/sched/env_dup.c b/nuttx/sched/env_dup.c index 30c0b7773..479f7cae7 100644 --- a/nuttx/sched/env_dup.c +++ b/nuttx/sched/env_dup.c @@ -68,7 +68,7 @@ * exact duplicate of the parent task's environment. * * Parameters: - * ptcb The tcb to receive the newly allocated copy of the parent + * ctcb The child tcb to receive the newly allocated copy of the parent * TCB's environment structure with reference count equal to one * * Return Value: @@ -79,13 +79,14 @@ * ****************************************************************************/ -int env_dup(FAR _TCB *ptcb) +int env_dup(FAR _TCB *ctcb) { - FAR _TCB *parent = (FAR _TCB*)g_readytorun.head; - environ_t *envp = NULL; + FAR _TCB *ptcb = (FAR _TCB*)g_readytorun.head; + FAR char *envp = NULL; + size_t envlen; int ret = OK; - DEBUGASSERT(ptcb); + DEBUGASSERT(ctcb && ptcb && ctcb->group && ptcb->group); /* Pre-emption must be disabled throughout the following because the * environment may be shared. @@ -95,27 +96,24 @@ int env_dup(FAR _TCB *ptcb) /* Does the parent task have an environment? */ - if (parent->envp) + if (ptcb->group && ptcb->group->tg_envp) { /* Yes..The parent task has an environment, duplicate it */ - size_t envlen = parent->envp->ev_alloc; - envp = (environ_t*)kmalloc(SIZEOF_ENVIRON_T(envlen)); + envlen = ptcb->group->tg_envsize; + envp = (FAR char *)kmalloc(envlen); if (!envp) { ret = -ENOMEM; } else { - envp->ev_crefs = 1; - envp->ev_alloc = envlen; - memcpy(envp->ev_env, parent->envp->ev_env, envlen); + ctcb->group->tg_envsize = envlen; + ctcb->group->tg_envp = envp; + memcpy(envp, ptcb->group->tg_envp, envlen); } } - /* Save the cloned environment in the new TCB */ - - ptcb->envp = envp; sched_unlock(); return ret; } diff --git a/nuttx/sched/env_dupenv.c b/nuttx/sched/env_dupenv.c deleted file mode 100644 index 32bf6a433..000000000 --- a/nuttx/sched/env_dupenv.c +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** - * eched/env_dupenv.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#ifndef CONFIG_DISABLE_ENVIRON - -#include -#include - -#include - -#include "os_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dupenv - * - * Description: - * Copy the internal environment structure of a task. This is the action - * that is performed when a new task is created: The new task has a private, - * exact duplicate of the parent task's environment. - * - * Parameters: - * None - * - * Return Value: - * A pointer to a newly allocated copy of the specified TCB's environment - * structure with reference count equal to one. - * - * Assumptions: - * Not called from an interrupt handler. - * - ****************************************************************************/ - -FAR environ_t *dupenv(FAR _TCB *ptcb) -{ - environ_t *envp = NULL; - - /* Pre-emption must be disabled throughout the following because the - * environment may be shared. - */ - - sched_lock(); - - /* Does the parent task have an environment? */ - - if (ptcb->envp) - { - /* Yes..The parent task has an environment, duplicate it */ - - size_t envlen = ptcb->envp->ev_alloc - envp = (environ_t*)kmalloc(SIZEOF_ENVIRON_T( envlen )); - if (envp) - { - envp->ev_crefs = 1; - envp->ev_alloc = envlen; - memcmp( envp->ev_env, ptcb->envp->ev_env, envlen ); - } - } - - sched_unlock(); - return envp; -} - -#endif /* CONFIG_DISABLE_ENVIRON */ - - - diff --git a/nuttx/sched/env_findvar.c b/nuttx/sched/env_findvar.c index a8e94180c..a744c6c3a 100644 --- a/nuttx/sched/env_findvar.c +++ b/nuttx/sched/env_findvar.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/env_findvar.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -85,7 +85,7 @@ static bool env_cmpname(const char *pszname, const char *peqname) * specified name. * * Parameters: - * envp The environment structre to be searched. + * group The task group containging environment array to be searched. * pname The variable name to find * * Return Value: @@ -97,32 +97,25 @@ static bool env_cmpname(const char *pszname, const char *peqname) * ****************************************************************************/ -FAR char *env_findvar(environ_t *envp, const char *pname) +FAR char *env_findvar(FAR struct task_group_s *group, const char *pname) { - char *ret = NULL; + char *ptr; + char *end; /* Verify input parameters */ - if (envp && pname) - { - char *ptr; - char *end = &envp->ev_env[envp->ev_alloc]; - - /* Search for a name=value string with matching name */ + DEBUGASSERT(group && pname); - for (ptr = envp->ev_env; - ptr < end && !env_cmpname( pname, ptr); - ptr += (strlen(ptr) + 1)); + /* Search for a name=value string with matching name */ - /* Check for success */ + end = &group->tg_envp[group->tg_envsize]; + for (ptr = group->tg_envp; + ptr < end && !env_cmpname(pname, ptr); + ptr += (strlen(ptr) + 1)); - if (ptr < end) - { - ret = ptr; - } - } + /* Check for success */ - return ret; + return (ptr < end) ? ptr : NULL; } #endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/nuttx/sched/env_getenv.c b/nuttx/sched/env_getenv.c index ee8d798b1..4709bc380 100644 --- a/nuttx/sched/env_getenv.c +++ b/nuttx/sched/env_getenv.c @@ -1,7 +1,7 @@ /**************************************************************************** * env_getenv.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -77,10 +77,10 @@ FAR char *getenv(const char *name) { - FAR _TCB *rtcb; - FAR environ_t *envp; - FAR char *pvar; - FAR char *pvalue = NULL; + FAR _TCB *rtcb; + FAR struct task_group_s *group; + FAR char *pvar; + FAR char *pvalue = NULL; int ret = OK; /* Verify that a string was passed */ @@ -95,11 +95,11 @@ FAR char *getenv(const char *name) sched_lock(); rtcb = (FAR _TCB*)g_readytorun.head; - envp = rtcb->envp; + group = rtcb->group; /* Check if the variable exists */ - if ( !envp || (pvar = env_findvar(envp, name)) == NULL) + if ( !group || (pvar = env_findvar(group, name)) == NULL) { ret = ENOENT; goto errout_with_lock; diff --git a/nuttx/sched/env_internal.h b/nuttx/sched/env_internal.h index 5370da059..6f1097c0b 100644 --- a/nuttx/sched/env_internal.h +++ b/nuttx/sched/env_internal.h @@ -1,7 +1,7 @@ /**************************************************************************** * sched/env_internal.h * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -50,9 +50,8 @@ #ifdef CONFIG_DISABLE_ENVIRON # define env_dup(ptcb) (0) -# define env_share(ptcb) (0) # define env_release(ptcb) (0) -#endif +#else /**************************************************************************** * Public Type Declarations @@ -62,34 +61,33 @@ * Public Variables ****************************************************************************/ -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - #ifdef __cplusplus #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif -#ifndef CONFIG_DISABLE_ENVIRON -/* functions used by the task/pthread creation and destruction logic */ +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ -EXTERN int env_dup(FAR _TCB *ptcb); -EXTERN int env_share(FAR _TCB *ptcb); -EXTERN int env_release(FAR _TCB *ptcb); +/* Functions used by the task/pthread creation and destruction logic */ -/* functions used internally by the environment handling logic */ +int env_dup(FAR _TCB *ctcb); +void env_release(FAR _TCB *tcb); -EXTERN FAR char *env_findvar(environ_t *envp, const char *pname); -EXTERN int env_removevar(environ_t *envp, char *pvar); -#endif +/* Functions used internally by the environment handling logic */ + +FAR char *env_findvar(FAR struct task_group_s *group, FAR const char *pname); +int env_removevar(FAR struct task_group_s *group, FAR char *pvar); #undef EXTERN #ifdef __cplusplus } #endif +#endif /* !CONFIG_DISABLE_ENVIRON */ #endif /* __SCHED_ENV_INTERNAL_H */ diff --git a/nuttx/sched/env_release.c b/nuttx/sched/env_release.c index 8bc8d2205..4de55c388 100644 --- a/nuttx/sched/env_release.c +++ b/nuttx/sched/env_release.c @@ -1,7 +1,7 @@ /**************************************************************************** - * sched/env_clearenv.c + * sched/env_release.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -58,65 +58,45 @@ * Name: env_release * * Description: - * The env_release() function clears the environment of all name-value - * pairs and sets the value of the external variable environ to NULL. + * env_release() is called only from group_leave() when the last member of + * a task group exits. The env_release() function clears the environment + * of all name-value pairs and sets the value of the external variable + * environ to NULL. * * Parameters: - * ptcb Identifies the TCB containing the environment structure + * tcb Identifies the TCB containing the environment structure to be + * released. * * Return Value: - * zero on success + * None * * Assumptions: * Not called from an interrupt handler * ****************************************************************************/ -int env_release(FAR _TCB *ptcb) +void env_release(FAR _TCB *tcb) { - int ret = OK; + FAR struct task_group_s *group; - if (!ptcb) - { - ret = -EINVAL; - } - else - { - FAR environ_t *envp; - - /* Examine the environ data in the TCB. Preemption is disabled because the - * the environment could be shared among threads. - */ - - sched_lock(); - envp = ptcb->envp; - if (ptcb->envp) - { - /* Check the reference count on the environment structure */ + DEBUGASSERT(tcb && tcb->group); + group = tcb->group; - if (envp->ev_crefs <= 1) - { - /* Decrementing the reference count will destroy the environment */ + /* Free any allocate environment strings */ - sched_free(envp); - } - else - { - /* The environment will persist after decrementing the reference - * count */ - - envp->ev_crefs--; - } - - /* In any case, the environment is no longer accessible on this thread */ - - ptcb->envp = NULL; - } + if (group->tg_envp) + { + /* Free the environment */ - sched_unlock(); + sched_free(group->tg_envp); } - return ret; + /* In any event, make sure that all environment-related varialbles in the + * task group structure are reset to initial values. + */ + + group->tg_envsize = 0; + group->tg_envp = NULL; } #endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/nuttx/sched/env_removevar.c b/nuttx/sched/env_removevar.c index e96aa7a37..811e6079e 100644 --- a/nuttx/sched/env_removevar.c +++ b/nuttx/sched/env_removevar.c @@ -59,7 +59,7 @@ * Remove the referenced name=value pair from the environment * * Parameters: - * envp The environment containing the name=value pair + * group The task group with the environment containing the name=value pair * pvar A pointer to the name=value pair in the restroom * * Return Value: @@ -72,42 +72,44 @@ * ****************************************************************************/ -int env_removevar(environ_t *envp, char *pvar) +int env_removevar(FAR struct task_group_s *group, FAR char *pvar) { + FAR char *end; /* Pointer to the end+1 of the environment */ + int alloc; /* Size of the allocated environment */ int ret = ERROR; - if (envp && pvar) - { - /* Verify that the pointer lies within the environment region */ - int alloc = envp->ev_alloc; /* Size of the allocated environment */ - char *end = &envp->ev_env[alloc]; /* Pointer to the end+1 of the environment */ + DEBUGASSERT(group && pvar); - if (pvar >= envp->ev_env && pvar < end) - { - /* Set up for the removal */ + /* Verify that the pointer lies within the environment region */ - int len = strlen(pvar) + 1; /* Length of name=value string to remove */ - char *src = &pvar[len]; /* Address of name=value string after */ - char *dest = pvar; /* Location to move the next string */ - int count = end - src; /* Number of bytes to move (might be zero) */ + alloc = group->tg_envsize; /* Size of the allocated environment */ + end = &group->tg_envp[alloc]; /* Pointer to the end+1 of the environment */ - /* Move all of the environment strings after the removed one 'down.' - * this is inefficient, but robably not high duty. - */ + if (pvar >= group->tg_envp && pvar < end) + { + /* Set up for the removal */ - while (count-- > 0) - { - *dest++ = *src++; - } + int len = strlen(pvar) + 1; /* Length of name=value string to remove */ + char *src = &pvar[len]; /* Address of name=value string after */ + char *dest = pvar; /* Location to move the next string */ + int count = end - src; /* Number of bytes to move (might be zero) */ - /* Then set to the new allocation size. The caller is expected to - * call realloc at some point but we don't do that here because the - * caller may add more stuff to the environment. - */ + /* Move all of the environment strings after the removed one 'down.' + * this is inefficient, but robably not high duty. + */ - envp->ev_alloc -= len; - ret = OK; + while (count-- > 0) + { + *dest++ = *src++; } + + /* Then set to the new allocation size. The caller is expected to + * call realloc at some point but we don't do that here because the + * caller may add more stuff to the environment. + */ + + group->tg_envsize -= len; + ret = OK; } return ret; diff --git a/nuttx/sched/env_setenv.c b/nuttx/sched/env_setenv.c index c186241ef..cfde71604 100644 --- a/nuttx/sched/env_setenv.c +++ b/nuttx/sched/env_setenv.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/env_setenv.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -83,12 +83,14 @@ * ****************************************************************************/ -int setenv(const char *name, const char *value, int overwrite) +int setenv(FAR const char *name, FAR const char *value, int overwrite) { - FAR _TCB *rtcb; - FAR environ_t *envp; - FAR char *pvar; - int varlen; + FAR _TCB *rtcb; + FAR struct task_group_s *group; + FAR char *pvar; + FAR char *newenvp; + int newsize; + int varlen; int ret = OK; /* Verify input parameter */ @@ -122,14 +124,15 @@ int setenv(const char *name, const char *value, int overwrite) /* Get a reference to the thread-private environ in the TCB.*/ sched_lock(); - rtcb = (FAR _TCB*)g_readytorun.head; - envp = rtcb->envp; + rtcb = (FAR _TCB*)g_readytorun.head; + group = rtcb->group; + DEBUGASSERT(group); - /* Check if the variable alreay exists */ + /* Check if the variable already exists */ - if ( envp && (pvar = env_findvar(envp, name)) != NULL) + if (group->tg_envp && (pvar = env_findvar(group, name)) != NULL) { - /* It does! Do we have permission to overwrite the existing value? */ + /* It does! Do we have permission to overwrite the existing value? */ if (!overwrite) { @@ -144,7 +147,7 @@ int setenv(const char *name, const char *value, int overwrite) * the environment buffer; this will happen below. */ - (void)env_removevar(envp, pvar); + (void)env_removevar(group, pvar); } /* Get the size of the new name=value string. The +2 is for the '=' and for @@ -155,43 +158,39 @@ int setenv(const char *name, const char *value, int overwrite) /* Then allocate or reallocate the environment buffer */ - if (envp) + if (group->tg_envp) { - int alloc = envp->ev_alloc; - environ_t *tmp = (environ_t*)krealloc(envp, SIZEOF_ENVIRON_T(alloc + varlen)); - if (!tmp) + newsize = group->tg_envsize + varlen; + newenvp = (FAR char *)krealloc(group->tg_envp, newsize); + if (!newenvp) { ret = ENOMEM; goto errout_with_lock; } - envp = tmp; - envp->ev_alloc = alloc + varlen; - pvar = &envp->ev_env[alloc]; + pvar = &newenvp[group->tg_envsize]; } else { - envp = (environ_t*)kmalloc(SIZEOF_ENVIRON_T(varlen)); - if (!envp) + newsize = varlen; + newenvp = (FAR char *)kmalloc(varlen); + if (!newenvp) { ret = ENOMEM; goto errout_with_lock; } - envp->ev_crefs = 1; - envp->ev_alloc = varlen; - pvar = envp->ev_env; + pvar = newenvp; } - /* Now, put the new name=value string into the environment buffer */ + /* Save the new buffer and size */ - sprintf(pvar, "%s=%s", name, value); + group->tg_envp = newenvp; + group->tg_envsize = newsize; - /* Save the new environment pointer (it might have changed due to allocation or - * reallocation. - */ + /* Now, put the new name=value string into the environment buffer */ - rtcb->envp = envp; + sprintf(pvar, "%s=%s", name, value); sched_unlock(); return OK; diff --git a/nuttx/sched/env_share.c b/nuttx/sched/env_share.c deleted file mode 100644 index 5f37a0219..000000000 --- a/nuttx/sched/env_share.c +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** - * sched/env_share.c - * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#ifndef CONFIG_DISABLE_ENVIRON - -#include -#include - -#include "os_internal.h" -#include "env_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: env_share - * - * Description: - * Increment the reference count on the internal environment structure of - * a task. This is the action that is performed when a new pthread is - * created: The new pthread shares the environment with its parent. - * - * Parameters: - * ptcb The new TCB to receive the shared environment. - * - * Return Value: - * A pointer to a specified TCB's environment structure with an incremented - * reference count. - * - * Assumptions: - * Not called from an interrupt handler. - * - ****************************************************************************/ - -int env_share(FAR _TCB *ptcb) -{ - int ret = OK; - if (!ptcb) - { - ret = -EINVAL; - } - else - { - FAR _TCB *parent = (FAR _TCB*)g_readytorun.head; - environ_t *envp = parent->envp; - - /* Pre-emption must be disabled throughout the following because the - * environment is shared. - */ - - sched_lock(); - - /* Does the parent task have an environment? */ - - if (envp) - { - /* Yes.. increment the reference count on the environment */ - - envp->ev_crefs++; - } - - /* Then share the environment */ - - ptcb->envp = envp; - sched_unlock(); - } - - return ret; -} - -#endif /* CONFIG_DISABLE_ENVIRON */ - - - diff --git a/nuttx/sched/env_unsetenv.c b/nuttx/sched/env_unsetenv.c index 52469fac9..8206a4ece 100644 --- a/nuttx/sched/env_unsetenv.c +++ b/nuttx/sched/env_unsetenv.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/env_unsetenv.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -75,61 +75,47 @@ * ****************************************************************************/ -int unsetenv(const char *name) +int unsetenv(FAR const char *name) { - FAR _TCB *rtcb; - FAR environ_t *envp; - FAR char *pvar; + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + FAR struct task_group_s *group = rtcb->group; + FAR char *pvar; + FAR char *newenvp; + int newsize; int ret = OK; - /* Verify input parameter */ - - if (!name) - { - ret = EINVAL; - goto errout; - } - - /* Get a reference to the thread-private environ in the TCB.*/ - - sched_lock(); - rtcb = (FAR _TCB*)g_readytorun.head; - envp = rtcb->envp; + DEBUGASSERT(name && group); /* Check if the variable exists */ - if ( envp && (pvar = env_findvar(envp, name)) != NULL) + sched_lock(); + if (group && (pvar = env_findvar(group, name)) != NULL) { - int alloc; - environ_t *tmp; - /* It does! Remove the name=value pair from the environment. */ - (void)env_removevar(envp, pvar); + (void)env_removevar(group, pvar); /* Reallocate the new environment buffer */ - alloc = envp->ev_alloc; - tmp = (environ_t*)krealloc(envp, SIZEOF_ENVIRON_T(alloc)); - if (!tmp) + newsize = group->tg_envsize; + newenvp = (FAR char *)krealloc(group->tg_envp, newsize); + if (!newenvp) { - ret = ENOMEM; - goto errout_with_lock; + set_errno(ENOMEM); + ret = ERROR; } + else + { + /* Save the new environment pointer (it might have changed due to + * reallocation. + */ - /* Save the new environment pointer (it might have changed due to reallocation. */ - - rtcb->envp = tmp; + group->tg_envp = newenvp; + } } sched_unlock(); - return OK; - -errout_with_lock: - sched_unlock(); -errout: - errno = ret; - return ERROR; + return ret; } #endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/nuttx/sched/group_create.c b/nuttx/sched/group_create.c index 4612ae8c5..da91fa065 100644 --- a/nuttx/sched/group_create.c +++ b/nuttx/sched/group_create.c @@ -46,6 +46,9 @@ #include +#include "group_internal.h" +#include "env_internal.h" + #ifdef HAVE_TASK_GROUP /***************************************************************************** @@ -97,12 +100,29 @@ int group_allocate(FAR _TCB *tcb) { + int ret; + DEBUGASSERT(tcb && !tcb->group); /* Allocate the group structure and assign it to the TCB */ tcb->group = (FAR struct task_group_s *)kzalloc(sizeof(struct task_group_s)); - return tcb->group ? OK : -ENOMEM; + if (!tcb->group) + { + return -ENOMEM; + } + + /* Duplicate the parent tasks envionment */ + + ret = env_dup(tcb); + if (ret < 0) + { + kfree(tcb->group); + tcb->group = NULL; + return ret; + } + + return OK; } /***************************************************************************** @@ -128,12 +148,12 @@ int group_allocate(FAR _TCB *tcb) int group_initialize(FAR _TCB *tcb) { -#ifdef HAVE_GROUP_MEMBERS FAR struct task_group_s *group; DEBUGASSERT(tcb && tcb->group); group = tcb->group; +#ifdef HAVE_GROUP_MEMBERS /* Allocate space to hold GROUP_INITIAL_MEMBERS members of the group */ group->tg_members = (FAR pid_t *)kmalloc(GROUP_INITIAL_MEMBERS*sizeof(pid_t)); diff --git a/nuttx/sched/group_internal.h b/nuttx/sched/group_internal.h new file mode 100644 index 000000000..aa8476e3c --- /dev/null +++ b/nuttx/sched/group_internal.h @@ -0,0 +1,104 @@ +/**************************************************************************** + * sched/group_internal.h + * + * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __SCHED_GROUP_INERNAL_H +#define __SCHED_GROUP_INERNAL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ +/* Task group data structure management */ + +#ifdef HAVE_TASK_GROUP +int group_allocate(FAR _TCB *tcb); +int group_initialize(FAR _TCB *tcb); +int group_bind(FAR _TCB *tcb); +int group_join(FAR _TCB *tcb); +void group_leave(FAR _TCB *tcb); +#ifndef CONFIG_DISABLE_SIGNALS +int group_signal(FAR _TCB *tcb, FAR siginfo_t *info); +#else +# define group_signal(tcb,info) (0) +#endif +#else +# define group_allocate(tcb) (0) +# define group_initialize(tcb) (0) +# define group_bind(tcb) (0) +# define group_join(tcb) (0) +# define group_leave(tcb) +# define group_signal(tcb,info) (0) +#endif /* HAVE_TASK_GROUP */ + +/* Parent/child data management */ + +#ifdef CONFIG_SCHED_HAVE_PARENT +int task_reparent(pid_t ppid, pid_t chpid); + +#ifdef CONFIG_SCHED_CHILD_STATUS +FAR struct child_status_s *task_allocchild(void); +void task_freechild(FAR struct child_status_s *status); +void task_addchild(FAR _TCB *tcb, FAR struct child_status_s *child); +FAR struct child_status_s *task_exitchild(FAR _TCB *tcb); +FAR struct child_status_s *task_findchild(FAR _TCB *tcb, pid_t pid); +FAR struct child_status_s *task_removechild(FAR _TCB *tcb, pid_t pid); +void task_removechildren(FAR _TCB *tcb); +#endif +#endif /* CONFIG_SCHED_HAVE_PARENT */ + +#endif /* __SCHED_GROUP_INERNAL_H */ diff --git a/nuttx/sched/group_join.c b/nuttx/sched/group_join.c index 9dcea6599..077c45763 100644 --- a/nuttx/sched/group_join.c +++ b/nuttx/sched/group_join.c @@ -46,7 +46,8 @@ #include -#include "os_internal.h" +#include "group_internal.h" +#include "env_internal.h" #ifdef HAVE_TASK_GROUP @@ -137,7 +138,6 @@ int group_bind(FAR _TCB *tcb) int group_join(FAR _TCB *tcb) { -#ifdef HAVE_GROUP_MEMBERS FAR struct task_group_s *group; DEBUGASSERT(tcb && tcb->group && @@ -147,6 +147,7 @@ int group_join(FAR _TCB *tcb) group = tcb->group; +#ifdef HAVE_GROUP_MEMBERS /* Will we need to extend the size of the array of groups? */ if (group->tg_nmembers >= group->tg_mxmembers) diff --git a/nuttx/sched/group_leave.c b/nuttx/sched/group_leave.c index 223af1556..d5fa9dbaf 100644 --- a/nuttx/sched/group_leave.c +++ b/nuttx/sched/group_leave.c @@ -44,7 +44,8 @@ #include #include -#include "os_internal.h" +#include "group_internal.h" +#include "env_internal.h" #ifdef HAVE_TASK_GROUP @@ -92,7 +93,6 @@ void group_leave(FAR _TCB *tcb) { FAR struct task_group_s *group; - int i; DEBUGASSERT(tcb); @@ -102,6 +102,8 @@ void group_leave(FAR _TCB *tcb) if (group) { #ifdef HAVE_GROUP_MEMBERS + int i; + /* Find the member in the array of members and remove it */ for (i = 0; i < group->tg_nmembers; i++) @@ -142,8 +144,14 @@ void group_leave(FAR _TCB *tcb) /* Release all of the resource contained within the group */ /* Free all un-reaped child exit status */ - task_removechildren(tcb); +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) + task_removechildren(tcb); +#endif + /* Release all shared environment variables */ +#ifndef CONFIG_DISABLE_ENVIRON + env_release(tcb); +#endif /* Release the group container itself */ sched_free(group); @@ -166,8 +174,14 @@ void group_leave(FAR _TCB *tcb) /* Release all of the resource contained within the group */ /* Free all un-reaped child exit status */ +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) task_removechildren(tcb); +#endif + /* Release all shared environment variables */ +#ifndef CONFIG_DISABLE_ENVIRON + env_release(tcb); +#endif /* Release the group container itself */ sched_free(group); diff --git a/nuttx/sched/group_signal.c b/nuttx/sched/group_signal.c index 68912fe00..5020ec436 100644 --- a/nuttx/sched/group_signal.c +++ b/nuttx/sched/group_signal.c @@ -44,6 +44,8 @@ #include #include +#include "os_internal.h" +#include "group_internal.h" #include "sig_internal.h" #if defined(HAVE_TASK_GROUP) && !defined(CONFIG_DISABLE_SIGNALS) diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index 599be25bb..e3d0fd48f 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -262,6 +262,9 @@ extern const tasklist_t g_tasklisttable[NUM_TASK_STATES]; ****************************************************************************/ int os_bringup(void); +#ifdef CONFIG_SCHED_CHILD_STATUS +void weak_function task_initialize(void); +#endif void task_start(void); int task_schedsetup(FAR _TCB *tcb, int priority, start_t start, main_t main, uint8_t ttype); @@ -269,41 +272,6 @@ int task_argsetup(FAR _TCB *tcb, FAR const char *name, FAR const char *argv[]); void task_exithook(FAR _TCB *tcb, int status); int task_deletecurrent(void); -#ifdef CONFIG_SCHED_HAVE_PARENT -int task_reparent(pid_t ppid, pid_t chpid); - -#ifdef HAVE_TASK_GROUP -int group_allocate(FAR _TCB *tcb); -int group_initialize(FAR _TCB *tcb); -int group_bind(FAR _TCB *tcb); -int group_join(FAR _TCB *tcb); -void group_leave(FAR _TCB *tcb); -#ifndef CONFIG_DISABLE_SIGNALS -int group_signal(FAR _TCB *tcb, FAR siginfo_t *info); -#else -# define group_signal(tcb,info) (0) -#endif -#else -# define group_allocate(tcb) (0) -# define group_initialize(tcb) (0) -# define group_bind(tcb) (0) -# define group_join(tcb) (0) -# define group_leave(tcb) -# define group_signal(tcb,info) (0) -#endif - -#ifdef CONFIG_SCHED_CHILD_STATUS -void weak_function task_initialize(void); -FAR struct child_status_s *task_allocchild(void); -void task_freechild(FAR struct child_status_s *status); -void task_addchild(FAR _TCB *tcb, FAR struct child_status_s *child); -FAR struct child_status_s *task_exitchild(FAR _TCB *tcb); -FAR struct child_status_s *task_findchild(FAR _TCB *tcb, pid_t pid); -FAR struct child_status_s *task_removechild(FAR _TCB *tcb, pid_t pid); -void task_removechildren(FAR _TCB *tcb); -#endif -#endif - #ifndef CONFIG_CUSTOM_STACK int kernel_thread(FAR const char *name, int priority, int stack_size, main_t entry, FAR const char *argv[]); diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c index 3aecc7efb..b2551d2a3 100644 --- a/nuttx/sched/os_start.c +++ b/nuttx/sched/os_start.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/os_start.c * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -63,6 +63,9 @@ #include "clock_internal.h" #include "timer_internal.h" #include "irq_internal.h" +#ifdef HAVE_TASK_GROUP +#include "group_internal.h" +#endif /**************************************************************************** * Pre-processor Definitions diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c index 89a2feb00..9fd6a4a61 100644 --- a/nuttx/sched/pthread_create.c +++ b/nuttx/sched/pthread_create.c @@ -53,8 +53,8 @@ #include #include "os_internal.h" +#include "group_internal.h" #include "clock_internal.h" -#include "env_internal.h" #include "pthread_internal.h" /**************************************************************************** @@ -305,10 +305,6 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, goto errout_with_tcb; } - /* Share the parent's envionment */ - - (void)env_share(ptcb); - /* Allocate a detachable structure to support pthread_join logic */ pjoin = (FAR join_t*)kzalloc(sizeof(join_t)); diff --git a/nuttx/sched/sched_releasetcb.c b/nuttx/sched/sched_releasetcb.c index 50505f579..00d4c2c0c 100644 --- a/nuttx/sched/sched_releasetcb.c +++ b/nuttx/sched/sched_releasetcb.c @@ -45,8 +45,8 @@ #include #include "os_internal.h" +#include "group_internal.h" #include "timer_internal.h" -#include "env_internal.h" /************************************************************************ * Private Functions @@ -167,10 +167,6 @@ int sched_releasetcb(FAR _TCB *tcb) ret = sched_releasefiles(tcb); - /* Release environment variables */ - - (void)env_release(tcb); - /* Release this thread's reference to the address environment */ #ifdef CONFIG_ADDRENV diff --git a/nuttx/sched/sched_waitid.c b/nuttx/sched/sched_waitid.c index e47e3c38c..41e488f90 100644 --- a/nuttx/sched/sched_waitid.c +++ b/nuttx/sched/sched_waitid.c @@ -46,6 +46,7 @@ #include #include "os_internal.h" +#include "group_internal.h" #if defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT) diff --git a/nuttx/sched/sched_waitpid.c b/nuttx/sched/sched_waitpid.c index 2d0fe2e48..4af7f7ef3 100644 --- a/nuttx/sched/sched_waitpid.c +++ b/nuttx/sched/sched_waitpid.c @@ -47,6 +47,7 @@ #include #include "os_internal.h" +#include "group_internal.h" #ifdef CONFIG_SCHED_WAITPID diff --git a/nuttx/sched/sig_action.c b/nuttx/sched/sig_action.c index b307c1fb6..fe72cc22d 100644 --- a/nuttx/sched/sig_action.c +++ b/nuttx/sched/sig_action.c @@ -46,6 +46,7 @@ #include #include "os_internal.h" +#include "group_internal.h" #include "sig_internal.h" /**************************************************************************** diff --git a/nuttx/sched/task_childstatus.c b/nuttx/sched/task_childstatus.c index aff2bdf3a..c0df3d534 100644 --- a/nuttx/sched/task_childstatus.c +++ b/nuttx/sched/task_childstatus.c @@ -44,6 +44,7 @@ #include #include "os_internal.h" +#include "group_internal.h" #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c index bb309444b..85c0f5e92 100644 --- a/nuttx/sched/task_create.c +++ b/nuttx/sched/task_create.c @@ -48,7 +48,7 @@ #include #include "os_internal.h" -#include "env_internal.h" +#include "group_internal.h" /**************************************************************************** * Definitions @@ -142,10 +142,6 @@ static int thread_create(const char *name, uint8_t ttype, int priority, } #endif - /* Clone the parent's task environment */ - - (void)env_dup(tcb); - /* Allocate the stack for the TCB */ #ifndef CONFIG_CUSTOM_STACK diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index 2d596978f..cbada851a 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -49,6 +49,7 @@ #include #include "os_internal.h" +#include "group_internal.h" #include "sig_internal.h" /**************************************************************************** diff --git a/nuttx/sched/task_init.c b/nuttx/sched/task_init.c index 6ae643948..8dfd8b7f6 100644 --- a/nuttx/sched/task_init.c +++ b/nuttx/sched/task_init.c @@ -47,7 +47,7 @@ #include #include "os_internal.h" -#include "env_internal.h" +#include "group_internal.h" /**************************************************************************** * Definitions @@ -145,10 +145,6 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, } #endif - /* Clone the parent's task environment */ - - (void)env_dup(tcb); - /* Configure the user provided stack region */ #ifndef CONFIG_CUSTOM_STACK @@ -162,7 +158,7 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, if (ret < OK) { errcode = -ret; - goto errout_with_env; + goto errout_with_group; } /* Setup to pass parameters to the new task */ @@ -176,14 +172,11 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, if (ret < 0) { errcode = -ret; - goto errout_with_env; + goto errout_with_group; } #endif return OK; -errout_with_env: - env_release(tcb); - errout_with_group: #ifdef HAVE_TASK_GROUP group_leave(tcb); diff --git a/nuttx/sched/task_posixspawn.c b/nuttx/sched/task_posixspawn.c index 7bb9c9a4d..e9ad1fc45 100644 --- a/nuttx/sched/task_posixspawn.c +++ b/nuttx/sched/task_posixspawn.c @@ -54,6 +54,7 @@ #include #include "os_internal.h" +#include "group_internal.h" /**************************************************************************** * Private Types diff --git a/nuttx/sched/task_reparent.c b/nuttx/sched/task_reparent.c index 0b502dcce..1193c9a7f 100644 --- a/nuttx/sched/task_reparent.c +++ b/nuttx/sched/task_reparent.c @@ -42,6 +42,7 @@ #include #include "os_internal.h" +#include "group_internal.h" #ifdef CONFIG_SCHED_HAVE_PARENT diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c index 7675c7481..b66f3cc7c 100644 --- a/nuttx/sched/task_setup.c +++ b/nuttx/sched/task_setup.c @@ -49,6 +49,7 @@ #include #include "os_internal.h" +#include "group_internal.h" /**************************************************************************** * Definitions diff --git a/nuttx/sched/task_vfork.c b/nuttx/sched/task_vfork.c index fece4c596..3f058bdec 100644 --- a/nuttx/sched/task_vfork.c +++ b/nuttx/sched/task_vfork.c @@ -48,7 +48,7 @@ #include #include "os_internal.h" -#include "env_internal.h" +#include "group_internal.h" /**************************************************************************** * Pre-processor Definitions @@ -132,10 +132,6 @@ FAR _TCB *task_vforksetup(start_t retaddr) } #endif - /* Clone the parent's task environment */ - - (void)env_dup(child); - /* Get the priority of the parent task */ #ifdef CONFIG_PRIORITY_INHERITANCE -- cgit v1.2.3 From a1aa13f62853491f8bd96a3dea0f0427fa83ad05 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 26 Jan 2013 17:28:20 +0000 Subject: Don't keep the parent task's task ID in the child task's TCB. Instead, keep the parent task group IN the child task's task group. git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5566 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 4 +- nuttx/include/nuttx/sched.h | 12 +- nuttx/sched/Makefile | 16 +- nuttx/sched/group_childstatus.c | 441 ++++++++++++++++++++++++++++++++++++++++ nuttx/sched/group_create.c | 99 ++++++++- nuttx/sched/group_find.c | 125 ++++++++++++ nuttx/sched/group_internal.h | 71 +++++-- nuttx/sched/group_join.c | 48 ++++- nuttx/sched/group_leave.c | 212 ++++++++++++++----- nuttx/sched/group_signal.c | 40 +++- nuttx/sched/sched_waitid.c | 22 +- nuttx/sched/sched_waitpid.c | 40 ++-- nuttx/sched/sig_action.c | 2 +- nuttx/sched/task_childstatus.c | 440 --------------------------------------- nuttx/sched/task_exithook.c | 175 ++++++++++++---- nuttx/sched/task_reparent.c | 156 +++++++++++++- nuttx/sched/task_setup.c | 32 ++- 17 files changed, 1322 insertions(+), 613 deletions(-) create mode 100644 nuttx/sched/group_childstatus.c create mode 100644 nuttx/sched/group_find.c delete mode 100644 nuttx/sched/task_childstatus.c diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index f23a3ed73..858f82819 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4031,4 +4031,6 @@ members for the parent task group. * include/nuttx/sched.h and sched/env_*.c: Move environment variables into task group structure. - + * sched/: Lots of file changed. Don't keep the parent task's + task ID in the child task's TCB. Instead, keep the parent + task group IN the child task's task group. diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index dd33b4570..8ebb7db4c 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -95,6 +95,7 @@ #define TCB_FLAG_NONCANCELABLE (1 << 2) /* Bit 2: Pthread is non-cancelable */ #define TCB_FLAG_CANCEL_PENDING (1 << 3) /* Bit 3: Pthread cancel is pending */ #define TCB_FLAG_ROUND_ROBIN (1 << 4) /* Bit 4: Round robin sched enabled */ +#define TCB_FLAG_EXIT_PROCESSING (1 << 5) /* Bit 5: Exitting */ /* Values for struct task_group tg_flags */ @@ -253,6 +254,11 @@ struct dspace_s #ifdef HAVE_TASK_GROUP struct task_group_s { +#ifdef HAVE_GROUP_MEMBERS + struct task_group_s *flink; /* Supports a singly linked list */ + gid_t tg_gid; /* The ID of this task group */ + gid_t tg_pgid; /* The ID of the parent task group */ +#endif uint8_t tg_flags; /* See GROUP_FLAG_* definitions */ /* Group membership ***********************************************************/ @@ -311,12 +317,16 @@ struct _TCB /* Task Management Fields *****************************************************/ pid_t pid; /* This is the ID of the thread */ + #ifdef CONFIG_SCHED_HAVE_PARENT /* Support parent-child relationship */ - pid_t parent; /* This is the ID of the parent thread */ +#ifndef HAVE_GROUP_MEMBERS /* Don't know pids of group members */ + pid_t ppid; /* This is the ID of the parent thread */ #ifndef CONFIG_SCHED_CHILD_STATUS /* Retain child thread status */ uint16_t nchildren; /* This is the number active children */ #endif #endif +#endif /* CONFIG_SCHED_HAVE_PARENT */ + start_t start; /* Thread start function */ entry_t entry; /* Entry Point into the thread */ diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index 6a0b99144..d059152e0 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -73,13 +73,6 @@ ifeq ($(CONFIG_PRIORITY_INHERITANCE),y) SCHED_SRCS += sched_reprioritize.c endif -ifeq ($(CONFIG_SCHED_HAVE_PARENT),y) -SCHED_SRCS += task_reparent.c -ifeq ($(CONFIG_SCHED_CHILD_STATUS),y) -SCHED_SRCS += task_childstatus.c -endif -endif - ifeq ($(CONFIG_SCHED_WAITPID),y) SCHED_SRCS += sched_waitpid.c ifeq ($(CONFIG_SCHED_HAVE_PARENT),y) @@ -87,7 +80,14 @@ SCHED_SRCS += sched_waitid.c sched_wait.c endif endif -GRP_SRCS = group_create.c group_join.c group_leave.c +GRP_SRCS = group_create.c group_join.c group_leave.c group_find.c + +ifeq ($(CONFIG_SCHED_HAVE_PARENT),y) +GRP_SRCS += task_reparent.c +ifeq ($(CONFIG_SCHED_CHILD_STATUS),y) +GRP_SRCS += group_childstatus.c +endif +endif ifneq ($(CONFIG_DISABLE_SIGNALS),y) GRP_SRCS += group_signal.c diff --git a/nuttx/sched/group_childstatus.c b/nuttx/sched/group_childstatus.c new file mode 100644 index 000000000..ef42b6c34 --- /dev/null +++ b/nuttx/sched/group_childstatus.c @@ -0,0 +1,441 @@ +/***************************************************************************** + * sched/group_childstatus.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ + +/***************************************************************************** + * Included Files + *****************************************************************************/ + +#include + +#include +#include +#include + +#include "os_internal.h" +#include "group_internal.h" + +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) + +/***************************************************************************** + * Pre-processor Definitions + *****************************************************************************/ +/* Note that there cannot be more that CONFIG_MAX_TASKS tasks in total. + * However, the number of child status structures may need to be significantly + * larger because this number includes the maximum number of tasks that are + * running PLUS the number of tasks that have exit'ed without having their + * exit status reaped (via wait(), waitid(), or waitpid()). + * + * Obviously, if tasks spawn children indefinitely and never have the exit + * status reaped, then you have a memory leak! + */ + +#if !defined(CONFIG_PREALLOC_CHILDSTATUS) || CONFIG_PREALLOC_CHILDSTATUS == 0 +# undef CONFIG_PREALLOC_CHILDSTATUS +# define CONFIG_PREALLOC_CHILDSTATUS (2*CONFIG_MAX_TASKS) +#endif + +#ifndef CONFIG_DEBUG +# undef CONFIG_DEBUG_CHILDSTATUS +#endif + +/***************************************************************************** + * Private Types + *****************************************************************************/ +/* Globals are maintained in a structure to minimize name collisions. */ + +struct child_pool_s +{ + struct child_status_s alloc[CONFIG_PREALLOC_CHILDSTATUS]; + FAR struct child_status_s *freelist; +}; + +/***************************************************************************** + * Private Data + *****************************************************************************/ + +static struct child_pool_s g_child_pool; + +/***************************************************************************** + * Private Functions + *****************************************************************************/ + +/***************************************************************************** + * Name: group_dumpchildren + * + * Description: + * Dump all of the children when the part TCB list is modified. + * + * Parameters: + * group - The task group containing the child status. + * + * Return Value: + * None. + * + * Assumptions: + * Called early in initialization. No special precautions are required. + * + *****************************************************************************/ + +#ifdef CONFIG_DEBUG_CHILDSTATUS +static void group_dumpchildren(FAR struct task_group_s *group, + FAR const char *msg) +{ + FAR struct child_status_s *child; + int i; + + dbg("Task group=%p: %s\n", group, msg); + for (i = 0, child = group->tg_children; child; i++, child = child->flink) + { + dbg(" %d. ch_flags=%02x ch_pid=%d ch_status=%d\n", + i, child->ch_flags, child->ch_pid, child->ch_status); + } +} +#else +# define group_dumpchildren(t,m) +#endif + +/***************************************************************************** + * Public Functions + *****************************************************************************/ + +/***************************************************************************** + * Name: task_initialize + * + * Description: + * Initialize task related status. At present, this includes only the + * initialize of the child status pool. + * + * Parameters: + * None. + * + * Return Value: + * None. + * + * Assumptions: + * Called early in initialization. No special precautions are required. + * + *****************************************************************************/ + +void task_initialize(void) +{ + FAR struct child_status_s *curr; + FAR struct child_status_s *prev; + int i; + + /* Save all of the child status structures in a free list */ + + prev = &g_child_pool.alloc[0]; + g_child_pool.freelist = prev; + for (i = 0; i < CONFIG_PREALLOC_CHILDSTATUS; i++) + { + curr = &g_child_pool.alloc[i]; + prev->flink = curr; + prev = curr; + } +} + +/***************************************************************************** + * Name: group_allocchild + * + * Description: + * Allocate a child status structure by removing the next entry from a + * free list. + * + * Parameters: + * None. + * + * Return Value: + * On success, a non-NULL pointer to a child status structure. NULL is + * returned if there are no remaining, pre-allocated child status structures. + * + * Assumptions: + * Called during task creation in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +FAR struct child_status_s *group_allocchild(void) +{ + FAR struct child_status_s *ret; + + /* Return the status block at the head of the free list */ + + ret = g_child_pool.freelist; + if (ret) + { + g_child_pool.freelist = ret->flink; + ret->flink = NULL; + } + + return ret; +} + +/***************************************************************************** + * Name: group_freechild + * + * Description: + * Release a child status structure by returning it to a free list. + * + * Parameters: + * status - The child status structure to be freed. + * + * Return Value: + * None. + * + * Assumptions: + * Called during task creation in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +void group_freechild(FAR struct child_status_s *child) +{ + /* Return the child status structure to the free list */ + + if (child) + { + child->flink = g_child_pool.freelist; + g_child_pool.freelist = child; + } +} + +/***************************************************************************** + * Name: group_addchild + * + * Description: + * Add a child status structure in the given TCB. + * + * Parameters: + * group - The task group for the child status. + * child - The structure to be added + * + * Return Value: + * N + * + * Assumptions: + * Called during task creation processing in a safe context. No special + * precautions are required here. + * + *****************************************************************************/ + +void group_addchild(FAR struct task_group_s *group, + FAR struct child_status_s *child) +{ + /* Add the entry into the TCB list of children */ + + child->flink = group->tg_children; + group->tg_children = child; + + group_dumpchildren(group, "group_addchild"); +} + +/***************************************************************************** + * Name: group_findchild + * + * Description: + * Find a child status structure in the given task group. A reference to + * the child structure is returned, but the child remains the the group's + * list of children. + * + * Parameters: + * group - The ID of the parent task group to containing the child status. + * pid - The ID of the child to find. + * + * Return Value: + * On success, a non-NULL pointer to a child status structure. NULL is + * returned if there is child status structure for that pid in the TCB. + * + * Assumptions: + * Called during SIGCHLD processing in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +FAR struct child_status_s *group_findchild(FAR struct task_group_s *group, + pid_t pid) +{ + FAR struct child_status_s *child; + + DEBUGASSERT(group); + + /* Find the status structure with the matching PID */ + + for (child = group->tg_children; child; child = child->flink) + { + if (child->ch_pid == pid) + { + return child; + } + } + + return NULL; +} + +/***************************************************************************** + * Name: group_exitchild + * + * Description: + * Search for any child that has exitted. + * + * Parameters: + * tcb - The TCB of the parent task to containing the child status. + * + * Return Value: + * On success, a non-NULL pointer to a child status structure for the + * exited child. NULL is returned if not child has exited. + * + * Assumptions: + * Called during SIGCHLD processing in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +FAR struct child_status_s *group_exitchild(FAR struct task_group_s *group) +{ + FAR struct child_status_s *child; + + /* Find the status structure of any child task that has exitted. */ + + for (child = group->tg_children; child; child = child->flink) + { + if ((child->ch_flags & CHILD_FLAG_EXITED) != 0) + { + return child; + } + } + + return NULL; +} + +/***************************************************************************** + * Name: group_removechild + * + * Description: + * Remove one child structure from a task group. The child is removed, but + * is not yet freed. group_freechild must be called in order to free the + * child status structure. + * + * Parameters: + * group - The task group containing the child status. + * pid - The ID of the child to find. + * + * Return Value: + * On success, a non-NULL pointer to a child status structure. NULL is + * returned if there is child status structure for that pid in the TCB. + * + * Assumptions: + * Called during SIGCHLD processing in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +FAR struct child_status_s *group_removechild(FAR struct task_group_s *group, + pid_t pid) +{ + FAR struct child_status_s *curr; + FAR struct child_status_s *prev; + + DEBUGASSERT(group); + + /* Find the status structure with the matching PID */ + + for (prev = NULL, curr = group->tg_children; + curr; + prev = curr, curr = curr->flink) + { + if (curr->ch_pid == pid) + { + break; + } + } + + /* Did we find it? If so, remove it from the group. */ + + if (curr) + { + /* Do we remove it from mid-list? Or from the head of the list? */ + + if (prev) + { + prev->flink = curr->flink; + } + else + { + group->tg_children = curr->flink; + } + + curr->flink = NULL; + group_dumpchildren(group, "group_removechild"); + } + + return curr; +} + +/***************************************************************************** + * Name: group_removechildren + * + * Description: + * Remove and free all child structure from the task group. + * + * Parameters: + * group - The task group containing the child status. + * + * Return Value: + * None. + * + * Assumptions: + * Called during task exit processing in a safe context. No special + * precautions are required here. + * + *****************************************************************************/ + +void group_removechildren(FAR struct task_group_s *group) +{ + FAR struct child_status_s *curr; + FAR struct child_status_s *next; + + /* Remove all child structures for the TCB and return them to the freelist */ + + for (curr = group->tg_children; curr; curr = next) + { + next = curr->flink; + group_freechild(curr); + } + + group->tg_children = NULL; + group_dumpchildren(group, "group_removechildren"); +} + +#endif /* CONFIG_SCHED_HAVE_PARENT && CONFIG_SCHED_CHILD_STATUS */ diff --git a/nuttx/sched/group_create.c b/nuttx/sched/group_create.c index da91fa065..768641be1 100644 --- a/nuttx/sched/group_create.c +++ b/nuttx/sched/group_create.c @@ -1,5 +1,5 @@ /***************************************************************************** - * sched/group_allocate.c + * sched/group_create.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -65,11 +65,87 @@ /***************************************************************************** * Private Data *****************************************************************************/ +/* This is counter that is used to generate unique task group IDs */ + +#ifdef HAVE_GROUP_MEMBERS +static gid_t g_gidcounter; +#endif + +/***************************************************************************** + * Public Data + *****************************************************************************/ +/* This is the head of a list of all group members */ + +#ifdef HAVE_GROUP_MEMBERS +FAR struct task_group_s *g_grouphead; +#endif /***************************************************************************** * Private Functions *****************************************************************************/ +/***************************************************************************** + * Name: group_assigngid + * + * Description: + * Create a unique group ID. + * + * Parameters: + * tcb - The tcb in need of the task group. + * + * Return Value: + * None + * + * Assumptions: + * Called during task creation in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +#ifdef HAVE_GROUP_MEMBERS +void group_assigngid(FAR struct task_group_s *group) +{ + irqstate_t flags; + gid_t gid; + + /* Pre-emption should already be enabled, but lets be paranoid careful */ + + sched_lock(); + + /* Loop until we create a unique ID */ + + for (;;) + { + /* Increment the ID counter. This is global data so be extra paraoid. */ + + flags = irqsave(); + gid = ++g_gidcounter; + + /* Check for overflow */ + + if (gid <= 0) + { + g_gidcounter = 1; + irqrestore(flags); + } + else + { + /* Does a task group with this ID already exist? */ + + irqrestore(flags); + if (group_find(gid) == NULL) + { + /* Now assign this ID to the group and return */ + + group->tg_gid = gid; + sched_unlock(); + return; + } + } + } +} +#endif /* HAVE_GROUP_MEMBERS */ + /***************************************************************************** * Public Functions *****************************************************************************/ @@ -112,6 +188,14 @@ int group_allocate(FAR _TCB *tcb) return -ENOMEM; } + /* Assign the group a unique ID. If g_gidcounter were to wrap before we + * finish with task creation, that would be a problem. + */ + +#ifdef HAVE_GROUP_MEMBERS + group_assigngid(tcb->group); +#endif + /* Duplicate the parent tasks envionment */ ret = env_dup(tcb); @@ -149,6 +233,9 @@ int group_allocate(FAR _TCB *tcb) int group_initialize(FAR _TCB *tcb) { FAR struct task_group_s *group; +#ifdef HAVE_GROUP_MEMBERS + irqstate_t flags; +#endif DEBUGASSERT(tcb && tcb->group); group = tcb->group; @@ -172,9 +259,17 @@ int group_initialize(FAR _TCB *tcb) */ group->tg_mxmembers = GROUP_INITIAL_MEMBERS; /* Number of members in allocation */ + + /* Add the initialized entry to the list of groups */ + + flags = irqsave(); + group->flink = g_grouphead; + g_grouphead = group; + irqrestore(flags); + #endif - group->tg_nmembers = 1; /* Number of members in the group */ + group->tg_nmembers = 1; /* Number of members in the group */ return OK; } diff --git a/nuttx/sched/group_find.c b/nuttx/sched/group_find.c new file mode 100644 index 000000000..eb3989223 --- /dev/null +++ b/nuttx/sched/group_find.c @@ -0,0 +1,125 @@ +/***************************************************************************** + * sched/group_find.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ + +/***************************************************************************** + * Included Files + *****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#include "group_internal.h" +#include "env_internal.h" + +#ifdef HAVE_TASK_GROUP + +/***************************************************************************** + * Pre-processor Definitions + *****************************************************************************/ + +/***************************************************************************** + * Private Types + *****************************************************************************/ + +/***************************************************************************** + * Private Data + *****************************************************************************/ + +/***************************************************************************** + * Public Data + *****************************************************************************/ + +/***************************************************************************** + * Private Functions + *****************************************************************************/ + +/***************************************************************************** + * Public Functions + *****************************************************************************/ + +/***************************************************************************** + * Name: group_find + * + * Description: + * Given a group ID, find the group task structure with that ID. IDs are + * used instead of pointers to group structures. This is done because a + * group can disappear at any time leaving a stale pointer; an ID is cleaner + * because if the group disappears, this function will fail gracefully. + * + * Parameters: + * gid - The group ID to find. + * + * Return Value: + * On success, a pointer to the group task structure is returned. This + * function can fail only if there is no group that corresponds to the + * groupd ID. + * + * Assumptions: + * Called during when signally tasks in a safe context. No special + * precautions should be required here. However, extra care is taken when + * accessing the global g_grouphead list. + * + *****************************************************************************/ + +#ifdef HAVE_GROUP_MEMBERS +FAR struct task_group_s *group_find(gid_t gid) +{ + FAR struct task_group_s *group; + irqstate_t flags; + + /* Find the status structure with the matching PID */ + + flags = irqsave(); + for (group = g_grouphead; group; group = group->flink) + { + if (group->tg_gid == gid) + { + irqrestore(flags); + return group; + } + } + + irqrestore(flags); + return NULL; +} +#endif + +#endif /* HAVE_TASK_GROUP */ diff --git a/nuttx/sched/group_internal.h b/nuttx/sched/group_internal.h index aa8476e3c..b78b38453 100644 --- a/nuttx/sched/group_internal.h +++ b/nuttx/sched/group_internal.h @@ -52,37 +52,62 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* Any negative GID is invalid. */ + +#define INVALID_GROUP_ID (pid_t)-1 +#define IS_INVALID_GID(gid) ((int)(gid) < 0) /**************************************************************************** * Public Type Definitions ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Data ****************************************************************************/ +/* This is the head of a list of all group members */ + +#ifdef HAVE_GROUP_MEMBERS +extern FAR struct task_group_s *g_grouphead; +#endif + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ /* Task group data structure management */ #ifdef HAVE_TASK_GROUP -int group_allocate(FAR _TCB *tcb); -int group_initialize(FAR _TCB *tcb); -int group_bind(FAR _TCB *tcb); -int group_join(FAR _TCB *tcb); +int group_allocate(FAR _TCB *tcb); +int group_initialize(FAR _TCB *tcb); +int group_bind(FAR _TCB *tcb); +int group_join(FAR _TCB *tcb); void group_leave(FAR _TCB *tcb); + +#ifdef HAVE_GROUP_MEMBERS +FAR struct task_group_s *group_find(gid_t gid); +int group_addmember(FAR struct task_group_s *group, pid_t pid); +int group_removemember(FAR struct task_group_s *group, pid_t pid); +#else +# define group_find(gid) (NULL) +# define group_addmember(group,pid) (0) +# define group_removemember(group,pid) (1) +#endif + #ifndef CONFIG_DISABLE_SIGNALS -int group_signal(FAR _TCB *tcb, FAR siginfo_t *info); +int group_signal(FAR struct task_group_s *group, FAR siginfo_t *info); #else -# define group_signal(tcb,info) (0) +# define group_signal(tcb,info) (0) #endif + #else -# define group_allocate(tcb) (0) -# define group_initialize(tcb) (0) -# define group_bind(tcb) (0) -# define group_join(tcb) (0) -# define group_leave(tcb) -# define group_signal(tcb,info) (0) +# define group_allocate(tcb) (0) +# define group_initialize(tcb) (0) +# define group_bind(tcb) (0) +# define group_join(tcb) (0) +# define group_leave(tcb) +# define group_find(gid) (NULL) +# define group_addmember(group,pid) (0) +# define group_removemember(group,pid) (1) +# define group_signal(tcb,info) (0) #endif /* HAVE_TASK_GROUP */ /* Parent/child data management */ @@ -91,14 +116,18 @@ int group_signal(FAR _TCB *tcb, FAR siginfo_t *info); int task_reparent(pid_t ppid, pid_t chpid); #ifdef CONFIG_SCHED_CHILD_STATUS -FAR struct child_status_s *task_allocchild(void); -void task_freechild(FAR struct child_status_s *status); -void task_addchild(FAR _TCB *tcb, FAR struct child_status_s *child); -FAR struct child_status_s *task_exitchild(FAR _TCB *tcb); -FAR struct child_status_s *task_findchild(FAR _TCB *tcb, pid_t pid); -FAR struct child_status_s *task_removechild(FAR _TCB *tcb, pid_t pid); -void task_removechildren(FAR _TCB *tcb); -#endif +FAR struct child_status_s *group_allocchild(void); +void group_freechild(FAR struct child_status_s *status); +void group_addchild(FAR struct task_group_s *group, + FAR struct child_status_s *child); +FAR struct child_status_s *group_exitchild(FAR struct task_group_s *group); +FAR struct child_status_s *group_findchild(FAR struct task_group_s *group, + pid_t pid); +FAR struct child_status_s *group_removechild(FAR struct task_group_s *group, + pid_t pid); +void group_removechildren(FAR struct task_group_s *group); + +#endif /* CONFIG_SCHED_CHILD_STATUS */ #endif /* CONFIG_SCHED_HAVE_PARENT */ #endif /* __SCHED_GROUP_INERNAL_H */ diff --git a/nuttx/sched/group_join.c b/nuttx/sched/group_join.c index 077c45763..70319b3a1 100644 --- a/nuttx/sched/group_join.c +++ b/nuttx/sched/group_join.c @@ -139,6 +139,9 @@ int group_bind(FAR _TCB *tcb) int group_join(FAR _TCB *tcb) { FAR struct task_group_s *group; +#ifdef HAVE_GROUP_MEMBERS + int ret; +#endif DEBUGASSERT(tcb && tcb->group && tcb->group->tg_nmembers < UINT8_MAX); @@ -146,8 +149,45 @@ int group_join(FAR _TCB *tcb) /* Get the group from the TCB */ group = tcb->group; - + #ifdef HAVE_GROUP_MEMBERS + /* Add the member to the group */ + + ret = group_addmember(group, tcb->pid); + if (ret < 0) + { + return ret; + } +#endif + + group->tg_nmembers++; + return OK; +} + +/***************************************************************************** + * Name: group_addmember + * + * Description: + * Add a new member to a group. + * + * Parameters: + * group - The task group to add the new member + * pid - The new member + * + * Return Value: + * 0 (OK) on success; a negated errno value on failure. + * + * Assumptions: + * Called during thread creation and during reparenting in a safe context. + * No special precautions are required here. + * + *****************************************************************************/ + +#ifdef HAVE_GROUP_MEMBERS +int group_addmember(FAR struct task_group_s *group, pid_t pid) +{ + DEBUGASSERT(group && group->tg_nmembers < UINT8_MAX); + /* Will we need to extend the size of the array of groups? */ if (group->tg_nmembers >= group->tg_mxmembers) @@ -179,11 +219,9 @@ int group_join(FAR _TCB *tcb) /* Assign this new pid to the group. */ - group->tg_members[group->tg_nmembers] = tcb->pid; -#endif - - group->tg_nmembers++; + group->tg_members[group->tg_nmembers] = pid; return OK; } +#endif /* HAVE_GROUP_MEMBERS */ #endif /* HAVE_TASK_GROUP */ diff --git a/nuttx/sched/group_leave.c b/nuttx/sched/group_leave.c index d5fa9dbaf..add424185 100644 --- a/nuttx/sched/group_leave.c +++ b/nuttx/sched/group_leave.c @@ -65,6 +65,65 @@ * Private Functions *****************************************************************************/ +/***************************************************************************** + * Name: group_remove + * + * Description: + * Remove a group from the list of groups. + * + * Parameters: + * group - The group to be removed. + * + * Return Value: + * None. + * + * Assumptions: + * Called during task deletion in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +#ifdef HAVE_GROUP_MEMBERS +void group_remove(FAR struct task_group_s *group) +{ + FAR struct task_group_s *curr; + FAR struct task_group_s *prev; + irqstate_t flags; + + /* Let's be especially careful while access the global task group list. + * This is probably un-necessary. + */ + + flags = irqsave(); + + /* Find the task group structure */ + + for (prev = NULL, curr = g_grouphead; + curr && curr != group; + prev = curr, curr = curr->flink); + + /* Did we find it? If so, remove it from the list. */ + + if (curr) + { + /* Do we remove it from mid-list? Or from the head of the list? */ + + if (prev) + { + prev->flink = curr->flink; + } + else + { + g_grouphead = curr->flink; + } + + curr->flink = NULL; + } + + irqrestore(flags); +} +#endif + /***************************************************************************** * Public Functions *****************************************************************************/ @@ -90,6 +149,8 @@ * *****************************************************************************/ +#ifdef HAVE_GROUP_MEMBERS + void group_leave(FAR _TCB *tcb) { FAR struct task_group_s *group; @@ -101,64 +162,57 @@ void group_leave(FAR _TCB *tcb) group = tcb->group; if (group) { -#ifdef HAVE_GROUP_MEMBERS - int i; + /* Remove the member from group */ - /* Find the member in the array of members and remove it */ + int ret = group_removemember(group, tcb->pid); + DEBUGASSERT(ret >= 0); - for (i = 0; i < group->tg_nmembers; i++) - { - /* Does this member have the matching pid */ - - if (group->tg_members[i] == tcb->pid) - { - /* Yes.. break out of the loop. We don't do the actual - * removal here, instead we re-test i and do the adjustments - * outside of the loop. We do this because we want the - * DEBUGASSERT to work properly. - */ - - break; - } - } - - /* Now, test if we found the task in the array of members. */ + /* Is the group now empty? */ - DEBUGASSERT(i < group->tg_nmembers); - if (i < group->tg_nmembers) + if (ret == 0) { - /* Yes..Is this the last member of the group? */ - - if (group->tg_nmembers > 1) - { - /* No.. remove the member from the array of members */ - - group->tg_members[i] = group->tg_members[group->tg_nmembers - 1]; - group->tg_nmembers--; - } - - /* Yes.. that was the last member remaining in the group */ - - else - { - /* Release all of the resource contained within the group */ - /* Free all un-reaped child exit status */ + /* Release all of the resource contained within the group */ + /* Free all un-reaped child exit status */ #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) - task_removechildren(tcb); + group_removechildren(tcb->group); #endif - /* Release all shared environment variables */ + /* Release all shared environment variables */ #ifndef CONFIG_DISABLE_ENVIRON - env_release(tcb); + env_release(tcb); #endif - /* Release the group container itself */ + /* Remove the group from the list of groups */ + + group_remove(group); + + /* Release the group container itself */ - sched_free(group); - } + sched_free(group); } -#else - /* Yes..Is this the last member of the group? */ + + /* In any event, we can detach the group from the TCB so that we won't + * do this again. + */ + + tcb->group = NULL; + } +} + +#else /* HAVE_GROUP_MEMBERS */ + +void group_leave(FAR _TCB *tcb) +{ + FAR struct task_group_s *group; + + DEBUGASSERT(tcb); + + /* Make sure that we have a group */ + + group = tcb->group; + if (group) + { + /* Yes, we have a group.. Is this the last member of the group? */ if (group->tg_nmembers > 1) { @@ -175,7 +229,7 @@ void group_leave(FAR _TCB *tcb) /* Free all un-reaped child exit status */ #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) - task_removechildren(tcb); + group_removechildren(tcb->group); #endif /* Release all shared environment variables */ @@ -186,7 +240,6 @@ void group_leave(FAR _TCB *tcb) sched_free(group); } -#endif /* In any event, we can detach the group from the TCB so we won't do * this again. @@ -196,4 +249,67 @@ void group_leave(FAR _TCB *tcb) } } +#endif /* HAVE_GROUP_MEMBERS */ + +/***************************************************************************** + * Name: group_removemember + * + * Description: + * Remove a member from a group. + * + * Parameters: + * group - The group from which to remove the member. + * pid - The member to be removed. + * + * Return Value: + * On success, returns the number of members remaining in the group (>=0). + * Can fail only if the member is not found in the group. On failure, + * returns -ENOENT + * + * Assumptions: + * Called during task deletion and also from the reparenting logic, both + * in a safe context. No special precautions are required here. + * + *****************************************************************************/ + +#ifdef HAVE_GROUP_MEMBERS +int group_removemember(FAR struct task_group_s *group, pid_t pid) +{ + int i; + + DEBUGASSERT(group); + + /* Find the member in the array of members and remove it */ + + for (i = 0; i < group->tg_nmembers; i++) + { + /* Does this member have the matching pid */ + + if (group->tg_members[i] == pid) + { + /* Yes.. break out of the loop. We don't do the actual + * removal here, instead we re-test i and do the adjustments + * outside of the loop. We do this because we want the + * DEBUGASSERT to work properly. + */ + + break; + } + } + + /* Now, test if we found the task in the array of members. */ + + if (i < group->tg_nmembers) + { + /* Remove the member from the array of members */ + + group->tg_members[i] = group->tg_members[group->tg_nmembers - 1]; + group->tg_nmembers--; + return group->tg_nmembers; + } + + return -ENOENT; +} +#endif /* HAVE_GROUP_MEMBERS */ + #endif /* HAVE_TASK_GROUP */ diff --git a/nuttx/sched/group_signal.c b/nuttx/sched/group_signal.c index 5020ec436..009ab7a55 100644 --- a/nuttx/sched/group_signal.c +++ b/nuttx/sched/group_signal.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "os_internal.h" @@ -74,10 +75,10 @@ * Name: group_signal * * Description: - * Send a signal to every member of the group to which task belongs. + * Send a signal to every member of the group. * * Parameters: - * tcb - The tcb of one task in the task group that needs to be signalled. + * group - The task group that needs to be signalled. * * Return Value: * 0 (OK) on success; a negated errno value on failure. @@ -88,15 +89,13 @@ * *****************************************************************************/ -int group_signal(FAR _TCB *tcb, FAR siginfo_t *info) +int group_signal(FAR struct task_group_s *group, FAR siginfo_t *info) { #ifdef HAVE_GROUP_MEMBERS - FAR struct task_group_s *group; FAR _TCB *gtcb; int i; - DEBUGASSERT(tcb && tcb->group && info); - group = tcb->group; + DEBUGASSERT(group && info); /* Make sure that pre-emption is disabled to that we signal all of teh * members of the group before any of them actually run. @@ -130,8 +129,35 @@ int group_signal(FAR _TCB *tcb, FAR siginfo_t *info) sched_unlock(); return OK; #else - return sig_received(tcb, info); + return -ENOSYS; #endif } +/***************************************************************************** + * Name: group_signalmember + * + * Description: + * Send a signal to every member of the group to which task belongs. + * + * Parameters: + * tcb - The tcb of one task in the task group that needs to be signalled. + * + * Return Value: + * 0 (OK) on success; a negated errno value on failure. + * + * Assumptions: + * Called during task terminatino in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +int group_signalmember(FAR _TCB *tcb, FAR siginfo_t *info) +{ +#ifdef HAVE_GROUP_MEMBERS + DEBUGASSERT(tcb); + return group_signal(tcb->group, info); +#else + return sig_received(tcb, info); +#endif +} #endif /* HAVE_TASK_GROUP && !CONFIG_DISABLE_SIGNALS */ diff --git a/nuttx/sched/sched_waitid.c b/nuttx/sched/sched_waitid.c index 41e488f90..9c24189c4 100644 --- a/nuttx/sched/sched_waitid.c +++ b/nuttx/sched/sched_waitid.c @@ -79,8 +79,8 @@ static void exited_child(FAR _TCB *rtcb, FAR struct child_status_s *child, /* Discard the child entry */ - (void)task_removechild(rtcb, child->ch_pid); - task_freechild(child); + (void)group_removechild(rtcb->group, child->ch_pid); + group_freechild(child); } #endif @@ -212,7 +212,11 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) /* Get the TCB corresponding to this PID and make sure it is our child. */ ctcb = sched_gettcb((pid_t)id); - if (!ctcb || ctcb->parent != rtcb->pid) +#ifdef HAVE_GROUP_MEMBERS + if (!ctcb || ctcb->group->tg_pgid != rtcb->group->tg_gid) +#else + if (!ctcb || ctcb->ppid != rtcb->pid) +#endif { err = ECHILD; goto errout_with_errno; @@ -224,7 +228,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) { /* Check if this specific pid has allocated child status? */ - if (task_findchild(rtcb, (pid_t)id) == NULL) + if (group_findchild(rtcb->group, (pid_t)id) == NULL) { /* This specific pid is not a child */ @@ -246,7 +250,11 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) /* Get the TCB corresponding to this PID and make sure it is our child. */ ctcb = sched_gettcb((pid_t)id); - if (!ctcb || ctcb->parent != rtcb->pid) +#ifdef HAVE_GROUP_MEMBERS + if (!ctcb || ctcb->group->tg_pgid != rtcb->group->tg_gid) +#else + if (!ctcb || ctcb->ppid != rtcb->pid) +#endif { err = ECHILD; goto errout_with_errno; @@ -270,7 +278,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) { /* We are waiting for any child to exit */ - if (retains && (child = task_exitchild(rtcb)) != NULL) + if (retains && (child = group_exitchild(rtcb->group)) != NULL) { /* A child has exited. Apparently we missed the signal. * Return the exit status and break out of the loop. @@ -287,7 +295,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) { /* Yes ... Get the current status of the child task. */ - child = task_findchild(rtcb, (pid_t)id); + child = group_findchild(rtcb->group, (pid_t)id); DEBUGASSERT(child); /* Did the child exit? */ diff --git a/nuttx/sched/sched_waitpid.c b/nuttx/sched/sched_waitpid.c index 4af7f7ef3..0285c2673 100644 --- a/nuttx/sched/sched_waitpid.c +++ b/nuttx/sched/sched_waitpid.c @@ -172,16 +172,12 @@ * * Assumptions: * - *****************************************************************************/ - -/*************************************************************************** - * NOTE: This is a partially functional, experimental version of waitpid() + * Compatibility + * If there is no SIGCHLD signal supported (CONFIG_SCHED_HAVE_PARENT not + * defined), then waitpid() is still available, but does not obey the + * restriction that the pid be a child of the caller. * - * If there is no SIGCHLD signal supported (CONFIG_SCHED_HAVE_PARENT not - * defined), then waitpid() is still available, but does not obey the - * restriction that the pid be a child of the caller. - * - ***************************************************************************/ + *****************************************************************************/ #ifndef CONFIG_SCHED_HAVE_PARENT pid_t waitpid(pid_t pid, int *stat_loc, int options) @@ -325,7 +321,11 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Get the TCB corresponding to this PID and make sure it is our child. */ ctcb = sched_gettcb(pid); - if (!ctcb || ctcb->parent != rtcb->pid) +#ifdef HAVE_GROUP_MEMBERS + if (!ctcb || ctcb->group->tg_pgid != rtcb->group->tg_gid) +#else + if (!ctcb || ctcb->ppid != rtcb->pid) +#endif { err = ECHILD; goto errout_with_errno; @@ -337,7 +337,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) { /* Check if this specific pid has allocated child status? */ - if (task_findchild(rtcb, pid) == NULL) + if (group_findchild(rtcb->group, pid) == NULL) { err = ECHILD; goto errout_with_errno; @@ -357,7 +357,11 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Get the TCB corresponding to this PID and make sure it is our child. */ ctcb = sched_gettcb(pid); - if (!ctcb || ctcb->parent != rtcb->pid) +#ifdef HAVE_GROUP_MEMBERS + if (!ctcb || ctcb->group->tg_pgid != rtcb->group->tg_gid) +#else + if (!ctcb || ctcb->ppid != rtcb->pid) +#endif { err = ECHILD; goto errout_with_errno; @@ -383,7 +387,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) */ DEBUGASSERT(!retains || rtcb->group->tg_children); - if (retains && (child = task_exitchild(rtcb)) != NULL) + if (retains && (child = group_exitchild(rtcb->group)) != NULL) { /* A child has exited. Apparently we missed the signal. * Return the saved exit status. @@ -395,8 +399,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Discard the child entry and break out of the loop */ - (void)task_removechild(rtcb, child->ch_pid); - task_freechild(child); + (void)group_removechild(rtcb->group, child->ch_pid); + group_freechild(child); break; } } @@ -407,7 +411,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) { /* Get the current status of the child task. */ - child = task_findchild(rtcb, pid); + child = group_findchild(rtcb->group, pid); DEBUGASSERT(child); /* Did the child exit? */ @@ -420,8 +424,8 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* Discard the child entry and break out of the loop */ - (void)task_removechild(rtcb, pid); - task_freechild(child); + (void)group_removechild(rtcb->group, pid); + group_freechild(child); break; } } diff --git a/nuttx/sched/sig_action.c b/nuttx/sched/sig_action.c index fe72cc22d..5c00179dc 100644 --- a/nuttx/sched/sig_action.c +++ b/nuttx/sched/sig_action.c @@ -242,7 +242,7 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * /* Free all pending exit status */ - task_removechildren(rtcb); + group_removechildren(rtcb->group); irqrestore(flags); } #endif diff --git a/nuttx/sched/task_childstatus.c b/nuttx/sched/task_childstatus.c deleted file mode 100644 index c0df3d534..000000000 --- a/nuttx/sched/task_childstatus.c +++ /dev/null @@ -1,440 +0,0 @@ -/***************************************************************************** - * sched/task_childstatus.c - * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - *****************************************************************************/ - -/***************************************************************************** - * Included Files - *****************************************************************************/ - -#include - -#include -#include -#include - -#include "os_internal.h" -#include "group_internal.h" - -#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) - -/***************************************************************************** - * Pre-processor Definitions - *****************************************************************************/ -/* Note that there cannot be more that CONFIG_MAX_TASKS tasks in total. - * However, the number of child status structures may need to be significantly - * larger because this number includes the maximum number of tasks that are - * running PLUS the number of tasks that have exit'ed without having their - * exit status reaped (via wait(), waitid(), or waitpid()). - * - * Obviously, if tasks spawn children indefinitely and never have the exit - * status reaped, then you have a memory leak! - */ - -#if !defined(CONFIG_PREALLOC_CHILDSTATUS) || CONFIG_PREALLOC_CHILDSTATUS == 0 -# undef CONFIG_PREALLOC_CHILDSTATUS -# define CONFIG_PREALLOC_CHILDSTATUS (2*CONFIG_MAX_TASKS) -#endif - -#ifndef CONFIG_DEBUG -# undef CONFIG_DEBUG_CHILDSTATUS -#endif - -/***************************************************************************** - * Private Types - *****************************************************************************/ -/* Globals are maintained in a structure to minimize name collisions. */ - -struct child_pool_s -{ - struct child_status_s alloc[CONFIG_PREALLOC_CHILDSTATUS]; - FAR struct child_status_s *freelist; -}; - -/***************************************************************************** - * Private Data - *****************************************************************************/ - -static struct child_pool_s g_child_pool; - -/***************************************************************************** - * Private Functions - *****************************************************************************/ - -/***************************************************************************** - * Name: task_dumpchildren - * - * Description: - * Dump all of the children when the part TCB list is modified. - * - * Parameters: - * tcb - The parent TCB. - * - * Return Value: - * None. - * - * Assumptions: - * Called early in initialization. No special precautions are required. - * - *****************************************************************************/ - -#ifdef CONFIG_DEBUG_CHILDSTATUS -static void task_dumpchildren(FAR _TCB *tcb, FAR const char *msg) -{ - FAR struct child_status_s *child; - FAR struct task_group_s *group = tcb->group; - int i; - - dbg("Parent TCB=%p group=%p: %s\n", tcb, group, msg); - for (i = 0, child = group->tg_children; child; i++, child = child->flink) - { - dbg(" %d. ch_flags=%02x ch_pid=%d ch_status=%d\n", - i, child->ch_flags, child->ch_pid, child->ch_status); - } -} -#else -# define task_dumpchildren(t,m) -#endif - -/***************************************************************************** - * Public Functions - *****************************************************************************/ - -/***************************************************************************** - * Name: task_initialize - * - * Description: - * Initialize task related status. At present, this includes only the - * initialize of the child status pool. - * - * Parameters: - * None. - * - * Return Value: - * None. - * - * Assumptions: - * Called early in initialization. No special precautions are required. - * - *****************************************************************************/ - -void task_initialize(void) -{ - FAR struct child_status_s *curr; - FAR struct child_status_s *prev; - int i; - - /* Save all of the child status structures in a free list */ - - prev = &g_child_pool.alloc[0]; - g_child_pool.freelist = prev; - for (i = 0; i < CONFIG_PREALLOC_CHILDSTATUS; i++) - { - curr = &g_child_pool.alloc[i]; - prev->flink = curr; - prev = curr; - } -} - -/***************************************************************************** - * Name: task_allocchild - * - * Description: - * Allocate a child status structure by removing the next entry from a - * free list. - * - * Parameters: - * None. - * - * Return Value: - * On success, a non-NULL pointer to a child status structure. NULL is - * returned if there are no remaining, pre-allocated child status structures. - * - * Assumptions: - * Called during task creation in a safe context. No special precautions - * are required here. - * - *****************************************************************************/ - -FAR struct child_status_s *task_allocchild(void) -{ - FAR struct child_status_s *ret; - - /* Return the status block at the head of the free list */ - - ret = g_child_pool.freelist; - if (ret) - { - g_child_pool.freelist = ret->flink; - ret->flink = NULL; - } - - return ret; -} - -/***************************************************************************** - * Name: task_freechild - * - * Description: - * Release a child status structure by returning it to a free list. - * - * Parameters: - * status - The child status structure to be freed. - * - * Return Value: - * None. - * - * Assumptions: - * Called during task creation in a safe context. No special precautions - * are required here. - * - *****************************************************************************/ - -void task_freechild(FAR struct child_status_s *child) -{ - /* Return the child status structure to the free list */ - - if (child) - { - child->flink = g_child_pool.freelist; - g_child_pool.freelist = child; - } -} - -/***************************************************************************** - * Name: task_addchild - * - * Description: - * Add a child status structure in the given TCB. - * - * Parameters: - * tcb - The TCB of the parent task to containing the child status. - * child - The structure to be added - * - * Return Value: - * N - * - * Assumptions: - * Called during task creation processing in a safe context. No special - * precautions are required here. - * - *****************************************************************************/ - -void task_addchild(FAR _TCB *tcb, FAR struct child_status_s *child) -{ - FAR struct task_group_s *group = tcb->group; - - /* Add the entry into the TCB list of children */ - - child->flink = group->tg_children; - group->tg_children = child; - - task_dumpchildren(tcb, "task_addchild"); -} - -/***************************************************************************** - * Name: task_findchild - * - * Description: - * Find a child status structure in the given TCB. A reference to the - * child structure is returned, but the child remains the the TCB's list - * of children. - * - * Parameters: - * tcb - The TCB of the parent task to containing the child status. - * pid - The ID of the child to find. - * - * Return Value: - * On success, a non-NULL pointer to a child status structure. NULL is - * returned if there is child status structure for that pid in the TCB. - * - * Assumptions: - * Called during SIGCHLD processing in a safe context. No special precautions - * are required here. - * - *****************************************************************************/ - -FAR struct child_status_s *task_findchild(FAR _TCB *tcb, pid_t pid) -{ - FAR struct task_group_s *group = tcb->group; - FAR struct child_status_s *child; - - /* Find the status structure with the matching PID */ - - for (child = group->tg_children; child; child = child->flink) - { - if (child->ch_pid == pid) - { - return child; - } - } - - return NULL; -} - -/***************************************************************************** - * Name: task_exitchild - * - * Description: - * Search for any child that has exitted. - * - * Parameters: - * tcb - The TCB of the parent task to containing the child status. - * - * Return Value: - * On success, a non-NULL pointer to a child status structure for the - * exited child. NULL is returned if not child has exited. - * - * Assumptions: - * Called during SIGCHLD processing in a safe context. No special precautions - * are required here. - * - *****************************************************************************/ - -FAR struct child_status_s *task_exitchild(FAR _TCB *tcb) -{ - FAR struct task_group_s *group = tcb->group; - FAR struct child_status_s *child; - - /* Find the status structure of any child task that has exitted. */ - - for (child = group->tg_children; child; child = child->flink) - { - if ((child->ch_flags & CHILD_FLAG_EXITED) != 0) - { - return child; - } - } - - return NULL; -} - -/***************************************************************************** - * Name: task_removechild - * - * Description: - * Remove one child structure from the TCB. The child is removed, but is - * not yet freed. task_freechild must be called in order to free the child - * status structure. - * - * Parameters: - * tcb - The TCB of the parent task to containing the child status. - * pid - The ID of the child to find. - * - * Return Value: - * On success, a non-NULL pointer to a child status structure. NULL is - * returned if there is child status structure for that pid in the TCB. - * - * Assumptions: - * Called during SIGCHLD processing in a safe context. No special precautions - * are required here. - * - *****************************************************************************/ - -FAR struct child_status_s *task_removechild(FAR _TCB *tcb, pid_t pid) -{ - FAR struct task_group_s *group = tcb->group; - FAR struct child_status_s *curr; - FAR struct child_status_s *prev; - - /* Find the status structure with the matching PID */ - - for (prev = NULL, curr = group->tg_children; - curr; - prev = curr, curr = curr->flink) - { - if (curr->ch_pid == pid) - { - break; - } - } - - /* Did we find it? If so, remove it from the TCB. */ - - if (curr) - { - /* Do we remove it from mid-list? Or from the head of the list? */ - - if (prev) - { - prev->flink = curr->flink; - } - else - { - group->tg_children = curr->flink; - } - - curr->flink = NULL; - task_dumpchildren(tcb, "task_removechild"); - } - - return curr; -} - -/***************************************************************************** - * Name: task_removechildren - * - * Description: - * Remove and free all child structure from the TCB. - * - * Parameters: - * tcb - The TCB of the parent task to containing the child status. - * - * Return Value: - * None. - * - * Assumptions: - * Called during task exit processing in a safe context. No special - * precautions are required here. - * - *****************************************************************************/ - -void task_removechildren(FAR _TCB *tcb) -{ - FAR struct task_group_s *group = tcb->group; - FAR struct child_status_s *curr; - FAR struct child_status_s *next; - - /* Remove all child structures for the TCB and return them to the freelist */ - - for (curr = group->tg_children; curr; curr = next) - { - next = curr->flink; - task_freechild(curr); - } - - group->tg_children = NULL; - task_dumpchildren(tcb, "task_removechildren"); -} - -#endif /* CONFIG_SCHED_HAVE_PARENT && CONFIG_SCHED_CHILD_STATUS */ diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index cbada851a..3fdf08bf7 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -104,10 +104,7 @@ static inline void task_atexit(FAR _TCB *tcb) (*tcb->atexitfunc[index])(); - /* Nullify the atexit function. task_exithook may be called more then - * once in most task exit scenarios. Nullifying the atext function - * pointer will assure that the callback is performed only once. - */ + /* Nullify the atexit function to prevent its reuse. */ tcb->atexitfunc[index] = NULL; } @@ -120,10 +117,7 @@ static inline void task_atexit(FAR _TCB *tcb) (*tcb->atexitfunc)(); - /* Nullify the atexit function. task_exithook may be called more then - * once in most task exit scenarios. Nullifying the atext function - * pointer will assure that the callback is performed only once. - */ + /* Nullify the atexit function to prevent its reuse. */ tcb->atexitfunc = NULL; } @@ -161,10 +155,7 @@ static inline void task_onexit(FAR _TCB *tcb, int status) (*tcb->onexitfunc[index])(status, tcb->onexitarg[index]); - /* Nullify the on_exit function. task_exithook may be called more then - * once in most task exit scenarios. Nullifying the atext function - * pointer will assure that the callback is performed only once. - */ + /* Nullify the on_exit function to prevent its reuse. */ tcb->onexitfunc[index] = NULL; } @@ -176,10 +167,7 @@ static inline void task_onexit(FAR _TCB *tcb, int status) (*tcb->onexitfunc)(status, tcb->onexitarg); - /* Nullify the on_exit function. task_exithook may be called more then - * once in most task exit scenarios. Nullifying the on_exit function - * pointer will assure that the callback is performed only once. - */ + /* Nullify the on_exit function to prevent its reuse. */ tcb->onexitfunc = NULL; } @@ -198,20 +186,96 @@ static inline void task_onexit(FAR _TCB *tcb, int status) ****************************************************************************/ #ifdef CONFIG_SCHED_HAVE_PARENT +#ifdef HAVE_GROUP_MEMBERS +static inline void task_sigchild(gid_t pgid, FAR _TCB *ctcb, int status) +{ + FAR struct task_group_s *chgrp = ctcb->group; + FAR struct task_group_s *pgrp; + siginfo_t info; + + DEBUGASSERT(chgrp); + + /* Only the final exiting thread in a task group should generate SIGCHLD. */ + + if (chgrp->tg_nmembers == 1) + { + /* Get the parent task group */ + + pgrp = group_find(chgrp->tg_pgid); + + /* It is possible that all of the members of the parent task group + * have exited. This would not be an error. In this case, the + * child task group has been orphaned. + */ + + if (!pgrp) + { + /* Set the task group ID to an invalid group ID. The dead parent + * task group ID could get reused some time in the future. + */ + + chgrp->tg_pgid = INVALID_GROUP_ID; + return; + } + +#ifdef CONFIG_SCHED_CHILD_STATUS + /* Check if the parent task group has suppressed retention of child exit + * status information. Only 'tasks' report exit status, not pthreads. + * pthreads have a different mechanism. + */ + + if ((pgrp->tg_flags & GROUP_FLAG_NOCLDWAIT) == 0) + { + FAR struct child_status_s *child; + + /* No.. Find the exit status entry for this task in the parent TCB */ + + child = group_findchild(pgrp, getpid()); + DEBUGASSERT(child); + if (child) + { + /* Mark that the child has exit'ed */ + + child->ch_flags |= CHILD_FLAG_EXITED; + + /* Save the exit status */ + + child->ch_status = status; + } + } +#endif /* CONFIG_SCHED_CHILD_STATUS */ + + /* Create the siginfo structure. We don't actually know the cause. + * That is a bug. Let's just say that the child task just exit-ted + * for now. + */ + + info.si_signo = SIGCHLD; + info.si_code = CLD_EXITED; + info.si_value.sival_ptr = NULL; + info.si_pid = ctcb->pid; + info.si_status = status; + + /* Send the signal. We need to use this internal interface so that we + * can provide the correct si_code value with the signal. + */ + + (void)group_signal(pgrp, &info); + } +} + +#else /* HAVE_GROUP_MEMBERS */ + static inline void task_sigchild(FAR _TCB *ptcb, FAR _TCB *ctcb, int status) { siginfo_t info; - /* Only the final exiting thread in a task group should generate SIGCHLD. - * If task groups are not supported then we will report SIGCHLD when the - * task exits. + /* If task groups are not supported then we will report SIGCHLD when the + * task exits. Unfortunately, there could still be threads in the group + * that are still running. */ -#ifdef CONFIG_SCHED_CHILD_STATUS - if (ctcb->group->tg_nmembers == 1) -#else if ((ctcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_TASK) -#endif { #ifdef CONFIG_SCHED_CHILD_STATUS /* Check if the parent task group has suppressed retention of child exit @@ -225,7 +289,7 @@ static inline void task_sigchild(FAR _TCB *ptcb, FAR _TCB *ctcb, int status) /* No.. Find the exit status entry for this task in the parent TCB */ - child = task_findchild(ptcb, getpid()); + child = group_findchild(ptcb->group, getpid()); DEBUGASSERT(child); if (child) { @@ -238,12 +302,15 @@ static inline void task_sigchild(FAR _TCB *ptcb, FAR _TCB *ctcb, int status) child->ch_status = status; } } -#else + +#else /* CONFIG_SCHED_CHILD_STATUS */ + /* Decrement the number of children from this parent */ DEBUGASSERT(ptcb->nchildren > 0); ptcb->nchildren--; -#endif + +#endif /* CONFIG_SCHED_CHILD_STATUS */ /* Create the siginfo structure. We don't actually know the cause. * That is a bug. Let's just say that the child task just exit-ted @@ -260,16 +327,16 @@ static inline void task_sigchild(FAR _TCB *ptcb, FAR _TCB *ctcb, int status) * can provide the correct si_code value with the signal. */ -#ifdef HAVE_GROUP_MEMBERS - (void)group_signal(ptcb, &info); -#else (void)sig_received(ptcb, &info); -#endif } } -#else -# define task_sigchild(ptct,ctcb,status) -#endif + +#endif /* HAVE_GROUP_MEMBERS */ +#else /* CONFIG_SCHED_HAVE_PARENT */ + +# define task_sigchild(x,ctcb,status) + +#endif /* CONFIG_SCHED_HAVE_PARENT */ /**************************************************************************** * Name: task_leavegroup @@ -282,6 +349,18 @@ static inline void task_sigchild(FAR _TCB *ptcb, FAR _TCB *ctcb, int status) #ifdef CONFIG_SCHED_HAVE_PARENT static inline void task_leavegroup(FAR _TCB *ctcb, int status) { +#ifdef HAVE_GROUP_MEMBERS + DEBUGASSERT(ctcb && ctcb->group); + + /* Keep things stationary throughout the following */ + + sched_lock(); + + /* Send SIGCHLD to all members of the parent's task group */ + + task_sigchild(ctcb->group->tg_pgid, ctcb, status); + sched_unlock(); +#else FAR _TCB *ptcb; /* Keep things stationary throughout the following */ @@ -289,12 +368,12 @@ static inline void task_leavegroup(FAR _TCB *ctcb, int status) sched_lock(); /* Get the TCB of the receiving, parent task. We do this early to - * handle multiple calls to task_leavegroup. ctcb->parent is set to an + * handle multiple calls to task_leavegroup. ctcb->ppid is set to an * invalid value below and the following call will fail if we are * called again. */ - ptcb = sched_gettcb(ctcb->parent); + ptcb = sched_gettcb(ctcb->ppid); if (!ptcb) { /* The parent no longer exists... bail */ @@ -307,14 +386,11 @@ static inline void task_leavegroup(FAR _TCB *ctcb, int status) task_sigchild(ptcb, ctcb, status); - /* Set the parent to an impossible PID. We do this because under certain - * conditions, task_exithook() can be called multiple times. If this - * function is called again, sched_gettcb() will fail on the invalid - * parent PID above and all will be well. - */ + /* Forget who our parent was */ - ctcb->parent = INVALID_PROCESS_ID; + ctcb->ppid = INVALID_PROCESS_ID; sched_unlock(); +#endif } #else # define task_leavegroup(ctcb,status) @@ -385,6 +461,16 @@ static inline void task_exitwakeup(FAR _TCB *tcb, int status) void task_exithook(FAR _TCB *tcb, int status) { + /* Under certain conditions, task_exithook() can be called multiple times. + * A bit in the TCB was set the first time this function was called. If + * that bit is set, then just ext doing nothing more.. + */ + + if ((tcb->flags & TCB_FLAG_EXIT_PROCESSING) != 0) + { + return; + } + /* If exit function(s) were registered, call them now before we do any un- * initialization. NOTE: In the case of task_delete(), the exit function * will *not* be called on the thread execution of the task being deleted! @@ -433,4 +519,11 @@ void task_exithook(FAR _TCB *tcb, int status) #ifndef CONFIG_DISABLE_SIGNALS sig_cleanup(tcb); /* Deallocate Signal lists */ #endif + + /* This function can be re-entered in certain cases. Set a flag + * bit in the TCB to not that we have already completed this exit + * processing. + */ + + tcb->flags |= TCB_FLAG_EXIT_PROCESSING; } diff --git a/nuttx/sched/task_reparent.c b/nuttx/sched/task_reparent.c index 1193c9a7f..5bb62893f 100644 --- a/nuttx/sched/task_reparent.c +++ b/nuttx/sched/task_reparent.c @@ -70,6 +70,141 @@ * *****************************************************************************/ +#ifdef HAVE_GROUP_MEMBERS +int task_reparent(pid_t ppid, pid_t chpid) +{ +#ifdef CONFIG_SCHED_CHILD_STATUS + FAR struct child_status_s *child; +#endif + FAR struct task_group_s *chgrp; + FAR struct task_group_s *ogrp; + FAR struct task_group_s *pgrp; + _TCB *tcb; + gid_t ogid; + gid_t pgid; + irqstate_t flags; + int ret; + + /* Disable interrupts so that nothing can change in the relatinoship of + * the three task: Child, current parent, and new parent. + */ + + flags = irqsave(); + + /* Get the child tasks task group */ + + tcb = sched_gettcb(chpid); + if (!tcb) + { + ret = -ECHILD; + goto errout_with_ints; + } + + DEBUGASSERT(tcb->group); + chgrp = tcb->group; + + /* Get the GID of the old parent task's task group (ogid) */ + + ogid = chgrp->tg_pgid; + + /* Get the old parent task's task group (ogrp) */ + + ogrp = group_find(ogid); + if (!ogrp) + { + ret = -ESRCH; + goto errout_with_ints; + } + + /* If new parent task's PID (ppid) is zero, then new parent is the + * grandparent will be the new parent, i.e., the parent of the current + * parent task. + */ + + if (ppid == 0) + { + /* Get the grandparent task's task group (pgrp) */ + + pgid = ogrp->tg_pgid; + pgrp = group_find(pgid); + } + else + { + /* Get the new parent task's task group (pgrp) */ + + tcb = sched_gettcb(ppid); + if (!tcb) + { + ret = -ESRCH; + goto errout_with_ints; + } + + pgrp = tcb->group; + pgid = pgrp->tg_gid; + } + + if (!pgrp) + { + ret = -ESRCH; + goto errout_with_ints; + } + + /* Then reparent the child. Notice that we don't actually change the + * parent of the task. Rather, we change the parent task group for + * all members of the child's task group. + */ + + chgrp->tg_pgid = pgid; + +#ifdef CONFIG_SCHED_CHILD_STATUS + /* Remove the child status entry from old parent task group */ + + child = group_removechild(ogrp, chpid); + if (child) + { + /* Has the new parent's task group supressed child exit status? */ + + if ((pgrp->tg_flags && GROUP_FLAG_NOCLDWAIT) == 0) + { + /* No.. Add the child status entry to the new parent's task group */ + + group_addchild(pgrp, child); + } + else + { + /* Yes.. Discard the child status entry */ + + group_freechild(child); + } + + /* Either case is a success */ + + ret = OK; + } + else + { + /* This would not be an error if the original parent's task group has + * suppressed child exit status. + */ + + ret = ((ogrp->tg_flags && GROUP_FLAG_NOCLDWAIT) == 0) ? -ENOENT : OK; + } + +#else /* CONFIG_SCHED_CHILD_STATUS */ + + DEBUGASSERT(otcb->nchildren > 0); + + otcb->nchildren--; /* The orignal parent now has one few children */ + ptcb->nchildren++; /* The new parent has one additional child */ + ret = OK; + +#endif /* CONFIG_SCHED_CHILD_STATUS */ + +errout_with_ints: + irqrestore(flags); + return ret; +} +#else int task_reparent(pid_t ppid, pid_t chpid) { #ifdef CONFIG_SCHED_CHILD_STATUS @@ -99,7 +234,7 @@ int task_reparent(pid_t ppid, pid_t chpid) /* Get the PID of the child task's parent (opid) */ - opid = chtcb->parent; + opid = chtcb->ppid; /* Get the TCB of the child task's parent (otcb) */ @@ -117,7 +252,7 @@ int task_reparent(pid_t ppid, pid_t chpid) if (ppid == 0) { - ppid = otcb->parent; + ppid = otcb->ppid; } /* Get the new parent task's TCB (ptcb) */ @@ -131,12 +266,12 @@ int task_reparent(pid_t ppid, pid_t chpid) /* Then reparent the child */ - chtcb->parent = ppid; /* The task specified by ppid is the new parent */ + chtcb->ppid = ppid; /* The task specified by ppid is the new parent */ #ifdef CONFIG_SCHED_CHILD_STATUS /* Remove the child status entry from old parent TCB */ - child = task_removechild(otcb, chpid); + child = group_removechild(otcb->group, chpid); if (child) { /* Has the new parent's task group supressed child exit status? */ @@ -145,13 +280,13 @@ int task_reparent(pid_t ppid, pid_t chpid) { /* No.. Add the child status entry to the new parent's task group */ - task_addchild(ptcb, child); + group_addchild(ptcb->group, child); } else { /* Yes.. Discard the child status entry */ - task_freechild(child); + group_freechild(child); } /* Either case is a success */ @@ -166,17 +301,20 @@ int task_reparent(pid_t ppid, pid_t chpid) ret = ((otcb->group->tg_flags && GROUP_FLAG_NOCLDWAIT) == 0) ? -ENOENT : OK; } -#else + +#else /* CONFIG_SCHED_CHILD_STATUS */ + DEBUGASSERT(otcb->nchildren > 0); otcb->nchildren--; /* The orignal parent now has one few children */ ptcb->nchildren++; /* The new parent has one additional child */ ret = OK; -#endif + +#endif /* CONFIG_SCHED_CHILD_STATUS */ errout_with_ints: irqrestore(flags); return ret; } - +#endif #endif /* CONFIG_SCHED_HAVE_PARENT */ diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c index b66f3cc7c..b770d46e6 100644 --- a/nuttx/sched/task_setup.c +++ b/nuttx/sched/task_setup.c @@ -172,12 +172,36 @@ static inline void task_saveparent(FAR _TCB *tcb, uint8_t ttype) { FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; +#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_SCHED_CHILD_STATUS) + DEBUGASSERT(tcb && tcb->group && rtcb->group); +#else +#endif + +#ifdef HAVE_GROUP_MEMBERS + /* Save the ID of the parent tasks' task group in the child's task group. + * Do nothing for pthreads. The parent and the child are both members of + * the same task group. + */ + + if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD) + { + /* This is a new task in a new task group, we have to copy the ID from + * the parent's task group structure to child's task group. + */ + + tcb->group->tg_pgid = rtcb->group->tg_gid; + } + +#else + DEBUGASSERT(tcb); + /* Save the parent task's ID in the child task's TCB. I am not sure if * this makes sense for the case of pthreads or not, but I don't think it * is harmful in any event. */ - tcb->parent = rtcb->pid; + tcb->ppid = rtcb->pid; +#endif #ifdef CONFIG_SCHED_CHILD_STATUS /* Tasks can also suppress retention of their child status by applying @@ -192,13 +216,13 @@ static inline void task_saveparent(FAR _TCB *tcb, uint8_t ttype) * parent TCB. There should not be. */ - child = task_findchild(rtcb, tcb->pid); + child = group_findchild(rtcb->group, tcb->pid); DEBUGASSERT(!child); if (!child) { /* Allocate a new status structure */ - child = task_allocchild(); + child = group_allocchild(); } /* Did we successfully find/allocate the child status structure? */ @@ -214,7 +238,7 @@ static inline void task_saveparent(FAR _TCB *tcb, uint8_t ttype) /* Add the entry into the TCB list of children */ - task_addchild(rtcb, child); + group_addchild(rtcb->group, child); } } #else -- cgit v1.2.3 From 5b6482a22bb8b656e3d70a6efc5ae2c77ed2a58b Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 26 Jan 2013 20:17:29 +0000 Subject: Move file data from TCB to task group git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5567 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 2 + nuttx/TODO | 23 +---- nuttx/arch/arm/src/common/up_exit.c | 8 +- nuttx/arch/avr/src/common/up_exit.c | 8 +- nuttx/arch/hc/src/common/up_exit.c | 8 +- nuttx/arch/mips/src/common/up_exit.c | 8 +- nuttx/arch/sh/src/common/up_exit.c | 9 +- nuttx/arch/x86/src/common/up_exit.c | 6 +- nuttx/arch/z16/src/common/up_exit.c | 11 +- nuttx/arch/z80/src/common/up_exit.c | 9 +- nuttx/fs/fs_fdopen.c | 8 +- nuttx/fs/fs_files.c | 101 ++++--------------- nuttx/include/nuttx/fs/fs.h | 89 +++++++---------- nuttx/include/nuttx/sched.h | 42 +++++--- nuttx/sched/group_leave.c | 16 ++- nuttx/sched/sched_getfiles.c | 5 +- nuttx/sched/sched_releasefiles.c | 13 ++- nuttx/sched/sched_releasetcb.c | 4 - nuttx/sched/sched_setupidlefiles.c | 15 +-- nuttx/sched/sched_setuppthreadfiles.c | 8 -- nuttx/sched/sched_setuptaskfiles.c | 49 +++++---- nuttx/sched/task_exithook.c | 182 +++++++++++++++++++++------------- 22 files changed, 288 insertions(+), 336 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 858f82819..ae7105b89 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4034,3 +4034,5 @@ * sched/: Lots of file changed. Don't keep the parent task's task ID in the child task's TCB. Instead, keep the parent task group IN the child task's task group. + * fs/, sched/, include/nuttx/sched.h, and include/nutts/fs/fs.h: + Move file data from TCB to task group structure. diff --git a/nuttx/TODO b/nuttx/TODO index d6bd18d12..cb99f1bf7 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated January 24, 2013) +NuttX TODO List (Last updated January 26, 2013) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -6,7 +6,7 @@ standards, things that could be improved, and ideas for enhancements. nuttx/ - (11) Task/Scheduler (sched/) + (10) Task/Scheduler (sched/) (2) Memory Managment (mm/) (3) Signals (sched/, arch/) (2) pthreads (sched/) @@ -161,25 +161,6 @@ o Task/Scheduler (sched/) Status: Open Priority: Medium Low for now - Title: IMPROVED TASK CONTROL BLOCK STRUCTURE - Description: All task resources that are shared amongst threads have - their own "break-away", reference-counted structure. The - Task Control Block (TCB) of each thread holds a reference - to each breakaway structure (see include/nuttx/sched.h). - It would be more efficent to have one reference counted - structure that holds all of the shared resources. - - These are the current shared structures: - - Environment varaibles (struct environ_s) - - PIC data space and address environments (struct dspace_s) - - File descriptors (struct filelist) - - FILE streams (struct streamlist) - - Sockets (struct socketlist) - Status: Open - Priority: Low. This is an enhancement. It would slight reduce - memory usage but would also increase coupling. These - resources are nicely modular now. - Title: ISSUES WITH atexit() AND on_exit() Description: These functions execute with the following bad properties: diff --git a/nuttx/arch/arm/src/common/up_exit.c b/nuttx/arch/arm/src/common/up_exit.c index 6f6d54f76..5b469fd03 100644 --- a/nuttx/arch/arm/src/common/up_exit.c +++ b/nuttx/arch/arm/src/common/up_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * common/up_exit.c * - * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 201-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -85,12 +85,10 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) #if CONFIG_NFILE_DESCRIPTORS > 0 if (tcb->filelist) { - sdbg(" filelist refcount=%d\n", - tcb->filelist->fl_crefs); - + FAR struct filelist *list = tcb->group->tg_filelist; for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - struct inode *inode = tcb->filelist->fl_files[i].f_inode; + struct inode *inode = list->fl_files[i].f_inode; if (inode) { sdbg(" fd=%d refcount=%d\n", diff --git a/nuttx/arch/avr/src/common/up_exit.c b/nuttx/arch/avr/src/common/up_exit.c index 0a8cc0d18..0813754a0 100644 --- a/nuttx/arch/avr/src/common/up_exit.c +++ b/nuttx/arch/avr/src/common/up_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/avr/src/common/up_exit.c * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -85,12 +85,10 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) #if CONFIG_NFILE_DESCRIPTORS > 0 if (tcb->filelist) { - sdbg(" filelist refcount=%d\n", - tcb->filelist->fl_crefs); - + FAR struct filelist *list = tcb->group->tg_filelist; for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - struct inode *inode = tcb->filelist->fl_files[i].f_inode; + struct inode *inode = list->fl_files[i].f_inode; if (inode) { sdbg(" fd=%d refcount=%d\n", diff --git a/nuttx/arch/hc/src/common/up_exit.c b/nuttx/arch/hc/src/common/up_exit.c index 7cd16b438..5313a1172 100644 --- a/nuttx/arch/hc/src/common/up_exit.c +++ b/nuttx/arch/hc/src/common/up_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/hc/src/common/up_exit.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -85,12 +85,10 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) #if CONFIG_NFILE_DESCRIPTORS > 0 if (tcb->filelist) { - sdbg(" filelist refcount=%d\n", - tcb->filelist->fl_crefs); - + FAR struct filelist *list = tcb->group->tg_filelist; for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - struct inode *inode = tcb->filelist->fl_files[i].f_inode; + struct inode *inode = list->fl_files[i].f_inode; if (inode) { sdbg(" fd=%d refcount=%d\n", diff --git a/nuttx/arch/mips/src/common/up_exit.c b/nuttx/arch/mips/src/common/up_exit.c index 876b486b6..5a7b68a99 100644 --- a/nuttx/arch/mips/src/common/up_exit.c +++ b/nuttx/arch/mips/src/common/up_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/mips/src/common/up_exit.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -87,12 +87,10 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) #if CONFIG_NFILE_DESCRIPTORS > 0 if (tcb->filelist) { - sdbg(" filelist refcount=%d\n", - tcb->filelist->fl_crefs); - + FAR struct filelist *list = tcb->group->tg_filelist; for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - struct inode *inode = tcb->filelist->fl_files[i].f_inode; + struct inode *inode = list->fl_files[i].f_inode; if (inode) { sdbg(" fd=%d refcount=%d\n", diff --git a/nuttx/arch/sh/src/common/up_exit.c b/nuttx/arch/sh/src/common/up_exit.c index 84a44a705..af270b335 100644 --- a/nuttx/arch/sh/src/common/up_exit.c +++ b/nuttx/arch/sh/src/common/up_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * common/up_exit.c * - * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -81,16 +81,15 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) #endif sdbg(" TCB=%p name=%s\n", tcb, tcb->argv[0]); + sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 if (tcb->filelist) { - sdbg(" filelist refcount=%d\n", - tcb->filelist->fl_crefs); - + FAR struct filelist *list = tcb->group->tg_filelist; for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - struct inode *inode = tcb->filelist->fl_files[i].f_inode; + struct inode *inode = list->fl_files[i].f_inode; if (inode) { sdbg(" fd=%d refcount=%d\n", diff --git a/nuttx/arch/x86/src/common/up_exit.c b/nuttx/arch/x86/src/common/up_exit.c index e3d27b0af..6a98c7dd0 100644 --- a/nuttx/arch/x86/src/common/up_exit.c +++ b/nuttx/arch/x86/src/common/up_exit.c @@ -85,12 +85,10 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) #if CONFIG_NFILE_DESCRIPTORS > 0 if (tcb->filelist) { - sdbg(" filelist refcount=%d\n", - tcb->filelist->fl_crefs); - + FAR struct filelist *list = tcb->group->tg_filelist; for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - struct inode *inode = tcb->filelist->fl_files[i].f_inode; + struct inode *inode = list->fl_files[i].f_inode; if (inode) { sdbg(" fd=%d refcount=%d\n", diff --git a/nuttx/arch/z16/src/common/up_exit.c b/nuttx/arch/z16/src/common/up_exit.c index 41f058347..ad0c55eed 100644 --- a/nuttx/arch/z16/src/common/up_exit.c +++ b/nuttx/arch/z16/src/common/up_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * common/up_exit.c * - * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -81,17 +81,16 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) int i; #endif - dbg(" TCB=%p name=%s\n", tcb, tcb->argv[0]); + lldbg(" TCB=%p name=%s\n", tcb, tcb->argv[0]); + lldbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 if (tcb->filelist) { - lldbg(" filelist refcount=%d\n", - tcb->filelist->fl_crefs); - + FAR struct filelist *list = tcb->group->tg_filelist; for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - struct inode *inode = tcb->filelist->fl_files[i].f_inode; + struct inode *inode = list->fl_files[i].f_inode; if (inode) { lldbg(" fd=%d refcount=%d\n", diff --git a/nuttx/arch/z80/src/common/up_exit.c b/nuttx/arch/z80/src/common/up_exit.c index 85ddd841e..50289f52b 100644 --- a/nuttx/arch/z80/src/common/up_exit.c +++ b/nuttx/arch/z80/src/common/up_exit.c @@ -82,17 +82,16 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) int i; #endif - dbg(" TCB=%p name=%s\n", tcb, tcb->argv[0]); + lldbg(" TCB=%p name=%s\n", tcb, tcb->argv[0]); + lldbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 if (tcb->filelist) { - lldbg(" filelist refcount=%d\n", - tcb->filelist->fl_crefs); - + FAR struct filelist *list = tcb->group->tg_filelist; for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - struct inode *inode = tcb->filelist->fl_files[i].f_inode; + struct inode *inode = list->fl_files[i].f_inode; if (inode) { lldbg(" fd=%d refcount=%d\n", diff --git a/nuttx/fs/fs_fdopen.c b/nuttx/fs/fs_fdopen.c index fd6aa88a8..629083c77 100644 --- a/nuttx/fs/fs_fdopen.c +++ b/nuttx/fs/fs_fdopen.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/fs_fdopen.c * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -68,9 +68,11 @@ static inline int fs_checkfd(FAR _TCB *tcb, int fd, int oflags) FAR struct filelist *flist; FAR struct inode *inode; - /* Get the file list from the TCB */ + DEBUGASSERT(tcb && tcb->group); - flist = tcb->filelist; + /* Get the file list from the task group */ + + flist = &tcb->group->tg_filelist; /* Get the inode associated with the file descriptor. This should * normally be the case if fd >= 0. But not in the case where the diff --git a/nuttx/fs/fs_files.c b/nuttx/fs/fs_files.c index 06addb1ef..c68ec7e73 100644 --- a/nuttx/fs/fs_files.c +++ b/nuttx/fs/fs_files.c @@ -155,56 +155,19 @@ void files_initialize(void) } /**************************************************************************** - * Name: files_alloclist + * Name: files_initlist * - * Description: Allocate a list of files for a new task + * Description: Initializes the list of files for a new task * ****************************************************************************/ -FAR struct filelist *files_alloclist(void) +void files_initlist(FAR struct filelist *list) { - FAR struct filelist *list; - list = (FAR struct filelist*)kzalloc(sizeof(struct filelist)); - if (list) - { - /* Start with a reference count of one */ - - list->fl_crefs = 1; - - /* Initialize the list access mutex */ + DEBUGASSERT(list); - (void)sem_init(&list->fl_sem, 0, 1); - } + /* Initialize the list access mutex */ - return list; -} - -/**************************************************************************** - * Name: files_addreflist - * - * Description: - * Increase the reference count on a file list - * - ****************************************************************************/ - -int files_addreflist(FAR struct filelist *list) -{ - if (list) - { - /* Increment the reference count on the list. - * NOTE: that we disable interrupts to do this - * (vs. taking the list semaphore). We do this - * because file cleanup operations often must be - * done from the IDLE task which cannot wait - * on semaphores. - */ - - register irqstate_t flags = irqsave(); - list->fl_crefs++; - irqrestore(flags); - } - - return OK; + (void)sem_init(&list->fl_sem, 0, 1); } /**************************************************************************** @@ -215,51 +178,25 @@ int files_addreflist(FAR struct filelist *list) * ****************************************************************************/ -int files_releaselist(FAR struct filelist *list) +void files_releaselist(FAR struct filelist *list) { - int crefs; - if (list) - { - /* Decrement the reference count on the list. - * NOTE: that we disable interrupts to do this - * (vs. taking the list semaphore). We do this - * because file cleanup operations often must be - * done from the IDLE task which cannot wait - * on semaphores. - */ - - register irqstate_t flags = irqsave(); - crefs = --(list->fl_crefs); - irqrestore(flags); - - /* If the count decrements to zero, then there is no reference - * to the structure and it should be deallocated. Since there - * are references, it would be an error if any task still held - * a reference to the list's semaphore. - */ - - if (crefs <= 0) - { - int i; + int i; - /* Close each file descriptor .. Normally, you would need - * take the list semaphore, but it is safe to ignore the - * semaphore in this context because there are no references - */ + DEBUGASSERT(list); - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) - { - (void)_files_close(&list->fl_files[i]); - } - - /* Destroy the semaphore and release the filelist */ + /* Close each file descriptor .. Normally, you would need take the list + * semaphore, but it is safe to ignore the semaphore in this context because + * there should not be any references in this context. + */ - (void)sem_destroy(&list->fl_sem); - sched_free(list); - } + for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + { + (void)_files_close(&list->fl_files[i]); } - return OK; + /* Destroy the semaphore */ + + (void)sem_destroy(&list->fl_sem); } /**************************************************************************** diff --git a/nuttx/include/nuttx/fs/fs.h b/nuttx/include/nuttx/fs/fs.h index 327bf37ca..02855460c 100644 --- a/nuttx/include/nuttx/fs/fs.h +++ b/nuttx/include/nuttx/fs/fs.h @@ -240,7 +240,6 @@ struct file struct filelist { sem_t fl_sem; /* Manage access to the file list */ - int16_t fl_crefs; /* Reference count */ struct file fl_files[CONFIG_NFILE_DESCRIPTORS]; }; #endif @@ -318,7 +317,8 @@ typedef int (*foreach_mountpoint_t)(FAR const char *mountpoint, #undef EXTERN #if defined(__cplusplus) #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif @@ -333,7 +333,7 @@ extern "C" { * ****************************************************************************/ -EXTERN void weak_function fs_initialize(void); +void weak_function fs_initialize(void); /* fs_foreachmountpoint.c ***************************************************/ /**************************************************************************** @@ -357,7 +357,7 @@ EXTERN void weak_function fs_initialize(void); ****************************************************************************/ #ifndef CONFIG_DISABLE_MOUNTPOUNT -EXTERN int foreach_mountpoint(foreach_mountpoint_t handler, FAR void *arg); +int foreach_mountpoint(foreach_mountpoint_t handler, FAR void *arg); #endif /* fs_registerdriver.c ******************************************************/ @@ -384,9 +384,8 @@ EXTERN int foreach_mountpoint(foreach_mountpoint_t handler, FAR void *arg); * ****************************************************************************/ -EXTERN int register_driver(const char *path, - const struct file_operations *fops, - mode_t mode, void *priv); +int register_driver(FAR const char *path, FAR const struct file_operations *fops, + mode_t mode, FAR void *priv); /* fs_registerblockdriver.c *************************************************/ /**************************************************************************** @@ -412,9 +411,9 @@ EXTERN int register_driver(const char *path, * ****************************************************************************/ -EXTERN int register_blockdriver(const char *path, - const struct block_operations *bops, - mode_t mode, void *priv); +int register_blockdriver(FAR const char *path, + FAR const struct block_operations *bops, mode_t mode, + FAR void *priv); /* fs_unregisterdriver.c ****************************************************/ /**************************************************************************** @@ -425,7 +424,7 @@ EXTERN int register_blockdriver(const char *path, * ****************************************************************************/ -EXTERN int unregister_driver(const char *path); +int unregister_driver(const char *path); /* fs_unregisterblockdriver.c ***********************************************/ /**************************************************************************** @@ -436,7 +435,7 @@ EXTERN int unregister_driver(const char *path); * ****************************************************************************/ -EXTERN int unregister_blockdriver(const char *path); +int unregister_blockdriver(const char *path); /* fs_open.c ****************************************************************/ /**************************************************************************** @@ -447,30 +446,19 @@ EXTERN int unregister_blockdriver(const char *path); * ****************************************************************************/ -EXTERN int inode_checkflags(FAR struct inode *inode, int oflags); +int inode_checkflags(FAR struct inode *inode, int oflags); /* fs_files.c ***************************************************************/ /**************************************************************************** - * Name: files_alloclist - * - * Description: Allocate a list of files for a new task - * - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -EXTERN FAR struct filelist *files_alloclist(void); -#endif - -/**************************************************************************** - * Name: files_addreflist + * Name: files_initlist * * Description: - * Increase the reference count on a file list + * Initializes the list of files for a new task * ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 -EXTERN int files_addreflist(FAR struct filelist *list); +void files_initlist(FAR struct filelist *list); #endif /**************************************************************************** @@ -482,7 +470,7 @@ EXTERN int files_addreflist(FAR struct filelist *list); ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 -EXTERN int files_releaselist(FAR struct filelist *list); +void files_releaselist(FAR struct filelist *list); #endif /**************************************************************************** @@ -495,7 +483,7 @@ EXTERN int files_releaselist(FAR struct filelist *list); ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 -EXTERN int files_dup(FAR struct file *filep1, FAR struct file *filep2); +int files_dup(FAR struct file *filep1, FAR struct file *filep2); #endif /* fs_filedup.c *************************************************************/ @@ -515,7 +503,7 @@ EXTERN int files_dup(FAR struct file *filep1, FAR struct file *filep2); ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 -EXTERN int file_dup(int fd, int minfd); +int file_dup(int fd, int minfd); #endif /* fs_filedup2.c ************************************************************/ @@ -535,7 +523,7 @@ EXTERN int file_dup(int fd, int minfd); #if CONFIG_NFILE_DESCRIPTORS > 0 #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 -EXTERN int file_dup2(int fd1, int fd2); +int file_dup2(int fd1, int fd2); #else # define file_dup2(fd1, fd2) dup2(fd1, fd2) #endif @@ -566,8 +554,8 @@ EXTERN int file_dup2(int fd1, int fd2); ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 -EXTERN int open_blockdriver(FAR const char *pathname, int mountflags, - FAR struct inode **ppinode); +int open_blockdriver(FAR const char *pathname, int mountflags, + FAR struct inode **ppinode); #endif /* fs_closeblockdriver.c ****************************************************/ @@ -589,7 +577,7 @@ EXTERN int open_blockdriver(FAR const char *pathname, int mountflags, ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 -EXTERN int close_blockdriver(FAR struct inode *inode); +int close_blockdriver(FAR struct inode *inode); #endif /* fs_fdopen.c **************************************************************/ @@ -609,7 +597,7 @@ typedef struct _TCB _TCB; #define __TCB_DEFINED__ #endif -EXTERN FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb); +FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb); #endif /* lib/stdio/lib_fflush.c **************************************************/ @@ -623,7 +611,7 @@ EXTERN FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb); ****************************************************************************/ #if CONFIG_NFILE_STREAMS > 0 -EXTERN int lib_flushall(FAR struct streamlist *list); +int lib_flushall(FAR struct streamlist *list); #endif /* drivers/dev_null.c *******************************************************/ @@ -635,7 +623,7 @@ EXTERN int lib_flushall(FAR struct streamlist *list); * ****************************************************************************/ -EXTERN void devnull_register(void); +void devnull_register(void); /* drivers/dev_zero.c *******************************************************/ /**************************************************************************** @@ -646,7 +634,7 @@ EXTERN void devnull_register(void); * ****************************************************************************/ -EXTERN void devzero_register(void); +void devzero_register(void); /* drivers/loop.c ***********************************************************/ /**************************************************************************** @@ -658,8 +646,8 @@ EXTERN void devzero_register(void); * ****************************************************************************/ -EXTERN int losetup(FAR const char *devname, FAR const char *filename, - uint16_t sectsize, off_t offset, bool readonly); +int losetup(FAR const char *devname, FAR const char *filename, + uint16_t sectsize, off_t offset, bool readonly); /**************************************************************************** * Name: loteardown @@ -669,7 +657,7 @@ EXTERN int losetup(FAR const char *devname, FAR const char *filename, * ****************************************************************************/ -EXTERN int loteardown(FAR const char *devname); +int loteardown(FAR const char *devname); /* drivers/bch/bchdev_register.c ********************************************/ /**************************************************************************** @@ -681,8 +669,8 @@ EXTERN int loteardown(FAR const char *devname); * ****************************************************************************/ -EXTERN int bchdev_register(FAR const char *blkdev, FAR const char *chardev, - bool readonly); +int bchdev_register(FAR const char *blkdev, FAR const char *chardev, + bool readonly); /* drivers/bch/bchdev_unregister.c ******************************************/ /**************************************************************************** @@ -694,7 +682,7 @@ EXTERN int bchdev_register(FAR const char *blkdev, FAR const char *chardev, * ****************************************************************************/ -EXTERN int bchdev_unregister(FAR const char *chardev); +int bchdev_unregister(FAR const char *chardev); /* Low level, direct access. NOTE: low-level access and character driver access * are incompatible. One and only one access method should be implemented. @@ -710,8 +698,7 @@ EXTERN int bchdev_unregister(FAR const char *chardev); * ****************************************************************************/ -EXTERN int bchlib_setup(FAR const char *blkdev, bool readonly, - FAR void **handle); +int bchlib_setup(FAR const char *blkdev, bool readonly, FAR void **handle); /* drivers/bch/bchlib_teardown.c ********************************************/ /**************************************************************************** @@ -723,7 +710,7 @@ EXTERN int bchlib_setup(FAR const char *blkdev, bool readonly, * ****************************************************************************/ -EXTERN int bchlib_teardown(FAR void *handle); +int bchlib_teardown(FAR void *handle); /* drivers/bch/bchlib_read.c ************************************************/ /**************************************************************************** @@ -735,8 +722,8 @@ EXTERN int bchlib_teardown(FAR void *handle); * ****************************************************************************/ -EXTERN ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, - size_t len); +ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, + size_t len); /* drivers/bch/bchlib_write.c ***********************************************/ /**************************************************************************** @@ -748,8 +735,8 @@ EXTERN ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, * ****************************************************************************/ -EXTERN ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, - size_t offset, size_t len); +ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, + size_t len); #undef EXTERN #if defined(__cplusplus) diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 8ebb7db4c..1580a80d3 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -52,6 +52,7 @@ #include #include +#include #include /******************************************************************************** @@ -63,14 +64,24 @@ #undef HAVE_TASK_GROUP #undef HAVE_GROUP_MEMBERS +/* We need a group an group members if we are supportint the parent/child + * relationship. + */ + #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) -# define HAVE_TASK_GROUP 1 -# define HAVE_GROUP_MEMBERS 1 -#endif +# define HAVE_TASK_GROUP 1 +# define HAVE_GROUP_MEMBERS 1 -#if !defined(CONFIG_DISABLE_ENVIRON) -# undef HAVE_TASK_GROUP -# define HAVE_TASK_GROUP 1 +/* We need a group (but not members) if any other resources are shared within + * a task group. + */ + +#else +# if !defined(CONFIG_DISABLE_ENVIRON) +# define HAVE_TASK_GROUP 1 +# elif CONFIG_NFILE_DESCRIPTORS > 0 +# define HAVE_TASK_GROUP 1 +# endif #endif /* In any event, we don't need group members if support for pthreads is disabled */ @@ -79,7 +90,7 @@ # undef HAVE_GROUP_MEMBERS #endif -/* Task Management Definitins ***************************************************/ +/* Task Management Definitions **************************************************/ /* This is the maximum number of times that a lock can be set */ @@ -282,16 +293,19 @@ struct task_group_s FAR char *tg_envp; /* Allocated environment strings */ #endif - /* PIC data space and address environments */ + /* PIC data space and address environments ************************************/ /* Not yet (see struct dspace_s) */ - /* File descriptors */ - /* Not yet (see struct filelist) */ + /* File descriptors ***********************************************************/ - /* FILE streams */ +#if CONFIG_NFILE_DESCRIPTORS > 0 + struct filelist tg_filelist; /* Maps file descriptor to file */ +#endif + + /* FILE streams ***************************************************************/ /* Not yet (see streamlist) */ - /* Sockets */ + /* Sockets ********************************************************************/ /* Not yet (see struct socketlist) */ }; #endif @@ -433,10 +447,6 @@ struct _TCB /* File system support ********************************************************/ -#if CONFIG_NFILE_DESCRIPTORS > 0 - FAR struct filelist *filelist; /* Maps file descriptor to file */ -#endif - #if CONFIG_NFILE_STREAMS > 0 FAR struct streamlist *streams; /* Holds C buffered I/O info */ #endif diff --git a/nuttx/sched/group_leave.c b/nuttx/sched/group_leave.c index add424185..f5dca1829 100644 --- a/nuttx/sched/group_leave.c +++ b/nuttx/sched/group_leave.c @@ -176,6 +176,13 @@ void group_leave(FAR _TCB *tcb) #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) group_removechildren(tcb->group); +#endif + /* Free all file-related resources now. We really need to close + * files as soon as possible while we still have a functioning task. + */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 + (void)sched_releasefiles(tcb); #endif /* Release all shared environment variables */ @@ -231,7 +238,14 @@ void group_leave(FAR _TCB *tcb) #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) group_removechildren(tcb->group); #endif - /* Release all shared environment variables */ + /* Free all file-related resources now. We really need to close + * files as soon as possible while we still have a functioning task. + */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 + (void)sched_releasefiles(tcb); +#endif + /* Release all shared environment variables */ #ifndef CONFIG_DISABLE_ENVIRON env_release(tcb); diff --git a/nuttx/sched/sched_getfiles.c b/nuttx/sched/sched_getfiles.c index 256b4cb6b..eca4ba3ff 100644 --- a/nuttx/sched/sched_getfiles.c +++ b/nuttx/sched/sched_getfiles.c @@ -70,7 +70,10 @@ FAR struct filelist *sched_getfiles(void) { FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - return rtcb->filelist; + FAR struct task_group_s *group = rtcb->group; + + DEBUGASSERT(group); + return &group->tg_filelist; } #endif /* CONFIG_NFILE_DESCRIPTORS */ diff --git a/nuttx/sched/sched_releasefiles.c b/nuttx/sched/sched_releasefiles.c index a3ef71af4..4be92f4eb 100644 --- a/nuttx/sched/sched_releasefiles.c +++ b/nuttx/sched/sched_releasefiles.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched_releasefiles.c * - * Copyright (C) 2007, 2008, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -78,13 +78,12 @@ int sched_releasefiles(_TCB *tcb) if (tcb) { #if CONFIG_NFILE_DESCRIPTORS > 0 - /* Free the file descriptor list */ + FAR struct task_group_s *group = tcb->group; + DEBUGASSERT(group); - if (tcb->filelist) - { - files_releaselist(tcb->filelist); - tcb->filelist = NULL; - } + /* Free resources used by the file descriptor list */ + + files_releaselist(&group->tg_filelist); #if CONFIG_NFILE_STREAMS > 0 /* Free the stream list */ diff --git a/nuttx/sched/sched_releasetcb.c b/nuttx/sched/sched_releasetcb.c index 00d4c2c0c..02f7170c2 100644 --- a/nuttx/sched/sched_releasetcb.c +++ b/nuttx/sched/sched_releasetcb.c @@ -163,10 +163,6 @@ int sched_releasetcb(FAR _TCB *tcb) } } - /* Release any allocated file structures */ - - ret = sched_releasefiles(tcb); - /* Release this thread's reference to the address environment */ #ifdef CONFIG_ADDRENV diff --git a/nuttx/sched/sched_setupidlefiles.c b/nuttx/sched/sched_setupidlefiles.c index ae814e1a6..4bbd4d3b7 100644 --- a/nuttx/sched/sched_setupidlefiles.c +++ b/nuttx/sched/sched_setupidlefiles.c @@ -79,18 +79,21 @@ int sched_setupidlefiles(FAR _TCB *tcb) { +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct task_group_s *group = tcb->group; +#endif #if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) int fd; #endif - /* Allocate file descriptors for the TCB */ +#if CONFIG_NFILE_DESCRIPTORS > 0 + DEBUGASSERT(group); +#endif + + /* Initialize file descriptors for the TCB */ #if CONFIG_NFILE_DESCRIPTORS > 0 - tcb->filelist = files_alloclist(); - if (!tcb->filelist) - { - return -ENOMEM; - } + files_initlist(&group->tg_filelist); #endif /* Allocate socket descriptors for the TCB */ diff --git a/nuttx/sched/sched_setuppthreadfiles.c b/nuttx/sched/sched_setuppthreadfiles.c index 648d9273e..78d6cbfec 100644 --- a/nuttx/sched/sched_setuppthreadfiles.c +++ b/nuttx/sched/sched_setuppthreadfiles.c @@ -79,14 +79,6 @@ int sched_setuppthreadfiles(FAR _TCB *tcb) { FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; -#if CONFIG_NFILE_DESCRIPTORS > 0 - /* The child thread inherits the parent file descriptors */ - - tcb->filelist = rtcb->filelist; - files_addreflist(tcb->filelist); - -#endif /* CONFIG_NFILE_DESCRIPTORS */ - #if CONFIG_NSOCKET_DESCRIPTORS > 0 /* The child thread inherits the parent socket descriptors */ diff --git a/nuttx/sched/sched_setuptaskfiles.c b/nuttx/sched/sched_setuptaskfiles.c index d01b8d4cd..9e44147e9 100644 --- a/nuttx/sched/sched_setuptaskfiles.c +++ b/nuttx/sched/sched_setuptaskfiles.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched_setuptaskfiles.c * - * Copyright (C) 2007-2008, 2010, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2008, 2010, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -93,34 +93,33 @@ static inline void sched_dupfiles(FAR _TCB *tcb) FAR struct file *child; int i; + DEBUGASSERT(tcb && tcb->group && rtcb->group); + /* Duplicate the file descriptors. This will be either all of the * file descriptors or just the first three (stdin, stdout, and stderr) * if CONFIG_FDCLONE_STDIO is defined. NFSDS_TOCLONE is set * accordingly above. */ - if (rtcb->filelist) - { - /* Get pointers to the parent and child task file lists */ + /* Get pointers to the parent and child task file lists */ - parent = rtcb->filelist->fl_files; - child = tcb->filelist->fl_files; + parent = rtcb->group->tg_filelist.fl_files; + child = tcb->group->tg_filelist.fl_files; - /* Check each file in the parent file list */ + /* Check each file in the parent file list */ - for (i = 0; i < NFDS_TOCLONE; i++) - { - /* Check if this file is opened by the parent. We can tell if - * if the file is open because it contain a reference to a non-NULL - * i-node structure. - */ + for (i = 0; i < NFDS_TOCLONE; i++) + { + /* Check if this file is opened by the parent. We can tell if + * if the file is open because it contain a reference to a non-NULL + * i-node structure. + */ - if (parent[i].f_inode) - { - /* Yes... duplicate it for the child */ + if (parent[i].f_inode) + { + /* Yes... duplicate it for the child */ - (void)files_dup(&parent[i], &child[i]); - } + (void)files_dup(&parent[i], &child[i]); } } } @@ -209,14 +208,14 @@ static inline void sched_dupsockets(FAR _TCB *tcb) int sched_setuptaskfiles(FAR _TCB *tcb) { - /* Allocate file descriptors for the TCB */ - #if CONFIG_NFILE_DESCRIPTORS > 0 - tcb->filelist = files_alloclist(); - if (!tcb->filelist) - { - return -ENOMEM; - } + FAR struct task_group_s *group = tcb->group; + + DEBUGASSERT(group); + + /* Initialize file descriptors for the TCB */ + + files_initlist(&group->tg_filelist); #endif /* Allocate socket descriptors for the TCB */ diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index 3fdf08bf7..5a2b9e57e 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -177,6 +177,89 @@ static inline void task_onexit(FAR _TCB *tcb, int status) # define task_onexit(tcb,status) #endif +/**************************************************************************** + * Name: task_exitstatus + * + * Description: + * Report exit status when main task of a task group exits + * + ****************************************************************************/ + +#ifdef CONFIG_SCHED_CHILD_STATUS +static inline void task_exitstatus(FAR struct task_group_s *group, int status) +{ + FAR struct child_status_s *child; + + /* Check if the parent task group has suppressed retention of + * child exit status information. + */ + + if ((group->tg_flags & GROUP_FLAG_NOCLDWAIT) == 0) + { + /* No.. Find the exit status entry for this task in the parent TCB */ + + child = group_findchild(group, getpid()); + DEBUGASSERT(child); + if (child) + { +#ifndef HAVE_GROUP_MEMBERS + /* No group members? Save the exit status */ + + child->ch_status = status; +#endif + /* Save the exit status.. For the case of HAVE_GROUP_MEMBERS, + * the child status will be as exited until the last member + * of the task group exits. + */ + + child->ch_status = status; + } + } +} +#else + +# define task_exitstatus(group,status) + +#endif /* CONFIG_SCHED_CHILD_STATUS */ + +/**************************************************************************** + * Name: task_groupexit + * + * Description: + * Mark that the final thread of a child task group as exited. + * + ****************************************************************************/ + +#ifdef CONFIG_SCHED_CHILD_STATUS +static inline void task_groupexit(FAR struct task_group_s *group) +{ + FAR struct child_status_s *child; + + /* Check if the parent task group has suppressed retention of child exit + * status information. + */ + + if ((group->tg_flags & GROUP_FLAG_NOCLDWAIT) == 0) + { + /* No.. Find the exit status entry for this task in the parent TCB */ + + child = group_findchild(group, getpid()); + DEBUGASSERT(child); + if (child) + { + /* Mark that all members of the child task group has exit'ed */ + + child->ch_flags |= CHILD_FLAG_EXITED; + } + } +} + +#else + +# define task_groupexit(group) + +#endif /* CONFIG_SCHED_CHILD_STATUS */ + /**************************************************************************** * Name: task_sigchild * @@ -195,55 +278,41 @@ static inline void task_sigchild(gid_t pgid, FAR _TCB *ctcb, int status) DEBUGASSERT(chgrp); - /* Only the final exiting thread in a task group should generate SIGCHLD. */ + /* Get the parent task group. It is possible that all of the members of + * the parent task group have exited. This would not be an error. In + * this case, the child task group has been orphaned. + */ - if (chgrp->tg_nmembers == 1) + pgrp = group_find(chgrp->tg_pgid); + if (!pgrp) { - /* Get the parent task group */ - - pgrp = group_find(chgrp->tg_pgid); - - /* It is possible that all of the members of the parent task group - * have exited. This would not be an error. In this case, the - * child task group has been orphaned. + /* Set the task group ID to an invalid group ID. The dead parent + * task group ID could get reused some time in the future. */ - if (!pgrp) - { - /* Set the task group ID to an invalid group ID. The dead parent - * task group ID could get reused some time in the future. - */ - - chgrp->tg_pgid = INVALID_GROUP_ID; - return; - } - -#ifdef CONFIG_SCHED_CHILD_STATUS - /* Check if the parent task group has suppressed retention of child exit - * status information. Only 'tasks' report exit status, not pthreads. - * pthreads have a different mechanism. - */ - - if ((pgrp->tg_flags & GROUP_FLAG_NOCLDWAIT) == 0) - { - FAR struct child_status_s *child; + chgrp->tg_pgid = INVALID_GROUP_ID; + return; + } - /* No.. Find the exit status entry for this task in the parent TCB */ + /* Save the exit status now if this is the main thread of the task group + * that is exiting. Only the exiting main task of a task group carries + * interpretable exit Check if this is the main task that is exiting. + */ - child = group_findchild(pgrp, getpid()); - DEBUGASSERT(child); - if (child) - { - /* Mark that the child has exit'ed */ + if ((ctcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_TASK) + { + task_exitstatus(pgrp, status); + } - child->ch_flags |= CHILD_FLAG_EXITED; + /* But only the final exiting thread in a task group, whatever it is, + * should generate SIGCHLD. + */ - /* Save the exit status */ + if (chgrp->tg_nmembers == 1) + { + /* Mark that all of the threads in the task group have exited */ - child->ch_status = status; - } - } -#endif /* CONFIG_SCHED_CHILD_STATUS */ + task_groupexit(pgrp); /* Create the siginfo structure. We don't actually know the cause. * That is a bug. Let's just say that the child task just exit-ted @@ -278,30 +347,9 @@ static inline void task_sigchild(FAR _TCB *ptcb, FAR _TCB *ctcb, int status) if ((ctcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_TASK) { #ifdef CONFIG_SCHED_CHILD_STATUS - /* Check if the parent task group has suppressed retention of child exit - * status information. Only 'tasks' report exit status, not pthreads. - * pthreads have a different mechanism. - */ + /* Save the exit status now of the main thread */ - if ((ptcb->group->tg_flags & GROUP_FLAG_NOCLDWAIT) == 0) - { - FAR struct child_status_s *child; - - /* No.. Find the exit status entry for this task in the parent TCB */ - - child = group_findchild(ptcb->group, getpid()); - DEBUGASSERT(child); - if (child) - { - /* Mark that the child has exit'ed */ - - child->ch_flags |= CHILD_FLAG_EXITED; - - /* Save the exit status */ - - child->ch_status = status; - } - } + task_exitstatus(ptcb->group, status); #else /* CONFIG_SCHED_CHILD_STATUS */ @@ -506,14 +554,6 @@ void task_exithook(FAR _TCB *tcb, int status) group_leave(tcb); #endif - /* Free all file-related resources now. This gets called again - * just be be certain when the TCB is delallocated. However, we - * really need to close files as soon as possible while we still - * have a functioning task. - */ - - (void)sched_releasefiles(tcb); - /* Deallocate anything left in the TCB's queues */ #ifndef CONFIG_DISABLE_SIGNALS -- cgit v1.2.3 From 3bec164b3ae1cd7f9b5dcec532e7d073be96d45d Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 26 Jan 2013 21:01:19 +0000 Subject: Fix a recently introduced memory leak git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5568 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/sched/Makefile | 3 +- nuttx/sched/group_internal.h | 8 +++ nuttx/sched/group_leave.c | 107 ++++++++++++++++++++---------------- nuttx/sched/group_releasefiles.c | 113 +++++++++++++++++++++++++++++++++++++++ nuttx/sched/os_internal.h | 2 - nuttx/sched/sched_releasefiles.c | 113 --------------------------------------- 6 files changed, 185 insertions(+), 161 deletions(-) create mode 100644 nuttx/sched/group_releasefiles.c delete mode 100644 nuttx/sched/sched_releasefiles.c diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index d059152e0..c8fe7cf69 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -41,7 +41,7 @@ AOBJS = $(ASRCS:.S=$(OBJEXT)) MISC_SRCS = os_start.c os_bringup.c errno_getptr.c errno_get.c errno_set.c MISC_SRCS += sched_garbage.c sched_setupstreams.c sched_getfiles.c sched_getsockets.c MISC_SRCS += sched_getstreams.c sched_setupidlefiles.c sched_setuptaskfiles.c -MISC_SRCS += sched_setuppthreadfiles.c sched_releasefiles.c +MISC_SRCS += sched_setuppthreadfiles.c TSK_SRCS = prctl.c task_create.c task_init.c task_setup.c task_activate.c TSK_SRCS += task_start.c task_delete.c task_deletecurrent.c task_exithook.c @@ -81,6 +81,7 @@ endif endif GRP_SRCS = group_create.c group_join.c group_leave.c group_find.c +GRP_SRCS += group_releasefiles.c ifeq ($(CONFIG_SCHED_HAVE_PARENT),y) GRP_SRCS += task_reparent.c diff --git a/nuttx/sched/group_internal.h b/nuttx/sched/group_internal.h index b78b38453..39d0a2b7c 100644 --- a/nuttx/sched/group_internal.h +++ b/nuttx/sched/group_internal.h @@ -127,6 +127,14 @@ FAR struct child_status_s *group_removechild(FAR struct task_group_s *group, pid_t pid); void group_removechildren(FAR struct task_group_s *group); +/* File/network resources */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 +int group_releasefiles(FAR _TCB *tcb); +#else +# define group_releasefiles(t) (OK) +#endif + #endif /* CONFIG_SCHED_CHILD_STATUS */ #endif /* CONFIG_SCHED_HAVE_PARENT */ diff --git a/nuttx/sched/group_leave.c b/nuttx/sched/group_leave.c index f5dca1829..158ba30b5 100644 --- a/nuttx/sched/group_leave.c +++ b/nuttx/sched/group_leave.c @@ -124,6 +124,64 @@ void group_remove(FAR struct task_group_s *group) } #endif +/***************************************************************************** + * Name: group_release + * + * Description: + * Release group resources after the last member has left the group. + * + * Parameters: + * group - The group to be removed. + * + * Return Value: + * None. + * + * Assumptions: + * Called during task deletion in a safe context. No special precautions + * are required here. + * + *****************************************************************************/ + +static inline void group_release(FAR _TCB *tcb, + FAR struct task_group_s *group) +{ + /* Free all un-reaped child exit status */ + +#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) + group_removechildren(group); +#endif + + /* Free all file-related resources now. We really need to close files as + * soon as possible while we still have a functioning task. + */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + (void)group_releasefiles(tcb); +#endif + + /* Release all shared environment variables */ + +#ifndef CONFIG_DISABLE_ENVIRON + env_release(tcb); +#endif + + /* Remove the group from the list of groups */ + + group_remove(group); + + /* Release the members array */ + + if (group->tg_members) + { + sched_free(group->tg_members); + group->tg_members = NULL; + } + + /* Release the group container itself */ + + sched_free(group); +} + /***************************************************************************** * Public Functions *****************************************************************************/ @@ -150,7 +208,6 @@ void group_remove(FAR struct task_group_s *group) *****************************************************************************/ #ifdef HAVE_GROUP_MEMBERS - void group_leave(FAR _TCB *tcb) { FAR struct task_group_s *group; @@ -171,31 +228,9 @@ void group_leave(FAR _TCB *tcb) if (ret == 0) { - /* Release all of the resource contained within the group */ - /* Free all un-reaped child exit status */ - -#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) - group_removechildren(tcb->group); -#endif - /* Free all file-related resources now. We really need to close - * files as soon as possible while we still have a functioning task. - */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 - (void)sched_releasefiles(tcb); -#endif - /* Release all shared environment variables */ + /* Release all of the resource held by the task group */ -#ifndef CONFIG_DISABLE_ENVIRON - env_release(tcb); -#endif - /* Remove the group from the list of groups */ - - group_remove(group); - - /* Release the group container itself */ - - sched_free(group); + group_release(tcb, group); } /* In any event, we can detach the group from the TCB so that we won't @@ -232,27 +267,9 @@ void group_leave(FAR _TCB *tcb) else { - /* Release all of the resource contained within the group */ - /* Free all un-reaped child exit status */ - -#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) - group_removechildren(tcb->group); -#endif - /* Free all file-related resources now. We really need to close - * files as soon as possible while we still have a functioning task. - */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 - (void)sched_releasefiles(tcb); -#endif - /* Release all shared environment variables */ - -#ifndef CONFIG_DISABLE_ENVIRON - env_release(tcb); -#endif - /* Release the group container itself */ + /* Release all of the resource held by the task group */ - sched_free(group); + group_release(tcb, group); } /* In any event, we can detach the group from the TCB so we won't do diff --git a/nuttx/sched/group_releasefiles.c b/nuttx/sched/group_releasefiles.c new file mode 100644 index 000000000..40bf373b4 --- /dev/null +++ b/nuttx/sched/group_releasefiles.c @@ -0,0 +1,113 @@ +/**************************************************************************** + * sched/group_releasefiles.c + * + * Copyright (C) 2007, 2008, 2012-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: group_releasefiles + * + * Description: + * Release file resources attached to a TCB. This file may be called + * multiple times as a task exists. It will be called as early as possible + * to support proper closing of complex drivers that may need to wait + * on external events. + * + * Parameters: + * tcb - tcb of the new task. + * + * Return Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +int group_releasefiles(_TCB *tcb) +{ + if (tcb) + { +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct task_group_s *group = tcb->group; + DEBUGASSERT(group); + + /* Free resources used by the file descriptor list */ + + files_releaselist(&group->tg_filelist); + +#if CONFIG_NFILE_STREAMS > 0 + /* Free the stream list */ + + if (tcb->streams) + { + lib_releaselist(tcb->streams); + tcb->streams = NULL; + } +#endif /* CONFIG_NFILE_STREAMS */ +#endif /* CONFIG_NFILE_DESCRIPTORS */ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + /* Free the file descriptor list */ + + if (tcb->sockets) + { + net_releaselist(tcb->sockets); + tcb->sockets = NULL; + } +#endif /* CONFIG_NSOCKET_DESCRIPTORS */ + } + + return OK; +} + +#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index e3d0fd48f..5aa6487d0 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -105,7 +105,6 @@ enum os_crash_codes_e # define sched_setupidlefiles(t) (OK) # define sched_setuptaskfiles(t) (OK) # define sched_setuppthreadfiles(t) (OK) -# define sched_releasefiles(t) (OK) #endif /* One processor family supported by NuttX has a single, fixed hardware stack. @@ -301,7 +300,6 @@ int sched_setuppthreadfiles(FAR _TCB *tcb); #if CONFIG_NFILE_STREAMS > 0 int sched_setupstreams(FAR _TCB *tcb); #endif -int sched_releasefiles(FAR _TCB *tcb); #endif int sched_releasetcb(FAR _TCB *tcb); diff --git a/nuttx/sched/sched_releasefiles.c b/nuttx/sched/sched_releasefiles.c deleted file mode 100644 index 4be92f4eb..000000000 --- a/nuttx/sched/sched_releasefiles.c +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** - * sched/sched_releasefiles.c - * - * Copyright (C) 2007, 2008, 2012-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sched_releasefiles - * - * Description: - * Release file resources attached to a TCB. This file may be called - * multiple times as a task exists. It will be called as early as possible - * to support proper closing of complex drivers that may need to wait - * on external events. - * - * Parameters: - * tcb - tcb of the new task. - * - * Return Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -int sched_releasefiles(_TCB *tcb) -{ - if (tcb) - { -#if CONFIG_NFILE_DESCRIPTORS > 0 - FAR struct task_group_s *group = tcb->group; - DEBUGASSERT(group); - - /* Free resources used by the file descriptor list */ - - files_releaselist(&group->tg_filelist); - -#if CONFIG_NFILE_STREAMS > 0 - /* Free the stream list */ - - if (tcb->streams) - { - lib_releaselist(tcb->streams); - tcb->streams = NULL; - } -#endif /* CONFIG_NFILE_STREAMS */ -#endif /* CONFIG_NFILE_DESCRIPTORS */ - -#if CONFIG_NSOCKET_DESCRIPTORS > 0 - /* Free the file descriptor list */ - - if (tcb->sockets) - { - net_releaselist(tcb->sockets); - tcb->sockets = NULL; - } -#endif /* CONFIG_NSOCKET_DESCRIPTORS */ - } - - return OK; -} - -#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ -- cgit v1.2.3 From b82c36961aa730fc39a9fc8eac17e2518128cb67 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 26 Jan 2013 22:25:21 +0000 Subject: Move stream data from TCB to task group structure. git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5569 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 2 + nuttx/arch/arm/src/common/up_exit.c | 42 +++++------ nuttx/arch/avr/src/common/up_exit.c | 42 +++++------ nuttx/arch/hc/src/common/up_exit.c | 42 +++++------ nuttx/arch/mips/src/common/up_exit.c | 42 +++++------ nuttx/arch/sh/src/common/up_exit.c | 42 +++++------ nuttx/arch/x86/src/common/up_exit.c | 44 +++++------ nuttx/arch/z16/src/common/up_exit.c | 42 +++++------ nuttx/arch/z80/src/common/up_exit.c | 44 +++++------ nuttx/fs/fs_fdopen.c | 5 +- nuttx/include/nuttx/fs/fs.h | 1 - nuttx/include/nuttx/lib.h | 9 +-- nuttx/include/nuttx/sched.h | 13 ++-- nuttx/libc/misc/lib_init.c | 134 ++++++++++------------------------ nuttx/libc/stdio/lib_libflushall.c | 2 +- nuttx/sched/group_internal.h | 27 +------ nuttx/sched/group_leave.c | 2 + nuttx/sched/group_releasefiles.c | 9 +-- nuttx/sched/sched_getfiles.c | 2 +- nuttx/sched/sched_getstreams.c | 7 +- nuttx/sched/sched_setuppthreadfiles.c | 9 --- nuttx/sched/sched_setupstreams.c | 35 +++++---- nuttx/sched/task_exithook.c | 2 +- 23 files changed, 242 insertions(+), 357 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index ae7105b89..b5933f620 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4036,3 +4036,5 @@ task group IN the child task's task group. * fs/, sched/, include/nuttx/sched.h, and include/nutts/fs/fs.h: Move file data from TCB to task group structure. + * libc/stdio/, sched/, include/nuttx/lib.h, and include/nutts/fs/fs.h: + Move stream data from TCB to task group structure. diff --git a/nuttx/arch/arm/src/common/up_exit.c b/nuttx/arch/arm/src/common/up_exit.c index 5b469fd03..16f5c4442 100644 --- a/nuttx/arch/arm/src/common/up_exit.c +++ b/nuttx/arch/arm/src/common/up_exit.c @@ -75,7 +75,11 @@ #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) { -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct filelist *filelist; +#if CONFIG_NFILE_STREAMS > 0 + FAR struct streamlist *streamlist; +#endif int i; #endif @@ -83,40 +87,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 - if (tcb->filelist) + filelist = tcb->group->tg_filelist; + for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - FAR struct filelist *list = tcb->group->tg_filelist; - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + struct inode *inode = filelist->fl_files[i].f_inode; + if (inode) { - struct inode *inode = list->fl_files[i].f_inode; - if (inode) - { - sdbg(" fd=%d refcount=%d\n", - i, inode->i_crefs); - } + sdbg(" fd=%d refcount=%d\n", + i, inode->i_crefs); } } #endif #if CONFIG_NFILE_STREAMS > 0 - if (tcb->streams) + streamlist = tcb->group->tg_streamlist; + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { - sdbg(" streamlist refcount=%d\n", - tcb->streams->sl_crefs); - - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + struct file_struct *filep = &streamlist->sl_streams[i]; + if (filep->fs_filedes >= 0) { - struct file_struct *filep = &tcb->streams->sl_streams[i]; - if (filep->fs_filedes >= 0) - { #if CONFIG_STDIO_BUFFER_SIZE > 0 - sdbg(" fd=%d nbytes=%d\n", - filep->fs_filedes, - filep->fs_bufpos - filep->fs_bufstart); + sdbg(" fd=%d nbytes=%d\n", + filep->fs_filedes, + filep->fs_bufpos - filep->fs_bufstart); #else - sdbg(" fd=%d\n", filep->fs_filedes); + sdbg(" fd=%d\n", filep->fs_filedes); #endif - } } } #endif diff --git a/nuttx/arch/avr/src/common/up_exit.c b/nuttx/arch/avr/src/common/up_exit.c index 0813754a0..68e33fde7 100644 --- a/nuttx/arch/avr/src/common/up_exit.c +++ b/nuttx/arch/avr/src/common/up_exit.c @@ -75,7 +75,11 @@ #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) { -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct filelist *filelist; +#if CONFIG_NFILE_STREAMS > 0 + FAR struct streamlist *streamlist; +#endif int i; #endif @@ -83,40 +87,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 - if (tcb->filelist) + filelist = tcb->group->tg_filelist; + for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - FAR struct filelist *list = tcb->group->tg_filelist; - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + struct inode *inode = filelist->fl_files[i].f_inode; + if (inode) { - struct inode *inode = list->fl_files[i].f_inode; - if (inode) - { - sdbg(" fd=%d refcount=%d\n", - i, inode->i_crefs); - } + sdbg(" fd=%d refcount=%d\n", + i, inode->i_crefs); } } #endif #if CONFIG_NFILE_STREAMS > 0 - if (tcb->streams) + streamlist = tcb->group->tg_streamlist; + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { - sdbg(" streamlist refcount=%d\n", - tcb->streams->sl_crefs); - - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + struct file_struct *filep = &streamlist->sl_streams[i]; + if (filep->fs_filedes >= 0) { - struct file_struct *filep = &tcb->streams->sl_streams[i]; - if (filep->fs_filedes >= 0) - { #if CONFIG_STDIO_BUFFER_SIZE > 0 - sdbg(" fd=%d nbytes=%d\n", - filep->fs_filedes, - filep->fs_bufpos - filep->fs_bufstart); + sdbg(" fd=%d nbytes=%d\n", + filep->fs_filedes, + filep->fs_bufpos - filep->fs_bufstart); #else - sdbg(" fd=%d\n", filep->fs_filedes); + sdbg(" fd=%d\n", filep->fs_filedes); #endif - } } } #endif diff --git a/nuttx/arch/hc/src/common/up_exit.c b/nuttx/arch/hc/src/common/up_exit.c index 5313a1172..1c46875f8 100644 --- a/nuttx/arch/hc/src/common/up_exit.c +++ b/nuttx/arch/hc/src/common/up_exit.c @@ -75,7 +75,11 @@ #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) { -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct filelist *filelist; +#if CONFIG_NFILE_STREAMS > 0 + FAR struct streamlist *streamlist; +#endif int i; #endif @@ -83,40 +87,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 - if (tcb->filelist) + filelist = tcb->group->tg_filelist; + for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - FAR struct filelist *list = tcb->group->tg_filelist; - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + struct inode *inode = filelist->fl_files[i].f_inode; + if (inode) { - struct inode *inode = list->fl_files[i].f_inode; - if (inode) - { - sdbg(" fd=%d refcount=%d\n", - i, inode->i_crefs); - } + sdbg(" fd=%d refcount=%d\n", + i, inode->i_crefs); } } #endif #if CONFIG_NFILE_STREAMS > 0 - if (tcb->streams) + streamlist = tcb->group->tg_streamlist; + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { - sdbg(" streamlist refcount=%d\n", - tcb->streams->sl_crefs); - - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + struct file_struct *filep = &streamlist->sl_streams[i]; + if (filep->fs_filedes >= 0) { - struct file_struct *filep = &tcb->streams->sl_streams[i]; - if (filep->fs_filedes >= 0) - { #if CONFIG_STDIO_BUFFER_SIZE > 0 - sdbg(" fd=%d nbytes=%d\n", - filep->fs_filedes, - filep->fs_bufpos - filep->fs_bufstart); + sdbg(" fd=%d nbytes=%d\n", + filep->fs_filedes, + filep->fs_bufpos - filep->fs_bufstart); #else - sdbg(" fd=%d\n", filep->fs_filedes); + sdbg(" fd=%d\n", filep->fs_filedes); #endif - } } } #endif diff --git a/nuttx/arch/mips/src/common/up_exit.c b/nuttx/arch/mips/src/common/up_exit.c index 5a7b68a99..e112364b4 100644 --- a/nuttx/arch/mips/src/common/up_exit.c +++ b/nuttx/arch/mips/src/common/up_exit.c @@ -77,7 +77,11 @@ #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) { -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct filelist *filelist; +#if CONFIG_NFILE_STREAMS > 0 + FAR struct streamlist *streamlist; +#endif int i; #endif @@ -85,40 +89,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 - if (tcb->filelist) + filelist = tcb->group->tg_filelist; + for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - FAR struct filelist *list = tcb->group->tg_filelist; - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + struct inode *inode = filelist->fl_files[i].f_inode; + if (inode) { - struct inode *inode = list->fl_files[i].f_inode; - if (inode) - { - sdbg(" fd=%d refcount=%d\n", - i, inode->i_crefs); - } + sdbg(" fd=%d refcount=%d\n", + i, inode->i_crefs); } } #endif #if CONFIG_NFILE_STREAMS > 0 - if (tcb->streams) + streamlist = tcb->group->tg_streamlist; + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { - sdbg(" streamlist refcount=%d\n", - tcb->streams->sl_crefs); - - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + struct file_struct *filep = &streamlist->sl_streams[i]; + if (filep->fs_filedes >= 0) { - struct file_struct *filep = &tcb->streams->sl_streams[i]; - if (filep->fs_filedes >= 0) - { #if CONFIG_STDIO_BUFFER_SIZE > 0 - sdbg(" fd=%d nbytes=%d\n", - filep->fs_filedes, - filep->fs_bufpos - filep->fs_bufstart); + sdbg(" fd=%d nbytes=%d\n", + filep->fs_filedes, + filep->fs_bufpos - filep->fs_bufstart); #else - sdbg(" fd=%d\n", filep->fs_filedes); + sdbg(" fd=%d\n", filep->fs_filedes); #endif - } } } #endif diff --git a/nuttx/arch/sh/src/common/up_exit.c b/nuttx/arch/sh/src/common/up_exit.c index af270b335..705f49852 100644 --- a/nuttx/arch/sh/src/common/up_exit.c +++ b/nuttx/arch/sh/src/common/up_exit.c @@ -76,7 +76,11 @@ #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) { -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct filelist *filelist; +#if CONFIG_NFILE_STREAMS > 0 + FAR struct streamlist *streamlist; +#endif int i; #endif @@ -84,40 +88,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 - if (tcb->filelist) + filelist = tcb->group->tg_filelist; + for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - FAR struct filelist *list = tcb->group->tg_filelist; - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + struct inode *inode = filelist->fl_files[i].f_inode; + if (inode) { - struct inode *inode = list->fl_files[i].f_inode; - if (inode) - { - sdbg(" fd=%d refcount=%d\n", - i, inode->i_crefs); - } + sdbg(" fd=%d refcount=%d\n", + i, inode->i_crefs); } } #endif #if CONFIG_NFILE_STREAMS > 0 - if (tcb->streams) + streamlist = tcb->group->tg_streamlist; + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { - sdbg(" streamlist refcount=%d\n", - tcb->streams->sl_crefs); - - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + struct file_struct *filep = &streamlist->sl_streams[i]; + if (filep->fs_filedes >= 0) { - struct file_struct *filep = &tcb->streams->sl_streams[i]; - if (filep->fs_filedes >= 0) - { #if CONFIG_STDIO_BUFFER_SIZE > 0 - sdbg(" fd=%d nbytes=%d\n", - filep->fs_filedes, - filep->fs_bufpos - filep->fs_bufstart); + sdbg(" fd=%d nbytes=%d\n", + filep->fs_filedes, + filep->fs_bufpos - filep->fs_bufstart); #else - sdbg(" fd=%d\n", filep->fs_filedes); + sdbg(" fd=%d\n", filep->fs_filedes); #endif - } } } #endif diff --git a/nuttx/arch/x86/src/common/up_exit.c b/nuttx/arch/x86/src/common/up_exit.c index 6a98c7dd0..dee6f7d49 100644 --- a/nuttx/arch/x86/src/common/up_exit.c +++ b/nuttx/arch/x86/src/common/up_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * common/up_exit.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -75,7 +75,11 @@ #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) { -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct filelist *filelist; +#if CONFIG_NFILE_STREAMS > 0 + FAR struct streamlist *streamlist; +#endif int i; #endif @@ -83,40 +87,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 - if (tcb->filelist) + filelist = tcb->group->tg_filelist; + for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - FAR struct filelist *list = tcb->group->tg_filelist; - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + struct inode *inode = filelist->fl_files[i].f_inode; + if (inode) { - struct inode *inode = list->fl_files[i].f_inode; - if (inode) - { - sdbg(" fd=%d refcount=%d\n", - i, inode->i_crefs); - } + sdbg(" fd=%d refcount=%d\n", + i, inode->i_crefs); } } #endif #if CONFIG_NFILE_STREAMS > 0 - if (tcb->streams) + streamlist = tcb->group->tg_streamlist; + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { - sdbg(" streamlist refcount=%d\n", - tcb->streams->sl_crefs); - - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + struct file_struct *filep = &streamlist->sl_streams[i]; + if (filep->fs_filedes >= 0) { - struct file_struct *filep = &tcb->streams->sl_streams[i]; - if (filep->fs_filedes >= 0) - { #if CONFIG_STDIO_BUFFER_SIZE > 0 - sdbg(" fd=%d nbytes=%d\n", - filep->fs_filedes, - filep->fs_bufpos - filep->fs_bufstart); + sdbg(" fd=%d nbytes=%d\n", + filep->fs_filedes, + filep->fs_bufpos - filep->fs_bufstart); #else - sdbg(" fd=%d\n", filep->fs_filedes); + sdbg(" fd=%d\n", filep->fs_filedes); #endif - } } } #endif diff --git a/nuttx/arch/z16/src/common/up_exit.c b/nuttx/arch/z16/src/common/up_exit.c index ad0c55eed..20b808360 100644 --- a/nuttx/arch/z16/src/common/up_exit.c +++ b/nuttx/arch/z16/src/common/up_exit.c @@ -77,7 +77,11 @@ #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) { -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct filelist *filelist; +#if CONFIG_NFILE_STREAMS > 0 + FAR struct streamlist *streamlist; +#endif int i; #endif @@ -85,40 +89,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) lldbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 - if (tcb->filelist) + filelist = tcb->group->tg_filelist; + for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - FAR struct filelist *list = tcb->group->tg_filelist; - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + struct inode *inode = filelist->fl_files[i].f_inode; + if (inode) { - struct inode *inode = list->fl_files[i].f_inode; - if (inode) - { - lldbg(" fd=%d refcount=%d\n", - i, inode->i_crefs); - } + lldbg(" fd=%d refcount=%d\n", + i, inode->i_crefs); } } #endif #if CONFIG_NFILE_STREAMS > 0 - if (tcb->streams) + streamlist = tcb->group->tg_streamlist; + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { - lldbg(" streamlist refcount=%d\n", - tcb->streams->sl_crefs); - - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + struct file_struct *filep = &streamlist->sl_streams[i]; + if (filep->fs_filedes >= 0) { - struct file_struct *filep = &tcb->streams->sl_streams[i]; - if (filep->fs_filedes >= 0) - { #if CONFIG_STDIO_BUFFER_SIZE > 0 - lldbg(" fd=%d nbytes=%d\n", - filep->fs_filedes, - filep->fs_bufpos - filep->fs_bufstart); + lldbg(" fd=%d nbytes=%d\n", + filep->fs_filedes, + filep->fs_bufpos - filep->fs_bufstart); #else - lldbg(" fd=%d\n", filep->fs_filedes); + lldbg(" fd=%d\n", filep->fs_filedes); #endif - } } } #endif diff --git a/nuttx/arch/z80/src/common/up_exit.c b/nuttx/arch/z80/src/common/up_exit.c index 50289f52b..603a0bfbe 100644 --- a/nuttx/arch/z80/src/common/up_exit.c +++ b/nuttx/arch/z80/src/common/up_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * common/up_exit.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -78,7 +78,11 @@ #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) { -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct filelist *filelist; +#if CONFIG_NFILE_STREAMS > 0 + FAR struct streamlist *streamlist; +#endif int i; #endif @@ -86,40 +90,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) lldbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state); #if CONFIG_NFILE_DESCRIPTORS > 0 - if (tcb->filelist) + filelist = tcb->group->tg_filelist; + for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { - FAR struct filelist *list = tcb->group->tg_filelist; - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + struct inode *inode = filelist->fl_files[i].f_inode; + if (inode) { - struct inode *inode = list->fl_files[i].f_inode; - if (inode) - { - lldbg(" fd=%d refcount=%d\n", - i, inode->i_crefs); - } + lldbg(" fd=%d refcount=%d\n", + i, inode->i_crefs); } } #endif #if CONFIG_NFILE_STREAMS > 0 - if (tcb->streams) + streamlist = tcb->group->tg_streamlist; + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { - lldbg(" streamlist refcount=%d\n", - tcb->streams->sl_crefs); - - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + struct file_struct *filep = &streamlist->sl_streams[i]; + if (filep->fs_filedes >= 0) { - struct file_struct *filep = &tcb->streams->sl_streams[i]; - if (filep->fs_filedes >= 0) - { #if CONFIG_STDIO_BUFFER_SIZE > 0 - lldbg(" fd=%d nbytes=%d\n", - filep->fs_filedes, - filep->fs_bufpos - filep->fs_bufstart); + lldbg(" fd=%d nbytes=%d\n", + filep->fs_filedes, + filep->fs_bufpos - filep->fs_bufstart); #else - lldbg(" fd=%d\n", filep->fs_filedes); + lldbg(" fd=%d\n", filep->fs_filedes); #endif - } } } #endif diff --git a/nuttx/fs/fs_fdopen.c b/nuttx/fs/fs_fdopen.c index 629083c77..d8a370482 100644 --- a/nuttx/fs/fs_fdopen.c +++ b/nuttx/fs/fs_fdopen.c @@ -144,6 +144,7 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb) { tcb = sched_self(); } + DEBUGASSERT(tcb && tcb->group); /* Verify that this is a valid file/socket descriptor and that the * requested access can be support. @@ -191,9 +192,9 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb) /* Get the stream list from the TCB */ - slist = tcb->streams; + slist = &tcb->group->tg_streamlist; - /* Find an unallocated FILE structure in the stream list */ + /* Find an unallocated FILE structure in the stream list */ ret = sem_wait(&slist->sl_sem); if (ret != OK) diff --git a/nuttx/include/nuttx/fs/fs.h b/nuttx/include/nuttx/fs/fs.h index 02855460c..93ca2a334 100644 --- a/nuttx/include/nuttx/fs/fs.h +++ b/nuttx/include/nuttx/fs/fs.h @@ -293,7 +293,6 @@ struct file_struct struct streamlist { - int sl_crefs; /* Reference count */ sem_t sl_sem; /* For thread safety */ struct file_struct sl_streams[CONFIG_NFILE_STREAMS]; }; diff --git a/nuttx/include/nuttx/lib.h b/nuttx/include/nuttx/lib.h index 220af2030..3bc581e18 100644 --- a/nuttx/include/nuttx/lib.h +++ b/nuttx/include/nuttx/lib.h @@ -2,7 +2,7 @@ * include/nuttx/lib.h * Non-standard, internal APIs available in lib/. * - * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -67,11 +67,10 @@ extern "C" { /* Functions contained in lib_init.c ****************************************/ -EXTERN void weak_function lib_initialize(void); +void weak_function lib_initialize(void); #if CONFIG_NFILE_STREAMS > 0 -EXTERN FAR struct streamlist *lib_alloclist(void); -EXTERN void lib_addreflist(FAR struct streamlist *list); -EXTERN void lib_releaselist(FAR struct streamlist *list); +void lib_streaminit(FAR struct streamlist *list); +void lib_releaselist(FAR struct streamlist *list); #endif #undef EXTERN diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 1580a80d3..a084d50ba 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -81,6 +81,8 @@ # define HAVE_TASK_GROUP 1 # elif CONFIG_NFILE_DESCRIPTORS > 0 # define HAVE_TASK_GROUP 1 +# elif CONFIG_NFILE_STREAMS > 0 +# define HAVE_TASK_GROUP 1 # endif #endif @@ -303,7 +305,10 @@ struct task_group_s #endif /* FILE streams ***************************************************************/ - /* Not yet (see streamlist) */ + +#if CONFIG_NFILE_STREAMS > 0 + struct streamlist tg_streamlist; /* Holds C buffered I/O info */ +#endif /* CONFIG_NFILE_STREAMS */ /* Sockets ********************************************************************/ /* Not yet (see struct socketlist) */ @@ -445,12 +450,6 @@ struct _TCB int pterrno; /* Current per-thread errno */ - /* File system support ********************************************************/ - -#if CONFIG_NFILE_STREAMS > 0 - FAR struct streamlist *streams; /* Holds C buffered I/O info */ -#endif - /* Network socket *************************************************************/ #if CONFIG_NSOCKET_DESCRIPTORS > 0 diff --git a/nuttx/libc/misc/lib_init.c b/nuttx/libc/misc/lib_init.c index 6a120f7b1..434c46505 100644 --- a/nuttx/libc/misc/lib_init.c +++ b/nuttx/libc/misc/lib_init.c @@ -1,7 +1,7 @@ /************************************************************ * libc/misc/lib_init.c * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -76,69 +76,35 @@ void weak_const_function lib_initialize(void) } #if CONFIG_NFILE_STREAMS > 0 -/* The following function is called when a new TCB is allocated. It - * creates the streamlist instance that is stored in the TCB. +/* The following function is called when a new task is allocated. It + * intializes the streamlist instance that is stored in the task group. */ -FAR struct streamlist *lib_alloclist(void) +void lib_streaminit(FAR struct streamlist *list) { - FAR struct streamlist *list; - list = (FAR struct streamlist*)lib_zalloc(sizeof(struct streamlist)); - if (list) - { - int i; - - /* Start with a reference count of one */ - - list->sl_crefs = 1; + int i; - /* Initialize the list access mutex */ + /* Initialize the list access mutex */ - (void)sem_init(&list->sl_sem, 0, 1); + (void)sem_init(&list->sl_sem, 0, 1); - /* Initialize each FILE structure */ + /* Initialize each FILE structure */ - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) - { - /* Clear the IOB */ + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + { + /* Clear the IOB */ - memset(&list->sl_streams[i], 0, sizeof(FILE)); + memset(&list->sl_streams[i], 0, sizeof(FILE)); - /* Indicate not opened */ + /* Indicate not opened */ - list->sl_streams[i].fs_filedes = -1; + list->sl_streams[i].fs_filedes = -1; - /* Initialize the stream semaphore to one to support one-at- - * a-time access to private data sets. - */ - - lib_sem_initialize(&list->sl_streams[i]); - } - } - return list; + /* Initialize the stream semaphore to one to support one-at- + * a-time access to private data sets. + */ -} - -/* This function is called when a TCB is closed (such as with - * pthread_create(). It increases the reference count on the stream - * list. - */ - -void lib_addreflist(FAR struct streamlist *list) -{ - if (list) - { - /* Increment the reference count on the list. - * NOTE: that we disable interrupts to do this - * (vs. taking the list semaphore). We do this - * because file cleanup operations often must be - * done from the IDLE task which cannot wait - * on semaphores. - */ - - register irqstate_t flags = irqsave(); - list->sl_crefs++; - irqrestore(flags); + lib_sem_initialize(&list->sl_streams[i]); } } @@ -149,57 +115,33 @@ void lib_addreflist(FAR struct streamlist *list) void lib_releaselist(FAR struct streamlist *list) { - int crefs; - if (list) - { - /* Decrement the reference count on the list. - * NOTE: that we disable interrupts to do this - * (vs. taking the list semaphore). We do this - * because file cleanup operations often must be - * done from the IDLE task which cannot wait - * on semaphores. - */ - - register irqstate_t flags = irqsave(); - crefs = --(list->sl_crefs); - irqrestore(flags); - - /* If the count decrements to zero, then there is no reference - * to the structure and it should be deallocated. Since there - * are references, it would be an error if any task still held - * a reference to the list's semaphore. - */ - - if (crefs <= 0) - { #if CONFIG_STDIO_BUFFER_SIZE > 0 - int i; + int i; #endif - /* Destroy the semaphore and release the filelist */ - (void)sem_destroy(&list->sl_sem); + DEBUGASSERT(list); + + /* Destroy the semaphore and release the filelist */ - /* Release each stream in the list */ + (void)sem_destroy(&list->sl_sem); + + /* Release each stream in the list */ #if CONFIG_STDIO_BUFFER_SIZE > 0 - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) - { - /* Destroy the semaphore that protects the IO buffer */ - - (void)sem_destroy(&list->sl_streams[i].fs_sem); - - /* Release the IO buffer */ - if (list->sl_streams[i].fs_bufstart) - { - sched_free(list->sl_streams[i].fs_bufstart); - } - } -#endif - /* Finally, release the list itself */ + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + { + /* Destroy the semaphore that protects the IO buffer */ - sched_free(list); - } - } + (void)sem_destroy(&list->sl_streams[i].fs_sem); + + /* Release the IO buffer */ + + if (list->sl_streams[i].fs_bufstart) + { + sched_free(list->sl_streams[i].fs_bufstart); + } + } +#endif } #endif /* CONFIG_NFILE_STREAMS */ diff --git a/nuttx/libc/stdio/lib_libflushall.c b/nuttx/libc/stdio/lib_libflushall.c index 7ac3da7e0..22baed968 100644 --- a/nuttx/libc/stdio/lib_libflushall.c +++ b/nuttx/libc/stdio/lib_libflushall.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_libflushall.c * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/sched/group_internal.h b/nuttx/sched/group_internal.h index 39d0a2b7c..e6e0dfd16 100644 --- a/nuttx/sched/group_internal.h +++ b/nuttx/sched/group_internal.h @@ -86,28 +86,11 @@ void group_leave(FAR _TCB *tcb); FAR struct task_group_s *group_find(gid_t gid); int group_addmember(FAR struct task_group_s *group, pid_t pid); int group_removemember(FAR struct task_group_s *group, pid_t pid); -#else -# define group_find(gid) (NULL) -# define group_addmember(group,pid) (0) -# define group_removemember(group,pid) (1) #endif #ifndef CONFIG_DISABLE_SIGNALS int group_signal(FAR struct task_group_s *group, FAR siginfo_t *info); -#else -# define group_signal(tcb,info) (0) #endif - -#else -# define group_allocate(tcb) (0) -# define group_initialize(tcb) (0) -# define group_bind(tcb) (0) -# define group_join(tcb) (0) -# define group_leave(tcb) -# define group_find(gid) (NULL) -# define group_addmember(group,pid) (0) -# define group_removemember(group,pid) (1) -# define group_signal(tcb,info) (0) #endif /* HAVE_TASK_GROUP */ /* Parent/child data management */ @@ -127,15 +110,13 @@ FAR struct child_status_s *group_removechild(FAR struct task_group_s *group, pid_t pid); void group_removechildren(FAR struct task_group_s *group); +#endif /* CONFIG_SCHED_CHILD_STATUS */ +#endif /* CONFIG_SCHED_HAVE_PARENT */ + /* File/network resources */ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 -int group_releasefiles(FAR _TCB *tcb); -#else -# define group_releasefiles(t) (OK) +int group_releasefiles(FAR _TCB *tcb); #endif -#endif /* CONFIG_SCHED_CHILD_STATUS */ -#endif /* CONFIG_SCHED_HAVE_PARENT */ - #endif /* __SCHED_GROUP_INERNAL_H */ diff --git a/nuttx/sched/group_leave.c b/nuttx/sched/group_leave.c index 158ba30b5..70ef93666 100644 --- a/nuttx/sched/group_leave.c +++ b/nuttx/sched/group_leave.c @@ -165,6 +165,7 @@ static inline void group_release(FAR _TCB *tcb, env_release(tcb); #endif +#ifdef HAVE_GROUP_MEMBERS /* Remove the group from the list of groups */ group_remove(group); @@ -176,6 +177,7 @@ static inline void group_release(FAR _TCB *tcb, sched_free(group->tg_members); group->tg_members = NULL; } +#endif /* Release the group container itself */ diff --git a/nuttx/sched/group_releasefiles.c b/nuttx/sched/group_releasefiles.c index 40bf373b4..b33415c76 100644 --- a/nuttx/sched/group_releasefiles.c +++ b/nuttx/sched/group_releasefiles.c @@ -80,7 +80,9 @@ int group_releasefiles(_TCB *tcb) #if CONFIG_NFILE_DESCRIPTORS > 0 FAR struct task_group_s *group = tcb->group; DEBUGASSERT(group); +#endif +#if CONFIG_NFILE_DESCRIPTORS > 0 /* Free resources used by the file descriptor list */ files_releaselist(&group->tg_filelist); @@ -88,11 +90,8 @@ int group_releasefiles(_TCB *tcb) #if CONFIG_NFILE_STREAMS > 0 /* Free the stream list */ - if (tcb->streams) - { - lib_releaselist(tcb->streams); - tcb->streams = NULL; - } + lib_releaselist(&group->tg_streamlist); + #endif /* CONFIG_NFILE_STREAMS */ #endif /* CONFIG_NFILE_DESCRIPTORS */ diff --git a/nuttx/sched/sched_getfiles.c b/nuttx/sched/sched_getfiles.c index eca4ba3ff..17ca2bbf6 100644 --- a/nuttx/sched/sched_getfiles.c +++ b/nuttx/sched/sched_getfiles.c @@ -1,7 +1,7 @@ /************************************************************************ * sched/sched_getfiles.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/sched/sched_getstreams.c b/nuttx/sched/sched_getstreams.c index f7c21ab4c..dab406e66 100644 --- a/nuttx/sched/sched_getstreams.c +++ b/nuttx/sched/sched_getstreams.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched_getstreams.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -70,7 +70,10 @@ FAR struct streamlist *sched_getstreams(void) { FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - return rtcb->streams; + FAR struct task_group_s *group = rtcb->group; + + DEBUGASSERT(group); + return &group->tg_streamlist; } #endif /* CONFIG_NFILE_DESCRIPTORS && CONFIG_NFILE_STREAMS */ diff --git a/nuttx/sched/sched_setuppthreadfiles.c b/nuttx/sched/sched_setuppthreadfiles.c index 78d6cbfec..91d72fa7f 100644 --- a/nuttx/sched/sched_setuppthreadfiles.c +++ b/nuttx/sched/sched_setuppthreadfiles.c @@ -77,8 +77,6 @@ int sched_setuppthreadfiles(FAR _TCB *tcb) { - FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - #if CONFIG_NSOCKET_DESCRIPTORS > 0 /* The child thread inherits the parent socket descriptors */ @@ -87,13 +85,6 @@ int sched_setuppthreadfiles(FAR _TCB *tcb) #endif /* CONFIG_NSOCKET_DESCRIPTORS */ -#if CONFIG_NFILE_STREAMS > 0 - /* The child thread inherits the parent streams */ - - tcb->streams = rtcb->streams; - lib_addreflist(tcb->streams); - -#endif /* CONFIG_NFILE_STREAMS */ return OK; } diff --git a/nuttx/sched/sched_setupstreams.c b/nuttx/sched/sched_setupstreams.c index 22895b047..fb2e4d0be 100644 --- a/nuttx/sched/sched_setupstreams.c +++ b/nuttx/sched/sched_setupstreams.c @@ -72,24 +72,23 @@ int sched_setupstreams(FAR _TCB *tcb) { - /* Allocate file streams for the TCB */ - - tcb->streams = lib_alloclist(); - if (tcb->streams) - { - /* fdopen to get the stdin, stdout and stderr streams. - * The following logic depends on the fact that the library - * layer will allocate FILEs in order. - * - * fd = 0 is stdin (read-only) - * fd = 1 is stdout (write-only, append) - * fd = 2 is stderr (write-only, append) - */ - - (void)fs_fdopen(0, O_RDONLY, tcb); - (void)fs_fdopen(1, O_WROK|O_CREAT, tcb); - (void)fs_fdopen(2, O_WROK|O_CREAT, tcb); - } + DEBUGASSERT(tcb && tcb->group); + + /* Initialize file streams for the task group */ + + lib_streaminit(&tcb->group->tg_streamlist); + + /* fdopen to get the stdin, stdout and stderr streams. The following logic + * depends on the fact that the library layer will allocate FILEs in order. + * + * fd = 0 is stdin (read-only) + * fd = 1 is stdout (write-only, append) + * fd = 2 is stderr (write-only, append) + */ + + (void)fs_fdopen(0, O_RDONLY, tcb); + (void)fs_fdopen(1, O_WROK|O_CREAT, tcb); + (void)fs_fdopen(2, O_WROK|O_CREAT, tcb); return OK; } diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index 5a2b9e57e..889df25e0 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -543,7 +543,7 @@ void task_exithook(FAR _TCB *tcb, int status) */ #if CONFIG_NFILE_STREAMS > 0 - (void)lib_flushall(tcb->streams); + (void)lib_flushall(&tcb->group->tg_streamlist); #endif /* Leave the task group. Perhaps discarding any un-reaped child -- cgit v1.2.3 From 47b94bafa5045532f239ea57a3610873b1a71368 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 26 Jan 2013 23:49:02 +0000 Subject: Move socket data from TCB to task group structure. git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5570 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 6 +- nuttx/include/nuttx/net/net.h | 8 +- nuttx/include/nuttx/sched.h | 13 +- nuttx/net/net_sockets.c | 100 +++----------- nuttx/sched/Makefile | 6 +- nuttx/sched/env_clearenv.c | 5 +- nuttx/sched/env_dup.c | 12 +- nuttx/sched/env_internal.h | 8 +- nuttx/sched/env_release.c | 11 +- nuttx/sched/group_create.c | 2 +- nuttx/sched/group_internal.h | 8 +- nuttx/sched/group_leave.c | 34 +++-- nuttx/sched/group_releasefiles.c | 112 --------------- nuttx/sched/group_setupidlefiles.c | 147 ++++++++++++++++++++ nuttx/sched/group_setupstreams.c | 97 +++++++++++++ nuttx/sched/group_setuptaskfiles.c | 245 +++++++++++++++++++++++++++++++++ nuttx/sched/os_internal.h | 17 --- nuttx/sched/os_start.c | 2 +- nuttx/sched/pthread_create.c | 9 -- nuttx/sched/sched_getsockets.c | 7 +- nuttx/sched/sched_setupidlefiles.c | 151 --------------------- nuttx/sched/sched_setuppthreadfiles.c | 91 ------------- nuttx/sched/sched_setupstreams.c | 97 ------------- nuttx/sched/sched_setuptaskfiles.c | 248 ---------------------------------- nuttx/sched/task_create.c | 2 +- nuttx/sched/task_init.c | 2 +- nuttx/sched/task_vfork.c | 2 +- 27 files changed, 583 insertions(+), 859 deletions(-) delete mode 100644 nuttx/sched/group_releasefiles.c create mode 100644 nuttx/sched/group_setupidlefiles.c create mode 100644 nuttx/sched/group_setupstreams.c create mode 100644 nuttx/sched/group_setuptaskfiles.c delete mode 100644 nuttx/sched/sched_setupidlefiles.c delete mode 100644 nuttx/sched/sched_setuppthreadfiles.c delete mode 100644 nuttx/sched/sched_setupstreams.c delete mode 100644 nuttx/sched/sched_setuptaskfiles.c diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index b5933f620..255d69a3d 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4035,6 +4035,8 @@ task ID in the child task's TCB. Instead, keep the parent task group IN the child task's task group. * fs/, sched/, include/nuttx/sched.h, and include/nutts/fs/fs.h: - Move file data from TCB to task group structure. + Move file data from the TCB to the task group structure. * libc/stdio/, sched/, include/nuttx/lib.h, and include/nutts/fs/fs.h: - Move stream data from TCB to task group structure. + Move stream data from the TCB to the task group structure. + * net/, sched/, and include/nuttx/net/net.h: Move socket data + from the TCB to the task group structure. diff --git a/nuttx/include/nuttx/net/net.h b/nuttx/include/nuttx/net/net.h index b625b2fbe..d23fb8796 100644 --- a/nuttx/include/nuttx/net/net.h +++ b/nuttx/include/nuttx/net/net.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/net/net.h * - * Copyright (C) 2007, 2009-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -106,7 +106,6 @@ struct socket struct socketlist { sem_t sl_sem; /* Manage access to the socket list */ - int16_t sl_crefs; /* Reference count */ struct socket sl_sockets[CONFIG_NSOCKET_DESCRIPTORS]; }; #endif @@ -145,9 +144,8 @@ int net_checksd(int fd, int oflags); */ void weak_function net_initialize(void); -FAR struct socketlist *net_alloclist(void); -int net_addreflist(FAR struct socketlist *list); -int net_releaselist(FAR struct socketlist *list); +void net_initlist(FAR struct socketlist *list); +void net_releaselist(FAR struct socketlist *list); /* Given a socket descriptor, return the underly NuttX-specific socket * structure. diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index a084d50ba..244455cd4 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -83,6 +83,8 @@ # define HAVE_TASK_GROUP 1 # elif CONFIG_NFILE_STREAMS > 0 # define HAVE_TASK_GROUP 1 +# elif CONFIG_NSOCKET_DESCRIPTORS > 0 +# define HAVE_TASK_GROUP 1 # endif #endif @@ -311,7 +313,10 @@ struct task_group_s #endif /* CONFIG_NFILE_STREAMS */ /* Sockets ********************************************************************/ - /* Not yet (see struct socketlist) */ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + struct socketlist tg_socketlist; /* Maps socket descriptor to socket */ +#endif }; #endif @@ -450,12 +455,6 @@ struct _TCB int pterrno; /* Current per-thread errno */ - /* Network socket *************************************************************/ - -#if CONFIG_NSOCKET_DESCRIPTORS > 0 - FAR struct socketlist *sockets; /* Maps file descriptor to file */ -#endif - /* State save areas ***********************************************************/ /* The form and content of these fields are processor-specific. */ diff --git a/nuttx/net/net_sockets.c b/nuttx/net/net_sockets.c index 81e48c121..ddb54c98c 100644 --- a/nuttx/net/net_sockets.c +++ b/nuttx/net/net_sockets.c @@ -116,99 +116,37 @@ void net_initialize(void) #if CONFIG_NSOCKET_DESCRIPTORS > 0 -/* Allocate a list of files for a new task */ +/* Initialize a list of sockets for a new task */ -FAR struct socketlist *net_alloclist(void) +void net_initlist(FAR struct socketlist *list) { - FAR struct socketlist *list; - list = (FAR struct socketlist*)kzalloc(sizeof(struct socketlist)); - if (list) - { - /* Start with a reference count of one */ - - list->sl_crefs = 1; - - /* Initialize the list access mutex */ + /* Initialize the list access mutex */ - (void)sem_init(&list->sl_sem, 0, 1); - } - return list; + (void)sem_init(&list->sl_sem, 0, 1); } -/* Increase the reference count on a file list */ +/* Release release resources held by the socket list */ -int net_addreflist(FAR struct socketlist *list) +void net_releaselist(FAR struct socketlist *list) { - if (list) - { - /* Increment the reference count on the list. - * NOTE: that we disable interrupts to do this - * (vs. taking the list semaphore). We do this - * because file cleanup operations often must be - * done from the IDLE task which cannot wait - * on semaphores. - */ - - register uip_lock_t flags = uip_lock(); - list->sl_crefs++; - uip_unlock(flags); - } - return OK; -} + int ndx; -/* Release a reference to the file list */ + DEBUGASSERT(list); -int net_releaselist(FAR struct socketlist *list) -{ - int crefs; - int ndx; + /* Close each open socket in the list. */ - if (list) + for (ndx = 0; ndx < CONFIG_NSOCKET_DESCRIPTORS; ndx++) { - /* Decrement the reference count on the list. - * NOTE: that we disable interrupts to do this - * (vs. taking the list semaphore). We do this - * because file cleanup operations often must be - * done from the IDLE task which cannot wait - * on semaphores. - */ - - uip_lock_t flags = uip_lock(); - crefs = --(list->sl_crefs); - uip_unlock(flags); - - /* If the count decrements to zero, then there is no reference - * to the structure and it should be deallocated. Since there - * are references, it would be an error if any task still held - * a reference to the list's semaphore. - */ - - if (crefs <= 0) - { - /* Close each open socket in the list - * REVISIT: psock_close() will attempt to use semaphores. - * If we actually are in the IDLE thread, then could this cause - * problems? Probably not, if the task has exited and crefs is - * zero, then there probably could not be a contender for the - * semaphore. - */ - - for (ndx = 0; ndx < CONFIG_NSOCKET_DESCRIPTORS; ndx++) - { - FAR struct socket *psock = &list->sl_sockets[ndx]; - if (psock->s_crefs > 0) - { - (void)psock_close(psock); - } - } - - /* Destroy the semaphore and release the filelist */ - - (void)sem_destroy(&list->sl_sem); - sched_free(list); - } + FAR struct socket *psock = &list->sl_sockets[ndx]; + if (psock->s_crefs > 0) + { + (void)psock_close(psock); + } } - return OK; + + /* Destroy the semaphore */ + + (void)sem_destroy(&list->sl_sem); } int sockfd_allocate(int minsd) diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index c8fe7cf69..7710ae058 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -39,9 +39,7 @@ ASRCS = AOBJS = $(ASRCS:.S=$(OBJEXT)) MISC_SRCS = os_start.c os_bringup.c errno_getptr.c errno_get.c errno_set.c -MISC_SRCS += sched_garbage.c sched_setupstreams.c sched_getfiles.c sched_getsockets.c -MISC_SRCS += sched_getstreams.c sched_setupidlefiles.c sched_setuptaskfiles.c -MISC_SRCS += sched_setuppthreadfiles.c +MISC_SRCS += sched_garbage.c sched_getfiles.c sched_getsockets.c sched_getstreams.c TSK_SRCS = prctl.c task_create.c task_init.c task_setup.c task_activate.c TSK_SRCS += task_start.c task_delete.c task_deletecurrent.c task_exithook.c @@ -81,7 +79,7 @@ endif endif GRP_SRCS = group_create.c group_join.c group_leave.c group_find.c -GRP_SRCS += group_releasefiles.c +GRP_SRCS += group_setupstreams.c group_setupidlefiles.c group_setuptaskfiles.c ifeq ($(CONFIG_SCHED_HAVE_PARENT),y) GRP_SRCS += task_reparent.c diff --git a/nuttx/sched/env_clearenv.c b/nuttx/sched/env_clearenv.c index a9e9f5efd..062fd60ed 100644 --- a/nuttx/sched/env_clearenv.c +++ b/nuttx/sched/env_clearenv.c @@ -74,7 +74,10 @@ int clearenv(void) { - env_release((FAR _TCB*)g_readytorun.head); + FAR _TCB *tcb = (FAR _TCB*)g_readytorun.head; + DEBUGASSERT(tcb->group); + + env_release(tcb->group); return OK; } diff --git a/nuttx/sched/env_dup.c b/nuttx/sched/env_dup.c index 479f7cae7..3b653b010 100644 --- a/nuttx/sched/env_dup.c +++ b/nuttx/sched/env_dup.c @@ -68,8 +68,8 @@ * exact duplicate of the parent task's environment. * * Parameters: - * ctcb The child tcb to receive the newly allocated copy of the parent - * TCB's environment structure with reference count equal to one + * group The child task group to receive the newly allocated copy of the + * parent task groups environment structure. * * Return Value: * zero on success @@ -79,14 +79,14 @@ * ****************************************************************************/ -int env_dup(FAR _TCB *ctcb) +int env_dup(FAR struct task_group_s *group) { FAR _TCB *ptcb = (FAR _TCB*)g_readytorun.head; FAR char *envp = NULL; size_t envlen; int ret = OK; - DEBUGASSERT(ctcb && ptcb && ctcb->group && ptcb->group); + DEBUGASSERT(group && ptcb && ptcb->group); /* Pre-emption must be disabled throughout the following because the * environment may be shared. @@ -108,8 +108,8 @@ int env_dup(FAR _TCB *ctcb) } else { - ctcb->group->tg_envsize = envlen; - ctcb->group->tg_envp = envp; + group->tg_envsize = envlen; + group->tg_envp = envp; memcpy(envp, ptcb->group->tg_envp, envlen); } } diff --git a/nuttx/sched/env_internal.h b/nuttx/sched/env_internal.h index 6f1097c0b..e02bf289d 100644 --- a/nuttx/sched/env_internal.h +++ b/nuttx/sched/env_internal.h @@ -49,8 +49,8 @@ ****************************************************************************/ #ifdef CONFIG_DISABLE_ENVIRON -# define env_dup(ptcb) (0) -# define env_release(ptcb) (0) +# define env_dup(group) (0) +# define env_release(group) (0) #else /**************************************************************************** @@ -75,8 +75,8 @@ extern "C" /* Functions used by the task/pthread creation and destruction logic */ -int env_dup(FAR _TCB *ctcb); -void env_release(FAR _TCB *tcb); +int env_dup(FAR struct task_group_s *group); +void env_release(FAR struct task_group_s *group); /* Functions used internally by the environment handling logic */ diff --git a/nuttx/sched/env_release.c b/nuttx/sched/env_release.c index 4de55c388..aebb1f7e8 100644 --- a/nuttx/sched/env_release.c +++ b/nuttx/sched/env_release.c @@ -64,8 +64,8 @@ * environ to NULL. * * Parameters: - * tcb Identifies the TCB containing the environment structure to be - * released. + * group Identifies the task group containing the environment structure + * to be released. * * Return Value: * None @@ -75,12 +75,9 @@ * ****************************************************************************/ -void env_release(FAR _TCB *tcb) +void env_release(FAR struct task_group_s *group) { - FAR struct task_group_s *group; - - DEBUGASSERT(tcb && tcb->group); - group = tcb->group; + DEBUGASSERT(group); /* Free any allocate environment strings */ diff --git a/nuttx/sched/group_create.c b/nuttx/sched/group_create.c index 768641be1..24f6923aa 100644 --- a/nuttx/sched/group_create.c +++ b/nuttx/sched/group_create.c @@ -198,7 +198,7 @@ int group_allocate(FAR _TCB *tcb) /* Duplicate the parent tasks envionment */ - ret = env_dup(tcb); + ret = env_dup(tcb->group); if (ret < 0) { kfree(tcb->group); diff --git a/nuttx/sched/group_internal.h b/nuttx/sched/group_internal.h index e6e0dfd16..ca6aacff7 100644 --- a/nuttx/sched/group_internal.h +++ b/nuttx/sched/group_internal.h @@ -113,10 +113,14 @@ void group_removechildren(FAR struct task_group_s *group); #endif /* CONFIG_SCHED_CHILD_STATUS */ #endif /* CONFIG_SCHED_HAVE_PARENT */ -/* File/network resources */ +/* Group data resource configuration */ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 -int group_releasefiles(FAR _TCB *tcb); +int group_setupidlefiles(FAR _TCB *tcb); +int group_setuptaskfiles(FAR _TCB *tcb); +#if CONFIG_NFILE_STREAMS > 0 +int group_setupstreams(FAR _TCB *tcb); +#endif #endif #endif /* __SCHED_GROUP_INERNAL_H */ diff --git a/nuttx/sched/group_leave.c b/nuttx/sched/group_leave.c index 70ef93666..4dec30633 100644 --- a/nuttx/sched/group_leave.c +++ b/nuttx/sched/group_leave.c @@ -44,6 +44,10 @@ #include #include +#include +#include +#include + #include "group_internal.h" #include "env_internal.h" @@ -142,8 +146,7 @@ void group_remove(FAR struct task_group_s *group) * *****************************************************************************/ -static inline void group_release(FAR _TCB *tcb, - FAR struct task_group_s *group) +static inline void group_release(FAR struct task_group_s *group) { /* Free all un-reaped child exit status */ @@ -155,14 +158,29 @@ static inline void group_release(FAR _TCB *tcb, * soon as possible while we still have a functioning task. */ -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - (void)group_releasefiles(tcb); -#endif +#if CONFIG_NFILE_DESCRIPTORS > 0 + /* Free resources held by the file descriptor list */ + + files_releaselist(&group->tg_filelist); + +#if CONFIG_NFILE_STREAMS > 0 + /* Free resource held by the stream list */ + + lib_releaselist(&group->tg_streamlist); + +#endif /* CONFIG_NFILE_STREAMS */ +#endif /* CONFIG_NFILE_DESCRIPTORS */ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + /* Free resource held by the socket list */ + + net_releaselist(&group->tg_socketlist); +#endif /* CONFIG_NSOCKET_DESCRIPTORS */ /* Release all shared environment variables */ #ifndef CONFIG_DISABLE_ENVIRON - env_release(tcb); + env_release(group); #endif #ifdef HAVE_GROUP_MEMBERS @@ -232,7 +250,7 @@ void group_leave(FAR _TCB *tcb) { /* Release all of the resource held by the task group */ - group_release(tcb, group); + group_release(group); } /* In any event, we can detach the group from the TCB so that we won't @@ -271,7 +289,7 @@ void group_leave(FAR _TCB *tcb) { /* Release all of the resource held by the task group */ - group_release(tcb, group); + group_release(group); } /* In any event, we can detach the group from the TCB so we won't do diff --git a/nuttx/sched/group_releasefiles.c b/nuttx/sched/group_releasefiles.c deleted file mode 100644 index b33415c76..000000000 --- a/nuttx/sched/group_releasefiles.c +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** - * sched/group_releasefiles.c - * - * Copyright (C) 2007, 2008, 2012-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: group_releasefiles - * - * Description: - * Release file resources attached to a TCB. This file may be called - * multiple times as a task exists. It will be called as early as possible - * to support proper closing of complex drivers that may need to wait - * on external events. - * - * Parameters: - * tcb - tcb of the new task. - * - * Return Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -int group_releasefiles(_TCB *tcb) -{ - if (tcb) - { -#if CONFIG_NFILE_DESCRIPTORS > 0 - FAR struct task_group_s *group = tcb->group; - DEBUGASSERT(group); -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 - /* Free resources used by the file descriptor list */ - - files_releaselist(&group->tg_filelist); - -#if CONFIG_NFILE_STREAMS > 0 - /* Free the stream list */ - - lib_releaselist(&group->tg_streamlist); - -#endif /* CONFIG_NFILE_STREAMS */ -#endif /* CONFIG_NFILE_DESCRIPTORS */ - -#if CONFIG_NSOCKET_DESCRIPTORS > 0 - /* Free the file descriptor list */ - - if (tcb->sockets) - { - net_releaselist(tcb->sockets); - tcb->sockets = NULL; - } -#endif /* CONFIG_NSOCKET_DESCRIPTORS */ - } - - return OK; -} - -#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/group_setupidlefiles.c b/nuttx/sched/group_setupidlefiles.c new file mode 100644 index 000000000..98cc7885e --- /dev/null +++ b/nuttx/sched/group_setupidlefiles.c @@ -0,0 +1,147 @@ +/**************************************************************************** + * sched/group_setupidlefiles.c + * + * Copyright (C) 2007-2010, 2012-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "os_internal.h" + +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: group_setupidlefiles + * + * Description: + * Configure the idle thread's TCB. + * + * Parameters: + * tcb - tcb of the idle task. + * + * Return Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +int group_setupidlefiles(FAR _TCB *tcb) +{ +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0 + FAR struct task_group_s *group = tcb->group; +#endif +#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) + int fd; +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0 + DEBUGASSERT(group); +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 + /* Initialize file descriptors for the TCB */ + + files_initlist(&group->tg_filelist); +#endif + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + /* Allocate socket descriptors for the TCB */ + + net_initlist(&group->tg_socketlist); +#endif + + /* Open stdin, dup to get stdout and stderr. This should always + * be the first file opened and, hence, should always get file + * descriptor 0. + */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) + fd = open("/dev/console", O_RDWR); + if (fd == 0) + { + /* Successfully opened /dev/console as stdin (fd == 0) */ + + (void)file_dup2(0, 1); + (void)file_dup2(0, 2); + } + else + { + /* We failed to open /dev/console OR for some reason, we opened + * it and got some file descriptor other than 0. + */ + + if (fd > 0) + { + slldbg("Open /dev/console fd: %d\n", fd); + (void)close(fd); + } + else + { + slldbg("Failed to open /dev/console: %d\n", errno); + } + return -ENFILE; + } +#endif + + /* Allocate file/socket streams for the TCB */ + +#if CONFIG_NFILE_STREAMS > 0 + return group_setupstreams(tcb); +#else + return OK; +#endif +} + +#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/group_setupstreams.c b/nuttx/sched/group_setupstreams.c new file mode 100644 index 000000000..88e266280 --- /dev/null +++ b/nuttx/sched/group_setupstreams.c @@ -0,0 +1,97 @@ +/**************************************************************************** + * group_setupstreams.c + * + * Copyright (C) 2007-2008, 2010-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include + +/* Make sure that there are file or socket descriptors in the system and + * that some number of streams have been configured. + */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 +#if CONFIG_NFILE_STREAMS > 0 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: group_setupstreams + * + * Description: + * Setup streams data structures that may be used for standard C buffered + * I/O with underlying socket or file desciptors + * + ****************************************************************************/ + +int group_setupstreams(FAR _TCB *tcb) +{ + DEBUGASSERT(tcb && tcb->group); + + /* Initialize file streams for the task group */ + + lib_streaminit(&tcb->group->tg_streamlist); + + /* fdopen to get the stdin, stdout and stderr streams. The following logic + * depends on the fact that the library layer will allocate FILEs in order. + * + * fd = 0 is stdin (read-only) + * fd = 1 is stdout (write-only, append) + * fd = 2 is stderr (write-only, append) + */ + + (void)fs_fdopen(0, O_RDONLY, tcb); + (void)fs_fdopen(1, O_WROK|O_CREAT, tcb); + (void)fs_fdopen(2, O_WROK|O_CREAT, tcb); + + return OK; +} + +#endif /* CONFIG_NFILE_STREAMS > 0 */ +#endif /* CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0*/ diff --git a/nuttx/sched/group_setuptaskfiles.c b/nuttx/sched/group_setuptaskfiles.c new file mode 100644 index 000000000..d52adcfee --- /dev/null +++ b/nuttx/sched/group_setuptaskfiles.c @@ -0,0 +1,245 @@ +/**************************************************************************** + * sched/group_setuptaskfiles.c + * + * Copyright (C) 2007-2008, 2010, 2012-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "os_internal.h" + +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Determine how many file descriptors to clone. If CONFIG_FDCLONE_DISABLE + * is set, no file descriptors will be cloned. If CONFIG_FDCLONE_STDIO is + * set, only the first three descriptors (stdin, stdout, and stderr) will + * be cloned. Otherwise all file descriptors will be cloned. + */ + +#if defined(CONFIG_FDCLONE_STDIO) && CONFIG_NFILE_DESCRIPTORS > 3 +# define NFDS_TOCLONE 3 +#else +# define NFDS_TOCLONE CONFIG_NFILE_DESCRIPTORS +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sched_dupfiles + * + * Description: + * Duplicate parent task's file descriptors. + * + * Input Parameters: + * tcb - tcb of the new task. + * + * Return Value: + * None + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_FDCLONE_DISABLE) +static inline void sched_dupfiles(FAR _TCB *tcb) +{ + /* The parent task is the one at the head of the ready-to-run list */ + + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + FAR struct file *parent; + FAR struct file *child; + int i; + + DEBUGASSERT(tcb && tcb->group && rtcb->group); + + /* Duplicate the file descriptors. This will be either all of the + * file descriptors or just the first three (stdin, stdout, and stderr) + * if CONFIG_FDCLONE_STDIO is defined. NFSDS_TOCLONE is set + * accordingly above. + */ + + /* Get pointers to the parent and child task file lists */ + + parent = rtcb->group->tg_filelist.fl_files; + child = tcb->group->tg_filelist.fl_files; + + /* Check each file in the parent file list */ + + for (i = 0; i < NFDS_TOCLONE; i++) + { + /* Check if this file is opened by the parent. We can tell if + * if the file is open because it contain a reference to a non-NULL + * i-node structure. + */ + + if (parent[i].f_inode) + { + /* Yes... duplicate it for the child */ + + (void)files_dup(&parent[i], &child[i]); + } + } +} +#else /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_FDCLONE_DISABLE */ +# define sched_dupfiles(tcb) +#endif /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_FDCLONE_DISABLE */ + +/**************************************************************************** + * Name: sched_dupsockets + * + * Description: + * Duplicate the parent task's socket descriptors. + * + * Input Parameters: + * tcb - tcb of the new task. + * + * Return Value: + * None + * + ****************************************************************************/ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 && !defined(CONFIG_SDCLONE_DISABLE) +static inline void sched_dupsockets(FAR _TCB *tcb) +{ + /* The parent task is the one at the head of the ready-to-run list */ + + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + FAR struct socket *parent; + FAR struct socket *child; + int i; + + /* Duplicate the socket descriptors of all sockets opened by the parent + * task. + */ + + DEBUGASSERT(tcb && tcb->group && rtcb->group); + + /* Get pointers to the parent and child task socket lists */ + + parent = rtcb->group->tg_sockets->sl_sockets; + child = tcb->group->tg_sockets->sl_sockets; + + /* Check each socket in the parent socket list */ + + for (i = 0; i < CONFIG_NSOCKET_DESCRIPTORS; i++) + { + /* Check if this parent socket is allocated. We can tell if the + * socket is allocated because it will have a positive, non-zero + * reference count. + */ + + if (parent[i].s_crefs > 0) + { + /* Yes... duplicate it for the child */ + + (void)net_clone(&parent[i], &child[i]); + } + } +} +#else /* CONFIG_NSOCKET_DESCRIPTORS && !CONFIG_SDCLONE_DISABLE */ +# define sched_dupsockets(tcb) +#endif /* CONFIG_NSOCKET_DESCRIPTORS && !CONFIG_SDCLONE_DISABLE */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: group_setuptaskfiles + * + * Description: + * Configure a newly allocated TCB so that it will inherit + * file descriptors and streams from the parent task. + * + * Parameters: + * tcb - tcb of the new task. + * + * Return Value: + * Zero (OK) is returned on success; A negated errno value is returned on + * failure. + * + * Assumptions: + * + ****************************************************************************/ + +int group_setuptaskfiles(FAR _TCB *tcb) +{ +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + FAR struct task_group_s *group = tcb->group; + + DEBUGASSERT(group); +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 + /* Initialize file descriptors for the TCB */ + + files_initlist(&group->tg_filelist); +#endif + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + /* Allocate socket descriptors for the TCB */ + + net_initlist(&group->tg_socketlist); +#endif + + /* Duplicate the parent task's file descriptors */ + + sched_dupfiles(tcb); + + /* Duplicate the parent task's socket descriptors */ + + sched_dupsockets(tcb); + + /* Allocate file/socket streams for the new TCB */ + +#if CONFIG_NFILE_STREAMS > 0 + return group_setupstreams(tcb); +#else + return OK; +#endif +} + +#endif /* CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0*/ diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index 5aa6487d0..262a40ccc 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -99,14 +99,6 @@ enum os_crash_codes_e #define MAX_TASKS_MASK (CONFIG_MAX_TASKS-1) #define PIDHASH(pid) ((pid) & MAX_TASKS_MASK) -/* Stubs used when there are no file descriptors */ - -#if CONFIG_NFILE_DESCRIPTORS <= 0 && CONFIG_NSOCKET_DESCRIPTORS <= 0 -# define sched_setupidlefiles(t) (OK) -# define sched_setuptaskfiles(t) (OK) -# define sched_setuppthreadfiles(t) (OK) -#endif - /* One processor family supported by NuttX has a single, fixed hardware stack. * That is the 8051 family. So for that family only, there is a variant form * of kernel_thread() that does not take a stack size parameter. The following @@ -293,15 +285,6 @@ int sched_reprioritize(FAR _TCB *tcb, int sched_priority); FAR _TCB *sched_gettcb(pid_t pid); bool sched_verifytcb(FAR _TCB *tcb); -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 -int sched_setupidlefiles(FAR _TCB *tcb); -int sched_setuptaskfiles(FAR _TCB *tcb); -int sched_setuppthreadfiles(FAR _TCB *tcb); -#if CONFIG_NFILE_STREAMS > 0 -int sched_setupstreams(FAR _TCB *tcb); -#endif -#endif - int sched_releasetcb(FAR _TCB *tcb); void sched_garbagecollection(void); diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c index b2551d2a3..5e6eaa858 100644 --- a/nuttx/sched/os_start.c +++ b/nuttx/sched/os_start.c @@ -451,7 +451,7 @@ void os_start(void) * inherited by all of the threads created by the IDLE task. */ - (void)sched_setupidlefiles(&g_idletcb); + (void)group_setupidlefiles(&g_idletcb); /* Create initial tasks and bring-up the system */ diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c index 9fd6a4a61..48a0788a6 100644 --- a/nuttx/sched/pthread_create.c +++ b/nuttx/sched/pthread_create.c @@ -296,15 +296,6 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, } #endif - /* Associate file descriptors with the new task */ - - ret = sched_setuppthreadfiles(ptcb); - if (ret != OK) - { - errcode = ret; - goto errout_with_tcb; - } - /* Allocate a detachable structure to support pthread_join logic */ pjoin = (FAR join_t*)kzalloc(sizeof(join_t)); diff --git a/nuttx/sched/sched_getsockets.c b/nuttx/sched/sched_getsockets.c index cd499420f..ea988d6ff 100644 --- a/nuttx/sched/sched_getsockets.c +++ b/nuttx/sched/sched_getsockets.c @@ -1,7 +1,7 @@ /************************************************************************ * sched/sched_getsockets.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -71,7 +71,10 @@ FAR struct socketlist *sched_getsockets(void) { FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - return rtcb->sockets; + FAR struct task_group_s *group = rtcb->group; + + DEBUGASSERT(group); + return &group->tg_socketlist; } #endif /* CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/sched_setupidlefiles.c b/nuttx/sched/sched_setupidlefiles.c deleted file mode 100644 index 4bbd4d3b7..000000000 --- a/nuttx/sched/sched_setupidlefiles.c +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** - * sched/sched_setupidlefiles.c - * - * Copyright (C) 2007-2010, 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "os_internal.h" - -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sched_setupidlefiles - * - * Description: - * Configure the idle thread's TCB. - * - * Parameters: - * tcb - tcb of the idle task. - * - * Return Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -int sched_setupidlefiles(FAR _TCB *tcb) -{ -#if CONFIG_NFILE_DESCRIPTORS > 0 - FAR struct task_group_s *group = tcb->group; -#endif -#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) - int fd; -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 - DEBUGASSERT(group); -#endif - - /* Initialize file descriptors for the TCB */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 - files_initlist(&group->tg_filelist); -#endif - - /* Allocate socket descriptors for the TCB */ - -#if CONFIG_NSOCKET_DESCRIPTORS > 0 - tcb->sockets = net_alloclist(); - if (!tcb->sockets) - { - return -ENOMEM; - } -#endif - - /* Open stdin, dup to get stdout and stderr. This should always - * be the first file opened and, hence, should always get file - * descriptor 0. - */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) - fd = open("/dev/console", O_RDWR); - if (fd == 0) - { - /* Successfully opened /dev/console as stdin (fd == 0) */ - - (void)file_dup2(0, 1); - (void)file_dup2(0, 2); - } - else - { - /* We failed to open /dev/console OR for some reason, we opened - * it and got some file descriptor other than 0. - */ - - if (fd > 0) - { - slldbg("Open /dev/console fd: %d\n", fd); - (void)close(fd); - } - else - { - slldbg("Failed to open /dev/console: %d\n", errno); - } - return -ENFILE; - } -#endif - - /* Allocate file/socket streams for the TCB */ - -#if CONFIG_NFILE_STREAMS > 0 - return sched_setupstreams(tcb); -#else - return OK; -#endif -} - -#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/sched_setuppthreadfiles.c b/nuttx/sched/sched_setuppthreadfiles.c deleted file mode 100644 index 91d72fa7f..000000000 --- a/nuttx/sched/sched_setuppthreadfiles.c +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** - * sched_setuppthreadfiles.c - * - * Copyright (C) 2007, 2009, 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include -#include - -#include "os_internal.h" - -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sched_setuppthreadfiles - * - * Description: - * Configure a newly allocated TCB so that it will inherit file - * descriptors and streams from the parent pthread. - * - * Parameters: - * tcb - tcb of the new task. - * - * Return Value: - * OK (if an error were returned, it would need to be a non-negated - * errno value). - * - * Assumptions: - * - ****************************************************************************/ - -int sched_setuppthreadfiles(FAR _TCB *tcb) -{ -#if CONFIG_NSOCKET_DESCRIPTORS > 0 - /* The child thread inherits the parent socket descriptors */ - - tcb->sockets = rtcb->sockets; - net_addreflist(tcb->sockets); - -#endif /* CONFIG_NSOCKET_DESCRIPTORS */ - - return OK; -} - -#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/sched_setupstreams.c b/nuttx/sched/sched_setupstreams.c deleted file mode 100644 index fb2e4d0be..000000000 --- a/nuttx/sched/sched_setupstreams.c +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** - * sched_setupstreams.c - * - * Copyright (C) 2007-2008, 2010-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include -#include - -/* Make sure that there are file or socket descriptors in the system and - * that some number of streams have been configured. - */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 -#if CONFIG_NFILE_STREAMS > 0 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sched_setupstreams - * - * Description: - * Setup streams data structures that may be used for standard C buffered - * I/O with underlying socket or file desciptors - * - ****************************************************************************/ - -int sched_setupstreams(FAR _TCB *tcb) -{ - DEBUGASSERT(tcb && tcb->group); - - /* Initialize file streams for the task group */ - - lib_streaminit(&tcb->group->tg_streamlist); - - /* fdopen to get the stdin, stdout and stderr streams. The following logic - * depends on the fact that the library layer will allocate FILEs in order. - * - * fd = 0 is stdin (read-only) - * fd = 1 is stdout (write-only, append) - * fd = 2 is stderr (write-only, append) - */ - - (void)fs_fdopen(0, O_RDONLY, tcb); - (void)fs_fdopen(1, O_WROK|O_CREAT, tcb); - (void)fs_fdopen(2, O_WROK|O_CREAT, tcb); - - return OK; -} - -#endif /* CONFIG_NFILE_STREAMS > 0 */ -#endif /* CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0*/ diff --git a/nuttx/sched/sched_setuptaskfiles.c b/nuttx/sched/sched_setuptaskfiles.c deleted file mode 100644 index 9e44147e9..000000000 --- a/nuttx/sched/sched_setuptaskfiles.c +++ /dev/null @@ -1,248 +0,0 @@ -/**************************************************************************** - * sched/sched_setuptaskfiles.c - * - * Copyright (C) 2007-2008, 2010, 2012-2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include - -#include "os_internal.h" - -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Determine how many file descriptors to clone. If CONFIG_FDCLONE_DISABLE - * is set, no file descriptors will be cloned. If CONFIG_FDCLONE_STDIO is - * set, only the first three descriptors (stdin, stdout, and stderr) will - * be cloned. Otherwise all file descriptors will be cloned. - */ - -#if defined(CONFIG_FDCLONE_STDIO) && CONFIG_NFILE_DESCRIPTORS > 3 -# define NFDS_TOCLONE 3 -#else -# define NFDS_TOCLONE CONFIG_NFILE_DESCRIPTORS -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sched_dupfiles - * - * Description: - * Duplicate parent task's file descriptors. - * - * Input Parameters: - * tcb - tcb of the new task. - * - * Return Value: - * None - * - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_FDCLONE_DISABLE) -static inline void sched_dupfiles(FAR _TCB *tcb) -{ - /* The parent task is the one at the head of the ready-to-run list */ - - FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - FAR struct file *parent; - FAR struct file *child; - int i; - - DEBUGASSERT(tcb && tcb->group && rtcb->group); - - /* Duplicate the file descriptors. This will be either all of the - * file descriptors or just the first three (stdin, stdout, and stderr) - * if CONFIG_FDCLONE_STDIO is defined. NFSDS_TOCLONE is set - * accordingly above. - */ - - /* Get pointers to the parent and child task file lists */ - - parent = rtcb->group->tg_filelist.fl_files; - child = tcb->group->tg_filelist.fl_files; - - /* Check each file in the parent file list */ - - for (i = 0; i < NFDS_TOCLONE; i++) - { - /* Check if this file is opened by the parent. We can tell if - * if the file is open because it contain a reference to a non-NULL - * i-node structure. - */ - - if (parent[i].f_inode) - { - /* Yes... duplicate it for the child */ - - (void)files_dup(&parent[i], &child[i]); - } - } -} -#else /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_FDCLONE_DISABLE */ -# define sched_dupfiles(tcb) -#endif /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_FDCLONE_DISABLE */ - -/**************************************************************************** - * Name: sched_dupsockets - * - * Description: - * Duplicate the parent task's socket descriptors. - * - * Input Parameters: - * tcb - tcb of the new task. - * - * Return Value: - * None - * - ****************************************************************************/ - -#if CONFIG_NSOCKET_DESCRIPTORS > 0 && !defined(CONFIG_SDCLONE_DISABLE) -static inline void sched_dupsockets(FAR _TCB *tcb) -{ - /* The parent task is the one at the head of the ready-to-run list */ - - FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - FAR struct socket *parent; - FAR struct socket *child; - int i; - - /* Duplicate the socket descriptors of all sockets opened by the parent - * task. - */ - - if (rtcb->sockets) - { - /* Get pointers to the parent and child task socket lists */ - - parent = rtcb->sockets->sl_sockets; - child = tcb->sockets->sl_sockets; - - /* Check each socket in the parent socket list */ - - for (i = 0; i < CONFIG_NSOCKET_DESCRIPTORS; i++) - { - /* Check if this parent socket is allocated. We can tell if the - * socket is allocated because it will have a positive, non-zero - * reference count. - */ - - if (parent[i].s_crefs > 0) - { - /* Yes... duplicate it for the child */ - - (void)net_clone(&parent[i], &child[i]); - } - } - } -} -#else /* CONFIG_NSOCKET_DESCRIPTORS && !CONFIG_SDCLONE_DISABLE */ -# define sched_dupsockets(tcb) -#endif /* CONFIG_NSOCKET_DESCRIPTORS && !CONFIG_SDCLONE_DISABLE */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sched_setuptaskfiles - * - * Description: - * Configure a newly allocated TCB so that it will inherit - * file descriptors and streams from the parent task. - * - * Parameters: - * tcb - tcb of the new task. - * - * Return Value: - * Zero (OK) is returned on success; A negated errno value is returned on - * failure. - * - * Assumptions: - * - ****************************************************************************/ - -int sched_setuptaskfiles(FAR _TCB *tcb) -{ -#if CONFIG_NFILE_DESCRIPTORS > 0 - FAR struct task_group_s *group = tcb->group; - - DEBUGASSERT(group); - - /* Initialize file descriptors for the TCB */ - - files_initlist(&group->tg_filelist); -#endif - - /* Allocate socket descriptors for the TCB */ - -#if CONFIG_NSOCKET_DESCRIPTORS > 0 - tcb->sockets = net_alloclist(); - if (!tcb->sockets) - { - return -ENOMEM; - } -#endif - - /* Duplicate the parent task's file descriptors */ - - sched_dupfiles(tcb); - - /* Duplicate the parent task's socket descriptors */ - - sched_dupsockets(tcb); - - /* Allocate file/socket streams for the new TCB */ - -#if CONFIG_NFILE_STREAMS > 0 - return sched_setupstreams(tcb); -#else - return OK; -#endif -} - -#endif /* CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0*/ diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c index 85c0f5e92..944743200 100644 --- a/nuttx/sched/task_create.c +++ b/nuttx/sched/task_create.c @@ -134,7 +134,7 @@ static int thread_create(const char *name, uint8_t ttype, int priority, /* Associate file descriptors with the new task */ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - ret = sched_setuptaskfiles(tcb); + ret = group_setuptaskfiles(tcb); if (ret != OK) { errcode = -ret; diff --git a/nuttx/sched/task_init.c b/nuttx/sched/task_init.c index 8dfd8b7f6..78f35bc2a 100644 --- a/nuttx/sched/task_init.c +++ b/nuttx/sched/task_init.c @@ -137,7 +137,7 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, /* Associate file descriptors with the new task */ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - ret = sched_setuptaskfiles(tcb); + ret = group_setuptaskfiles(tcb); if (ret < 0) { errcode = -ret; diff --git a/nuttx/sched/task_vfork.c b/nuttx/sched/task_vfork.c index 3f058bdec..5b42a1e55 100644 --- a/nuttx/sched/task_vfork.c +++ b/nuttx/sched/task_vfork.c @@ -125,7 +125,7 @@ FAR _TCB *task_vforksetup(start_t retaddr) /* Associate file descriptors with the new task */ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - ret = sched_setuptaskfiles(child); + ret = group_setuptaskfiles(child); if (ret != OK) { goto errout_with_tcb; -- cgit v1.2.3 From e96d8f046b6bce6c4e810b302c1cc1cc578bdae3 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 27 Jan 2013 15:52:58 +0000 Subject: Add a start hook that can be setup to call a function in the context of a new thread before the new threads main() has been called. git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5571 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/elf/tests/signal/signal.c | 2 +- apps/examples/nxflat/tests/signal/signal.c | 2 +- nuttx/ChangeLog | 6 ++ nuttx/TODO | 17 +++- nuttx/binfmt/Kconfig | 5 +- nuttx/binfmt/binfmt_execmodule.c | 61 +++++-------- nuttx/binfmt/binfmt_internal.h | 2 +- nuttx/configs/stm32f4discovery/elf/defconfig | 45 ++++++++-- .../configs/stm32f4discovery/posix_spawn/defconfig | 1 + nuttx/include/nuttx/sched.h | 24 ++++- nuttx/sched/Kconfig | 10 +++ nuttx/sched/Makefile | 4 + nuttx/sched/group_setupidlefiles.c | 1 + nuttx/sched/group_setupstreams.c | 2 + nuttx/sched/group_setuptaskfiles.c | 5 +- nuttx/sched/task_start.c | 9 ++ nuttx/sched/task_starthook.c | 100 +++++++++++++++++++++ 17 files changed, 239 insertions(+), 57 deletions(-) create mode 100644 nuttx/sched/task_starthook.c diff --git a/apps/examples/elf/tests/signal/signal.c b/apps/examples/elf/tests/signal/signal.c index b40da7a86..d43f012cb 100644 --- a/apps/examples/elf/tests/signal/signal.c +++ b/apps/examples/elf/tests/signal/signal.c @@ -161,7 +161,7 @@ int main(int argc, char **argv) /* Send SIGUSR1 to ourselves via kill() */ printf("Kill-ing SIGUSR1 from pid=%d\n", mypid); - status = kill(0, SIGUSR1); + status = kill(mypid, SIGUSR1); if (status != 0) { fprintf(stderr, "Failed to kill SIGUSR1, errno=%d\n", errno); diff --git a/apps/examples/nxflat/tests/signal/signal.c b/apps/examples/nxflat/tests/signal/signal.c index c5ea6bdcc..ac03f6d33 100644 --- a/apps/examples/nxflat/tests/signal/signal.c +++ b/apps/examples/nxflat/tests/signal/signal.c @@ -161,7 +161,7 @@ int main(int argc, char **argv) /* Send SIGUSR1 to ourselves via kill() */ printf("Kill-ing SIGUSR1 from pid=%d\n", mypid); - status = kill(0, SIGUSR1); + status = kill(mypid, SIGUSR1); if (status != 0) { fprintf(stderr, "Failed to kill SIGUSR1, errno=%d\n", errno); diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 255d69a3d..32112f358 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4040,3 +4040,9 @@ Move stream data from the TCB to the task group structure. * net/, sched/, and include/nuttx/net/net.h: Move socket data from the TCB to the task group structure. + * sched/task_starthook.c, sched/task_start.c, and include/nuttx/sched.h: + Add a task start hook that will be called before the task main + is started. This can be used to schedule C++ constructors to run + automatically in the context of the new task. + * binfmt/binfmt_execmodule: Execute constructors as a start hook. + diff --git a/nuttx/TODO b/nuttx/TODO index cb99f1bf7..05e0fa99b 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated January 26, 2013) +NuttX TODO List (Last updated January 27, 2013) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -6,7 +6,7 @@ standards, things that could be improved, and ideas for enhancements. nuttx/ - (10) Task/Scheduler (sched/) + (11) Task/Scheduler (sched/) (2) Memory Managment (mm/) (3) Signals (sched/, arch/) (2) pthreads (sched/) @@ -193,6 +193,16 @@ o Task/Scheduler (sched/) Status: Open Priority: Low (it might as well be low since it isn't going to be fixed). + Title: errno IS NOT SHARED AMONG THREADS + Description: In NuttX, the errno value is unique for each thread. But for + bug-for-bug compatibility, the same errno should be shared by + the task and each thread that it creates. It is *very* easy + to make this change: Just move the pterrno field from + _TCB to struct task_group_s. However, I am still not sure + if this should be done or not. + Status: Open + Priority: Low + o Memory Managment (mm/) ^^^^^^^^^^^^^^^^^^^^^^ @@ -407,6 +417,9 @@ o Binary loaders (binfmt/) Description: Not all of the NXFLAT test under apps/examples/nxflat are working. Most simply do not compile yet. tests/mutex runs okay but outputs garbage on completion. + + Update: 13-27-1, tests/mutex crashed with a memory corruption + problem the last time that I ran it. Status: Open Priority: High diff --git a/nuttx/binfmt/Kconfig b/nuttx/binfmt/Kconfig index 8d6c0bb18..6e5f7c251 100644 --- a/nuttx/binfmt/Kconfig +++ b/nuttx/binfmt/Kconfig @@ -72,9 +72,10 @@ config PIC config BINFMT_CONSTRUCTORS bool "C++ Static Constructor Support" default n - depends on HAVE_CXX && ELF # FIX ME: Currently only supported for ELF + depends on HAVE_CXX && SCHED_STARTHOOK && ELF ---help--- - Build in support for C++ constructors in loaded modules. + Build in support for C++ constructors in loaded modules. Currently + only support for ELF binary formats. config SYMTAB_ORDEREDBYNAME bool "Symbol Tables Ordered by Name" diff --git a/nuttx/binfmt/binfmt_execmodule.c b/nuttx/binfmt/binfmt_execmodule.c index afa445abb..10068b482 100644 --- a/nuttx/binfmt/binfmt_execmodule.c +++ b/nuttx/binfmt/binfmt_execmodule.c @@ -58,6 +58,14 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* If C++ constructors are used, then CONFIG_SCHED_STARTHOOK must also be + * selected be the start hook is used to schedule execution of the + * constructors. + */ + +#if defined(CONFIG_BINFMT_CONSTRUCTORS) && !defined(CONFIG_SCHED_STARTHOOK) +# errror "CONFIG_SCHED_STARTHOOK must be defined to use constructors" +#endif /**************************************************************************** * Private Function Prototypes @@ -75,7 +83,9 @@ * Name: exec_ctors * * Description: - * Execute C++ static constructors. + * Execute C++ static constructors. This function is registered as a + * start hook and runs on the thread of the newly created task before + * the new task's main function is called. * * Input Parameters: * loadinfo - Load state information @@ -87,26 +97,12 @@ ****************************************************************************/ #ifdef CONFIG_BINFMT_CONSTRUCTORS -static inline int exec_ctors(FAR const struct binary_s *binp) +static void exec_ctors(FAR void *arg) { + FAR const struct binary_s *binp = (FAR const struct binary_s *)arg; binfmt_ctor_t *ctor = binp->ctors; -#ifdef CONFIG_ADDRENV - hw_addrenv_t oldenv; - int ret; -#endif int i; - /* Instantiate the address enviroment containing the constructors */ - -#ifdef CONFIG_ADDRENV - ret = up_addrenv_select(binp->addrenv, &oldenv); - if (ret < 0) - { - bdbg("up_addrenv_select() failed: %d\n", ret); - return ret; - } -#endif - /* Execute each constructor */ for (i = 0; i < binp->nctors; i++) @@ -116,14 +112,6 @@ static inline int exec_ctors(FAR const struct binary_s *binp) (*ctor)(); ctor++; } - - /* Restore the address enviroment */ - -#ifdef CONFIG_ADDRENV - return up_addrenv_restore(oldenv); -#else - return OK; -#endif } #endif @@ -139,7 +127,7 @@ static inline int exec_ctors(FAR const struct binary_s *binp) * * Returned Value: * This is an end-user function, so it follows the normal convention: - * Returns the PID of the exec'ed module. On failure, it.returns + * Returns the PID of the exec'ed module. On failure, it returns * -1 (ERROR) and sets errno appropriately. * ****************************************************************************/ @@ -229,22 +217,19 @@ int exec_module(FAR const struct binary_s *binp) } #endif - /* Get the assigned pid before we start the task */ - - pid = tcb->pid; - - /* Execute all of the C++ static constructors */ + /* Setup a start hook that will execute all of the C++ static constructors + * on the newly created thread. The struct binary_s must persist at least + * until the new task has been started. + */ #ifdef CONFIG_BINFMT_CONSTRUCTORS - ret = exec_ctors(binp); - if (ret < 0) - { - err = -ret; - bdbg("exec_ctors() failed: %d\n", ret); - goto errout_with_stack; - } + task_starthook(tcb, exec_ctors, (FAR void *)binp); #endif + /* Get the assigned pid before we start the task */ + + pid = tcb->pid; + /* Then activate the task at the provided priority */ ret = task_activate(tcb); diff --git a/nuttx/binfmt/binfmt_internal.h b/nuttx/binfmt/binfmt_internal.h index 4fab9724d..fa750543a 100644 --- a/nuttx/binfmt/binfmt_internal.h +++ b/nuttx/binfmt/binfmt_internal.h @@ -71,7 +71,7 @@ EXTERN FAR struct binfmt_s *g_binfmts; * Public Function Prototypes ***********************************************************************/ -/* Dump the contents of strtuc binary_s */ +/* Dump the contents of struct binary_s */ #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT) EXTERN int dump_module(FAR const struct binary_s *bin); diff --git a/nuttx/configs/stm32f4discovery/elf/defconfig b/nuttx/configs/stm32f4discovery/elf/defconfig index 3f5a5d0fc..f7e0dc5f2 100644 --- a/nuttx/configs/stm32f4discovery/elf/defconfig +++ b/nuttx/configs/stm32f4discovery/elf/defconfig @@ -69,7 +69,7 @@ CONFIG_ARCH="arm" # CONFIG_ARCH_CHIP_DM320 is not set # CONFIG_ARCH_CHIP_IMX is not set # CONFIG_ARCH_CHIP_KINETIS is not set -# CONFIG_ARCH_CHIP_LM3S is not set +# CONFIG_ARCH_CHIP_LM is not set # CONFIG_ARCH_CHIP_LPC17XX is not set # CONFIG_ARCH_CHIP_LPC214X is not set # CONFIG_ARCH_CHIP_LPC2378 is not set @@ -81,6 +81,7 @@ CONFIG_ARCH_CHIP_STM32=y CONFIG_ARCH_CORTEXM4=y CONFIG_ARCH_FAMILY="armv7-m" CONFIG_ARCH_CHIP="stm32" +CONFIG_ARMV7M_USEBASEPRI=y CONFIG_ARCH_HAVE_CMNVECTOR=y # CONFIG_ARMV7M_CMNVECTOR is not set # CONFIG_ARCH_FPU is not set @@ -201,26 +202,35 @@ CONFIG_STM32_JTAG_SW_ENABLE=y # CONFIG_STM32_FORCEPOWER is not set # CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set CONFIG_STM32_CCMEXCLUDE=y +CONFIG_STM32_USART=y # # U[S]ART Configuration # # CONFIG_USART2_RS485 is not set +# CONFIG_STM32_USART_SINGLEWIRE is not set # # USB Host Configuration # +# +# External Memory Configuration +# + # # Architecture Options # # CONFIG_ARCH_NOINTC is not set +# CONFIG_ARCH_VECNOTIRQ is not set # CONFIG_ARCH_DMA is not set CONFIG_ARCH_IRQPRIO=y # CONFIG_CUSTOM_STACK is not set # CONFIG_ADDRENV is not set +CONFIG_ARCH_HAVE_VFORK=y CONFIG_ARCH_STACKDUMP=y # CONFIG_ENDIAN_BIG is not set +# CONFIG_ARCH_HAVE_RAMFUNCS is not set # # Board Settings @@ -266,6 +276,7 @@ CONFIG_MSEC_PER_TICK=10 CONFIG_RR_INTERVAL=200 # CONFIG_SCHED_INSTRUMENTATION is not set CONFIG_TASK_NAME_SIZE=0 +# CONFIG_SCHED_HAVE_PARENT is not set # CONFIG_JULIAN_TIME is not set CONFIG_START_YEAR=2012 CONFIG_START_MONTH=10 @@ -278,6 +289,7 @@ CONFIG_DEV_CONSOLE=y CONFIG_SDCLONE_DISABLE=y # CONFIG_SCHED_WORKQUEUE is not set # CONFIG_SCHED_WAITPID is not set +CONFIG_SCHED_STARTHOOK=y # CONFIG_SCHED_ATEXIT is not set # CONFIG_SCHED_ONEXIT is not set CONFIG_USER_ENTRYPOINT="elf_main" @@ -287,9 +299,15 @@ CONFIG_DISABLE_OS_API=y # CONFIG_DISABLE_PTHREAD is not set # CONFIG_DISABLE_SIGNALS is not set # CONFIG_DISABLE_MQUEUE is not set -# CONFIG_DISABLE_MOUNTPOINT is not set # CONFIG_DISABLE_ENVIRON is not set -# CONFIG_DISABLE_POLL is not set + +# +# Signal Numbers +# +CONFIG_SIG_SIGUSR1=1 +CONFIG_SIG_SIGUSR2=2 +CONFIG_SIG_SIGALARM=3 +CONFIG_SIG_SIGCONDTIMEDOUT=16 # # Sizes of configurable things (0 disables) @@ -317,6 +335,7 @@ CONFIG_PTHREAD_STACK_DEFAULT=2048 # # Device Drivers # +# CONFIG_DISABLE_POLL is not set CONFIG_DEV_NULL=y # CONFIG_DEV_ZERO is not set # CONFIG_LOOP is not set @@ -381,8 +400,9 @@ CONFIG_USART2_2STOP=0 # # File system configuration # -# CONFIG_FS_FAT is not set +# CONFIG_DISABLE_MOUNTPOINT is not set # CONFIG_FS_RAMMAP is not set +# CONFIG_FS_FAT is not set # CONFIG_FS_NXFFS is not set CONFIG_FS_ROMFS=y @@ -415,6 +435,7 @@ CONFIG_ELF_ALIGN_LOG2=2 CONFIG_ELF_STACKSIZE=2048 CONFIG_ELF_BUFFERSIZE=128 CONFIG_ELF_BUFFERINCR=32 +# CONFIG_BUILTIN is not set # CONFIG_PIC is not set CONFIG_BINFMT_CONSTRUCTORS=y CONFIG_SYMTAB_ORDEREDBYNAME=y @@ -422,6 +443,10 @@ CONFIG_SYMTAB_ORDEREDBYNAME=y # # Library Routines # + +# +# Standard C Library Options +# CONFIG_STDIO_BUFFER_SIZE=256 CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=2 @@ -433,6 +458,7 @@ CONFIG_LIB_HOMEDIR="/" # CONFIG_EOL_IS_LF is not set # CONFIG_EOL_IS_BOTH_CRLF is not set CONFIG_EOL_IS_EITHER_CRLF=y +# CONFIG_LIBC_EXECFUNCS is not set # CONFIG_LIBC_STRERROR is not set # CONFIG_LIBC_PERROR_STDOUT is not set CONFIG_ARCH_LOWPUTC=y @@ -440,6 +466,11 @@ CONFIG_LIB_SENDFILE_BUFSIZE=512 # CONFIG_ARCH_ROMGETC is not set # CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set +# +# Non-standard Helper Functions +# +# CONFIG_LIB_KBDCODEC is not set + # # Basic CXX Support # @@ -458,9 +489,8 @@ CONFIG_HAVE_CXX=y # # -# Named Applications +# Built-In Applications # -# CONFIG_BUILTIN is not set # # Examples @@ -486,7 +516,6 @@ CONFIG_EXAMPLES_ELF_DEVPATH="/dev/ram0" # CONFIG_EXAMPLES_MM is not set # CONFIG_EXAMPLES_MOUNT is not set # CONFIG_EXAMPLES_MODBUS is not set -# CONFIG_EXAMPLES_NETTEST is not set # CONFIG_EXAMPLES_NSH is not set # CONFIG_EXAMPLES_NULL is not set # CONFIG_EXAMPLES_NX is not set @@ -501,6 +530,7 @@ CONFIG_EXAMPLES_ELF_DEVPATH="/dev/ram0" # CONFIG_EXAMPLES_PASHELLO is not set # CONFIG_EXAMPLES_PIPE is not set # CONFIG_EXAMPLES_POLL is not set +# CONFIG_EXAMPLES_POSIXSPAWN is not set # CONFIG_EXAMPLES_QENCODER is not set # CONFIG_EXAMPLES_RGMP is not set # CONFIG_EXAMPLES_ROMFS is not set @@ -516,7 +546,6 @@ CONFIG_EXAMPLES_ELF_DEVPATH="/dev/ram0" # CONFIG_EXAMPLES_USBMSC is not set # CONFIG_EXAMPLES_USBTERM is not set # CONFIG_EXAMPLES_WATCHDOG is not set -# CONFIG_EXAMPLES_WLAN is not set # # Interpreters diff --git a/nuttx/configs/stm32f4discovery/posix_spawn/defconfig b/nuttx/configs/stm32f4discovery/posix_spawn/defconfig index 9e30ada8a..97cf84ab4 100644 --- a/nuttx/configs/stm32f4discovery/posix_spawn/defconfig +++ b/nuttx/configs/stm32f4discovery/posix_spawn/defconfig @@ -279,6 +279,7 @@ CONFIG_DEV_CONSOLE=y CONFIG_SDCLONE_DISABLE=y # CONFIG_SCHED_WORKQUEUE is not set # CONFIG_SCHED_WAITPID is not set +CONFIG_SCHED_STARTHOOK=y # CONFIG_SCHED_ATEXIT is not set # CONFIG_SCHED_ONEXIT is not set CONFIG_USER_ENTRYPOINT="spawn_main" diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 244455cd4..f8b4eb0dc 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -183,7 +183,13 @@ union entry_u }; typedef union entry_u entry_t; -/* These is the types of the functions that are executed with exit() is called +/* This is the type of the function called at task startup */ + +#ifdef CONFIG_SCHED_STARTHOOK +typedef CODE void (*starthook_t)(FAR void *arg); +#endif + +/* These are the types of the functions that are executed with exit() is called * (if registered via atexit() on on_exit()). */ @@ -298,7 +304,10 @@ struct task_group_s #endif /* PIC data space and address environments ************************************/ - /* Not yet (see struct dspace_s) */ + /* Logically the PIC data space belongs here (see struct dspace_s). The + * current logic needs review: There are differences in the away that the + * life of the PIC data is managed. + */ /* File descriptors ***********************************************************/ @@ -354,6 +363,11 @@ struct _TCB start_t start; /* Thread start function */ entry_t entry; /* Entry Point into the thread */ +#ifdef CONFIG_SCHED_STARTHOOK + starthook_t starthook; /* Task startup function */ + FAR void *starthookarg; /* The argument passed to the function */ +#endif + #if defined(CONFIG_SCHED_ATEXIT) && !defined(CONFIG_SCHED_ONEXIT) # if defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1 atexitfunc_t atexitfunc[CONFIG_SCHED_ATEXIT_MAX]; @@ -516,6 +530,12 @@ FAR struct streamlist *sched_getstreams(void); FAR struct socketlist *sched_getsockets(void); #endif /* CONFIG_NSOCKET_DESCRIPTORS */ +/* Setup up a start hook */ + +#ifdef CONFIG_SCHED_STARTHOOK +void task_starthook(FAR _TCB *tcb, starthook_t starthook, FAR void *arg); +#endif + /* Internal vfork support.The overall sequence is: * * 1) User code calls vfork(). vfork() is provided in architecture-specific diff --git a/nuttx/sched/Kconfig b/nuttx/sched/Kconfig index 7745c2c25..097dd1993 100644 --- a/nuttx/sched/Kconfig +++ b/nuttx/sched/Kconfig @@ -296,6 +296,16 @@ config SCHED_WAITPID compliant) and will enable the waitid() and wait() interfaces as well. +config SCHED_STARTHOOK + bool "Enable startup hook" + default n + ---help--- + Enable a non-standard, internal OS API call task_starthook(). + task_starthook() registers a function that will be called on task + startup before that actual task entry point is called. The + starthook is useful, for example, for setting up automatic + configuration of C++ constructors. + config SCHED_ATEXIT bool "Enable atexit() API" default n diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index 7710ae058..961560176 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -54,6 +54,10 @@ TSK_SRCS += task_posixspawn.c endif endif +ifeq ($(CONFIG_SCHED_STARTHOOK),y) +TSK_SRCS += task_starthook.c +endif + SCHED_SRCS = sched_setparam.c sched_setpriority.c sched_getparam.c SCHED_SRCS += sched_setscheduler.c sched_getscheduler.c SCHED_SRCS += sched_yield.c sched_rrgetinterval.c sched_foreach.c diff --git a/nuttx/sched/group_setupidlefiles.c b/nuttx/sched/group_setupidlefiles.c index 98cc7885e..ceb9f3e2c 100644 --- a/nuttx/sched/group_setupidlefiles.c +++ b/nuttx/sched/group_setupidlefiles.c @@ -50,6 +50,7 @@ #include #include "os_internal.h" +#include "group_internal.h" #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 diff --git a/nuttx/sched/group_setupstreams.c b/nuttx/sched/group_setupstreams.c index 88e266280..08399ae41 100644 --- a/nuttx/sched/group_setupstreams.c +++ b/nuttx/sched/group_setupstreams.c @@ -46,6 +46,8 @@ #include #include +#include "group_internal.h" + /* Make sure that there are file or socket descriptors in the system and * that some number of streams have been configured. */ diff --git a/nuttx/sched/group_setuptaskfiles.c b/nuttx/sched/group_setuptaskfiles.c index d52adcfee..e2e7d4634 100644 --- a/nuttx/sched/group_setuptaskfiles.c +++ b/nuttx/sched/group_setuptaskfiles.c @@ -46,6 +46,7 @@ #include #include "os_internal.h" +#include "group_internal.h" #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 @@ -159,8 +160,8 @@ static inline void sched_dupsockets(FAR _TCB *tcb) /* Get pointers to the parent and child task socket lists */ - parent = rtcb->group->tg_sockets->sl_sockets; - child = tcb->group->tg_sockets->sl_sockets; + parent = rtcb->group->tg_socketlist.sl_sockets; + child = tcb->group->tg_socketlist.sl_sockets; /* Check each socket in the parent socket list */ diff --git a/nuttx/sched/task_start.c b/nuttx/sched/task_start.c index a9cc38dfc..5a32a5dd8 100644 --- a/nuttx/sched/task_start.c +++ b/nuttx/sched/task_start.c @@ -94,6 +94,15 @@ void task_start(void) FAR _TCB *tcb = (FAR _TCB*)g_readytorun.head; int argc; + /* Execute the start hook if one has been registered */ + +#ifdef CONFIG_SCHED_STARTHOOK + if (tcb->starthook) + { + tcb->starthook(tcb->starthookarg); + } +#endif + /* Count how many non-null arguments we are passing */ for (argc = 1; argc <= CONFIG_MAX_TASK_ARGS; argc++) diff --git a/nuttx/sched/task_starthook.c b/nuttx/sched/task_starthook.c new file mode 100644 index 000000000..1cb29349f --- /dev/null +++ b/nuttx/sched/task_starthook.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * sched/task_start.c + * + * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#ifdef CONFIG_SCHED_STARTHOOK + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: task_starthook + * + * Description: + * Configure a start hook... a function that will be called on the thread + * of the new task before the new task's main entry point is called. + * The start hook is useful, for example, for setting up automatic + * configuration of C++ constructors. + * + * Inputs: + * tcb - The new, unstarted task task that needs the start hook + * starthook - The pointer to the start hook function + * arg - The argument to pass to the start hook function. + * + * Return: + * None + * + ****************************************************************************/ + +void task_starthook(FAR _TCB *tcb, starthook_t starthook, FAR void *arg) +{ + DEBUGASSERT(tcb); + tcb->starthook = starthook; + tcb->starthookarg = arg; +} + +#endif /* CONFIG_SCHED_STARTHOOK */ -- cgit v1.2.3 From b4db7635d85361c3cb8a718d5f460000b7123fb3 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 27 Jan 2013 19:17:56 +0000 Subject: Add configs/stm32f4discovery/usbnsh git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5572 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 3 + nuttx/configs/stm32f4discovery/README.txt | 50 ++ nuttx/configs/stm32f4discovery/usbnsh/Make.defs | 111 ++++ nuttx/configs/stm32f4discovery/usbnsh/defconfig | 738 ++++++++++++++++++++++++ nuttx/configs/stm32f4discovery/usbnsh/setenv.sh | 75 +++ nuttx/drivers/usbdev/Kconfig | 18 +- nuttx/fs/Kconfig | 23 +- nuttx/fs/fs_syslog.c | 2 +- nuttx/libc/stdio/lib_lowprintf.c | 2 + nuttx/libc/stdio/lib_rawprintf.c | 3 + nuttx/sched/os_start.c | 23 +- nuttx/sched/task_vfork.c | 1 + 12 files changed, 1029 insertions(+), 20 deletions(-) create mode 100644 nuttx/configs/stm32f4discovery/usbnsh/Make.defs create mode 100644 nuttx/configs/stm32f4discovery/usbnsh/defconfig create mode 100755 nuttx/configs/stm32f4discovery/usbnsh/setenv.sh diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 32112f358..76ed2b603 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4045,4 +4045,7 @@ is started. This can be used to schedule C++ constructors to run automatically in the context of the new task. * binfmt/binfmt_execmodule: Execute constructors as a start hook. + * sched/os_start.c: Fix ordering of group initialization. + * configs/stm32f4discovery/usbnsh: Add an NSH STM32F4Discovery + configuration that uses USB CDC/ACM for the NSH console. diff --git a/nuttx/configs/stm32f4discovery/README.txt b/nuttx/configs/stm32f4discovery/README.txt index 39fb41d78..0e295c429 100644 --- a/nuttx/configs/stm32f4discovery/README.txt +++ b/nuttx/configs/stm32f4discovery/README.txt @@ -1473,6 +1473,56 @@ Where is one of the following: 3. By default, this project assumes that you are *NOT* using the DFU bootloader. + usbnsh: + ------- + + This is another NSH example. If differs from other 'nsh' configurations + in that this configurations uses a USB serial device for console I/O. + Such a configuration is useful on the stm32f4discovery which has no + builtin RS-232 drivers. + + NOTES: + + 1. This configuration uses the mconf-based configuration tool. To + change this configuration using that tool, you should: + + a. Build and install the kconfig-mconf tool. See nuttx/README.txt + and misc/tools/ + + b. Execute 'make menuconfig' in nuttx/ in order to start the + reconfiguration process. + + 2. By default, this configuration uses the CodeSourcery toolchain + for Windows and builds under Cygwin (or probably MSYS). That + can easily be reconfigured, of course. + + CONFIG_HOST_WINDOWS=y : Builds under Windows + CONFIG_WINDOWS_CYGWIN=y : Using Cygwin + CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery for Windows + + 3. This configuration does have UART2 output enabled and set up as + the system logging device: + + CONFIG_SYSLOG=y : Enable output to syslog, not console + CONFIG_SYSLOG_CHAR=y : Use a character device for system logging + CONFIG_SYSLOG_DEVPATH="/dev/ttyS0" : UART2 will be /dev/ttyS0 + + Debug, however, is not enable so in the default configuration nothing + should appear on UART2 unless you enable some debug output. + + 4. By default, this project assumes that you are *NOT* using the DFU + bootloader. + + Using the Prolifics PL2303 Emulation + ------------------------------------ + You could also use the non-standard PL2303 serial device instead of + the standard CDC/ACM serial device by changing: + + CONFIG_CDCACM=y : Disable the CDC/ACM serial device class + CONFIG_CDCACM_CONSOLE=y : The CDC/ACM serial device is NOT the console + CONFIG_PL2303=y : The Prolifics PL2303 emulation is enabled + CONFIG_PL2303_CONSOLE=y : The PL2303 serial device is the console + winbuild: -------- diff --git a/nuttx/configs/stm32f4discovery/usbnsh/Make.defs b/nuttx/configs/stm32f4discovery/usbnsh/Make.defs new file mode 100644 index 000000000..0bea20b8a --- /dev/null +++ b/nuttx/configs/stm32f4discovery/usbnsh/Make.defs @@ -0,0 +1,111 @@ +############################################################################ +# configs/stm32f4discovery/usbnsh/Make.defs +# +# Copyright (C) 2013 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +include ${TOPDIR}/.config +include ${TOPDIR}/tools/Config.mk +include ${TOPDIR}/arch/arm/src/armv7-m/Toolchain.defs + +LDSCRIPT = ld.script + +ifeq ($(WINTOOL),y) + # Windows-native toolchains + DIRLINK = $(TOPDIR)/tools/copydir.sh + DIRUNLINK = $(TOPDIR)/tools/unlink.sh + MKDEP = $(TOPDIR)/tools/mknulldeps.sh + ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" + ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}" + ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT)}" + MAXOPTIMIZATION = -O2 +else + # Linux/Cygwin-native toolchain + MKDEP = $(TOPDIR)/tools/mkdeps.sh + ARCHINCLUDES = -I. -isystem $(TOPDIR)/include + ARCHXXINCLUDES = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx + ARCHSCRIPT = -T$(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT) +endif + +CC = $(CROSSDEV)gcc +CXX = $(CROSSDEV)g++ +CPP = $(CROSSDEV)gcc -E +LD = $(CROSSDEV)ld +AR = $(ARCROSSDEV)ar rcs +NM = $(ARCROSSDEV)nm +OBJCOPY = $(CROSSDEV)objcopy +OBJDUMP = $(CROSSDEV)objdump + +ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'} +ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1} + +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + ARCHOPTIMIZATION = -g +else + ARCHOPTIMIZATION = $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer +endif + +ARCHCFLAGS = -fno-builtin +ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fno-rtti +ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow +ARCHWARNINGSXX = -Wall -Wshadow +ARCHDEFINES = +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 + +CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) +AFLAGS = $(CFLAGS) -D__ASSEMBLY__ + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 + +OBJEXT = .o +LIBEXT = .a +EXEEXT = + +ifneq ($(CROSSDEV),arm-nuttx-elf-) + LDFLAGS += -nostartfiles -nodefaultlibs +endif +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + LDFLAGS += -g +endif + + +HOSTCC = gcc +HOSTINCLUDES = -I. +HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -g -pipe +HOSTLDFLAGS = + diff --git a/nuttx/configs/stm32f4discovery/usbnsh/defconfig b/nuttx/configs/stm32f4discovery/usbnsh/defconfig new file mode 100644 index 000000000..3ddcab424 --- /dev/null +++ b/nuttx/configs/stm32f4discovery/usbnsh/defconfig @@ -0,0 +1,738 @@ +# +# Automatically generated file; DO NOT EDIT. +# Nuttx/ Configuration +# +CONFIG_NUTTX_NEWCONFIG=y + +# +# Build Setup +# +# CONFIG_EXPERIMENTAL is not set +# CONFIG_HOST_LINUX is not set +# CONFIG_HOST_OSX is not set +CONFIG_HOST_WINDOWS=y +# CONFIG_HOST_OTHER is not set +# CONFIG_WINDOWS_NATIVE is not set +CONFIG_WINDOWS_CYGWIN=y +# CONFIG_WINDOWS_MSYS is not set +# CONFIG_WINDOWS_OTHER is not set + +# +# Build Configuration +# +# CONFIG_APPS_DIR="../apps" +# CONFIG_BUILD_2PASS is not set + +# +# Binary Output Formats +# +# CONFIG_RRLOAD_BINARY is not set +CONFIG_INTELHEX_BINARY=y +# CONFIG_MOTOROLA_SREC is not set +CONFIG_RAW_BINARY=y + +# +# Customize Header Files +# +# CONFIG_ARCH_STDBOOL_H is not set +# CONFIG_ARCH_MATH_H is not set +# CONFIG_ARCH_FLOAT_H is not set +# CONFIG_ARCH_STDARG_H is not set + +# +# Debug Options +# +# CONFIG_DEBUG is not set +# CONFIG_DEBUG_SYMBOLS is not set + +# +# System Type +# +# CONFIG_ARCH_8051 is not set +CONFIG_ARCH_ARM=y +# CONFIG_ARCH_AVR is not set +# CONFIG_ARCH_HC is not set +# CONFIG_ARCH_MIPS is not set +# CONFIG_ARCH_RGMP is not set +# CONFIG_ARCH_SH is not set +# CONFIG_ARCH_SIM is not set +# CONFIG_ARCH_X86 is not set +# CONFIG_ARCH_Z16 is not set +# CONFIG_ARCH_Z80 is not set +CONFIG_ARCH="arm" + +# +# ARM Options +# +# CONFIG_ARCH_CHIP_C5471 is not set +# CONFIG_ARCH_CHIP_CALYPSO is not set +# CONFIG_ARCH_CHIP_DM320 is not set +# CONFIG_ARCH_CHIP_IMX is not set +# CONFIG_ARCH_CHIP_KINETIS is not set +# CONFIG_ARCH_CHIP_LM is not set +# CONFIG_ARCH_CHIP_LPC17XX is not set +# CONFIG_ARCH_CHIP_LPC214X is not set +# CONFIG_ARCH_CHIP_LPC2378 is not set +# CONFIG_ARCH_CHIP_LPC31XX is not set +# CONFIG_ARCH_CHIP_LPC43XX is not set +# CONFIG_ARCH_CHIP_SAM3U is not set +CONFIG_ARCH_CHIP_STM32=y +# CONFIG_ARCH_CHIP_STR71X is not set +CONFIG_ARCH_CORTEXM4=y +CONFIG_ARCH_FAMILY="armv7-m" +CONFIG_ARCH_CHIP="stm32" +# CONFIG_ARMV7M_USEBASEPRI is not set +CONFIG_ARCH_HAVE_CMNVECTOR=y +# CONFIG_ARMV7M_CMNVECTOR is not set +# CONFIG_ARCH_FPU is not set +CONFIG_ARCH_HAVE_MPU=y +# CONFIG_ARMV7M_MPU is not set +CONFIG_BOARD_LOOPSPERMSEC=16717 +# CONFIG_ARCH_CALIBRATION is not set + +# +# ARMV7M Configuration Options +# +# CONFIG_ARMV7M_TOOLCHAIN_ATOLLIC is not set +# CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODEREDW is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set +CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y +# CONFIG_ARMV7M_TOOLCHAIN_DEVKITARM is not set +# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABI is not set +# CONFIG_ARMV7M_TOOLCHAIN_RAISONANCE is not set +# CONFIG_SERIAL_TERMIOS is not set + +# +# STM32 Configuration Options +# +# CONFIG_ARCH_CHIP_STM32F100C8 is not set +# CONFIG_ARCH_CHIP_STM32F100CB is not set +# CONFIG_ARCH_CHIP_STM32F100R8 is not set +# CONFIG_ARCH_CHIP_STM32F100RB is not set +# CONFIG_ARCH_CHIP_STM32F100RC is not set +# CONFIG_ARCH_CHIP_STM32F100RD is not set +# CONFIG_ARCH_CHIP_STM32F100RE is not set +# CONFIG_ARCH_CHIP_STM32F100V8 is not set +# CONFIG_ARCH_CHIP_STM32F100VB is not set +# CONFIG_ARCH_CHIP_STM32F100VC is not set +# CONFIG_ARCH_CHIP_STM32F100VD is not set +# CONFIG_ARCH_CHIP_STM32F100VE is not set +# CONFIG_ARCH_CHIP_STM32F103RET6 is not set +# CONFIG_ARCH_CHIP_STM32F103VCT6 is not set +# CONFIG_ARCH_CHIP_STM32F103VET6 is not set +# CONFIG_ARCH_CHIP_STM32F103ZET6 is not set +# CONFIG_ARCH_CHIP_STM32F105VBT7 is not set +# CONFIG_ARCH_CHIP_STM32F107VC is not set +# CONFIG_ARCH_CHIP_STM32F207IG is not set +# CONFIG_ARCH_CHIP_STM32F405RG is not set +# CONFIG_ARCH_CHIP_STM32F405VG is not set +# CONFIG_ARCH_CHIP_STM32F405ZG is not set +# CONFIG_ARCH_CHIP_STM32F407VE is not set +CONFIG_ARCH_CHIP_STM32F407VG=y +# CONFIG_ARCH_CHIP_STM32F407ZE is not set +# CONFIG_ARCH_CHIP_STM32F407ZG is not set +# CONFIG_ARCH_CHIP_STM32F407IE is not set +# CONFIG_ARCH_CHIP_STM32F407IG is not set +CONFIG_STM32_STM32F40XX=y +# CONFIG_STM32_DFU is not set + +# +# STM32 Peripheral Support +# +# CONFIG_STM32_ADC1 is not set +# CONFIG_STM32_ADC2 is not set +# CONFIG_STM32_ADC3 is not set +# CONFIG_STM32_BKPSRAM is not set +# CONFIG_STM32_CAN1 is not set +# CONFIG_STM32_CAN2 is not set +# CONFIG_STM32_CCMDATARAM is not set +# CONFIG_STM32_CRC is not set +# CONFIG_STM32_CRYP is not set +# CONFIG_STM32_DMA1 is not set +# CONFIG_STM32_DMA2 is not set +# CONFIG_STM32_DAC1 is not set +# CONFIG_STM32_DAC2 is not set +# CONFIG_STM32_DCMI is not set +# CONFIG_STM32_ETHMAC is not set +# CONFIG_STM32_FSMC is not set +# CONFIG_STM32_HASH is not set +# CONFIG_STM32_I2C1 is not set +# CONFIG_STM32_I2C2 is not set +# CONFIG_STM32_I2C3 is not set +# CONFIG_STM32_IWDG is not set +CONFIG_STM32_OTGFS=y +# CONFIG_STM32_OTGHS is not set +CONFIG_STM32_PWR=y +# CONFIG_STM32_RNG is not set +# CONFIG_STM32_SDIO is not set +CONFIG_STM32_SPI1=y +# CONFIG_STM32_SPI2 is not set +# CONFIG_STM32_SPI3 is not set +CONFIG_STM32_SYSCFG=y +# CONFIG_STM32_TIM1 is not set +# CONFIG_STM32_TIM2 is not set +# CONFIG_STM32_TIM3 is not set +# CONFIG_STM32_TIM4 is not set +# CONFIG_STM32_TIM5 is not set +# CONFIG_STM32_TIM6 is not set +# CONFIG_STM32_TIM7 is not set +# CONFIG_STM32_TIM8 is not set +# CONFIG_STM32_TIM9 is not set +# CONFIG_STM32_TIM10 is not set +# CONFIG_STM32_TIM11 is not set +# CONFIG_STM32_TIM12 is not set +# CONFIG_STM32_TIM13 is not set +# CONFIG_STM32_TIM14 is not set +# CONFIG_STM32_USART1 is not set +CONFIG_STM32_USART2=y +# CONFIG_STM32_USART3 is not set +# CONFIG_STM32_UART4 is not set +# CONFIG_STM32_UART5 is not set +# CONFIG_STM32_USART6 is not set +# CONFIG_STM32_WWDG is not set +CONFIG_STM32_SPI=y + +# +# Alternate Pin Mapping +# +# CONFIG_STM32_FLASH_PREFETCH is not set +# CONFIG_STM32_JTAG_DISABLE is not set +# CONFIG_STM32_JTAG_FULL_ENABLE is not set +# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set +CONFIG_STM32_JTAG_SW_ENABLE=y +# CONFIG_STM32_FORCEPOWER is not set +# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set +# CONFIG_STM32_CCMEXCLUDE is not set +CONFIG_STM32_USART=y + +# +# U[S]ART Configuration +# +# CONFIG_USART2_RS485 is not set +# CONFIG_STM32_USART_SINGLEWIRE is not set + +# +# SPI Configuration +# +# CONFIG_STM32_SPI_INTERRUPTS is not set +# CONFIG_STM32_SPI_DMA is not set + +# +# USB Host Configuration +# + +# +# External Memory Configuration +# + +# +# Architecture Options +# +# CONFIG_ARCH_NOINTC is not set +# CONFIG_ARCH_VECNOTIRQ is not set +# CONFIG_ARCH_DMA is not set +CONFIG_ARCH_IRQPRIO=y +# CONFIG_CUSTOM_STACK is not set +# CONFIG_ADDRENV is not set +CONFIG_ARCH_HAVE_VFORK=y +CONFIG_ARCH_STACKDUMP=y +# CONFIG_ENDIAN_BIG is not set +# CONFIG_ARCH_HAVE_RAMFUNCS is not set + +# +# Board Settings +# +CONFIG_DRAM_START=0x20000000 +CONFIG_DRAM_SIZE=114688 +CONFIG_ARCH_HAVE_INTERRUPTSTACK=y +CONFIG_ARCH_INTERRUPTSTACK=0 + +# +# Boot options +# +# CONFIG_BOOT_RUNFROMEXTSRAM is not set +CONFIG_BOOT_RUNFROMFLASH=y +# CONFIG_BOOT_RUNFROMISRAM is not set +# CONFIG_BOOT_RUNFROMSDRAM is not set +# CONFIG_BOOT_COPYTORAM is not set + +# +# Board Selection +# +CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y +# CONFIG_ARCH_BOARD_CUSTOM is not set +CONFIG_ARCH_BOARD="stm32f4discovery" + +# +# Common Board Options +# +CONFIG_ARCH_HAVE_LEDS=y +CONFIG_ARCH_LEDS=y +CONFIG_ARCH_HAVE_BUTTONS=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_HAVE_IRQBUTTONS=y +# CONFIG_ARCH_IRQBUTTONS is not set +CONFIG_NSH_MMCSDMINOR=0 + +# +# Board-Specific Options +# + +# +# RTOS Features +# +CONFIG_MSEC_PER_TICK=10 +CONFIG_RR_INTERVAL=200 +# CONFIG_SCHED_INSTRUMENTATION is not set +CONFIG_TASK_NAME_SIZE=0 +# CONFIG_SCHED_HAVE_PARENT is not set +# CONFIG_JULIAN_TIME is not set +CONFIG_START_YEAR=2013 +CONFIG_START_MONTH=1 +CONFIG_START_DAY=27 +CONFIG_DEV_CONSOLE=y +# CONFIG_MUTEX_TYPES is not set +# CONFIG_PRIORITY_INHERITANCE is not set +# CONFIG_FDCLONE_DISABLE is not set +# CONFIG_FDCLONE_STDIO is not set +CONFIG_SDCLONE_DISABLE=y +# CONFIG_SCHED_WORKQUEUE is not set +CONFIG_SCHED_WAITPID=y +# CONFIG_SCHED_STARTHOOK is not set +# CONFIG_SCHED_ATEXIT is not set +# CONFIG_SCHED_ONEXIT is not set +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_DISABLE_OS_API=y +# CONFIG_DISABLE_CLOCK is not set +# CONFIG_DISABLE_POSIX_TIMERS is not set +# CONFIG_DISABLE_PTHREAD is not set +# CONFIG_DISABLE_SIGNALS is not set +# CONFIG_DISABLE_MQUEUE is not set +# CONFIG_DISABLE_ENVIRON is not set + +# +# Signal Numbers +# +CONFIG_SIG_SIGUSR1=1 +CONFIG_SIG_SIGUSR2=2 +CONFIG_SIG_SIGALARM=3 +CONFIG_SIG_SIGCONDTIMEDOUT=16 + +# +# Sizes of configurable things (0 disables) +# +CONFIG_MAX_TASKS=16 +CONFIG_MAX_TASK_ARGS=4 +CONFIG_NPTHREAD_KEYS=4 +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NAME_MAX=32 +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_MQ_MAXMSGSIZE=32 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_PREALLOC_WDOGS=4 +CONFIG_PREALLOC_TIMERS=4 + +# +# Stack and heap information +# +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_USERMAIN_STACKSIZE=2048 +CONFIG_PTHREAD_STACK_MIN=256 +CONFIG_PTHREAD_STACK_DEFAULT=2048 + +# +# Device Drivers +# +CONFIG_DISABLE_POLL=y +CONFIG_DEV_NULL=y +# CONFIG_DEV_ZERO is not set +# CONFIG_LOOP is not set +# CONFIG_RAMDISK is not set +# CONFIG_CAN is not set +# CONFIG_PWM is not set +# CONFIG_I2C is not set +CONFIG_ARCH_HAVE_I2CRESET=y +CONFIG_SPI=y +# CONFIG_SPI_OWNBUS is not set +CONFIG_SPI_EXCHANGE=y +# CONFIG_SPI_CMDDATA is not set +# CONFIG_RTC is not set +# CONFIG_WATCHDOG is not set +# CONFIG_ANALOG is not set +# CONFIG_BCH is not set +# CONFIG_INPUT is not set +# CONFIG_LCD is not set +# CONFIG_MMCSD is not set +# CONFIG_MTD is not set +# CONFIG_PIPES is not set +# CONFIG_PM is not set +# CONFIG_POWER is not set +# CONFIG_SENSORS is not set +# CONFIG_SERCOMM_CONSOLE is not set +CONFIG_SERIAL=y +# CONFIG_DEV_LOWCONSOLE is not set +# CONFIG_16550_UART is not set +CONFIG_ARCH_HAVE_USART2=y +CONFIG_MCU_SERIAL=y +CONFIG_STANDARD_SERIAL=y +# CONFIG_USART2_SERIAL_CONSOLE is not set +CONFIG_NO_SERIAL_CONSOLE=y + +# +# USART2 Configuration +# +CONFIG_USART2_RXBUFSIZE=256 +CONFIG_USART2_TXBUFSIZE=256 +CONFIG_USART2_BAUD=115200 +CONFIG_USART2_BITS=8 +CONFIG_USART2_PARITY=0 +CONFIG_USART2_2STOP=0 +CONFIG_USBDEV=y + +# +# Device Controller Driver Options +# +# CONFIG_USBDEV_ISOCHRONOUS is not set +# CONFIG_USBDEV_DUALSPEED is not set +CONFIG_USBDEV_SELFPOWERED=y +# CONFIG_USBDEV_BUSPOWERED is not set +# CONFIG_USBDEV_DMA is not set +# CONFIG_USBDEV_TRACE is not set +# CONFIG_USBDEV_COMPOSITE is not set +# CONFIG_PL2303 is not set +CONFIG_CDCACM=y +CONFIG_CDCACM_CONSOLE=y +CONFIG_CDCACM_EP0MAXPACKET=64 +CONFIG_CDCACM_EPINTIN=2 +CONFIG_CDCACM_EPINTIN_FSSIZE=64 +CONFIG_CDCACM_EPINTIN_HSSIZE=64 +CONFIG_CDCACM_EPBULKOUT=0 +CONFIG_CDCACM_EPBULKOUT_FSSIZE=64 +CONFIG_CDCACM_EPBULKOUT_HSSIZE=512 +CONFIG_CDCACM_EPBULKIN=0 +CONFIG_CDCACM_EPBULKIN_FSSIZE=64 +CONFIG_CDCACM_EPBULKIN_HSSIZE=512 +CONFIG_CDCACM_NWRREQS=4 +CONFIG_CDCACM_NRDREQS=4 +CONFIG_CDCACM_RXBUFSIZE=256 +# CONFIG_CDCACM_TXBUFSIZE is not set +CONFIG_CDCACM_VENDORID=0x0525 +CONFIG_CDCACM_PRODUCTID=0xa4a7 +CONFIG_CDCACM_VENDORSTR="NuttX" +CONFIG_CDCACM_PRODUCTSTR="USBdev Serial" +# CONFIG_USBMSC is not set +# CONFIG_USBHOST is not set +# CONFIG_WIRELESS is not set + +# +# System Logging Device Options +# + +# +# System Logging +# +# CONFIG_RAMLOG is not set + +# +# Networking Support +# +# CONFIG_NET is not set + +# +# File Systems +# + +# +# File system configuration +# +# CONFIG_DISABLE_MOUNTPOINT is not set +# CONFIG_FS_RAMMAP is not set +# CONFIG_FS_FAT is not set +# CONFIG_FS_NXFFS is not set +# CONFIG_FS_ROMFS is not set +# CONFIG_FS_BINFS is not set + +# +# System Logging +# +CONFIG_SYSLOG=y +CONFIG_SYSLOG_CHAR=y +CONFIG_SYSLOG_DEVPATH="/dev/ttyS0" + +# +# Graphics Support +# +# CONFIG_NX is not set + +# +# Memory Management +# +# CONFIG_MM_SMALL is not set +CONFIG_MM_REGIONS=2 +# CONFIG_GRAN is not set + +# +# Binary Formats +# +# CONFIG_BINFMT_DISABLE is not set +# CONFIG_BINFMT_EXEPATH is not set +# CONFIG_NXFLAT is not set +# CONFIG_ELF is not set +CONFIG_BUILTIN=y +# CONFIG_PIC is not set +# CONFIG_SYMTAB_ORDEREDBYNAME is not set + +# +# Library Routines +# + +# +# Standard C Library Options +# +CONFIG_STDIO_BUFFER_SIZE=64 +CONFIG_STDIO_LINEBUFFER=y +CONFIG_NUNGET_CHARS=2 +CONFIG_LIB_HOMEDIR="/" +# CONFIG_LIBM is not set +# CONFIG_NOPRINTF_FIELDWIDTH is not set +# CONFIG_LIBC_FLOATINGPOINT is not set +# CONFIG_EOL_IS_CR is not set +# CONFIG_EOL_IS_LF is not set +# CONFIG_EOL_IS_BOTH_CRLF is not set +CONFIG_EOL_IS_EITHER_CRLF=y +# CONFIG_LIBC_EXECFUNCS is not set +# CONFIG_LIBC_STRERROR is not set +# CONFIG_LIBC_PERROR_STDOUT is not set +CONFIG_ARCH_LOWPUTC=y +CONFIG_LIB_SENDFILE_BUFSIZE=512 +# CONFIG_ARCH_ROMGETC is not set +# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set + +# +# Non-standard Helper Functions +# +# CONFIG_LIB_KBDCODEC is not set + +# +# Basic CXX Support +# +# CONFIG_C99_BOOL8 is not set +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +# CONFIG_CXX_NEWLONG is not set + +# +# uClibc++ Standard C++ Library +# +# CONFIG_UCLIBCXX is not set + +# +# Application Configuration +# + +# +# Built-In Applications +# +CONFIG_BUILTIN_PROXY_STACKSIZE=1024 + +# +# Examples +# +# CONFIG_EXAMPLES_BUTTONS is not set +# CONFIG_EXAMPLES_CAN is not set +# CONFIG_EXAMPLES_CDCACM is not set +# CONFIG_EXAMPLES_COMPOSITE is not set +# CONFIG_EXAMPLES_CXXTEST is not set +# CONFIG_EXAMPLES_DHCPD is not set +# CONFIG_EXAMPLES_ELF is not set +# CONFIG_EXAMPLES_FTPC is not set +# CONFIG_EXAMPLES_FTPD is not set +# CONFIG_EXAMPLES_HELLO is not set +# CONFIG_EXAMPLES_HELLOXX is not set +# CONFIG_EXAMPLES_JSON is not set +# CONFIG_EXAMPLES_HIDKBD is not set +# CONFIG_EXAMPLES_KEYPADTEST is not set +# CONFIG_EXAMPLES_IGMP is not set +# CONFIG_EXAMPLES_LCDRW is not set +# CONFIG_EXAMPLES_MM is not set +# CONFIG_EXAMPLES_MOUNT is not set +# CONFIG_EXAMPLES_MODBUS is not set +CONFIG_EXAMPLES_NSH=y +# CONFIG_EXAMPLES_NULL is not set +# CONFIG_EXAMPLES_NX is not set +# CONFIG_EXAMPLES_NXCONSOLE is not set +# CONFIG_EXAMPLES_NXFFS is not set +# CONFIG_EXAMPLES_NXFLAT is not set +# CONFIG_EXAMPLES_NXHELLO is not set +# CONFIG_EXAMPLES_NXIMAGE is not set +# CONFIG_EXAMPLES_NXLINES is not set +# CONFIG_EXAMPLES_NXTEXT is not set +# CONFIG_EXAMPLES_OSTEST is not set +# CONFIG_EXAMPLES_PASHELLO is not set +# CONFIG_EXAMPLES_PIPE is not set +# CONFIG_EXAMPLES_POSIXSPAWN is not set +# CONFIG_EXAMPLES_QENCODER is not set +# CONFIG_EXAMPLES_RGMP is not set +# CONFIG_EXAMPLES_ROMFS is not set +# CONFIG_EXAMPLES_SENDMAIL is not set +# CONFIG_EXAMPLES_SERLOOP is not set +# CONFIG_EXAMPLES_TELNETD is not set +# CONFIG_EXAMPLES_THTTPD is not set +# CONFIG_EXAMPLES_TIFF is not set +# CONFIG_EXAMPLES_TOUCHSCREEN is not set +# CONFIG_EXAMPLES_UDP is not set +# CONFIG_EXAMPLES_UIP is not set +# CONFIG_EXAMPLES_USBSERIAL is not set +# CONFIG_EXAMPLES_USBMSC is not set +# CONFIG_EXAMPLES_USBTERM is not set +# CONFIG_EXAMPLES_WATCHDOG is not set + +# +# Interpreters +# + +# +# Interpreters +# +# CONFIG_INTERPRETERS_FICL is not set +# CONFIG_INTERPRETERS_PCODE is not set + +# +# Network Utilities +# + +# +# Networking Utilities +# +# CONFIG_NETUTILS_CODECS is not set +# CONFIG_NETUTILS_DHCPC is not set +# CONFIG_NETUTILS_DHCPD is not set +# CONFIG_NETUTILS_FTPC is not set +# CONFIG_NETUTILS_FTPD is not set +# CONFIG_NETUTILS_JSON is not set +# CONFIG_NETUTILS_RESOLV is not set +# CONFIG_NETUTILS_SMTP is not set +# CONFIG_NETUTILS_TELNETD is not set +# CONFIG_NETUTILS_TFTPC is not set +# CONFIG_NETUTILS_THTTPD is not set +# CONFIG_NETUTILS_UIPLIB is not set +# CONFIG_NETUTILS_WEBCLIENT is not set + +# +# ModBus +# + +# +# FreeModbus +# +# CONFIG_MODBUS is not set + +# +# NSH Library +# +CONFIG_NSH_LIBRARY=y +CONFIG_NSH_BUILTIN_APPS=y + +# +# Disable Individual commands +# +# CONFIG_NSH_DISABLE_CAT is not set +# CONFIG_NSH_DISABLE_CD is not set +# CONFIG_NSH_DISABLE_CP is not set +# CONFIG_NSH_DISABLE_DD is not set +# CONFIG_NSH_DISABLE_ECHO is not set +# CONFIG_NSH_DISABLE_EXEC is not set +# CONFIG_NSH_DISABLE_EXIT is not set +# CONFIG_NSH_DISABLE_FREE is not set +# CONFIG_NSH_DISABLE_GET is not set +# CONFIG_NSH_DISABLE_HELP is not set +# CONFIG_NSH_DISABLE_HEXDUMP is not set +# CONFIG_NSH_DISABLE_IFCONFIG is not set +# CONFIG_NSH_DISABLE_KILL is not set +# CONFIG_NSH_DISABLE_LOSETUP is not set +# CONFIG_NSH_DISABLE_LS is not set +# CONFIG_NSH_DISABLE_MB is not set +# CONFIG_NSH_DISABLE_MKDIR is not set +# CONFIG_NSH_DISABLE_MKFATFS is not set +# CONFIG_NSH_DISABLE_MKFIFO is not set +# CONFIG_NSH_DISABLE_MKRD is not set +# CONFIG_NSH_DISABLE_MH is not set +# CONFIG_NSH_DISABLE_MOUNT is not set +# CONFIG_NSH_DISABLE_MW is not set +# CONFIG_NSH_DISABLE_NSFMOUNT is not set +# CONFIG_NSH_DISABLE_PS is not set +# CONFIG_NSH_DISABLE_PING is not set +# CONFIG_NSH_DISABLE_PUT is not set +# CONFIG_NSH_DISABLE_PWD is not set +# CONFIG_NSH_DISABLE_RM is not set +# CONFIG_NSH_DISABLE_RMDIR is not set +# CONFIG_NSH_DISABLE_SET is not set +# CONFIG_NSH_DISABLE_SH is not set +# CONFIG_NSH_DISABLE_SLEEP is not set +# CONFIG_NSH_DISABLE_TEST is not set +# CONFIG_NSH_DISABLE_UMOUNT is not set +# CONFIG_NSH_DISABLE_UNSET is not set +# CONFIG_NSH_DISABLE_USLEEP is not set +# CONFIG_NSH_DISABLE_WGET is not set +# CONFIG_NSH_DISABLE_XD is not set +CONFIG_NSH_CODECS_BUFSIZE=128 +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_NESTDEPTH=3 +# CONFIG_NSH_DISABLESCRIPT is not set +# CONFIG_NSH_DISABLEBG is not set +CONFIG_NSH_CONSOLE=y +# CONFIG_NSH_USBCONSOLE is not set +# CONFIG_NSH_CONDEV is not set +CONFIG_NSH_ARCHINIT=y + +# +# NxWidgets/NxWM +# + +# +# System NSH Add-Ons +# + +# +# Custom Free Memory Command +# +# CONFIG_SYSTEM_FREE is not set + +# +# I2C tool +# + +# +# FLASH Program Installation +# +# CONFIG_SYSTEM_INSTALL is not set + +# +# readline() +# +CONFIG_SYSTEM_READLINE=y +CONFIG_READLINE_ECHO=y + +# +# Power Off +# +# CONFIG_SYSTEM_POWEROFF is not set + +# +# RAMTRON +# +# CONFIG_SYSTEM_RAMTRON is not set + +# +# SD Card +# +# CONFIG_SYSTEM_SDCARD is not set + +# +# Sysinfo +# +# CONFIG_SYSTEM_SYSINFO is not set diff --git a/nuttx/configs/stm32f4discovery/usbnsh/setenv.sh b/nuttx/configs/stm32f4discovery/usbnsh/setenv.sh new file mode 100755 index 000000000..a56f85d35 --- /dev/null +++ b/nuttx/configs/stm32f4discovery/usbnsh/setenv.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# configs/stm32f4discovery/usbnsh/setenv.sh +# +# Copyright (C) 2013 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +if [ "$_" = "$0" ] ; then + echo "You must source this script, not run it!" 1>&2 + exit 1 +fi + +WD=`pwd` +if [ ! -x "setenv.sh" ]; then + echo "This script must be executed from the top-level NuttX build directory" + exit 1 +fi + +if [ -z "${PATH_ORIG}" ]; then + export PATH_ORIG="${PATH}" +fi + +# This is the Cygwin path to the location where I installed the RIDE +# toolchain under windows. You will also have to edit this if you install +# the RIDE toolchain in any other location +#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Raisonance/Ride/arm-gcc/bin" + +# This is the Cygwin path to the location where I installed the CodeSourcery +# toolchain under windows. You will also have to edit this if you install +# the CodeSourcery toolchain in any other location +export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin" + +# These are the Cygwin paths to the locations where I installed the Atollic +# toolchain under windows. You will also have to edit this if you install +# the Atollic toolchain in any other location. /usr/bin is added before +# the Atollic bin path because there is are binaries named gcc.exe and g++.exe +# at those locations as well. +#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin" +#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin" + +# This is the Cygwin path to the location where I build the buildroot +# toolchain. +#export TOOLCHAIN_BIN="${WD}/../misc/buildroot/build_arm_nofpu/staging_dir/bin" + +# Add the path to the toolchain to the PATH varialble +export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}" + +echo "PATH : ${PATH}" diff --git a/nuttx/drivers/usbdev/Kconfig b/nuttx/drivers/usbdev/Kconfig index 70c7a04f0..6fa4124be 100644 --- a/nuttx/drivers/usbdev/Kconfig +++ b/nuttx/drivers/usbdev/Kconfig @@ -154,6 +154,14 @@ menuconfig PL2303 This logic emulates the Prolific PL2303 serial/USB converter if PL2303 + +config PL2303_CONSOLE + bool "PL2303 console device" + default n + ---help--- + Register the USB device as /dev/console so that is will be used + as the console device. + config PL2303_EPINTIN int "Logical endpoint numbers" default 1 @@ -218,8 +226,16 @@ menuconfig CDCACM Enables USB Modem (CDC ACM) support if CDCACM + +config CDCACM_CONSOLE + bool "CDC/ACM console device" + default n + ---help--- + Register the USB device as /dev/console so that is will be used + as the console device. + config CDCACM_COMPOSITE - bool "CDCACM composite support" + bool "CDC/ACM composite support" default n depends on USBDEV_COMPOSITE ---help--- diff --git a/nuttx/fs/Kconfig b/nuttx/fs/Kconfig index ab03a2b64..e6647f516 100644 --- a/nuttx/fs/Kconfig +++ b/nuttx/fs/Kconfig @@ -24,23 +24,26 @@ config SYSLOG ---help--- Enables generic system logging features. -config SYSLOG_DEVPATH - string "System log device" - default "/dev/syslog" - depends on SYSLOG - ---help--- - The full path to the system logging device. For the RAMLOG SYSLOG device, - this is normally "/dev/ramlog". For character SYSLOG devices, it should be - some other existing character device (or file) supported by the configuration - (such as "/dev/ttyS1")/ +if SYSLOG config SYSLOG_CHAR bool "System log character device support" default y - depends on SYSLOG ---help--- Enable the generic character device for the SYSLOG. The full path to the SYSLOG device is provided by SYSLOG_DEVPATH. A valid character device (or file) must exist at this path. It will by opened by syslog_initialize. Do not enable more than one SYSLOG device. + +config SYSLOG_DEVPATH + string "System log device" + default "/dev/syslog" + depends on SYSLOG_CHAR + ---help--- + The full path to the system logging device. For the RAMLOG SYSLOG device, + this is normally "/dev/ramlog". For character SYSLOG devices, it should be + some other existing character device (or file) supported by the configuration + (such as "/dev/ttyS1")/ + +endif diff --git a/nuttx/fs/fs_syslog.c b/nuttx/fs/fs_syslog.c index 1d569082a..f348bdb03 100644 --- a/nuttx/fs/fs_syslog.c +++ b/nuttx/fs/fs_syslog.c @@ -265,7 +265,7 @@ int syslog_initialize(void) { /* The inode was not found. In this case, we will attempt to re-open * the device repeatedly. The assumption is that the device path is - * value but that the driver has not yet been registered. + * valid but that the driver has not yet been registered. */ g_sysdev.sl_state = SYSLOG_REOPEN; diff --git a/nuttx/libc/stdio/lib_lowprintf.c b/nuttx/libc/stdio/lib_lowprintf.c index f7d4ffe2f..667fad7be 100644 --- a/nuttx/libc/stdio/lib_lowprintf.c +++ b/nuttx/libc/stdio/lib_lowprintf.c @@ -38,8 +38,10 @@ ****************************************************************************/ #include + #include #include + #include "lib_internal.h" /* This interface can only be used from within the kernel */ diff --git a/nuttx/libc/stdio/lib_rawprintf.c b/nuttx/libc/stdio/lib_rawprintf.c index 98bbbea05..d8deba12d 100644 --- a/nuttx/libc/stdio/lib_rawprintf.c +++ b/nuttx/libc/stdio/lib_rawprintf.c @@ -37,8 +37,11 @@ * Included Files ****************************************************************************/ +#include + #include #include + #include "lib_internal.h" /**************************************************************************** diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c index 5e6eaa858..c60edc495 100644 --- a/nuttx/sched/os_start.c +++ b/nuttx/sched/os_start.c @@ -327,6 +327,12 @@ void os_start(void) } #endif + /* Allocate the IDLE group and suppress child status. */ + +#ifdef HAVE_TASK_GROUP + (void)group_allocate(&g_idletcb); +#endif + /* Initialize the interrupt handling subsystem (if included) */ #ifdef CONFIG_HAVE_WEAKFUNCTIONS @@ -439,20 +445,21 @@ void os_start(void) lib_initialize(); } - /* Create the IDLE group and suppress child status */ - -#ifdef HAVE_TASK_GROUP - (void)group_allocate(&g_idletcb); - (void)group_initialize(&g_idletcb); - g_idletcb.group->tg_flags = GROUP_FLAG_NOCLDWAIT; -#endif - /* Create stdout, stderr, stdin on the IDLE task. These will be * inherited by all of the threads created by the IDLE task. */ (void)group_setupidlefiles(&g_idletcb); + /* Complete initialization of the IDLE group. Suppress retention + * of child status in the IDLE group. + */ + +#ifdef HAVE_TASK_GROUP + (void)group_initialize(&g_idletcb); + g_idletcb.group->tg_flags = GROUP_FLAG_NOCLDWAIT; +#endif + /* Create initial tasks and bring-up the system */ (void)os_bringup(); diff --git a/nuttx/sched/task_vfork.c b/nuttx/sched/task_vfork.c index 5b42a1e55..ac86ddc56 100644 --- a/nuttx/sched/task_vfork.c +++ b/nuttx/sched/task_vfork.c @@ -39,6 +39,7 @@ #include +#include #include #include #include -- cgit v1.2.3 From d3e4a31ac5b12f763cf1e04448437ae646d6c121 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 27 Jan 2013 20:05:29 +0000 Subject: configs/stm32f4discovery/nsh converted to use kconfig-frontends git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5573 42af7a65-404d-4744-a932-0658087f49c3 --- apps/builtin/exec_builtin.c | 2 +- nuttx/ChangeLog | 2 + nuttx/configs/stm32f4discovery/README.txt | 59 +- nuttx/configs/stm32f4discovery/nsh/appconfig | 67 -- nuttx/configs/stm32f4discovery/nsh/defconfig | 1161 +++++++++++++------------- nuttx/configs/stm32f4discovery/pm/defconfig | 2 +- 6 files changed, 616 insertions(+), 677 deletions(-) delete mode 100644 nuttx/configs/stm32f4discovery/nsh/appconfig diff --git a/apps/builtin/exec_builtin.c b/apps/builtin/exec_builtin.c index 60e8b742d..5d3a1c08a 100644 --- a/apps/builtin/exec_builtin.c +++ b/apps/builtin/exec_builtin.c @@ -309,7 +309,7 @@ static inline int builtin_startproxy(int index, FAR const char **argv, { struct sched_param param; pid_t proxy; - int errcode; + int errcode = OK; #ifdef CONFIG_SCHED_WAITPID int status; #endif diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 76ed2b603..4fc75c084 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4048,4 +4048,6 @@ * sched/os_start.c: Fix ordering of group initialization. * configs/stm32f4discovery/usbnsh: Add an NSH STM32F4Discovery configuration that uses USB CDC/ACM for the NSH console. + * configs/stm32f4discovery/nsh: Converted to use the kconfig-frontends + tools. diff --git a/nuttx/configs/stm32f4discovery/README.txt b/nuttx/configs/stm32f4discovery/README.txt index 0e295c429..207ee6cde 100644 --- a/nuttx/configs/stm32f4discovery/README.txt +++ b/nuttx/configs/stm32f4discovery/README.txt @@ -1165,14 +1165,30 @@ Where is one of the following: nsh: --- Configures the NuttShell (nsh) located at apps/examples/nsh. The - Configuration enables both the serial and telnet NSH interfaces. + Configuration enables the serial interfaces on UART2. Support for + builtin applications is enabled, but in the base configuration no + builtin applications are selected (see NOTES below). - Default toolchain: + NOTES: + + 1. This configuration uses the mconf-based configuration tool. To + change this configuration using that tool, you should: - CONFIG_STM32_CODESOURCERYL=y : CodeSourcery under Linux / Mac OS X + a. Build and install the kconfig-mconf tool. See nuttx/README.txt + and misc/tools/ - NOTES: - 1. This example supports the PWM test (apps/examples/pwm) but this must + b. Execute 'make menuconfig' in nuttx/ in order to start the + reconfiguration process. + + 2. By default, this configuration uses the CodeSourcery toolchain + for Windows and builds under Cygwin (or probably MSYS). That + can easily be reconfigured, of course. + + CONFIG_HOST_WINDOWS=y : Builds under Windows + CONFIG_WINDOWS_CYGWIN=y : Using Cygwin + CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery for Windows + + 3. This example supports the PWM test (apps/examples/pwm) but this must be manually enabled by selecting: CONFIG_PWM=y : Enable the generic PWM infrastructure @@ -1185,27 +1201,28 @@ Where is one of the following: CONFIG_DEBUG_PWM - 2. This example supports the Quadrature Encode test (apps/examples/qencoder) + 5. This example supports the Quadrature Encode test (apps/examples/qencoder) but this must be manually enabled by selecting: - CONFIG_QENCODER=y : Enable the generic Quadrature Encoder infrastructure - CONFIG_STM32_TIM8=y : Enable TIM8 - CONFIG_STM32_TIM2=n : (Or optionally TIM2) - CONFIG_STM32_TIM8_QE=y : Use TIM8 as the quadrature encoder - CONFIG_STM32_TIM2_QE=y : (Or optionally TIM2) + CONFIG_EXAMPLES_QENCODER=y : Enable the apps/examples/qencoder + CONFIG_SENSORS=y : Enable support for sensors + CONFIG_QENCODER=y : Enable the generic Quadrature Encoder infrastructure + CONFIG_STM32_TIM8=y : Enable TIM8 + CONFIG_STM32_TIM2=n : (Or optionally TIM2) + CONFIG_STM32_TIM8_QE=y : Use TIM8 as the quadrature encoder + CONFIG_STM32_TIM2_QE=y : (Or optionally TIM2) - See also apps/examples/README.txt - - Special PWM-only debug options: + See also apps/examples/README.tx. Special PWM-only debug options: CONFIG_DEBUG_QENCODER - 3. This example supports the watchdog timer test (apps/examples/watchdog) + 6. This example supports the watchdog timer test (apps/examples/watchdog) but this must be manually enabled by selecting: - CONFIG_WATCHDOG=y : Enables watchdog timer driver support - CONFIG_STM32_WWDG=y : Enables the WWDG timer facility, OR - CONFIG_STM32_IWDG=y : Enables the IWDG timer facility (but not both) + CONFIG_EXAMPLES_WATCHDOG=y : Enable the apps/examples/watchdog + CONFIG_WATCHDOG=y : Enables watchdog timer driver support + CONFIG_STM32_WWDG=y : Enables the WWDG timer facility, OR + CONFIG_STM32_IWDG=y : Enables the IWDG timer facility (but not both) The WWDG watchdog is driven off the (fast) 42MHz PCLK1 and, as result, has a maximum timeout value of 49 milliseconds. for WWDG watchdog, you @@ -1216,14 +1233,14 @@ Where is one of the following: The IWDG timer has a range of about 35 seconds and should not be an issue. - 4. USB Support (CDC/ACM device) + 7. USB Support (CDC/ACM device) CONFIG_STM32_OTGFS=y : STM32 OTG FS support CONFIG_USBDEV=y : USB device support must be enabled CONFIG_CDCACM=y : The CDC/ACM driver must be built CONFIG_NSH_BUILTIN_APPS=y : NSH built-in application support must be enabled - 5. Using the USB console. + 8. Using the USB console. The STM32F4Discovery NSH configuration can be set up to use a USB CDC/ACM (or PL2303) USB console. The normal way that you would configure the @@ -1268,7 +1285,7 @@ Where is one of the following: you can still use certain kinds of debug output (see include/debug.h, all of the interfaces based on lib_lowprintf will work in this configuration). - 6. USB OTG FS Host Support. The following changes will enable support for + 9. USB OTG FS Host Support. The following changes will enable support for a USB host on the STM32F4Discovery, including support for a mass storage class driver: diff --git a/nuttx/configs/stm32f4discovery/nsh/appconfig b/nuttx/configs/stm32f4discovery/nsh/appconfig deleted file mode 100644 index 097948c87..000000000 --- a/nuttx/configs/stm32f4discovery/nsh/appconfig +++ /dev/null @@ -1,67 +0,0 @@ -############################################################################ -# configs/stm32f4discovery/nsh/appconfig -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -# Path to example in apps/examples containing the user_start entry point - -CONFIGURED_APPS += examples/nsh - -# The NSH application library - -CONFIGURED_APPS += system/readline -CONFIGURED_APPS += nshlib - -# Applications configured as an NX built-in commands - -ifeq ($(CONFIG_ADC),y) -CONFIGURED_APPS += examples/adc -endif - -ifeq ($(CONFIG_PWM),y) -CONFIGURED_APPS += examples/pwm -endif - -ifeq ($(CONFIG_QENCODER),y) -CONFIGURED_APPS += examples/qencoder -endif - -ifeq ($(CONFIG_USBDEV),y) -ifeq ($(CONFIG_CDCACM),y) -CONFIGURED_APPS += examples/cdcacm -endif -endif - -ifeq ($(CONFIG_WATCHDOG),y) -CONFIGURED_APPS += examples/watchdog -endif diff --git a/nuttx/configs/stm32f4discovery/nsh/defconfig b/nuttx/configs/stm32f4discovery/nsh/defconfig index 3ec117055..ea97dfeff 100644 --- a/nuttx/configs/stm32f4discovery/nsh/defconfig +++ b/nuttx/configs/stm32f4discovery/nsh/defconfig @@ -1,713 +1,700 @@ -############################################################################ -# configs/stm32f4discovery/nsh/defconfig -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ -# -# Architecture Selection # -CONFIG_ARCH="arm" -CONFIG_ARCH_ARM=y -CONFIG_ARCH_CORTEXM4=y -CONFIG_ARCH_CHIP="stm32" -CONFIG_ARCH_CHIP_STM32F407VG=y -CONFIG_ARCH_BOARD="stm32f4discovery" -CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y -CONFIG_BOARD_LOOPSPERMSEC=16717 -CONFIG_DRAM_SIZE=114688 -CONFIG_DRAM_START=0x20000000 -CONFIG_ARCH_IRQPRIO=y -CONFIG_ARCH_FPU=n -CONFIG_ARCH_INTERRUPTSTACK=0 -CONFIG_ARCH_STACKDUMP=y -CONFIG_ARCH_BOOTLOADER=n -CONFIG_ARCH_LEDS=y -CONFIG_ARCH_BUTTONS=y -CONFIG_ARCH_CALIBRATION=n -CONFIG_ARCH_DMA=n +# Automatically generated file; DO NOT EDIT. +# Nuttx/ Configuration +# +CONFIG_NUTTX_NEWCONFIG=y # -# Identify toolchain and linker options +# Build Setup # -CONFIG_STM32_CODESOURCERYW=n -CONFIG_STM32_CODESOURCERYL=y -CONFIG_STM32_ATOLLIC_LITE=n -CONFIG_STM32_ATOLLIC_PRO=n -CONFIG_STM32_DEVKITARM=n -CONFIG_STM32_RAISONANCE=n -CONFIG_STM32_BUILDROOT=n +# CONFIG_EXPERIMENTAL is not set +# CONFIG_HOST_LINUX is not set +# CONFIG_HOST_OSX is not set +CONFIG_HOST_WINDOWS=y +# CONFIG_HOST_OTHER is not set +# CONFIG_WINDOWS_NATIVE is not set +CONFIG_WINDOWS_CYGWIN=y +# CONFIG_WINDOWS_MSYS is not set +# CONFIG_WINDOWS_OTHER is not set # -# JTAG Enable settings (by default only SW-DP is enabled): +# Build Configuration # -CONFIG_STM32_DFU=n -CONFIG_STM32_JTAG_FULL_ENABLE=n -CONFIG_STM32_JTAG_NOJNTRST_ENABLE=n -CONFIG_STM32_JTAG_SW_ENABLE=y +# CONFIG_APPS_DIR="../apps" +# CONFIG_BUILD_2PASS is not set # -# Individual subsystems can be enabled: -# -# AHB1: -CONFIG_STM32_CRC=n -CONFIG_STM32_BKPSRAM=n -CONFIG_STM32_CCMDATARAM=n -CONFIG_STM32_DMA1=n -CONFIG_STM32_DMA2=n -CONFIG_STM32_ETHMAC=n -CONFIG_STM32_OTGHS=n -# AHB2: -CONFIG_STM32_DCMI=n -CONFIG_STM32_CRYP=n -CONFIG_STM32_HASH=n -CONFIG_STM32_RNG=n +# Binary Output Formats +# +# CONFIG_RRLOAD_BINARY is not set +CONFIG_INTELHEX_BINARY=y +# CONFIG_MOTOROLA_SREC is not set +CONFIG_RAW_BINARY=y + +# +# Customize Header Files +# +# CONFIG_ARCH_STDBOOL_H is not set +# CONFIG_ARCH_MATH_H is not set +# CONFIG_ARCH_FLOAT_H is not set +# CONFIG_ARCH_STDARG_H is not set + +# +# Debug Options +# +# CONFIG_DEBUG is not set +# CONFIG_DEBUG_SYMBOLS is not set + +# +# System Type +# +# CONFIG_ARCH_8051 is not set +CONFIG_ARCH_ARM=y +# CONFIG_ARCH_AVR is not set +# CONFIG_ARCH_HC is not set +# CONFIG_ARCH_MIPS is not set +# CONFIG_ARCH_RGMP is not set +# CONFIG_ARCH_SH is not set +# CONFIG_ARCH_SIM is not set +# CONFIG_ARCH_X86 is not set +# CONFIG_ARCH_Z16 is not set +# CONFIG_ARCH_Z80 is not set +CONFIG_ARCH="arm" + +# +# ARM Options +# +# CONFIG_ARCH_CHIP_C5471 is not set +# CONFIG_ARCH_CHIP_CALYPSO is not set +# CONFIG_ARCH_CHIP_DM320 is not set +# CONFIG_ARCH_CHIP_IMX is not set +# CONFIG_ARCH_CHIP_KINETIS is not set +# CONFIG_ARCH_CHIP_LM is not set +# CONFIG_ARCH_CHIP_LPC17XX is not set +# CONFIG_ARCH_CHIP_LPC214X is not set +# CONFIG_ARCH_CHIP_LPC2378 is not set +# CONFIG_ARCH_CHIP_LPC31XX is not set +# CONFIG_ARCH_CHIP_LPC43XX is not set +# CONFIG_ARCH_CHIP_SAM3U is not set +CONFIG_ARCH_CHIP_STM32=y +# CONFIG_ARCH_CHIP_STR71X is not set +CONFIG_ARCH_CORTEXM4=y +CONFIG_ARCH_FAMILY="armv7-m" +CONFIG_ARCH_CHIP="stm32" +# CONFIG_ARMV7M_USEBASEPRI is not set +CONFIG_ARCH_HAVE_CMNVECTOR=y +# CONFIG_ARMV7M_CMNVECTOR is not set +# CONFIG_ARCH_FPU is not set +CONFIG_ARCH_HAVE_MPU=y +# CONFIG_ARMV7M_MPU is not set +CONFIG_BOARD_LOOPSPERMSEC=16717 +# CONFIG_ARCH_CALIBRATION is not set + +# +# ARMV7M Configuration Options +# +# CONFIG_ARMV7M_TOOLCHAIN_ATOLLIC is not set +# CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODEREDW is not set +CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y +# CONFIG_ARMV7M_TOOLCHAIN_DEVKITARM is not set +# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABI is not set +# CONFIG_ARMV7M_TOOLCHAIN_RAISONANCE is not set +# CONFIG_SERIAL_TERMIOS is not set + +# +# STM32 Configuration Options +# +# CONFIG_ARCH_CHIP_STM32F100C8 is not set +# CONFIG_ARCH_CHIP_STM32F100CB is not set +# CONFIG_ARCH_CHIP_STM32F100R8 is not set +# CONFIG_ARCH_CHIP_STM32F100RB is not set +# CONFIG_ARCH_CHIP_STM32F100RC is not set +# CONFIG_ARCH_CHIP_STM32F100RD is not set +# CONFIG_ARCH_CHIP_STM32F100RE is not set +# CONFIG_ARCH_CHIP_STM32F100V8 is not set +# CONFIG_ARCH_CHIP_STM32F100VB is not set +# CONFIG_ARCH_CHIP_STM32F100VC is not set +# CONFIG_ARCH_CHIP_STM32F100VD is not set +# CONFIG_ARCH_CHIP_STM32F100VE is not set +# CONFIG_ARCH_CHIP_STM32F103RET6 is not set +# CONFIG_ARCH_CHIP_STM32F103VCT6 is not set +# CONFIG_ARCH_CHIP_STM32F103VET6 is not set +# CONFIG_ARCH_CHIP_STM32F103ZET6 is not set +# CONFIG_ARCH_CHIP_STM32F105VBT7 is not set +# CONFIG_ARCH_CHIP_STM32F107VC is not set +# CONFIG_ARCH_CHIP_STM32F207IG is not set +# CONFIG_ARCH_CHIP_STM32F405RG is not set +# CONFIG_ARCH_CHIP_STM32F405VG is not set +# CONFIG_ARCH_CHIP_STM32F405ZG is not set +# CONFIG_ARCH_CHIP_STM32F407VE is not set +CONFIG_ARCH_CHIP_STM32F407VG=y +# CONFIG_ARCH_CHIP_STM32F407ZE is not set +# CONFIG_ARCH_CHIP_STM32F407ZG is not set +# CONFIG_ARCH_CHIP_STM32F407IE is not set +# CONFIG_ARCH_CHIP_STM32F407IG is not set +CONFIG_STM32_STM32F40XX=y +# CONFIG_STM32_DFU is not set + +# +# STM32 Peripheral Support +# +# CONFIG_STM32_ADC1 is not set +# CONFIG_STM32_ADC2 is not set +# CONFIG_STM32_ADC3 is not set +# CONFIG_STM32_BKPSRAM is not set +# CONFIG_STM32_CAN1 is not set +# CONFIG_STM32_CAN2 is not set +# CONFIG_STM32_CCMDATARAM is not set +# CONFIG_STM32_CRC is not set +# CONFIG_STM32_CRYP is not set +# CONFIG_STM32_DMA1 is not set +# CONFIG_STM32_DMA2 is not set +# CONFIG_STM32_DAC1 is not set +# CONFIG_STM32_DAC2 is not set +# CONFIG_STM32_DCMI is not set +# CONFIG_STM32_ETHMAC is not set +# CONFIG_STM32_FSMC is not set +# CONFIG_STM32_HASH is not set +# CONFIG_STM32_I2C1 is not set +# CONFIG_STM32_I2C2 is not set +# CONFIG_STM32_I2C3 is not set +# CONFIG_STM32_IWDG is not set CONFIG_STM32_OTGFS=y -# AHB3: -CONFIG_STM32_FSMC=n -# APB1: -CONFIG_STM32_TIM2=n -CONFIG_STM32_TIM3=n -CONFIG_STM32_TIM4=n -CONFIG_STM32_TIM5=n -CONFIG_STM32_TIM6=n -CONFIG_STM32_TIM7=n -CONFIG_STM32_TIM12=n -CONFIG_STM32_TIM13=n -CONFIG_STM32_TIM14=n -CONFIG_STM32_WWDG=n -CONFIG_STM32_IWDG=n -CONFIG_STM32_SPI2=n -CONFIG_STM32_SPI3=n -CONFIG_STM32_USART2=y -CONFIG_STM32_USART3=n -CONFIG_STM32_UART4=n -CONFIG_STM32_UART5=n -CONFIG_STM32_I2C1=n -CONFIG_STM32_I2C2=n -CONFIG_STM32_I2C3=n -CONFIG_STM32_CAN1=n -CONFIG_STM32_CAN2=n -CONFIG_STM32_DAC=n +# CONFIG_STM32_OTGHS is not set CONFIG_STM32_PWR=y -# APB2: -CONFIG_STM32_TIM1=n -CONFIG_STM32_TIM8=n -CONFIG_STM32_USART1=n -CONFIG_STM32_USART6=n -CONFIG_STM32_ADC1=n -CONFIG_STM32_ADC2=n -CONFIG_STM32_ADC3=n -CONFIG_STM32_SDIO=n +# CONFIG_STM32_RNG is not set +# CONFIG_STM32_SDIO is not set CONFIG_STM32_SPI1=y +# CONFIG_STM32_SPI2 is not set +# CONFIG_STM32_SPI3 is not set CONFIG_STM32_SYSCFG=y -CONFIG_STM32_TIM9=n -CONFIG_STM32_TIM10=n -CONFIG_STM32_TIM11=n +# CONFIG_STM32_TIM1 is not set +# CONFIG_STM32_TIM2 is not set +# CONFIG_STM32_TIM3 is not set +# CONFIG_STM32_TIM4 is not set +# CONFIG_STM32_TIM5 is not set +# CONFIG_STM32_TIM6 is not set +# CONFIG_STM32_TIM7 is not set +# CONFIG_STM32_TIM8 is not set +# CONFIG_STM32_TIM9 is not set +# CONFIG_STM32_TIM10 is not set +# CONFIG_STM32_TIM11 is not set +# CONFIG_STM32_TIM12 is not set +# CONFIG_STM32_TIM13 is not set +# CONFIG_STM32_TIM14 is not set +# CONFIG_STM32_USART1 is not set +CONFIG_STM32_USART2=y +# CONFIG_STM32_USART3 is not set +# CONFIG_STM32_UART4 is not set +# CONFIG_STM32_UART5 is not set +# CONFIG_STM32_USART6 is not set +# CONFIG_STM32_WWDG is not set +CONFIG_STM32_SPI=y # -# STM32F40xxx specific serial device driver settings +# Alternate Pin Mapping # -CONFIG_USART1_SERIAL_CONSOLE=n -CONFIG_USART2_SERIAL_CONSOLE=y -CONFIG_USART3_SERIAL_CONSOLE=n -CONFIG_UART4_SERIAL_CONSOLE=n -CONFIG_UART5_SERIAL_CONSOLE=n - -CONFIG_USART1_TXBUFSIZE=128 -CONFIG_USART2_TXBUFSIZE=128 -CONFIG_USART3_TXBUFSIZE=128 -CONFIG_UART4_TXBUFSIZE=128 -CONFIG_UART5_TXBUFSIZE=128 - -CONFIG_USART1_RXBUFSIZE=128 -CONFIG_USART2_RXBUFSIZE=128 -CONFIG_USART3_RXBUFSIZE=128 -CONFIG_UART4_RXBUFSIZE=128 -CONFIG_UART5_RXBUFSIZE=128 - -CONFIG_USART1_BAUD=115200 -CONFIG_USART2_BAUD=115200 -CONFIG_USART3_BAUD=115200 -CONFIG_UART4_BAUD=115200 -CONFIG_UART5_BAUD=115200 +# CONFIG_STM32_FLASH_PREFETCH is not set +# CONFIG_STM32_JTAG_DISABLE is not set +# CONFIG_STM32_JTAG_FULL_ENABLE is not set +# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set +CONFIG_STM32_JTAG_SW_ENABLE=y +# CONFIG_STM32_FORCEPOWER is not set +# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set +# CONFIG_STM32_CCMEXCLUDE is not set +CONFIG_STM32_USART=y -CONFIG_USART1_BITS=8 -CONFIG_USART2_BITS=8 -CONFIG_USART3_BITS=8 -CONFIG_UART4_BITS=8 -CONFIG_UART5_BITS=8 +# +# U[S]ART Configuration +# +# CONFIG_USART2_RS485 is not set +# CONFIG_STM32_USART_SINGLEWIRE is not set -CONFIG_USART1_PARITY=0 -CONFIG_USART2_PARITY=0 -CONFIG_USART3_PARITY=0 -CONFIG_UART4_PARITY=0 -CONFIG_UART5_PARITY=0 +# +# SPI Configuration +# +# CONFIG_STM32_SPI_INTERRUPTS is not set +# CONFIG_STM32_SPI_DMA is not set -CONFIG_USART1_2STOP=0 -CONFIG_USART2_2STOP=0 -CONFIG_USART3_2STOP=0 -CONFIG_UART4_2STOP=0 -CONFIG_UART5_2STOP=0 +# +# USB Host Configuration +# # -# STM32F40xxx specific SPI device driver settings +# External Memory Configuration # -CONFIG_SPI_EXCHANGE=y # -# STM32F40xxx specific CAN device driver settings +# Architecture Options # -CONFIG_CAN=n -CONFIG_CAN_EXTID=n -#CONFIG_CAN_FIFOSIZE -#CONFIG_CAN_NPENDINGRTR -CONFIG_CAN_LOOPBACK=n -CONFIG_CAN1_BAUD=700000 -CONFIG_CAN2_BAUD=700000 +# CONFIG_ARCH_NOINTC is not set +# CONFIG_ARCH_VECNOTIRQ is not set +# CONFIG_ARCH_DMA is not set +CONFIG_ARCH_IRQPRIO=y +# CONFIG_CUSTOM_STACK is not set +# CONFIG_ADDRENV is not set +CONFIG_ARCH_HAVE_VFORK=y +CONFIG_ARCH_STACKDUMP=y +# CONFIG_ENDIAN_BIG is not set +# CONFIG_ARCH_HAVE_RAMFUNCS is not set # -# STM32F40xxx Ethernet device driver settings +# Board Settings # -CONFIG_STM32_PHYADDR=1 -CONFIG_STM32_MII=y -CONFIG_STM32_MII_MCO1=y -CONFIG_STM32_MII_MCO2=n -CONFIG_STM32_RMII=n -CONFIG_STM32_AUTONEG=y -#CONFIG_STM32_ETHFD -#CONFIG_STM32_ETH100MB -CONFIG_STM32_PHYSR=16 -CONFIG_STM32_PHYSR_SPEED=0x0002 -CONFIG_STM32_PHYSR_100MBPS=0x0000 -CONFIG_STM32_PHYSR_MODE=0x0004 -CONFIG_STM32_PHYSR_FULLDUPLEX=0x0004 -CONFIG_STM32_ETH_PTP=n -CONFIG_STM32_ETHMAC_REGDEBUG=n +CONFIG_DRAM_START=0x20000000 +CONFIG_DRAM_SIZE=114688 +CONFIG_ARCH_HAVE_INTERRUPTSTACK=y +CONFIG_ARCH_INTERRUPTSTACK=0 # -# PWM configuration +# Boot options # -# The stm32f4discovery has no real on-board PWM devices, but the board can be configured to output -# a pulse train using TIM4 CH2. (Don't forget to set CONFIG_STM32_TIM4=y above) +# CONFIG_BOOT_RUNFROMEXTSRAM is not set +CONFIG_BOOT_RUNFROMFLASH=y +# CONFIG_BOOT_RUNFROMISRAM is not set +# CONFIG_BOOT_RUNFROMSDRAM is not set +# CONFIG_BOOT_COPYTORAM is not set + # -CONFIG_PWM=n -CONFIG_STM32_TIM4_PWM=y -CONFIG_STM32_TIM4_CHANNEL=2 +# Board Selection +# +CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y +# CONFIG_ARCH_BOARD_CUSTOM is not set +CONFIG_ARCH_BOARD="stm32f4discovery" # -# Quadrature Encoder configuration. +# Common Board Options # -CONFIG_QENCODER=n -CONFIG_STM32_TIM2_QE=n -CONFIG_STM32_TIM2_QECLKOUT=28000000 -CONFIG_STM32_TIM8_QE=y -CONFIG_STM32_TIM8_QECLKOUT=28000000 +CONFIG_ARCH_HAVE_LEDS=y +CONFIG_ARCH_LEDS=y +CONFIG_ARCH_HAVE_BUTTONS=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_HAVE_IRQBUTTONS=y +# CONFIG_ARCH_IRQBUTTONS is not set +CONFIG_NSH_MMCSDMINOR=0 # -# General build options +# Board-Specific Options # -CONFIG_RRLOAD_BINARY=n -CONFIG_INTELHEX_BINARY=y -CONFIG_MOTOROLA_SREC=n -CONFIG_RAW_BINARY=y # -# General OS setup +# RTOS Features # -CONFIG_USER_ENTRYPOINT="nsh_main" -CONFIG_DEBUG=n -CONFIG_DEBUG_VERBOSE=n -CONFIG_DEBUG_SYMBOLS=n -CONFIG_DEBUG_FS=n -CONFIG_DEBUG_GRAPHICS=n -CONFIG_DEBUG_LCD=n -CONFIG_DEBUG_USB=n -CONFIG_DEBUG_NET=n -CONFIG_DEBUG_RTC=n -CONFIG_DEBUG_ANALOG=n -CONFIG_DEBUG_PWM=n -CONFIG_DEBUG_CAN=n -CONFIG_DEBUG_QENCODER=n -CONFIG_HAVE_CXX=y -CONFIG_HAVE_CXXINITIALIZE=y -CONFIG_MM_REGIONS=2 -CONFIG_ARCH_LOWPUTC=y +CONFIG_MSEC_PER_TICK=10 CONFIG_RR_INTERVAL=200 -CONFIG_SCHED_INSTRUMENTATION=n +# CONFIG_SCHED_INSTRUMENTATION is not set CONFIG_TASK_NAME_SIZE=0 +# CONFIG_SCHED_HAVE_PARENT is not set +# CONFIG_JULIAN_TIME is not set CONFIG_START_YEAR=2011 CONFIG_START_MONTH=12 CONFIG_START_DAY=6 -CONFIG_GREGORIAN_TIME=n -CONFIG_JULIAN_TIME=n CONFIG_DEV_CONSOLE=y -CONFIG_DEV_LOWCONSOLE=n -CONFIG_MUTEX_TYPES=n -CONFIG_PRIORITY_INHERITANCE=n -CONFIG_SEM_PREALLOCHOLDERS=0 -CONFIG_SEM_NNESTPRIO=0 -CONFIG_FDCLONE_DISABLE=n -CONFIG_FDCLONE_STDIO=n +# CONFIG_MUTEX_TYPES is not set +# CONFIG_PRIORITY_INHERITANCE is not set +# CONFIG_FDCLONE_DISABLE is not set +# CONFIG_FDCLONE_STDIO is not set CONFIG_SDCLONE_DISABLE=y -CONFIG_SCHED_WORKQUEUE=n -CONFIG_SCHED_WORKPRIORITY=192 -CONFIG_SCHED_WORKPERIOD=50000 -CONFIG_SCHED_WORKSTACKSIZE=1024 -CONFIG_SIG_SIGWORK=17 +# CONFIG_SCHED_WORKQUEUE is not set CONFIG_SCHED_WAITPID=y -CONFIG_SCHED_ATEXIT=n +# CONFIG_SCHED_STARTHOOK is not set +# CONFIG_SCHED_ATEXIT is not set +# CONFIG_SCHED_ONEXIT is not set +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_DISABLE_OS_API=y +# CONFIG_DISABLE_CLOCK is not set +# CONFIG_DISABLE_POSIX_TIMERS is not set +# CONFIG_DISABLE_PTHREAD is not set +# CONFIG_DISABLE_SIGNALS is not set +# CONFIG_DISABLE_MQUEUE is not set +# CONFIG_DISABLE_ENVIRON is not set # -# Settings for NXFLAT +# Signal Numbers # -CONFIG_NXFLAT=n -CONFIG_NXFLAT_DUMPBUFFER=n -CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SIG_SIGUSR1=1 +CONFIG_SIG_SIGUSR2=2 +CONFIG_SIG_SIGALARM=3 +CONFIG_SIG_SIGCONDTIMEDOUT=16 # -# The following can be used to disable categories of -# APIs supported by the OS. If the compiler supports -# weak functions, then it should not be necessary to -# disable functions unless you want to restrict usage -# of those APIs. +# Sizes of configurable things (0 disables) # -# There are certain dependency relationships in these -# features. +CONFIG_MAX_TASKS=16 +CONFIG_MAX_TASK_ARGS=4 +CONFIG_NPTHREAD_KEYS=4 +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NAME_MAX=32 +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_MQ_MAXMSGSIZE=32 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_PREALLOC_WDOGS=4 +CONFIG_PREALLOC_TIMERS=4 + # -# o mq_notify logic depends on signals to awaken tasks -# waiting for queues to become full or empty. -# o pthread_condtimedwait() depends on signals to wake -# up waiting tasks. +# Stack and heap information +# +CONFIG_IDLETHREAD_STACKSIZE=1024 +CONFIG_USERMAIN_STACKSIZE=2048 +CONFIG_PTHREAD_STACK_MIN=256 +CONFIG_PTHREAD_STACK_DEFAULT=2048 + +# +# Device Drivers # -CONFIG_DISABLE_CLOCK=n -CONFIG_DISABLE_POSIX_TIMERS=n -CONFIG_DISABLE_PTHREAD=n -CONFIG_DISABLE_SIGNALS=n -CONFIG_DISABLE_MQUEUE=n -CONFIG_DISABLE_MOUNTPOINT=n -CONFIG_DISABLE_ENVIRON=n CONFIG_DISABLE_POLL=y +CONFIG_DEV_NULL=y +# CONFIG_DEV_ZERO is not set +# CONFIG_LOOP is not set +# CONFIG_RAMDISK is not set +# CONFIG_CAN is not set +# CONFIG_PWM is not set +# CONFIG_I2C is not set +CONFIG_ARCH_HAVE_I2CRESET=y +CONFIG_SPI=y +# CONFIG_SPI_OWNBUS is not set +CONFIG_SPI_EXCHANGE=y +# CONFIG_SPI_CMDDATA is not set +# CONFIG_RTC is not set +# CONFIG_WATCHDOG is not set +# CONFIG_ANALOG is not set +# CONFIG_BCH is not set +# CONFIG_INPUT is not set +# CONFIG_LCD is not set +# CONFIG_MMCSD is not set +# CONFIG_MTD is not set +# CONFIG_PIPES is not set +# CONFIG_PM is not set +# CONFIG_POWER is not set +# CONFIG_SENSORS is not set +# CONFIG_SERCOMM_CONSOLE is not set +CONFIG_SERIAL=y +# CONFIG_DEV_LOWCONSOLE is not set +# CONFIG_16550_UART is not set +CONFIG_ARCH_HAVE_USART2=y +CONFIG_MCU_SERIAL=y +CONFIG_STANDARD_SERIAL=y +CONFIG_USART2_SERIAL_CONSOLE=y +# CONFIG_NO_SERIAL_CONSOLE is not set # -# Misc libc settings +# USART2 Configuration # -CONFIG_NOPRINTF_FIELDWIDTH=n +CONFIG_USART2_RXBUFSIZE=128 +CONFIG_USART2_TXBUFSIZE=128 +CONFIG_USART2_BAUD=115200 +CONFIG_USART2_BITS=8 +CONFIG_USART2_PARITY=0 +CONFIG_USART2_2STOP=0 +# CONFIG_USBDEV is not set +# CONFIG_USBHOST is not set +# CONFIG_WIRELESS is not set # -# Allow for architecture optimized implementations +# System Logging Device Options +# + # -# The architecture can provide optimized versions of the -# following to improve system performance +# System Logging # -CONFIG_ARCH_MEMCPY=n -CONFIG_ARCH_MEMCMP=n -CONFIG_ARCH_MEMMOVE=n -CONFIG_ARCH_MEMSET=n -CONFIG_ARCH_STRCMP=n -CONFIG_ARCH_STRCPY=n -CONFIG_ARCH_STRNCPY=n -CONFIG_ARCH_STRLEN=n -CONFIG_ARCH_STRNLEN=n -CONFIG_ARCH_BZERO=n +# CONFIG_RAMLOG is not set # -# Sizes of configurable things (0 disables) +# Networking Support +# +# CONFIG_NET is not set + +# +# File Systems +# + +# +# File system configuration +# +# CONFIG_DISABLE_MOUNTPOINT is not set +# CONFIG_FS_RAMMAP is not set +# CONFIG_FS_FAT is not set +# CONFIG_FS_NXFFS is not set +# CONFIG_FS_ROMFS is not set +# CONFIG_FS_BINFS is not set + +# +# System Logging +# +# CONFIG_SYSLOG is not set + +# +# Graphics Support +# +# CONFIG_NX is not set + +# +# Memory Management +# +# CONFIG_MM_SMALL is not set +CONFIG_MM_REGIONS=2 +# CONFIG_GRAN is not set + +# +# Binary Formats +# +# CONFIG_BINFMT_DISABLE is not set +# CONFIG_BINFMT_EXEPATH is not set +# CONFIG_NXFLAT is not set +# CONFIG_ELF is not set +CONFIG_BUILTIN=y +# CONFIG_PIC is not set +# CONFIG_SYMTAB_ORDEREDBYNAME is not set + +# +# Library Routines +# + +# +# Standard C Library Options # -CONFIG_MAX_TASKS=16 -CONFIG_MAX_TASK_ARGS=4 -CONFIG_NPTHREAD_KEYS=4 -CONFIG_NFILE_DESCRIPTORS=8 -CONFIG_NFILE_STREAMS=8 -CONFIG_NAME_MAX=32 CONFIG_STDIO_BUFFER_SIZE=256 CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=2 -CONFIG_PREALLOC_MQ_MSGS=4 -CONFIG_MQ_MAXMSGSIZE=32 -CONFIG_MAX_WDOGPARMS=2 -CONFIG_PREALLOC_WDOGS=4 -CONFIG_PREALLOC_TIMERS=4 +CONFIG_LIB_HOMEDIR="/" +# CONFIG_LIBM is not set +# CONFIG_NOPRINTF_FIELDWIDTH is not set +# CONFIG_LIBC_FLOATINGPOINT is not set +# CONFIG_EOL_IS_CR is not set +# CONFIG_EOL_IS_LF is not set +# CONFIG_EOL_IS_BOTH_CRLF is not set +CONFIG_EOL_IS_EITHER_CRLF=y +# CONFIG_LIBC_EXECFUNCS is not set +# CONFIG_LIBC_STRERROR is not set +# CONFIG_LIBC_PERROR_STDOUT is not set +CONFIG_ARCH_LOWPUTC=y +CONFIG_LIB_SENDFILE_BUFSIZE=512 +# CONFIG_ARCH_ROMGETC is not set +# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set # -# Framebuffer driver options +# Non-standard Helper Functions # -CONFIG_FB_CMAP=n -CONFIG_FB_HWCURSOR=n -CONFIG_FB_HWCURSORIMAGE=n -#CONFIG_FB_HWCURSORSIZE -#CONFIG_FB_TRANSPARENCY +# CONFIG_LIB_KBDCODEC is not set # -# Filesystem configuration +# Basic CXX Support # -CONFIG_FS_FAT=n -CONFIG_FAT_LCNAMES=y -CONFIG_FAT_LFN=y -CONFIG_FAT_MAXFNAME=32 -CONFIG_FS_NXFFS=n -CONFIG_FS_ROMFS=n +# CONFIG_C99_BOOL8 is not set +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +# CONFIG_CXX_NEWLONG is not set # -# SPI-based MMC/SD driver +# uClibc++ Standard C++ Library # -CONFIG_MMCSD_NSLOTS=0 -CONFIG_MMCSD_READONLY=n -CONFIG_MMCSD_SPICLOCK=12500000 +# CONFIG_UCLIBCXX is not set # -# Block driver buffering +# Application Configuration # -CONFIG_FS_READAHEAD=n -CONFIG_FS_WRITEBUFFER=n # -# STM32 SDIO-based MMC/SD driver +# Built-In Applications # -CONFIG_SDIO_DMA=n -#CONFIG_SDIO_PRI=128 -#CONFIG_SDIO_DMAPRIO -#CONFIG_SDIO_WIDTH_D1_ONLY -CONFIG_MMCSD_MULTIBLOCK_DISABLE=y -CONFIG_MMCSD_MMCSUPPORT=n -CONFIG_MMCSD_HAVECARDDETECT=n +CONFIG_BUILTIN_PROXY_STACKSIZE=1024 # -# TCP/IP and UDP support via uIP +# Examples # -CONFIG_NET=n -CONFIG_NET_NOINTS=n -CONFIG_NET_MULTIBUFFER=y -CONFIG_NET_IPv6=n -CONFIG_NSOCKET_DESCRIPTORS=10 -CONFIG_NET_SOCKOPTS=y -CONFIG_NET_BUFSIZE=562 -CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=40 -#CONFIG_NET_TCP_READAHEAD_BUFSIZE -CONFIG_NET_NTCP_READAHEAD_BUFFERS=16 -CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_MAX_LISTENPORTS=40 -CONFIG_NET_UDP=y -CONFIG_NET_UDP_CHECKSUMS=y -#CONFIG_NET_UDP_CONNS=10 -CONFIG_NET_ICMP=y -CONFIG_NET_ICMP_PING=y -#CONFIG_NET_PINGADDRCONF=0 -CONFIG_NET_STATISTICS=y -#CONFIG_NET_RECEIVE_WINDOW= -CONFIG_NET_BROADCAST=n -#CONFIG_NET_ARPTAB_SIZE=8 -CONFIG_NET_ARP_IPIN=n -CONFIG_NET_MULTICAST=n - -# -# UIP Network Utilities +# CONFIG_EXAMPLES_BUTTONS is not set +# CONFIG_EXAMPLES_CAN is not set +# CONFIG_EXAMPLES_CDCACM is not set +# CONFIG_EXAMPLES_COMPOSITE is not set +# CONFIG_EXAMPLES_CXXTEST is not set +# CONFIG_EXAMPLES_DHCPD is not set +# CONFIG_EXAMPLES_ELF is not set +# CONFIG_EXAMPLES_FTPC is not set +# CONFIG_EXAMPLES_FTPD is not set +# CONFIG_EXAMPLES_HELLO is not set +# CONFIG_EXAMPLES_HELLOXX is not set +# CONFIG_EXAMPLES_JSON is not set +# CONFIG_EXAMPLES_HIDKBD is not set +# CONFIG_EXAMPLES_KEYPADTEST is not set +# CONFIG_EXAMPLES_IGMP is not set +# CONFIG_EXAMPLES_LCDRW is not set +# CONFIG_EXAMPLES_MM is not set +# CONFIG_EXAMPLES_MOUNT is not set +# CONFIG_EXAMPLES_MODBUS is not set +CONFIG_EXAMPLES_NSH=y +# CONFIG_EXAMPLES_NULL is not set +# CONFIG_EXAMPLES_NX is not set +# CONFIG_EXAMPLES_NXCONSOLE is not set +# CONFIG_EXAMPLES_NXFFS is not set +# CONFIG_EXAMPLES_NXFLAT is not set +# CONFIG_EXAMPLES_NXHELLO is not set +# CONFIG_EXAMPLES_NXIMAGE is not set +# CONFIG_EXAMPLES_NXLINES is not set +# CONFIG_EXAMPLES_NXTEXT is not set +# CONFIG_EXAMPLES_OSTEST is not set +# CONFIG_EXAMPLES_PASHELLO is not set +# CONFIG_EXAMPLES_PIPE is not set +# CONFIG_EXAMPLES_POSIXSPAWN is not set +# CONFIG_EXAMPLES_QENCODER is not set +# CONFIG_EXAMPLES_RGMP is not set +# CONFIG_EXAMPLES_ROMFS is not set +# CONFIG_EXAMPLES_SENDMAIL is not set +# CONFIG_EXAMPLES_SERLOOP is not set +# CONFIG_EXAMPLES_TELNETD is not set +# CONFIG_EXAMPLES_THTTPD is not set +# CONFIG_EXAMPLES_TIFF is not set +# CONFIG_EXAMPLES_TOUCHSCREEN is not set +# CONFIG_EXAMPLES_UDP is not set +# CONFIG_EXAMPLES_UIP is not set +# CONFIG_EXAMPLES_USBSERIAL is not set +# CONFIG_EXAMPLES_USBMSC is not set +# CONFIG_EXAMPLES_USBTERM is not set +# CONFIG_EXAMPLES_WATCHDOG is not set + +# +# Interpreters # -CONFIG_NET_DHCP_LIGHT=n -CONFIG_NET_RESOLV_ENTRIES=4 # -# RTC Configuration +# Interpreters # -CONFIG_RTC=n -CONFIG_RTC_DATETIME=y -CONFIG_RTC_HIRES=n -CONFIG_RTC_FREQUENCY=1 -CONFIG_RTC_ALARM=n - -# -# STM32 USB OTG FS Device Configuration -# -CONFIG_USBDEV=n -CONFIG_USBDEV_ISOCHRONOUS=n -CONFIG_USBDEV_DUALSPEED=n -CONFIG_USBDEV_SELFPOWERED=y -CONFIG_USBDEV_REMOTEWAKEUP=n -CONFIG_USBDEV_MAXPOWER=100 -CONFIG_USBDEV_TRACE=n -CONFIG_USBDEV_TRACE_NRECORDS=128 - -# -# STM32 USB OTG FS Host Configuration -# -CONFIG_USBHOST=n -#CONFIG_STM32_OTGFS_RXFIFO_SIZE -#CONFIG_STM32_OTGFS_NPTXFIFO_SIZE -#CONFIG_STM32_OTGFS_PTXFIFO_SIZE -#CONFIG_STM32_OTGFS_DESCSIZE -CONFIG_STM32_OTGFS_SOFINTR=n -CONFIG_STM32_USBHOST_REGDEBUG=n -CONFIG_STM32_USBHOST_PKTDUMP=n - -# -# USB Serial Device Configuration (Prolifics PL2303 emulation) -# -CONFIG_PL2303=n -CONFIG_PL2303_EPINTIN=1 -CONFIG_PL2303_EPBULKOUT=2 -CONFIG_PL2303_EPBULKIN=3 -CONFIG_PL2303_NWRREQS=4 -CONFIG_PL2303_NRDREQS=4 -CONFIG_PL2303_VENDORID=0x067b -CONFIG_PL2303_PRODUCTID=0x2303 -CONFIG_PL2303_VENDORSTR="Nuttx" -CONFIG_PL2303_PRODUCTSTR="USBdev Serial" -CONFIG_PL2303_RXBUFSIZE=512 -CONFIG_PL2303_TXBUFSIZE=512 - -# -# USB serial device class driver (Standard CDC ACM class) -# -CONFIG_CDCACM=n -CONFIG_CDCACM_CONSOLE=n -#CONFIG_CDCACM_EP0MAXPACKET -CONFIG_CDCACM_EPINTIN=1 -#CONFIG_CDCACM_EPINTIN_FSSIZE -#CONFIG_CDCACM_EPINTIN_HSSIZE -CONFIG_CDCACM_EPBULKOUT=3 -#CONFIG_CDCACM_EPBULKOUT_FSSIZE -#CONFIG_CDCACM_EPBULKOUT_HSSIZE -CONFIG_CDCACM_EPBULKIN=2 -#CONFIG_CDCACM_EPBULKIN_FSSIZE -#CONFIG_CDCACM_EPBULKIN_HSSIZE -#CONFIG_CDCACM_NWRREQS -#CONFIG_CDCACM_NRDREQS -#CONFIG_CDCACM_VENDORID -#CONFIG_CDCACM_VENDORSTR -#CONFIG_CDCACM_PRODUCTID -#CONFIG_CDCACM_PRODUCTSTR -#CONFIG_CDCACM_RXBUFSIZE -#CONFIG_CDCACM_TXBUFSIZE - -# -# USB Storage Device Configuration -# -CONFIG_USBMSC=n -CONFIG_USBMSC_EP0MAXPACKET=64 -CONFIG_USBMSC_EPBULKOUT=2 -CONFIG_USBMSC_EPBULKIN=5 -CONFIG_USBMSC_NRDREQS=2 -CONFIG_USBMSC_NWRREQS=2 -CONFIG_USBMSC_BULKINREQLEN=256 -CONFIG_USBMSC_BULKOUTREQLEN=256 -CONFIG_USBMSC_VENDORID=0x584e -CONFIG_USBMSC_VENDORSTR="NuttX" -CONFIG_USBMSC_PRODUCTID=0x5342 -CONFIG_USBMSC_PRODUCTSTR="USBdev Storage" -CONFIG_USBMSC_VERSIONNO=0x0399 -CONFIG_USBMSC_REMOVABLE=y - -# -# Watchdog timer configuration -# -CONFIG_WATCHDOG=n - -# -# Graphics related configuration settings -# -CONFIG_NX=n -CONFIG_NX_MULTIUSER=n -CONFIG_NX_NPLANES=1 -CONFIG_NX_DISABLE_1BPP=y -CONFIG_NX_DISABLE_2BPP=y -CONFIG_NX_DISABLE_4BPP=y -CONFIG_NX_DISABLE_8BPP=y -CONFIG_NX_DISABLE_16BPP=n -CONFIG_NX_DISABLE_24BPP=y -CONFIG_NX_DISABLE_32BPP=y -CONFIG_NX_PACKEDMSFIRST=n -CONFIG_NX_LCDDRIVER=y -CONFIG_LCD_MAXPOWER=1 -CONFIG_LCD_MAXCONTRAST=1 -CONFIG_NX_MOUSE=y -CONFIG_NX_KBD=y -#CONFIG_NXTK_BORDERWIDTH=4 -CONFIG_NXTK_BORDERCOLOR1=0xd69a -CONFIG_NXTK_BORDERCOLOR2=0xad55 -CONFIG_NXTK_AUTORAISE=n -CONFIG_NXFONT_SANS17X22=y -CONFIG_NXFONT_SANS20X26=n -CONFIG_NXFONT_SANS22X29=n -CONFIG_NXFONT_SANS23X27=n -CONFIG_NXFONT_SANS28X37=n -CONFIG_NXFONT_SANS17X23B=n -CONFIG_NXFONT_SANS20X27B=y -CONFIG_NXFONT_SANS22X29B=y -CONFIG_NXFONT_SANS28X37B=n -CONFIG_NXFONT_SANS40X49B=n -CONFIG_NXFONT_SERIF22X29=n -CONFIG_NXFONT_SERIF29X37=n -CONFIG_NXFONT_SERIF38X48=n -CONFIG_NXFONT_SERIF22X28B=n -CONFIG_NXFONT_SERIF27X38B=n -CONFIG_NXFONT_SERIF38X49B=n -CONFIG_NXFONTS_CHARBITS=7 -CONFIG_NX_BLOCKING=y -CONFIG_NX_MXSERVERMSGS=32 -CONFIG_NX_MXCLIENTMSGS=16 - -# -# Settings for examples/uip -# -CONFIG_EXAMPLES_UIP_IPADDR=0x0a000002 -CONFIG_EXAMPLES_UIP_DRIPADDR=0x0a000001 -CONFIG_EXAMPLES_UIP_NETMASK=0xffffff00 -CONFIG_EXAMPLES_UIP_DHCPC=n - -# -# Settings for examples/nettest -CONFIG_EXAMPLES_NETTEST_SERVER=n -CONFIG_EXAMPLES_NETTEST_PERFORMANCE=n -CONFIG_EXAMPLES_NETTEST_NOMAC=y -CONFIG_EXAMPLES_NETTEST_IPADDR=0x0a000002 -CONFIG_EXAMPLES_NETTEST_DRIPADDR=0x0a000001 -CONFIG_EXAMPLES_NETTEST_NETMASK=0xffffff00 -CONFIG_EXAMPLES_NETTEST_CLIENTIP=0x0a000001 - -# -# Settings for examples/ostest -# -CONFIG_EXAMPLES_OSTEST_LOOPS=1 -CONFIG_EXAMPLES_OSTEST_STACKSIZE=2048 -CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS=3 - -# -# Settings for apps/nshlib +# CONFIG_INTERPRETERS_FICL is not set +# CONFIG_INTERPRETERS_PCODE is not set + # -CONFIG_BUILTIN=y +# Network Utilities +# + +# +# Networking Utilities +# +# CONFIG_NETUTILS_CODECS is not set +# CONFIG_NETUTILS_DHCPC is not set +# CONFIG_NETUTILS_DHCPD is not set +# CONFIG_NETUTILS_FTPC is not set +# CONFIG_NETUTILS_FTPD is not set +# CONFIG_NETUTILS_JSON is not set +# CONFIG_NETUTILS_RESOLV is not set +# CONFIG_NETUTILS_SMTP is not set +# CONFIG_NETUTILS_TELNETD is not set +# CONFIG_NETUTILS_TFTPC is not set +# CONFIG_NETUTILS_THTTPD is not set +# CONFIG_NETUTILS_UIPLIB is not set +# CONFIG_NETUTILS_WEBCLIENT is not set + +# +# ModBus +# + +# +# FreeModbus +# +# CONFIG_MODBUS is not set + +# +# NSH Library +# +CONFIG_NSH_LIBRARY=y CONFIG_NSH_BUILTIN_APPS=y + +# +# Disable Individual commands +# +# CONFIG_NSH_DISABLE_CAT is not set +# CONFIG_NSH_DISABLE_CD is not set +# CONFIG_NSH_DISABLE_CP is not set +# CONFIG_NSH_DISABLE_DD is not set +# CONFIG_NSH_DISABLE_ECHO is not set +# CONFIG_NSH_DISABLE_EXEC is not set +# CONFIG_NSH_DISABLE_EXIT is not set +# CONFIG_NSH_DISABLE_FREE is not set +# CONFIG_NSH_DISABLE_GET is not set +# CONFIG_NSH_DISABLE_HELP is not set +# CONFIG_NSH_DISABLE_HEXDUMP is not set +# CONFIG_NSH_DISABLE_IFCONFIG is not set +# CONFIG_NSH_DISABLE_KILL is not set +# CONFIG_NSH_DISABLE_LOSETUP is not set +# CONFIG_NSH_DISABLE_LS is not set +# CONFIG_NSH_DISABLE_MB is not set +# CONFIG_NSH_DISABLE_MKDIR is not set +# CONFIG_NSH_DISABLE_MKFATFS is not set +# CONFIG_NSH_DISABLE_MKFIFO is not set +# CONFIG_NSH_DISABLE_MKRD is not set +# CONFIG_NSH_DISABLE_MH is not set +# CONFIG_NSH_DISABLE_MOUNT is not set +# CONFIG_NSH_DISABLE_MW is not set +# CONFIG_NSH_DISABLE_NSFMOUNT is not set +# CONFIG_NSH_DISABLE_PS is not set +# CONFIG_NSH_DISABLE_PING is not set +# CONFIG_NSH_DISABLE_PUT is not set +# CONFIG_NSH_DISABLE_PWD is not set +# CONFIG_NSH_DISABLE_RM is not set +# CONFIG_NSH_DISABLE_RMDIR is not set +# CONFIG_NSH_DISABLE_SET is not set +# CONFIG_NSH_DISABLE_SH is not set +# CONFIG_NSH_DISABLE_SLEEP is not set +# CONFIG_NSH_DISABLE_TEST is not set +# CONFIG_NSH_DISABLE_UMOUNT is not set +# CONFIG_NSH_DISABLE_UNSET is not set +# CONFIG_NSH_DISABLE_USLEEP is not set +# CONFIG_NSH_DISABLE_WGET is not set +# CONFIG_NSH_DISABLE_XD is not set +CONFIG_NSH_CODECS_BUFSIZE=128 CONFIG_NSH_FILEIOSIZE=512 -CONFIG_NSH_STRERROR=n CONFIG_NSH_LINELEN=64 CONFIG_NSH_NESTDEPTH=3 -CONFIG_NSH_DISABLESCRIPT=n -CONFIG_NSH_DISABLEBG=n -CONFIG_NSH_ROMFSETC=n +# CONFIG_NSH_DISABLESCRIPT is not set +# CONFIG_NSH_DISABLEBG is not set CONFIG_NSH_CONSOLE=y -CONFIG_NSH_TELNET=n -CONFIG_NSH_USBCONSOLE=n -CONFIG_NSH_USBCONDEV="/dev/ttyACM0" -CONFIG_NSH_UBSDEV_MINOR=0 -CONFIG_NSH_USBDEV_TRACEINIT=n -CONFIG_NSH_USBDEV_TRACECLASS=n -CONFIG_NSH_USBDEV_TRACETRANSFERS=n -CONFIG_NSH_USBDEV_TRACECONTROLLER=n -CONFIG_NSH_USBDEV_TRACEINTERRUPTS=n -#CONFIG_NSH_CONDEV -CONFIG_NSH_ARCHINIT=n -CONFIG_NSH_IOBUFFER_SIZE=512 -CONFIG_NSH_DHCPC=n -CONFIG_NSH_NOMAC=y -CONFIG_NSH_IPADDR=0x0a000002 -CONFIG_NSH_DRIPADDR=0x0a000001 -CONFIG_NSH_NETMASK=0xffffff00 -CONFIG_NSH_ROMFSMOUNTPT="/etc" -CONFIG_NSH_INITSCRIPT="init.d/rcS" -CONFIG_NSH_ROMFSDEVNO=0 -CONFIG_NSH_ROMFSSECTSIZE=64 -CONFIG_NSH_FATDEVNO=1 -CONFIG_NSH_FATSECTSIZE=512 -CONFIG_NSH_FATNSECTORS=1024 -CONFIG_NSH_FATMOUNTPT="/tmp" - -# -# Architecture-specific NSH options -# -CONFIG_NSH_MMCSDSPIPORTNO=0 -CONFIG_NSH_MMCSDSLOTNO=0 -CONFIG_NSH_MMCSDMINOR=0 +# CONFIG_NSH_CONDEV is not set +# CONFIG_NSH_ARCHINIT is not set # -# Settings for examples/usbserial +# NxWidgets/NxWM # -CONFIG_EXAMPLES_USBSERIAL_INONLY=n -CONFIG_EXAMPLES_USBSERIAL_OUTONLY=n -CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL=n -CONFIG_EXAMPLES_USBSERIAL_ONLYBIG=n - -CONFIG_EXAMPLES_USBSERIAL_TRACEINIT=n -CONFIG_EXAMPLES_USBSERIAL_TRACECLASS=n -CONFIG_EXAMPLES_USBSERIAL_TRACETRANSFERS=n -CONFIG_EXAMPLES_USBSERIAL_TRACECONTROLLER=n -CONFIG_EXAMPLES_USBSERIAL_TRACEINTERRUPTS=n # -# Settings for examples/cdcacm -# -# Configuration prequisites: +# System NSH Add-Ons # -CONFIG_EXAMPLES_CDCACM_DEVMINOR=0 -CONFIG_EXAMPLES_CDCACM_TRACEINIT=n -CONFIG_EXAMPLES_CDCACM_TRACECLASS=n -CONFIG_EXAMPLES_CDCACM_TRACETRANSFERS=n -CONFIG_EXAMPLES_CDCACM_TRACECONTROLLER=n -CONFIG_EXAMPLES_CDCACM_TRACEINTERRUPTS=n # -# Settings for examples/adc +# Custom Free Memory Command # +# CONFIG_SYSTEM_FREE is not set # -# Settings for examples/can +# I2C tool # # -# Settings for examples/pwm +# FLASH Program Installation # +# CONFIG_SYSTEM_INSTALL is not set # -# Settings for examples/watchdog +# readline() # +CONFIG_SYSTEM_READLINE=y +CONFIG_READLINE_ECHO=y -# This test depends on these specific Watchdog/NSH configurations settings (your -# specific watchdog hardware settings might require additional settings). # +# Power Off +# +# CONFIG_SYSTEM_POWEROFF is not set # -# Settings for examples/watchdog +# RAMTRON +# +# CONFIG_SYSTEM_RAMTRON is not set + # -# This test depends on these specific Watchdog/NSH configurations settings (your -# specific watchdog hardware settings might require additional settings). +# SD Card # +# CONFIG_SYSTEM_SDCARD is not set # -# Stack and heap information +# Sysinfo # -CONFIG_BOOT_RUNFROMFLASH=n -CONFIG_BOOT_COPYTORAM=n -CONFIG_CUSTOM_STACK=n -CONFIG_IDLETHREAD_STACKSIZE=1024 -CONFIG_USERMAIN_STACKSIZE=2048 -CONFIG_PTHREAD_STACK_MIN=256 -CONFIG_PTHREAD_STACK_DEFAULT=2048 -CONFIG_HEAP_BASE= -CONFIG_HEAP_SIZE= +# CONFIG_SYSTEM_SYSINFO is not set diff --git a/nuttx/configs/stm32f4discovery/pm/defconfig b/nuttx/configs/stm32f4discovery/pm/defconfig index 332235050..981a8abb2 100644 --- a/nuttx/configs/stm32f4discovery/pm/defconfig +++ b/nuttx/configs/stm32f4discovery/pm/defconfig @@ -635,7 +635,7 @@ CONFIG_NSH_CONSOLE=y CONFIG_NSH_TELNET=n CONFIG_NSH_USBCONSOLE=n CONFIG_NSH_USBCONDEV="/dev/ttyACM0" -CONFIG_NSH_UBSDEV_MINOR=0 +CONFIG_NSH_USBDEV_MINOR=0 CONFIG_NSH_USBDEV_TRACEINIT=n CONFIG_NSH_USBDEV_TRACECLASS=n CONFIG_NSH_USBDEV_TRACETRANSFERS=n -- cgit v1.2.3 From 02b171cb25870b7caf1161469edd43486bf4145b Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 28 Jan 2013 01:44:45 +0000 Subject: Updates for stm32f4discovery/usbnsh configuration git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5574 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/README.txt | 26 +++++++++++++++++++-- nuttx/configs/sim/nsh/defconfig | 18 ++++++++------ nuttx/configs/stm32f4discovery/README.txt | 31 ++++++++++++++----------- nuttx/configs/stm32f4discovery/usbnsh/defconfig | 10 ++++---- nuttx/drivers/usbdev/Kconfig | 14 +++++------ nuttx/include/nuttx/usb/cdcacm.h | 12 +++++----- 6 files changed, 70 insertions(+), 41 deletions(-) diff --git a/nuttx/README.txt b/nuttx/README.txt index 2ff473fa0..c597091dc 100644 --- a/nuttx/README.txt +++ b/nuttx/README.txt @@ -280,8 +280,14 @@ NuttX Configuration Tool make menuconfig - This make target will bring up NuttX configuration menus. The - 'menuconfig' target depends on two things: + This make target will bring up NuttX configuration menus. + + WARNING: Never do 'make menuconfig' on a configuration that has + not been converted to use the kconfig-frontends tools! This will + damage your configuration (see + http://www.nuttx.org/doku.php?id=wiki:howtos:convertconfig). + + The 'menuconfig' make target depends on two things: 1. The Kconfig configuration data files that appear in almost all NuttX directories. These data files are the part that is still @@ -319,6 +325,22 @@ NuttX Configuration Tool This is pretty straight forward for creating new configurations but may be less intuitive for modifying existing configurations. +Refreshing Configurations with 'make oldconfig' +----------------------------------------------- + + Whenever you use a configuration, you really should always do + the following *before* you make NuttX: + + make oldconfig + + This will make sure that the configuration is up-to-date in + the event that it has lapsed behind the current NuttX development. + + WARNING: Never do 'make oldconfig' (OR 'make menuconfig') on a + configuration that has not been converted to use the kconfig-frontends + tools! This will damage your configuration (see + http://www.nuttx.org/doku.php?id=wiki:howtos:convertconfig). + Incompatibilities with Older Configurations ------------------------------------------- diff --git a/nuttx/configs/sim/nsh/defconfig b/nuttx/configs/sim/nsh/defconfig index 7b72ac303..6b0b8400a 100644 --- a/nuttx/configs/sim/nsh/defconfig +++ b/nuttx/configs/sim/nsh/defconfig @@ -56,7 +56,7 @@ CONFIG_ARCH_SIM=y # CONFIG_ARCH_Z16 is not set # CONFIG_ARCH_Z80 is not set CONFIG_ARCH="sim" -CONFIG_BOARD_LOOPSPERMSEC= +CONFIG_BOARD_LOOPSPERMSEC=0 # # Simulation Configuration Options @@ -64,6 +64,10 @@ CONFIG_BOARD_LOOPSPERMSEC= # CONFIG_SIM_M32 is not set # CONFIG_SIM_WALLTIME is not set +# +# External Memory Configuration +# + # # Architecture Options # @@ -81,8 +85,8 @@ CONFIG_BOARD_LOOPSPERMSEC= # # Board Settings # -CONFIG_DRAM_START= -CONFIG_DRAM_SIZE= +CONFIG_DRAM_START=0x0 +CONFIG_DRAM_SIZE=0 # # Boot options @@ -117,6 +121,7 @@ CONFIG_RR_INTERVAL=0 # CONFIG_SCHED_INSTRUMENTATION is not set CONFIG_TASK_NAME_SIZE=32 CONFIG_SCHED_HAVE_PARENT=y +# CONFIG_SCHED_CHILD_STATUS is not set # CONFIG_JULIAN_TIME is not set CONFIG_START_YEAR=2008 CONFIG_START_MONTH=6 @@ -129,6 +134,7 @@ CONFIG_DEV_CONSOLE=y CONFIG_SDCLONE_DISABLE=y # CONFIG_SCHED_WORKQUEUE is not set CONFIG_SCHED_WAITPID=y +# CONFIG_SCHED_STARTHOOK is not set # CONFIG_SCHED_ATEXIT is not set CONFIG_SCHED_ONEXIT=y CONFIG_SCHED_ONEXIT_MAX=1 @@ -139,9 +145,7 @@ CONFIG_DISABLE_OS_API=y # CONFIG_DISABLE_PTHREAD is not set # CONFIG_DISABLE_SIGNALS is not set # CONFIG_DISABLE_MQUEUE is not set -# CONFIG_DISABLE_MOUNTPOINT is not set # CONFIG_DISABLE_ENVIRON is not set -CONFIG_DISABLE_POLL=y # # Signal Numbers @@ -178,6 +182,7 @@ CONFIG_PTHREAD_STACK_DEFAULT=8192 # # Device Drivers # +CONFIG_DISABLE_POLL=y CONFIG_DEV_NULL=y # CONFIG_DEV_ZERO is not set # CONFIG_LOOP is not set @@ -228,6 +233,7 @@ CONFIG_SERIAL=y # # File system configuration # +# CONFIG_DISABLE_MOUNTPOINT is not set # CONFIG_FS_RAMMAP is not set CONFIG_FS_FAT=y CONFIG_FAT_LCNAMES=y @@ -338,7 +344,6 @@ CONFIG_EXAMPLES_HELLO=y # CONFIG_EXAMPLES_MM is not set # CONFIG_EXAMPLES_MOUNT is not set # CONFIG_EXAMPLES_MODBUS is not set -# CONFIG_EXAMPLES_NETTEST is not set CONFIG_EXAMPLES_NSH=y # CONFIG_EXAMPLES_NULL is not set # CONFIG_EXAMPLES_NX is not set @@ -352,7 +357,6 @@ CONFIG_EXAMPLES_NSH=y # CONFIG_EXAMPLES_OSTEST is not set # CONFIG_EXAMPLES_PASHELLO is not set # CONFIG_EXAMPLES_PIPE is not set -# CONFIG_EXAMPLES_POLL is not set # CONFIG_EXAMPLES_POSIXSPAWN is not set # CONFIG_EXAMPLES_QENCODER is not set # CONFIG_EXAMPLES_RGMP is not set diff --git a/nuttx/configs/stm32f4discovery/README.txt b/nuttx/configs/stm32f4discovery/README.txt index 207ee6cde..e34168224 100644 --- a/nuttx/configs/stm32f4discovery/README.txt +++ b/nuttx/configs/stm32f4discovery/README.txt @@ -1235,10 +1235,11 @@ Where is one of the following: 7. USB Support (CDC/ACM device) - CONFIG_STM32_OTGFS=y : STM32 OTG FS support - CONFIG_USBDEV=y : USB device support must be enabled - CONFIG_CDCACM=y : The CDC/ACM driver must be built - CONFIG_NSH_BUILTIN_APPS=y : NSH built-in application support must be enabled + CONFIG_STM32_OTGFS=y : STM32 OTG FS support + CONFIG_USBDEV=y : USB device support must be enabled + CONFIG_CDCACM=y : The CDC/ACM driver must be built + CONFIG_NSH_BUILTIN_APPS=y : NSH built-in application support must be enabled + CONFIG_NSH_ARCHINIT=y : To perform USB initialization 8. Using the USB console. @@ -1246,11 +1247,12 @@ Where is one of the following: (or PL2303) USB console. The normal way that you would configure the the USB console would be to change the .config file like this: - CONFIG_STM32_OTGFS=y : STM32 OTG FS support - CONFIG_DEV_CONSOLE=n : Inhibit use of /dev/console by other logic - CONFIG_USBDEV=y : USB device support must be enabled - CONFIG_CDCACM=y : The CDC/ACM driver must be built - CONFIG_CDCACM_CONSOLE=y : Enable the CDC/ACM USB console. + CONFIG_STM32_OTGFS=y : STM32 OTG FS support + CONFIG_USART2_SERIAL_CONSOLE=n : Disable the USART2 console + CONFIG_DEV_CONSOLE=n : Inhibit use of /dev/console by other logic + CONFIG_USBDEV=y : USB device support must be enabled + CONFIG_CDCACM=y : The CDC/ACM driver must be built + CONFIG_CDCACM_CONSOLE=y : Enable the CDC/ACM USB console. However, that configuration does not work. It fails early probably because of some dependency on /dev/console before the USB connection is established. @@ -1260,11 +1262,12 @@ Where is one of the following: but this version will will use /dev/console. Instead, it will use the normal /dev/ttyACM0 USB serial device for the console: - CONFIG_STM32_OTGFS=y : STM32 OTG FS support - CONFIG_USBDEV=y : USB device support must be enabled - CONFIG_CDCACM=y : The CDC/ACM driver must be built - CONFIG_CDCACM_CONSOLE=n : Done use the CDC/ACM USB console. - CONFIG_NSH_USBCONSOLE=y : Instead use some other USB device for the console + CONFIG_STM32_OTGFS=y : STM32 OTG FS support + CONFIG_USART2_SERIAL_CONSOLE=n : Disable the USART2 console + CONFIG_USBDEV=y : USB device support must be enabled + CONFIG_CDCACM=y : The CDC/ACM driver must be built + CONFIG_CDCACM_CONSOLE=n : Don't use the CDC/ACM USB console. + CONFIG_NSH_USBCONSOLE=y : Instead use some other USB device for the console The particular USB device that is used is: diff --git a/nuttx/configs/stm32f4discovery/usbnsh/defconfig b/nuttx/configs/stm32f4discovery/usbnsh/defconfig index 3ddcab424..534445f01 100644 --- a/nuttx/configs/stm32f4discovery/usbnsh/defconfig +++ b/nuttx/configs/stm32f4discovery/usbnsh/defconfig @@ -292,7 +292,7 @@ CONFIG_TASK_NAME_SIZE=0 CONFIG_START_YEAR=2013 CONFIG_START_MONTH=1 CONFIG_START_DAY=27 -CONFIG_DEV_CONSOLE=y +# CONFIG_DEV_CONSOLE is not set # CONFIG_MUTEX_TYPES is not set # CONFIG_PRIORITY_INHERITANCE is not set # CONFIG_FDCLONE_DISABLE is not set @@ -406,19 +406,19 @@ CONFIG_USBDEV_SELFPOWERED=y CONFIG_CDCACM=y CONFIG_CDCACM_CONSOLE=y CONFIG_CDCACM_EP0MAXPACKET=64 -CONFIG_CDCACM_EPINTIN=2 +CONFIG_CDCACM_EPINTIN=1 CONFIG_CDCACM_EPINTIN_FSSIZE=64 CONFIG_CDCACM_EPINTIN_HSSIZE=64 -CONFIG_CDCACM_EPBULKOUT=0 +CONFIG_CDCACM_EPBULKOUT=3 CONFIG_CDCACM_EPBULKOUT_FSSIZE=64 CONFIG_CDCACM_EPBULKOUT_HSSIZE=512 -CONFIG_CDCACM_EPBULKIN=0 +CONFIG_CDCACM_EPBULKIN=2 CONFIG_CDCACM_EPBULKIN_FSSIZE=64 CONFIG_CDCACM_EPBULKIN_HSSIZE=512 CONFIG_CDCACM_NWRREQS=4 CONFIG_CDCACM_NRDREQS=4 CONFIG_CDCACM_RXBUFSIZE=256 -# CONFIG_CDCACM_TXBUFSIZE is not set +CONFIG_CDCACM_TXBUFSIZE=256 CONFIG_CDCACM_VENDORID=0x0525 CONFIG_CDCACM_PRODUCTID=0xa4a7 CONFIG_CDCACM_VENDORSTR="NuttX" diff --git a/nuttx/drivers/usbdev/Kconfig b/nuttx/drivers/usbdev/Kconfig index 6fa4124be..5ab6bb8fa 100644 --- a/nuttx/drivers/usbdev/Kconfig +++ b/nuttx/drivers/usbdev/Kconfig @@ -272,10 +272,10 @@ config CDCACM_EP0MAXPACKET config CDCACM_EPINTIN int "Hardware endpoint that supports interrupt IN operation" - default 2 + default 1 ---help--- The logical 7-bit address of a hardware endpoint that supports - interrupt IN operation. Default 2. + interrupt IN operation. Default 1. config CDCACM_EPINTIN_FSSIZE int "Endpoint in full speed size" @@ -293,10 +293,10 @@ config CDCACM_EPINTIN_HSSIZE config CDCACM_EPBULKOUT int "Endpoint bulk out" - default 0 + default 3 ---help--- The logical 7-bit address of a hardware endpoint that supports - bulk OUT operation + bulk OUT operation. Default: 3 config CDCACM_EPBULKOUT_FSSIZE int "Endpoint bulk out full speed size" @@ -314,10 +314,10 @@ config CDCACM_EPBULKOUT_HSSIZE config CDCACM_EPBULKIN int "Endpoint bulk in" - default 0 + default 2 ---help--- The logical 7-bit address of a hardware endpoint that supports - bulk IN operation + bulk IN operation. Default: 2 config CDCACM_EPBULKIN_FSSIZE int "Endpoint bulk in full speed size" @@ -352,7 +352,7 @@ config CDCACM_RXBUFSIZE Size of the serial receive/transmit buffers config CDCACM_TXBUFSIZE - bool "Transmit buffer size" + int "Transmit buffer size" default 256 ---help--- Size of the serial receive/transmit buffers diff --git a/nuttx/include/nuttx/usb/cdcacm.h b/nuttx/include/nuttx/usb/cdcacm.h index 1dca050c4..49dc4ee12 100644 --- a/nuttx/include/nuttx/usb/cdcacm.h +++ b/nuttx/include/nuttx/usb/cdcacm.h @@ -54,7 +54,7 @@ * Endpoint 0 max packet size. Default 64. * CONFIG_CDCACM_EPINTIN * The logical 7-bit address of a hardware endpoint that supports - * interrupt IN operation. Default 2. + * interrupt IN operation. Default 1. * CONFIG_CDCACM_EPINTIN_FSSIZE * Max package size for the interrupt IN endpoint if full speed mode. * Default 64. @@ -63,7 +63,7 @@ * Default 64. * CONFIG_CDCACM_EPBULKOUT * The logical 7-bit address of a hardware endpoint that supports - * bulk OUT operation + * bulk OUT operation. Default: 3 * CONFIG_CDCACM_EPBULKOUT_FSSIZE * Max package size for the bulk OUT endpoint if full speed mode. * Default 64. @@ -72,7 +72,7 @@ * Default 512. * CONFIG_CDCACM_EPBULKIN * The logical 7-bit address of a hardware endpoint that supports - * bulk IN operation + * bulk IN operation. Default: 2 * CONFIG_CDCACM_EPBULKIN_FSSIZE * Max package size for the bulk IN endpoint if full speed mode. * Default 64. @@ -107,7 +107,7 @@ */ #ifndef CONFIG_CDCACM_EPINTIN -# define CONFIG_CDCACM_EPINTIN 2 +# define CONFIG_CDCACM_EPINTIN 1 #endif #ifndef CONFIG_CDCACM_EPINTIN_FSSIZE @@ -124,7 +124,7 @@ */ #ifndef CONFIG_CDCACM_EPBULKIN -# define CONFIG_CDCACM_EPBULKIN 3 +# define CONFIG_CDCACM_EPBULKIN 2 #endif #ifndef CONFIG_CDCACM_EPBULKIN_FSSIZE @@ -141,7 +141,7 @@ */ #ifndef CONFIG_CDCACM_EPBULKOUT -# define CONFIG_CDCACM_EPBULKOUT 4 +# define CONFIG_CDCACM_EPBULKOUT 3 #endif #ifndef CONFIG_CDCACM_EPBULKOUT_FSSIZE -- cgit v1.2.3 From cc99071a6827580d7b9c403a907605777522ab5f Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 28 Jan 2013 15:03:17 +0000 Subject: Serial driver needed even when no console; Fix user LED settings in all STM32 configurations git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5575 42af7a65-404d-4744-a932-0658087f49c3 --- misc/tools/README.txt | 21 ++++++++++---- nuttx/ChangeLog | 7 +++++ nuttx/arch/arm/src/common/up_initialize.c | 14 +++++++--- nuttx/arch/arm/src/common/up_internal.h | 17 ++++++++++-- nuttx/arch/avr/src/at32uc3/at32uc3_config.h | 17 ++++++++++-- nuttx/arch/avr/src/at90usb/at90usb_config.h | 17 ++++++++++-- nuttx/arch/avr/src/atmega/atmega_config.h | 17 ++++++++++-- nuttx/arch/avr/src/common/up_initialize.c | 28 ++++++++++++++++--- nuttx/arch/hc/src/common/up_initialize.c | 14 +++++++--- nuttx/arch/hc/src/common/up_internal.h | 17 ++++++++++-- nuttx/arch/mips/src/common/up_initialize.c | 12 ++++++-- nuttx/arch/mips/src/common/up_internal.h | 15 +++++++++- nuttx/arch/sh/src/common/up_initialize.c | 22 +++++++++------ nuttx/arch/sh/src/common/up_internal.h | 15 +++++++++- nuttx/arch/x86/src/common/up_initialize.c | 14 +++++++--- nuttx/arch/x86/src/common/up_internal.h | 17 ++++++++++-- nuttx/arch/z16/src/common/up_initialize.c | 6 ++-- nuttx/arch/z16/src/common/up_internal.h | 35 +++++++++++++++++++++--- nuttx/arch/z80/src/common/up_initialize.c | 14 +++++----- nuttx/arch/z80/src/common/up_internal.h | 31 +++++++++++++++++++-- nuttx/configs/cloudctrl/src/up_userleds.c | 8 +++--- nuttx/configs/fire-stm32v2/src/up_userleds.c | 6 ++-- nuttx/configs/lpc4330-xplorer/src/up_userleds.c | 8 +++--- nuttx/configs/shenzhou/src/up_userleds.c | 8 +++--- nuttx/configs/stm3220g-eval/src/up_userleds.c | 8 +++--- nuttx/configs/stm3240g-eval/src/up_userleds.c | 8 +++--- nuttx/configs/stm32f4discovery/README.txt | 2 +- nuttx/configs/stm32f4discovery/src/up_userleds.c | 8 +++--- 28 files changed, 314 insertions(+), 92 deletions(-) diff --git a/misc/tools/README.txt b/misc/tools/README.txt index 1546c6f39..e1c67c5f0 100644 --- a/misc/tools/README.txt +++ b/misc/tools/README.txt @@ -30,25 +30,34 @@ kconfig-frontends General build instructions: cd kconfig-frontends - ./configure + ./configure --enable-mconf make make install - To suppress the nconf and the graphical interfaces which are not used by - NuttX: + It is a good idea to add '--enable-mconf' on the 'configure' command line. + The kconfig-frontends make will generate many programs, but the NuttX + build system only needs the 'kconfig-conf' and 'kconfig-mconf' programs. + If the requirements for 'kconfig-mconf' are not supported by your system, + the kconfig-frontends configuration system will not build it. Adding the + option --enable-mconf assures you that 'kconfig-mconf' will be built or + if it is not built, it will tell you why it was not built. - ./configure --disable-gconf --disable-qconf + To suppress the 'nconf' and the graphical front-ends which are not used by + NuttX, you can add: + + ./configure --enable-mconfig --disable-nconf --disable-gconf --disable-qconf make make install To suppress the graphical interfaces, use static libraries, and disable creation of other utilities: - ./configure --disable-shared --enable-static --disable-gconf --disable-qconf --disable-nconf --disable-utils + ./configure --disable-shared --enable-static --enable-mconfig --disable-nconf --disable-gconf --disable-qconf --disable-nconf --disable-utils make make install - You may require root privileges to 'make install'. + The default installation location for the tools is /usr/local/bin. You + may require root privileges to 'make install'. --program-prefix= ----------------- diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 4fc75c084..c2ce13738 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4050,4 +4050,11 @@ configuration that uses USB CDC/ACM for the NSH console. * configs/stm32f4discovery/nsh: Converted to use the kconfig-frontends tools. + * configs/*/src/up_userleds.c: Fix a error that was cloned into + all STM32 user LED code. The wrong defintions were being used + to set LEDs on or off. + * arch/*/common/up_internal.h and arch/*/common/up_initialize.c: + Serial was driver was not being built if there is no console + device. Obviously, the serial driver may be needed even in + this case. diff --git a/nuttx/arch/arm/src/common/up_initialize.c b/nuttx/arch/arm/src/common/up_initialize.c index 80f9b1193..0ea3fcd35 100644 --- a/nuttx/arch/arm/src/common/up_initialize.c +++ b/nuttx/arch/arm/src/common/up_initialize.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/common/up_initialize.c * - * Copyright (C) 2007-2010, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2010, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -161,11 +161,17 @@ void up_initialize(void) devnull_register(); /* Standard /dev/null */ #endif - /* Initialize the console device driver */ + /* Initialize the serial device driver */ -#if defined(USE_SERIALDRIVER) +#ifdef USE_SERIALDRIVER up_serialinit(); -#elif defined(CONFIG_DEV_LOWCONSOLE) +#endif + + /* Initialize the console device driver (if it is other than the standard + * serial driver). + */ + +#if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); diff --git a/nuttx/arch/arm/src/common/up_internal.h b/nuttx/arch/arm/src/common/up_internal.h index 55071345f..8a24f003e 100644 --- a/nuttx/arch/arm/src/common/up_internal.h +++ b/nuttx/arch/arm/src/common/up_internal.h @@ -1,7 +1,7 @@ /**************************************************************************** * common/up_internal.h * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -63,7 +63,10 @@ #undef CONFIG_SUPPRESS_UART_CONFIG /* DEFINED: Do not reconfig UART */ #undef CONFIG_DUMP_ON_EXIT /* DEFINED: Dump task state on exit */ -/* Determine which (if any) console driver to use */ +/* Determine which (if any) console driver to use. If a console is enabled + * and no other console device is specified, then a serial console is + * assumed. + */ #if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS == 0 # undef USE_SERIALDRIVER @@ -84,6 +87,16 @@ # endif #endif +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) +# define USE_SERIALDRIVER 1 +#endif + /* Determine which device to use as the system logging device */ #ifndef CONFIG_SYSLOG diff --git a/nuttx/arch/avr/src/at32uc3/at32uc3_config.h b/nuttx/arch/avr/src/at32uc3/at32uc3_config.h index 1f942591a..8867fae86 100644 --- a/nuttx/arch/avr/src/at32uc3/at32uc3_config.h +++ b/nuttx/arch/avr/src/at32uc3/at32uc3_config.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/avr/src/at32uc3/at32uc3_config.h * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -144,7 +144,10 @@ # undef HAVE_SERIAL_CONSOLE #endif -/* Determine which (if any) console driver to use */ +/* Determine which (if any) console driver to use. If a console is enabled + * and no other console device is specified, then a serial console is + * assumed. + */ #if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0 # undef USE_SERIALDRIVER @@ -168,6 +171,16 @@ # endif #endif +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) +# define USE_SERIALDRIVER 1 +#endif + /* Determine which device to use as the system logging device */ #ifndef CONFIG_SYSLOG diff --git a/nuttx/arch/avr/src/at90usb/at90usb_config.h b/nuttx/arch/avr/src/at90usb/at90usb_config.h index 0aa73053e..3f0d80a19 100644 --- a/nuttx/arch/avr/src/at90usb/at90usb_config.h +++ b/nuttx/arch/avr/src/at90usb/at90usb_config.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/avr/src/at90usb/at90usb_config.h * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -63,7 +63,10 @@ # undef HAVE_SERIAL_CONSOLE #endif -/* Determine which (if any) console driver to use */ +/* Determine which (if any) console driver to use. If a console is enabled + * and no other console device is specified, then a serial console is + * assumed. + */ #if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0 # undef USE_SERIALDRIVER @@ -87,6 +90,16 @@ # endif #endif +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) +# define USE_SERIALDRIVER 1 +#endif + /* Determine which device to use as the system logging device */ #ifndef CONFIG_SYSLOG diff --git a/nuttx/arch/avr/src/atmega/atmega_config.h b/nuttx/arch/avr/src/atmega/atmega_config.h index 3835fb459..5d784ccf3 100644 --- a/nuttx/arch/avr/src/atmega/atmega_config.h +++ b/nuttx/arch/avr/src/atmega/atmega_config.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/avr/src/atmega/atmega_config.h * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -68,7 +68,10 @@ # undef HAVE_SERIAL_CONSOLE #endif -/* Determine which (if any) console driver to use */ +/* Determine which (if any) console driver to use. If a console is enabled + * and no other console device is specified, then a serial console is + * assumed. + */ #if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0 # undef USE_SERIALDRIVER @@ -92,6 +95,16 @@ # endif #endif +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) +# define USE_SERIALDRIVER 1 +#endif + /* Determine which device to use as the system logging device */ #ifndef CONFIG_SYSLOG diff --git a/nuttx/arch/avr/src/common/up_initialize.c b/nuttx/arch/avr/src/common/up_initialize.c index 76de41c99..684dab09d 100644 --- a/nuttx/arch/avr/src/common/up_initialize.c +++ b/nuttx/arch/avr/src/common/up_initialize.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/avr/src/common/up_initialize.c * - * Copyright (C) 2010, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -57,6 +57,10 @@ * up_serialinit to be incorrectly called if there is no USART configured to * be an RS-232 device (see as an example arch/avr/src/at32uc23/at32uc3_config.h) * This will probably have to be revisited someday. + * + * If a console is enabled and no other console device is specified, then a + * serial console is + * assumed. */ #if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0 @@ -78,6 +82,16 @@ # endif #endif +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) +# define USE_SERIALDRIVER 1 +#endif + /* Determine which device to use as the system logging device */ #ifndef CONFIG_SYSLOG @@ -182,11 +196,17 @@ void up_initialize(void) devnull_register(); /* Standard /dev/null */ #endif - /* Initialize the console device driver */ + /* Initialize the serial device driver */ -#if defined(USE_SERIALDRIVER) +#ifdef USE_SERIALDRIVER up_serialinit(); -#elif defined(CONFIG_DEV_LOWCONSOLE) +#endif + + /* Initialize the console device driver (if it is other than the standard + * serial driver). + */ + +#if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); diff --git a/nuttx/arch/hc/src/common/up_initialize.c b/nuttx/arch/hc/src/common/up_initialize.c index b9dfd9ba1..885e79905 100644 --- a/nuttx/arch/hc/src/common/up_initialize.c +++ b/nuttx/arch/hc/src/common/up_initialize.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/hc/src/common/up_initialize.c * - * Copyright (C) 2009-2010, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -149,11 +149,17 @@ void up_initialize(void) devnull_register(); /* Standard /dev/null */ #endif - /* Initialize the console device driver */ + /* Initialize the serial device driver */ -#if defined(USE_SERIALDRIVER) +#ifdef USE_SERIALDRIVER up_serialinit(); -#elif defined(CONFIG_DEV_LOWCONSOLE) +#endif + + /* Initialize the console device driver (if it is other than the standard + * serial driver). + */ + +#if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); diff --git a/nuttx/arch/hc/src/common/up_internal.h b/nuttx/arch/hc/src/common/up_internal.h index f1daf690f..0de737fb6 100644 --- a/nuttx/arch/hc/src/common/up_internal.h +++ b/nuttx/arch/hc/src/common/up_internal.h @@ -1,7 +1,7 @@ /**************************************************************************** * arch/hc/src/common/up_internal.h * - * Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -62,7 +62,10 @@ #undef CONFIG_SUPPRESS_UART_CONFIG /* DEFINED: Do not reconfig UART */ #undef CONFIG_DUMP_ON_EXIT /* DEFINED: Dump task state on exit */ -/* Determine which (if any) console driver to use */ +/* Determine which (if any) console driver to use. If a console is enabled + * and no other console device is specified, then a serial console is + * assumed. + */ #if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0 # undef USE_SERIALDRIVER @@ -83,6 +86,16 @@ # endif #endif +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) +# define USE_SERIALDRIVER 1 +#endif + /* Determine which device to use as the system logging device */ #ifndef CONFIG_SYSLOG diff --git a/nuttx/arch/mips/src/common/up_initialize.c b/nuttx/arch/mips/src/common/up_initialize.c index 3063b4b4b..a0f0ca9d5 100644 --- a/nuttx/arch/mips/src/common/up_initialize.c +++ b/nuttx/arch/mips/src/common/up_initialize.c @@ -151,11 +151,17 @@ void up_initialize(void) devnull_register(); /* Standard /dev/null */ #endif - /* Initialize the console device driver */ + /* Initialize the serial device driver */ -#if defined(USE_SERIALDRIVER) +#ifdef USE_SERIALDRIVER up_serialinit(); -#elif defined(CONFIG_DEV_LOWCONSOLE) +#endif + + /* Initialize the console device driver (if it is other than the standard + * serial driver). + */ + +#if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); diff --git a/nuttx/arch/mips/src/common/up_internal.h b/nuttx/arch/mips/src/common/up_internal.h index b284961b0..927538dea 100644 --- a/nuttx/arch/mips/src/common/up_internal.h +++ b/nuttx/arch/mips/src/common/up_internal.h @@ -60,7 +60,10 @@ #undef CONFIG_SUPPRESS_UART_CONFIG /* DEFINED: Do not reconfig UART */ #undef CONFIG_DUMP_ON_EXIT /* DEFINED: Dump task state on exit */ -/* Determine which (if any) console driver to use */ +/* Determine which (if any) console driver to use. If a console is enabled + * and no other console device is specified, then a serial console is + * assumed. + */ #if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0 # undef USE_SERIALDRIVER @@ -81,6 +84,16 @@ # endif #endif +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) +# define USE_SERIALDRIVER 1 +#endif + /* Determine which device to use as the system logging device */ #ifndef CONFIG_SYSLOG diff --git a/nuttx/arch/sh/src/common/up_initialize.c b/nuttx/arch/sh/src/common/up_initialize.c index 3aef5c637..727dc1352 100644 --- a/nuttx/arch/sh/src/common/up_initialize.c +++ b/nuttx/arch/sh/src/common/up_initialize.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/sh/src/common/up_initialize.c * - * Copyright (C) 2008-2010, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2010, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -136,16 +136,20 @@ void up_initialize(void) devnull_register(); /* Standard /dev/null */ #endif - /* Initialize the console device driver. NOTE that the naming - * implies that the console is a serial driver. That is usually the case, - * however, if no UARTs are enabled, the console could als be provided - * through some other device, such as an LCD. Architecture-specific logic - * will have to detect that case. + /* Initialize the serial device driver */ + +#ifdef USE_SERIALDRIVER + up_serialinit(); +#endif + + /* Initialize the console device driver (if it is other than the standard + * serial driver). NOTE that the naming implies that the console is a serial + * driver. That is usually the case, however, if no UARTs are enabled, the + * console could als be provided through some other device, such as an LCD. + * Architecture-specific logic will have to detect that case. */ -#if defined(USE_SERIALDRIVER) - up_consoleinit(); -#elif defined(CONFIG_DEV_LOWCONSOLE) +#if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); diff --git a/nuttx/arch/sh/src/common/up_internal.h b/nuttx/arch/sh/src/common/up_internal.h index f47b1078f..f56e97c97 100644 --- a/nuttx/arch/sh/src/common/up_internal.h +++ b/nuttx/arch/sh/src/common/up_internal.h @@ -1,7 +1,7 @@ /**************************************************************************** * arch/sh/src/common/up_internal.h * - * Copyright (C) 2008-2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -67,6 +67,9 @@ * however, if no UARTs are enabled, the console could als be provided * through some other device, such as an LCD. Architecture-specific logic * will have to detect that case. + * + * If a console is enabled and no other console device is specified, then + * a serial console is assumed. */ #if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0 @@ -88,6 +91,16 @@ # endif #endif +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) +# define USE_SERIALDRIVER 1 +#endif + /* Determine which device to use as the system logging device */ #ifndef CONFIG_SYSLOG diff --git a/nuttx/arch/x86/src/common/up_initialize.c b/nuttx/arch/x86/src/common/up_initialize.c index 49238556d..b49dd55b4 100644 --- a/nuttx/arch/x86/src/common/up_initialize.c +++ b/nuttx/arch/x86/src/common/up_initialize.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/x86/src/common/up_initialize.c * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -151,11 +151,17 @@ void up_initialize(void) devnull_register(); /* Standard /dev/null */ #endif - /* Initialize the console device driver */ + /* Initialize the serial device driver */ -#if defined(USE_SERIALDRIVER) +#ifdef USE_SERIALDRIVER up_serialinit(); -#elif defined(CONFIG_DEV_LOWCONSOLE) +#endif + + /* Initialize the console device driver (if it is other than the standard + * serial driver). + */ + +#if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); diff --git a/nuttx/arch/x86/src/common/up_internal.h b/nuttx/arch/x86/src/common/up_internal.h index df43ca1a8..c27717c38 100644 --- a/nuttx/arch/x86/src/common/up_internal.h +++ b/nuttx/arch/x86/src/common/up_internal.h @@ -1,7 +1,7 @@ /**************************************************************************** * arch/x86/src/common/up_internal.h * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -62,7 +62,10 @@ #undef CONFIG_SUPPRESS_UART_CONFIG /* DEFINED: Do not reconfig UART */ #undef CONFIG_DUMP_ON_EXIT /* DEFINED: Dump task state on exit */ -/* Determine which (if any) console driver to use */ +/* Determine which (if any) console driver to use. If a console is enabled + * and no other console device is specified, then a serial console is + * assumed. + */ #if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0 # undef USE_SERIALDRIVER @@ -83,6 +86,16 @@ # endif #endif +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) +# define USE_SERIALDRIVER 1 +#endif + /* Determine which device to use as the system logging device */ #ifndef CONFIG_SYSLOG diff --git a/nuttx/arch/z16/src/common/up_initialize.c b/nuttx/arch/z16/src/common/up_initialize.c index e9c58c489..f06d8ff24 100644 --- a/nuttx/arch/z16/src/common/up_initialize.c +++ b/nuttx/arch/z16/src/common/up_initialize.c @@ -1,7 +1,7 @@ /**************************************************************************** * common/up_initialize.c * - * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -168,7 +168,9 @@ void up_initialize(void) up_serialinit(); #endif - /* Initialize the console device driver */ + /* Initialize the console device driver (if it is other than the standard + * serial driver). + */ #if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); diff --git a/nuttx/arch/z16/src/common/up_internal.h b/nuttx/arch/z16/src/common/up_internal.h index 2c1968e8d..e4dfd1dd5 100644 --- a/nuttx/arch/z16/src/common/up_internal.h +++ b/nuttx/arch/z16/src/common/up_internal.h @@ -1,7 +1,7 @@ /**************************************************************************** * common/up_internal.h * - * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -60,15 +60,42 @@ #undef CONFIG_Z16_LOWPUTC /* Support up_lowputc for debug */ #undef CONFIG_Z16_LOWGETC /* support up_lowgetc for debug */ -/* Determine which (if any) console driver to use */ +/* Determine which (if any) console driver to use. If a console is enabled + * and no other console device is specified, then a serial console is + * assumed. + */ #if defined(CONFIG_Z16_LOWPUTC) || defined(CONFIG_Z16_LOWGETC) || \ CONFIG_NFILE_DESCRIPTORS == 0 || defined(CONFIG_DEV_LOWCONSOLE) # define USE_LOWCONSOLE 1 # define USE_LOWUARTINIT 1 -#elif defined(CONFIG_DEV_CONSOLE) && CONFIG_NFILE_DESCRIPTORS > 0 +#elif !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0 +# undef USE_SERIALDRIVER +# undef USE_EARLYSERIALINIT +# undef CONFIG_DEV_LOWCONSOLE +# undef CONFIG_RAMLOG_CONSOLE +#else +# if defined(CONFIG_RAMLOG_CONSOLE) +# undef USE_SERIALDRIVER +# undef USE_EARLYSERIALINIT +# undef CONFIG_DEV_LOWCONSOLE +# elif defined(CONFIG_DEV_LOWCONSOLE) +# undef USE_SERIALDRIVER +# undef USE_EARLYSERIALINIT +# else +# define USE_SERIALDRIVER 1 +# define USE_EARLYSERIALINIT 1 +# endif +#endif + +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) # define USE_SERIALDRIVER 1 -# define USE_EARLYSERIALINIT 1 #endif /* Determine which device to use as the system logging device */ diff --git a/nuttx/arch/z80/src/common/up_initialize.c b/nuttx/arch/z80/src/common/up_initialize.c index 652a7cc88..c7b7bdb22 100644 --- a/nuttx/arch/z80/src/common/up_initialize.c +++ b/nuttx/arch/z80/src/common/up_initialize.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/common/up_initialize.c * - * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -161,15 +161,15 @@ void up_initialize(void) /* Initialize the serial device driver */ -#ifdef USE_LOWSERIALINIT - up_lowserialinit(); +#ifdef USE_SERIALDRIVER + up_serialinit(); #endif - /* Initialize the console device driver */ + /* Initialize the console device driver (if it is other than the standard + * serial driver). + */ -#if defined(USE_SERIALDRIVER) - up_serialinit(); -#elif defined(CONFIG_DEV_LOWCONSOLE) +#if defined(CONFIG_DEV_LOWCONSOLE) lowconsole_init(); #elif defined(CONFIG_RAMLOG_CONSOLE) ramlog_consoleinit(); diff --git a/nuttx/arch/z80/src/common/up_internal.h b/nuttx/arch/z80/src/common/up_internal.h index 5f1750b64..36e1ac141 100644 --- a/nuttx/arch/z80/src/common/up_internal.h +++ b/nuttx/arch/z80/src/common/up_internal.h @@ -66,7 +66,10 @@ * Definitions ****************************************************************************/ -/* Determine which (if any) console driver to use */ +/* Determine which (if any) console driver to use. If a console is enabled + * and no other console device is specified, then a serial console is + * assumed. + */ #if CONFIG_NFILE_DESCRIPTORS == 0 || defined(CONFIG_DEV_LOWCONSOLE) # undef USE_SERIALDRIVER @@ -75,9 +78,31 @@ # else # undef USE_LOWSERIALINIT # endif -#elif defined(CONFIG_DEV_CONSOLE) && CONFIG_NFILE_DESCRIPTORS > 0 +#elif !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0 +# undef USE_SERIALDRIVER +# undef USE_LOWSERIALINIT +# undef CONFIG_DEV_LOWCONSOLE +# undef CONFIG_RAMLOG_CONSOLE +#else +# undef USE_LOWSERIALINIT +# if defined(CONFIG_RAMLOG_CONSOLE) +# undef USE_SERIALDRIVER +# undef CONFIG_DEV_LOWCONSOLE +# elif defined(CONFIG_DEV_LOWCONSOLE) +# undef USE_SERIALDRIVER +# else +# define USE_SERIALDRIVER 1 +# endif +#endif + +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) # define USE_SERIALDRIVER 1 -# undef USE_LOWSERIALINIT #endif /**************************************************************************** diff --git a/nuttx/configs/cloudctrl/src/up_userleds.c b/nuttx/configs/cloudctrl/src/up_userleds.c index 5c112123b..bbb7cc62c 100644 --- a/nuttx/configs/cloudctrl/src/up_userleds.c +++ b/nuttx/configs/cloudctrl/src/up_userleds.c @@ -123,10 +123,10 @@ void stm32_setled(int led, bool ledon) void stm32_setleds(uint8_t ledset) { - stm32_gpiowrite(BOARD_LED1, (ledset & BOARD_LED1_BIT) == 0); - stm32_gpiowrite(BOARD_LED2, (ledset & BOARD_LED2_BIT) == 0); - stm32_gpiowrite(BOARD_LED3, (ledset & BOARD_LED3_BIT) == 0); - stm32_gpiowrite(BOARD_LED4, (ledset & BOARD_LED4_BIT) == 0); + stm32_gpiowrite(GPIO_LED1, (ledset & BOARD_LED1_BIT) == 0); + stm32_gpiowrite(GPIO_LED2, (ledset & BOARD_LED2_BIT) == 0); + stm32_gpiowrite(GPIO_LED3, (ledset & BOARD_LED3_BIT) == 0); + stm32_gpiowrite(GPIO_LED4, (ledset & BOARD_LED4_BIT) == 0); } #endif /* !CONFIG_ARCH_LEDS */ diff --git a/nuttx/configs/fire-stm32v2/src/up_userleds.c b/nuttx/configs/fire-stm32v2/src/up_userleds.c index da43d03ad..3dd1843ee 100644 --- a/nuttx/configs/fire-stm32v2/src/up_userleds.c +++ b/nuttx/configs/fire-stm32v2/src/up_userleds.c @@ -131,9 +131,9 @@ void stm32_setled(int led, bool ledon) void stm32_setleds(uint8_t ledset) { - stm32_gpiowrite(BOARD_LED1, (ledset & BOARD_LED1_BIT) == 0); - stm32_gpiowrite(BOARD_LED2, (ledset & BOARD_LED2_BIT) == 0); - stm32_gpiowrite(BOARD_LED3, (ledset & BOARD_LED3_BIT) == 0); + stm32_gpiowrite(GPIO_LED1, (ledset & BOARD_LED1_BIT) == 0); + stm32_gpiowrite(GPIO_LED2, (ledset & BOARD_LED2_BIT) == 0); + stm32_gpiowrite(GPIO_LED3, (ledset & BOARD_LED3_BIT) == 0); } #endif /* !CONFIG_ARCH_LEDS */ diff --git a/nuttx/configs/lpc4330-xplorer/src/up_userleds.c b/nuttx/configs/lpc4330-xplorer/src/up_userleds.c index e7b4b1189..2d8b5b511 100644 --- a/nuttx/configs/lpc4330-xplorer/src/up_userleds.c +++ b/nuttx/configs/lpc4330-xplorer/src/up_userleds.c @@ -140,8 +140,8 @@ void lpc43_ledinit(void) void lpc43_setled(int led, bool ledon) { - uint16_t gpiocfg = (led == BOARD_LED1 ? BOARD_LED1 : BOARD_LED2); - lpc43_gpio_write(GPIO_LED1, !ledon); + uint16_t gpiocfg = (led == BOARD_LED1 ? GPIO_LED1 : GPIO_LED2); + lpc43_gpio_write(gpiocfg, !ledon); } /**************************************************************************** @@ -150,8 +150,8 @@ void lpc43_setled(int led, bool ledon) void lpc43_setleds(uint8_t ledset) { - lpc43_gpio_write(BOARD_LED1, (ledset & BOARD_LED1_BIT) == 0); - lpc43_gpio_write(BOARD_LED2, (ledset & BOARD_LED2_BIT) == 0); + lpc43_gpio_write(GPIO_LED1, (ledset & BOARD_LED1_BIT) == 0); + lpc43_gpio_write(GPIO_LED2, (ledset & BOARD_LED2_BIT) == 0); } #endif /* !CONFIG_ARCH_LEDS */ diff --git a/nuttx/configs/shenzhou/src/up_userleds.c b/nuttx/configs/shenzhou/src/up_userleds.c index 0ba029228..4e1493a8d 100644 --- a/nuttx/configs/shenzhou/src/up_userleds.c +++ b/nuttx/configs/shenzhou/src/up_userleds.c @@ -122,10 +122,10 @@ void stm32_setled(int led, bool ledon) void stm32_setleds(uint8_t ledset) { - stm32_gpiowrite(BOARD_LED1, (ledset & BOARD_LED1_BIT) == 0); - stm32_gpiowrite(BOARD_LED2, (ledset & BOARD_LED2_BIT) == 0); - stm32_gpiowrite(BOARD_LED3, (ledset & BOARD_LED3_BIT) == 0); - stm32_gpiowrite(BOARD_LED4, (ledset & BOARD_LED4_BIT) == 0); + stm32_gpiowrite(GPIO_LED1, (ledset & BOARD_LED1_BIT) == 0); + stm32_gpiowrite(GPIO_LED2, (ledset & BOARD_LED2_BIT) == 0); + stm32_gpiowrite(GPIO_LED3, (ledset & BOARD_LED3_BIT) == 0); + stm32_gpiowrite(GPIO_LED4, (ledset & BOARD_LED4_BIT) == 0); } #endif /* !CONFIG_ARCH_LEDS */ diff --git a/nuttx/configs/stm3220g-eval/src/up_userleds.c b/nuttx/configs/stm3220g-eval/src/up_userleds.c index 6dc3db135..84510c703 100644 --- a/nuttx/configs/stm3220g-eval/src/up_userleds.c +++ b/nuttx/configs/stm3220g-eval/src/up_userleds.c @@ -122,10 +122,10 @@ void stm32_setled(int led, bool ledon) void stm32_setleds(uint8_t ledset) { - stm32_gpiowrite(BOARD_LED1, (ledset & BOARD_LED1_BIT) == 0); - stm32_gpiowrite(BOARD_LED2, (ledset & BOARD_LED2_BIT) == 0); - stm32_gpiowrite(BOARD_LED3, (ledset & BOARD_LED3_BIT) == 0); - stm32_gpiowrite(BOARD_LED4, (ledset & BOARD_LED4_BIT) == 0); + stm32_gpiowrite(GPIO_LED1, (ledset & BOARD_LED1_BIT) == 0); + stm32_gpiowrite(GPIO_LED2, (ledset & BOARD_LED2_BIT) == 0); + stm32_gpiowrite(GPIO_LED3, (ledset & BOARD_LED3_BIT) == 0); + stm32_gpiowrite(GPIO_LED4, (ledset & BOARD_LED4_BIT) == 0); } #endif /* !CONFIG_ARCH_LEDS */ diff --git a/nuttx/configs/stm3240g-eval/src/up_userleds.c b/nuttx/configs/stm3240g-eval/src/up_userleds.c index 59be38561..01c4b36d6 100644 --- a/nuttx/configs/stm3240g-eval/src/up_userleds.c +++ b/nuttx/configs/stm3240g-eval/src/up_userleds.c @@ -122,10 +122,10 @@ void stm32_setled(int led, bool ledon) void stm32_setleds(uint8_t ledset) { - stm32_gpiowrite(BOARD_LED1, (ledset & BOARD_LED1_BIT) == 0); - stm32_gpiowrite(BOARD_LED2, (ledset & BOARD_LED2_BIT) == 0); - stm32_gpiowrite(BOARD_LED3, (ledset & BOARD_LED3_BIT) == 0); - stm32_gpiowrite(BOARD_LED4, (ledset & BOARD_LED4_BIT) == 0); + stm32_gpiowrite(GPIO_LED1, (ledset & BOARD_LED1_BIT) == 0); + stm32_gpiowrite(GPIO_LED2, (ledset & BOARD_LED2_BIT) == 0); + stm32_gpiowrite(GPIO_LED3, (ledset & BOARD_LED3_BIT) == 0); + stm32_gpiowrite(GPIO_LED4, (ledset & BOARD_LED4_BIT) == 0); } #endif /* !CONFIG_ARCH_LEDS */ diff --git a/nuttx/configs/stm32f4discovery/README.txt b/nuttx/configs/stm32f4discovery/README.txt index e34168224..e9c0e81c2 100644 --- a/nuttx/configs/stm32f4discovery/README.txt +++ b/nuttx/configs/stm32f4discovery/README.txt @@ -269,7 +269,7 @@ LEDs ==== The STM32F4Discovery board has four LEDs; green, organge, red and blue on the -board.. These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is +board. These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is defined. In that case, the usage by the board port is defined in include/board.h and src/up_leds.c. The LEDs are used to encode OS-related events as follows: diff --git a/nuttx/configs/stm32f4discovery/src/up_userleds.c b/nuttx/configs/stm32f4discovery/src/up_userleds.c index 90adb4882..173c12696 100644 --- a/nuttx/configs/stm32f4discovery/src/up_userleds.c +++ b/nuttx/configs/stm32f4discovery/src/up_userleds.c @@ -222,10 +222,10 @@ void stm32_setled(int led, bool ledon) void stm32_setleds(uint8_t ledset) { - stm32_gpiowrite(BOARD_LED1, (ledset & BOARD_LED1_BIT) == 0); - stm32_gpiowrite(BOARD_LED2, (ledset & BOARD_LED2_BIT) == 0); - stm32_gpiowrite(BOARD_LED3, (ledset & BOARD_LED3_BIT) == 0); - stm32_gpiowrite(BOARD_LED4, (ledset & BOARD_LED4_BIT) == 0); + stm32_gpiowrite(GPIO_LED1, (ledset & BOARD_LED1_BIT) == 0); + stm32_gpiowrite(GPIO_LED2, (ledset & BOARD_LED2_BIT) == 0); + stm32_gpiowrite(GPIO_LED3, (ledset & BOARD_LED3_BIT) == 0); + stm32_gpiowrite(GPIO_LED4, (ledset & BOARD_LED4_BIT) == 0); } /**************************************************************************** -- cgit v1.2.3 From 12af0cacd651e051a01db21092c6c3aff07ebd97 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 28 Jan 2013 17:43:55 +0000 Subject: Misc SYSLOG and STM32 serial fixes git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5576 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 11 ++++++- nuttx/arch/arm/src/stm32/stm32_serial.c | 12 ++++---- nuttx/configs/stm32f4discovery/README.txt | 32 +------------------- nuttx/fs/fs_syslog.c | 49 +++++++++++++++++++++---------- nuttx/libc/stdio/lib_syslogstream.c | 16 +++++----- 5 files changed, 61 insertions(+), 59 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index c2ce13738..039a79f62 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4057,4 +4057,13 @@ Serial was driver was not being built if there is no console device. Obviously, the serial driver may be needed even in this case. - + * arch/arm/src/stm32/stm32_serial.c: If there is a serial console, + it would be ttyS0 and the others would be ttyS1-5. If there + is not serial console, was labeling them ttyS1-6; now labels them + ttyS0-5. + * fs/fs_syslog.c: Can't handle SYSLOG output to character device from + the IDLE task (because it can't block). syslog_putc now returns EOF + on failure and sets errno. Fixed some errors in error handling. + * libc/stdio/lib_syslogstream.c: Checking of return value from + syslog_putc was bogus. Switching to EOF for all errors solves + this. diff --git a/nuttx/arch/arm/src/stm32/stm32_serial.c b/nuttx/arch/arm/src/stm32/stm32_serial.c index 0151bd247..12da1ee10 100644 --- a/nuttx/arch/arm/src/stm32/stm32_serial.c +++ b/nuttx/arch/arm/src/stm32/stm32_serial.c @@ -1998,7 +1998,8 @@ void up_serialinit(void) { #ifdef HAVE_UART char devname[16]; - unsigned i, j; + unsigned i; + unsigned minor = 0; #ifdef CONFIG_PM int ret; #endif @@ -2015,6 +2016,7 @@ void up_serialinit(void) #if CONSOLE_UART > 0 (void)uart_register("/dev/console", &uart_devs[CONSOLE_UART - 1]->dev); (void)uart_register("/dev/ttyS0", &uart_devs[CONSOLE_UART - 1]->dev); + minor = 1; /* If we need to re-initialise the console to enable DMA do that here. */ @@ -2028,19 +2030,19 @@ void up_serialinit(void) strcpy(devname, "/dev/ttySx"); - for (i = 0, j = 1; i < STM32_NUSART; i++) + for (i = 0; i < STM32_NUSART; i++) { - /* don't create a device for the console - we did that above */ + /* Don't create a device for the console - we did that above */ if ((uart_devs[i] == 0) || (uart_devs[i]->dev.isconsole)) { continue; } - /* register USARTs as devices in increasing order */ + /* Register USARTs as devices in increasing order */ - devname[9] = '0' + j++; + devname[9] = '0' + minor++; (void)uart_register(devname, &uart_devs[i]->dev); } #endif /* HAVE UART */ diff --git a/nuttx/configs/stm32f4discovery/README.txt b/nuttx/configs/stm32f4discovery/README.txt index e9c0e81c2..378509be8 100644 --- a/nuttx/configs/stm32f4discovery/README.txt +++ b/nuttx/configs/stm32f4discovery/README.txt @@ -1254,40 +1254,10 @@ Where is one of the following: CONFIG_CDCACM=y : The CDC/ACM driver must be built CONFIG_CDCACM_CONSOLE=y : Enable the CDC/ACM USB console. - However, that configuration does not work. It fails early probably because - of some dependency on /dev/console before the USB connection is established. - - But there is a work around for this that works better (but has some side - effects). The following configuration will also create a NSH USB console - but this version will will use /dev/console. Instead, it will use the - normal /dev/ttyACM0 USB serial device for the console: - - CONFIG_STM32_OTGFS=y : STM32 OTG FS support - CONFIG_USART2_SERIAL_CONSOLE=n : Disable the USART2 console - CONFIG_USBDEV=y : USB device support must be enabled - CONFIG_CDCACM=y : The CDC/ACM driver must be built - CONFIG_CDCACM_CONSOLE=n : Don't use the CDC/ACM USB console. - CONFIG_NSH_USBCONSOLE=y : Instead use some other USB device for the console - - The particular USB device that is used is: - - CONFIG_NSH_USBCONDEV="/dev/ttyACM0" - - NOTE 1: When you first start the USB console, you have hit ENTER a few + NOTE: When you first start the USB console, you have hit ENTER a few times before NSH starts. The logic does this to prevent sending USB data before there is anything on the host side listening for USB serial input. - Now the side effects: - - NOTE 2. When any other device other than /dev/console is used for a user - interface, linefeeds (\n) will not be expanded to carriage return / - linefeeds (\r\n). You will need to set your terminal program to account - for this. - - NOTE 3: /dev/console still exists and still refers to the serial port. So - you can still use certain kinds of debug output (see include/debug.h, all - of the interfaces based on lib_lowprintf will work in this configuration). - 9. USB OTG FS Host Support. The following changes will enable support for a USB host on the STM32F4Discovery, including support for a mass storage class driver: diff --git a/nuttx/fs/fs_syslog.c b/nuttx/fs/fs_syslog.c index f348bdb03..ab6cec51e 100644 --- a/nuttx/fs/fs_syslog.c +++ b/nuttx/fs/fs_syslog.c @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -282,7 +283,7 @@ int syslog_initialize(void) if (!INODE_IS_DRIVER(inode)) #endif { - ret = ENXIO; + ret = -ENXIO; goto errout_with_inode; } @@ -290,7 +291,7 @@ int syslog_initialize(void) if (!inode->u.i_ops || !inode->u.i_ops->write) { - return -EACCES; + ret = -EACCES; goto errout_with_inode; } @@ -346,8 +347,8 @@ int syslog_initialize(void) return OK; errout_with_inode: - g_sysdev.sl_state = SYSLOG_FAILURE; inode_release(inode); + g_sysdev.sl_state = SYSLOG_FAILURE; return ret; } @@ -366,6 +367,8 @@ int syslog_initialize(void) int syslog_putc(int ch) { ssize_t nbytes; + uint8_t uch; + int errcode; int ret; /* Ignore any output: @@ -382,7 +385,10 @@ int syslog_putc(int ch) * (4) Any debug output generated from interrupt handlers. A disadvantage * of using the generic character device for the SYSLOG is that it * cannot handle debug output generated from interrupt level handlers. - * (5) If an irrecoverable failure occurred during initialization. In + * (5) Any debug output generated from the IDLE loop. The character + * driver interface is blocking and the IDLE thread is not permitted + * to block. + * (6) If an irrecoverable failure occurred during initialization. In * this case, we won't ever bother to try again (ever). * * NOTE: That the third case is different. It applies only to the thread @@ -390,11 +396,12 @@ int syslog_putc(int ch) * that is why that case is handled in syslog_semtake(). */ - /* Case (4) */ + /* Cases (4) and (5) */ - if (up_interrupt_context()) + if (up_interrupt_context() || getpid() == 0) { - return -ENOSYS; /* Not supported */ + errcode = ENOSYS; + goto errout_with_errcode; } /* We can save checks in the usual case: That after the SYSLOG device @@ -408,14 +415,16 @@ int syslog_putc(int ch) if (g_sysdev.sl_state == SYSLOG_UNINITIALIZED || g_sysdev.sl_state == SYSLOG_INITIALIZING) { - return -EAGAIN; /* Can't access the SYSLOG now... maybe next time? */ + errcode = EAGAIN; /* Can't access the SYSLOG now... maybe next time? */ + goto errout_with_errcode; } - /* Case (5) */ + /* Case (6) */ if (g_sysdev.sl_state == SYSLOG_FAILURE) { - return -ENXIO; /* There is no SYSLOG device */ + errcode = ENXIO; /* There is no SYSLOG device */ + goto errout_with_errcode; } /* syslog_initialize() is called as soon as enough of the operating @@ -443,7 +452,8 @@ int syslog_putc(int ch) if (ret < 0) { sched_unlock(); - return ret; + errcode = -ret; + goto errout_with_errcode; } } @@ -471,7 +481,8 @@ int syslog_putc(int ch) * way, we are outta here. */ - return ret; + errcode = -ret; + goto errout_with_errcode; } /* Pre-pend a newline with a carriage return. */ @@ -497,19 +508,27 @@ int syslog_putc(int ch) { /* Write the non-newline character (and don't flush) */ - nbytes = syslog_write(&ch, 1); + uch = (uint8_t)ch; + nbytes = syslog_write(&uch, 1); } syslog_givesem(); - /* Check if the write was successful */ + /* Check if the write was successful. If not, nbytes will be + * a negated errno value. + */ if (nbytes < 0) { - return nbytes; + errcode = -ret; + goto errout_with_errcode; } return ch; + +errout_with_errcode: + set_errno(errcode); + return EOF; } #endif /* CONFIG_SYSLOG && CONFIG_SYSLOG_CHAR */ diff --git a/nuttx/libc/stdio/lib_syslogstream.c b/nuttx/libc/stdio/lib_syslogstream.c index 5529c5de8..121227d3c 100644 --- a/nuttx/libc/stdio/lib_syslogstream.c +++ b/nuttx/libc/stdio/lib_syslogstream.c @@ -63,6 +63,7 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch) { + int errcode; int ret; /* Try writing until the write was successful or until an irrecoverable @@ -71,22 +72,23 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch) do { - /* Write the character to the supported logging device */ + /* Write the character to the supported logging device. On failure, + * syslog_putc returns EOF with the errno value set; + */ ret = syslog_putc(ch); - if (ret == OK) + if (ret != EOF) { this->nput++; return; } - /* On failure syslog_putc will return a negated errno value. The - * errno variable will not be set. The special value -EINTR means that - * syslog_putc() was awakened by a signal. This is not a real error and - * must be ignored in this context. + /* The special errno value -EINTR means that syslog_putc() was + * awakened by a signal. This is not a real error and must be + * ignored in this context. */ } - while (ret == -EINTR); + while (errno == -EINTR); } /**************************************************************************** -- cgit v1.2.3 From 433dae74225a98c5ed65834b8574eea90259e220 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 28 Jan 2013 18:45:09 +0000 Subject: Beginning of apps/system/usbmonitor (incomplete); more LM4F changes from JP git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5577 42af7a65-404d-4744-a932-0658087f49c3 --- apps/ChangeLog.txt | 2 + apps/system/Kconfig | 4 + apps/system/Make.defs | 3 + apps/system/Makefile | 2 +- apps/system/free/README.txt | 6 -- apps/system/poweroff/README.txt | 5 - apps/system/ramtron/README.txt | 7 -- apps/system/sdcard/README.txt | 7 -- apps/system/sysinfo/README.txt | 6 -- apps/system/usbmonitor/Kconfig | 33 ++++++ apps/system/usbmonitor/Makefile | 116 ++++++++++++++++++++ apps/system/usbmonitor/usbmonitor.c | 162 ++++++++++++++++++++++++++++ nuttx/ChangeLog | 3 + nuttx/Documentation/README.html | 8 +- nuttx/README.txt | 12 +-- nuttx/arch/arm/src/lm/chip/lm3s_memorymap.h | 18 ++-- nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h | 89 ++++++++++++++- 17 files changed, 421 insertions(+), 62 deletions(-) delete mode 100644 apps/system/free/README.txt delete mode 100644 apps/system/poweroff/README.txt delete mode 100644 apps/system/ramtron/README.txt delete mode 100644 apps/system/sdcard/README.txt delete mode 100644 apps/system/sysinfo/README.txt create mode 100644 apps/system/usbmonitor/Kconfig create mode 100644 apps/system/usbmonitor/Makefile create mode 100644 apps/system/usbmonitor/usbmonitor.c diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 494ce34eb..778f1fcf2 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -495,3 +495,5 @@ * apps/examples/nettest and poll: Complete Kconfig files. * apps/examples/ostest/waitpid.c: Need to use WEXITSTATUS() to decode the correct exit status. + * system/usbmonitor: A daemon that can be used to monitor USB + trace outpout. diff --git a/apps/system/Kconfig b/apps/system/Kconfig index d4d434665..6c8651088 100644 --- a/apps/system/Kconfig +++ b/apps/system/Kconfig @@ -34,3 +34,7 @@ endmenu menu "Sysinfo" source "$APPSDIR/system/sysinfo/Kconfig" endmenu + +menu "USB Monitor" +source "$APPSDIR/system/usbmonitor/Kconfig" +endmenu diff --git a/apps/system/Make.defs b/apps/system/Make.defs index 3d10f84e5..3c679f112 100644 --- a/apps/system/Make.defs +++ b/apps/system/Make.defs @@ -66,3 +66,6 @@ ifeq ($(CONFIG_SYSTEM_SYSINFO),y) CONFIGURED_APPS += system/sysinfo endif +ifeq ($(CONFIG_SYSTEM_USBMONITOR),y) +CONFIGURED_APPS += system/usbmonitor +endif diff --git a/apps/system/Makefile b/apps/system/Makefile index 057fbcf77..f39eedec4 100644 --- a/apps/system/Makefile +++ b/apps/system/Makefile @@ -37,7 +37,7 @@ # Sub-directories containing system task -SUBDIRS = free i2c install readline poweroff ramtron sdcard sysinfo +SUBDIRS = free i2c install readline poweroff ramtron sdcard sysinfo usbmonitor # Create the list of installed runtime modules (INSTALLED_DIRS) diff --git a/apps/system/free/README.txt b/apps/system/free/README.txt deleted file mode 100644 index 1c2d380d4..000000000 --- a/apps/system/free/README.txt +++ /dev/null @@ -1,6 +0,0 @@ - -This application provides UNIX style memory free information. - - Source: NuttX - Author: Gregory Nutt - Date: 17. March 2011 diff --git a/apps/system/poweroff/README.txt b/apps/system/poweroff/README.txt deleted file mode 100644 index e02180e5a..000000000 --- a/apps/system/poweroff/README.txt +++ /dev/null @@ -1,5 +0,0 @@ - -This application provides poweroff command - - Source: NuttX - Date: 13. March 2011 diff --git a/apps/system/ramtron/README.txt b/apps/system/ramtron/README.txt deleted file mode 100644 index 152774b66..000000000 --- a/apps/system/ramtron/README.txt +++ /dev/null @@ -1,7 +0,0 @@ - -This application provides RAMTRON tool/lib to start, stop or to perform -RAMTRON custom operations. - - Source: NuttX - Author: Uros Platise - Date: 18. March 2011 diff --git a/apps/system/sdcard/README.txt b/apps/system/sdcard/README.txt deleted file mode 100644 index 332aa26cf..000000000 --- a/apps/system/sdcard/README.txt +++ /dev/null @@ -1,7 +0,0 @@ - -This application provides SDcard tool/lib to start, stop, eject or insert -a memory card. - - Source: NuttX - Author: Uros Platise - Date: 18. March 2011 diff --git a/apps/system/sysinfo/README.txt b/apps/system/sysinfo/README.txt deleted file mode 100644 index 3792f4a59..000000000 --- a/apps/system/sysinfo/README.txt +++ /dev/null @@ -1,6 +0,0 @@ - -This application provides access to System Information - - Source: NuttX - Date: 15. April 2011 - Author: Uros Platise diff --git a/apps/system/usbmonitor/Kconfig b/apps/system/usbmonitor/Kconfig new file mode 100644 index 000000000..7199845b1 --- /dev/null +++ b/apps/system/usbmonitor/Kconfig @@ -0,0 +1,33 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +config SYSTEM_USBMONITOR + bool "USB Monitor" + default n + depends on USBDEV && USBDEV_TRACE && SYSLOG + ---help--- + If USB device tracing is enabled (USBDEV_TRACE), then this option + will select the USB monitor. The USB monitor is a daemon that will + periodically collect the buffered USB trace data and dump it to the + SYSLOG device. + +if SYSTEM_USBMONITOR + +config SYSTEM_USBMONITOR_STACKSIZE + int "USB Monitor Stack Size" + default 2048 + depends on NSH_BUILTIN_APPS + ---help--- + The stack size to use the the USB monitor daemon. Default: 2048 + +config SYSTEM_USBMONITOR_PRIORITY + int "USB Monitor Stack Size" + default 50 + depends on NSH_BUILTIN_APPS + ---help--- + The priority to use the the USB monitor daemon. Default: 50 + +endif + diff --git a/apps/system/usbmonitor/Makefile b/apps/system/usbmonitor/Makefile new file mode 100644 index 000000000..04fcaf0ac --- /dev/null +++ b/apps/system/usbmonitor/Makefile @@ -0,0 +1,116 @@ +############################################################################ +# apps/system/usbmonitor/Makefile +# +# Copyright (C) 2013 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +ifeq ($(WINTOOL),y) +INCDIROPT = -w +endif + +# Hello Application +# TODO: appname can be automatically extracted from the directory name + +APPNAME = usbmon +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 768 + +ASRCS = +CSRCS = usbmonitor.c + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\libapps$(LIBEXT) +else + BIN = ../../libapps$(LIBEXT) +endif +endif + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built +.PHONY: context depend clean distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + $(Q) touch .built + +# Register application + +ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) +$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile + $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) + +context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat +else +context: +endif + +# Create dependencies + +.depend: Makefile $(SRCS) + $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep diff --git a/apps/system/usbmonitor/usbmonitor.c b/apps/system/usbmonitor/usbmonitor.c new file mode 100644 index 000000000..b101b128c --- /dev/null +++ b/apps/system/usbmonitor/usbmonitor.c @@ -0,0 +1,162 @@ +/**************************************************************************** + * apps/system/free/free.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include + +/**************************************************************************** + * Private Typs + ****************************************************************************/ + +struct usbmon_state_s +{ +#ifdef CONFIG_NSH_BUILTIN_APPS + volatile bool started; + volatile bool stop; + pid_t pid; +#endif +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct usbmon_state_s g_usbmonitor; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int usbmonitor_daemon(int argc, char **argv) +{ +#ifdef CONFIG_NSH_BUILTIN_APPS + print("USB Monitor running: %d\n", g_usbmonitor.pid); +#endif + +#ifdef CONFIG_NSH_BUILTIN_APPS + /* If we are running as an NSH command, then loop until we detect that + * there is a request to stop. + */ + + while (!g_usbmonitor.stop) +#else + /* If we are running as a standalone program, then loop forever */ + + for (;;) +#endif + { +#warning "Missing logic" + } + + /* Stopped */ + +#ifdef CONFIG_NSH_BUILTIN_APPS + g_usbmonitor.stop = false; + g_usbmonitor.started = false; + print("USB Monitor stopped: %d\n", g_usbmonitor.pid); +#endif + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int usbmonitor_main(int argc, char **argv) +{ +#ifdef CONFIG_NSH_BUILTIN_APPS + /* Has the monitor already started? */ + + sched_lock(); + if (!g_usbmonitor.started) + { + int ret; + + /* No.. start it now */ + + g_usbmonitor.started = true; + g_usbmonitor.stop = false; + + ret = TASK_CREATE("USB Monitor", CONFIG_SYSTEM_USBMONITOR_PRIORITY, + CONFIG_SYSTEM_USBMONITOR_STACKSIZE, + (main_t)usbmonitor_daemon, (const char **)NULL); + if (ret < 0) + { + int errcode = errno; + fprintf(stderr, "ERROR: Failed to start the USB monitor: %d\n", + errcode); + } + else + { + g_usbmonitor.pid = ret; + print("USB Monitor started: %d\n", g_usbmonitor.pid); + } + + sched_unlock(); + return 0; + } + + sched_unlock(); + print("USB Monitor running: %d\n", g_usbmonitor.pid); + return 0; +#else + return usbmonitor_daemon(argc, argv); +#endif +} + +#ifdef CONFIG_NSH_BUILTIN_APPS +int usbmonitor_stop(int argc, char **argv) +{ + /* Has the monitor already started? */ + + if (g_usbmonitor.started) + { + print("USB Monitor stopping: %d\n", g_usbmonitor.pid); + g_usbmonitor.stop = true; + return 0; + } + + print("USB Monitor stopped: %d\n", g_usbmonitor.pid); + return 0; +} +#endif + diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 039a79f62..759177fca 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4067,3 +4067,6 @@ * libc/stdio/lib_syslogstream.c: Checking of return value from syslog_putc was bogus. Switching to EOF for all errors solves this. + * arch/arm/src/lm/chip/lm4f_memorymap.h: More LM4F changes from + Jose Pablo Carballo. + diff --git a/nuttx/Documentation/README.html b/nuttx/Documentation/README.html index 281b738b8..44b663188 100644 --- a/nuttx/Documentation/README.html +++ b/nuttx/Documentation/README.html @@ -278,13 +278,7 @@ | | `- README.txt | `- system/ | |- i2c/README.txt - | |- free/README.txt - | |- install/README.txt - | |- poweroff/README.txt - | |- ramtron/README.txt - | |- sdcard/README.txt - | |- sysinfo/README.txt - | `- README.txt + | `- install/README.txt `- NxWidgets |- Doxygen | `- README.txt diff --git a/nuttx/README.txt b/nuttx/README.txt index c597091dc..340087791 100644 --- a/nuttx/README.txt +++ b/nuttx/README.txt @@ -1181,17 +1181,9 @@ apps |- NxWidgets/ | `- README.txt |- system/ - | |- i2c/README.txt - | |- free/README.txt - | |- install + | |- i2c | | `- README.txt - | |- poweroff - | | `- README.txt - | |- ramtron - | | `- README.txt - | |- sdcard - | | `- README.txt - | `- sysinfo + | `- install | `- README.txt `- README.txt diff --git a/nuttx/arch/arm/src/lm/chip/lm3s_memorymap.h b/nuttx/arch/arm/src/lm/chip/lm3s_memorymap.h index 32b7a9f18..8caeada17 100644 --- a/nuttx/arch/arm/src/lm/chip/lm3s_memorymap.h +++ b/nuttx/arch/arm/src/lm/chip/lm3s_memorymap.h @@ -58,7 +58,7 @@ /* -0x3fffffff: Reserved */ # define LM_PERIPH_BASE 0x40000000 /* -0x4001ffff: FiRM Peripherals */ /* -0x41ffffff: Peripherals */ -# define LM_APERIPH_BASE 0x42000000 /* -0x43ffffff: Bit-band alise of 40000000- */ +# define LM_APERIPH_BASE 0x42000000 /* -0x43ffffff: Bit-band alias of 40000000- */ /* -0xdfffffff: Reserved */ # define LM_ITM_BASE 0xe0000000 /* -0xe0000fff: Instrumentation Trace Macrocell */ # define LM_DWT_BASE 0xe0001000 /* -0xe0001fff: Data Watchpoint and Trace */ @@ -327,19 +327,19 @@ /* -0x57fff: Reserved */ # define LM_GPIOAAHB_BASE (LM_PERIPH_BASE + 0x58000) /* -0x58fff: GPIO Port A (AHB aperture) */ # define LM_GPIOBAHB_BASE (LM_PERIPH_BASE + 0x59000) /* -0x59fff: GPIO Port B (AHB aperture) */ -# define LM_GPIOCAHB_BASE (LM_PERIPH_BASE + 0x5A000) /* -0x5afff: GPIO Port C (AHB aperture) */ -# define LM_GPIODAHB_BASE (LM_PERIPH_BASE + 0x5B000) /* -0x5bfff: GPIO Port D (AHB aperture) */ -# define LM_GPIOEAHB_BASE (LM_PERIPH_BASE + 0x5C000) /* -0x5cfff: GPIO Port E (AHB aperture) */ -# define LM_GPIOFAHB_BASE (LM_PERIPH_BASE + 0x5D000) /* -0x5dfff: GPIO Port F (AHB aperture) */ -# define LM_GPIOGAHB_BASE (LM_PERIPH_BASE + 0x5E000) /* -0x5efff: GPIO Port G (AHB aperture) */ -# define LM_GPIOHAHB_BASE (LM_PERIPH_BASE + 0x5F000) /* -0x5ffff: GPIO Port H (AHB aperture) */ +# define LM_GPIOCAHB_BASE (LM_PERIPH_BASE + 0x5a000) /* -0x5afff: GPIO Port C (AHB aperture) */ +# define LM_GPIODAHB_BASE (LM_PERIPH_BASE + 0x5b000) /* -0x5bfff: GPIO Port D (AHB aperture) */ +# define LM_GPIOEAHB_BASE (LM_PERIPH_BASE + 0x5c000) /* -0x5cfff: GPIO Port E (AHB aperture) */ +# define LM_GPIOFAHB_BASE (LM_PERIPH_BASE + 0x5d000) /* -0x5dfff: GPIO Port F (AHB aperture) */ +# define LM_GPIOGAHB_BASE (LM_PERIPH_BASE + 0x5e000) /* -0x5efff: GPIO Port G (AHB aperture) */ +# define LM_GPIOHAHB_BASE (LM_PERIPH_BASE + 0x5f000) /* -0x5ffff: GPIO Port H (AHB aperture) */ # define LM_GPIOJAHB_BASE (LM_PERIPH_BASE + 0x60000) /* -0x60fff: GPIO Port J (AHB aperture) */ /* -0xcffff: Reserved */ -# define LM_EPI0_BASE (LM_PERIPH_BASE + 0xD0000) /* -0xd0fff: EPI 0 */ +# define LM_EPI0_BASE (LM_PERIPH_BASE + 0xd0000) /* -0xd0fff: EPI 0 */ /* -0xfcfff: Reserved */ # define LM_FLASHCON_BASE (LM_PERIPH_BASE + 0xfd000) /* -0xfdfff: FLASH Control */ # define LM_SYSCON_BASE (LM_PERIPH_BASE + 0xfe000) /* -0xfefff: System Control */ -# define LM_UDMA_BASE (LM_PERIPH_BASE + 0xff000) /* -0xfffff: System Control */ +# define LM_UDMA_BASE (LM_PERIPH_BASE + 0xff000) /* -0xfffff: Micro Direct Memory Access */ /* -0x1ffffff: Reserved */ #else # error "Peripheral base addresses not specified for this Stellaris chip" diff --git a/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h b/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h index 6963545fe..c8c62d4b4 100644 --- a/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h +++ b/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h @@ -1,5 +1,5 @@ /************************************************************************************ - * arch/arm/src/lm/chip/lm3s_memorymap.h + * arch/arm/src/lm/chip/lm4f_memorymap.h * * Copyright (C) 2013 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt @@ -55,9 +55,21 @@ # define LM_ROM_BASE 0x01000000 /* -0x1fffffff: Reserved for ROM */ # define LM_SRAM_BASE 0x20000000 /* -0x20007fff: Bit-banded on-chip SRAM */ /* -0x21ffffff: Reserved */ -/* @TODO */ -#endif - +# define LM_ASRAM_BASE 0x22000000 /* -0x220fffff: Bit-band alias of 20000000- */ + /* -0x3fffffff: Reserved */ +# define LM_PERIPH_BASE 0x40000000 /* -0x4001ffff: FiRM Peripherals */ + /* -0x41ffffff: Peripherals */ +# define LM_APERIPH_BASE 0x42000000 /* -0x43ffffff: Bit-band alias of 40000000- */ + /* -0xdfffffff: Reserved */ +# define LM_ITM_BASE 0xe0000000 /* -0xe0000fff: Instrumentation Trace Macrocell */ +# define LM_DWT_BASE 0xe0001000 /* -0xe0001fff: Data Watchpoint and Trace */ +# define LM_FPB_BASE 0xe0002000 /* -0xe0002fff: Flash Patch and Breakpoint */ + /* -0xe000dfff: Reserved */ +# define LM_NVIC_BASE 0xe000e000 /* -0xe000efff: Nested Vectored Interrupt Controller */ + /* -0xe003ffff: Reserved */ +# define LM_TPIU_BASE 0xe0040000 /* -0xe0040fff: Trace Port Interface Unit */ +# define LM_ETM_BASE 0xe0041000 /* -0xe0041fff: Embedded Trace Macrocell */ + /* -0xffffffff: Reserved */ #else # error "Memory map not specified for this LM4F chip" #endif @@ -65,6 +77,75 @@ /* Peripheral base addresses ********************************************************/ #if defined(CONFIG_ARCH_CHIP_LM4F120) +/* FiRM Peripheral Base Addresses */ + +# define LM_WDOG0_BASE (LM_PERIPH_BASE + 0x00000) /* -0x00fff: Watchdog Timer 0 */ +# define LM_WDOG1_BASE (LM_PERIPH_BASE + 0x01000) /* -0x00fff: Watchdog Timer 1 */ + /* -0x03fff: Reserved */ +# define LM_GPIOA_BASE (LM_PERIPH_BASE + 0x04000) /* -0x04fff: GPIO Port A */ +# define LM_GPIOB_BASE (LM_PERIPH_BASE + 0x05000) /* -0x05fff: GPIO Port B */ +# define LM_GPIOC_BASE (LM_PERIPH_BASE + 0x06000) /* -0x06fff: GPIO Port C */ +# define LM_GPIOD_BASE (LM_PERIPH_BASE + 0x07000) /* -0x07fff: GPIO Port D */ +# define LM_SSI0_BASE (LM_PERIPH_BASE + 0x08000) /* -0x08fff: SSI0 */ +# define LM_SSI1_BASE (LM_PERIPH_BASE + 0x09000) /* -0x09fff: SSI1 */ +# define LM_SSI2_BASE (LM_PERIPH_BASE + 0x0a000) /* -0x0afff: SSI2 */ +# define LM_SSI3_BASE (LM_PERIPH_BASE + 0x0b000) /* -0x0bfff: SSI3 */ +# define LM_UART0_BASE (LM_PERIPH_BASE + 0x0c000) /* -0x0cfff: UART0 */ +# define LM_UART1_BASE (LM_PERIPH_BASE + 0x0d000) /* -0x0dfff: UART1 */ +# define LM_UART2_BASE (LM_PERIPH_BASE + 0x0e000) /* -0x0efff: UART2 */ +# define LM_UART3_BASE (LM_PERIPH_BASE + 0x0f000) /* -0x0ffff: UART3 */ +# define LM_UART4_BASE (LM_PERIPH_BASE + 0x10000) /* -0x10fff: UART4 */ +# define LM_UART5_BASE (LM_PERIPH_BASE + 0x11000) /* -0x11fff: UART5 */ +# define LM_UART6_BASE (LM_PERIPH_BASE + 0x12000) /* -0x12fff: UART6 */ +# define LM_UART7_BASE (LM_PERIPH_BASE + 0x13000) /* -0x13fff: UART7 */ + /* -0x1ffff: Reserved */ +/* Peripheral Base Addresses */ + +# define LM_I2CM0_BASE (LM_PERIPH_BASE + 0x20000) /* -0x207ff: I2C Master 0 */ +# define LM_I2CS0_BASE (LM_PERIPH_BASE + 0x20800) /* -0x20fbf: I2C Slave 0 */ +# define LM_I2CSC0_BASE (LM_PERIPH_BASE + 0x20fc0) /* -0x20fff: I2C Status and Control 0 */ +# define LM_I2CM1_BASE (LM_PERIPH_BASE + 0x21000) /* -0x217ff: I2C Master 1 */ +# define LM_I2CS1_BASE (LM_PERIPH_BASE + 0x21800) /* -0x21fbf: I2C Slave 1 */ +# define LM_I2CSC1_BASE (LM_PERIPH_BASE + 0x21fc0) /* -0x21fff: I2C Status and Control 1 */ +# define LM_I2CM2_BASE (LM_PERIPH_BASE + 0x22000) /* -0x227ff: I2C Master 2 */ +# define LM_I2CS2_BASE (LM_PERIPH_BASE + 0x22800) /* -0x22fbf: I2C Slave 2 */ +# define LM_I2CSC2_BASE (LM_PERIPH_BASE + 0x22fc0) /* -0x22fff: I2C Status and Control 2 */ +# define LM_I2CM3_BASE (LM_PERIPH_BASE + 0x23000) /* -0x237ff: I2C Master 3 */ +# define LM_I2CS3_BASE (LM_PERIPH_BASE + 0x23800) /* -0x23fbf: I2C Slave 3 */ +# define LM_I2CSC3_BASE (LM_PERIPH_BASE + 0x23fc0) /* -0x23fff: I2C Status and Control 3 */ +# define LM_GPIOE_BASE (LM_PERIPH_BASE + 0x24000) /* -0x24fff: GPIO Port E */ +# define LM_GPIOF_BASE (LM_PERIPH_BASE + 0x25000) /* -0x25fff: GPIO Port F */ + /* -0x2ffff: Reserved */ +# define LM_TIMER0_BASE (LM_PERIPH_BASE + 0x30000) /* -0x30fff: 16/32 Timer 0 */ +# define LM_TIMER1_BASE (LM_PERIPH_BASE + 0x31000) /* -0x31fff: 16/32 Timer 1 */ +# define LM_TIMER2_BASE (LM_PERIPH_BASE + 0x32000) /* -0x32fff: 16/32 Timer 2 */ +# define LM_TIMER3_BASE (LM_PERIPH_BASE + 0x33000) /* -0x33fff: 16/32 Timer 3 */ +# define LM_TIMER4_BASE (LM_PERIPH_BASE + 0x34000) /* -0x34fff: 16/32 Timer 4 */ +# define LM_TIMER5_BASE (LM_PERIPH_BASE + 0x35000) /* -0x35fff: 16/32 Timer 5 */ +# define LM_WTIMER0_BASE (LM_PERIPH_BASE + 0x36000) /* -0x36fff: 32/64 Wide Timer 0 */ +# define LM_WTIMER1_BASE (LM_PERIPH_BASE + 0x37000) /* -0x37fff: 32/64 Wide Timer 1 */ +# define LM_ADC0_BASE (LM_PERIPH_BASE + 0x38000) /* -0x38fff: ADC 0 */ +# define LM_ADC1_BASE (LM_PERIPH_BASE + 0x39000) /* -0x39fff: ADC 1 */ + /* -0x3bfff: Reserved */ +# define LM_COMPARE_BASE (LM_PERIPH_BASE + 0x3c000) /* -0x3cfff: Analog Comparators */ + /* -0x43fff: Reserved */ +# define LM_CANCON_BASE (LM_PERIPH_BASE + 0x40000) /* -0x40fff: CAN Controller */ + /* -0x4bfff: Reserved */ +# define LM_WTIMER2_BASE (LM_PERIPH_BASE + 0x4c000) /* -0x4cfff: 32/64 Wide Timer 2 */ +# define LM_WTIMER3_BASE (LM_PERIPH_BASE + 0x4d000) /* -0x4dfff: 32/64 Wide Timer 3 */ +# define LM_WTIMER4_BASE (LM_PERIPH_BASE + 0x4e000) /* -0x4efff: 32/64 Wide Timer 4 */ +# define LM_WTIMER5_BASE (LM_PERIPH_BASE + 0x4f000) /* -0x4ffff: 32/64 Wide Timer 5 */ +# define LM_USB_BASE (LM_PERIPH_BASE + 0x50000) /* -0x50fff: USB */ + /* -0x57fff: Reserved */ +# define LM_GPIOAAHB_BASE (LM_PERIPH_BASE + 0x58000) /* -0x58fff: GPIO Port A (AHB aperture) */ +# define LM_GPIOBAHB_BASE (LM_PERIPH_BASE + 0x59000) /* -0x59fff: GPIO Port B (AHB aperture) */ +# define LM_GPIOCAHB_BASE (LM_PERIPH_BASE + 0x5A000) /* -0x5afff: GPIO Port C (AHB aperture) */ +# define LM_GPIODAHB_BASE (LM_PERIPH_BASE + 0x5B000) /* -0x5bfff: GPIO Port D (AHB aperture) */ +# define LM_GPIOEAHB_BASE (LM_PERIPH_BASE + 0x5C000) /* -0x5cfff: GPIO Port E (AHB aperture) */ +# define LM_GPIOFAHB_BASE (LM_PERIPH_BASE + 0x5D000) /* -0x5dfff: GPIO Port F (AHB aperture) */ + /* -0xaefff: Reserved */ +# define LM_EEPROM_BASE (LM_PERIPH_BASE + 0xaf000) /* -0xaffff: EEPROM and Key Locker */ + /* -0xf8fff: Reserved */ /* @TODO */ #else # error "Peripheral base addresses not specified for this Stellaris chip" -- cgit v1.2.3 From 79ccfa4ae6db4b085703b12c8f6846716fc69df7 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 28 Jan 2013 21:55:16 +0000 Subject: Add syslog.h; rename lib_rawprintf() to syslog() git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5578 42af7a65-404d-4744-a932-0658087f49c3 --- .../UnitTests/CButtonArray/cbuttonarraytest.hxx | 4 +- NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx | 4 +- .../UnitTests/CGlyphButton/cglyphbuttontest.hxx | 4 +- NxWidgets/UnitTests/CImage/cimagetest.hxx | 4 +- NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx | 4 +- .../CLatchButtonArray/clatchbuttonarraytest.hxx | 4 +- NxWidgets/UnitTests/CListBox/clistboxtest.hxx | 4 +- .../UnitTests/CProgressBar/cprogressbartest.hxx | 4 +- .../UnitTests/CRadioButton/cradiobuttontest.hxx | 4 +- .../cscrollbarhorizontaltest.hxx | 4 +- .../CScrollbarVertical/cscrollbarverticaltest.hxx | 4 +- .../CSliderHorizonal/csliderhorizontaltest.hxx | 4 +- .../CSliderVertical/csliderverticaltest.hxx | 4 +- apps/examples/adc/adc.h | 4 +- apps/examples/buttons/buttons_main.c | 28 ++-- apps/examples/can/can.h | 4 +- apps/examples/cdcacm/cdcacm.h | 4 +- apps/examples/composite/composite.h | 4 +- apps/examples/igmp/igmp.h | 6 +- apps/examples/nettest/nettest.h | 6 +- apps/examples/nx/nx_internal.h | 4 +- apps/examples/nxconsole/nxcon_internal.h | 4 +- apps/examples/nxffs/nxffs_main.c | 2 +- apps/examples/nxhello/nxhello.h | 4 +- apps/examples/nximage/nximage.h | 4 +- apps/examples/nxlines/nxlines.h | 4 +- apps/examples/nxtext/nxtext_internal.h | 4 +- apps/examples/poll/poll_internal.h | 6 +- apps/examples/pwm/pwm.h | 4 +- apps/examples/qencoder/qe.h | 4 +- apps/examples/thttpd/thttpd_main.c | 4 +- apps/examples/touchscreen/tc.h | 4 +- apps/examples/udp/udp-internal.h | 4 +- apps/examples/uip/uip_main.c | 4 +- apps/examples/usbserial/usbserial_main.c | 8 +- apps/examples/usbstorage/usbmsc.h | 4 +- apps/examples/usbterm/usbterm.h | 8 +- apps/examples/watchdog/watchdog.h | 4 +- apps/include/usbmonitor.h | 96 +++++++++++++ apps/nshlib/nsh_usbdev.c | 2 +- apps/system/usbmonitor/Makefile | 4 +- apps/system/usbmonitor/usbmonitor.c | 68 ++++----- misc/tools/README.txt | 4 +- nuttx/Documentation/NuttxPortingGuide.html | 10 +- nuttx/Kconfig | 5 +- nuttx/TODO | 17 +-- nuttx/arch/arm/src/arm/up_assert.c | 4 +- nuttx/arch/arm/src/arm/up_dataabort.c | 2 +- nuttx/arch/arm/src/arm/up_prefetchabort.c | 2 +- nuttx/arch/arm/src/arm/up_syscall.c | 2 +- nuttx/arch/arm/src/arm/up_undefinedinsn.c | 2 +- nuttx/arch/arm/src/armv7-m/up_assert.c | 4 +- nuttx/arch/arm/src/dm320/dm320_decodeirq.c | 2 +- nuttx/arch/arm/src/imx/imx_decodeirq.c | 2 +- nuttx/arch/arm/src/lpc214x/lpc214x_decodeirq.c | 2 +- nuttx/arch/arm/src/lpc2378/lpc23xx_decodeirq.c | 2 +- nuttx/arch/arm/src/lpc31xx/lpc31_decodeirq.c | 2 +- nuttx/arch/arm/src/stm32/stm32_i2c.c | 6 +- nuttx/arch/arm/src/str71x/str71x_decodeirq.c | 2 +- nuttx/arch/avr/src/avr/up_dumpstate.c | 2 +- nuttx/arch/avr/src/avr32/up_dumpstate.c | 2 +- nuttx/arch/avr/src/common/up_assert.c | 4 +- nuttx/arch/hc/src/m9s12/m9s12_assert.c | 4 +- nuttx/arch/mips/src/mips32/up_assert.c | 4 +- nuttx/arch/mips/src/mips32/up_dumpstate.c | 2 +- nuttx/arch/sh/src/common/up_assert.c | 2 +- nuttx/arch/sh/src/m16c/m16c_dumpstate.c | 2 +- nuttx/arch/sh/src/sh1/sh1_dumpstate.c | 2 +- nuttx/arch/sim/src/up_initialize.c | 4 +- nuttx/arch/sim/src/up_tapdev.c | 26 ++-- nuttx/arch/x86/src/common/up_assert.c | 4 +- nuttx/arch/x86/src/i486/up_regdump.c | 2 +- nuttx/arch/z16/src/common/up_assert.c | 2 +- nuttx/arch/z16/src/common/up_registerdump.c | 2 +- nuttx/arch/z16/src/common/up_stackdump.c | 2 +- nuttx/arch/z16/src/z16f/z16f_sysexec.c | 4 +- nuttx/arch/z80/src/common/up_assert.c | 2 +- nuttx/arch/z80/src/common/up_doirq.c | 2 +- nuttx/arch/z80/src/common/up_stackdump.c | 2 +- nuttx/arch/z80/src/ez80/ez80_registerdump.c | 2 +- nuttx/arch/z80/src/z180/z180_registerdump.c | 2 +- nuttx/arch/z80/src/z8/z8_registerdump.c | 2 +- nuttx/arch/z80/src/z80/z80_registerdump.c | 2 +- nuttx/binfmt/libelf/libelf_read.c | 2 +- nuttx/binfmt/libnxflat/libnxflat_read.c | 2 +- nuttx/configs/README.txt | 2 +- nuttx/configs/cloudctrl/src/up_nsh.c | 4 +- nuttx/configs/cloudctrl/src/up_usbmsc.c | 4 +- nuttx/configs/demo9s12ne64/src/up_nsh.c | 4 +- nuttx/configs/ea3131/src/up_nsh.c | 4 +- nuttx/configs/ea3131/src/up_usbmsc.c | 4 +- nuttx/configs/ea3152/src/up_nsh.c | 4 +- nuttx/configs/ea3152/src/up_usbmsc.c | 4 +- nuttx/configs/eagle100/src/up_nsh.c | 4 +- nuttx/configs/ekk-lm3s9b96/src/up_nsh.c | 4 +- nuttx/configs/ez80f910200kitg/ostest/defconfig | 2 +- nuttx/configs/ez80f910200zco/ostest/defconfig | 2 +- nuttx/configs/fire-stm32v2/src/up_composite.c | 4 +- nuttx/configs/fire-stm32v2/src/up_nsh.c | 4 +- nuttx/configs/fire-stm32v2/src/up_usbmsc.c | 4 +- nuttx/configs/hymini-stm32v/src/up_nsh.c | 4 +- nuttx/configs/hymini-stm32v/src/up_usbmsc.c | 4 +- nuttx/configs/kwikstik-k40/src/up_nsh.c | 4 +- nuttx/configs/kwikstik-k40/src/up_usbmsc.c | 4 +- nuttx/configs/lincoln60/src/up_nsh.c | 4 +- nuttx/configs/lm3s6432-s2e/src/up_nsh.c | 4 +- nuttx/configs/lm3s6965-ek/src/up_nsh.c | 4 +- nuttx/configs/lm3s8962-ek/src/up_nsh.c | 4 +- nuttx/configs/lpcxpresso-lpc1768/src/up_nsh.c | 4 +- nuttx/configs/lpcxpresso-lpc1768/src/up_usbmsc.c | 4 +- nuttx/configs/mbed/src/up_nsh.c | 4 +- nuttx/configs/mcu123-lpc214x/src/up_composite.c | 4 +- nuttx/configs/mcu123-lpc214x/src/up_nsh.c | 4 +- nuttx/configs/mcu123-lpc214x/src/up_usbmsc.c | 4 +- nuttx/configs/ne64badge/src/up_nsh.c | 4 +- nuttx/configs/nucleus2g/src/up_nsh.c | 4 +- nuttx/configs/nucleus2g/src/up_usbmsc.c | 4 +- nuttx/configs/olimex-lpc1766stk/src/up_nsh.c | 4 +- nuttx/configs/olimex-lpc1766stk/src/up_usbmsc.c | 4 +- nuttx/configs/olimex-lpc2378/src/up_nsh.c | 4 +- nuttx/configs/olimex-strp711/src/up_nsh.c | 4 +- nuttx/configs/pic32-starterkit/src/up_nsh.c | 4 +- nuttx/configs/pic32-starterkit/src/up_usbmsc.c | 4 +- nuttx/configs/pic32mx7mmb/src/up_nsh.c | 4 +- nuttx/configs/pic32mx7mmb/src/up_usbmsc.c | 4 +- nuttx/configs/rgmp/include/README.txt | 2 +- nuttx/configs/rgmp/src/README.txt | 2 +- nuttx/configs/sam3u-ek/src/up_nsh.c | 4 +- nuttx/configs/sam3u-ek/src/up_usbmsc.c | 4 +- nuttx/configs/shenzhou/src/up_composite.c | 4 +- nuttx/configs/shenzhou/src/up_ili93xx.c | 6 +- nuttx/configs/shenzhou/src/up_nsh.c | 4 +- nuttx/configs/shenzhou/src/up_usbmsc.c | 4 +- nuttx/configs/sim/cxxtest/defconfig | 2 +- nuttx/configs/sim/ostest/defconfig | 2 +- nuttx/configs/stm3210e-eval/src/up_composite.c | 4 +- nuttx/configs/stm3210e-eval/src/up_lcd.c | 6 +- nuttx/configs/stm3210e-eval/src/up_nsh.c | 4 +- nuttx/configs/stm3210e-eval/src/up_pmbuttons.c | 6 +- nuttx/configs/stm3210e-eval/src/up_usbmsc.c | 4 +- nuttx/configs/stm3220g-eval/src/up_lcd.c | 6 +- nuttx/configs/stm3220g-eval/src/up_nsh.c | 4 +- nuttx/configs/stm3240g-eval/discover/defconfig | 2 +- nuttx/configs/stm3240g-eval/src/up_lcd.c | 6 +- nuttx/configs/stm3240g-eval/src/up_nsh.c | 4 +- nuttx/configs/stm3240g-eval/xmlrpc/defconfig | 2 +- nuttx/configs/stm32f4discovery/src/up_nsh.c | 4 +- nuttx/configs/stm32f4discovery/src/up_pmbuttons.c | 2 +- nuttx/configs/sure-pic32mx/src/up_nsh.c | 4 +- nuttx/configs/teensy/src/up_usbmsc.c | 4 +- nuttx/configs/twr-k60n512/src/up_nsh.c | 4 +- nuttx/configs/twr-k60n512/src/up_usbmsc.c | 4 +- nuttx/configs/ubw32/src/up_nsh.c | 4 +- nuttx/configs/vsn/src/usbmsc.c | 4 +- nuttx/configs/vsn/src/vsn.h | 4 +- nuttx/configs/z16f2800100zcog/ostest/defconfig | 2 +- nuttx/configs/z16f2800100zcog/pashello/README.txt | 24 ++-- nuttx/configs/z16f2800100zcog/pashello/defconfig | 2 +- nuttx/configs/z8encore000zco/ostest/defconfig | 2 +- nuttx/configs/z8f64200100kit/ostest/defconfig | 2 +- nuttx/drivers/lcd/mio283qt2.c | 6 +- nuttx/drivers/lcd/ssd1289.c | 6 +- nuttx/drivers/mmcsd/mmcsd_debug.c | 4 +- nuttx/drivers/net/enc28j60.c | 96 ++++++------- nuttx/drivers/syslog/ramlog.c | 6 +- nuttx/drivers/usbdev/usbdev_trace.c | 4 +- nuttx/drivers/usbdev/usbmsc.h | 8 +- nuttx/fs/fs_syslog.c | 6 +- nuttx/fs/nxffs/nxffs_dump.c | 2 +- nuttx/include/debug.h | 37 ++--- nuttx/include/nuttx/syslog.h | 6 +- nuttx/include/syslog.h | 94 +++++++++++++ nuttx/libc/lib.csv | 6 +- nuttx/libc/lib_internal.h | 12 +- nuttx/libc/misc/lib_dbg.c | 36 ++--- nuttx/libc/misc/lib_dumpbuffer.c | 8 +- nuttx/libc/stdio/Make.defs | 2 +- nuttx/libc/stdio/lib_lowprintf.c | 130 ----------------- nuttx/libc/stdio/lib_lowsyslog.c | 130 +++++++++++++++++ nuttx/libc/stdio/lib_printf.c | 4 +- nuttx/libc/stdio/lib_rawprintf.c | 154 --------------------- nuttx/libc/stdio/lib_syslog.c | 154 +++++++++++++++++++++ 182 files changed, 943 insertions(+), 786 deletions(-) create mode 100644 apps/include/usbmonitor.h create mode 100644 nuttx/include/syslog.h delete mode 100644 nuttx/libc/stdio/lib_lowprintf.c create mode 100644 nuttx/libc/stdio/lib_lowsyslog.c delete mode 100644 nuttx/libc/stdio/lib_rawprintf.c create mode 100644 nuttx/libc/stdio/lib_syslog.c diff --git a/NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx b/NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx index b8a9e15e5..1dc794a48 100644 --- a/NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx +++ b/NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx @@ -75,11 +75,11 @@ # define CONFIG_CBUTTONARRAYTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx b/NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx index 0397b37dd..58099acdf 100644 --- a/NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx +++ b/NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx @@ -69,11 +69,11 @@ # define CONFIG_CCHECKBOXTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx b/NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx index b3e5bb656..2c21d4cb1 100644 --- a/NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx +++ b/NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx @@ -76,11 +76,11 @@ # define CONFIG_CGLYPHBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CImage/cimagetest.hxx b/NxWidgets/UnitTests/CImage/cimagetest.hxx index 9592f2936..5b5901bb1 100644 --- a/NxWidgets/UnitTests/CImage/cimagetest.hxx +++ b/NxWidgets/UnitTests/CImage/cimagetest.hxx @@ -71,11 +71,11 @@ # define CONFIG_CIMAGETEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx b/NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx index d11c92375..12d7e18fa 100644 --- a/NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx +++ b/NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx @@ -72,11 +72,11 @@ # define CONFIG_CKEYPADTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx b/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx index 98c0a3bb3..80bf8fb71 100644 --- a/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx +++ b/NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx @@ -75,11 +75,11 @@ # define CONFIG_CLATCHBUTTONARRAYTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CListBox/clistboxtest.hxx b/NxWidgets/UnitTests/CListBox/clistboxtest.hxx index a19a2fabc..dfe179503 100644 --- a/NxWidgets/UnitTests/CListBox/clistboxtest.hxx +++ b/NxWidgets/UnitTests/CListBox/clistboxtest.hxx @@ -69,11 +69,11 @@ # define CONFIG_CLISTBOXTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CProgressBar/cprogressbartest.hxx b/NxWidgets/UnitTests/CProgressBar/cprogressbartest.hxx index a7a4238e7..2223d8081 100644 --- a/NxWidgets/UnitTests/CProgressBar/cprogressbartest.hxx +++ b/NxWidgets/UnitTests/CProgressBar/cprogressbartest.hxx @@ -69,11 +69,11 @@ # define CONFIG_CPROGRESSBARTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CRadioButton/cradiobuttontest.hxx b/NxWidgets/UnitTests/CRadioButton/cradiobuttontest.hxx index 540d5019b..3f81371db 100644 --- a/NxWidgets/UnitTests/CRadioButton/cradiobuttontest.hxx +++ b/NxWidgets/UnitTests/CRadioButton/cradiobuttontest.hxx @@ -70,11 +70,11 @@ # define CONFIG_CRADIOBUTTONTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx b/NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx index 774225091..30f66ca45 100644 --- a/NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx +++ b/NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx @@ -69,11 +69,11 @@ # define CONFIG_CSCROLLBARHORIZONTALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx b/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx index 8b9fb1ee8..6323b0f26 100644 --- a/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx +++ b/NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx @@ -69,11 +69,11 @@ # define CONFIG_CSCROLLBARVERTICALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx b/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx index 9709a2b7c..fd333af5c 100644 --- a/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx +++ b/NxWidgets/UnitTests/CSliderHorizonal/csliderhorizontaltest.hxx @@ -69,11 +69,11 @@ # define CONFIG_CSLIDERHORIZONTALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx b/NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx index 3bb174ba0..6a893e395 100644 --- a/NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx +++ b/NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx @@ -69,11 +69,11 @@ # define CONFIG_CSLIDERVERTICALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR #endif -// If debug is enabled, use the debug function, lib_rawprintf() instead +// If debug is enabled, use the debug function, syslog() instead // of printf() so that the output is synchronized. #ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog #else # define message printf #endif diff --git a/apps/examples/adc/adc.h b/apps/examples/adc/adc.h index 9f79db92a..2d8af87e1 100644 --- a/apps/examples/adc/adc.h +++ b/apps/examples/adc/adc.h @@ -74,7 +74,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) syslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -82,7 +82,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_rawprintf +# define message syslog # define msgflush() # else # define message printf diff --git a/apps/examples/buttons/buttons_main.c b/apps/examples/buttons/buttons_main.c index 5f25c1ef1..655080def 100644 --- a/apps/examples/buttons/buttons_main.c +++ b/apps/examples/buttons/buttons_main.c @@ -299,11 +299,11 @@ static void show_buttons(uint8_t oldset, uint8_t newset) state = "released"; } - /* Use lib_lowprintf() because we make be executing from an + /* Use lowsyslog() because we make be executing from an * interrupt handler. */ - lib_lowprintf(" %s %s\n", g_buttoninfo[BUTTON_INDEX(i)].name, state); + lowsyslog(" %s %s\n", g_buttoninfo[BUTTON_INDEX(i)].name, state); } } } @@ -313,8 +313,8 @@ static void button_handler(int id, int irq) { uint8_t newset = up_buttons(); - lib_lowprintf("IRQ:%d Button %d:%s SET:%02x:\n", - irq, id, g_buttoninfo[BUTTON_INDEX(id)].name, newset); + lowsyslog("IRQ:%d Button %d:%s SET:%02x:\n", + irq, id, g_buttoninfo[BUTTON_INDEX(id)].name, newset); show_buttons(g_oldset, newset); g_oldset = newset; } @@ -409,7 +409,7 @@ int buttons_main(int argc, char *argv[]) { maxbuttons = strtol(argv[1], NULL, 10); } - lib_lowprintf("maxbuttons: %d\n", maxbuttons); + lowsyslog("maxbuttons: %d\n", maxbuttons); #endif /* Initialize the button GPIOs */ @@ -423,11 +423,11 @@ int buttons_main(int argc, char *argv[]) { xcpt_t oldhandler = up_irqbutton(i, g_buttoninfo[BUTTON_INDEX(i)].handler); - /* Use lib_lowprintf() for compatibility with interrrupt handler output. */ + /* Use lowsyslog() for compatibility with interrrupt handler output. */ - lib_lowprintf("Attached handler at %p to button %d [%s], oldhandler:%p\n", - g_buttoninfo[BUTTON_INDEX(i)].handler, i, - g_buttoninfo[BUTTON_INDEX(i)].name, oldhandler); + lowsyslog("Attached handler at %p to button %d [%s], oldhandler:%p\n", + g_buttoninfo[BUTTON_INDEX(i)].handler, i, + g_buttoninfo[BUTTON_INDEX(i)].name, oldhandler); /* Some hardware multiplexes different GPIO button sources to the same * physical interrupt. If we register multiple such multiplexed button @@ -438,9 +438,9 @@ int buttons_main(int argc, char *argv[]) if (oldhandler != NULL) { - lib_lowprintf("WARNING: oldhandler:%p is not NULL! " - "Button events may be lost or aliased!\n", - oldhandler); + lowsyslog("WARNING: oldhandler:%p is not NULL! " + "Button events may be lost or aliased!\n", + oldhandler); } } #endif @@ -468,11 +468,11 @@ int buttons_main(int argc, char *argv[]) flags = irqsave(); - /* Use lib_lowprintf() for compatibility with interrrupt handler + /* Use lowsyslog() for compatibility with interrrupt handler * output. */ - lib_lowprintf("POLL SET:%02x:\n", newset); + lowsyslog("POLL SET:%02x:\n", newset); show_buttons(g_oldset, newset); g_oldset = newset; irqrestore(flags); diff --git a/apps/examples/can/can.h b/apps/examples/can/can.h index 53a6b63ea..d9f9236f7 100644 --- a/apps/examples/can/can.h +++ b/apps/examples/can/can.h @@ -89,7 +89,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) syslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -97,7 +97,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_rawprintf +# define message syslog # define msgflush() # else # define message printf diff --git a/apps/examples/cdcacm/cdcacm.h b/apps/examples/cdcacm/cdcacm.h index 18570bff0..1b3b2511c 100644 --- a/apps/examples/cdcacm/cdcacm.h +++ b/apps/examples/cdcacm/cdcacm.h @@ -112,7 +112,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -120,7 +120,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/examples/composite/composite.h b/apps/examples/composite/composite.h index 73a4453be..3f7f7ebad 100644 --- a/apps/examples/composite/composite.h +++ b/apps/examples/composite/composite.h @@ -173,7 +173,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -181,7 +181,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/examples/igmp/igmp.h b/apps/examples/igmp/igmp.h index 093f58c1f..5e1fa8d95 100644 --- a/apps/examples/igmp/igmp.h +++ b/apps/examples/igmp/igmp.h @@ -46,12 +46,12 @@ * Definitions ****************************************************************************/ -/* Used lib_rawprintf() so that there is no confusion from buffered IO */ +/* Used syslog() so that there is no confusion from buffered IO */ #ifdef CONFIG_CPP_HAVE_VARARGS -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) syslog(__VA_ARGS__) #else -# define message lib_rawprintf +# define message syslog #endif /**************************************************************************** diff --git a/apps/examples/nettest/nettest.h b/apps/examples/nettest/nettest.h index 37ac470d1..5021e05d6 100644 --- a/apps/examples/nettest/nettest.h +++ b/apps/examples/nettest/nettest.h @@ -69,12 +69,12 @@ #else - /* Used lib_rawprintf() so that there is not confusion from buffered IO */ + /* Used syslog() so that there is not confusion from buffered IO */ # ifdef CONFIG_CPP_HAVE_VARARGS -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) syslog(__VA_ARGS__) # else -# define message lib_rawprintf +# define message syslog # endif /* At present, uIP does only abortive disconnects */ diff --git a/apps/examples/nx/nx_internal.h b/apps/examples/nx/nx_internal.h index d9a6a2ade..53f1763b4 100644 --- a/apps/examples/nx/nx_internal.h +++ b/apps/examples/nx/nx_internal.h @@ -168,7 +168,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -176,7 +176,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/examples/nxconsole/nxcon_internal.h b/apps/examples/nxconsole/nxcon_internal.h index c5ad760ad..c921bed38 100644 --- a/apps/examples/nxconsole/nxcon_internal.h +++ b/apps/examples/nxconsole/nxcon_internal.h @@ -239,7 +239,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -247,7 +247,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/examples/nxffs/nxffs_main.c b/apps/examples/nxffs/nxffs_main.c index 5401fc932..8bb5cd1fe 100644 --- a/apps/examples/nxffs/nxffs_main.c +++ b/apps/examples/nxffs/nxffs_main.c @@ -120,7 +120,7 @@ #endif #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_FS) -# define message lib_rawprintf +# define message syslog # define msgflush() #else # define message printf diff --git a/apps/examples/nxhello/nxhello.h b/apps/examples/nxhello/nxhello.h index 2dce7bf6c..f395b7018 100644 --- a/apps/examples/nxhello/nxhello.h +++ b/apps/examples/nxhello/nxhello.h @@ -96,7 +96,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -104,7 +104,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/examples/nximage/nximage.h b/apps/examples/nximage/nximage.h index eac0f5dc2..ef475ca29 100644 --- a/apps/examples/nximage/nximage.h +++ b/apps/examples/nximage/nximage.h @@ -111,7 +111,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -119,7 +119,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/examples/nxlines/nxlines.h b/apps/examples/nxlines/nxlines.h index a26db9f29..c9101124e 100644 --- a/apps/examples/nxlines/nxlines.h +++ b/apps/examples/nxlines/nxlines.h @@ -120,7 +120,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -128,7 +128,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/examples/nxtext/nxtext_internal.h b/apps/examples/nxtext/nxtext_internal.h index f0001e0bb..1e64193a3 100644 --- a/apps/examples/nxtext/nxtext_internal.h +++ b/apps/examples/nxtext/nxtext_internal.h @@ -194,7 +194,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -202,7 +202,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/examples/poll/poll_internal.h b/apps/examples/poll/poll_internal.h index b2400932e..759d23f1c 100644 --- a/apps/examples/poll/poll_internal.h +++ b/apps/examples/poll/poll_internal.h @@ -71,7 +71,7 @@ # undef HAVE_NETPOLL #endif -/* If debug is enabled, then use lib_rawprintf so that OS debug output and +/* If debug is enabled, then use syslog so that OS debug output and * the test output are synchronized. * * These macros will differ depending upon if the toolchain supports @@ -80,7 +80,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) syslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -88,7 +88,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_rawprintf +# define message syslog # define msgflush() # else # define message printf diff --git a/apps/examples/pwm/pwm.h b/apps/examples/pwm/pwm.h index 5c049a8f8..a6132ca8b 100644 --- a/apps/examples/pwm/pwm.h +++ b/apps/examples/pwm/pwm.h @@ -92,7 +92,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) syslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -100,7 +100,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_rawprintf +# define message syslog # define msgflush() # else # define message printf diff --git a/apps/examples/qencoder/qe.h b/apps/examples/qencoder/qe.h index 4c03689ab..3c20511ca 100644 --- a/apps/examples/qencoder/qe.h +++ b/apps/examples/qencoder/qe.h @@ -77,7 +77,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) syslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -85,7 +85,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_rawprintf +# define message syslog # define msgflush() # else # define message printf diff --git a/apps/examples/thttpd/thttpd_main.c b/apps/examples/thttpd/thttpd_main.c index 97f922a76..9d08824e6 100644 --- a/apps/examples/thttpd/thttpd_main.c +++ b/apps/examples/thttpd/thttpd_main.c @@ -125,7 +125,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -133,7 +133,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/examples/touchscreen/tc.h b/apps/examples/touchscreen/tc.h index 654b1d874..dddff11c3 100644 --- a/apps/examples/touchscreen/tc.h +++ b/apps/examples/touchscreen/tc.h @@ -82,7 +82,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) syslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -90,7 +90,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_rawprintf +# define message syslog # define msgflush() # else # define message printf diff --git a/apps/examples/udp/udp-internal.h b/apps/examples/udp/udp-internal.h index 2a966c746..c8010e6c8 100644 --- a/apps/examples/udp/udp-internal.h +++ b/apps/examples/udp/udp-internal.h @@ -63,12 +63,12 @@ #else - /* If debug is enabled, use the synchronous lib_lowprintf so that the + /* If debug is enabled, use the synchronous lowsyslog so that the * program output does not get disassociated in the debug output. */ # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif diff --git a/apps/examples/uip/uip_main.c b/apps/examples/uip/uip_main.c index 6c2f96f39..8e485441c 100644 --- a/apps/examples/uip/uip_main.c +++ b/apps/examples/uip/uip_main.c @@ -86,13 +86,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message (void) # endif diff --git a/apps/examples/usbserial/usbserial_main.c b/apps/examples/usbserial/usbserial_main.c index 016c8b292..dc7e1959a 100644 --- a/apps/examples/usbserial/usbserial_main.c +++ b/apps/examples/usbserial/usbserial_main.c @@ -109,16 +109,16 @@ TRACE_TRANSFER_BITS|TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) -# define trmessage lib_lowprintf +# define message(...) lowsyslog(__VA_ARGS__) +# define trmessage lowsyslog # else # define message(...) printf(__VA_ARGS__) # define trmessage printf # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf -# define trmessage lib_lowprintf +# define message lowsyslog +# define trmessage lowsyslog # else # define message printf # define trmessage printf diff --git a/apps/examples/usbstorage/usbmsc.h b/apps/examples/usbstorage/usbmsc.h index 9d48c4521..95453198a 100644 --- a/apps/examples/usbstorage/usbmsc.h +++ b/apps/examples/usbstorage/usbmsc.h @@ -85,7 +85,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -93,7 +93,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/examples/usbterm/usbterm.h b/apps/examples/usbterm/usbterm.h index 2534c2f3c..560e55346 100644 --- a/apps/examples/usbterm/usbterm.h +++ b/apps/examples/usbterm/usbterm.h @@ -101,16 +101,16 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_rawprintf(__VA_ARGS__) -# define trmessage lib_rawprintf +# define message(...) syslog(__VA_ARGS__) +# define trmessage syslog # else # define message(...) printf(__VA_ARGS__) # define trmessage printf # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf -# define trmessage lib_lowprintf +# define message lowsyslog +# define trmessage lowsyslog # else # define message printf # define trmessage printf diff --git a/apps/examples/watchdog/watchdog.h b/apps/examples/watchdog/watchdog.h index dc2dea944..dd4daebb9 100644 --- a/apps/examples/watchdog/watchdog.h +++ b/apps/examples/watchdog/watchdog.h @@ -89,7 +89,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) syslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -97,7 +97,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_rawprintf +# define message syslog # define msgflush() # else # define message printf diff --git a/apps/include/usbmonitor.h b/apps/include/usbmonitor.h new file mode 100644 index 000000000..01fa060b0 --- /dev/null +++ b/apps/include/usbmonitor.h @@ -0,0 +1,96 @@ +/**************************************************************************** + * apps/include/usbmonitor.h + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_INCLUDE_USBMONITOR_H +#define __APPS_INCLUDE_USBMONITOR_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_SYSTEM_USBMONITOR + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: usbmon_start and usbmon_stop + * + * Start and top the USB monitor daemon. These are normally controlled + * from the USB command line, but the ability to control these + * programmatically is also helpful (for example, so that the daemon is + * running before NSH starts). + * + * Input Parameters: + * Standard task parameters. These can be called or spawned. Since the + * return almost immediately, it is fine to just call the functions. The + * parameters are not used so you can pass 0 and NULL, respectivley; this + * is done this way so that these functions can be NSH builtin + * applications. + * + * Returned values: + * Standard task return values (zero meaning success). + * + **************************************************************************/ + +int usbmonitor_start(int argc, char **argv); +int usbmonitor_stop(int argc, char **argv); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_SYSTEM_USBMONITOR */ +#endif /* __APPS_INCLUDE_USBMONITOR_H */ diff --git a/apps/nshlib/nsh_usbdev.c b/apps/nshlib/nsh_usbdev.c index 3d123532a..d137e3dae 100644 --- a/apps/nshlib/nsh_usbdev.c +++ b/apps/nshlib/nsh_usbdev.c @@ -63,7 +63,7 @@ ****************************************************************************/ #if defined(CONFIG_DEBUG) || defined(CONFIG_NSH_USBCONSOLE) -# define trmessage lib_lowprintf +# define trmessage lowsyslog #else # define trmessage printf #endif diff --git a/apps/system/usbmonitor/Makefile b/apps/system/usbmonitor/Makefile index 04fcaf0ac..b4c323eb7 100644 --- a/apps/system/usbmonitor/Makefile +++ b/apps/system/usbmonitor/Makefile @@ -44,7 +44,6 @@ endif # Hello Application # TODO: appname can be automatically extracted from the directory name -APPNAME = usbmon PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = 768 @@ -90,7 +89,8 @@ $(COBJS): %$(OBJEXT): %.c ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) + $(call REGISTER,"usbmon_start",$(PRIORITY),$(STACKSIZE),usbmonitor_start) + $(call REGISTER,"usbmon_stop",$(PRIORITY),$(STACKSIZE),usbmonintor_stop) context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat else diff --git a/apps/system/usbmonitor/usbmonitor.c b/apps/system/usbmonitor/usbmonitor.c index b101b128c..b615b99f9 100644 --- a/apps/system/usbmonitor/usbmonitor.c +++ b/apps/system/usbmonitor/usbmonitor.c @@ -40,20 +40,29 @@ #include #include -#include -#include +#include +#include +#include + +#include event, trace->value); + return 0; +} + static int usbmonitor_daemon(int argc, char **argv) { -#ifdef CONFIG_NSH_BUILTIN_APPS - print("USB Monitor running: %d\n", g_usbmonitor.pid); -#endif + syslog(USBMON_PREFIX "Running: %d\n", g_usbmonitor.pid); -#ifdef CONFIG_NSH_BUILTIN_APPS - /* If we are running as an NSH command, then loop until we detect that - * there is a request to stop. - */ + /* Loop until we detect that there is a request to stop. */ while (!g_usbmonitor.stop) -#else - /* If we are running as a standalone program, then loop forever */ - - for (;;) -#endif { -#warning "Missing logic" + (void)usbmonitor_enumerate(nsh_tracecallback, NULL); } /* Stopped */ -#ifdef CONFIG_NSH_BUILTIN_APPS g_usbmonitor.stop = false; g_usbmonitor.started = false; - print("USB Monitor stopped: %d\n", g_usbmonitor.pid); -#endif + syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid); + return 0; } @@ -101,9 +105,8 @@ static int usbmonitor_daemon(int argc, char **argv) * Public Functions ****************************************************************************/ -int usbmonitor_main(int argc, char **argv) +int usbmonitor_start(int argc, char **argv) { -#ifdef CONFIG_NSH_BUILTIN_APPS /* Has the monitor already started? */ sched_lock(); @@ -122,13 +125,14 @@ int usbmonitor_main(int argc, char **argv) if (ret < 0) { int errcode = errno; - fprintf(stderr, "ERROR: Failed to start the USB monitor: %d\n", - errcode); + syslog(USBMON_PREFIX + "ERROR: Failed to start the USB monitor: %d\n", + errcode); } else { g_usbmonitor.pid = ret; - print("USB Monitor started: %d\n", g_usbmonitor.pid); + syslog(USBMON_PREFIX "Started: %d\n", g_usbmonitor.pid); } sched_unlock(); @@ -136,27 +140,23 @@ int usbmonitor_main(int argc, char **argv) } sched_unlock(); - print("USB Monitor running: %d\n", g_usbmonitor.pid); + syslog(USBMON_PREFIX "Running: %d\n", g_usbmonitor.pid); return 0; -#else - return usbmonitor_daemon(argc, argv); -#endif } -#ifdef CONFIG_NSH_BUILTIN_APPS int usbmonitor_stop(int argc, char **argv) { /* Has the monitor already started? */ if (g_usbmonitor.started) { - print("USB Monitor stopping: %d\n", g_usbmonitor.pid); + syslog(USBMON_PREFIX "Stopping: %d\n", g_usbmonitor.pid); g_usbmonitor.stop = true; return 0; } - print("USB Monitor stopped: %d\n", g_usbmonitor.pid); + syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid); return 0; } -#endif +#endif /* CONFIG_SYSTEM_USBMONITOR */ diff --git a/misc/tools/README.txt b/misc/tools/README.txt index e1c67c5f0..1eb8790f1 100644 --- a/misc/tools/README.txt +++ b/misc/tools/README.txt @@ -45,14 +45,14 @@ kconfig-frontends To suppress the 'nconf' and the graphical front-ends which are not used by NuttX, you can add: - ./configure --enable-mconfig --disable-nconf --disable-gconf --disable-qconf + ./configure --enable-mconf --disable-nconf --disable-gconf --disable-qconf make make install To suppress the graphical interfaces, use static libraries, and disable creation of other utilities: - ./configure --disable-shared --enable-static --enable-mconfig --disable-nconf --disable-gconf --disable-qconf --disable-nconf --disable-utils + ./configure --disable-shared --enable-static --enable-mconf --disable-nconf --disable-gconf --disable-qconf --disable-nconf --disable-utils make make install diff --git a/nuttx/Documentation/NuttxPortingGuide.html b/nuttx/Documentation/NuttxPortingGuide.html index fd358f423..f2f7ada02 100644 --- a/nuttx/Documentation/NuttxPortingGuide.html +++ b/nuttx/Documentation/NuttxPortingGuide.html @@ -4324,17 +4324,17 @@ build
  • CONFIG_DEBUG: enables built-in debug options. This includes more extensive parameter checking, debug assertions, and other debug logic. - This option is also necessary (but not sufficient) to enable debug console output; - Debug console output must also be enabled on a subsystem-by-subsystem basis as described below. + This option is also necessary (but not sufficient) to enable debug syslog output; + Debug syslog output must also be enabled on a subsystem-by-subsystem basis as described below.
  • - CONFIG_DEBUG_VERBOSE: If debug console output is enabled, the option enables more verbose debug output. + CONFIG_DEBUG_VERBOSE: If debug syslog output is enabled, the option enables more verbose debug output. Ignored if CONFIG_DEBUG is not defined. If only CONFIG_DEBUG then the only output will be errors, warnings, and critical information. - If CONFIG_DEBUG_VERBOSE is defined in addition, then general debug comments will also be included in the console output. + If CONFIG_DEBUG_VERBOSE is defined in addition, then general debug comments will also be included in the syslog output.
  • - CONFIG_DEBUG_ENABLE: Support an interface to enable or disable debug output. + CONFIG_SYSLOG_ENABLE: Support an interface to enable or disable syslog output.
  • CONFIG_DEBUG_SYMBOLS: build without optimization and with debug symbols (needed for use with a debugger). diff --git a/nuttx/Kconfig b/nuttx/Kconfig index 10d624efb..937bab2be 100644 --- a/nuttx/Kconfig +++ b/nuttx/Kconfig @@ -312,11 +312,12 @@ config DEBUG_VERBOSE often annoying) output will be generated. This means there are two levels of debug output: errors-only and everything. -config DEBUG_ENABLE +config SYSLOG_ENABLE bool "Enable Debug Controls" default n ---help--- - Support an interface to dynamically enable or disable debug output. + Support an interface called syslog_enable to dynamically enable or + disable debug output. comment "Subsystem Debug Options" diff --git a/nuttx/TODO b/nuttx/TODO index 05e0fa99b..6b2c6c883 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated January 27, 2013) +NuttX TODO List (Last updated January 28, 2013) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -14,7 +14,7 @@ nuttx/ (6) Binary loaders (binfmt/) (16) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) - (12) Libraries (libc/, ) + (11) Libraries (libc/, ) (9) File system/Generic drivers (fs/, drivers/) (5) Graphics subystem (graphics/) (1) Pascal add-on (pcode/) @@ -812,19 +812,6 @@ o Libraries (libc/) Status: Open Priority: ?? - Title: SYSLOG INTEGRATION - Description: There are the beginnings of some system logging capabilities (see - drivers/syslog, fs/fs_syslog.c, and libc/stdio/lib_librawprintf.c and - lib_liblowprintf.c. For NuttX, SYSLOG is a concept and includes, - extends, and replaces the legacy NuttX debug ouput. Some additional - integration is required to formalized this. For example: - - o lib_rawprintf() shjould be renamed syslog(). - o debug.h should be renamed syslog.h - o And what about lib_lowprintf()? llsyslog? - Status: Open - Priority: Low -- more of a roadmap - Title: FLOATING POINT FORMATS Description: Only the %f floating point format is supported. Others are accepted but treated like %f. diff --git a/nuttx/arch/arm/src/arm/up_assert.c b/nuttx/arch/arm/src/arm/up_assert.c index 3d75a4655..3cc79df01 100644 --- a/nuttx/arch/arm/src/arm/up_assert.c +++ b/nuttx/arch/arm/src/arm/up_assert.c @@ -62,7 +62,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /* The following is just intended to keep some ugliness out of the mainline @@ -70,7 +70,7 @@ * * CONFIG_TASK_NAME_SIZE > 0 && <-- The task has a name * (defined(CONFIG_DEBUG) || <-- And the debug is enabled (lldbg used) - * defined(CONFIG_ARCH_STACKDUMP) <-- Or lib_lowprintf() is used + * defined(CONFIG_ARCH_STACKDUMP) <-- Or lowsyslog() is used */ #undef CONFIG_PRINT_TASKNAME diff --git a/nuttx/arch/arm/src/arm/up_dataabort.c b/nuttx/arch/arm/src/arm/up_dataabort.c index f01941968..60ef8385e 100644 --- a/nuttx/arch/arm/src/arm/up_dataabort.c +++ b/nuttx/arch/arm/src/arm/up_dataabort.c @@ -62,7 +62,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/arm/src/arm/up_prefetchabort.c b/nuttx/arch/arm/src/arm/up_prefetchabort.c index 9af644fc0..9d028b0d4 100644 --- a/nuttx/arch/arm/src/arm/up_prefetchabort.c +++ b/nuttx/arch/arm/src/arm/up_prefetchabort.c @@ -62,7 +62,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/arm/src/arm/up_syscall.c b/nuttx/arch/arm/src/arm/up_syscall.c index 1bcd66502..eb9bac8ad 100644 --- a/nuttx/arch/arm/src/arm/up_syscall.c +++ b/nuttx/arch/arm/src/arm/up_syscall.c @@ -56,7 +56,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/arm/src/arm/up_undefinedinsn.c b/nuttx/arch/arm/src/arm/up_undefinedinsn.c index d61abe11b..88e3a79d9 100644 --- a/nuttx/arch/arm/src/arm/up_undefinedinsn.c +++ b/nuttx/arch/arm/src/arm/up_undefinedinsn.c @@ -54,7 +54,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/arm/src/armv7-m/up_assert.c b/nuttx/arch/arm/src/armv7-m/up_assert.c index ab30b09f3..8e29bfe80 100644 --- a/nuttx/arch/arm/src/armv7-m/up_assert.c +++ b/nuttx/arch/arm/src/armv7-m/up_assert.c @@ -62,7 +62,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /* The following is just intended to keep some ugliness out of the mainline @@ -70,7 +70,7 @@ * * CONFIG_TASK_NAME_SIZE > 0 && <-- The task has a name * (defined(CONFIG_DEBUG) || <-- And the debug is enabled (lldbg used) - * defined(CONFIG_ARCH_STACKDUMP) <-- Or lib_lowprintf() is used + * defined(CONFIG_ARCH_STACKDUMP) <-- Or lowsyslog() is used */ #undef CONFIG_PRINT_TASKNAME diff --git a/nuttx/arch/arm/src/dm320/dm320_decodeirq.c b/nuttx/arch/arm/src/dm320/dm320_decodeirq.c index c7032c4b1..98ba76097 100644 --- a/nuttx/arch/arm/src/dm320/dm320_decodeirq.c +++ b/nuttx/arch/arm/src/dm320/dm320_decodeirq.c @@ -74,7 +74,7 @@ void up_decodeirq(uint32_t* regs) { #ifdef CONFIG_SUPPRESS_INTERRUPTS - lib_lowprintf("Unexpected IRQ\n"); + lowsyslog("Unexpected IRQ\n"); current_regs = regs; PANIC(OSERR_ERREXCEPTION); #else diff --git a/nuttx/arch/arm/src/imx/imx_decodeirq.c b/nuttx/arch/arm/src/imx/imx_decodeirq.c index ba37a60a2..230a4fc20 100644 --- a/nuttx/arch/arm/src/imx/imx_decodeirq.c +++ b/nuttx/arch/arm/src/imx/imx_decodeirq.c @@ -74,7 +74,7 @@ void up_decodeirq(uint32_t* regs) { #ifdef CONFIG_SUPPRESS_INTERRUPTS - lib_lowprintf("Unexpected IRQ\n"); + lowsyslog("Unexpected IRQ\n"); current_regs = regs; PANIC(OSERR_ERREXCEPTION); #else diff --git a/nuttx/arch/arm/src/lpc214x/lpc214x_decodeirq.c b/nuttx/arch/arm/src/lpc214x/lpc214x_decodeirq.c index 652fe4d61..057e526c2 100644 --- a/nuttx/arch/arm/src/lpc214x/lpc214x_decodeirq.c +++ b/nuttx/arch/arm/src/lpc214x/lpc214x_decodeirq.c @@ -112,7 +112,7 @@ static void lpc214x_decodeirq( uint32_t *regs) #endif { #ifdef CONFIG_SUPPRESS_INTERRUPTS - lib_lowprintf("Unexpected IRQ\n"); + lowsyslog("Unexpected IRQ\n"); current_regs = regs; PANIC(OSERR_ERREXCEPTION); #else diff --git a/nuttx/arch/arm/src/lpc2378/lpc23xx_decodeirq.c b/nuttx/arch/arm/src/lpc2378/lpc23xx_decodeirq.c index a55ed339d..3a50beb50 100644 --- a/nuttx/arch/arm/src/lpc2378/lpc23xx_decodeirq.c +++ b/nuttx/arch/arm/src/lpc2378/lpc23xx_decodeirq.c @@ -111,7 +111,7 @@ static void lpc23xx_decodeirq(uint32_t *regs) #endif { #ifdef CONFIG_SUPPRESS_INTERRUPTS - lib_lowprintf("Unexpected IRQ\n"); + lowsyslog("Unexpected IRQ\n"); current_regs = regs; PANIC(OSERR_ERREXCEPTION); #else diff --git a/nuttx/arch/arm/src/lpc31xx/lpc31_decodeirq.c b/nuttx/arch/arm/src/lpc31xx/lpc31_decodeirq.c index 41e1d3e13..0e73f131b 100644 --- a/nuttx/arch/arm/src/lpc31xx/lpc31_decodeirq.c +++ b/nuttx/arch/arm/src/lpc31xx/lpc31_decodeirq.c @@ -77,7 +77,7 @@ void up_decodeirq(uint32_t *regs) { #ifdef CONFIG_SUPPRESS_INTERRUPTS - lib_lowprintf("Unexpected IRQ\n"); + lowsyslog("Unexpected IRQ\n"); current_regs = regs; PANIC(OSERR_ERREXCEPTION); #else diff --git a/nuttx/arch/arm/src/stm32/stm32_i2c.c b/nuttx/arch/arm/src/stm32/stm32_i2c.c index 18687c6f4..c2d638dd4 100644 --- a/nuttx/arch/arm/src/stm32/stm32_i2c.c +++ b/nuttx/arch/arm/src/stm32/stm32_i2c.c @@ -159,7 +159,7 @@ #endif /* I2C event trace logic. NOTE: trace uses the internal, non-standard, low-level - * debug interface lib_rawprintf() but does not require that any other debug + * debug interface syslog() but does not require that any other debug * is enabled. */ @@ -899,11 +899,11 @@ static void stm32_i2c_tracedump(FAR struct stm32_i2c_priv_s *priv) struct stm32_trace_s *trace; int i; - lib_rawprintf("Elapsed time: %d\n", clock_systimer() - priv->start_time); + syslog("Elapsed time: %d\n", clock_systimer() - priv->start_time); for (i = 0; i <= priv->tndx; i++) { trace = &priv->trace[i]; - lib_rawprintf("%2d. STATUS: %08x COUNT: %3d EVENT: %2d PARM: %08x TIME: %d\n", + syslog("%2d. STATUS: %08x COUNT: %3d EVENT: %2d PARM: %08x TIME: %d\n", i+1, trace->status, trace->count, trace->event, trace->parm, trace->time - priv->start_time); } diff --git a/nuttx/arch/arm/src/str71x/str71x_decodeirq.c b/nuttx/arch/arm/src/str71x/str71x_decodeirq.c index 326abd763..48c9aa7e4 100644 --- a/nuttx/arch/arm/src/str71x/str71x_decodeirq.c +++ b/nuttx/arch/arm/src/str71x/str71x_decodeirq.c @@ -91,7 +91,7 @@ void up_decodeirq(uint32_t *regs) { #ifdef CONFIG_SUPPRESS_INTERRUPTS up_ledon(LED_INIRQ); - lib_lowprintf("Unexpected IRQ\n"); + lowsyslog("Unexpected IRQ\n"); current_regs = regs; PANIC(OSERR_ERREXCEPTION); #else diff --git a/nuttx/arch/avr/src/avr/up_dumpstate.c b/nuttx/arch/avr/src/avr/up_dumpstate.c index 902c2ce9f..3ce595bf0 100644 --- a/nuttx/arch/avr/src/avr/up_dumpstate.c +++ b/nuttx/arch/avr/src/avr/up_dumpstate.c @@ -63,7 +63,7 @@ */ #undef lldbg -#define lldbg lib_lowprintf +#define lldbg lowsyslog /**************************************************************************** * Private Data diff --git a/nuttx/arch/avr/src/avr32/up_dumpstate.c b/nuttx/arch/avr/src/avr32/up_dumpstate.c index 15a3e7ef8..d6113d40b 100644 --- a/nuttx/arch/avr/src/avr32/up_dumpstate.c +++ b/nuttx/arch/avr/src/avr32/up_dumpstate.c @@ -63,7 +63,7 @@ */ #undef lldbg -#define lldbg lib_lowprintf +#define lldbg lowsyslog /**************************************************************************** * Private Data diff --git a/nuttx/arch/avr/src/common/up_assert.c b/nuttx/arch/avr/src/common/up_assert.c index 12bb564d3..3e90094eb 100644 --- a/nuttx/arch/avr/src/common/up_assert.c +++ b/nuttx/arch/avr/src/common/up_assert.c @@ -61,7 +61,7 @@ * * CONFIG_TASK_NAME_SIZE > 0 && <-- The task has a name * (defined(CONFIG_DEBUG) || <-- And the debug is enabled (lldbg used) - * defined(CONFIG_ARCH_STACKDUMP)) <-- Or lib_lowprintf() is used + * defined(CONFIG_ARCH_STACKDUMP)) <-- Or lowsyslog() is used */ #undef CONFIG_PRINT_TASKNAME @@ -75,7 +75,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/hc/src/m9s12/m9s12_assert.c b/nuttx/arch/hc/src/m9s12/m9s12_assert.c index ff9ce5ca4..65cc75590 100644 --- a/nuttx/arch/hc/src/m9s12/m9s12_assert.c +++ b/nuttx/arch/hc/src/m9s12/m9s12_assert.c @@ -62,7 +62,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /* The following is just intended to keep some ugliness out of the mainline @@ -70,7 +70,7 @@ * * CONFIG_TASK_NAME_SIZE > 0 && <-- The task has a name * (defined(CONFIG_DEBUG) || <-- And the debug is enabled (lldbg used) - * defined(CONFIG_ARCH_STACKDUMP) <-- Or lib_lowprintf() is used + * defined(CONFIG_ARCH_STACKDUMP) <-- Or lowsyslog() is used */ #undef CONFIG_PRINT_TASKNAME diff --git a/nuttx/arch/mips/src/mips32/up_assert.c b/nuttx/arch/mips/src/mips32/up_assert.c index ed4ee4cf7..7d98e7427 100644 --- a/nuttx/arch/mips/src/mips32/up_assert.c +++ b/nuttx/arch/mips/src/mips32/up_assert.c @@ -62,7 +62,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /* The following is just intended to keep some ugliness out of the mainline @@ -70,7 +70,7 @@ * * CONFIG_TASK_NAME_SIZE > 0 && <-- The task has a name * (defined(CONFIG_DEBUG) || <-- And the debug is enabled (lldbg used) - * defined(CONFIG_ARCH_STACKDUMP) <-- Or lib_lowprintf() is used + * defined(CONFIG_ARCH_STACKDUMP) <-- Or lowsyslog() is used */ #undef CONFIG_PRINT_TASKNAME diff --git a/nuttx/arch/mips/src/mips32/up_dumpstate.c b/nuttx/arch/mips/src/mips32/up_dumpstate.c index 866c17b4f..1cd426767 100644 --- a/nuttx/arch/mips/src/mips32/up_dumpstate.c +++ b/nuttx/arch/mips/src/mips32/up_dumpstate.c @@ -63,7 +63,7 @@ */ #undef lldbg -#define lldbg lib_lowprintf +#define lldbg lowsyslog /**************************************************************************** * Private Data diff --git a/nuttx/arch/sh/src/common/up_assert.c b/nuttx/arch/sh/src/common/up_assert.c index ccc0c98e6..5b56e7731 100644 --- a/nuttx/arch/sh/src/common/up_assert.c +++ b/nuttx/arch/sh/src/common/up_assert.c @@ -61,7 +61,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/sh/src/m16c/m16c_dumpstate.c b/nuttx/arch/sh/src/m16c/m16c_dumpstate.c index 438ff21d2..38571a7e1 100644 --- a/nuttx/arch/sh/src/m16c/m16c_dumpstate.c +++ b/nuttx/arch/sh/src/m16c/m16c_dumpstate.c @@ -62,7 +62,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/sh/src/sh1/sh1_dumpstate.c b/nuttx/arch/sh/src/sh1/sh1_dumpstate.c index 296e20a45..f54ea46ce 100644 --- a/nuttx/arch/sh/src/sh1/sh1_dumpstate.c +++ b/nuttx/arch/sh/src/sh1/sh1_dumpstate.c @@ -61,7 +61,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/sim/src/up_initialize.c b/nuttx/arch/sim/src/up_initialize.c index de11c7947..f8ae563e0 100644 --- a/nuttx/arch/sim/src/up_initialize.c +++ b/nuttx/arch/sim/src/up_initialize.c @@ -85,13 +85,13 @@ void up_initialize(void) { - /* The real purpose of the following is to make sure that lib_rawprintf + /* The real purpose of the following is to make sure that syslog * is drawn into the link. It is needed by up_tapdev which is linked * separately. */ #ifdef CONFIG_NET - lib_rawprintf("SIM: Initializing"); + syslog("SIM: Initializing"); #endif /* Register devices */ diff --git a/nuttx/arch/sim/src/up_tapdev.c b/nuttx/arch/sim/src/up_tapdev.c index f2bbcc14a..197049a34 100644 --- a/nuttx/arch/sim/src/up_tapdev.c +++ b/nuttx/arch/sim/src/up_tapdev.c @@ -61,7 +61,7 @@ #include #include -extern int lib_rawprintf(const char *format, ...); +extern int syslog(const char *format, ...); extern int uipdriver_setmacaddr(unsigned char *macaddr); /**************************************************************************** @@ -119,14 +119,14 @@ static int gtapdevfd; #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], + syslog("TAPDEV: %s %d bytes\n", msg, buflen); + syslog(" %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]); + buf[13], buf[12]); #else - buf[12], buf[13]); + buf[12], buf[13]); #endif } #else @@ -179,7 +179,7 @@ void tapdev_init(void) gtapdevfd = open(DEVTAP, O_RDWR, 0644); if (gtapdevfd < 0) { - lib_rawprintf("TAPDEV: open failed: %d\n", -gtapdevfd ); + syslog("TAPDEV: open failed: %d\n", -gtapdevfd ); return; } @@ -190,7 +190,7 @@ void tapdev_init(void) ret = ioctl(gtapdevfd, TUNSETIFF, (unsigned long) &ifr); if (ret < 0) { - lib_rawprintf("TAPDEV: ioctl failed: %d\n", -ret ); + syslog("TAPDEV: ioctl failed: %d\n", -ret ); return; } @@ -235,7 +235,7 @@ unsigned int tapdev_read(unsigned char *buf, unsigned int buflen) ret = read(gtapdevfd, buf, buflen); if (ret < 0) { - lib_rawprintf("TAPDEV: read failed: %d\n", -ret); + syslog("TAPDEV: read failed: %d\n", -ret); return 0; } @@ -247,12 +247,12 @@ void tapdev_send(unsigned char *buf, unsigned int buflen) { int ret; #ifdef TAPDEV_DEBUG - lib_rawprintf("tapdev_send: sending %d bytes\n", buflen); + syslog("tapdev_send: sending %d bytes\n", buflen); gdrop++; if(gdrop % 8 == 7) { - lib_rawprintf("Dropped a packet!\n"); + syslog("Dropped a packet!\n"); return; } #endif @@ -260,7 +260,7 @@ void tapdev_send(unsigned char *buf, unsigned int buflen) ret = write(gtapdevfd, buf, buflen); if (ret < 0) { - lib_rawprintf("TAPDEV: write failed: %d", -ret); + syslog("TAPDEV: write failed: %d", -ret); exit(1); } dump_ethhdr("write", buf, buflen); diff --git a/nuttx/arch/x86/src/common/up_assert.c b/nuttx/arch/x86/src/common/up_assert.c index aa752f84e..87958baa6 100644 --- a/nuttx/arch/x86/src/common/up_assert.c +++ b/nuttx/arch/x86/src/common/up_assert.c @@ -63,7 +63,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /* The following is just intended to keep some ugliness out of the mainline @@ -71,7 +71,7 @@ * * CONFIG_TASK_NAME_SIZE > 0 && <-- The task has a name * (defined(CONFIG_DEBUG) || <-- And the debug is enabled (lldbg used) - * defined(CONFIG_ARCH_STACKDUMP) <-- Or lib_lowprintf() is used + * defined(CONFIG_ARCH_STACKDUMP) <-- Or lowsyslog() is used */ #undef CONFIG_PRINT_TASKNAME diff --git a/nuttx/arch/x86/src/i486/up_regdump.c b/nuttx/arch/x86/src/i486/up_regdump.c index b7547aec4..e30670128 100644 --- a/nuttx/arch/x86/src/i486/up_regdump.c +++ b/nuttx/arch/x86/src/i486/up_regdump.c @@ -51,7 +51,7 @@ /* Output debug info -- even if debug is not selected. */ #undef lldbg -#define lldbg lib_lowprintf +#define lldbg lowsyslog /**************************************************************************** * Private Data diff --git a/nuttx/arch/z16/src/common/up_assert.c b/nuttx/arch/z16/src/common/up_assert.c index 5832ead45..661d88833 100644 --- a/nuttx/arch/z16/src/common/up_assert.c +++ b/nuttx/arch/z16/src/common/up_assert.c @@ -62,7 +62,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/z16/src/common/up_registerdump.c b/nuttx/arch/z16/src/common/up_registerdump.c index dd1f210f7..178320dd2 100644 --- a/nuttx/arch/z16/src/common/up_registerdump.c +++ b/nuttx/arch/z16/src/common/up_registerdump.c @@ -58,7 +58,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/z16/src/common/up_stackdump.c b/nuttx/arch/z16/src/common/up_stackdump.c index b4930f620..077b0c8f7 100644 --- a/nuttx/arch/z16/src/common/up_stackdump.c +++ b/nuttx/arch/z16/src/common/up_stackdump.c @@ -55,7 +55,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/z16/src/z16f/z16f_sysexec.c b/nuttx/arch/z16/src/z16f/z16f_sysexec.c index 2fbc1e2c9..e824076b0 100644 --- a/nuttx/arch/z16/src/z16f/z16f_sysexec.c +++ b/nuttx/arch/z16/src/z16f/z16f_sysexec.c @@ -53,9 +53,9 @@ ***************************************************************************/ #ifdef CONFIG_ARCH_LOWPUTC -# define SYSDBG lib_lowprintf +# define SYSDBG lowsyslog #else -# define SYSDBG lib_rawprintf +# define SYSDBG syslog #endif /*************************************************************************** diff --git a/nuttx/arch/z80/src/common/up_assert.c b/nuttx/arch/z80/src/common/up_assert.c index ff4e569fb..11a2a4f2a 100644 --- a/nuttx/arch/z80/src/common/up_assert.c +++ b/nuttx/arch/z80/src/common/up_assert.c @@ -62,7 +62,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/z80/src/common/up_doirq.c b/nuttx/arch/z80/src/common/up_doirq.c index 4b57f8f7b..ad318e17f 100644 --- a/nuttx/arch/z80/src/common/up_doirq.c +++ b/nuttx/arch/z80/src/common/up_doirq.c @@ -76,7 +76,7 @@ FAR chipreg_t *up_doirq(uint8_t irq, FAR chipreg_t *regs) #ifdef CONFIG_SUPPRESS_INTERRUPTS - lib_lowprintf("Unexpected IRQ\n"); + lowsyslog("Unexpected IRQ\n"); IRQ_ENTER(regs); PANIC(OSERR_ERREXCEPTION); return NULL; /* Won't get here */ diff --git a/nuttx/arch/z80/src/common/up_stackdump.c b/nuttx/arch/z80/src/common/up_stackdump.c index 817c2d315..f9c515337 100644 --- a/nuttx/arch/z80/src/common/up_stackdump.c +++ b/nuttx/arch/z80/src/common/up_stackdump.c @@ -56,7 +56,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/z80/src/ez80/ez80_registerdump.c b/nuttx/arch/z80/src/ez80/ez80_registerdump.c index a43bd6459..bf53f81f7 100644 --- a/nuttx/arch/z80/src/ez80/ez80_registerdump.c +++ b/nuttx/arch/z80/src/ez80/ez80_registerdump.c @@ -58,7 +58,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/z80/src/z180/z180_registerdump.c b/nuttx/arch/z80/src/z180/z180_registerdump.c index 65ae791db..17a44b059 100644 --- a/nuttx/arch/z80/src/z180/z180_registerdump.c +++ b/nuttx/arch/z80/src/z180/z180_registerdump.c @@ -58,7 +58,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/z80/src/z8/z8_registerdump.c b/nuttx/arch/z80/src/z8/z8_registerdump.c index 36b6cdd37..f1ce13a24 100644 --- a/nuttx/arch/z80/src/z8/z8_registerdump.c +++ b/nuttx/arch/z80/src/z8/z8_registerdump.c @@ -59,7 +59,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/arch/z80/src/z80/z80_registerdump.c b/nuttx/arch/z80/src/z80/z80_registerdump.c index 0d09a243a..7bf21a26f 100644 --- a/nuttx/arch/z80/src/z80/z80_registerdump.c +++ b/nuttx/arch/z80/src/z80/z80_registerdump.c @@ -58,7 +58,7 @@ #ifdef CONFIG_ARCH_STACKDUMP # undef lldbg -# define lldbg lib_lowprintf +# define lldbg lowsyslog #endif /**************************************************************************** diff --git a/nuttx/binfmt/libelf/libelf_read.c b/nuttx/binfmt/libelf/libelf_read.c index f4b725183..25ee7ba29 100644 --- a/nuttx/binfmt/libelf/libelf_read.c +++ b/nuttx/binfmt/libelf/libelf_read.c @@ -54,7 +54,7 @@ ****************************************************************************/ #undef ELF_DUMP_READDATA /* Define to dump all file data read */ -#define DUMPER lib_rawprintf /* If ELF_DUMP_READDATA is defined, this +#define DUMPER syslog /* If ELF_DUMP_READDATA is defined, this * is the API used to dump data */ /**************************************************************************** diff --git a/nuttx/binfmt/libnxflat/libnxflat_read.c b/nuttx/binfmt/libnxflat/libnxflat_read.c index 8deeb0805..103a81f81 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_read.c +++ b/nuttx/binfmt/libnxflat/libnxflat_read.c @@ -55,7 +55,7 @@ ****************************************************************************/ #undef NXFLAT_DUMP_READDATA /* Define to dump all file data read */ -#define DUMPER lib_rawprintf /* If NXFLAT_DUMP_READDATA is defined, this +#define DUMPER syslog /* If NXFLAT_DUMP_READDATA is defined, this * is the API used to dump data */ /**************************************************************************** diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt index 1b78567a3..8d9bb381f 100644 --- a/nuttx/configs/README.txt +++ b/nuttx/configs/README.txt @@ -261,7 +261,7 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_DEBUG - enables built-in debug options CONFIG_DEBUG_VERBOSE - enables verbose debug output - CCONFIG_DEBUG_ENABLE - Support an interface to enable or disable debug output. + CCONFIG_SYSLOG_ENABLE - Support an interface to enable or disable debug output. CONFIG_DEBUG_SYMBOLS - build without optimization and with debug symbols (needed for use with a debugger). CONFIG_DEBUG_SCHED - enable OS debug output (disabled by diff --git a/nuttx/configs/cloudctrl/src/up_nsh.c b/nuttx/configs/cloudctrl/src/up_nsh.c index f389460bb..6baeeeab8 100644 --- a/nuttx/configs/cloudctrl/src/up_nsh.c +++ b/nuttx/configs/cloudctrl/src/up_nsh.c @@ -101,13 +101,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/cloudctrl/src/up_usbmsc.c b/nuttx/configs/cloudctrl/src/up_usbmsc.c index 1e74e6f24..95fc0189a 100644 --- a/nuttx/configs/cloudctrl/src/up_usbmsc.c +++ b/nuttx/configs/cloudctrl/src/up_usbmsc.c @@ -61,7 +61,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -69,7 +69,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/demo9s12ne64/src/up_nsh.c b/nuttx/configs/demo9s12ne64/src/up_nsh.c index 7e53f7f07..c4773c0ac 100644 --- a/nuttx/configs/demo9s12ne64/src/up_nsh.c +++ b/nuttx/configs/demo9s12ne64/src/up_nsh.c @@ -54,13 +54,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/ea3131/src/up_nsh.c b/nuttx/configs/ea3131/src/up_nsh.c index 29ee7ed2c..b763c26f0 100644 --- a/nuttx/configs/ea3131/src/up_nsh.c +++ b/nuttx/configs/ea3131/src/up_nsh.c @@ -100,13 +100,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/ea3131/src/up_usbmsc.c b/nuttx/configs/ea3131/src/up_usbmsc.c index 5f4850ea1..e1869af4d 100644 --- a/nuttx/configs/ea3131/src/up_usbmsc.c +++ b/nuttx/configs/ea3131/src/up_usbmsc.c @@ -91,8 +91,8 @@ int usbmsc_archinitialize(void) pbuffer = (uint8_t *) malloc (BUFFER_SIZE); if (!pbuffer) { - lib_lowprintf ("usbmsc_archinitialize: Failed to allocate ramdisk of size %d\n", - BUFFER_SIZE); + lowsyslog("usbmsc_archinitialize: Failed to allocate ramdisk of size %d\n", + BUFFER_SIZE); return -ENOMEM; } diff --git a/nuttx/configs/ea3152/src/up_nsh.c b/nuttx/configs/ea3152/src/up_nsh.c index 2b523b44a..d4ac3da27 100644 --- a/nuttx/configs/ea3152/src/up_nsh.c +++ b/nuttx/configs/ea3152/src/up_nsh.c @@ -100,13 +100,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/ea3152/src/up_usbmsc.c b/nuttx/configs/ea3152/src/up_usbmsc.c index 2c3356b4e..ee67f0eed 100644 --- a/nuttx/configs/ea3152/src/up_usbmsc.c +++ b/nuttx/configs/ea3152/src/up_usbmsc.c @@ -91,8 +91,8 @@ int usbmsc_archinitialize(void) pbuffer = (uint8_t *) malloc (BUFFER_SIZE); if (!pbuffer) { - lib_lowprintf ("usbmsc_archinitialize: Failed to allocate ramdisk of size %d\n", - BUFFER_SIZE); + lowsyslog("usbmsc_archinitialize: Failed to allocate ramdisk of size %d\n", + BUFFER_SIZE); return -ENOMEM; } diff --git a/nuttx/configs/eagle100/src/up_nsh.c b/nuttx/configs/eagle100/src/up_nsh.c index 65fd30023..b1df8cde6 100644 --- a/nuttx/configs/eagle100/src/up_nsh.c +++ b/nuttx/configs/eagle100/src/up_nsh.c @@ -95,13 +95,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/ekk-lm3s9b96/src/up_nsh.c b/nuttx/configs/ekk-lm3s9b96/src/up_nsh.c index 6f9aac6b1..f54fb726c 100644 --- a/nuttx/configs/ekk-lm3s9b96/src/up_nsh.c +++ b/nuttx/configs/ekk-lm3s9b96/src/up_nsh.c @@ -55,13 +55,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/ez80f910200kitg/ostest/defconfig b/nuttx/configs/ez80f910200kitg/ostest/defconfig index d86177828..1abc3fb58 100644 --- a/nuttx/configs/ez80f910200kitg/ostest/defconfig +++ b/nuttx/configs/ez80f910200kitg/ostest/defconfig @@ -44,7 +44,7 @@ CONFIG_WINDOWS_CYGWIN=y # CONFIG_DEBUG=y # CONFIG_DEBUG_VERBOSE is not set -# CONFIG_DEBUG_ENABLE is not set +# CONFIG_SYSLOG_ENABLE is not set # # Subsystem Debug Options diff --git a/nuttx/configs/ez80f910200zco/ostest/defconfig b/nuttx/configs/ez80f910200zco/ostest/defconfig index e414cfcc1..146b56327 100644 --- a/nuttx/configs/ez80f910200zco/ostest/defconfig +++ b/nuttx/configs/ez80f910200zco/ostest/defconfig @@ -44,7 +44,7 @@ CONFIG_WINDOWS_CYGWIN=y # CONFIG_DEBUG=y # CONFIG_DEBUG_VERBOSE is not set -# CONFIG_DEBUG_ENABLE is not set +# CONFIG_SYSLOG_ENABLE is not set # # Subsystem Debug Options diff --git a/nuttx/configs/fire-stm32v2/src/up_composite.c b/nuttx/configs/fire-stm32v2/src/up_composite.c index 6ebc06176..15200caa8 100644 --- a/nuttx/configs/fire-stm32v2/src/up_composite.c +++ b/nuttx/configs/fire-stm32v2/src/up_composite.c @@ -60,7 +60,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -68,7 +68,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/fire-stm32v2/src/up_nsh.c b/nuttx/configs/fire-stm32v2/src/up_nsh.c index ba93d714f..fa261f561 100644 --- a/nuttx/configs/fire-stm32v2/src/up_nsh.c +++ b/nuttx/configs/fire-stm32v2/src/up_nsh.c @@ -127,13 +127,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/fire-stm32v2/src/up_usbmsc.c b/nuttx/configs/fire-stm32v2/src/up_usbmsc.c index 8a8269539..f1f6ee69c 100644 --- a/nuttx/configs/fire-stm32v2/src/up_usbmsc.c +++ b/nuttx/configs/fire-stm32v2/src/up_usbmsc.c @@ -60,7 +60,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -68,7 +68,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/hymini-stm32v/src/up_nsh.c b/nuttx/configs/hymini-stm32v/src/up_nsh.c index ae1ea03a6..5b823012d 100644 --- a/nuttx/configs/hymini-stm32v/src/up_nsh.c +++ b/nuttx/configs/hymini-stm32v/src/up_nsh.c @@ -110,13 +110,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/hymini-stm32v/src/up_usbmsc.c b/nuttx/configs/hymini-stm32v/src/up_usbmsc.c index 1ce55adcc..da8f02533 100644 --- a/nuttx/configs/hymini-stm32v/src/up_usbmsc.c +++ b/nuttx/configs/hymini-stm32v/src/up_usbmsc.c @@ -78,7 +78,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -86,7 +86,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/kwikstik-k40/src/up_nsh.c b/nuttx/configs/kwikstik-k40/src/up_nsh.c index 884ff3c44..1e52c931e 100644 --- a/nuttx/configs/kwikstik-k40/src/up_nsh.c +++ b/nuttx/configs/kwikstik-k40/src/up_nsh.c @@ -109,13 +109,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/kwikstik-k40/src/up_usbmsc.c b/nuttx/configs/kwikstik-k40/src/up_usbmsc.c index 8051ea1ba..ea97cb99f 100644 --- a/nuttx/configs/kwikstik-k40/src/up_usbmsc.c +++ b/nuttx/configs/kwikstik-k40/src/up_usbmsc.c @@ -74,7 +74,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -82,7 +82,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/lincoln60/src/up_nsh.c b/nuttx/configs/lincoln60/src/up_nsh.c index 2c829837a..a4a679415 100644 --- a/nuttx/configs/lincoln60/src/up_nsh.c +++ b/nuttx/configs/lincoln60/src/up_nsh.c @@ -56,13 +56,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/lm3s6432-s2e/src/up_nsh.c b/nuttx/configs/lm3s6432-s2e/src/up_nsh.c index 46726e753..75107be22 100644 --- a/nuttx/configs/lm3s6432-s2e/src/up_nsh.c +++ b/nuttx/configs/lm3s6432-s2e/src/up_nsh.c @@ -57,13 +57,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/lm3s6965-ek/src/up_nsh.c b/nuttx/configs/lm3s6965-ek/src/up_nsh.c index 409b351f0..24b8b0206 100644 --- a/nuttx/configs/lm3s6965-ek/src/up_nsh.c +++ b/nuttx/configs/lm3s6965-ek/src/up_nsh.c @@ -95,13 +95,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/lm3s8962-ek/src/up_nsh.c b/nuttx/configs/lm3s8962-ek/src/up_nsh.c index 693862184..f12c48988 100644 --- a/nuttx/configs/lm3s8962-ek/src/up_nsh.c +++ b/nuttx/configs/lm3s8962-ek/src/up_nsh.c @@ -95,13 +95,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/lpcxpresso-lpc1768/src/up_nsh.c b/nuttx/configs/lpcxpresso-lpc1768/src/up_nsh.c index b9c39ed16..6165cd9e9 100644 --- a/nuttx/configs/lpcxpresso-lpc1768/src/up_nsh.c +++ b/nuttx/configs/lpcxpresso-lpc1768/src/up_nsh.c @@ -103,13 +103,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/lpcxpresso-lpc1768/src/up_usbmsc.c b/nuttx/configs/lpcxpresso-lpc1768/src/up_usbmsc.c index c43028f1e..937c7857a 100644 --- a/nuttx/configs/lpcxpresso-lpc1768/src/up_usbmsc.c +++ b/nuttx/configs/lpcxpresso-lpc1768/src/up_usbmsc.c @@ -74,7 +74,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -82,7 +82,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/mbed/src/up_nsh.c b/nuttx/configs/mbed/src/up_nsh.c index 3a23ca7a5..883a0da15 100644 --- a/nuttx/configs/mbed/src/up_nsh.c +++ b/nuttx/configs/mbed/src/up_nsh.c @@ -72,13 +72,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/mcu123-lpc214x/src/up_composite.c b/nuttx/configs/mcu123-lpc214x/src/up_composite.c index 3540cdb8a..8feacc971 100644 --- a/nuttx/configs/mcu123-lpc214x/src/up_composite.c +++ b/nuttx/configs/mcu123-lpc214x/src/up_composite.c @@ -75,7 +75,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -83,7 +83,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/mcu123-lpc214x/src/up_nsh.c b/nuttx/configs/mcu123-lpc214x/src/up_nsh.c index 14b5d7d97..c4a56784f 100644 --- a/nuttx/configs/mcu123-lpc214x/src/up_nsh.c +++ b/nuttx/configs/mcu123-lpc214x/src/up_nsh.c @@ -95,13 +95,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/mcu123-lpc214x/src/up_usbmsc.c b/nuttx/configs/mcu123-lpc214x/src/up_usbmsc.c index 79d9344a4..f003d4c3c 100644 --- a/nuttx/configs/mcu123-lpc214x/src/up_usbmsc.c +++ b/nuttx/configs/mcu123-lpc214x/src/up_usbmsc.c @@ -74,7 +74,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -82,7 +82,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/ne64badge/src/up_nsh.c b/nuttx/configs/ne64badge/src/up_nsh.c index 17a52819b..10e0e74d5 100644 --- a/nuttx/configs/ne64badge/src/up_nsh.c +++ b/nuttx/configs/ne64badge/src/up_nsh.c @@ -54,13 +54,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/nucleus2g/src/up_nsh.c b/nuttx/configs/nucleus2g/src/up_nsh.c index 9986c8282..4453d73a1 100644 --- a/nuttx/configs/nucleus2g/src/up_nsh.c +++ b/nuttx/configs/nucleus2g/src/up_nsh.c @@ -97,13 +97,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/nucleus2g/src/up_usbmsc.c b/nuttx/configs/nucleus2g/src/up_usbmsc.c index 8c71a5ce7..f4a533cb6 100644 --- a/nuttx/configs/nucleus2g/src/up_usbmsc.c +++ b/nuttx/configs/nucleus2g/src/up_usbmsc.c @@ -74,7 +74,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -82,7 +82,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/olimex-lpc1766stk/src/up_nsh.c b/nuttx/configs/olimex-lpc1766stk/src/up_nsh.c index 99e9c4d9c..f201c8a1b 100644 --- a/nuttx/configs/olimex-lpc1766stk/src/up_nsh.c +++ b/nuttx/configs/olimex-lpc1766stk/src/up_nsh.c @@ -124,13 +124,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/olimex-lpc1766stk/src/up_usbmsc.c b/nuttx/configs/olimex-lpc1766stk/src/up_usbmsc.c index ce7c75771..5f97aff81 100644 --- a/nuttx/configs/olimex-lpc1766stk/src/up_usbmsc.c +++ b/nuttx/configs/olimex-lpc1766stk/src/up_usbmsc.c @@ -77,7 +77,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -85,7 +85,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/olimex-lpc2378/src/up_nsh.c b/nuttx/configs/olimex-lpc2378/src/up_nsh.c index 6279a7668..f5ec1fed8 100644 --- a/nuttx/configs/olimex-lpc2378/src/up_nsh.c +++ b/nuttx/configs/olimex-lpc2378/src/up_nsh.c @@ -84,13 +84,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/olimex-strp711/src/up_nsh.c b/nuttx/configs/olimex-strp711/src/up_nsh.c index 21c3efb83..7499a8d8f 100644 --- a/nuttx/configs/olimex-strp711/src/up_nsh.c +++ b/nuttx/configs/olimex-strp711/src/up_nsh.c @@ -99,13 +99,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/pic32-starterkit/src/up_nsh.c b/nuttx/configs/pic32-starterkit/src/up_nsh.c index 0f0f0dffe..f0e745112 100644 --- a/nuttx/configs/pic32-starterkit/src/up_nsh.c +++ b/nuttx/configs/pic32-starterkit/src/up_nsh.c @@ -154,13 +154,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/pic32-starterkit/src/up_usbmsc.c b/nuttx/configs/pic32-starterkit/src/up_usbmsc.c index c645c0fe5..51e450c56 100644 --- a/nuttx/configs/pic32-starterkit/src/up_usbmsc.c +++ b/nuttx/configs/pic32-starterkit/src/up_usbmsc.c @@ -50,7 +50,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -58,7 +58,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/pic32mx7mmb/src/up_nsh.c b/nuttx/configs/pic32mx7mmb/src/up_nsh.c index d063450d3..a1bfbeaa2 100644 --- a/nuttx/configs/pic32mx7mmb/src/up_nsh.c +++ b/nuttx/configs/pic32mx7mmb/src/up_nsh.c @@ -153,13 +153,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/pic32mx7mmb/src/up_usbmsc.c b/nuttx/configs/pic32mx7mmb/src/up_usbmsc.c index fbebaa3d1..d1f473d4f 100644 --- a/nuttx/configs/pic32mx7mmb/src/up_usbmsc.c +++ b/nuttx/configs/pic32mx7mmb/src/up_usbmsc.c @@ -50,7 +50,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -58,7 +58,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/rgmp/include/README.txt b/nuttx/configs/rgmp/include/README.txt index 006f13e7c..78da4eb92 100644 --- a/nuttx/configs/rgmp/include/README.txt +++ b/nuttx/configs/rgmp/include/README.txt @@ -1 +1 @@ -This directory is reserved for RGMP header files +This directory is reserved for RGMP header files diff --git a/nuttx/configs/rgmp/src/README.txt b/nuttx/configs/rgmp/src/README.txt index d7d216e24..3d0f237c0 100644 --- a/nuttx/configs/rgmp/src/README.txt +++ b/nuttx/configs/rgmp/src/README.txt @@ -1 +1 @@ -This directory is reserved for RGMP source files +This directory is reserved for RGMP source files diff --git a/nuttx/configs/sam3u-ek/src/up_nsh.c b/nuttx/configs/sam3u-ek/src/up_nsh.c index e8c0df87b..7b3174a74 100644 --- a/nuttx/configs/sam3u-ek/src/up_nsh.c +++ b/nuttx/configs/sam3u-ek/src/up_nsh.c @@ -100,13 +100,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) syslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_rawprintf +# define message syslog # else # define message printf # endif diff --git a/nuttx/configs/sam3u-ek/src/up_usbmsc.c b/nuttx/configs/sam3u-ek/src/up_usbmsc.c index 7e04ee04a..dfe2e2c49 100644 --- a/nuttx/configs/sam3u-ek/src/up_usbmsc.c +++ b/nuttx/configs/sam3u-ek/src/up_usbmsc.c @@ -76,7 +76,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -84,7 +84,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/shenzhou/src/up_composite.c b/nuttx/configs/shenzhou/src/up_composite.c index 81c33dcc8..fb1640908 100644 --- a/nuttx/configs/shenzhou/src/up_composite.c +++ b/nuttx/configs/shenzhou/src/up_composite.c @@ -60,7 +60,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -68,7 +68,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/shenzhou/src/up_ili93xx.c b/nuttx/configs/shenzhou/src/up_ili93xx.c index a89e20d02..1a099f820 100644 --- a/nuttx/configs/shenzhou/src/up_ili93xx.c +++ b/nuttx/configs/shenzhou/src/up_ili93xx.c @@ -833,14 +833,14 @@ static void stm32_dumprun(FAR const char *msg, FAR uint16_t *run, size_t npixels { int i, j; - lib_rawprintf("\n%s:\n", msg); + syslog("\n%s:\n", msg); for (i = 0; i < npixels; i += 16) { up_putc(' '); - lib_rawprintf(" "); + syslog(" "); for (j = 0; j < 16; j++) { - lib_rawprintf(" %04x", *run++); + syslog(" %04x", *run++); } up_putc('\n'); } diff --git a/nuttx/configs/shenzhou/src/up_nsh.c b/nuttx/configs/shenzhou/src/up_nsh.c index 685281f5d..d68a734e0 100644 --- a/nuttx/configs/shenzhou/src/up_nsh.c +++ b/nuttx/configs/shenzhou/src/up_nsh.c @@ -149,13 +149,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/shenzhou/src/up_usbmsc.c b/nuttx/configs/shenzhou/src/up_usbmsc.c index 8566aedfd..eaecfb496 100644 --- a/nuttx/configs/shenzhou/src/up_usbmsc.c +++ b/nuttx/configs/shenzhou/src/up_usbmsc.c @@ -60,7 +60,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -68,7 +68,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/sim/cxxtest/defconfig b/nuttx/configs/sim/cxxtest/defconfig index 6ac45d44d..b12eda172 100644 --- a/nuttx/configs/sim/cxxtest/defconfig +++ b/nuttx/configs/sim/cxxtest/defconfig @@ -36,7 +36,7 @@ CONFIG_ARCH_FLOAT_H=y # CONFIG_DEBUG=y CONFIG_DEBUG_VERBOSE=y -# CONFIG_DEBUG_ENABLE is not set +# CONFIG_SYSLOG_ENABLE is not set # # Subsystem Debug Options diff --git a/nuttx/configs/sim/ostest/defconfig b/nuttx/configs/sim/ostest/defconfig index 65f5330fc..07a0f71b4 100644 --- a/nuttx/configs/sim/ostest/defconfig +++ b/nuttx/configs/sim/ostest/defconfig @@ -40,7 +40,7 @@ CONFIG_HOST_LINUX=y # CONFIG_DEBUG=y CONFIG_DEBUG_VERBOSE=y -# CONFIG_DEBUG_ENABLE is not set +# CONFIG_SYSLOG_ENABLE is not set # # Subsystem Debug Options diff --git a/nuttx/configs/stm3210e-eval/src/up_composite.c b/nuttx/configs/stm3210e-eval/src/up_composite.c index e80e0fcb4..de5759c78 100644 --- a/nuttx/configs/stm3210e-eval/src/up_composite.c +++ b/nuttx/configs/stm3210e-eval/src/up_composite.c @@ -79,7 +79,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -87,7 +87,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/stm3210e-eval/src/up_lcd.c b/nuttx/configs/stm3210e-eval/src/up_lcd.c index 8b832aafb..81cc3f20a 100644 --- a/nuttx/configs/stm3210e-eval/src/up_lcd.c +++ b/nuttx/configs/stm3210e-eval/src/up_lcd.c @@ -704,14 +704,14 @@ static void stm3210e_dumprun(FAR const char *msg, FAR uint16_t *run, size_t npix { int i, j; - lib_rawprintf("\n%s:\n", msg); + syslog("\n%s:\n", msg); for (i = 0; i < npixels; i += 16) { up_putc(' '); - lib_rawprintf(" "); + syslog(" "); for (j = 0; j < 16; j++) { - lib_rawprintf(" %04x", *run++); + syslog(" %04x", *run++); } up_putc('\n'); } diff --git a/nuttx/configs/stm3210e-eval/src/up_nsh.c b/nuttx/configs/stm3210e-eval/src/up_nsh.c index 3e7c2013c..544a0e75e 100644 --- a/nuttx/configs/stm3210e-eval/src/up_nsh.c +++ b/nuttx/configs/stm3210e-eval/src/up_nsh.c @@ -108,13 +108,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/stm3210e-eval/src/up_pmbuttons.c b/nuttx/configs/stm3210e-eval/src/up_pmbuttons.c index c0f16ee8c..cc6f3cae0 100644 --- a/nuttx/configs/stm3210e-eval/src/up_pmbuttons.c +++ b/nuttx/configs/stm3210e-eval/src/up_pmbuttons.c @@ -308,9 +308,9 @@ void up_pmbuttons(void) if (oldhandler != NULL) { - lib_lowprintf("WARNING: oldhandler:%p is not NULL! " - "Button events may be lost or aliased!\n", - oldhandler); + lowsyslog("WARNING: oldhandler:%p is not NULL! " + "Button events may be lost or aliased!\n", + oldhandler); } } #endif diff --git a/nuttx/configs/stm3210e-eval/src/up_usbmsc.c b/nuttx/configs/stm3210e-eval/src/up_usbmsc.c index dce463abc..d1727174e 100644 --- a/nuttx/configs/stm3210e-eval/src/up_usbmsc.c +++ b/nuttx/configs/stm3210e-eval/src/up_usbmsc.c @@ -78,7 +78,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -86,7 +86,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/stm3220g-eval/src/up_lcd.c b/nuttx/configs/stm3220g-eval/src/up_lcd.c index a1fcceef7..4a1ce0953 100644 --- a/nuttx/configs/stm3220g-eval/src/up_lcd.c +++ b/nuttx/configs/stm3220g-eval/src/up_lcd.c @@ -550,14 +550,14 @@ static void stm3220g_dumprun(FAR const char *msg, FAR uint16_t *run, size_t npix { int i, j; - lib_rawprintf("\n%s:\n", msg); + syslog("\n%s:\n", msg); for (i = 0; i < npixels; i += 16) { up_putc(' '); - lib_rawprintf(" "); + syslog(" "); for (j = 0; j < 16; j++) { - lib_rawprintf(" %04x", *run++); + syslog(" %04x", *run++); } up_putc('\n'); } diff --git a/nuttx/configs/stm3220g-eval/src/up_nsh.c b/nuttx/configs/stm3220g-eval/src/up_nsh.c index e1359de96..068deb1a6 100644 --- a/nuttx/configs/stm3220g-eval/src/up_nsh.c +++ b/nuttx/configs/stm3220g-eval/src/up_nsh.c @@ -122,13 +122,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/stm3240g-eval/discover/defconfig b/nuttx/configs/stm3240g-eval/discover/defconfig index e11d39ce1..37b74972f 100644 --- a/nuttx/configs/stm3240g-eval/discover/defconfig +++ b/nuttx/configs/stm3240g-eval/discover/defconfig @@ -35,7 +35,7 @@ CONFIG_RAW_BINARY=y # CONFIG_DEBUG=y # CONFIG_DEBUG_VERBOSE is not set -# CONFIG_DEBUG_ENABLE is not set +# CONFIG_SYSLOG_ENABLE is not set # # Subsystem Debug Options diff --git a/nuttx/configs/stm3240g-eval/src/up_lcd.c b/nuttx/configs/stm3240g-eval/src/up_lcd.c index 45e4a2b57..74088dc5e 100644 --- a/nuttx/configs/stm3240g-eval/src/up_lcd.c +++ b/nuttx/configs/stm3240g-eval/src/up_lcd.c @@ -550,14 +550,14 @@ static void stm3240g_dumprun(FAR const char *msg, FAR uint16_t *run, size_t npix { int i, j; - lib_rawprintf("\n%s:\n", msg); + syslog("\n%s:\n", msg); for (i = 0; i < npixels; i += 16) { up_putc(' '); - lib_rawprintf(" "); + syslog(" "); for (j = 0; j < 16; j++) { - lib_rawprintf(" %04x", *run++); + syslog(" %04x", *run++); } up_putc('\n'); } diff --git a/nuttx/configs/stm3240g-eval/src/up_nsh.c b/nuttx/configs/stm3240g-eval/src/up_nsh.c index c106e9918..596f902db 100644 --- a/nuttx/configs/stm3240g-eval/src/up_nsh.c +++ b/nuttx/configs/stm3240g-eval/src/up_nsh.c @@ -128,13 +128,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/stm3240g-eval/xmlrpc/defconfig b/nuttx/configs/stm3240g-eval/xmlrpc/defconfig index 4f621d453..daa1efb8a 100644 --- a/nuttx/configs/stm3240g-eval/xmlrpc/defconfig +++ b/nuttx/configs/stm3240g-eval/xmlrpc/defconfig @@ -35,7 +35,7 @@ CONFIG_RAW_BINARY=y # CONFIG_DEBUG=y # CONFIG_DEBUG_VERBOSE is not set -# CONFIG_DEBUG_ENABLE is not set +# CONFIG_SYSLOG_ENABLE is not set # # Subsystem Debug Options diff --git a/nuttx/configs/stm32f4discovery/src/up_nsh.c b/nuttx/configs/stm32f4discovery/src/up_nsh.c index 2a933569f..fd3fe5cd9 100644 --- a/nuttx/configs/stm32f4discovery/src/up_nsh.c +++ b/nuttx/configs/stm32f4discovery/src/up_nsh.c @@ -89,13 +89,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/stm32f4discovery/src/up_pmbuttons.c b/nuttx/configs/stm32f4discovery/src/up_pmbuttons.c index aa72e3da1..4bc241fce 100644 --- a/nuttx/configs/stm32f4discovery/src/up_pmbuttons.c +++ b/nuttx/configs/stm32f4discovery/src/up_pmbuttons.c @@ -139,7 +139,7 @@ void up_pmbuttons(void) if (oldhandler != NULL) { - lib_lowprintf("WARNING: oldhandler:%p is not NULL! " + lowsyslog("WARNING: oldhandler:%p is not NULL! " "Button events may be lost or aliased!\n", oldhandler); } diff --git a/nuttx/configs/sure-pic32mx/src/up_nsh.c b/nuttx/configs/sure-pic32mx/src/up_nsh.c index 4b68350ed..94ae10d21 100644 --- a/nuttx/configs/sure-pic32mx/src/up_nsh.c +++ b/nuttx/configs/sure-pic32mx/src/up_nsh.c @@ -124,13 +124,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/teensy/src/up_usbmsc.c b/nuttx/configs/teensy/src/up_usbmsc.c index fcf7fe2f5..0b944eda3 100644 --- a/nuttx/configs/teensy/src/up_usbmsc.c +++ b/nuttx/configs/teensy/src/up_usbmsc.c @@ -78,7 +78,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -86,7 +86,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/twr-k60n512/src/up_nsh.c b/nuttx/configs/twr-k60n512/src/up_nsh.c index 3bb4e8527..8069e3f96 100644 --- a/nuttx/configs/twr-k60n512/src/up_nsh.c +++ b/nuttx/configs/twr-k60n512/src/up_nsh.c @@ -109,13 +109,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/twr-k60n512/src/up_usbmsc.c b/nuttx/configs/twr-k60n512/src/up_usbmsc.c index 1a8f7a70d..c893551ca 100644 --- a/nuttx/configs/twr-k60n512/src/up_usbmsc.c +++ b/nuttx/configs/twr-k60n512/src/up_usbmsc.c @@ -74,7 +74,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -82,7 +82,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/ubw32/src/up_nsh.c b/nuttx/configs/ubw32/src/up_nsh.c index 5e5895b63..7c6452004 100644 --- a/nuttx/configs/ubw32/src/up_nsh.c +++ b/nuttx/configs/ubw32/src/up_nsh.c @@ -54,13 +54,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/vsn/src/usbmsc.c b/nuttx/configs/vsn/src/usbmsc.c index c0eebf6bf..198e27dea 100644 --- a/nuttx/configs/vsn/src/usbmsc.c +++ b/nuttx/configs/vsn/src/usbmsc.c @@ -79,7 +79,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -87,7 +87,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/nuttx/configs/vsn/src/vsn.h b/nuttx/configs/vsn/src/vsn.h index eb999f246..f8414f36c 100644 --- a/nuttx/configs/vsn/src/vsn.h +++ b/nuttx/configs/vsn/src/vsn.h @@ -175,13 +175,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/nuttx/configs/z16f2800100zcog/ostest/defconfig b/nuttx/configs/z16f2800100zcog/ostest/defconfig index 64828738f..50c3a96c6 100644 --- a/nuttx/configs/z16f2800100zcog/ostest/defconfig +++ b/nuttx/configs/z16f2800100zcog/ostest/defconfig @@ -44,7 +44,7 @@ CONFIG_WINDOWS_CYGWIN=y # CONFIG_DEBUG=y # CONFIG_DEBUG_VERBOSE is not set -# CONFIG_DEBUG_ENABLE is not set +# CONFIG_SYSLOG_ENABLE is not set # # Subsystem Debug Options diff --git a/nuttx/configs/z16f2800100zcog/pashello/README.txt b/nuttx/configs/z16f2800100zcog/pashello/README.txt index bc9828184..97d326097 100644 --- a/nuttx/configs/z16f2800100zcog/pashello/README.txt +++ b/nuttx/configs/z16f2800100zcog/pashello/README.txt @@ -1,12 +1,12 @@ -README.txt -^^^^^^^^^^ - -pashello.zfpproj is a simple ZDS-II project that will allow you - to use the ZDS-II debugger. Before using, copy the following - files from the toplevel directory: - - nuttx.hex, nuttx.map, nuttx.lod - - to this directory as: - - pashello.hex, pashello.map, pashello.lod +README.txt +^^^^^^^^^^ + +pashello.zfpproj is a simple ZDS-II project that will allow you + to use the ZDS-II debugger. Before using, copy the following + files from the toplevel directory: + + nuttx.hex, nuttx.map, nuttx.lod + + to this directory as: + + pashello.hex, pashello.map, pashello.lod diff --git a/nuttx/configs/z16f2800100zcog/pashello/defconfig b/nuttx/configs/z16f2800100zcog/pashello/defconfig index ba99283d3..96bff8dee 100644 --- a/nuttx/configs/z16f2800100zcog/pashello/defconfig +++ b/nuttx/configs/z16f2800100zcog/pashello/defconfig @@ -44,7 +44,7 @@ CONFIG_WINDOWS_CYGWIN=y # CONFIG_DEBUG=y # CONFIG_DEBUG_VERBOSE is not set -# CONFIG_DEBUG_ENABLE is not set +# CONFIG_SYSLOG_ENABLE is not set # # Subsystem Debug Options diff --git a/nuttx/configs/z8encore000zco/ostest/defconfig b/nuttx/configs/z8encore000zco/ostest/defconfig index 7bd512727..605bec669 100644 --- a/nuttx/configs/z8encore000zco/ostest/defconfig +++ b/nuttx/configs/z8encore000zco/ostest/defconfig @@ -44,7 +44,7 @@ CONFIG_WINDOWS_CYGWIN=y # CONFIG_DEBUG=y # CONFIG_DEBUG_VERBOSE is not set -# CONFIG_DEBUG_ENABLE is not set +# CONFIG_SYSLOG_ENABLE is not set # # Subsystem Debug Options diff --git a/nuttx/configs/z8f64200100kit/ostest/defconfig b/nuttx/configs/z8f64200100kit/ostest/defconfig index e98e41561..aabfc6ee4 100644 --- a/nuttx/configs/z8f64200100kit/ostest/defconfig +++ b/nuttx/configs/z8f64200100kit/ostest/defconfig @@ -44,7 +44,7 @@ CONFIG_WINDOWS_CYGWIN=y # CONFIG_DEBUG=y # CONFIG_DEBUG_VERBOSE is not set -# CONFIG_DEBUG_ENABLE is not set +# CONFIG_SYSLOG_ENABLE is not set # # Subsystem Debug Options diff --git a/nuttx/drivers/lcd/mio283qt2.c b/nuttx/drivers/lcd/mio283qt2.c index 1758e230c..4c8835eef 100644 --- a/nuttx/drivers/lcd/mio283qt2.c +++ b/nuttx/drivers/lcd/mio283qt2.c @@ -495,14 +495,14 @@ static void mio283qt2_dumprun(FAR const char *msg, FAR uint16_t *run, size_t npi { int i, j; - lib_rawprintf("\n%s:\n", msg); + syslog("\n%s:\n", msg); for (i = 0; i < npixels; i += 16) { up_putc(' '); - lib_rawprintf(" "); + syslog(" "); for (j = 0; j < 16; j++) { - lib_rawprintf(" %04x", *run++); + syslog(" %04x", *run++); } up_putc('\n'); } diff --git a/nuttx/drivers/lcd/ssd1289.c b/nuttx/drivers/lcd/ssd1289.c index e42b5bded..d78688be5 100644 --- a/nuttx/drivers/lcd/ssd1289.c +++ b/nuttx/drivers/lcd/ssd1289.c @@ -497,14 +497,14 @@ static void ssd1289_dumprun(FAR const char *msg, FAR uint16_t *run, size_t npixe { int i, j; - lib_rawprintf("\n%s:\n", msg); + syslog("\n%s:\n", msg); for (i = 0; i < npixels; i += 16) { up_putc(' '); - lib_rawprintf(" "); + syslog(" "); for (j = 0; j < 16; j++) { - lib_rawprintf(" %04x", *run++); + syslog(" %04x", *run++); } up_putc('\n'); } diff --git a/nuttx/drivers/mmcsd/mmcsd_debug.c b/nuttx/drivers/mmcsd/mmcsd_debug.c index 0bd7f896e..8cb5b2a2a 100644 --- a/nuttx/drivers/mmcsd/mmcsd_debug.c +++ b/nuttx/drivers/mmcsd/mmcsd_debug.c @@ -56,9 +56,9 @@ /* This needs to match the logic in include/debug.h */ #ifdef CONFIG_CPP_HAVE_VARARGS -# define message(format, arg...) lib_rawprintf(format, ##arg) +# define message(format, arg...) syslog(format, ##arg) #else -# define message lib_rawprintf +# define message syslog #endif /**************************************************************************** diff --git a/nuttx/drivers/net/enc28j60.c b/nuttx/drivers/net/enc28j60.c index 2346ee2d6..203259aeb 100644 --- a/nuttx/drivers/net/enc28j60.c +++ b/nuttx/drivers/net/enc28j60.c @@ -179,10 +179,10 @@ /* Debug ********************************************************************/ #ifdef CONFIG_ENC28J60_REGDEBUG -# define enc_wrdump(a,v) lib_lowprintf("ENC28J60: %02x<-%02x\n", a, v); -# define enc_rddump(a,v) lib_lowprintf("ENC28J60: %02x->%02x\n", a, v); -# define enc_cmddump(c) lib_lowprintf("ENC28J60: CMD: %02x\n", c); -# define enc_bmdump(c,b,s) lib_lowprintf("ENC28J60: CMD: %02x buffer: %p length: %d\n", c,b,s); +# define enc_wrdump(a,v) lowsyslog("ENC28J60: %02x<-%02x\n", a, v); +# define enc_rddump(a,v) lowsyslog("ENC28J60: %02x->%02x\n", a, v); +# define enc_cmddump(c) lowsyslog("ENC28J60: CMD: %02x\n", c); +# define enc_bmdump(c,b,s) lowsyslog("ENC28J60: CMD: %02x buffer: %p length: %d\n", c,b,s); #else # define enc_wrdump(a,v) # define enc_rddump(a,v) @@ -773,56 +773,56 @@ static int enc_waitbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, #if 0 /* Sometimes useful */ static void enc_rxdump(FAR struct enc_driver_s *priv) { - lib_lowprintf("Rx Registers:\n"); - lib_lowprintf(" EIE: %02x EIR: %02x\n", - enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR)); - lib_lowprintf(" ESTAT: %02x ECON1: %02x ECON2: %02x\n", - enc_rdgreg(priv, ENC_ESTAT), enc_rdgreg(priv, ENC_ECON1), - enc_rdgreg(priv, ENC_ECON2)); - lib_lowprintf(" ERXST: %02x %02x\n", - enc_rdbreg(priv, ENC_ERXSTH), enc_rdbreg(priv, ENC_ERXSTL)); - lib_lowprintf(" ERXND: %02x %02x\n", - enc_rdbreg(priv, ENC_ERXNDH), enc_rdbreg(priv, ENC_ERXNDL)); - lib_lowprintf(" ERXRDPT: %02x %02x\n", - enc_rdbreg(priv, ENC_ERXRDPTH), enc_rdbreg(priv, ENC_ERXRDPTL)); - lib_lowprintf(" ERXFCON: %02x EPKTCNT: %02x\n", - enc_rdbreg(priv, ENC_ERXFCON), enc_rdbreg(priv, ENC_EPKTCNT)); - lib_lowprintf(" MACON1: %02x MACON3: %02x\n", - enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3)); - lib_lowprintf(" MAMXFL: %02x %02x\n", - enc_rdbreg(priv, ENC_MAMXFLH), enc_rdbreg(priv, ENC_MAMXFLL)); - lib_lowprintf(" MAADR: %02x:%02x:%02x:%02x:%02x:%02x\n", - enc_rdbreg(priv, ENC_MAADR1), enc_rdbreg(priv, ENC_MAADR2), - enc_rdbreg(priv, ENC_MAADR3), enc_rdbreg(priv, ENC_MAADR4), - enc_rdbreg(priv, ENC_MAADR5), enc_rdbreg(priv, ENC_MAADR6)); + lowsyslog("Rx Registers:\n"); + lowsyslog(" EIE: %02x EIR: %02x\n", + enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR)); + lowsyslog(" ESTAT: %02x ECON1: %02x ECON2: %02x\n", + enc_rdgreg(priv, ENC_ESTAT), enc_rdgreg(priv, ENC_ECON1), + enc_rdgreg(priv, ENC_ECON2)); + lowsyslog(" ERXST: %02x %02x\n", + enc_rdbreg(priv, ENC_ERXSTH), enc_rdbreg(priv, ENC_ERXSTL)); + lowsyslog(" ERXND: %02x %02x\n", + enc_rdbreg(priv, ENC_ERXNDH), enc_rdbreg(priv, ENC_ERXNDL)); + lowsyslog(" ERXRDPT: %02x %02x\n", + enc_rdbreg(priv, ENC_ERXRDPTH), enc_rdbreg(priv, ENC_ERXRDPTL)); + lowsyslog(" ERXFCON: %02x EPKTCNT: %02x\n", + enc_rdbreg(priv, ENC_ERXFCON), enc_rdbreg(priv, ENC_EPKTCNT)); + lowsyslog(" MACON1: %02x MACON3: %02x\n", + enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3)); + lowsyslog(" MAMXFL: %02x %02x\n", + enc_rdbreg(priv, ENC_MAMXFLH), enc_rdbreg(priv, ENC_MAMXFLL)); + lowsyslog(" MAADR: %02x:%02x:%02x:%02x:%02x:%02x\n", + enc_rdbreg(priv, ENC_MAADR1), enc_rdbreg(priv, ENC_MAADR2), + enc_rdbreg(priv, ENC_MAADR3), enc_rdbreg(priv, ENC_MAADR4), + enc_rdbreg(priv, ENC_MAADR5), enc_rdbreg(priv, ENC_MAADR6)); } #endif #if 0 /* Sometimes useful */ static void enc_txdump(FAR struct enc_driver_s *priv) { - lib_lowprintf("Tx Registers:\n"); - lib_lowprintf(" EIE: %02x EIR: %02x ESTAT: %02x\n", - enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR),); - lib_lowprintf(" ESTAT: %02x ECON1: %02x\n", - enc_rdgreg(priv, ENC_ESTAT), enc_rdgreg(priv, ENC_ECON1)); - lib_lowprintf(" ETXST: %02x %02x\n", - enc_rdbreg(priv, ENC_ETXSTH), enc_rdbreg(priv, ENC_ETXSTL)); - lib_lowprintf(" ETXND: %02x %02x\n", - enc_rdbreg(priv, ENC_ETXNDH), enc_rdbreg(priv, ENC_ETXNDL)); - lib_lowprintf(" MACON1: %02x MACON3: %02x MACON4: %02x\n", - enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3), - enc_rdbreg(priv, ENC_MACON4)); - lib_lowprintf(" MACON1: %02x MACON3: %02x MACON4: %02x\n", - enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3), - enc_rdbreg(priv, ENC_MACON4)); - lib_lowprintf(" MABBIPG: %02x MAIPG %02x %02x\n", - enc_rdbreg(priv, ENC_MABBIPG), enc_rdbreg(priv, ENC_MAIPGH), - enc_rdbreg(priv, ENC_MAIPGL)); - lib_lowprintf(" MACLCON1: %02x MACLCON2: %02x\n", - enc_rdbreg(priv, ENC_MACLCON1), enc_rdbreg(priv, ENC_MACLCON2)); - lib_lowprintf(" MAMXFL: %02x %02x\n", - enc_rdbreg(priv, ENC_MAMXFLH), enc_rdbreg(priv, ENC_MAMXFLL)); + lowsyslog("Tx Registers:\n"); + lowsyslog(" EIE: %02x EIR: %02x ESTAT: %02x\n", + enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR),); + lowsyslog(" ESTAT: %02x ECON1: %02x\n", + enc_rdgreg(priv, ENC_ESTAT), enc_rdgreg(priv, ENC_ECON1)); + lowsyslog(" ETXST: %02x %02x\n", + enc_rdbreg(priv, ENC_ETXSTH), enc_rdbreg(priv, ENC_ETXSTL)); + lowsyslog(" ETXND: %02x %02x\n", + enc_rdbreg(priv, ENC_ETXNDH), enc_rdbreg(priv, ENC_ETXNDL)); + lowsyslog(" MACON1: %02x MACON3: %02x MACON4: %02x\n", + enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3), + enc_rdbreg(priv, ENC_MACON4)); + lowsyslog(" MACON1: %02x MACON3: %02x MACON4: %02x\n", + enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3), + enc_rdbreg(priv, ENC_MACON4)); + lowsyslog(" MABBIPG: %02x MAIPG %02x %02x\n", + enc_rdbreg(priv, ENC_MABBIPG), enc_rdbreg(priv, ENC_MAIPGH), + enc_rdbreg(priv, ENC_MAIPGL)); + lowsyslog(" MACLCON1: %02x MACLCON2: %02x\n", + enc_rdbreg(priv, ENC_MACLCON1), enc_rdbreg(priv, ENC_MACLCON2)); + lowsyslog(" MAMXFL: %02x %02x\n", + enc_rdbreg(priv, ENC_MAMXFLH), enc_rdbreg(priv, ENC_MAMXFLL)); } #endif diff --git a/nuttx/drivers/syslog/ramlog.c b/nuttx/drivers/syslog/ramlog.c index b3a2ad0f5..08bbbfb59 100644 --- a/nuttx/drivers/syslog/ramlog.c +++ b/nuttx/drivers/syslog/ramlog.c @@ -726,10 +726,10 @@ int ramlog_sysloginit(void) * * Description: * This is the low-level system logging interface. The debugging/syslogging - * interfaces are lib_rawprintf() and lib_lowprinf(). The difference is - * the lib_rawprintf() writes to fd=1 (stdout) and lib_lowprintf() uses + * interfaces are syslog() and lowsyslog(). The difference is that + * the syslog() internface writes to fd=1 (stdout) whereas lowsyslog() uses * a lower level interface that works from interrupt handlers. This - * function is a a low-level interface used to implement lib_lowprintf() + * function is a a low-level interface used to implement lowsyslog() * when CONFIG_RAMLOG_SYSLOG=y and CONFIG_SYSLOG=y * ****************************************************************************/ diff --git a/nuttx/drivers/usbdev/usbdev_trace.c b/nuttx/drivers/usbdev/usbdev_trace.c index c8cc09292..c332c1358 100644 --- a/nuttx/drivers/usbdev/usbdev_trace.c +++ b/nuttx/drivers/usbdev/usbdev_trace.c @@ -168,9 +168,9 @@ void usbtrace(uint16_t event, uint16_t value) } } #else - /* Just print the data using lib_lowprintf */ + /* Just print the data using lowsyslog */ - usbtrace_trprintf((trprintf_t)lib_lowprintf, event, value); + usbtrace_trprintf((trprintf_t)lowsyslog, event, value); #endif } irqrestore(flags); diff --git a/nuttx/drivers/usbdev/usbmsc.h b/nuttx/drivers/usbdev/usbmsc.h index 883a49951..da35ae923 100644 --- a/nuttx/drivers/usbdev/usbmsc.h +++ b/nuttx/drivers/usbdev/usbmsc.h @@ -199,9 +199,9 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG # ifdef CONFIG_ARCH_LOWPUTC -# define dbgprintf(format, arg...) lib_lowprintf(format, ##arg) +# define dbgprintf(format, arg...) lowsyslog(format, ##arg) # else -# define dbgprintf(format, arg...) lib_rawprintf(format, ##arg) +# define dbgprintf(format, arg...) syslog(format, ##arg) # endif # else # define dbgprintf(x...) @@ -209,9 +209,9 @@ #else # ifdef CONFIG_DEBUG # ifdef CONFIG_ARCH_LOWPUTC -# define dbgprintf lib_lowprintf +# define dbgprintf lowsyslog # else -# define dbgprintf lib_rawprintf +# define dbgprintf syslog # endif # else # define dbgprintf (void) diff --git a/nuttx/fs/fs_syslog.c b/nuttx/fs/fs_syslog.c index ab6cec51e..779263a3c 100644 --- a/nuttx/fs/fs_syslog.c +++ b/nuttx/fs/fs_syslog.c @@ -357,10 +357,10 @@ int syslog_initialize(void) * * Description: * This is the low-level system logging interface. The debugging/syslogging - * interfaces are lib_rawprintf() and lib_lowprinf(). The difference is - * the lib_rawprintf() writes to fd=1 (stdout) and lib_lowprintf() uses + * interfaces are syslog() and lowsyslog(). The difference is is that + * the syslog() function writes to fd=1 (stdout) whereas lowsyslog() uses * a lower level interface that works from interrupt handlers. This - * function is a a low-level interface used to implement lib_lowprintf(). + * function is a a low-level interface used to implement lowsyslog(). * ****************************************************************************/ diff --git a/nuttx/fs/nxffs/nxffs_dump.c b/nuttx/fs/nxffs/nxffs_dump.c index 6a89aaf1d..9caac4c4b 100644 --- a/nuttx/fs/nxffs/nxffs_dump.c +++ b/nuttx/fs/nxffs/nxffs_dump.c @@ -60,7 +60,7 @@ */ #undef fdbg -#define fdbg lib_rawprintf +#define fdbg syslog /**************************************************************************** * Private Types diff --git a/nuttx/include/debug.h b/nuttx/include/debug.h index aa5efd432..70ae2ee18 100644 --- a/nuttx/include/debug.h +++ b/nuttx/include/debug.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/debug.h * - * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,7 +43,7 @@ #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions @@ -104,22 +104,22 @@ #ifdef CONFIG_DEBUG # define dbg(format, arg...) \ - lib_rawprintf(EXTRA_FMT format EXTRA_ARG, ##arg) + syslog(EXTRA_FMT format EXTRA_ARG, ##arg) # ifdef CONFIG_ARCH_LOWPUTC # define lldbg(format, arg...) \ - lib_lowprintf(EXTRA_FMT format EXTRA_ARG, ##arg) + lowsyslog(EXTRA_FMT format EXTRA_ARG, ##arg) # else # define lldbg(x...) # endif # ifdef CONFIG_DEBUG_VERBOSE # define vdbg(format, arg...) \ - lib_rawprintf(EXTRA_FMT format EXTRA_ARG, ##arg) + syslog(EXTRA_FMT format EXTRA_ARG, ##arg) # ifdef CONFIG_ARCH_LOWPUTC # define llvdbg(format, arg...) \ - lib_lowprintf(EXTRA_FMT format EXTRA_ARG, ##arg) + lowsyslog(EXTRA_FMT format EXTRA_ARG, ##arg) # else # define llvdbg(x...) # endif @@ -576,29 +576,16 @@ extern "C" { #endif -/* These low-level debug APIs are provided by the NuttX library. If the - * cross-compiler's pre-processor supports a variable number of macro - * arguments, then the macros below will map all debug statements to one - * or the other of the following. - */ - -int lib_rawprintf(FAR const char *format, ...); - -#ifdef CONFIG_ARCH_LOWPUTC -int lib_lowprintf(FAR const char *format, ...); -#endif - /* Dump a buffer of data */ void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, unsigned int buflen); -/* Enable or disable debug output */ - -#ifdef CONFIG_DEBUG_ENABLE -void dbg_enable(bool enable); -#endif - -/* If the cross-compiler's pre-processor does not support variable length +/* The system logging interfaces are pnormally accessed via the macros + * provided above. If the cross-compiler's C pre-processor supports a + * variable number of macro arguments, then those macros below will map all + * debug statements to the logging interfaces declared in syslog.h. + * + * If the cross-compiler's pre-processor does not support variable length * arguments, then these additional APIs will be built. */ diff --git a/nuttx/include/nuttx/syslog.h b/nuttx/include/nuttx/syslog.h index 3c340d23a..bb3c8f493 100644 --- a/nuttx/include/nuttx/syslog.h +++ b/nuttx/include/nuttx/syslog.h @@ -116,10 +116,10 @@ EXTERN int syslog_initialize(void); * * Description: * This is the low-level system logging interface. The debugging/syslogging - * interfaces are lib_rawprintf() and lib_lowprinf(). The difference is - * the lib_rawprintf() writes to fd=1 (stdout) and lib_lowprintf() uses + * interfaces are syslog() and lowsyslog(). The difference is that + * the syslog() internface writes to fd=1 (stdout) whereas lowsyslog() uses * a lower level interface that works from interrupt handlers. This - * function is a a low-level interface used to implement lib_lowprintf(). + * function is a a low-level interface used to implement lowsyslog(). * ****************************************************************************/ diff --git a/nuttx/include/syslog.h b/nuttx/include/syslog.h new file mode 100644 index 000000000..cfb2db97b --- /dev/null +++ b/nuttx/include/syslog.h @@ -0,0 +1,94 @@ +/**************************************************************************** + * include/syslog.h + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_SYSLOG_H +#define __INCLUDE_SYSLOG_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#if defined(__cplusplus) +extern "C" +{ +#endif + +/* These low-level debug APIs are provided by the NuttX library. These are + * normally accessed via the macros in debug.h. If the cross-compiler's + * C pre-processor supports a variable number of macro arguments, then those + * macros below will map all debug statements to one or the other of the + * following. + */ + +int syslog(FAR const char *format, ...); +int vsyslog(const char *src, va_list ap); + +#ifdef CONFIG_ARCH_LOWPUTC +int lowsyslog(FAR const char *format, ...); +int lowvsyslog(const char *src, va_list ap); +#endif + +/* Enable or disable syslog output */ + +#ifdef CONFIG_SYSLOG_ENABLE +void syslog_enable(bool enable); +#endif + +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_SYSLOG_H */ diff --git a/nuttx/libc/lib.csv b/nuttx/libc/lib.csv index 171f64e9b..29cdf39a6 100644 --- a/nuttx/libc/lib.csv +++ b/nuttx/libc/lib.csv @@ -16,7 +16,6 @@ "crc32","crc32.h","","uint32_t","FAR const uint8_t *","size_t" "crc32part","crc32.h","","uint32_t","FAR const uint8_t *","size_t","uint32_t" "dbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG)","int","const char *","..." -"dbg_enable","debug.h","defined(CONFIG_DEBUG_ENABLE)","void","bool" "dirname","libgen.h","","FAR char","FAR char *" "dq_addafter","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *" "dq_addbefore","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *" @@ -59,11 +58,10 @@ "inet_pton","arpa/inet.h","","int","int","FAR const char *","FAR void *" "labs","stdlib.h","","long int","long int" "lib_dumpbuffer","debug.h","","void","FAR const char *","FAR const uint8_t *","unsigned int" -"lib_lowprintf","debug.h","","int","FAR const char *","..." -"lib_rawprintf","debug.h","","int","FAR const char *","..." "llabs","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long int","long long int" "lldbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_ARCH_LOWPUTC)","int","const char *","..." "llvdbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_ARCH_LOWPUTC)","int","const char *","..." +"lowsyslog","syslog.h","","int","FAR const char *","..." "match","","","int","const char *","const char *" "memccpy","string.h","","FAR void","FAR void *","FAR const void *","int c","size_t" "memchr","string.h","","FAR void","FAR const void *","int c","size_t" @@ -154,6 +152,8 @@ "strtoll","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long","const char *nptr","char **endptr","int base" "strtoul","stdlib.h","","unsigned long","const char *","char **","int" "strtoull","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","unsigned long long","const char *","char **","int" +"syslog","syslog.h","","int","FAR const char *","..." +"syslog_enable","syslog.h","defined(CONFIG_SYSLOG_ENABLE)","void","bool" "tcflush","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int" "tcgetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","FAR struct termios *" "tcsetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int","FAR const struct termios *" diff --git a/nuttx/libc/lib_internal.h b/nuttx/libc/lib_internal.h index c09c751d4..17adff417 100644 --- a/nuttx/libc/lib_internal.h +++ b/nuttx/libc/lib_internal.h @@ -106,8 +106,8 @@ /* Debug output is initially disabled */ -#ifdef CONFIG_DEBUG_ENABLE -extern bool g_dbgenable; +#ifdef CONFIG_SYSLOG_ENABLE +extern bool g_syslogenable; #endif /**************************************************************************** @@ -137,14 +137,6 @@ int lib_sprintf(FAR struct lib_outstream_s *obj, int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list ap); -/* Defined lib_rawprintf.c */ - -int lib_rawvprintf(const char *src, va_list ap); - -/* Defined lib_lowprintf.c */ - -int lib_lowvprintf(const char *src, va_list ap); - /* Defined in lib_dtoa.c */ #ifdef CONFIG_LIBC_FLOATINGPOINT diff --git a/nuttx/libc/misc/lib_dbg.c b/nuttx/libc/misc/lib_dbg.c index 5605ff828..921a4e24d 100644 --- a/nuttx/libc/misc/lib_dbg.c +++ b/nuttx/libc/misc/lib_dbg.c @@ -50,8 +50,8 @@ /* Debug output is initially disabled */ -#ifdef CONFIG_DEBUG_ENABLE -bool g_dbgenable; +#ifdef CONFIG_SYSLOG_ENABLE +bool g_syslogenable; #endif /**************************************************************************** @@ -59,17 +59,17 @@ bool g_dbgenable; ****************************************************************************/ /**************************************************************************** - * Name: dbg_enable + * Name: syslog_enable * * Description: * Enable or disable debug output. * ****************************************************************************/ -#ifdef CONFIG_DEBUG_ENABLE -void dbg_enable(bool enable) +#ifdef CONFIG_SYSLOG_ENABLE +void syslog_enable(bool enable) { - g_dbgenable = enable; + g_syslogenable = enable; } #endif @@ -89,13 +89,13 @@ int dbg(const char *format, ...) va_list ap; int ret; -#ifdef CONFIG_DEBUG_ENABLE +#ifdef CONFIG_SYSLOG_ENABLE ret = 0; - if (g_dbgenable) + if (g_syslogenable) #endif { va_start(ap, format); - ret = lib_rawvprintf(format, ap); + ret = vsyslog(format, ap); va_end(ap); } @@ -108,13 +108,13 @@ int lldbg(const char *format, ...) va_list ap; int ret; -#ifdef CONFIG_DEBUG_ENABLE +#ifdef CONFIG_SYSLOG_ENABLE ret = 0; - if (g_dbgenable) + if (g_syslogenable) #endif { va_start(ap, format); - ret = lib_lowvprintf(format, ap); + ret = lowvsyslog(format, ap); va_end(ap); } @@ -128,13 +128,13 @@ int vdbg(const char *format, ...) va_list ap; int ret; -#ifdef CONFIG_DEBUG_ENABLE +#ifdef CONFIG_SYSLOG_ENABLE ret = 0; - if (g_dbgenable) + if (g_syslogenable) #endif { va_start(ap, format); - ret = lib_rawvprintf(format, ap); + ret = vsyslog(format, ap); va_end(ap); } @@ -147,13 +147,13 @@ int llvdbg(const char *format, ...) va_list ap; int ret; -#ifdef CONFIG_DEBUG_ENABLE +#ifdef CONFIG_SYSLOG_ENABLE ret = 0; - if (g_dbgenable) + if (g_syslogenable) #endif { va_start(ap, format); - ret = lib_lowvprintf(format, ap); + ret = lowvsyslog(format, ap); va_end(ap); } diff --git a/nuttx/libc/misc/lib_dumpbuffer.c b/nuttx/libc/misc/lib_dumpbuffer.c index 52158b220..5194560fd 100644 --- a/nuttx/libc/misc/lib_dumpbuffer.c +++ b/nuttx/libc/misc/lib_dumpbuffer.c @@ -51,15 +51,15 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_ARCH_LOWPUTC -# define message(format, arg...) lib_lowprintf(format, ##arg) +# define message(format, arg...) lowsyslog(format, ##arg) # else -# define message(format, arg...) lib_rawprintf(format, ##arg) +# define message(format, arg...) syslog(format, ##arg) # endif #else # ifdef CONFIG_ARCH_LOWPUTC -# define message lib_lowprintf +# define message lowsyslog # else -# define message lib_rawprintf +# define message syslog # endif #endif diff --git a/nuttx/libc/stdio/Make.defs b/nuttx/libc/stdio/Make.defs index e18ab0220..ffc9b1a75 100644 --- a/nuttx/libc/stdio/Make.defs +++ b/nuttx/libc/stdio/Make.defs @@ -37,7 +37,7 @@ # This first group of C files do not depend on having file descriptors or # C streams. -CSRCS += lib_fileno.c lib_printf.c lib_rawprintf.c lib_lowprintf.c \ +CSRCS += lib_fileno.c lib_printf.c lib_syslog.c lib_lowsyslog.c\ lib_sprintf.c lib_asprintf.c lib_snprintf.c lib_libsprintf.c \ lib_vsprintf.c lib_avsprintf.c lib_vsnprintf.c lib_libvsprintf.c \ lib_meminstream.c lib_memoutstream.c lib_lowinstream.c \ diff --git a/nuttx/libc/stdio/lib_lowprintf.c b/nuttx/libc/stdio/lib_lowprintf.c deleted file mode 100644 index 667fad7be..000000000 --- a/nuttx/libc/stdio/lib_lowprintf.c +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** - * libc/stdio/lib_lowprintf.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include "lib_internal.h" - -/* This interface can only be used from within the kernel */ - -#if !defined(CONFIG_NUTTX_KERNEL) || defined(__KERNEL__) - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_lowvprintf - ****************************************************************************/ - -#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG) - -int lib_lowvprintf(const char *fmt, va_list ap) -{ - struct lib_outstream_s stream; - - /* Wrap the stdout in a stream object and let lib_vsprintf do the work. */ - -#ifdef CONFIG_SYSLOG - lib_syslogstream((FAR struct lib_outstream_s *)&stream); -#else - lib_lowoutstream((FAR struct lib_outstream_s *)&stream); -#endif - return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); -} - -/**************************************************************************** - * Name: lib_lowprintf - ****************************************************************************/ - -int lib_lowprintf(const char *fmt, ...) -{ - va_list ap; - int ret; - -#ifdef CONFIG_DEBUG_ENABLE - ret = 0; - if (g_dbgenable) -#endif - { - va_start(ap, fmt); - ret = lib_lowvprintf(fmt, ap); - va_end(ap); - } - - return ret; -} - -#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG */ -#endif /* __KERNEL__ */ diff --git a/nuttx/libc/stdio/lib_lowsyslog.c b/nuttx/libc/stdio/lib_lowsyslog.c new file mode 100644 index 000000000..bfe6a2cce --- /dev/null +++ b/nuttx/libc/stdio/lib_lowsyslog.c @@ -0,0 +1,130 @@ +/**************************************************************************** + * libc/stdio/lib_lowsyslog.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "lib_internal.h" + +/* This interface can only be used from within the kernel */ + +#if !defined(CONFIG_NUTTX_KERNEL) || defined(__KERNEL__) + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lowvsyslog + ****************************************************************************/ + +#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG) + +int lowvsyslog(const char *fmt, va_list ap) +{ + struct lib_outstream_s stream; + + /* Wrap the stdout in a stream object and let lib_vsprintf do the work. */ + +#ifdef CONFIG_SYSLOG + lib_syslogstream((FAR struct lib_outstream_s *)&stream); +#else + lib_lowoutstream((FAR struct lib_outstream_s *)&stream); +#endif + return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); +} + +/**************************************************************************** + * Name: lowsyslog + ****************************************************************************/ + +int lowsyslog(const char *fmt, ...) +{ + va_list ap; + int ret; + +#ifdef CONFIG_SYSLOG_ENABLE + ret = 0; + if (g_syslogenable) +#endif + { + va_start(ap, fmt); + ret = lowvsyslog(fmt, ap); + va_end(ap); + } + + return ret; +} + +#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG */ +#endif /* __KERNEL__ */ diff --git a/nuttx/libc/stdio/lib_printf.c b/nuttx/libc/stdio/lib_printf.c index 0e90c7ca5..b035aa14f 100644 --- a/nuttx/libc/stdio/lib_printf.c +++ b/nuttx/libc/stdio/lib_printf.c @@ -93,9 +93,9 @@ int printf(const char *fmt, ...) #if CONFIG_NFILE_STREAMS > 0 ret = vfprintf(stdout, fmt, ap); #elif CONFIG_NFILE_DESCRIPTORS > 0 - ret = lib_rawvprintf(fmt, ap); + ret = vsyslog(fmt, ap); #elif defined(CONFIG_ARCH_LOWPUTC) - ret = lib_lowvprintf(fmt, ap); + ret = lowvsyslog(fmt, ap); #else # ifdef CONFIG_CPP_HAVE_WARNING # warning "printf has no data sink" diff --git a/nuttx/libc/stdio/lib_rawprintf.c b/nuttx/libc/stdio/lib_rawprintf.c deleted file mode 100644 index d8deba12d..000000000 --- a/nuttx/libc/stdio/lib_rawprintf.c +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** - * libc/stdio/lib_rawprintf.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Some output destinations are only available from within the kernel */ - -#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) -# undef CONFIG_SYSLOG -# undef CONFIG_ARCH_LOWPUTC -#endif - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_rawvprintf - ****************************************************************************/ - -int lib_rawvprintf(const char *fmt, va_list ap) -{ -#if defined(CONFIG_SYSLOG) - - struct lib_outstream_s stream; - - /* Wrap the low-level output in a stream object and let lib_vsprintf - * do the work. - */ - - lib_syslogstream((FAR struct lib_outstream_s *)&stream); - return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); - -#elif CONFIG_NFILE_DESCRIPTORS > 0 - - struct lib_rawoutstream_s rawoutstream; - - /* Wrap the stdout in a stream object and let lib_vsprintf - * do the work. - */ - - lib_rawoutstream(&rawoutstream, 1); - return lib_vsprintf(&rawoutstream.public, fmt, ap); - -#elif defined(CONFIG_ARCH_LOWPUTC) - - struct lib_outstream_s stream; - - /* Wrap the low-level output in a stream object and let lib_vsprintf - * do the work. - */ - - lib_lowoutstream((FAR struct lib_outstream_s *)&stream); - return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); - -#else - return 0; -#endif -} - -/**************************************************************************** - * Name: lib_rawprintf - ****************************************************************************/ - -int lib_rawprintf(const char *fmt, ...) -{ - va_list ap; - int ret; - -#ifdef CONFIG_DEBUG_ENABLE - ret = 0; - if (g_dbgenable) -#endif - { - va_start(ap, fmt); - ret = lib_rawvprintf(fmt, ap); - va_end(ap); - } - - return ret; -} diff --git a/nuttx/libc/stdio/lib_syslog.c b/nuttx/libc/stdio/lib_syslog.c new file mode 100644 index 000000000..bbf7860d2 --- /dev/null +++ b/nuttx/libc/stdio/lib_syslog.c @@ -0,0 +1,154 @@ +/**************************************************************************** + * libc/stdio/lib_syslog.c + * + * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Some output destinations are only available from within the kernel */ + +#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) +# undef CONFIG_SYSLOG +# undef CONFIG_ARCH_LOWPUTC +#endif + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: vsyslog + ****************************************************************************/ + +int vsyslog(const char *fmt, va_list ap) +{ +#if defined(CONFIG_SYSLOG) + + struct lib_outstream_s stream; + + /* Wrap the low-level output in a stream object and let lib_vsprintf + * do the work. + */ + + lib_syslogstream((FAR struct lib_outstream_s *)&stream); + return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); + +#elif CONFIG_NFILE_DESCRIPTORS > 0 + + struct lib_rawoutstream_s rawoutstream; + + /* Wrap the stdout in a stream object and let lib_vsprintf + * do the work. + */ + + lib_rawoutstream(&rawoutstream, 1); + return lib_vsprintf(&rawoutstream.public, fmt, ap); + +#elif defined(CONFIG_ARCH_LOWPUTC) + + struct lib_outstream_s stream; + + /* Wrap the low-level output in a stream object and let lib_vsprintf + * do the work. + */ + + lib_lowoutstream((FAR struct lib_outstream_s *)&stream); + return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); + +#else + return 0; +#endif +} + +/**************************************************************************** + * Name: syslog + ****************************************************************************/ + +int syslog(const char *fmt, ...) +{ + va_list ap; + int ret; + +#ifdef CONFIG_SYSLOG_ENABLE + ret = 0; + if (g_syslogenable) +#endif + { + va_start(ap, fmt); + ret = vsyslog(fmt, ap); + va_end(ap); + } + + return ret; +} -- cgit v1.2.3 From 2946cb47a8d70406a85c37f2d210e539c240a22b Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 29 Jan 2013 13:30:10 +0000 Subject: USB monitor daemon updates git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5579 42af7a65-404d-4744-a932-0658087f49c3 --- apps/system/usbmonitor/Makefile | 11 ++--- apps/system/usbmonitor/usbmonitor.c | 10 +++-- nuttx/Kconfig | 56 +++++++++++------------- nuttx/configs/stm32f4discovery/README.txt | 58 ++++++++++++++++++++++--- nuttx/configs/stm32f4discovery/src/up_nsh.c | 31 +++++++++++-- nuttx/configs/stm32f4discovery/usbnsh/defconfig | 2 +- nuttx/drivers/usbdev/Kconfig | 10 ++--- nuttx/fs/Kconfig | 15 ++++++- nuttx/graphics/nxfonts/nxfonts_getfont.c | 2 +- 9 files changed, 139 insertions(+), 56 deletions(-) diff --git a/apps/system/usbmonitor/Makefile b/apps/system/usbmonitor/Makefile index b4c323eb7..56b6ccee1 100644 --- a/apps/system/usbmonitor/Makefile +++ b/apps/system/usbmonitor/Makefile @@ -41,8 +41,7 @@ ifeq ($(WINTOOL),y) INCDIROPT = -w endif -# Hello Application -# TODO: appname can be automatically extracted from the directory name +# USB Monitor Application PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = 768 @@ -88,11 +87,13 @@ $(COBJS): %$(OBJEXT): %.c # Register application ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile +$(BUILTIN_REGISTRY)$(DELIM)usbmonitor_start.bdat: $(DEPCONFIG) Makefile $(call REGISTER,"usbmon_start",$(PRIORITY),$(STACKSIZE),usbmonitor_start) - $(call REGISTER,"usbmon_stop",$(PRIORITY),$(STACKSIZE),usbmonintor_stop) -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat +$(BUILTIN_REGISTRY)$(DELIM)usbmonitor_stop.bdat: $(DEPCONFIG) Makefile + $(call REGISTER,"usbmon_stop",$(PRIORITY),$(STACKSIZE),usbmonitor_stop) + +context: $(BUILTIN_REGISTRY)$(DELIM)usbmonitor_start.bdat $(BUILTIN_REGISTRY)$(DELIM)usbmonitor_stop.bdat else context: endif diff --git a/apps/system/usbmonitor/usbmonitor.c b/apps/system/usbmonitor/usbmonitor.c index b615b99f9..b386c3c2e 100644 --- a/apps/system/usbmonitor/usbmonitor.c +++ b/apps/system/usbmonitor/usbmonitor.c @@ -42,9 +42,12 @@ #include #include -#include +#include +#include +#include +#include -#include #ifdef CONFIG_SYSTEM_USBMONITOR @@ -89,7 +92,8 @@ static int usbmonitor_daemon(int argc, char **argv) while (!g_usbmonitor.stop) { - (void)usbmonitor_enumerate(nsh_tracecallback, NULL); + sleep(2); + (void)usbtrace_enumerate(usbmonitor_tracecallback, NULL); } /* Stopped */ diff --git a/nuttx/Kconfig b/nuttx/Kconfig index 937bab2be..af743b9db 100644 --- a/nuttx/Kconfig +++ b/nuttx/Kconfig @@ -297,27 +297,21 @@ config DEBUG ---help--- Enables built-in debug features. Selecting this option will (1) Enable debug assertions in the code, (2) enable extended parameter testing in - many functions, and (3) enable support for debug output. Note that enabling - this option by itself does not produce debug output. Debug output must - also be selected on a subsystem-by-subsystem basis. + many functions, and (3) enable support for debug output to the SYSLOG. + Note that enabling this option by itself does not produce debug output. + Debug output must also be selected on a subsystem-by-subsystem basis. if DEBUG config DEBUG_VERBOSE bool "Enable Debug Verbose Output" default n ---help--- - Enables verbose debug output (assuming debug output is enabled). As a - general rule, when DEBUG is enabled only errors will be reported in the debug - output. But if you also enable DEBUG_VERBOSE, then very chatty (and - often annoying) output will be generated. This means there are two levels - of debug output: errors-only and everything. - -config SYSLOG_ENABLE - bool "Enable Debug Controls" - default n - ---help--- - Support an interface called syslog_enable to dynamically enable or - disable debug output. + Enables verbose debug output (assuming debug featurses are enabled). + As a general rule, when DEBUG is enabled only errors will be + reported in the debug SYSLOG output. But if you also enable + DEBUG_VERBOSE, then very chatty (and often annoying) output will be + generated. This means there are two levels of debug output: + errors-only and everything. comment "Subsystem Debug Options" @@ -325,58 +319,58 @@ config DEBUG_MM bool "Enable Memory Manager Debug Output" default n ---help--- - Enable memory management debug output (disabled by default) + Enable memory management debug SYSLOG output (disabled by default) config DEBUG_SCHED bool "Enable Scheduler Debug Output" default n ---help--- - Enable OS debug output (disabled by default) + Enable OS debug SYSLOG output (disabled by default) config DEBUG_PAGING bool "Enable Demand Paging Debug Output" default n depends on PAGING ---help--- - Enable demand paging debug output (disabled by default) + Enable demand paging debug SYSLOG output (disabled by default) config DEBUG_NET bool "Enable Network Debug Output" default n depends on NET ---help--- - Enable network debug output (disabled by default) + Enable network debug SYSLOG output (disabled by default) config DEBUG_USB bool "Enable USB Debug Output" default n depends on USBDEV || USBHOST ---help--- - Enable usb debug output (disabled by default) + Enable usb debug SYSLOG output (disabled by default) config DEBUG_FS bool "Enable File System Debug Output" default n ---help--- - Enable file system debug output (disabled by default) + Enable file system debug SYSLOG output (disabled by default) config DEBUG_LIB bool "Enable C Library Debug Output" default n ---help--- - Enable C library debug output (disabled by default) + Enable C library debug SYSLOG output (disabled by default) config DEBUG_BINFMT bool "Enable Binary Loader Debug Output" default n ---help--- - Enable binary loader debug output (disabled by default) + Enable binary loader debug SYSLOG output (disabled by default) config DEBUG_GRAPHICS bool "Enable Graphics Debug Output" default n ---help--- - Enable NX graphics debug output (disabled by default) + Enable NX graphics debug SYSLOG output (disabled by default) comment "Driver Debug Options" @@ -385,21 +379,21 @@ config DEBUG_LCD default n depends on LCD ---help--- - Enable low level debug output from the LCD driver (disabled by default) + Enable low level debug SYSLOG output from the LCD driver (disabled by default) config DEBUG_INPUT bool "Enable Input Device Debug Output" default n depends on INPUT ---help--- - Enable low level debug output from the input device drivers such as + Enable low level debug SYSLOG output from the input device drivers such as mice and touchscreens (disabled by default) config DEBUG_ANALOG bool "Enable Analog Device Debug Output" default n ---help--- - Enable low level debug output from the analog device drivers such as + Enable low level debug SYSLOG output from the analog device drivers such as A/D and D/A converters (disabled by default) config DEBUG_I2C @@ -407,27 +401,27 @@ config DEBUG_I2C default n depends on I2C ---help--- - Enable I2C driver debug output (disabled by default) + Enable I2C driver debug SYSLOG output (disabled by default) config DEBUG_SPI bool "Enable SPI Debug Output" default n depends on SPI ---help--- - Enable I2C driver debug output (disabled by default) + Enable I2C driver debug SYSLOG output (disabled by default) config DEBUG_DMA bool "Enable DMA Debug Output" default n ---help--- - Enable DMA-releated debug output (disabled by default) + Enable DMA-releated debug SYSLOG output (disabled by default) config DEBUG_WATCHDOG bool "Enable Watchdog Timer Debug Output" default n depends on WATCHDOG ---help--- - Enable watchdog timer debug output (disabled by default) + Enable watchdog timer debug SYSLOG output (disabled by default) endif diff --git a/nuttx/configs/stm32f4discovery/README.txt b/nuttx/configs/stm32f4discovery/README.txt index 378509be8..41207fafa 100644 --- a/nuttx/configs/stm32f4discovery/README.txt +++ b/nuttx/configs/stm32f4discovery/README.txt @@ -1258,7 +1258,36 @@ Where is one of the following: times before NSH starts. The logic does this to prevent sending USB data before there is anything on the host side listening for USB serial input. - 9. USB OTG FS Host Support. The following changes will enable support for + 9. Here is an alternative USB console configuration. The following + configuration will also create a NSH USB console but this version + will use /dev/console. Instead, it will use the normal /dev/ttyACM0 + USB serial device for the console: + + CONFIG_STM32_OTGFS=y : STM32 OTG FS support + CONFIG_USART2_SERIAL_CONSOLE=y : Keep the USART2 console + CONFIG_DEV_CONSOLE=y : /dev/console exists (but NSH won't use it) + CONFIG_USBDEV=y : USB device support must be enabled + CONFIG_CDCACM=y : The CDC/ACM driver must be built + CONFIG_CDCACM_CONSOLE=n : Don't use the CDC/ACM USB console. + CONFIG_NSH_USBCONSOLE=y : Instead use some other USB device for the console + + The particular USB device that is used is: + + CONFIG_NSH_USBCONDEV="/dev/ttyACM0" + + The advantage of this configuration is only that it is easier to + bet working. This alternative does has some side effects: + + - When any other device other than /dev/console is used for a user + interface, linefeeds (\n) will not be expanded to carriage return / + linefeeds (\r\n). You will need to set your terminal program to account + for this. + + - /dev/console still exists and still refers to the serial port. So + you can still use certain kinds of debug output (see include/debug.h, all + of the interfaces based on lowsyslog will work in this configuration). + + 10. USB OTG FS Host Support. The following changes will enable support for a USB host on the STM32F4Discovery, including support for a mass storage class driver: @@ -1497,10 +1526,29 @@ Where is one of the following: CONFIG_SYSLOG_CHAR=y : Use a character device for system logging CONFIG_SYSLOG_DEVPATH="/dev/ttyS0" : UART2 will be /dev/ttyS0 - Debug, however, is not enable so in the default configuration nothing - should appear on UART2 unless you enable some debug output. - - 4. By default, this project assumes that you are *NOT* using the DFU + However, there is nothing to generate SYLOG output in the default + configuration so nothing should appear on UART2 unless you enable + some debug output or enable the USB monitor. + + 4. Enabling USB monitor SYSLOG output. If tracing is enabled, the USB + device will save encoded trace output in in-memory buffer; if the + USB monitor is enabled, that trace buffer will be periodically + emptied and dumped to the system loggin device (UART2 in this + configuraion): + + CONFIG_USBDEV_TRACE=y : Enable USB trace feature + CONFIG_USBDEV_TRACE_NRECORDS=128 : Buffer 128 records in memory + CONFIG_SYSTEM_USBMONITOR=y : Start the USB monitor daemon + CONFIG_SYSTEM_USBMONITOR_STACKSIZE=2048 : USB monitor daemon stack size + CONFIG_SYSTEM_USBMONITOR_PRIORITY=50 : USB monitor daemon priority + + CONFIG_NSH_USBDEV_TRACEINIT=y : Enable TRACE output + CONFIG_NSH_USBDEV_TRACECLASS=y + CONFIG_NSH_USBDEV_TRACETRANSFERS=y + CONFIG_NSH_USBDEV_TRACECONTROLLER=y + CONFIG_NSH_USBDEV_TRACEINTERRUPTS=y + + 5. By default, this project assumes that you are *NOT* using the DFU bootloader. Using the Prolifics PL2303 Emulation diff --git a/nuttx/configs/stm32f4discovery/src/up_nsh.c b/nuttx/configs/stm32f4discovery/src/up_nsh.c index fd3fe5cd9..565aac724 100644 --- a/nuttx/configs/stm32f4discovery/src/up_nsh.c +++ b/nuttx/configs/stm32f4discovery/src/up_nsh.c @@ -50,6 +50,10 @@ # include #endif +#ifdef CONFIG_SYSTEM_USBMONITOR +# include +#endif + #ifdef CONFIG_STM32_OTGFS # include "stm32_usbhost.h" #endif @@ -63,20 +67,23 @@ /* Configuration ************************************************************/ -#define HAVE_USBDEV 1 -#define HAVE_USBHOST 1 +#define HAVE_USBDEV 1 +#define HAVE_USBHOST 1 +#define HAVE_USBMONITOR 1 /* Can't support USB host or device features if USB OTG FS is not enabled */ #ifndef CONFIG_STM32_OTGFS # undef HAVE_USBDEV # undef HAVE_USBHOST +# undef HAVE_USBMONITOR #endif /* Can't support USB device is USB device is not enabled */ #ifndef CONFIG_USBDEV # undef HAVE_USBDEV +# undef HAVE_USBMONITOR #endif /* Can't support USB host is USB host is not enabled */ @@ -85,6 +92,12 @@ # undef HAVE_USBHOST #endif +/* Check if we should enable the USB monitor before starting NSH */ + +#if !defined(CONFIG_USBDEV_TRACE) || !defined(CONFIG_SYSTEM_USBMONITOR) +# undef HAVE_USBMONITOR +#endif + /* Debug ********************************************************************/ #ifdef CONFIG_CPP_HAVE_VARARGS @@ -115,9 +128,11 @@ int nsh_archinitialize(void) { -#ifdef HAVE_USBHOST +#if defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR) int ret; +#endif +#ifdef HAVE_USBHOST /* Initialize USB host operation. stm32_usbhost_initialize() starts a thread * will monitor for USB connection and disconnection events. */ @@ -130,5 +145,15 @@ int nsh_archinitialize(void) } #endif +#ifdef HAVE_USBMONITOR + /* Start the USB Monitor */ + + ret = usbmonitor_start(0, NULL); + if (ret != OK) + { + message("nsh_archinitialize: Start USB monitor: %d\n", ret); + } +#endif + return OK; } diff --git a/nuttx/configs/stm32f4discovery/usbnsh/defconfig b/nuttx/configs/stm32f4discovery/usbnsh/defconfig index 534445f01..ba704001a 100644 --- a/nuttx/configs/stm32f4discovery/usbnsh/defconfig +++ b/nuttx/configs/stm32f4discovery/usbnsh/defconfig @@ -422,7 +422,7 @@ CONFIG_CDCACM_TXBUFSIZE=256 CONFIG_CDCACM_VENDORID=0x0525 CONFIG_CDCACM_PRODUCTID=0xa4a7 CONFIG_CDCACM_VENDORSTR="NuttX" -CONFIG_CDCACM_PRODUCTSTR="USBdev Serial" +CONFIG_CDCACM_PRODUCTSTR="CDC/ACM Serial" # CONFIG_USBMSC is not set # CONFIG_USBHOST is not set # CONFIG_WIRELESS is not set diff --git a/nuttx/drivers/usbdev/Kconfig b/nuttx/drivers/usbdev/Kconfig index 5ab6bb8fa..e17b38022 100644 --- a/nuttx/drivers/usbdev/Kconfig +++ b/nuttx/drivers/usbdev/Kconfig @@ -148,7 +148,7 @@ config COMPOSITE_VERSIONNO endif menuconfig PL2303 - bool "Emulates the Prolific PL2303 serial/USB converter" + bool "Prolific PL2303 serial/USB converter emulation" default n ---help--- This logic emulates the Prolific PL2303 serial/USB converter @@ -216,7 +216,7 @@ config PL2303_VENDORSTR config PL2303_PRODUCTSTR string "Product string" - default "USBdev Serial" + default "PL2303 Emulation" endif menuconfig CDCACM @@ -380,7 +380,7 @@ config CDCACM_VENDORSTR config CDCACM_PRODUCTSTR string "Product string" - default "USBdev Serial" + default "CDC/ACM Serial" endif menuconfig USBMSC @@ -495,8 +495,8 @@ config USBMSC_PRODUCTID default 0x00 config USBMSC_PRODUCTSTR - string "Mass stroage product string" - default "Mass stroage" + string "Mass storage product string" + default "Mass Storage" config USBMSC_VERSIONNO hex "USB MSC Version Number" diff --git a/nuttx/fs/Kconfig b/nuttx/fs/Kconfig index e6647f516..6aac7a3f7 100644 --- a/nuttx/fs/Kconfig +++ b/nuttx/fs/Kconfig @@ -18,11 +18,22 @@ source fs/binfs/Kconfig comment "System Logging" +config SYSLOG_ENABLE + bool "Enable SYSLOG Controls" + default n + ---help--- + Support an interface called syslog_enable to dynamically enable or + disable SYSLOG output. Default: SYSLOG output is always enabled. + config SYSLOG - bool "System logging" + bool "Advanced SYSLOG features" default n ---help--- - Enables generic system logging features. + Enables generic system logging features. NOTE: This setting is not + required to enable system logging. If this feature is not enable + system logging will still be available and will log to the system + console (like printf()). This setting is required to enable + customization of the basic system loggin capability. if SYSLOG diff --git a/nuttx/graphics/nxfonts/nxfonts_getfont.c b/nuttx/graphics/nxfonts/nxfonts_getfont.c index c2af977f2..0eb48e9df 100644 --- a/nuttx/graphics/nxfonts/nxfonts_getfont.c +++ b/nuttx/graphics/nxfonts/nxfonts_getfont.c @@ -242,7 +242,7 @@ static FAR const struct nx_fontpackage_s *g_fontpackages[] = * Name: nxf_getglyphset * * Description: - * Return information about the font set containtined he selected + * Return information about the font set contained in the selected * character encoding. * * Input Parameters: -- cgit v1.2.3 From fb94bc1258c9fe4e78fe0d5515f6a6131a8d1e65 Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 29 Jan 2013 17:42:58 +0000 Subject: The USB monitor now works with the stm32f4discover/nsh configuration (but not with the usbnsh configuration) git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5580 42af7a65-404d-4744-a932-0658087f49c3 --- apps/nshlib/Kconfig | 20 ++++++-- apps/nshlib/README.txt | 12 +++-- apps/nshlib/nsh.h | 80 ++++++++++++++++++------------- apps/nshlib/nsh_usbdev.c | 23 +++++---- apps/system/usbmonitor/Kconfig | 42 ++++++++++++++-- apps/system/usbmonitor/usbmonitor.c | 76 +++++++++++++++++++++++++++-- nuttx/configs/stm32f4discovery/README.txt | 42 ++++++++++------ nuttx/fs/fs_syslog.c | 2 + nuttx/libc/stdio/lib_syslogstream.c | 1 - 9 files changed, 225 insertions(+), 73 deletions(-) diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig index f6a5aa045..589476baf 100644 --- a/apps/nshlib/Kconfig +++ b/apps/nshlib/Kconfig @@ -406,7 +406,7 @@ config NSH_USBCONDEV readable/write-able USB driver such as: NSH_USBCONDEV="/dev/ttyACM0". -config UBSDEV_MINOR +config USBDEV_MINOR int "USB console device minor number" default 0 depends on NSH_USBCONSOLE @@ -414,8 +414,22 @@ config UBSDEV_MINOR If there are more than one USB devices, then a USB device minor number may also need to be provided. Default: 0 -menu "USB Trace Support" +comment "USB Trace Support" +config NSH_USBDEV_TRACE + bool "Enable Builtin USB Trace Support" + default n depends on USBDEV && (DEBUG || USBDEV_TRACE) + ---help--- + Enable builtin USB trace support in NSH. If selected, buffered USB + trace data will be presented each time a command is provided to NSH. + The USB trace data will be sent to the console unless DEBUG set or + unless you are using a USB console. In those cases, the trace data + will go to the SYSLOG device. + + If not enabled, the USB trace support can be provided by external + logic such as apps/system/usbmonitor. + +if NSH_USBDEV_TRACE config NSH_USBDEV_TRACEINIT bool "Show initialization events" @@ -447,7 +461,7 @@ config NSH_USBDEV_TRACEINTERRUPTS ---help--- Show interrupt-related events -endmenu +endif config NSH_CONDEV bool "Default console device" diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt index 006839628..a03f4a8ee 100644 --- a/apps/nshlib/README.txt +++ b/apps/nshlib/README.txt @@ -1025,12 +1025,16 @@ NSH-Specific Configuration Settings If there are more than one USB devices, then a USB device minor number may also need to be provided: - CONFIG_NSH_UBSDEV_MINOR + CONFIG_NSH_USBDEV_MINOR The minor device number of the USB device. Default: 0 - If USB tracing is enabled (CONFIG_USBDEV_TRACE), then NSH will - initialize USB tracing as requested by the following. Default: - Only USB errors are traced. + CONFIG_NSH_USBDEV_TRACE + If USB tracing is enabled (CONFIG_USBDEV_TRACE), then NSH can + be configured to show the buffered USB trace data afer each + NSH command: + + If CONFIG_NSH_USBDEV_TRACE is selected, then USB trace data + can be filtered as follows. Default: Only USB errors are traced. CONFIG_NSH_USBDEV_TRACEINIT Show initialization events diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h index 64099a8df..705375e7e 100644 --- a/apps/nshlib/nsh.h +++ b/apps/nshlib/nsh.h @@ -1,7 +1,7 @@ /**************************************************************************** * apps/nshlib/nsh.h * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -93,7 +93,9 @@ # elif defined(CONFIG_CDCACM) && defined(CONFIG_CDCACM_CONSOLE) # define HAVE_USB_CONSOLE 1 -/* Check for other USB console. USB console device must be provided in CONFIG_NSH_CONDEV */ +/* Check for other USB console. USB console device must be provided in + * CONFIG_NSH_CONDEV. + */ # elif defined(CONFIG_NSH_USBCONSOLE) # define HAVE_USB_CONSOLE 1 @@ -106,8 +108,8 @@ /* The default USB console device minor number is 0*/ -# ifndef CONFIG_NSH_UBSDEV_MINOR -# define CONFIG_NSH_UBSDEV_MINOR 0 +# ifndef CONFIG_NSH_USBDEV_MINOR +# define CONFIG_NSH_USBDEV_MINOR 0 # endif /* The default console device is always /dev/console */ @@ -118,42 +120,52 @@ /* USB trace settings */ -#ifdef CONFIG_NSH_USBDEV_TRACEINIT -# define TRACE_INIT_BITS (TRACE_INIT_BIT) -#else -# define TRACE_INIT_BITS (0) -#endif +#ifndef CONFIG_USBDEV_TRACE +# undef CONFIG_NSH_USBDEV_TRACE +#endif -#define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT) +#ifdef CONFIG_NSH_USBDEV_TRACE +# ifdef CONFIG_NSH_USBDEV_TRACEINIT +# define TRACE_INIT_BITS (TRACE_INIT_BIT) +# else +# define TRACE_INIT_BITS (0) +# endif -#ifdef CONFIG_NSH_USBDEV_TRACECLASS -# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|TRACE_CLASSSTATE_BIT) -#else -# define TRACE_CLASS_BITS (0) -#endif +# define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT) -#ifdef CONFIG_NSH_USBDEV_TRACETRANSFERS -# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|TRACE_READ_BIT|\ - TRACE_WRITE_BIT|TRACE_COMPLETE_BIT) -#else -# define TRACE_TRANSFER_BITS (0) -#endif +# ifdef CONFIG_NSH_USBDEV_TRACECLASS +# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|\ + TRACE_CLASSSTATE_BIT) +# else +# define TRACE_CLASS_BITS (0) +# endif -#ifdef CONFIG_NSH_USBDEV_TRACECONTROLLER -# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) -#else -# define TRACE_CONTROLLER_BITS (0) -#endif +# ifdef CONFIG_NSH_USBDEV_TRACETRANSFERS +# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|\ + TRACE_READ_BIT|TRACE_WRITE_BIT|\ + TRACE_COMPLETE_BIT) +# else +# define TRACE_TRANSFER_BITS (0) +# endif -#ifdef CONFIG_NSH_USBDEV_TRACEINTERRUPTS -# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|TRACE_INTEXIT_BIT) -#else -# define TRACE_INTERRUPT_BITS (0) -#endif +# ifdef CONFIG_NSH_USBDEV_TRACECONTROLLER +# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) +# else +# define TRACE_CONTROLLER_BITS (0) +# endif -#define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|TRACE_CLASS_BITS|\ - TRACE_TRANSFER_BITS|TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) +# ifdef CONFIG_NSH_USBDEV_TRACEINTERRUPTS +# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|\ + TRACE_INTEXIT_BIT) +# else +# define TRACE_INTERRUPT_BITS (0) +# endif +# define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|\ + TRACE_CLASS_BITS|TRACE_TRANSFER_BITS|\ + TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) + +# endif #endif /* If Telnet is selected for the NSH console, then we must configure @@ -515,7 +527,7 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, /* USB debug support */ -#if defined(CONFIG_USBDEV_TRACE) && defined(HAVE_USB_CONSOLE) +#if defined(CONFIG_NSH_USBDEV_TRACE) && defined(HAVE_USB_CONSOLE) void nsh_usbtrace(void); #else # define nsh_usbtrace() diff --git a/apps/nshlib/nsh_usbdev.c b/apps/nshlib/nsh_usbdev.c index d137e3dae..2064cbd84 100644 --- a/apps/nshlib/nsh_usbdev.c +++ b/apps/nshlib/nsh_usbdev.c @@ -61,9 +61,15 @@ /**************************************************************************** * Definitions ****************************************************************************/ - -#if defined(CONFIG_DEBUG) || defined(CONFIG_NSH_USBCONSOLE) -# define trmessage lowsyslog +/* Output USB trace data to the console device using printf() unless (1) + * debug is enabled, then we want to keep the trace output in sync with the + * debug output by using syslog()we are using a USB console. In that case, + * we don't want the trace output on the USB console; let's try sending it + * a SYSLOG device (hopefully one is set up!) + */ + +#if defined(CONFIG_DEBUG) || defined(HAVE_USB_CONSOLE) +# define trmessage syslog #else # define trmessage printf #endif @@ -92,7 +98,7 @@ * Name: nsh_tracecallback ****************************************************************************/ -#ifdef CONFIG_USBDEV_TRACE +#ifdef CONFIG_NSH_USBDEV_TRACE static int nsh_tracecallback(struct usbtrace_s *trace, void *arg) { usbtrace_trprintf((trprintf_t)trmessage, trace->event, trace->value); @@ -119,7 +125,7 @@ int nsh_usbconsole(void) /* Initialize any USB tracing options that were requested */ -#ifdef CONFIG_USBDEV_TRACE +#ifdef CONFIG_NSH_USBDEV_TRACE usbtrace_enable(TRACE_BITSET); #endif @@ -133,9 +139,9 @@ int nsh_usbconsole(void) #if defined(CONFIG_PL2303) || defined(CONFIG_CDCACM) #ifdef CONFIG_CDCACM - ret = cdcacm_initialize(CONFIG_NSH_UBSDEV_MINOR, NULL); + ret = cdcacm_initialize(CONFIG_NSH_USBDEV_MINOR, NULL); #else - ret = usbdev_serialinitialize(CONFIG_NSH_UBSDEV_MINOR); + ret = usbdev_serialinitialize(CONFIG_NSH_USBDEV_MINOR); #endif DEBUGASSERT(ret == OK); #endif @@ -224,6 +230,7 @@ int nsh_usbconsole(void) (void)fdopen(0, "r"); (void)fdopen(1, "a"); (void)fdopen(2, "a"); + return OK; } @@ -233,7 +240,7 @@ int nsh_usbconsole(void) * Name: nsh_usbtrace ****************************************************************************/ -#if defined(CONFIG_USBDEV_TRACE) && defined(HAVE_USB_CONSOLE) +#if defined(CONFIG_NSH_USBDEV_TRACE) && defined(HAVE_USB_CONSOLE) void nsh_usbtrace(void) { (void)usbtrace_enumerate(nsh_tracecallback, NULL); diff --git a/apps/system/usbmonitor/Kconfig b/apps/system/usbmonitor/Kconfig index 7199845b1..bde97de15 100644 --- a/apps/system/usbmonitor/Kconfig +++ b/apps/system/usbmonitor/Kconfig @@ -16,18 +16,52 @@ config SYSTEM_USBMONITOR if SYSTEM_USBMONITOR config SYSTEM_USBMONITOR_STACKSIZE - int "USB Monitor Stack Size" + int "USB Monitor daemon stack size" default 2048 - depends on NSH_BUILTIN_APPS ---help--- The stack size to use the the USB monitor daemon. Default: 2048 config SYSTEM_USBMONITOR_PRIORITY - int "USB Monitor Stack Size" + int "USB Monitor daemon priority" default 50 - depends on NSH_BUILTIN_APPS ---help--- The priority to use the the USB monitor daemon. Default: 50 +config SYSTEM_USBMONITOR_INTERVAL + int "USB Monitor dump frequency" + default 2 + ---help--- + The rate in seconds that the USB monitor will wait before dumping + the next set of buffered USB trace data. Default: 2 seconds. + +config SYSTEM_USBMONITOR_TRACEINIT + bool "Show initialization events" + default n + ---help--- + Show initialization events + +config SYSTEM_USBMONITOR_TRACECLASS + bool "Show class driver events" + default n + ---help--- + Show class driver events + +config SYSTEM_USBMONITOR_TRACETRANSFERS + bool "Show data transfer events" + default n + ---help--- + Show data transfer events + +config SYSTEM_USBMONITOR_TRACECONTROLLER + bool "Show controller events" + default n + ---help--- + Show controller events + +config SYSTEM_USBMONITOR_TRACEINTERRUPTS + bool "Show interrupt-related events" + default n + ---help--- + Show interrupt-related events endif diff --git a/apps/system/usbmonitor/usbmonitor.c b/apps/system/usbmonitor/usbmonitor.c index b386c3c2e..cde945b43 100644 --- a/apps/system/usbmonitor/usbmonitor.c +++ b/apps/system/usbmonitor/usbmonitor.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/system/free/free.c + * apps/system/usbmonitor/usbmonitor.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -57,6 +57,60 @@ #define USBMON_PREFIX "USB Monitor: " +/* Configuration ************************************************************/ + +#ifndef CONFIG_SYSTEM_USBMONITOR_STACKSIZE +# define CONFIG_SYSTEM_USBMONITOR_STACKSIZE 2048 +#endif + +#ifndef CONFIG_SYSTEM_USBMONITOR_PRIORITY +# define CONFIG_SYSTEM_USBMONITOR_PRIORITY 50 +#endif + +#ifndef CONFIG_SYSTEM_USBMONITOR_INTERVAL +# define CONFIG_SYSTEM_USBMONITOR_INTERVAL 2 +#endif + +#ifdef CONFIG_SYSTEM_USBMONITOR_TRACEINIT +# define TRACE_INIT_BITS (TRACE_INIT_BIT) +#else +# define TRACE_INIT_BITS (0) +#endif + +#define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT) + +#ifdef CONFIG_SYSTEM_USBMONITOR_TRACECLASS +# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|\ + TRACE_CLASSSTATE_BIT) +#else +# define TRACE_CLASS_BITS (0) +#endif + +#ifdef CONFIG_SYSTEM_USBMONITOR_TRACETRANSFERS +# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|\ + TRACE_READ_BIT|TRACE_WRITE_BIT|\ + TRACE_COMPLETE_BIT) +#else +# define TRACE_TRANSFER_BITS (0) +#endif + +#ifdef CONFIG_SYSTEM_USBMONITOR_TRACECONTROLLER +# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) +#else +# define TRACE_CONTROLLER_BITS (0) +#endif + +#ifdef CONFIG_SYSTEM_USBMONITOR_TRACEINTERRUPTS +# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|\ + TRACE_INTEXIT_BIT) +#else +# define TRACE_INTERRUPT_BITS (0) +#endif + +#define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|\ + TRACE_CLASS_BITS|TRACE_TRANSFER_BITS|\ + TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) + /**************************************************************************** * Private Types ****************************************************************************/ @@ -92,7 +146,7 @@ static int usbmonitor_daemon(int argc, char **argv) while (!g_usbmonitor.stop) { - sleep(2); + sleep(CONFIG_SYSTEM_USBMONITOR_INTERVAL); (void)usbtrace_enumerate(usbmonitor_tracecallback, NULL); } @@ -120,6 +174,12 @@ int usbmonitor_start(int argc, char **argv) /* No.. start it now */ + /* First, initialize any USB tracing options that were requested */ + + usbtrace_enable(TRACE_BITSET); + + /* Then start the USB monitoring daemon */ + g_usbmonitor.started = true; g_usbmonitor.stop = false; @@ -144,7 +204,8 @@ int usbmonitor_start(int argc, char **argv) } sched_unlock(); - syslog(USBMON_PREFIX "Running: %d\n", g_usbmonitor.pid); + syslog(USBMON_PREFIX "%s: %d\n", + g_usbmonitor.stop ? "Stopping" : "Running", g_usbmonitor.pid); return 0; } @@ -154,9 +215,16 @@ int usbmonitor_stop(int argc, char **argv) if (g_usbmonitor.started) { + /* Stop the USB monitor. The next time the monitor wakes up, + * it will see the the stop indication and will exist. + */ + syslog(USBMON_PREFIX "Stopping: %d\n", g_usbmonitor.pid); g_usbmonitor.stop = true; - return 0; + + /* We may as well disable tracing since there is no listener */ + + usbtrace_enable(0); } syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid); diff --git a/nuttx/configs/stm32f4discovery/README.txt b/nuttx/configs/stm32f4discovery/README.txt index 41207fafa..25a770012 100644 --- a/nuttx/configs/stm32f4discovery/README.txt +++ b/nuttx/configs/stm32f4discovery/README.txt @@ -1287,19 +1287,29 @@ Where is one of the following: you can still use certain kinds of debug output (see include/debug.h, all of the interfaces based on lowsyslog will work in this configuration). + - But don't enable USB debug output! Since USB is console is used for + USB debug output and you are using a USB console, there will be + infinite loops and deadlocks: Debug output generates USB debug + output which generatates USB debug output, etc. If you want USB + debug output, you should consider enabling USB trace + (CONFIG_USBDEV_TRACE) and perhaps the USB monitor (CONFIG_SYSTEM_USBMONITOR). + + See the usbnsh configuration below for more information on configuring + USB trace output and the USB monitor. + 10. USB OTG FS Host Support. The following changes will enable support for a USB host on the STM32F4Discovery, including support for a mass storage class driver: - - CONFIG_USBDEV=n - Make sure tht USB device support is disabled - CONFIG_USBHOST=y - Enable USB host support - CONFIG_STM32_OTGFS=y - Enable the STM32 USB OTG FS block - CONFIG_STM32_SYSCFG=y - Needed for all USB OTF FS support - CONFIG_SCHED_WORKQUEUE=y - Worker thread support is required for the mass + + CONFIG_USBDEV=n : Make sure tht USB device support is disabled + CONFIG_USBHOST=y : Enable USB host support + CONFIG_STM32_OTGFS=y : Enable the STM32 USB OTG FS block + CONFIG_STM32_SYSCFG=y : Needed for all USB OTF FS support + CONFIG_SCHED_WORKQUEUE=y : Worker thread support is required for the mass storage class driver. - CONFIG_NSH_ARCHINIT=y - Architecture specific USB initialization + CONFIG_NSH_ARCHINIT=y : Architecture specific USB initialization is needed for NSH - CONFIG_FS_FAT=y - Needed by the USB host mass storage class. + CONFIG_FS_FAT=y : Needed by the USB host mass storage class. With those changes, you can use NSH with a FLASH pen driver as shown belong. Here NSH is started with nothing in the USB host slot: @@ -1466,7 +1476,6 @@ Where is one of the following: STANDBY mode. This used of the RTC alarm could conflict with other uses of the RTC alarm in your application. - posix_spawn: ------------ This configuration directory, performs a simple test os the posix_spawn @@ -1538,15 +1547,18 @@ Where is one of the following: CONFIG_USBDEV_TRACE=y : Enable USB trace feature CONFIG_USBDEV_TRACE_NRECORDS=128 : Buffer 128 records in memory - CONFIG_SYSTEM_USBMONITOR=y : Start the USB monitor daemon + CONFIG_NSH_USBDEV_TRACE=n : No builtin tracing from NSH + CONFIG_NSH_ARCHINIT=y : Automatically start the USB monitor + CONFIG_SYSTEM_USBMONITOR=y : Enable the USB monitor daemon CONFIG_SYSTEM_USBMONITOR_STACKSIZE=2048 : USB monitor daemon stack size CONFIG_SYSTEM_USBMONITOR_PRIORITY=50 : USB monitor daemon priority + CONFIG_SYSTEM_USBMONITOR_INTERVAL=2 : Dump trace data every 2 seconds - CONFIG_NSH_USBDEV_TRACEINIT=y : Enable TRACE output - CONFIG_NSH_USBDEV_TRACECLASS=y - CONFIG_NSH_USBDEV_TRACETRANSFERS=y - CONFIG_NSH_USBDEV_TRACECONTROLLER=y - CONFIG_NSH_USBDEV_TRACEINTERRUPTS=y + CONFIG_SYSTEM_USBMONITOR_TRACEINIT=y : Enable TRACE output + CONFIG_SYSTEM_USBMONITOR_TRACECLASS=y + CONFIG_SYSTEM_USBMONITOR_TRACETRANSFERS=y + CONFIG_SYSTEM_USBMONITOR_TRACECONTROLLER=y + CONFIG_SYSTEM_USBMONITOR_TRACEINTERRUPTS=y 5. By default, this project assumes that you are *NOT* using the DFU bootloader. diff --git a/nuttx/fs/fs_syslog.c b/nuttx/fs/fs_syslog.c index 779263a3c..d9ad29e0f 100644 --- a/nuttx/fs/fs_syslog.c +++ b/nuttx/fs/fs_syslog.c @@ -168,8 +168,10 @@ static inline int syslog_takesem(void) static inline void syslog_givesem(void) { +#ifdef CONFIG_DEBUG pid_t me = getpid(); DEBUGASSERT(g_sysdev.sl_holder == me); +#endif /* Relinquish the semaphore */ diff --git a/nuttx/libc/stdio/lib_syslogstream.c b/nuttx/libc/stdio/lib_syslogstream.c index 121227d3c..e29c5ca3d 100644 --- a/nuttx/libc/stdio/lib_syslogstream.c +++ b/nuttx/libc/stdio/lib_syslogstream.c @@ -63,7 +63,6 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch) { - int errcode; int ret; /* Try writing until the write was successful or until an irrecoverable -- cgit v1.2.3 From 6ebd56f299b9f855b5bfdca3b48163f335ce44e8 Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 29 Jan 2013 18:32:04 +0000 Subject: The USB monitor now works with configs/stm32f4discovery/usbnsh git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5581 42af7a65-404d-4744-a932-0658087f49c3 --- apps/nshlib/nsh.h | 78 +++++++++++++++++++++++++------------------------- nuttx/tools/mkconfig.c | 22 ++++++++------ 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h index 705375e7e..168503580 100644 --- a/apps/nshlib/nsh.h +++ b/apps/nshlib/nsh.h @@ -120,53 +120,53 @@ /* USB trace settings */ -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_NSH_USBDEV_TRACE -#endif +# ifndef CONFIG_USBDEV_TRACE +# undef CONFIG_NSH_USBDEV_TRACE +# endif -#ifdef CONFIG_NSH_USBDEV_TRACE -# ifdef CONFIG_NSH_USBDEV_TRACEINIT -# define TRACE_INIT_BITS (TRACE_INIT_BIT) -# else -# define TRACE_INIT_BITS (0) -# endif +# ifdef CONFIG_NSH_USBDEV_TRACE +# ifdef CONFIG_NSH_USBDEV_TRACEINIT +# define TRACE_INIT_BITS (TRACE_INIT_BIT) +# else +# define TRACE_INIT_BITS (0) +# endif -# define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT) +# define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT) -# ifdef CONFIG_NSH_USBDEV_TRACECLASS -# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|\ - TRACE_CLASSSTATE_BIT) -# else -# define TRACE_CLASS_BITS (0) -# endif +# ifdef CONFIG_NSH_USBDEV_TRACECLASS +# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|\ + TRACE_CLASSSTATE_BIT) +# else +# define TRACE_CLASS_BITS (0) +# endif -# ifdef CONFIG_NSH_USBDEV_TRACETRANSFERS -# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|\ - TRACE_READ_BIT|TRACE_WRITE_BIT|\ - TRACE_COMPLETE_BIT) -# else -# define TRACE_TRANSFER_BITS (0) -# endif +# ifdef CONFIG_NSH_USBDEV_TRACETRANSFERS +# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|\ + TRACE_READ_BIT|TRACE_WRITE_BIT|\ + TRACE_COMPLETE_BIT) +# else +# define TRACE_TRANSFER_BITS (0) +# endif -# ifdef CONFIG_NSH_USBDEV_TRACECONTROLLER -# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) -# else -# define TRACE_CONTROLLER_BITS (0) -# endif +# ifdef CONFIG_NSH_USBDEV_TRACECONTROLLER +# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT) +# else +# define TRACE_CONTROLLER_BITS (0) +# endif -# ifdef CONFIG_NSH_USBDEV_TRACEINTERRUPTS -# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|\ - TRACE_INTEXIT_BIT) -# else -# define TRACE_INTERRUPT_BITS (0) -# endif +# ifdef CONFIG_NSH_USBDEV_TRACEINTERRUPTS +# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|\ + TRACE_INTEXIT_BIT) +# else +# define TRACE_INTERRUPT_BITS (0) +# endif -# define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|\ - TRACE_CLASS_BITS|TRACE_TRANSFER_BITS|\ - TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) +# define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|\ + TRACE_CLASS_BITS|TRACE_TRANSFER_BITS|\ + TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS) -# endif -#endif +# endif /* CONFIG_NSH_USBDEV_TRACE */ +#endif /* HAVE_USB_CONSOLE */ /* If Telnet is selected for the NSH console, then we must configure * the resources used by the Telnet daemon and by the Telnet clients. diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c index d8d09df34..a622743a0 100644 --- a/nuttx/tools/mkconfig.c +++ b/nuttx/tools/mkconfig.c @@ -126,17 +126,23 @@ int main(int argc, char **argv, char **envp) printf("#ifndef CONFIG_RR_INTERVAL\n"); printf("# define CONFIG_RR_INTERVAL 0\n"); printf("#endif\n\n"); - printf("/* The correct way to disable filesystem supuport is to set the\n"); - printf(" * number of file descriptors to zero.\n"); + printf("/* The correct way to disable filesystem supuport is to set the number of\n"); + printf(" * file descriptors to zero.\n"); printf(" */\n\n"); printf("#ifndef CONFIG_NFILE_DESCRIPTORS\n"); printf("# define CONFIG_NFILE_DESCRIPTORS 0\n"); printf("#endif\n\n"); - printf("/* If a console is selected, then make sure that there are\n"); - printf(" * resources for 3 file descriptors and, if any streams are\n"); - printf(" * selected, also for 3 file streams.\n"); + printf("/* If a console is selected, then make sure that there are resources for\n"); + printf(" * three file descriptors and, if any streams are selected, also for three\n"); + printf(" * file streams.\n"); + printf(" *\n"); + printf(" * CONFIG_DEV_CONSOLE means that a builtin console device exists at /dev/console\n"); + printf(" * and can be opened during boot-up. Other consoles, such as USB consoles, may\n"); + printf(" * not exist at boot-upand have to be handled in a different way. Three file\n"); + printf(" * descriptors and three file streams are still needed.\n"); printf(" */\n\n"); - printf("#ifdef CONFIG_DEV_CONSOLE\n"); + printf("#if defined(CONFIG_DEV_CONSOLE) || defined(CONFIG_CDCACM_CONSOLE) || \\\n"); + printf(" defined(CONFIG_PL2303_CONSOLE)\n"); printf("# if CONFIG_NFILE_DESCRIPTORS < 3\n"); printf("# undef CONFIG_NFILE_DESCRIPTORS\n"); printf("# define CONFIG_NFILE_DESCRIPTORS 3\n"); @@ -145,12 +151,10 @@ int main(int argc, char **argv, char **envp) printf("# undef CONFIG_NFILE_STREAMS\n"); printf("# define CONFIG_NFILE_STREAMS 3\n"); printf("# endif\n\n"); - printf("/* If no console is selected, then disable all console devices */\n\n"); + printf("/* If no console is selected, then disable all builtin console devices */\n\n"); printf("#else\n"); printf("# undef CONFIG_DEV_LOWCONSOLE\n"); printf("# undef CONFIG_RAMLOG_CONSOLE\n"); - printf("# undef CONFIG_CDCACM_CONSOLE\n"); - printf("# undef CONFIG_PL2303_CONSOLE\n"); printf("#endif\n\n"); printf("/* If priority inheritance is disabled, then do not allocate any\n"); printf(" * associated resources.\n"); -- cgit v1.2.3 From 7f22c14077e8aa4edb0d35ca1c8a75f7a978c929 Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 29 Jan 2013 22:11:04 +0000 Subject: Add support for a login script (in addition to the init script); Add logic so that a USB console session can connect and reconnect to the USB serial device git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5582 42af7a65-404d-4744-a932-0658087f49c3 --- apps/ChangeLog.txt | 7 +- apps/include/nsh.h | 71 +++++++++--- apps/nshlib/Kconfig | 22 ++++ apps/nshlib/Makefile | 9 +- apps/nshlib/nsh.h | 47 ++++++-- apps/nshlib/nsh_consolemain.c | 88 +++++---------- apps/nshlib/nsh_fscmds.c | 67 +----------- apps/nshlib/nsh_script.c | 195 +++++++++++++++++++++++++++++++++ apps/nshlib/nsh_session.c | 163 ++++++++++++++++++++++++++++ apps/nshlib/nsh_telnetd.c | 33 +++++- apps/nshlib/nsh_usbdev.c | 245 +++++++++++++++++++++++++++++++++--------- 11 files changed, 732 insertions(+), 215 deletions(-) create mode 100644 apps/nshlib/nsh_script.c create mode 100644 apps/nshlib/nsh_session.c diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 778f1fcf2..6a2c1d4c9 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -495,5 +495,10 @@ * apps/examples/nettest and poll: Complete Kconfig files. * apps/examples/ostest/waitpid.c: Need to use WEXITSTATUS() to decode the correct exit status. - * system/usbmonitor: A daemon that can be used to monitor USB + * apps/system/usbmonitor: A daemon that can be used to monitor USB trace outpout. + * apps/nshlib/nsh_usbdev.c, nsh_consolemain.c, nsh_session.c, nsh_script.c: + Add support for a login script. The init.d/rcS script will be executed + once when NSH starts; the .nshrc script will be executed for each session: + Once for serial, once for each USB connection, once for each Telnet + session. diff --git a/apps/include/nsh.h b/apps/include/nsh.h index 4b5a3cd31..8e469a555 100644 --- a/apps/include/nsh.h +++ b/apps/include/nsh.h @@ -1,7 +1,7 @@ /**************************************************************************** * apps/include/nsh.h * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,31 @@ /**************************************************************************** * Pre-Processor Definitions ****************************************************************************/ +/* If a USB device is selected for the NSH console then we need to handle some + * special start-up conditions. + */ + +#undef HAVE_USB_CONSOLE +#if defined(CONFIG_USBDEV) + +/* Check for a PL2303 serial console. Use console device "/dev/console". */ + +# if defined(CONFIG_PL2303) && defined(CONFIG_PL2303_CONSOLE) +# define HAVE_USB_CONSOLE 1 + +/* Check for a CDC/ACM serial console. Use console device "/dev/console". */ + +# elif defined(CONFIG_CDCACM) && defined(CONFIG_CDCACM_CONSOLE) +# define HAVE_USB_CONSOLE 1 + +/* Check for a generic USB console. In this case, the USB console device + * must be provided in CONFIG_NSH_CONDEV. + */ + +# elif defined(CONFIG_NSH_USBCONSOLE) +# define HAVE_USB_CONSOLE 1 +# endif +#endif #if CONFIG_RR_INTERVAL > 0 # define SCHED_NSH SCHED_RR @@ -58,7 +83,8 @@ #ifdef __cplusplus #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif @@ -83,35 +109,54 @@ extern "C" { * ****************************************************************************/ -EXTERN void nsh_initialize(void); +void nsh_initialize(void); /**************************************************************************** * Name: nsh_consolemain * * Description: * This interfaces maybe to called or started with task_start to start a - * single an NSH instance that operates on stdin and stdout (/dev/console). - * This function does not return. + * single an NSH instance that operates on stdin and stdout. This + * function does not return. * + * This function handles generic /dev/console character devices, or + * special USB console devices. The USB console requires some special + * operations to handle the cases where the session is lost when the + * USB device is unplugged and restarted when the USB device is plugged + * in again. + * * Input Parameters: - * Standard task start-up arguements. These are not used. argc may be + * Standard task start-up arguments. These are not used. argc may be * zero and argv may be NULL. * * Returned Values: * This function does not normally return. exit() is usually called to * terminate the NSH session. This function will return in the event of - * an error. In that case, a nonzero value is returned (1). + * an error. In that case, a nonzero value is returned (EXIT_FAILURE=1). * ****************************************************************************/ -EXTERN int nsh_consolemain(int argc, char *argv[]); +int nsh_consolemain(int argc, char *argv[]); -/* nsh_telnetstart() starts a telnet daemon that will allow multiple - * NSH connections via telnet. This function returns immediately after - * the daemon has been started. - */ +/**************************************************************************** + * Name: nsh_telnetstart + * + * Description: + * nsh_telnetstart() starts the Telnet daemon that will allow multiple + * NSH connections via Telnet. This function returns immediately after + * the daemon has been started. + * + * Input Parameters: + * None. All of the properties of the Telnet daemon are controlled by + * NuttX configuration setting. + * + * Returned Values: + * The task ID of the Telnet daemon was successfully started. A negated + * errno value will be returned on failure. + * + ****************************************************************************/ -EXTERN int nsh_telnetstart(void); +int nsh_telnetstart(void); #undef EXTERN #ifdef __cplusplus diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig index 589476baf..92bc83cfd 100644 --- a/apps/nshlib/Kconfig +++ b/apps/nshlib/Kconfig @@ -292,6 +292,19 @@ config NSH_ROMFSETC endif if NSH_ROMFSETC + +config NSH_ROMFSRC + bool "Support ROMFS login script" + default n + ---help--- + The ROMFS start-up script will be executed excactly once. For + simple, persistence consoles (like a serial console). But with + other other kinds of consoles, there may be multiple, transient + sessions (such as Telnet and USB consoles). In these cases, you + may need another script that is executed at the beginning of each + session. Selecting this option enables support for such a login + script + config NSH_ROMFSMOUNTPT string "ROMFS mount point" default "/etc" @@ -308,6 +321,15 @@ config NSH_INITSCRIPT The default is init.d/rcS. This is a relative path and must not start with '/'. +config NSH_RCSCRIPT + string "Relative path to login script" + default ".nshrc" + depends on NSH_ROMFSRC + ---help--- + This is the relative path to the login script within the mountpoint. + The default is .nshrc. This is a relative path and must not + start with '/'. + config NSH_ROMFSDEVNO int "ROMFS block device minor number" default 0 diff --git a/apps/nshlib/Makefile b/apps/nshlib/Makefile index 948f43d52..76cdac40d 100644 --- a/apps/nshlib/Makefile +++ b/apps/nshlib/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/nshlib/Makefile # -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -39,9 +39,10 @@ include $(APPDIR)/Make.defs # NSH Library -ASRCS = -CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_fscmds.c nsh_ddcmd.c \ - nsh_proccmds.c nsh_mmcmds.c nsh_envcmds.c nsh_dbgcmds.c +ASRCS = +CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_script.c nsh_session.c +CSRCS += nsh_fscmds.c nsh_ddcmd.c nsh_proccmds.c nsh_mmcmds.c nsh_envcmds.c +CSRCS += nsh_dbgcmds.c ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) CSRCS += nsh_builtin.c diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h index 168503580..23209dba5 100644 --- a/apps/nshlib/nsh.h +++ b/apps/nshlib/nsh.h @@ -93,8 +93,8 @@ # elif defined(CONFIG_CDCACM) && defined(CONFIG_CDCACM_CONSOLE) # define HAVE_USB_CONSOLE 1 -/* Check for other USB console. USB console device must be provided in - * CONFIG_NSH_CONDEV. +/* Check for a generic USB console. In this case, the USB console device + * must be provided in CONFIG_NSH_CONDEV. */ # elif defined(CONFIG_NSH_USBCONSOLE) @@ -244,40 +244,59 @@ # error "Mountpoint support is disabled" # undef CONFIG_NSH_ROMFSETC # endif + # if CONFIG_NFILE_DESCRIPTORS < 4 # error "Not enough file descriptors" # undef CONFIG_NSH_ROMFSETC # endif + # ifndef CONFIG_FS_ROMFS # error "ROMFS support not enabled" # undef CONFIG_NSH_ROMFSETC # endif + # ifndef CONFIG_NSH_ROMFSMOUNTPT # define CONFIG_NSH_ROMFSMOUNTPT "/etc" # endif -# ifdef CONFIG_NSH_INIT -# ifndef CONFIG_NSH_INITSCRIPT -# define CONFIG_NSH_INITSCRIPT "init.d/rcS" -# endif + +# ifndef CONFIG_NSH_INITSCRIPT +# define CONFIG_NSH_INITSCRIPT "init.d/rcS" # endif + # undef NSH_INITPATH # define NSH_INITPATH CONFIG_NSH_ROMFSMOUNTPT "/" CONFIG_NSH_INITSCRIPT + +# ifdef CONFIG_NSH_ROMFSRC +# ifndef CONFIG_NSH_RCSCRIPT +# define CONFIG_NSH_RCSCRIPT ".nshrc" +# endif + +# undef NSH_RCPATH +# define NSH_RCPATH CONFIG_NSH_ROMFSMOUNTPT "/" CONFIG_NSH_RCSCRIPT +# endif + # ifndef CONFIG_NSH_ROMFSDEVNO # define CONFIG_NSH_ROMFSDEVNO 0 # endif + # ifndef CONFIG_NSH_ROMFSSECTSIZE # define CONFIG_NSH_ROMFSSECTSIZE 64 # endif + # define NSECTORS(b) (((b)+CONFIG_NSH_ROMFSSECTSIZE-1)/CONFIG_NSH_ROMFSSECTSIZE) # define STR_RAMDEVNO(m) #m # define MKMOUNT_DEVNAME(m) "/dev/ram" STR_RAMDEVNO(m) # define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_NSH_ROMFSDEVNO) + #else + +# undef CONFIG_NSH_ROMFSRC # undef CONFIG_NSH_ROMFSMOUNTPT -# undef CONFIG_NSH_INIT # undef CONFIG_NSH_INITSCRIPT +# undef CONFIG_NSH_RCSCRIPT # undef CONFIG_NSH_ROMFSDEVNO # undef CONFIG_NSH_ROMFSSECTSIZE + #endif /* This is the maximum number of arguments that will be accepted for a @@ -486,6 +505,12 @@ int nsh_usbconsole(void); #if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT) int nsh_script(FAR struct nsh_vtbl_s *vtbl, const char *cmd, const char *path); +#ifdef CONFIG_NSH_ROMFSETC +int nsh_initscript(FAR struct nsh_vtbl_s *vtbl); +#ifdef CONFIG_NSH_ROMFSRC +int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl); +#endif +#endif #endif /* Architecture-specific initialization */ @@ -496,8 +521,10 @@ int nsh_archinitialize(void); # define nsh_archinitialize() (-ENOSYS) #endif -/* Message handler */ +/* Basic session and message handling */ +struct console_stdio_s; +int nsh_session(FAR struct console_stdio_s *pstate); int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline); /* Application interface */ @@ -527,10 +554,8 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, /* USB debug support */ -#if defined(CONFIG_NSH_USBDEV_TRACE) && defined(HAVE_USB_CONSOLE) +#ifdef CONFIG_NSH_USBDEV_TRACE void nsh_usbtrace(void); -#else -# define nsh_usbtrace() #endif /* Shell command handlers */ diff --git a/apps/nshlib/nsh_consolemain.c b/apps/nshlib/nsh_consolemain.c index f05447a64..8be44f7aa 100644 --- a/apps/nshlib/nsh_consolemain.c +++ b/apps/nshlib/nsh_consolemain.c @@ -1,7 +1,7 @@ /**************************************************************************** * apps/nshlib/nsh_consolemain.c * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,8 @@ #include "nsh.h" #include "nsh_console.h" +#ifndef HAVE_USB_CONSOLE + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -76,21 +78,25 @@ ****************************************************************************/ /**************************************************************************** - * Name: nsh_consolemain + * Name: nsh_consolemain (Normal character device version) * * Description: * This interfaces maybe to called or started with task_start to start a - * single an NSH instance that operates on stdin and stdout (/dev/console). - * This function does not return. + * single an NSH instance that operates on stdin and stdout. This + * function does not normally return (see below). * + * This version of nsh_consolmain handles generic /dev/console character + * devices (see nsh_usbdev.c for another version for special USB console + * devices). + * * Input Parameters: - * Standard task start-up arguements. These are not used. argc may be + * Standard task start-up arguments. These are not used. argc may be * zero and argv may be NULL. * * Returned Values: * This function does not normally return. exit() is usually called to * terminate the NSH session. This function will return in the event of - * an error. In that case, a nonzero value is returned (1). + * an error. In that case, a nonzero value is returned (EXIT_FAILURE=1). * ****************************************************************************/ @@ -101,70 +107,26 @@ int nsh_consolemain(int argc, char *argv[]) DEBUGASSERT(pstate); - /* If we are using a USB serial console, then we will have to wait for the - * USB to be connected to the host. - */ - -#ifdef HAVE_USB_CONSOLE - ret = nsh_usbconsole(); - DEBUGASSERT(ret == OK); -#endif - - /* Present a greeting */ - - fputs(g_nshgreeting, pstate->cn_outstream); - fflush(pstate->cn_outstream); - - /* Execute the startup script */ + /* Execute the start-up script */ #ifdef CONFIG_NSH_ROMFSETC - (void)nsh_script(&pstate->cn_vtbl, "init", NSH_INITPATH); + (void)nsh_initscript(&pstate->cn_vtbl); #endif - /* Then enter the command line parsing loop */ - - for (;;) - { - /* For the case of debugging the USB console... dump collected USB trace data */ + /* Initialize any USB tracing options that were requested */ - nsh_usbtrace(); - - /* Display the prompt string */ - - fputs(g_nshprompt, pstate->cn_outstream); - fflush(pstate->cn_outstream); - - /* Get the next line of input */ - - ret = readline(pstate->cn_line, CONFIG_NSH_LINELEN, - INSTREAM(pstate), OUTSTREAM(pstate)); - if (ret > 0) - { - /* Parse process the command */ - - (void)nsh_parse(&pstate->cn_vtbl, pstate->cn_line); - fflush(pstate->cn_outstream); - } +#ifdef CONFIG_NSH_USBDEV_TRACE + usbtrace_enable(TRACE_BITSET); +#endif - /* Readline normally returns the number of characters read, - * but will return 0 on end of file or a negative value - * if an error occurs. Either will cause the session to - * terminate. - */ + /* Execute the session */ - else - { - fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_consolemain", - "readline", NSH_ERRNO_OF(-ret)); - nsh_exit(&pstate->cn_vtbl, 1); - } - } + ret = nsh_session(pstate); - /* Clean up. We do not get here, but this is necessary to keep some - * compilers happy. But others will complain that this code is not - * reachable. - */ + /* Exit upon return */ - nsh_exit(&pstate->cn_vtbl, 0); - return OK; + nsh_exit(&pstate->cn_vtbl, ret); + return ret; } + +#endif /* !HAVE_USB_CONSOLE */ diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c index 1a9f2eb57..f47dca896 100644 --- a/apps/nshlib/nsh_fscmds.c +++ b/apps/nshlib/nsh_fscmds.c @@ -1,7 +1,7 @@ /**************************************************************************** * apps/nshlib/nsh_fscmds.c * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -1220,71 +1220,6 @@ int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #endif #endif -/**************************************************************************** - * Name: nsh_script - ****************************************************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT) -int nsh_script(FAR struct nsh_vtbl_s *vtbl, const char *cmd, const char *path) -{ - char *fullpath; - FILE *stream; - char *buffer; - char *pret; - int ret = ERROR; - - /* The path to the script may be relative to the current working directory */ - - fullpath = nsh_getfullpath(vtbl, path); - if (!fullpath) - { - return ERROR; - } - - /* Get a reference to the common input buffer */ - - buffer = nsh_linebuffer(vtbl); - if (buffer) - { - /* Open the file containing the script */ - - stream = fopen(fullpath, "r"); - if (!stream) - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "fopen", NSH_ERRNO); - nsh_freefullpath(fullpath); - return ERROR; - } - - /* Loop, processing each command line in the script file (or - * until an error occurs) - */ - - do - { - /* Get the next line of input from the file */ - - fflush(stdout); - pret = fgets(buffer, CONFIG_NSH_LINELEN, stream); - if (pret) - { - /* Parse process the command. NOTE: this is recursive... - * we got to cmd_sh via a call to nsh_parse. So some - * considerable amount of stack may be used. - */ - - ret = nsh_parse(vtbl, buffer); - } - } - while (pret && ret == OK); - fclose(stream); - } - - nsh_freefullpath(fullpath); - return ret; -} -#endif - /**************************************************************************** * Name: cmd_sh ****************************************************************************/ diff --git a/apps/nshlib/nsh_script.c b/apps/nshlib/nsh_script.c new file mode 100644 index 000000000..3aa698b31 --- /dev/null +++ b/apps/nshlib/nsh_script.c @@ -0,0 +1,195 @@ +/**************************************************************************** + * apps/nshlib/nsh_script.c + * + * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "nsh.h" +#include "nsh_console.h" + +#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT) + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nsh_script + * + * Description: + * Execute the NSH script at path. + * + ****************************************************************************/ + +int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, + FAR const char *path) +{ + char *fullpath; + FILE *stream; + char *buffer; + char *pret; + int ret = ERROR; + + /* The path to the script may be relative to the current working directory */ + + fullpath = nsh_getfullpath(vtbl, path); + if (!fullpath) + { + return ERROR; + } + + /* Get a reference to the common input buffer */ + + buffer = nsh_linebuffer(vtbl); + if (buffer) + { + /* Open the file containing the script */ + + stream = fopen(fullpath, "r"); + if (!stream) + { + nsh_output(vtbl, g_fmtcmdfailed, cmd, "fopen", NSH_ERRNO); + nsh_freefullpath(fullpath); + return ERROR; + } + + /* Loop, processing each command line in the script file (or + * until an error occurs) + */ + + do + { + /* Get the next line of input from the file */ + + fflush(stdout); + pret = fgets(buffer, CONFIG_NSH_LINELEN, stream); + if (pret) + { + /* Parse process the command. NOTE: this is recursive... + * we got to cmd_sh via a call to nsh_parse. So some + * considerable amount of stack may be used. + */ + + ret = nsh_parse(vtbl, buffer); + } + } + while (pret && ret == OK); + fclose(stream); + } + + nsh_freefullpath(fullpath); + return ret; +} + +/**************************************************************************** + * Name: nsh_initscript + * + * Description: + * Attempt to execute the configured initialization script. This script + * should be executed once when NSH starts. nsh_initscript is idempotent + * and may, however, be called multiple times (the script will be executed + * once. + * + ****************************************************************************/ + +#ifdef CONFIG_NSH_ROMFSETC +int nsh_initscript(FAR struct nsh_vtbl_s *vtbl) +{ + static bool initialized; + bool already; + int ret = OK; + + /* Atomic test and set of the initialized flag */ + + sched_lock(); + already = initialized; + initialized = true; + sched_unlock(); + + /* If we have not already executed the init script, then do so now */ + + if (!already) + { + ret = nsh_script(vtbl, "init", NSH_INITPATH); + } + + return ret; +} + +/**************************************************************************** + * Name: nsh_loginscript + * + * Description: + * Attempt to execute the configured login script. This script + * should be executed when each NSH session starts. + * + ****************************************************************************/ + +#ifdef CONFIG_NSH_ROMFSRC +int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl) +{ + return nsh_script(vtbl, "login", NSH_RCPATH); +} +#endif +#endif /* CONFIG_NSH_ROMFSETC */ + +#endif /* CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !CONFIG_NSH_DISABLESCRIPT */ diff --git a/apps/nshlib/nsh_session.c b/apps/nshlib/nsh_session.c new file mode 100644 index 000000000..8079b2de5 --- /dev/null +++ b/apps/nshlib/nsh_session.c @@ -0,0 +1,163 @@ +/**************************************************************************** + * apps/nshlib/nsh_session.c + * + * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "nsh.h" +#include "nsh_console.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nsh_session + * + * Description: + * This is the common session logic or any NSH session. This function + * return when an error reading from the input stream occurs, presumably + * signaling the end of the session. + * + * This function: + * - Executes the NSH logic script + * - Presents a greeting + * - Then provides a prompt then gets and processes the command line. + * - This continues until an error occurs, then the session returns. + * + * Input Parameters: + * pstate - Abstracts the underlying session. + * + * Returned Values: + * EXIT_SUCESS or EXIT_FAILURE is returned. + * + ****************************************************************************/ + +int nsh_session(FAR struct console_stdio_s *pstate) +{ + int ret; + + DEBUGASSERT(pstate); + + /* Present a greeting */ + + fputs(g_nshgreeting, pstate->cn_outstream); + fflush(pstate->cn_outstream); + + /* Execute the login script */ + +#ifdef CONFIG_NSH_ROMFSRC + (void)nsh_loginscript(&pstate->cn_vtbl); +#endif + + /* Then enter the command line parsing loop */ + + for (;;) + { + /* For the case of debugging the USB console... dump collected USB trace data */ + +#ifdef CONFIG_NSH_USBDEV_TRACE + nsh_usbtrace(); +#endif + + /* Display the prompt string */ + + fputs(g_nshprompt, pstate->cn_outstream); + fflush(pstate->cn_outstream); + + /* Get the next line of input */ + + ret = readline(pstate->cn_line, CONFIG_NSH_LINELEN, + INSTREAM(pstate), OUTSTREAM(pstate)); + if (ret > 0) + { + /* Parse process the command */ + + (void)nsh_parse(&pstate->cn_vtbl, pstate->cn_line); + fflush(pstate->cn_outstream); + } + + /* Readline normally returns the number of characters read, + * but will return 0 on end of file or a negative value + * if an error occurs. Either will cause the session to + * terminate. + */ + + else + { + fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_session", + "readline", NSH_ERRNO_OF(-ret)); + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + } + } + + /* We do not get here, but this is necessary to keep some compilers happy. + * But others will complain that this code is not reachable. + */ + + return EXIT_SUCCESS; +} diff --git a/apps/nshlib/nsh_telnetd.c b/apps/nshlib/nsh_telnetd.c index 478935d7f..76ed81086 100644 --- a/apps/nshlib/nsh_telnetd.c +++ b/apps/nshlib/nsh_telnetd.c @@ -1,7 +1,7 @@ /**************************************************************************** * apps/nshlib/nsh_telnetd.c * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -198,15 +198,29 @@ int nsh_telnetmain(int argc, char *argv[]) } #endif /* CONFIG_NSH_TELNET_LOGIN */ + /* The following logic mostly the same as the login in nsh_session.c. It + * differs only in that gets() is called to get the command instead of + * readline(). + */ + /* Present the NSH greeting */ fputs(g_nshgreeting, pstate->cn_outstream); fflush(pstate->cn_outstream); - /* Execute the startup script */ + /* Execute the startup script. If standard console is also defined, then + * we will not bother with the initscript here (although it is safe to + * call nshinitscript multiple times). + */ #if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_CONSOLE) - (void)nsh_script(&pstate->cn_vtbl, "init", NSH_INITPATH); + (void)nsh_initscript(&pstate->cn_vtbl); +#endif + + /* Execute the login script */ + +#ifdef CONFIG_NSH_ROMFSRC + (void)nsh_loginscript(&pstate->cn_vtbl); #endif /* Then enter the command line parsing loop */ @@ -261,8 +275,8 @@ int nsh_telnetmain(int argc, char *argv[]) * NuttX configuration setting. * * Returned Values: - * Zero if the Telnet daemon was successfully started. A negated errno - * value will be returned on failure. + * The task ID of the Telnet daemon was successfully started. A negated + * errno value will be returned on failure. * ****************************************************************************/ @@ -271,6 +285,15 @@ int nsh_telnetstart(void) struct telnetd_config_s config; int ret; + /* Initialize any USB tracing options that were requested. If standard + * console is also defined, then we will defer this step to the standard + * console. + */ + +#if defined(CONFIG_NSH_USBDEV_TRACE) && !defined(CONFIG_NSH_CONSOLE) + usbtrace_enable(TRACE_BITSET); +#endif + /* Configure the telnet daemon */ config.d_port = HTONS(CONFIG_NSH_TELNETD_PORT); diff --git a/apps/nshlib/nsh_usbdev.c b/apps/nshlib/nsh_usbdev.c index 2064cbd84..193fe0d79 100644 --- a/apps/nshlib/nsh_usbdev.c +++ b/apps/nshlib/nsh_usbdev.c @@ -1,7 +1,7 @@ /**************************************************************************** * apps/nshlib/nsh_usbdev.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -55,11 +55,10 @@ #endif #include "nsh.h" - -#ifdef CONFIG_USBDEV +#include "nsh_console.h" /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /* Output USB trace data to the console device using printf() unless (1) * debug is enabled, then we want to keep the trace output in sync with the @@ -98,6 +97,14 @@ * Name: nsh_tracecallback ****************************************************************************/ +/**************************************************************************** + * Name: nsh_tracecallback + * + * Description: + * This is part of the USB trace logic + * + ****************************************************************************/ + #ifdef CONFIG_NSH_USBDEV_TRACE static int nsh_tracecallback(struct usbtrace_s *trace, void *arg) { @@ -107,27 +114,96 @@ static int nsh_tracecallback(struct usbtrace_s *trace, void *arg) #endif /**************************************************************************** - * Public Functions + * Name: nsh_configstdio + * + * Description: + * Configure standard I/O + * + ****************************************************************************/ + +#ifdef HAVE_USB_CONSOLE +static void nsh_configstdio(int fd) +{ + /* Make sure the stdin, stdout, and stderr are closed */ + + (void)fclose(stdin); + (void)fclose(stdout); + (void)fclose(stderr); + + /* Dup the fd to create standard fd 0-2 */ + + (void)dup2(fd, 0); + (void)dup2(fd, 1); + (void)dup2(fd, 2); + + /* fdopen to get the stdin, stdout and stderr streams. The following logic depends + * on the fact that the library layer will allocate FILEs in order. And since + * we closed stdin, stdout, and stderr above, that is what we should get. + * + * fd = 0 is stdin (read-only) + * fd = 1 is stdout (write-only, append) + * fd = 2 is stderr (write-only, append) + */ + + (void)fdopen(0, "r"); + (void)fdopen(1, "a"); + (void)fdopen(2, "a"); +} +#endif + +/**************************************************************************** + * Name: nsh_nullstdio + * + * Description: + * Use /dev/null for standard I/O + * ****************************************************************************/ +#ifdef HAVE_USB_CONSOLE +static int nsh_nullstdio(void) +{ + int fd; + + /* Open /dev/null for read/write access */ + + fd = open("/dev/null", O_RDWR); + if (fd >= 0) + { + /* Configure standard I/O to use /dev/null */ + + nsh_configstdio(fd); + + /* We can close the original file descriptor now (unless it was one of + * 0-2) + */ + + if (fd > 2) + { + close(fd); + } + + return OK; + } + + return fd; +} +#endif + /**************************************************************************** - * Name: nsh_usbconsole + * Name: nsh_waitusbready + * + * Description: + * Wait for the USB console device to be ready + * ****************************************************************************/ #ifdef HAVE_USB_CONSOLE -int nsh_usbconsole(void) +static int nsh_waitusbready(void) { char inch; ssize_t nbytes; int nlc; int fd; - int ret; - - /* Initialize any USB tracing options that were requested */ - -#ifdef CONFIG_NSH_USBDEV_TRACE - usbtrace_enable(TRACE_BITSET); -#endif /* Don't start the NSH console until the console device is ready. Chances * are, we get here with no functional console. The USB console will not @@ -135,17 +211,6 @@ int nsh_usbconsole(void) * host-side application opens the connection. */ - /* Initialize the USB serial driver */ - -#if defined(CONFIG_PL2303) || defined(CONFIG_CDCACM) -#ifdef CONFIG_CDCACM - ret = cdcacm_initialize(CONFIG_NSH_USBDEV_MINOR, NULL); -#else - ret = usbdev_serialinitialize(CONFIG_NSH_USBDEV_MINOR); -#endif - DEBUGASSERT(ret == OK); -#endif - /* Open the USB serial device for read/write access */ do @@ -199,17 +264,9 @@ int nsh_usbconsole(void) } while (nlc < 3); - /* Make sure the stdin, stdout, and stderr are closed */ - - (void)fclose(stdin); - (void)fclose(stdout); - (void)fclose(stderr); - - /* Dup the fd to create standard fd 0-2 */ + /* Configure standard I/O */ - (void)dup2(fd, 0); - (void)dup2(fd, 1); - (void)dup2(fd, 2); + nsh_configstdio(fd); /* We can close the original file descriptor now (unless it was one of 0-2) */ @@ -218,33 +275,117 @@ int nsh_usbconsole(void) close(fd); } - /* fdopen to get the stdin, stdout and stderr streams. The following logic depends - * on the fact that the library layer will allocate FILEs in order. And since - * we closed stdin, stdout, and stderr above, that is what we should get. - * - * fd = 0 is stdin (read-only) - * fd = 1 is stdout (write-only, append) - * fd = 2 is stderr (write-only, append) - */ - - (void)fdopen(0, "r"); - (void)fdopen(1, "a"); - (void)fdopen(2, "a"); - return OK; } +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nsh_consolemain (USB console version) + * + * Description: + * This interfaces maybe to called or started with task_start to start a + * single an NSH instance that operates on stdin and stdout. This + * function does not return. + * + * This function handles generic /dev/console character devices, or + * special USB console devices. The USB console requires some special + * operations to handle the cases where the session is lost when the + * USB device is unplugged and restarted when the USB device is plugged + * in again. + * + * Input Parameters: + * Standard task start-up arguments. These are not used. argc may be + * zero and argv may be NULL. + * + * Returned Values: + * This function does not return nor does it ever exit (unless the user + * executes the NSH exit command). + * + ****************************************************************************/ + +#ifdef HAVE_USB_CONSOLE +int nsh_consolemain(int argc, char *argv[]) +{ + FAR struct console_stdio_s *pstate = nsh_newconsole(); + int ret; -#endif /* HAVE_USB_CONSOLE */ + DEBUGASSERT(pstate); + + /* Initialize any USB tracing options that were requested */ + +#ifdef CONFIG_NSH_USBDEV_TRACE + usbtrace_enable(TRACE_BITSET); +#endif + + /* Initialize the USB serial driver */ + +#if defined(CONFIG_PL2303) || defined(CONFIG_CDCACM) +#ifdef CONFIG_CDCACM + ret = cdcacm_initialize(CONFIG_NSH_USBDEV_MINOR, NULL); +#else + ret = usbdev_serialinitialize(CONFIG_NSH_USBDEV_MINOR); +#endif + DEBUGASSERT(ret == OK); +#endif + + /* Configure to use /dev/null if we do not have a valid console. */ + +#ifndef CONFIG_DEV_CONSOLE + (void)nsh_nullstdio(); +#endif + + /* Execute the one-time start-up script (output may go to /dev/null) */ + +#ifdef CONFIG_NSH_ROMFSETC + (void)nsh_initscript(&pstate->cn_vtbl); +#endif + + /* Now loop, executing creating a session for each USB connection */ + + for (;;) + { + /* Wait for the USB to be connected to the host and switch + * standard I/O to the USB serial device. + */ + + ret = nsh_waitusbready(); + DEBUGASSERT(ret == OK); + + /* Execute the session */ + + (void)nsh_session(pstate); + + /* Switch to /dev/null because we probably no longer have a + * valid console device. + */ + + (void)nsh_nullstdio(); + } +} +#endif /**************************************************************************** * Name: nsh_usbtrace + * + * Description: + * The function is called from the nsh_session() to dump USB data to the + * SYSLOG device. + * + * Input Parameters: + * None + * + * Returned Values: + * None + * ****************************************************************************/ -#if defined(CONFIG_NSH_USBDEV_TRACE) && defined(HAVE_USB_CONSOLE) +#ifdef CONFIG_NSH_USBDEV_TRACE void nsh_usbtrace(void) { (void)usbtrace_enumerate(nsh_tracecallback, NULL); } #endif - -#endif /* CONFIG_USBDEV */ -- cgit v1.2.3 From 2ee8d521599a3b15275bffc9a27730f083898290 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 30 Jan 2013 13:24:45 +0000 Subject: LPC1788 updated from Rommel Marcelo git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5583 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/src/lpc17xx/chip/lpc178x_iocon.h | 217 +++++++++++++++++++++++- nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c | 168 +++++++++++++++++- nuttx/arch/arm/src/lpc17xx/lpc17_gpio.h | 38 +++-- 3 files changed, 389 insertions(+), 34 deletions(-) diff --git a/nuttx/arch/arm/src/lpc17xx/chip/lpc178x_iocon.h b/nuttx/arch/arm/src/lpc17xx/chip/lpc178x_iocon.h index b8c9ee480..a3c247caf 100755 --- a/nuttx/arch/arm/src/lpc17xx/chip/lpc178x_iocon.h +++ b/nuttx/arch/arm/src/lpc17xx/chip/lpc178x_iocon.h @@ -52,13 +52,7 @@ /* Register offsets *****************************************************************/ -#define LPC17_IOCON_P0_OFFSET (LPC17_IOCON_BASE+0x0000) -#define LPC17_IOCON_P1_OFFSET (LPC17_IOCON_BASE+0x0080) -#define LPC17_IOCON_P2_OFFSET (LPC17_IOCON_BASE+0x0100) -#define LPC17_IOCON_P3_OFFSET (LPC17_IOCON_BASE+0x0180) -#define LPC17_IOCON_P4_OFFSET (LPC17_IOCON_BASE+0x0200) -#define LPC17_IOCON_P5_OFFSET (LPC17_IOCON_BASE+0x0280) - +#define LPC17_IOCON_PP_OFFSET(p) ((p) << 2) #define LPC17_IOCON_PP0_OFFSET (0x0000) /* IOCON Port(n) register 0 */ #define LPC17_IOCON_PP1_OFFSET (0x0004) /* IOCON Port(n) register 1 */ #define LPC17_IOCON_PP2_OFFSET (0x0008) /* IOCON Port(n) register 2 */ @@ -94,10 +88,215 @@ /* Register addresses ***************************************************************/ -//~ #define LPC17_IOCON_PP1(portoffset) (portoffset+LPC17_IOCON_P0_OFFSET) +#define LPC17_IOCON_P_BASE(b) (LPC17_IOCON_BASE + ((b) << 7)) +#define LPC17_IOCON_P0_BASE (LPC17_IOCON_BASE + 0x0000) +#define LPC17_IOCON_P1_BASE (LPC17_IOCON_BASE + 0x0080) +#define LPC17_IOCON_P2_BASE (LPC17_IOCON_BASE + 0x0100) +#define LPC17_IOCON_P3_BASE (LPC17_IOCON_BASE + 0x0180) +#define LPC17_IOCON_P4_BASE (LPC17_IOCON_BASE + 0x0200) +#define LPC17_IOCON_P4_BASE (LPC17_IOCON_BASE + 0x0280) + +#define LPC17_IOCON_P(b,p) (LPC17_IOCON_P_BASE(b) + LPC17_IOCON_PP_OFFSET(p)) + +#define LPC17_IOCON_P0_0 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP0_OFFSET) +#define LPC17_IOCON_P0_1 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP1_OFFSET) +#define LPC17_IOCON_P0_2 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP2_OFFSET) +#define LPC17_IOCON_P0_3 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP3_OFFSET) +#define LPC17_IOCON_P0_4 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP4_OFFSET) +#define LPC17_IOCON_P0_5 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP5_OFFSET) +#define LPC17_IOCON_P0_6 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP6_OFFSET) +#define LPC17_IOCON_P0_7 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP7_OFFSET) +#define LPC17_IOCON_P0_8 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP8_OFFSET) +#define LPC17_IOCON_P0_9 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP9_OFFSET) +#define LPC17_IOCON_P0_10 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP10_OFFSET) +#define LPC17_IOCON_P0_11 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP11_OFFSET) +#define LPC17_IOCON_P0_12 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP12_OFFSET) +#define LPC17_IOCON_P0_13 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP13_OFFSET) +#define LPC17_IOCON_P0_14 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP14_OFFSET) +#define LPC17_IOCON_P0_15 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP15_OFFSET) +#define LPC17_IOCON_P0_16 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP16_OFFSET) +#define LPC17_IOCON_P0_17 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP17_OFFSET) +#define LPC17_IOCON_P0_18 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP18_OFFSET) +#define LPC17_IOCON_P0_19 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP19_OFFSET) +#define LPC17_IOCON_P0_20 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP20_OFFSET) +#define LPC17_IOCON_P0_21 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP21_OFFSET) +#define LPC17_IOCON_P0_22 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP22_OFFSET) +#define LPC17_IOCON_P0_23 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP23_OFFSET) +#define LPC17_IOCON_P0_24 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP24_OFFSET) +#define LPC17_IOCON_P0_25 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP25_OFFSET) +#define LPC17_IOCON_P0_26 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP26_OFFSET) +#define LPC17_IOCON_P0_27 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP27_OFFSET) +#define LPC17_IOCON_P0_28 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP28_OFFSET) +#define LPC17_IOCON_P0_29 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP29_OFFSET) +#define LPC17_IOCON_P0_30 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP30_OFFSET) +#define LPC17_IOCON_P0_31 (LPC17_IOCON_P0_BASE + LPC17_IOCON_PP31_OFFSET) + +#define LPC17_IOCON_P1_0 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP0_OFFSET) +#define LPC17_IOCON_P1_1 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP1_OFFSET) +#define LPC17_IOCON_P1_2 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP2_OFFSET) +#define LPC17_IOCON_P1_3 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP3_OFFSET) +#define LPC17_IOCON_P1_4 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP4_OFFSET) +#define LPC17_IOCON_P1_5 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP5_OFFSET) +#define LPC17_IOCON_P1_6 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP6_OFFSET) +#define LPC17_IOCON_P1_7 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP7_OFFSET) +#define LPC17_IOCON_P1_8 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP8_OFFSET) +#define LPC17_IOCON_P1_9 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP9_OFFSET) +#define LPC17_IOCON_P1_10 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP10_OFFSET) +#define LPC17_IOCON_P1_11 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP11_OFFSET) +#define LPC17_IOCON_P1_12 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP12_OFFSET) +#define LPC17_IOCON_P1_13 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP13_OFFSET) +#define LPC17_IOCON_P1_14 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP14_OFFSET) +#define LPC17_IOCON_P1_15 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP15_OFFSET) +#define LPC17_IOCON_P1_16 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP16_OFFSET) +#define LPC17_IOCON_P1_17 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP17_OFFSET) +#define LPC17_IOCON_P1_18 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP18_OFFSET) +#define LPC17_IOCON_P1_19 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP19_OFFSET) +#define LPC17_IOCON_P1_20 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP20_OFFSET) +#define LPC17_IOCON_P1_21 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP21_OFFSET) +#define LPC17_IOCON_P1_22 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP22_OFFSET) +#define LPC17_IOCON_P1_23 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP23_OFFSET) +#define LPC17_IOCON_P1_24 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP24_OFFSET) +#define LPC17_IOCON_P1_25 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP25_OFFSET) +#define LPC17_IOCON_P1_26 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP26_OFFSET) +#define LPC17_IOCON_P1_27 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP27_OFFSET) +#define LPC17_IOCON_P1_28 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP28_OFFSET) +#define LPC17_IOCON_P1_29 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP29_OFFSET) +#define LPC17_IOCON_P1_30 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP30_OFFSET) +#define LPC17_IOCON_P1_31 (LPC17_IOCON_P1_BASE + LPC17_IOCON_PP31_OFFSET) + +#define LPC17_IOCON_P2_0 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP0_OFFSET) +#define LPC17_IOCON_P2_1 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP1_OFFSET) +#define LPC17_IOCON_P2_2 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP2_OFFSET) +#define LPC17_IOCON_P2_3 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP3_OFFSET) +#define LPC17_IOCON_P2_4 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP4_OFFSET) +#define LPC17_IOCON_P2_5 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP5_OFFSET) +#define LPC17_IOCON_P2_6 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP6_OFFSET) +#define LPC17_IOCON_P2_7 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP7_OFFSET) +#define LPC17_IOCON_P2_8 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP8_OFFSET) +#define LPC17_IOCON_P2_9 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP9_OFFSET) +#define LPC17_IOCON_P2_10 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP10_OFFSET) +#define LPC17_IOCON_P2_11 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP11_OFFSET) +#define LPC17_IOCON_P2_12 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP12_OFFSET) +#define LPC17_IOCON_P2_13 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP13_OFFSET) +#define LPC17_IOCON_P2_14 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP14_OFFSET) +#define LPC17_IOCON_P2_15 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP15_OFFSET) +#define LPC17_IOCON_P2_16 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP16_OFFSET) +#define LPC17_IOCON_P2_17 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP17_OFFSET) +#define LPC17_IOCON_P2_18 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP18_OFFSET) +#define LPC17_IOCON_P2_19 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP19_OFFSET) +#define LPC17_IOCON_P2_20 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP20_OFFSET) +#define LPC17_IOCON_P2_21 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP21_OFFSET) +#define LPC17_IOCON_P2_22 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP22_OFFSET) +#define LPC17_IOCON_P2_23 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP23_OFFSET) +#define LPC17_IOCON_P2_24 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP24_OFFSET) +#define LPC17_IOCON_P2_25 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP25_OFFSET) +#define LPC17_IOCON_P2_26 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP26_OFFSET) +#define LPC17_IOCON_P2_27 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP27_OFFSET) +#define LPC17_IOCON_P2_28 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP28_OFFSET) +#define LPC17_IOCON_P2_29 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP29_OFFSET) +#define LPC17_IOCON_P2_30 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP30_OFFSET) +#define LPC17_IOCON_P2_31 (LPC17_IOCON_P2_BASE + LPC17_IOCON_PP31_OFFSET) + +#define LPC17_IOCON_P3_0 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP0_OFFSET) +#define LPC17_IOCON_P3_1 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP1_OFFSET) +#define LPC17_IOCON_P3_2 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP2_OFFSET) +#define LPC17_IOCON_P3_3 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP3_OFFSET) +#define LPC17_IOCON_P3_4 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP4_OFFSET) +#define LPC17_IOCON_P3_5 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP5_OFFSET) +#define LPC17_IOCON_P3_6 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP6_OFFSET) +#define LPC17_IOCON_P3_7 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP7_OFFSET) +#define LPC17_IOCON_P3_8 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP8_OFFSET) +#define LPC17_IOCON_P3_9 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP9_OFFSET) +#define LPC17_IOCON_P3_10 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP10_OFFSET) +#define LPC17_IOCON_P3_11 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP11_OFFSET) +#define LPC17_IOCON_P3_12 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP12_OFFSET) +#define LPC17_IOCON_P3_13 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP13_OFFSET) +#define LPC17_IOCON_P3_14 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP14_OFFSET) +#define LPC17_IOCON_P3_15 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP15_OFFSET) +#define LPC17_IOCON_P3_16 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP16_OFFSET) +#define LPC17_IOCON_P3_17 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP17_OFFSET) +#define LPC17_IOCON_P3_18 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP18_OFFSET) +#define LPC17_IOCON_P3_19 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP19_OFFSET) +#define LPC17_IOCON_P3_20 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP20_OFFSET) +#define LPC17_IOCON_P3_21 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP21_OFFSET) +#define LPC17_IOCON_P3_22 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP22_OFFSET) +#define LPC17_IOCON_P3_23 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP23_OFFSET) +#define LPC17_IOCON_P3_24 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP24_OFFSET) +#define LPC17_IOCON_P3_25 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP25_OFFSET) +#define LPC17_IOCON_P3_26 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP26_OFFSET) +#define LPC17_IOCON_P3_27 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP27_OFFSET) +#define LPC17_IOCON_P3_28 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP28_OFFSET) +#define LPC17_IOCON_P3_29 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP29_OFFSET) +#define LPC17_IOCON_P3_30 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP30_OFFSET) +#define LPC17_IOCON_P3_31 (LPC17_IOCON_P3_BASE + LPC17_IOCON_PP31_OFFSET) + +#define LPC17_IOCON_P4_0 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP0_OFFSET) +#define LPC17_IOCON_P4_1 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP1_OFFSET) +#define LPC17_IOCON_P4_2 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP2_OFFSET) +#define LPC17_IOCON_P4_3 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP3_OFFSET) +#define LPC17_IOCON_P4_4 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP4_OFFSET) +#define LPC17_IOCON_P4_5 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP5_OFFSET) +#define LPC17_IOCON_P4_6 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP6_OFFSET) +#define LPC17_IOCON_P4_7 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP7_OFFSET) +#define LPC17_IOCON_P4_8 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP8_OFFSET) +#define LPC17_IOCON_P4_9 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP9_OFFSET) +#define LPC17_IOCON_P4_10 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP10_OFFSET) +#define LPC17_IOCON_P4_11 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP11_OFFSET) +#define LPC17_IOCON_P4_12 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP12_OFFSET) +#define LPC17_IOCON_P4_13 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP13_OFFSET) +#define LPC17_IOCON_P4_14 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP14_OFFSET) +#define LPC17_IOCON_P4_15 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP15_OFFSET) +#define LPC17_IOCON_P4_16 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP16_OFFSET) +#define LPC17_IOCON_P4_17 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP17_OFFSET) +#define LPC17_IOCON_P4_18 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP18_OFFSET) +#define LPC17_IOCON_P4_19 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP19_OFFSET) +#define LPC17_IOCON_P4_20 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP20_OFFSET) +#define LPC17_IOCON_P4_21 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP21_OFFSET) +#define LPC17_IOCON_P4_22 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP22_OFFSET) +#define LPC17_IOCON_P4_23 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP23_OFFSET) +#define LPC17_IOCON_P4_24 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP24_OFFSET) +#define LPC17_IOCON_P4_25 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP25_OFFSET) +#define LPC17_IOCON_P4_26 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP26_OFFSET) +#define LPC17_IOCON_P4_27 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP27_OFFSET) +#define LPC17_IOCON_P4_28 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP28_OFFSET) +#define LPC17_IOCON_P4_29 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP29_OFFSET) +#define LPC17_IOCON_P4_30 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP30_OFFSET) +#define LPC17_IOCON_P4_31 (LPC17_IOCON_P4_BASE + LPC17_IOCON_PP31_OFFSET) + +#define LPC17_IOCON_P5_0 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP0_OFFSET) +#define LPC17_IOCON_P5_1 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP1_OFFSET) +#define LPC17_IOCON_P5_2 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP2_OFFSET) +#define LPC17_IOCON_P5_3 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP3_OFFSET) +#define LPC17_IOCON_P5_4 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP4_OFFSET) +#define LPC17_IOCON_P5_5 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP5_OFFSET) +#define LPC17_IOCON_P5_6 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP6_OFFSET) +#define LPC17_IOCON_P5_7 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP7_OFFSET) +#define LPC17_IOCON_P5_8 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP8_OFFSET) +#define LPC17_IOCON_P5_9 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP9_OFFSET) +#define LPC17_IOCON_P5_10 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP10_OFFSET) +#define LPC17_IOCON_P5_11 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP11_OFFSET) +#define LPC17_IOCON_P5_12 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP12_OFFSET) +#define LPC17_IOCON_P5_13 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP13_OFFSET) +#define LPC17_IOCON_P5_14 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP14_OFFSET) +#define LPC17_IOCON_P5_15 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP15_OFFSET) +#define LPC17_IOCON_P5_16 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP16_OFFSET) +#define LPC17_IOCON_P5_17 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP17_OFFSET) +#define LPC17_IOCON_P5_18 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP18_OFFSET) +#define LPC17_IOCON_P5_19 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP19_OFFSET) +#define LPC17_IOCON_P5_20 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP20_OFFSET) +#define LPC17_IOCON_P5_21 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP21_OFFSET) +#define LPC17_IOCON_P5_22 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP22_OFFSET) +#define LPC17_IOCON_P5_23 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP23_OFFSET) +#define LPC17_IOCON_P5_24 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP24_OFFSET) +#define LPC17_IOCON_P5_25 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP25_OFFSET) +#define LPC17_IOCON_P5_26 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP26_OFFSET) +#define LPC17_IOCON_P5_27 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP27_OFFSET) +#define LPC17_IOCON_P5_28 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP28_OFFSET) +#define LPC17_IOCON_P5_29 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP29_OFFSET) +#define LPC17_IOCON_P5_30 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP30_OFFSET) +#define LPC17_IOCON_P5_31 (LPC17_IOCON_P5_BASE + LPC17_IOCON_PP31_OFFSET) /* Register bit definitions *********************************************************/ -/* Pin Function Select register 0 (PINSEL0: 0x4002c000) */ /* IOCON pin function select */ #define IOCON_FUNC_GPIO (0) diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c b/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c index 73939a389..ece6adc5f 100644 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c @@ -93,37 +93,101 @@ const uint32_t g_fiobase[GPIO_NPORTS] = LPC17_FIO2_BASE, LPC17_FIO3_BASE, LPC17_FIO4_BASE +#if GPIO_NPORTS > 5 + , LPC17_FIO5_BASE +#endif +}; + +#ifdef LPC178X +/* IOCON register base addresses */ + +const uint32_t g_ioconport[GPIO_NPORTS] = +{ + LPC17_IOCON_P0, + LPC17_IOCON_P1, + LPC17_IOCON_P2, + LPC17_IOCON_P3, + LPC17_IOCON_P4, + LPC17_IOCON_P5 +} + +/* Register offsets */ + +const uint32_t g_ioconpin[32] = +{ + LPC17_IOCON_PP0_OFFSET, + LPC17_IOCON_PP1_OFFSET, + LPC17_IOCON_PP2_OFFSET, + LPC17_IOCON_PP3_OFFSET, + LPC17_IOCON_PP4_OFFSET, + LPC17_IOCON_PP5_OFFSET, + LPC17_IOCON_PP6_OFFSET, + LPC17_IOCON_PP7_OFFSET, + LPC17_IOCON_PP8_OFFSET, + LPC17_IOCON_PP9_OFFSET, + LPC17_IOCON_PP10_OFFSET, + LPC17_IOCON_PP11_OFFSET, + LPC17_IOCON_PP12_OFFSET, + LPC17_IOCON_PP13_OFFSET, + LPC17_IOCON_PP14_OFFSET, + LPC17_IOCON_PP15_OFFSET, + LPC17_IOCON_PP16_OFFSET, + LPC17_IOCON_PP17_OFFSET, + LPC17_IOCON_PP18_OFFSET, + LPC17_IOCON_PP19_OFFSET, + LPC17_IOCON_PP20_OFFSET, + LPC17_IOCON_PP21_OFFSET, + LPC17_IOCON_PP22_OFFSET, + LPC17_IOCON_PP23_OFFSET, + LPC17_IOCON_PP24_OFFSET, + LPC17_IOCON_PP25_OFFSET, + LPC17_IOCON_PP26_OFFSET, + LPC17_IOCON_PP27_OFFSET, + LPC17_IOCON_PP28_OFFSET, + LPC17_IOCON_PP29_OFFSET, + LPC17_IOCON_PP30_OFFSET, + LPC17_IOCON_PP31_OFFSET }; +#endif /* Port 0 and Port 2 can provide a single interrupt for any combination of - * port pins + * port pins */ -const uint32_t g_intbase[GPIO_NPORTS] = +const uint32_t g_intbase[GPIO_NPORTS] = { LPC17_GPIOINT0_BASE, 0, LPC17_GPIOINT2_BASE, 0, 0 +#if GPIO_NPORTS > 5 + , 0 +#endif }; -const uint32_t g_lopinsel[GPIO_NPORTS] = +const uint32_t g_lopinsel[GPIO_NPORTS] = { LPC17_PINCONN_PINSEL0, LPC17_PINCONN_PINSEL2, LPC17_PINCONN_PINSEL4, 0, 0 +#if GPIO_NPORTS > 5 + , 0 +#endif }; -const uint32_t g_hipinsel[GPIO_NPORTS] = +const uint32_t g_hipinsel[GPIO_NPORTS] = { LPC17_PINCONN_PINSEL1, LPC17_PINCONN_PINSEL3, 0, LPC17_PINCONN_PINSEL7, LPC17_PINCONN_PINSEL9 +#if GPIO_NPORTS > 5 + , 0 +#endif }; const uint32_t g_lopinmode[GPIO_NPORTS] = @@ -133,6 +197,9 @@ const uint32_t g_lopinmode[GPIO_NPORTS] = LPC17_PINCONN_PINMODE4, 0, 0 +#if GPIO_NPORTS > 5 + , 0 +#endif }; const uint32_t g_hipinmode[GPIO_NPORTS] = @@ -142,6 +209,9 @@ const uint32_t g_hipinmode[GPIO_NPORTS] = 0, LPC17_PINCONN_PINMODE7, LPC17_PINCONN_PINMODE9 +#if GPIO_NPORTS > 5 + , 0 +#endif }; const uint32_t g_odmode[GPIO_NPORTS] = @@ -151,6 +221,9 @@ const uint32_t g_odmode[GPIO_NPORTS] = LPC17_PINCONN_ODMODE2, LPC17_PINCONN_ODMODE3, LPC17_PINCONN_ODMODE4 +#if GPIO_NPORTS > 5 + , 0 +#endif }; /**************************************************************************** @@ -347,6 +420,27 @@ static void lpc17_clropendrain(unsigned int port, unsigned int pin) putreg32(regval, regaddr); } +/**************************************************************************** + * Name: lpc17_configiocon + * + * Description: + * Set the LPC178x IOCON register + ****************************************************************************/ + +#ifdef LPC178x +static int lpc17_configiocon(unsigned int port, unsigned int pin, + unsigned int value) +{ + uint32_t regaddr; + uint32_t regval; + + regaddr = (g_ioconbase[port] + g_ioconpin[pin]); + regval = getreg32(regaddr); + regval &= value; + putreg32(regval, regaddr); +} +#endif + /**************************************************************************** * Name: lpc17_configinput * @@ -361,9 +455,9 @@ static inline int lpc17_configinput(lpc17_pinset_t cfgset, unsigned int port, un uint32_t fiobase; uint32_t intbase; uint32_t pinmask = (1 << pin); - + /* Set up FIO registers */ - + fiobase = g_fiobase[port]; /* Set as input */ @@ -378,13 +472,13 @@ static inline int lpc17_configinput(lpc17_pinset_t cfgset, unsigned int port, un if (intbase != 0) { /* Disable any rising edge interrupts */ - + regval = getreg32(intbase + LPC17_GPIOINT_INTENR_OFFSET); regval &= ~pinmask; putreg32(regval, intbase + LPC17_GPIOINT_INTENR_OFFSET); /* Disable any falling edge interrupts */ - + regval = getreg32(intbase + LPC17_GPIOINT_INTENF_OFFSET); regval &= ~pinmask; putreg32(regval, intbase + LPC17_GPIOINT_INTENF_OFFSET); @@ -396,6 +490,8 @@ static inline int lpc17_configinput(lpc17_pinset_t cfgset, unsigned int port, un #endif } +#ifdef defined(LPC176x) + /* Set up PINSEL registers */ /* Configure as GPIO */ @@ -408,6 +504,40 @@ static inline int lpc17_configinput(lpc17_pinset_t cfgset, unsigned int port, un /* Open drain only applies to outputs */ lpc17_clropendrain(port, pin); + +#elif defined(LPC178x) + + uint32_t value; + + /* Configure as GPIO */ + + if ((cfgset & GPIO_FILTER) != 0) + { + value = (IOCON_FUNC_GPIO | ~GPIO_IOCON_TYPE_W_MASK); + } + else + { + value = (IOCON_FUNC_GPIO | ~GPIO_IOCON_TYPE_D_MASK); + } + + /* Set pull-up mode */ + + value |= ((cfgset & GPIO_PUMODE_MASK) >> GPIO_PINMODE_SHIFT); + + /* Clear open drain: open drain only applies to outputs */ + + value &= ~IOCON_OD_MASK ; + + /* Clear input hysteresis, invertion, slew */ + + value &= ~(IOCON_HYS_MASK | IOCON_INV_MASK | IOCON_SLEW_MASK); + + /* Set IOCON register */ + + lpc17_configiocon(port, pin, value); + +#endif + return OK; } @@ -541,7 +671,7 @@ int lpc17_configgpio(lpc17_pinset_t cfgset) unsigned int port; unsigned int pin; int ret = -EINVAL; - + /* Verify that this hardware supports the select GPIO port */ port = (cfgset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT; @@ -581,6 +711,26 @@ int lpc17_configgpio(lpc17_pinset_t cfgset) ret = lpc17_configalternate(cfgset, port, pin, PINCONN_PINSEL_ALT3); break; +#ifdef LPC178x + + case GPIO_ALT4: /* Alternate function 4 */ + ret = ; + break; + + case GPIO_ALT5: /* Alternate function 5 */ + ret = ; + break; + + case GPIO_ALT6: /* Alternate function 6 */ + ret = ; + break; + + case GPIO_ALT7: /* Alternate function 7 */ + ret = ; + break; + +#endif + default: break; } diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.h b/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.h index 993369aa2..62bf2d018 100644 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.h +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.h @@ -187,19 +187,20 @@ */ #define GPIO_IOCON_TYPE_D_MASK (0x0000067f) /* All port except where ADC/DAC, USB, I2C is present */ -#define GPIO_IOCON_TYPE_A_MASK (0x000105df) /* USB/ADC/DAC P0:12 to 13, P0:23 to 26, P1:30 to 31 */ +#define GPIO_IOCON_TYPE_A_MASK (0x000105df) /* USB/ADC/DAC P0:12-13, P0:23-26, P1:30-31 */ #define GPIO_IOCON_TYPE_U_MASK (0x00000007) /* USB P0:29 to 31 */ -#define GPIO_IOCON_TYPE_I_MASK (0x00000347) /* I2C/USB P0:27 to 28, P5:2 to 3 */ -#define GPIO_IOCON_TYPE_W_MASK (0x000007ff) /* I2S P0:7 to 9 */ - -# define GPIO_HYS (1 << 16) /* Bit 16: HYSTERESIS: 0-Disable, 1-Enabled */ -# define GPIO_INV (1 << 17) /* Bit 17: Input: 0-Not Inverted, 1-Inverted */ -# define GPIO_SLEW (1 << 18) /* Bit 18: Rate Control: 0-Standard mode, 1-Fast mode */ -# define GPIO_ADMODE (1 << 19) /* Bit 19: A/D Modes: 0-Analog, 1-Digital */ -# define GPIO_FILTER (1 << 20) /* Bit 20: Filter: 0-Off, 1-ON */ -# define GPIO_DACEN (1 << 21) /* Bit 21: DAC: 0-Disabled, 1-Enabled, P0:26 only */ -# define GPIO_I2CHS (1 << 22) /* Bit 22: Filter and Rate Control: 0-Enabled, 1-Disabled */ -# define GPIO_HIDRIVE (1 << 23) /* Bit 23: Current Sink: 0-4mA, 1-20mA P5:2 and P5:3 only,*/ +#define GPIO_IOCON_TYPE_I_MASK (0x00000347) /* I2C/USB P0:27-28, P5:2-3 */ +#define GPIO_IOCON_TYPE_W_MASK (0x000007ff) /* I2S P0:7-9 */ + +#define GPIO_IOCON_MASK (0x00FF0000) +# define GPIO_HYS (1 << 16) /* Bit 16: HYSTERESIS: 0-Disable, 1-Enabled */ +# define GPIO_INV (1 << 17) /* Bit 17: Input: 0-Not Inverted, 1-Inverted */ +# define GPIO_SLEW (1 << 18) /* Bit 18: Rate Control: 0-Standard mode, 1-Fast mode */ +# define GPIO_ADMODE (1 << 19) /* Bit 19: A/D Modes: 0-Analog, 1-Digital */ +# define GPIO_FILTER (1 << 20) /* Bit 20: Filter: 0-Off, 1-ON */ +# define GPIO_DACEN (1 << 21) /* Bit 21: DAC: 0-Disabled, 1-Enabled, P0:26 only */ +# define GPIO_I2CHS (1 << 22) /* Bit 22: Filter and Rate Control: 0-Enabled, 1-Disabled */ +# define GPIO_HIDRIVE (1 << 23) /* Bit 23: Current Sink: 0-4mA, 1-20mA P5:2 and P5:3 only,*/ /* Pin Function bits: FFFF * Only meaningful when the GPIO function is GPIO_PIN @@ -239,12 +240,13 @@ /* Pin Mode: MM */ +#define GPIO_PINMODE_SHIFT (7) #define GPIO_PUMODE_SHIFT (10) /* Bits 10-11: Pin pull-up mode */ #define GPIO_PUMODE_MASK (3 << GPIO_PUMODE_SHIFT) -# define GPIO_PULLUP (0 << GPIO_PUMODE_SHIFT) /* Pull-up resistor enabled */ -# define GPIO_REPEATER (1 << GPIO_PUMODE_SHIFT) /* Repeater mode enabled */ -# define GPIO_FLOAT (2 << GPIO_PUMODE_SHIFT) /* Neither pull-up nor -down */ -# define GPIO_PULLDN (3 << GPIO_PUMODE_SHIFT) /* Pull-down resistor enabled */ +# define GPIO_FLOAT (0 << GPIO_PUMODE_SHIFT) /* Pull-up resistor enabled */ +# define GPIO_PULLDN (1 << GPIO_PUMODE_SHIFT) /* Repeater mode enabled */ +# define GPIO_PULLUP (2 << GPIO_PUMODE_SHIFT) /* Neither pull-up nor -down */ +# define GPIO_REPEATER (3 << GPIO_PUMODE_SHIFT) /* Pull-down resistor enabled */ /* Open drain: O */ @@ -350,6 +352,10 @@ EXTERN const uint32_t g_hipinsel[GPIO_NPORTS]; EXTERN const uint32_t g_lopinmode[GPIO_NPORTS]; EXTERN const uint32_t g_hipinmode[GPIO_NPORTS]; EXTERN const uint32_t g_odmode[GPIO_NPORTS]; +#ifdef LPC178x +EXTERN const uint32_t g_ioconport[GPIO_NPORTS]; +EXTERN const uint32_t g_ioconpin[32]; +#endif /**************************************************************************** * Public Functions -- cgit v1.2.3 From 37d3293690108d09bf24ac1a5fb2e77cdf5ef89c Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 30 Jan 2013 14:42:10 +0000 Subject: Remove the g_iocon[] arrary git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5584 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/src/lpc17xx/chip/lpc178x_iocon.h | 4 +-- nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c | 40 +------------------------ nuttx/arch/arm/src/lpc17xx/lpc17_gpio.h | 1 - 3 files changed, 3 insertions(+), 42 deletions(-) diff --git a/nuttx/arch/arm/src/lpc17xx/chip/lpc178x_iocon.h b/nuttx/arch/arm/src/lpc17xx/chip/lpc178x_iocon.h index a3c247caf..ca4ab6b1d 100755 --- a/nuttx/arch/arm/src/lpc17xx/chip/lpc178x_iocon.h +++ b/nuttx/arch/arm/src/lpc17xx/chip/lpc178x_iocon.h @@ -52,7 +52,7 @@ /* Register offsets *****************************************************************/ -#define LPC17_IOCON_PP_OFFSET(p) ((p) << 2) +#define LPC17_IOCON_PP_OFFSET(p) ((unsigned int)(p) << 2) #define LPC17_IOCON_PP0_OFFSET (0x0000) /* IOCON Port(n) register 0 */ #define LPC17_IOCON_PP1_OFFSET (0x0004) /* IOCON Port(n) register 1 */ #define LPC17_IOCON_PP2_OFFSET (0x0008) /* IOCON Port(n) register 2 */ @@ -88,7 +88,7 @@ /* Register addresses ***************************************************************/ -#define LPC17_IOCON_P_BASE(b) (LPC17_IOCON_BASE + ((b) << 7)) +#define LPC17_IOCON_P_BASE(b) (LPC17_IOCON_BASE + (unsigned int(b) << 7)) #define LPC17_IOCON_P0_BASE (LPC17_IOCON_BASE + 0x0000) #define LPC17_IOCON_P1_BASE (LPC17_IOCON_BASE + 0x0080) #define LPC17_IOCON_P2_BASE (LPC17_IOCON_BASE + 0x0100) diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c b/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c index ece6adc5f..e3085ff78 100644 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c @@ -110,44 +110,6 @@ const uint32_t g_ioconport[GPIO_NPORTS] = LPC17_IOCON_P4, LPC17_IOCON_P5 } - -/* Register offsets */ - -const uint32_t g_ioconpin[32] = -{ - LPC17_IOCON_PP0_OFFSET, - LPC17_IOCON_PP1_OFFSET, - LPC17_IOCON_PP2_OFFSET, - LPC17_IOCON_PP3_OFFSET, - LPC17_IOCON_PP4_OFFSET, - LPC17_IOCON_PP5_OFFSET, - LPC17_IOCON_PP6_OFFSET, - LPC17_IOCON_PP7_OFFSET, - LPC17_IOCON_PP8_OFFSET, - LPC17_IOCON_PP9_OFFSET, - LPC17_IOCON_PP10_OFFSET, - LPC17_IOCON_PP11_OFFSET, - LPC17_IOCON_PP12_OFFSET, - LPC17_IOCON_PP13_OFFSET, - LPC17_IOCON_PP14_OFFSET, - LPC17_IOCON_PP15_OFFSET, - LPC17_IOCON_PP16_OFFSET, - LPC17_IOCON_PP17_OFFSET, - LPC17_IOCON_PP18_OFFSET, - LPC17_IOCON_PP19_OFFSET, - LPC17_IOCON_PP20_OFFSET, - LPC17_IOCON_PP21_OFFSET, - LPC17_IOCON_PP22_OFFSET, - LPC17_IOCON_PP23_OFFSET, - LPC17_IOCON_PP24_OFFSET, - LPC17_IOCON_PP25_OFFSET, - LPC17_IOCON_PP26_OFFSET, - LPC17_IOCON_PP27_OFFSET, - LPC17_IOCON_PP28_OFFSET, - LPC17_IOCON_PP29_OFFSET, - LPC17_IOCON_PP30_OFFSET, - LPC17_IOCON_PP31_OFFSET -}; #endif /* Port 0 and Port 2 can provide a single interrupt for any combination of @@ -434,7 +396,7 @@ static int lpc17_configiocon(unsigned int port, unsigned int pin, uint32_t regaddr; uint32_t regval; - regaddr = (g_ioconbase[port] + g_ioconpin[pin]); + regaddr = (g_ioconbase[port] + LPC17_IOCON_PP_OFFSET(pin)); regval = getreg32(regaddr); regval &= value; putreg32(regval, regaddr); diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.h b/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.h index 62bf2d018..99a0b67e9 100644 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.h +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.h @@ -354,7 +354,6 @@ EXTERN const uint32_t g_hipinmode[GPIO_NPORTS]; EXTERN const uint32_t g_odmode[GPIO_NPORTS]; #ifdef LPC178x EXTERN const uint32_t g_ioconport[GPIO_NPORTS]; -EXTERN const uint32_t g_ioconpin[32]; #endif /**************************************************************************** -- cgit v1.2.3 From e44fbfdc5a033611f4ebfb12b0dd67b263bb8d14 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 30 Jan 2013 16:44:26 +0000 Subject: Add LM3S/4F family definitions git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5585 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/include/lm/chip.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nuttx/arch/arm/include/lm/chip.h b/nuttx/arch/arm/include/lm/chip.h index 6761e029e..86e21c14d 100644 --- a/nuttx/arch/arm/include/lm/chip.h +++ b/nuttx/arch/arm/include/lm/chip.h @@ -50,6 +50,8 @@ /* Get customizations for each supported chip (only the LM3S6918 and 65 right now) */ #if defined(CONFIG_ARCH_CHIP_LM3S6918) +# define LM3S 1 /* LM3S family */ +# undef LM4F /* Not LM4F family */ # define LM_NTIMERS 4 /* Four general purpose timers */ # define LM_NWIDETIMERS 0 /* No general purpose wide timers */ # define LM_NETHCONTROLLERS 1 /* One Ethernet controller */ @@ -63,6 +65,8 @@ # define LM_NPORTS 8 /* 8 Ports (GPIOA-H) 5-38 GPIOs */ # define LM_NCANCONTROLLER 0 /* No CAN controllers */ #elif defined(CONFIG_ARCH_CHIP_LM3S6432) +# define LM3S 1 /* LM3S family */ +# undef LM4F /* Not LM4F family */ # define LM_NTIMERS 3 /* Three general purpose timers */ # define LM_NWIDETIMERS 0 /* No general purpose wide timers */ # define LM_NETHCONTROLLERS 1 /* One Ethernet controller */ @@ -76,6 +80,8 @@ # define LM_NPORTS 7 /* 7 Ports (GPIOA-G), 0-42 GPIOs */ # define LM_NCANCONTROLLER 0 /* No CAN controllers */ #elif defined(CONFIG_ARCH_CHIP_LM3S6965) +# define LM3S 1 /* LM3S family */ +# undef LM4F /* Not LM4F family */ # define LM_NTIMERS 4 /* Four general purpose timers */ # define LM_NWIDETIMERS 0 /* No general purpose wide timers */ # define LM_NETHCONTROLLERS 1 /* One Ethernet controller */ @@ -89,6 +95,8 @@ # define LM_NPORTS 7 /* 7 Ports (GPIOA-G), 0-42 GPIOs */ # define LM_NCANCONTROLLER 0 /* No CAN controllers */ #elif defined(CONFIG_ARCH_CHIP_LM3S9B96) +# define LM3S 1 /* LM3S family */ +# undef LM4F /* Not LM4F family */ # define LM_NTIMERS 4 /* Four general purpose timers */ # define LM_NWIDETIMERS 0 /* No general purpose wide timers */ # define LM_NETHCONTROLLERS 1 /* One Ethernet controller */ @@ -103,6 +111,8 @@ # define LM_NPORTS 9 /* 9 Ports (GPIOA-H,J) 0-65 GPIOs */ # define LM_NCANCONTROLLER 0 /* No CAN controllers */ #elif defined(CONFIG_ARCH_CHIP_LM3S8962) +# define LM3S 1 /* LM3S family */ +# undef LM4F /* Not LM4F family */ # define LM_NTIMERS 6 /* Four general purpose timers */ # define LM_NWIDETIMERS 0 /* No general purpose wide timers */ # define LM_NETHCONTROLLERS 1 /* One Ethernet controller */ @@ -115,6 +125,8 @@ # define LM_NPORTS 7 /* 7 Ports (GPIOA-G), 5-42 GPIOs */ # define LM_NCANCONTROLLER 1 /* One CAN controller */ #elif defined(CONFIG_ARCH_CHIP_LM4F120) +# undef LM3S /* Not LM3S family */ +# define LM4F 1 /* LM4F family */ # define LM_NTIMERS 6 /* Six general purpose timers */ # define LM_NWIDETIMERS 6 /* Six general purpose wide timers */ # define LM_NETHCONTROLLERS 0 /* No Ethernet controller */ -- cgit v1.2.3 From 4a3b0823cb1f58f03b2cb36a8b0df52c189fb511 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 30 Jan 2013 18:48:13 +0000 Subject: LM4F update from JP git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5586 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/src/lm/chip/lm3s_memorymap.h | 6 +- nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h | 7 +- nuttx/arch/arm/src/lm/chip/lm_gpio.h | 695 ++++++++++++++++------------ nuttx/arch/arm/src/stm32/stm32_otgfsdev.c | 31 +- nuttx/include/nuttx/usb/usbdev_trace.h | 5 + 5 files changed, 434 insertions(+), 310 deletions(-) diff --git a/nuttx/arch/arm/src/lm/chip/lm3s_memorymap.h b/nuttx/arch/arm/src/lm/chip/lm3s_memorymap.h index 8caeada17..d4bae8358 100644 --- a/nuttx/arch/arm/src/lm/chip/lm3s_memorymap.h +++ b/nuttx/arch/arm/src/lm/chip/lm3s_memorymap.h @@ -137,7 +137,7 @@ /* -0x47fff: Reserved */ # define LM_ETHCON_BASE (LM_PERIPH_BASE + 0x48000) /* -0x48fff: Ethernet Controller */ /* -0xfcfff: Reserved */ -# define LM_HIBERNATE_BASE (LM_PERIPH_BASE + 0xfc000) /* -0xfcfff: Ethernet Controller */ +# define LM_HIBERNATE_BASE (LM_PERIPH_BASE + 0xfc000) /* -0xfcfff: Hibernation Controller */ # define LM_FLASHCON_BASE (LM_PERIPH_BASE + 0xfd000) /* -0xfdfff: FLASH Control */ # define LM_SYSCON_BASE (LM_PERIPH_BASE + 0xfe000) /* -0xfefff: System Control */ /* -0x1ffffff: Reserved */ @@ -176,7 +176,7 @@ /* -0x47fff: Reserved */ # define LM_ETHCON_BASE (LM_PERIPH_BASE + 0x48000) /* -0x48fff: Ethernet Controller */ /* -0xfcfff: Reserved */ -# define LM_HIBERNATE_BASE (LM_PERIPH_BASE + 0xfc000) /* -0xfcfff: Ethernet Controller */ +# define LM_HIBERNATE_BASE (LM_PERIPH_BASE + 0xfc000) /* -0xfcfff: Hibernation Controller */ # define LM_FLASHCON_BASE (LM_PERIPH_BASE + 0xfd000) /* -0xfdfff: FLASH Control */ # define LM_SYSCON_BASE (LM_PERIPH_BASE + 0xfe000) /* -0xfefff: System Control */ /* -0x1ffffff: Reserved */ @@ -223,7 +223,7 @@ /* -0x47fff: Reserved */ # define LM_ETHCON_BASE (LM_PERIPH_BASE + 0x48000) /* -0x48fff: Ethernet Controller */ /* -0xfcfff: Reserved */ -# define LM_HIBERNATE_BASE (LM_PERIPH_BASE + 0xfc000) /* -0xfcfff: Ethernet Controller */ +# define LM_HIBERNATE_BASE (LM_PERIPH_BASE + 0xfc000) /* -0xfcfff: Hibernation Controller */ # define LM_FLASHCON_BASE (LM_PERIPH_BASE + 0xfd000) /* -0xfdfff: FLASH Control */ # define LM_SYSCON_BASE (LM_PERIPH_BASE + 0xfe000) /* -0xfefff: System Control */ /* -0x1ffffff: Reserved */ diff --git a/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h b/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h index c8c62d4b4..4d715e470 100644 --- a/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h +++ b/nuttx/arch/arm/src/lm/chip/lm4f_memorymap.h @@ -146,7 +146,12 @@ /* -0xaefff: Reserved */ # define LM_EEPROM_BASE (LM_PERIPH_BASE + 0xaf000) /* -0xaffff: EEPROM and Key Locker */ /* -0xf8fff: Reserved */ -/* @TODO */ +# define LM_SYSEXC_BASE (LM_PERIPH_BASE + 0xf9000) /* -0xf9fff: System Exception Control */ + /* -0xfbfff: Reserved */ +# define LM_HIBERNATE_BASE (LM_PERIPH_BASE + 0xfc000) /* -0xfcfff: Hibernation Controller */ +# define LM_FLASHCON_BASE (LM_PERIPH_BASE + 0xfd000) /* -0xfdfff: FLASH Control */ +# define LM_SYSCON_BASE (LM_PERIPH_BASE + 0xfe000) /* -0xfefff: System Control */ +# define LM_UDMA_BASE (LM_PERIPH_BASE + 0xff000) /* -0xfffff: Micro Direct Memory Access */ #else # error "Peripheral base addresses not specified for this Stellaris chip" #endif diff --git a/nuttx/arch/arm/src/lm/chip/lm_gpio.h b/nuttx/arch/arm/src/lm/chip/lm_gpio.h index 30b850fca..ebb5aa94f 100644 --- a/nuttx/arch/arm/src/lm/chip/lm_gpio.h +++ b/nuttx/arch/arm/src/lm/chip/lm_gpio.h @@ -2,7 +2,8 @@ * arch/arm/src/lm/chip/lm_gpio.h * * Copyright (C) 2009-2010, 2013 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Authors: Gregory Nutt + * Jose Pablo Carballo * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -68,6 +69,14 @@ #define LM_GPIO_DEN_OFFSET 0x51C /* GPIO Digital Enable */ #define LM_GPIO_LOCK_OFFSET 0x520 /* GPIO Lock */ #define LM_GPIO_CR_OFFSET 0x524 /* GPIO Commit */ + +#ifdef LM4F +# define LM_GPIO_AMSEL_OFFSET 0x528 /* GPIO Analog Mode Select */ +# define LM_GPIO_PCTL_OFFSET 0x52c /* GPIO Port Control */ +# define LM_GPIO_ADCCTL_OFFSET 0x530 /* GPIO ADC Control */ +# define LM_GPIO_DMACTL_OFFSET 0x534 /* GPIO DMA Control */ +#endif + #define LM_GPIO_PERIPHID4_OFFSET 0xfd0 /* GPIO Peripheral Identification 4 */ #define LM_GPIO_PERIPHID5_OFFSET 0xfd4 /* GPIO Peripheral Identification 5 */ #define LM_GPIO_PERIPHID6_OFFSET 0xfd8 /* GPIO Peripheral Identification 6 */ @@ -83,302 +92,394 @@ /* GPIO Register Addresses **********************************************************/ -#define LM_GPIOA_DATA (LM_GPIOA_BASE + LM_GPIO_DATA_OFFSET) -#define LM_GPIOA_DIR (LM_GPIOA_BASE + LM_GPIO_DIR_OFFSET) -#define LM_GPIOA_IS (LM_GPIOA_BASE + LM_GPIO_IS_OFFSET) -#define LM_GPIOA_IBE (LM_GPIOA_BASE + LM_GPIO_IBE_OFFSET) -#define LM_GPIOA_IEV (LM_GPIOA_BASE + LM_GPIO_IEV_OFFSET) -#define LM_GPIOA_IM (LM_GPIOA_BASE + LM_GPIO_IM_OFFSET) -#define LM_GPIOA_RIS (LM_GPIOA_BASE + LM_GPIO_RIS_OFFSET) -#define LM_GPIOA_MIS (LM_GPIOA_BASE + LM_GPIO_MIS_OFFSET) -#define LM_GPIOA_ICR (LM_GPIOA_BASE + LM_GPIO_ICR_OFFSET) -#define LM_GPIOA_AFSEL (LM_GPIOA_BASE + LM_GPIO_AFSEL_OFFSET) -#define LM_GPIOA_DR2R (LM_GPIOA_BASE + LM_GPIO_DR2R_OFFSET) -#define LM_GPIOA_DR4R (LM_GPIOA_BASE + LM_GPIO_DR4R_OFFSET) -#define LM_GPIOA_DR8R (LM_GPIOA_BASE + LM_GPIO_DR8R_OFFSET) -#define LM_GPIOA_ODR (LM_GPIOA_BASE + LM_GPIO_ODR_OFFSET) -#define LM_GPIOA_PUR (LM_GPIOA_BASE + LM_GPIO_PUR_OFFSET) -#define LM_GPIOA_PDR (LM_GPIOA_BASE + LM_GPIO_PDR_OFFSET) -#define LM_GPIOA_SLR (LM_GPIOA_BASE + LM_GPIO_SLR_OFFSET) -#define LM_GPIOA_DEN (LM_GPIOA_BASE + LM_GPIO_DEN_OFFSET) -#define LM_GPIOA_LOCK (LM_GPIOA_BASE + LM_GPIO_LOCK_OFFSET) -#define LM_GPIOA_CR (LM_GPIOA_BASE + LM_GPIO_CR_OFFSET) -#define LM_GPIOA_PERIPHID4 (LM_GPIOA_BASE + LM_GPIO_PERIPHID4_OFFSET) -#define LM_GPIOA_PERIPHID5 (LM_GPIOA_BASE + LM_GPIO_PERIPHID5_OFFSET) -#define LM_GPIOA_PERIPHID6 (LM_GPIOA_BASE + LM_GPIO_PERIPHID6_OFFSET) -#define LM_GPIOA_PERIPHID7 (LM_GPIOA_BASE + LM_GPIO_PERIPHID7_OFFSET) -#define LM_GPIOA_PERIPHID0 (LM_GPIOA_BASE + LM_GPIO_PERIPHID0_OFFSET) -#define LM_GPIOA_PERIPHID1 (LM_GPIOA_BASE + LM_GPIO_PERIPHID1_OFFSET) -#define LM_GPIOA_PERIPHID2 (LM_GPIOA_BASE + LM_GPIO_PERIPHID2_OFFSET) -#define LM_GPIOA_PERIPHID3 (LM_GPIOA_BASE + LM_GPIO_PERIPHID3_OFFSET) -#define LM_GPIOA_PCELLID0 (LM_GPIOA_BASE + LM_GPIO_PCELLID0_OFFSET) -#define LM_GPIOA_PCELLID1 (LM_GPIOA_BASE + LM_GPIO_PCELLID1_OFFSET) -#define LM_GPIOA_PCELLID2 (LM_GPIOA_BASE + LM_GPIO_PCELLID2_OFFSET) -#define LM_GPIOA_PCELLID3 (LM_GPIOA_BASE + LM_GPIO_PCELLID3_OFFSET) - -#define LM_GPIOB_DATA (LM_GPIOB_BASE + LM_GPIO_DATA_OFFSET) -#define LM_GPIOB_DIR (LM_GPIOB_BASE + LM_GPIO_DIR_OFFSET) -#define LM_GPIOB_IS (LM_GPIOB_BASE + LM_GPIO_IS_OFFSET) -#define LM_GPIOB_IBE (LM_GPIOB_BASE + LM_GPIO_IBE_OFFSET) -#define LM_GPIOB_IEV (LM_GPIOB_BASE + LM_GPIO_IEV_OFFSET) -#define LM_GPIOB_IM (LM_GPIOB_BASE + LM_GPIO_IM_OFFSET) -#define LM_GPIOB_RIS (LM_GPIOB_BASE + LM_GPIO_RIS_OFFSET) -#define LM_GPIOB_MIS (LM_GPIOB_BASE + LM_GPIO_MIS_OFFSET) -#define LM_GPIOB_ICR (LM_GPIOB_BASE + LM_GPIO_ICR_OFFSET) -#define LM_GPIOB_AFSEL (LM_GPIOB_BASE + LM_GPIO_AFSEL_OFFSET) -#define LM_GPIOB_DR2R (LM_GPIOB_BASE + LM_GPIO_DR2R_OFFSET) -#define LM_GPIOB_DR4R (LM_GPIOB_BASE + LM_GPIO_DR4R_OFFSET) -#define LM_GPIOB_DR8R (LM_GPIOB_BASE + LM_GPIO_DR8R_OFFSET) -#define LM_GPIOB_ODR (LM_GPIOB_BASE + LM_GPIO_ODR_OFFSET) -#define LM_GPIOB_PUR (LM_GPIOB_BASE + LM_GPIO_PUR_OFFSET) -#define LM_GPIOB_PDR (LM_GPIOB_BASE + LM_GPIO_PDR_OFFSET) -#define LM_GPIOB_SLR (LM_GPIOB_BASE + LM_GPIO_SLR_OFFSET) -#define LM_GPIOB_DEN (LM_GPIOB_BASE + LM_GPIO_DEN_OFFSET) -#define LM_GPIOB_LOCK (LM_GPIOB_BASE + LM_GPIO_LOCK_OFFSET) -#define LM_GPIOB_CR (LM_GPIOB_BASE + LM_GPIO_CR_OFFSET) -#define LM_GPIOB_PERIPHID4 (LM_GPIOB_BASE + LM_GPIO_PERIPHID4_OFFSET) -#define LM_GPIOB_PERIPHID5 (LM_GPIOB_BASE + LM_GPIO_PERIPHID5_OFFSET) -#define LM_GPIOB_PERIPHID6 (LM_GPIOB_BASE + LM_GPIO_PERIPHID6_OFFSET) -#define LM_GPIOB_PERIPHID7 (LM_GPIOB_BASE + LM_GPIO_PERIPHID7_OFFSET) -#define LM_GPIOB_PERIPHID0 (LM_GPIOB_BASE + LM_GPIO_PERIPHID0_OFFSET) -#define LM_GPIOB_PERIPHID1 (LM_GPIOB_BASE + LM_GPIO_PERIPHID1_OFFSET) -#define LM_GPIOB_PERIPHID2 (LM_GPIOB_BASE + LM_GPIO_PERIPHID2_OFFSET) -#define LM_GPIOB_PERIPHID3 (LM_GPIOB_BASE + LM_GPIO_PERIPHID3_OFFSET) -#define LM_GPIOB_PCELLID0 (LM_GPIOB_BASE + LM_GPIO_PCELLID0_OFFSET) -#define LM_GPIOB_PCELLID1 (LM_GPIOB_BASE + LM_GPIO_PCELLID1_OFFSET) -#define LM_GPIOB_PCELLID2 (LM_GPIOB_BASE + LM_GPIO_PCELLID2_OFFSET) -#define LM_GPIOB_PCELLID3 (LM_GPIOB_BASE + LM_GPIO_PCELLID3_OFFSET) - -#define LM_GPIOC_DATA (LM_GPIOC_BASE + LM_GPIO_DATA_OFFSET) -#define LM_GPIOC_DIR (LM_GPIOC_BASE + LM_GPIO_DIR_OFFSET) -#define LM_GPIOC_IS (LM_GPIOC_BASE + LM_GPIO_IS_OFFSET) -#define LM_GPIOC_IBE (LM_GPIOC_BASE + LM_GPIO_IBE_OFFSET) -#define LM_GPIOC_IEV (LM_GPIOC_BASE + LM_GPIO_IEV_OFFSET) -#define LM_GPIOC_IM (LM_GPIOC_BASE + LM_GPIO_IM_OFFSET) -#define LM_GPIOC_RIS (LM_GPIOC_BASE + LM_GPIO_RIS_OFFSET) -#define LM_GPIOC_MIS (LM_GPIOC_BASE + LM_GPIO_MIS_OFFSET) -#define LM_GPIOC_ICR (LM_GPIOC_BASE + LM_GPIO_ICR_OFFSET) -#define LM_GPIOC_AFSEL (LM_GPIOC_BASE + LM_GPIO_AFSEL_OFFSET) -#define LM_GPIOC_DR2R (LM_GPIOC_BASE + LM_GPIO_DR2R_OFFSET) -#define LM_GPIOC_DR4R (LM_GPIOC_BASE + LM_GPIO_DR4R_OFFSET) -#define LM_GPIOC_DR8R (LM_GPIOC_BASE + LM_GPIO_DR8R_OFFSET) -#define LM_GPIOC_ODR (LM_GPIOC_BASE + LM_GPIO_ODR_OFFSET) -#define LM_GPIOC_PUR (LM_GPIOC_BASE + LM_GPIO_PUR_OFFSET) -#define LM_GPIOC_PDR (LM_GPIOC_BASE + LM_GPIO_PDR_OFFSET) -#define LM_GPIOC_SLR (LM_GPIOC_BASE + LM_GPIO_SLR_OFFSET) -#define LM_GPIOC_DEN (LM_GPIOC_BASE + LM_GPIO_DEN_OFFSET) -#define LM_GPIOC_LOCK (LM_GPIOC_BASE + LM_GPIO_LOCK_OFFSET) -#define LM_GPIOC_CR (LM_GPIOC_BASE + LM_GPIO_CR_OFFSET) -#define LM_GPIOC_PERIPHID4 (LM_GPIOC_BASE + LM_GPIO_PERIPHID4_OFFSET) -#define LM_GPIOC_PERIPHID5 (LM_GPIOC_BASE + LM_GPIO_PERIPHID5_OFFSET) -#define LM_GPIOC_PERIPHID6 (LM_GPIOC_BASE + LM_GPIO_PERIPHID6_OFFSET) -#define LM_GPIOC_PERIPHID7 (LM_GPIOC_BASE + LM_GPIO_PERIPHID7_OFFSET) -#define LM_GPIOC_PERIPHID0 (LM_GPIOC_BASE + LM_GPIO_PERIPHID0_OFFSET) -#define LM_GPIOC_PERIPHID1 (LM_GPIOC_BASE + LM_GPIO_PERIPHID1_OFFSET) -#define LM_GPIOC_PERIPHID2 (LM_GPIOC_BASE + LM_GPIO_PERIPHID2_OFFSET) -#define LM_GPIOC_PERIPHID3 (LM_GPIOC_BASE + LM_GPIO_PERIPHID3_OFFSET) -#define LM_GPIOC_PCELLID0 (LM_GPIOC_BASE + LM_GPIO_PCELLID0_OFFSET) -#define LM_GPIOC_PCELLID1 (LM_GPIOC_BASE + LM_GPIO_PCELLID1_OFFSET) -#define LM_GPIOC_PCELLID2 (LM_GPIOC_BASE + LM_GPIO_PCELLID2_OFFSET) -#define LM_GPIOC_PCELLID3 (LM_GPIOC_BASE + LM_GPIO_PCELLID3_OFFSET) - -#define LM_GPIOD_DATA (LM_GPIOD_BASE + LM_GPIO_DATA_OFFSET) -#define LM_GPIOD_DIR (LM_GPIOD_BASE + LM_GPIO_DIR_OFFSET) -#define LM_GPIOD_IS (LM_GPIOD_BASE + LM_GPIO_IS_OFFSET) -#define LM_GPIOD_IBE (LM_GPIOD_BASE + LM_GPIO_IBE_OFFSET) -#define LM_GPIOD_IEV (LM_GPIOD_BASE + LM_GPIO_IEV_OFFSET) -#define LM_GPIOD_IM (LM_GPIOD_BASE + LM_GPIO_IM_OFFSET) -#define LM_GPIOD_RIS (LM_GPIOD_BASE + LM_GPIO_RIS_OFFSET) -#define LM_GPIOD_MIS (LM_GPIOD_BASE + LM_GPIO_MIS_OFFSET) -#define LM_GPIOD_ICR (LM_GPIOD_BASE + LM_GPIO_ICR_OFFSET) -#define LM_GPIOD_AFSEL (LM_GPIOD_BASE + LM_GPIO_AFSEL_OFFSET) -#define LM_GPIOD_DR2R (LM_GPIOD_BASE + LM_GPIO_DR2R_OFFSET) -#define LM_GPIOD_DR4R (LM_GPIOD_BASE + LM_GPIO_DR4R_OFFSET) -#define LM_GPIOD_DR8R (LM_GPIOD_BASE + LM_GPIO_DR8R_OFFSET) -#define LM_GPIOD_ODR (LM_GPIOD_BASE + LM_GPIO_ODR_OFFSET) -#define LM_GPIOD_PUR (LM_GPIOD_BASE + LM_GPIO_PUR_OFFSET) -#define LM_GPIOD_PDR (LM_GPIOD_BASE + LM_GPIO_PDR_OFFSET) -#define LM_GPIOD_SLR (LM_GPIOD_BASE + LM_GPIO_SLR_OFFSET) -#define LM_GPIOD_DEN (LM_GPIOD_BASE + LM_GPIO_DEN_OFFSET) -#define LM_GPIOD_LOCK (LM_GPIOD_BASE + LM_GPIO_LOCK_OFFSET) -#define LM_GPIOD_CR (LM_GPIOD_BASE + LM_GPIO_CR_OFFSET) -#define LM_GPIOD_PERIPHID4 (LM_GPIOD_BASE + LM_GPIO_PERIPHID4_OFFSET) -#define LM_GPIOD_PERIPHID5 (LM_GPIOD_BASE + LM_GPIO_PERIPHID5_OFFSET) -#define LM_GPIOD_PERIPHID6 (LM_GPIOD_BASE + LM_GPIO_PERIPHID6_OFFSET) -#define LM_GPIOD_PERIPHID7 (LM_GPIOD_BASE + LM_GPIO_PERIPHID7_OFFSET) -#define LM_GPIOD_PERIPHID0 (LM_GPIOD_BASE + LM_GPIO_PERIPHID0_OFFSET) -#define LM_GPIOD_PERIPHID1 (LM_GPIOD_BASE + LM_GPIO_PERIPHID1_OFFSET) -#define LM_GPIOD_PERIPHID2 (LM_GPIOD_BASE + LM_GPIO_PERIPHID2_OFFSET) -#define LM_GPIOD_PERIPHID3 (LM_GPIOD_BASE + LM_GPIO_PERIPHID3_OFFSET) -#define LM_GPIOD_PCELLID0 (LM_GPIOD_BASE + LM_GPIO_PCELLID0_OFFSET) -#define LM_GPIOD_PCELLID1 (LM_GPIOD_BASE + LM_GPIO_PCELLID1_OFFSET) -#define LM_GPIOD_PCELLID2 (LM_GPIOD_BASE + LM_GPIO_PCELLID2_OFFSET) -#define LM_GPIOD_PCELLID3 (LM_GPIOD_BASE + LM_GPIO_PCELLID3_OFFSET) - -#define LM_GPIOE_DATA (LM_GPIOE_BASE + LM_GPIO_DATA_OFFSET) -#define LM_GPIOE_DIR (LM_GPIOE_BASE + LM_GPIO_DIR_OFFSET) -#define LM_GPIOE_IS (LM_GPIOE_BASE + LM_GPIO_IS_OFFSET) -#define LM_GPIOE_IBE (LM_GPIOE_BASE + LM_GPIO_IBE_OFFSET) -#define LM_GPIOE_IEV (LM_GPIOE_BASE + LM_GPIO_IEV_OFFSET) -#define LM_GPIOE_IM (LM_GPIOE_BASE + LM_GPIO_IM_OFFSET) -#define LM_GPIOE_RIS (LM_GPIOE_BASE + LM_GPIO_RIS_OFFSET) -#define LM_GPIOE_MIS (LM_GPIOE_BASE + LM_GPIO_MIS_OFFSET) -#define LM_GPIOE_ICR (LM_GPIOE_BASE + LM_GPIO_ICR_OFFSET) -#define LM_GPIOE_AFSEL (LM_GPIOE_BASE + LM_GPIO_AFSEL_OFFSET) -#define LM_GPIOE_DR2R (LM_GPIOE_BASE + LM_GPIO_DR2R_OFFSET) -#define LM_GPIOE_DR4R (LM_GPIOE_BASE + LM_GPIO_DR4R_OFFSET) -#define LM_GPIOE_DR8R (LM_GPIOE_BASE + LM_GPIO_DR8R_OFFSET) -#define LM_GPIOE_ODR (LM_GPIOE_BASE + LM_GPIO_ODR_OFFSET) -#define LM_GPIOE_PUR (LM_GPIOE_BASE + LM_GPIO_PUR_OFFSET) -#define LM_GPIOE_PDR (LM_GPIOE_BASE + LM_GPIO_PDR_OFFSET) -#define LM_GPIOE_SLR (LM_GPIOE_BASE + LM_GPIO_SLR_OFFSET) -#define LM_GPIOE_DEN (LM_GPIOE_BASE + LM_GPIO_DEN_OFFSET) -#define LM_GPIOE_LOCK (LM_GPIOE_BASE + LM_GPIO_LOCK_OFFSET) -#define LM_GPIOE_CR (LM_GPIOE_BASE + LM_GPIO_CR_OFFSET) -#define LM_GPIOE_PERIPHID4 (LM_GPIOE_BASE + LM_GPIO_PERIPHID4_OFFSET) -#define LM_GPIOE_PERIPHID5 (LM_GPIOE_BASE + LM_GPIO_PERIPHID5_OFFSET) -#define LM_GPIOE_PERIPHID6 (LM_GPIOE_BASE + LM_GPIO_PERIPHID6_OFFSET) -#define LM_GPIOE_PERIPHID7 (LM_GPIOE_BASE + LM_GPIO_PERIPHID7_OFFSET) -#define LM_GPIOE_PERIPHID0 (LM_GPIOE_BASE + LM_GPIO_PERIPHID0_OFFSET) -#define LM_GPIOE_PERIPHID1 (LM_GPIOE_BASE + LM_GPIO_PERIPHID1_OFFSET) -#define LM_GPIOE_PERIPHID2 (LM_GPIOE_BASE + LM_GPIO_PERIPHID2_OFFSET) -#define LM_GPIOE_PERIPHID3 (LM_GPIOE_BASE + LM_GPIO_PERIPHID3_OFFSET) -#define LM_GPIOE_PCELLID0 (LM_GPIOE_BASE + LM_GPIO_PCELLID0_OFFSET) -#define LM_GPIOE_PCELLID1 (LM_GPIOE_BASE + LM_GPIO_PCELLID1_OFFSET) -#define LM_GPIOE_PCELLID2 (LM_GPIOE_BASE + LM_GPIO_PCELLID2_OFFSET) -#define LM_GPIOE_PCELLID3 (LM_GPIOE_BASE + LM_GPIO_PCELLID3_OFFSET) - -#define LM_GPIOF_DATA (LM_GPIOF_BASE + LM_GPIO_DATA_OFFSET) -#define LM_GPIOF_DIR (LM_GPIOF_BASE + LM_GPIO_DIR_OFFSET) -#define LM_GPIOF_IS (LM_GPIOF_BASE + LM_GPIO_IS_OFFSET) -#define LM_GPIOF_IBE (LM_GPIOF_BASE + LM_GPIO_IBE_OFFSET) -#define LM_GPIOF_IEV (LM_GPIOF_BASE + LM_GPIO_IEV_OFFSET) -#define LM_GPIOF_IM (LM_GPIOF_BASE + LM_GPIO_IM_OFFSET) -#define LM_GPIOF_RIS (LM_GPIOF_BASE + LM_GPIO_RIS_OFFSET) -#define LM_GPIOF_MIS (LM_GPIOF_BASE + LM_GPIO_MIS_OFFSET) -#define LM_GPIOF_ICR (LM_GPIOF_BASE + LM_GPIO_ICR_OFFSET) -#define LM_GPIOF_AFSEL (LM_GPIOF_BASE + LM_GPIO_AFSEL_OFFSET) -#define LM_GPIOF_DR2R (LM_GPIOF_BASE + LM_GPIO_DR2R_OFFSET) -#define LM_GPIOF_DR4R (LM_GPIOF_BASE + LM_GPIO_DR4R_OFFSET) -#define LM_GPIOF_DR8R (LM_GPIOF_BASE + LM_GPIO_DR8R_OFFSET) -#define LM_GPIOF_ODR (LM_GPIOF_BASE + LM_GPIO_ODR_OFFSET) -#define LM_GPIOF_PUR (LM_GPIOF_BASE + LM_GPIO_PUR_OFFSET) -#define LM_GPIOF_PDR (LM_GPIOF_BASE + LM_GPIO_PDR_OFFSET) -#define LM_GPIOF_SLR (LM_GPIOF_BASE + LM_GPIO_SLR_OFFSET) -#define LM_GPIOF_DEN (LM_GPIOF_BASE + LM_GPIO_DEN_OFFSET) -#define LM_GPIOF_LOCK (LM_GPIOF_BASE + LM_GPIO_LOCK_OFFSET) -#define LM_GPIOF_CR (LM_GPIOF_BASE + LM_GPIO_CR_OFFSET) -#define LM_GPIOF_PERIPHID4 (LM_GPIOF_BASE + LM_GPIO_PERIPHID4_OFFSET) -#define LM_GPIOF_PERIPHID5 (LM_GPIOF_BASE + LM_GPIO_PERIPHID5_OFFSET) -#define LM_GPIOF_PERIPHID6 (LM_GPIOF_BASE + LM_GPIO_PERIPHID6_OFFSET) -#define LM_GPIOF_PERIPHID7 (LM_GPIOF_BASE + LM_GPIO_PERIPHID7_OFFSET) -#define LM_GPIOF_PERIPHID0 (LM_GPIOF_BASE + LM_GPIO_PERIPHID0_OFFSET) -#define LM_GPIOF_PERIPHID1 (LM_GPIOF_BASE + LM_GPIO_PERIPHID1_OFFSET) -#define LM_GPIOF_PERIPHID2 (LM_GPIOF_BASE + LM_GPIO_PERIPHID2_OFFSET) -#define LM_GPIOF_PERIPHID3 (LM_GPIOF_BASE + LM_GPIO_PERIPHID3_OFFSET) -#define LM_GPIOF_PCELLID0 (LM_GPIOF_BASE + LM_GPIO_PCELLID0_OFFSET) -#define LM_GPIOF_PCELLID1 (LM_GPIOF_BASE + LM_GPIO_PCELLID1_OFFSET) -#define LM_GPIOF_PCELLID2 (LM_GPIOF_BASE + LM_GPIO_PCELLID2_OFFSET) -#define LM_GPIOF_PCELLID3 (LM_GPIOF_BASE + LM_GPIO_PCELLID3_OFFSET) - -#define LM_GPIOG_DATA (LM_GPIOG_BASE + LM_GPIO_DATA_OFFSET) -#define LM_GPIOG_DIR (LM_GPIOG_BASE + LM_GPIO_DIR_OFFSET) -#define LM_GPIOG_IS (LM_GPIOG_BASE + LM_GPIO_IS_OFFSET) -#define LM_GPIOG_IBE (LM_GPIOG_BASE + LM_GPIO_IBE_OFFSET) -#define LM_GPIOG_IEV (LM_GPIOG_BASE + LM_GPIO_IEV_OFFSET) -#define LM_GPIOG_IM (LM_GPIOG_BASE + LM_GPIO_IM_OFFSET) -#define LM_GPIOG_RIS (LM_GPIOG_BASE + LM_GPIO_RIS_OFFSET) -#define LM_GPIOG_MIS (LM_GPIOG_BASE + LM_GPIO_MIS_OFFSET) -#define LM_GPIOG_ICR (LM_GPIOG_BASE + LM_GPIO_ICR_OFFSET) -#define LM_GPIOG_AFSEL (LM_GPIOG_BASE + LM_GPIO_AFSEL_OFFSET) -#define LM_GPIOG_DR2R (LM_GPIOG_BASE + LM_GPIO_DR2R_OFFSET) -#define LM_GPIOG_DR4R (LM_GPIOG_BASE + LM_GPIO_DR4R_OFFSET) -#define LM_GPIOG_DR8R (LM_GPIOG_BASE + LM_GPIO_DR8R_OFFSET) -#define LM_GPIOG_ODR (LM_GPIOG_BASE + LM_GPIO_ODR_OFFSET) -#define LM_GPIOG_PUR (LM_GPIOG_BASE + LM_GPIO_PUR_OFFSET) -#define LM_GPIOG_PDR (LM_GPIOG_BASE + LM_GPIO_PDR_OFFSET) -#define LM_GPIOG_SLR (LM_GPIOG_BASE + LM_GPIO_SLR_OFFSET) -#define LM_GPIOG_DEN (LM_GPIOG_BASE + LM_GPIO_DEN_OFFSET) -#define LM_GPIOG_LOCK (LM_GPIOG_BASE + LM_GPIO_LOCK_OFFSET) -#define LM_GPIOG_CR (LM_GPIOG_BASE + LM_GPIO_CR_OFFSET) -#define LM_GPIOG_PERIPHID4 (LM_GPIOG_BASE + LM_GPIO_PERIPHID4_OFFSET) -#define LM_GPIOG_PERIPHID5 (LM_GPIOG_BASE + LM_GPIO_PERIPHID5_OFFSET) -#define LM_GPIOG_PERIPHID6 (LM_GPIOG_BASE + LM_GPIO_PERIPHID6_OFFSET) -#define LM_GPIOG_PERIPHID7 (LM_GPIOG_BASE + LM_GPIO_PERIPHID7_OFFSET) -#define LM_GPIOG_PERIPHID0 (LM_GPIOG_BASE + LM_GPIO_PERIPHID0_OFFSET) -#define LM_GPIOG_PERIPHID1 (LM_GPIOG_BASE + LM_GPIO_PERIPHID1_OFFSET) -#define LM_GPIOG_PERIPHID2 (LM_GPIOG_BASE + LM_GPIO_PERIPHID2_OFFSET) -#define LM_GPIOG_PERIPHID3 (LM_GPIOG_BASE + LM_GPIO_PERIPHID3_OFFSET) -#define LM_GPIOG_PCELLID0 (LM_GPIOG_BASE + LM_GPIO_PCELLID0_OFFSET) -#define LM_GPIOG_PCELLID1 (LM_GPIOG_BASE + LM_GPIO_PCELLID1_OFFSET) -#define LM_GPIOG_PCELLID2 (LM_GPIOG_BASE + LM_GPIO_PCELLID2_OFFSET) -#define LM_GPIOG_PCELLID3 (LM_GPIOG_BASE + LM_GPIO_PCELLID3_OFFSET) - -#define LM_GPIOH_DATA (LM_GPIOH_BASE + LM_GPIO_DATA_OFFSET) -#define LM_GPIOH_DIR (LM_GPIOH_BASE + LM_GPIO_DIR_OFFSET) -#define LM_GPIOH_IS (LM_GPIOH_BASE + LM_GPIO_IS_OFFSET) -#define LM_GPIOH_IBE (LM_GPIOH_BASE + LM_GPIO_IBE_OFFSET) -#define LM_GPIOH_IEV (LM_GPIOH_BASE + LM_GPIO_IEV_OFFSET) -#define LM_GPIOH_IM (LM_GPIOH_BASE + LM_GPIO_IM_OFFSET) -#define LM_GPIOH_RIS (LM_GPIOH_BASE + LM_GPIO_RIS_OFFSET) -#define LM_GPIOH_MIS (LM_GPIOH_BASE + LM_GPIO_MIS_OFFSET) -#define LM_GPIOH_ICR (LM_GPIOH_BASE + LM_GPIO_ICR_OFFSET) -#define LM_GPIOH_AFSEL (LM_GPIOH_BASE + LM_GPIO_AFSEL_OFFSET) -#define LM_GPIOH_DR2R (LM_GPIOH_BASE + LM_GPIO_DR2R_OFFSET) -#define LM_GPIOH_DR4R (LM_GPIOH_BASE + LM_GPIO_DR4R_OFFSET) -#define LM_GPIOH_DR8R (LM_GPIOH_BASE + LM_GPIO_DR8R_OFFSET) -#define LM_GPIOH_ODR (LM_GPIOH_BASE + LM_GPIO_ODR_OFFSET) -#define LM_GPIOH_PUR (LM_GPIOH_BASE + LM_GPIO_PUR_OFFSET) -#define LM_GPIOH_PDR (LM_GPIOH_BASE + LM_GPIO_PDR_OFFSET) -#define LM_GPIOH_SLR (LM_GPIOH_BASE + LM_GPIO_SLR_OFFSET) -#define LM_GPIOH_DEN (LM_GPIOH_BASE + LM_GPIO_DEN_OFFSET) -#define LM_GPIOH_LOCK (LM_GPIOH_BASE + LM_GPIO_LOCK_OFFSET) -#define LM_GPIOH_CR (LM_GPIOH_BASE + LM_GPIO_CR_OFFSET) -#define LM_GPIOH_PERIPHID4 (LM_GPIOH_BASE + LM_GPIO_PERIPHID4_OFFSET) -#define LM_GPIOH_PERIPHID5 (LM_GPIOH_BASE + LM_GPIO_PERIPHID5_OFFSET) -#define LM_GPIOH_PERIPHID6 (LM_GPIOH_BASE + LM_GPIO_PERIPHID6_OFFSET) -#define LM_GPIOH_PERIPHID7 (LM_GPIOH_BASE + LM_GPIO_PERIPHID7_OFFSET) -#define LM_GPIOH_PERIPHID0 (LM_GPIOH_BASE + LM_GPIO_PERIPHID0_OFFSET) -#define LM_GPIOH_PERIPHID1 (LM_GPIOH_BASE + LM_GPIO_PERIPHID1_OFFSET) -#define LM_GPIOH_PERIPHID2 (LM_GPIOH_BASE + LM_GPIO_PERIPHID2_OFFSET) -#define LM_GPIOH_PERIPHID3 (LM_GPIOH_BASE + LM_GPIO_PERIPHID3_OFFSET) -#define LM_GPIOH_PCELLID0 (LM_GPIOH_BASE + LM_GPIO_PCELLID0_OFFSET) -#define LM_GPIOH_PCELLID1 (LM_GPIOH_BASE + LM_GPIO_PCELLID1_OFFSET) -#define LM_GPIOH_PCELLID2 (LM_GPIOH_BASE + LM_GPIO_PCELLID2_OFFSET) -#define LM_GPIOH_PCELLID3 (LM_GPIOH_BASE + LM_GPIO_PCELLID3_OFFSET) - -#define LM_GPIOJ_DATA (LM_GPIOJ_BASE + LM_GPIO_DATA_OFFSET) -#define LM_GPIOJ_DIR (LM_GPIOJ_BASE + LM_GPIO_DIR_OFFSET) -#define LM_GPIOJ_IS (LM_GPIOJ_BASE + LM_GPIO_IS_OFFSET) -#define LM_GPIOJ_IBE (LM_GPIOJ_BASE + LM_GPIO_IBE_OFFSET) -#define LM_GPIOJ_IEV (LM_GPIOJ_BASE + LM_GPIO_IEV_OFFSET) -#define LM_GPIOJ_IM (LM_GPIOJ_BASE + LM_GPIO_IM_OFFSET) -#define LM_GPIOJ_RIS (LM_GPIOJ_BASE + LM_GPIO_RIS_OFFSET) -#define LM_GPIOJ_MIS (LM_GPIOJ_BASE + LM_GPIO_MIS_OFFSET) -#define LM_GPIOJ_ICR (LM_GPIOJ_BASE + LM_GPIO_ICR_OFFSET) -#define LM_GPIOJ_AFSEL (LM_GPIOJ_BASE + LM_GPIO_AFSEL_OFFSET) -#define LM_GPIOJ_DR2R (LM_GPIOJ_BASE + LM_GPIO_DR2R_OFFSET) -#define LM_GPIOJ_DR4R (LM_GPIOJ_BASE + LM_GPIO_DR4R_OFFSET) -#define LM_GPIOJ_DR8R (LM_GPIOJ_BASE + LM_GPIO_DR8R_OFFSET) -#define LM_GPIOJ_ODR (LM_GPIOJ_BASE + LM_GPIO_ODR_OFFSET) -#define LM_GPIOJ_PUR (LM_GPIOJ_BASE + LM_GPIO_PUR_OFFSET) -#define LM_GPIOJ_PDR (LM_GPIOJ_BASE + LM_GPIO_PDR_OFFSET) -#define LM_GPIOJ_SLR (LM_GPIOJ_BASE + LM_GPIO_SLR_OFFSET) -#define LM_GPIOJ_DEN (LM_GPIOJ_BASE + LM_GPIO_DEN_OFFSET) -#define LM_GPIOJ_LOCK (LM_GPIOJ_BASE + LM_GPIO_LOCK_OFFSET) -#define LM_GPIOJ_CR (LM_GPIOJ_BASE + LM_GPIO_CR_OFFSET) -#define LM_GPIOJ_PERIPHID4 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID4_OFFSET) -#define LM_GPIOJ_PERIPHID5 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID5_OFFSET) -#define LM_GPIOJ_PERIPHID6 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID6_OFFSET) -#define LM_GPIOJ_PERIPHID7 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID7_OFFSET) -#define LM_GPIOJ_PERIPHID0 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID0_OFFSET) -#define LM_GPIOJ_PERIPHID1 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID1_OFFSET) -#define LM_GPIOJ_PERIPHID2 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID2_OFFSET) -#define LM_GPIOJ_PERIPHID3 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID3_OFFSET) -#define LM_GPIOJ_PCELLID0 (LM_GPIOJ_BASE + LM_GPIO_PCELLID0_OFFSET) -#define LM_GPIOJ_PCELLID1 (LM_GPIOJ_BASE + LM_GPIO_PCELLID1_OFFSET) -#define LM_GPIOJ_PCELLID2 (LM_GPIOJ_BASE + LM_GPIO_PCELLID2_OFFSET) -#define LM_GPIOJ_PCELLID3 (LM_GPIOJ_BASE + LM_GPIO_PCELLID3_OFFSET) +#if LM_NPORTS > 0 + +# define LM_GPIOA_DATA (LM_GPIOA_BASE + LM_GPIO_DATA_OFFSET) +# define LM_GPIOA_DIR (LM_GPIOA_BASE + LM_GPIO_DIR_OFFSET) +# define LM_GPIOA_IS (LM_GPIOA_BASE + LM_GPIO_IS_OFFSET) +# define LM_GPIOA_IBE (LM_GPIOA_BASE + LM_GPIO_IBE_OFFSET) +# define LM_GPIOA_IEV (LM_GPIOA_BASE + LM_GPIO_IEV_OFFSET) +# define LM_GPIOA_IM (LM_GPIOA_BASE + LM_GPIO_IM_OFFSET) +# define LM_GPIOA_RIS (LM_GPIOA_BASE + LM_GPIO_RIS_OFFSET) +# define LM_GPIOA_MIS (LM_GPIOA_BASE + LM_GPIO_MIS_OFFSET) +# define LM_GPIOA_ICR (LM_GPIOA_BASE + LM_GPIO_ICR_OFFSET) +# define LM_GPIOA_AFSEL (LM_GPIOA_BASE + LM_GPIO_AFSEL_OFFSET) +# define LM_GPIOA_DR2R (LM_GPIOA_BASE + LM_GPIO_DR2R_OFFSET) +# define LM_GPIOA_DR4R (LM_GPIOA_BASE + LM_GPIO_DR4R_OFFSET) +# define LM_GPIOA_DR8R (LM_GPIOA_BASE + LM_GPIO_DR8R_OFFSET) +# define LM_GPIOA_ODR (LM_GPIOA_BASE + LM_GPIO_ODR_OFFSET) +# define LM_GPIOA_PUR (LM_GPIOA_BASE + LM_GPIO_PUR_OFFSET) +# define LM_GPIOA_PDR (LM_GPIOA_BASE + LM_GPIO_PDR_OFFSET) +# define LM_GPIOA_SLR (LM_GPIOA_BASE + LM_GPIO_SLR_OFFSET) +# define LM_GPIOA_DEN (LM_GPIOA_BASE + LM_GPIO_DEN_OFFSET) +# define LM_GPIOA_LOCK (LM_GPIOA_BASE + LM_GPIO_LOCK_OFFSET) +# define LM_GPIOA_CR (LM_GPIOA_BASE + LM_GPIO_CR_OFFSET) + +# ifdef LM4F +# define LM_GPIOA_AMSEL (LM_GPIOA_BASE + LM_GPIO_AMSEL_OFFSET) +# define LM_GPIOA_PCTL (LM_GPIOA_BASE + LM_GPIO_PCTL_OFFSET) +# define LM_GPIOA_ADCCTL (LM_GPIOA_BASE + LM_GPIO_ADCCTL_OFFSET) +# define LM_GPIOA_DMACTL (LM_GPIOA_BASE + LM_GPIO_DMACTL_OFFSET) +# endif + +# define LM_GPIOA_PERIPHID4 (LM_GPIOA_BASE + LM_GPIO_PERIPHID4_OFFSET) +# define LM_GPIOA_PERIPHID5 (LM_GPIOA_BASE + LM_GPIO_PERIPHID5_OFFSET) +# define LM_GPIOA_PERIPHID6 (LM_GPIOA_BASE + LM_GPIO_PERIPHID6_OFFSET) +# define LM_GPIOA_PERIPHID7 (LM_GPIOA_BASE + LM_GPIO_PERIPHID7_OFFSET) +# define LM_GPIOA_PERIPHID0 (LM_GPIOA_BASE + LM_GPIO_PERIPHID0_OFFSET) +# define LM_GPIOA_PERIPHID1 (LM_GPIOA_BASE + LM_GPIO_PERIPHID1_OFFSET) +# define LM_GPIOA_PERIPHID2 (LM_GPIOA_BASE + LM_GPIO_PERIPHID2_OFFSET) +# define LM_GPIOA_PERIPHID3 (LM_GPIOA_BASE + LM_GPIO_PERIPHID3_OFFSET) +# define LM_GPIOA_PCELLID0 (LM_GPIOA_BASE + LM_GPIO_PCELLID0_OFFSET) +# define LM_GPIOA_PCELLID1 (LM_GPIOA_BASE + LM_GPIO_PCELLID1_OFFSET) +# define LM_GPIOA_PCELLID2 (LM_GPIOA_BASE + LM_GPIO_PCELLID2_OFFSET) +# define LM_GPIOA_PCELLID3 (LM_GPIOA_BASE + LM_GPIO_PCELLID3_OFFSET) + +#elif LM_NPORTS > 1 + +# define LM_GPIOB_DATA (LM_GPIOB_BASE + LM_GPIO_DATA_OFFSET) +# define LM_GPIOB_DIR (LM_GPIOB_BASE + LM_GPIO_DIR_OFFSET) +# define LM_GPIOB_IS (LM_GPIOB_BASE + LM_GPIO_IS_OFFSET) +# define LM_GPIOB_IBE (LM_GPIOB_BASE + LM_GPIO_IBE_OFFSET) +# define LM_GPIOB_IEV (LM_GPIOB_BASE + LM_GPIO_IEV_OFFSET) +# define LM_GPIOB_IM (LM_GPIOB_BASE + LM_GPIO_IM_OFFSET) +# define LM_GPIOB_RIS (LM_GPIOB_BASE + LM_GPIO_RIS_OFFSET) +# define LM_GPIOB_MIS (LM_GPIOB_BASE + LM_GPIO_MIS_OFFSET) +# define LM_GPIOB_ICR (LM_GPIOB_BASE + LM_GPIO_ICR_OFFSET) +# define LM_GPIOB_AFSEL (LM_GPIOB_BASE + LM_GPIO_AFSEL_OFFSET) +# define LM_GPIOB_DR2R (LM_GPIOB_BASE + LM_GPIO_DR2R_OFFSET) +# define LM_GPIOB_DR4R (LM_GPIOB_BASE + LM_GPIO_DR4R_OFFSET) +# define LM_GPIOB_DR8R (LM_GPIOB_BASE + LM_GPIO_DR8R_OFFSET) +# define LM_GPIOB_ODR (LM_GPIOB_BASE + LM_GPIO_ODR_OFFSET) +# define LM_GPIOB_PUR (LM_GPIOB_BASE + LM_GPIO_PUR_OFFSET) +# define LM_GPIOB_PDR (LM_GPIOB_BASE + LM_GPIO_PDR_OFFSET) +# define LM_GPIOB_SLR (LM_GPIOB_BASE + LM_GPIO_SLR_OFFSET) +# define LM_GPIOB_DEN (LM_GPIOB_BASE + LM_GPIO_DEN_OFFSET) +# define LM_GPIOB_LOCK (LM_GPIOB_BASE + LM_GPIO_LOCK_OFFSET) +# define LM_GPIOB_CR (LM_GPIOB_BASE + LM_GPIO_CR_OFFSET) + +# ifdef LM4F +# define LM_GPIOB_AMSEL (LM_GPIOA_BASE + LM_GPIO_AMSEL_OFFSET) +# define LM_GPIOB_PCTL (LM_GPIOA_BASE + LM_GPIO_PCTL_OFFSET) +# define LM_GPIOB_ADCCTL (LM_GPIOA_BASE + LM_GPIO_ADCCTL_OFFSET) +# define LM_GPIOB_DMACTL (LM_GPIOA_BASE + LM_GPIO_DMACTL_OFFSET) +# endif + +# define LM_GPIOB_PERIPHID4 (LM_GPIOB_BASE + LM_GPIO_PERIPHID4_OFFSET) +# define LM_GPIOB_PERIPHID5 (LM_GPIOB_BASE + LM_GPIO_PERIPHID5_OFFSET) +# define LM_GPIOB_PERIPHID6 (LM_GPIOB_BASE + LM_GPIO_PERIPHID6_OFFSET) +# define LM_GPIOB_PERIPHID7 (LM_GPIOB_BASE + LM_GPIO_PERIPHID7_OFFSET) +# define LM_GPIOB_PERIPHID0 (LM_GPIOB_BASE + LM_GPIO_PERIPHID0_OFFSET) +# define LM_GPIOB_PERIPHID1 (LM_GPIOB_BASE + LM_GPIO_PERIPHID1_OFFSET) +# define LM_GPIOB_PERIPHID2 (LM_GPIOB_BASE + LM_GPIO_PERIPHID2_OFFSET) +# define LM_GPIOB_PERIPHID3 (LM_GPIOB_BASE + LM_GPIO_PERIPHID3_OFFSET) +# define LM_GPIOB_PCELLID0 (LM_GPIOB_BASE + LM_GPIO_PCELLID0_OFFSET) +# define LM_GPIOB_PCELLID1 (LM_GPIOB_BASE + LM_GPIO_PCELLID1_OFFSET) +# define LM_GPIOB_PCELLID2 (LM_GPIOB_BASE + LM_GPIO_PCELLID2_OFFSET) +# define LM_GPIOB_PCELLID3 (LM_GPIOB_BASE + LM_GPIO_PCELLID3_OFFSET) + +#elif LM_NPORTS > 2 + +# define LM_GPIOC_DATA (LM_GPIOC_BASE + LM_GPIO_DATA_OFFSET) +# define LM_GPIOC_DIR (LM_GPIOC_BASE + LM_GPIO_DIR_OFFSET) +# define LM_GPIOC_IS (LM_GPIOC_BASE + LM_GPIO_IS_OFFSET) +# define LM_GPIOC_IBE (LM_GPIOC_BASE + LM_GPIO_IBE_OFFSET) +# define LM_GPIOC_IEV (LM_GPIOC_BASE + LM_GPIO_IEV_OFFSET) +# define LM_GPIOC_IM (LM_GPIOC_BASE + LM_GPIO_IM_OFFSET) +# define LM_GPIOC_RIS (LM_GPIOC_BASE + LM_GPIO_RIS_OFFSET) +# define LM_GPIOC_MIS (LM_GPIOC_BASE + LM_GPIO_MIS_OFFSET) +# define LM_GPIOC_ICR (LM_GPIOC_BASE + LM_GPIO_ICR_OFFSET) +# define LM_GPIOC_AFSEL (LM_GPIOC_BASE + LM_GPIO_AFSEL_OFFSET) +# define LM_GPIOC_DR2R (LM_GPIOC_BASE + LM_GPIO_DR2R_OFFSET) +# define LM_GPIOC_DR4R (LM_GPIOC_BASE + LM_GPIO_DR4R_OFFSET) +# define LM_GPIOC_DR8R (LM_GPIOC_BASE + LM_GPIO_DR8R_OFFSET) +# define LM_GPIOC_ODR (LM_GPIOC_BASE + LM_GPIO_ODR_OFFSET) +# define LM_GPIOC_PUR (LM_GPIOC_BASE + LM_GPIO_PUR_OFFSET) +# define LM_GPIOC_PDR (LM_GPIOC_BASE + LM_GPIO_PDR_OFFSET) +# define LM_GPIOC_SLR (LM_GPIOC_BASE + LM_GPIO_SLR_OFFSET) +# define LM_GPIOC_DEN (LM_GPIOC_BASE + LM_GPIO_DEN_OFFSET) +# define LM_GPIOC_LOCK (LM_GPIOC_BASE + LM_GPIO_LOCK_OFFSET) +# define LM_GPIOC_CR (LM_GPIOC_BASE + LM_GPIO_CR_OFFSET) + +# ifdef LM4F +# define LM_GPIOC_AMSEL (LM_GPIOA_BASE + LM_GPIO_AMSEL_OFFSET) +# define LM_GPIOC_PCTL (LM_GPIOA_BASE + LM_GPIO_PCTL_OFFSET) +# define LM_GPIOC_ADCCTL (LM_GPIOA_BASE + LM_GPIO_ADCCTL_OFFSET) +# define LM_GPIOC_DMACTL (LM_GPIOA_BASE + LM_GPIO_DMACTL_OFFSET) +# endif + +# define LM_GPIOC_PERIPHID4 (LM_GPIOC_BASE + LM_GPIO_PERIPHID4_OFFSET) +# define LM_GPIOC_PERIPHID5 (LM_GPIOC_BASE + LM_GPIO_PERIPHID5_OFFSET) +# define LM_GPIOC_PERIPHID6 (LM_GPIOC_BASE + LM_GPIO_PERIPHID6_OFFSET) +# define LM_GPIOC_PERIPHID7 (LM_GPIOC_BASE + LM_GPIO_PERIPHID7_OFFSET) +# define LM_GPIOC_PERIPHID0 (LM_GPIOC_BASE + LM_GPIO_PERIPHID0_OFFSET) +# define LM_GPIOC_PERIPHID1 (LM_GPIOC_BASE + LM_GPIO_PERIPHID1_OFFSET) +# define LM_GPIOC_PERIPHID2 (LM_GPIOC_BASE + LM_GPIO_PERIPHID2_OFFSET) +# define LM_GPIOC_PERIPHID3 (LM_GPIOC_BASE + LM_GPIO_PERIPHID3_OFFSET) +# define LM_GPIOC_PCELLID0 (LM_GPIOC_BASE + LM_GPIO_PCELLID0_OFFSET) +# define LM_GPIOC_PCELLID1 (LM_GPIOC_BASE + LM_GPIO_PCELLID1_OFFSET) +# define LM_GPIOC_PCELLID2 (LM_GPIOC_BASE + LM_GPIO_PCELLID2_OFFSET) +# define LM_GPIOC_PCELLID3 (LM_GPIOC_BASE + LM_GPIO_PCELLID3_OFFSET) + +#elif LM_NPORTS > 3 + +# define LM_GPIOD_DATA (LM_GPIOD_BASE + LM_GPIO_DATA_OFFSET) +# define LM_GPIOD_DIR (LM_GPIOD_BASE + LM_GPIO_DIR_OFFSET) +# define LM_GPIOD_IS (LM_GPIOD_BASE + LM_GPIO_IS_OFFSET) +# define LM_GPIOD_IBE (LM_GPIOD_BASE + LM_GPIO_IBE_OFFSET) +# define LM_GPIOD_IEV (LM_GPIOD_BASE + LM_GPIO_IEV_OFFSET) +# define LM_GPIOD_IM (LM_GPIOD_BASE + LM_GPIO_IM_OFFSET) +# define LM_GPIOD_RIS (LM_GPIOD_BASE + LM_GPIO_RIS_OFFSET) +# define LM_GPIOD_MIS (LM_GPIOD_BASE + LM_GPIO_MIS_OFFSET) +# define LM_GPIOD_ICR (LM_GPIOD_BASE + LM_GPIO_ICR_OFFSET) +# define LM_GPIOD_AFSEL (LM_GPIOD_BASE + LM_GPIO_AFSEL_OFFSET) +# define LM_GPIOD_DR2R (LM_GPIOD_BASE + LM_GPIO_DR2R_OFFSET) +# define LM_GPIOD_DR4R (LM_GPIOD_BASE + LM_GPIO_DR4R_OFFSET) +# define LM_GPIOD_DR8R (LM_GPIOD_BASE + LM_GPIO_DR8R_OFFSET) +# define LM_GPIOD_ODR (LM_GPIOD_BASE + LM_GPIO_ODR_OFFSET) +# define LM_GPIOD_PUR (LM_GPIOD_BASE + LM_GPIO_PUR_OFFSET) +# define LM_GPIOD_PDR (LM_GPIOD_BASE + LM_GPIO_PDR_OFFSET) +# define LM_GPIOD_SLR (LM_GPIOD_BASE + LM_GPIO_SLR_OFFSET) +# define LM_GPIOD_DEN (LM_GPIOD_BASE + LM_GPIO_DEN_OFFSET) +# define LM_GPIOD_LOCK (LM_GPIOD_BASE + LM_GPIO_LOCK_OFFSET) +# define LM_GPIOD_CR (LM_GPIOD_BASE + LM_GPIO_CR_OFFSET) + +# ifdef LM4F +# define LM_GPIOD_AMSEL (LM_GPIOA_BASE + LM_GPIO_AMSEL_OFFSET) +# define LM_GPIOD_PCTL (LM_GPIOA_BASE + LM_GPIO_PCTL_OFFSET) +# define LM_GPIOD_ADCCTL (LM_GPIOA_BASE + LM_GPIO_ADCCTL_OFFSET) +# define LM_GPIOD_DMACTL (LM_GPIOA_BASE + LM_GPIO_DMACTL_OFFSET) +# endif + +# define LM_GPIOD_PERIPHID4 (LM_GPIOD_BASE + LM_GPIO_PERIPHID4_OFFSET) +# define LM_GPIOD_PERIPHID5 (LM_GPIOD_BASE + LM_GPIO_PERIPHID5_OFFSET) +# define LM_GPIOD_PERIPHID6 (LM_GPIOD_BASE + LM_GPIO_PERIPHID6_OFFSET) +# define LM_GPIOD_PERIPHID7 (LM_GPIOD_BASE + LM_GPIO_PERIPHID7_OFFSET) +# define LM_GPIOD_PERIPHID0 (LM_GPIOD_BASE + LM_GPIO_PERIPHID0_OFFSET) +# define LM_GPIOD_PERIPHID1 (LM_GPIOD_BASE + LM_GPIO_PERIPHID1_OFFSET) +# define LM_GPIOD_PERIPHID2 (LM_GPIOD_BASE + LM_GPIO_PERIPHID2_OFFSET) +# define LM_GPIOD_PERIPHID3 (LM_GPIOD_BASE + LM_GPIO_PERIPHID3_OFFSET) +# define LM_GPIOD_PCELLID0 (LM_GPIOD_BASE + LM_GPIO_PCELLID0_OFFSET) +# define LM_GPIOD_PCELLID1 (LM_GPIOD_BASE + LM_GPIO_PCELLID1_OFFSET) +# define LM_GPIOD_PCELLID2 (LM_GPIOD_BASE + LM_GPIO_PCELLID2_OFFSET) +# define LM_GPIOD_PCELLID3 (LM_GPIOD_BASE + LM_GPIO_PCELLID3_OFFSET) + +#elif LM_NPORTS > 4 + +# define LM_GPIOE_DATA (LM_GPIOE_BASE + LM_GPIO_DATA_OFFSET) +# define LM_GPIOE_DIR (LM_GPIOE_BASE + LM_GPIO_DIR_OFFSET) +# define LM_GPIOE_IS (LM_GPIOE_BASE + LM_GPIO_IS_OFFSET) +# define LM_GPIOE_IBE (LM_GPIOE_BASE + LM_GPIO_IBE_OFFSET) +# define LM_GPIOE_IEV (LM_GPIOE_BASE + LM_GPIO_IEV_OFFSET) +# define LM_GPIOE_IM (LM_GPIOE_BASE + LM_GPIO_IM_OFFSET) +# define LM_GPIOE_RIS (LM_GPIOE_BASE + LM_GPIO_RIS_OFFSET) +# define LM_GPIOE_MIS (LM_GPIOE_BASE + LM_GPIO_MIS_OFFSET) +# define LM_GPIOE_ICR (LM_GPIOE_BASE + LM_GPIO_ICR_OFFSET) +# define LM_GPIOE_AFSEL (LM_GPIOE_BASE + LM_GPIO_AFSEL_OFFSET) +# define LM_GPIOE_DR2R (LM_GPIOE_BASE + LM_GPIO_DR2R_OFFSET) +# define LM_GPIOE_DR4R (LM_GPIOE_BASE + LM_GPIO_DR4R_OFFSET) +# define LM_GPIOE_DR8R (LM_GPIOE_BASE + LM_GPIO_DR8R_OFFSET) +# define LM_GPIOE_ODR (LM_GPIOE_BASE + LM_GPIO_ODR_OFFSET) +# define LM_GPIOE_PUR (LM_GPIOE_BASE + LM_GPIO_PUR_OFFSET) +# define LM_GPIOE_PDR (LM_GPIOE_BASE + LM_GPIO_PDR_OFFSET) +# define LM_GPIOE_SLR (LM_GPIOE_BASE + LM_GPIO_SLR_OFFSET) +# define LM_GPIOE_DEN (LM_GPIOE_BASE + LM_GPIO_DEN_OFFSET) +# define LM_GPIOE_LOCK (LM_GPIOE_BASE + LM_GPIO_LOCK_OFFSET) +# define LM_GPIOE_CR (LM_GPIOE_BASE + LM_GPIO_CR_OFFSET) + +# ifdef LM4F +# define LM_GPIOE_AMSEL (LM_GPIOA_BASE + LM_GPIO_AMSEL_OFFSET) +# define LM_GPIOE_PCTL (LM_GPIOA_BASE + LM_GPIO_PCTL_OFFSET) +# define LM_GPIOE_ADCCTL (LM_GPIOA_BASE + LM_GPIO_ADCCTL_OFFSET) +# define LM_GPIOE_DMACTL (LM_GPIOA_BASE + LM_GPIO_DMACTL_OFFSET) +# endif + +# define LM_GPIOE_PERIPHID4 (LM_GPIOE_BASE + LM_GPIO_PERIPHID4_OFFSET) +# define LM_GPIOE_PERIPHID5 (LM_GPIOE_BASE + LM_GPIO_PERIPHID5_OFFSET) +# define LM_GPIOE_PERIPHID6 (LM_GPIOE_BASE + LM_GPIO_PERIPHID6_OFFSET) +# define LM_GPIOE_PERIPHID7 (LM_GPIOE_BASE + LM_GPIO_PERIPHID7_OFFSET) +# define LM_GPIOE_PERIPHID0 (LM_GPIOE_BASE + LM_GPIO_PERIPHID0_OFFSET) +# define LM_GPIOE_PERIPHID1 (LM_GPIOE_BASE + LM_GPIO_PERIPHID1_OFFSET) +# define LM_GPIOE_PERIPHID2 (LM_GPIOE_BASE + LM_GPIO_PERIPHID2_OFFSET) +# define LM_GPIOE_PERIPHID3 (LM_GPIOE_BASE + LM_GPIO_PERIPHID3_OFFSET) +# define LM_GPIOE_PCELLID0 (LM_GPIOE_BASE + LM_GPIO_PCELLID0_OFFSET) +# define LM_GPIOE_PCELLID1 (LM_GPIOE_BASE + LM_GPIO_PCELLID1_OFFSET) +# define LM_GPIOE_PCELLID2 (LM_GPIOE_BASE + LM_GPIO_PCELLID2_OFFSET) +# define LM_GPIOE_PCELLID3 (LM_GPIOE_BASE + LM_GPIO_PCELLID3_OFFSET) + +#elif LM_NPORTS > 5 + +# define LM_GPIOF_DATA (LM_GPIOF_BASE + LM_GPIO_DATA_OFFSET) +# define LM_GPIOF_DIR (LM_GPIOF_BASE + LM_GPIO_DIR_OFFSET) +# define LM_GPIOF_IS (LM_GPIOF_BASE + LM_GPIO_IS_OFFSET) +# define LM_GPIOF_IBE (LM_GPIOF_BASE + LM_GPIO_IBE_OFFSET) +# define LM_GPIOF_IEV (LM_GPIOF_BASE + LM_GPIO_IEV_OFFSET) +# define LM_GPIOF_IM (LM_GPIOF_BASE + LM_GPIO_IM_OFFSET) +# define LM_GPIOF_RIS (LM_GPIOF_BASE + LM_GPIO_RIS_OFFSET) +# define LM_GPIOF_MIS (LM_GPIOF_BASE + LM_GPIO_MIS_OFFSET) +# define LM_GPIOF_ICR (LM_GPIOF_BASE + LM_GPIO_ICR_OFFSET) +# define LM_GPIOF_AFSEL (LM_GPIOF_BASE + LM_GPIO_AFSEL_OFFSET) +# define LM_GPIOF_DR2R (LM_GPIOF_BASE + LM_GPIO_DR2R_OFFSET) +# define LM_GPIOF_DR4R (LM_GPIOF_BASE + LM_GPIO_DR4R_OFFSET) +# define LM_GPIOF_DR8R (LM_GPIOF_BASE + LM_GPIO_DR8R_OFFSET) +# define LM_GPIOF_ODR (LM_GPIOF_BASE + LM_GPIO_ODR_OFFSET) +# define LM_GPIOF_PUR (LM_GPIOF_BASE + LM_GPIO_PUR_OFFSET) +# define LM_GPIOF_PDR (LM_GPIOF_BASE + LM_GPIO_PDR_OFFSET) +# define LM_GPIOF_SLR (LM_GPIOF_BASE + LM_GPIO_SLR_OFFSET) +# define LM_GPIOF_DEN (LM_GPIOF_BASE + LM_GPIO_DEN_OFFSET) +# define LM_GPIOF_LOCK (LM_GPIOF_BASE + LM_GPIO_LOCK_OFFSET) +# define LM_GPIOF_CR (LM_GPIOF_BASE + LM_GPIO_CR_OFFSET) + +# ifdef LM4F +# define LM_GPIOF_AMSEL (LM_GPIOA_BASE + LM_GPIO_AMSEL_OFFSET) +# define LM_GPIOF_PCTL (LM_GPIOA_BASE + LM_GPIO_PCTL_OFFSET) +# define LM_GPIOF_ADCCTL (LM_GPIOA_BASE + LM_GPIO_ADCCTL_OFFSET) +# define LM_GPIOF_DMACTL (LM_GPIOA_BASE + LM_GPIO_DMACTL_OFFSET) +# endif + +# define LM_GPIOF_PERIPHID4 (LM_GPIOF_BASE + LM_GPIO_PERIPHID4_OFFSET) +# define LM_GPIOF_PERIPHID5 (LM_GPIOF_BASE + LM_GPIO_PERIPHID5_OFFSET) +# define LM_GPIOF_PERIPHID6 (LM_GPIOF_BASE + LM_GPIO_PERIPHID6_OFFSET) +# define LM_GPIOF_PERIPHID7 (LM_GPIOF_BASE + LM_GPIO_PERIPHID7_OFFSET) +# define LM_GPIOF_PERIPHID0 (LM_GPIOF_BASE + LM_GPIO_PERIPHID0_OFFSET) +# define LM_GPIOF_PERIPHID1 (LM_GPIOF_BASE + LM_GPIO_PERIPHID1_OFFSET) +# define LM_GPIOF_PERIPHID2 (LM_GPIOF_BASE + LM_GPIO_PERIPHID2_OFFSET) +# define LM_GPIOF_PERIPHID3 (LM_GPIOF_BASE + LM_GPIO_PERIPHID3_OFFSET) +# define LM_GPIOF_PCELLID0 (LM_GPIOF_BASE + LM_GPIO_PCELLID0_OFFSET) +# define LM_GPIOF_PCELLID1 (LM_GPIOF_BASE + LM_GPIO_PCELLID1_OFFSET) +# define LM_GPIOF_PCELLID2 (LM_GPIOF_BASE + LM_GPIO_PCELLID2_OFFSET) +# define LM_GPIOF_PCELLID3 (LM_GPIOF_BASE + LM_GPIO_PCELLID3_OFFSET) + +#elif LM_NPORTS > 6 + +# define LM_GPIOG_DATA (LM_GPIOG_BASE + LM_GPIO_DATA_OFFSET) +# define LM_GPIOG_DIR (LM_GPIOG_BASE + LM_GPIO_DIR_OFFSET) +# define LM_GPIOG_IS (LM_GPIOG_BASE + LM_GPIO_IS_OFFSET) +# define LM_GPIOG_IBE (LM_GPIOG_BASE + LM_GPIO_IBE_OFFSET) +# define LM_GPIOG_IEV (LM_GPIOG_BASE + LM_GPIO_IEV_OFFSET) +# define LM_GPIOG_IM (LM_GPIOG_BASE + LM_GPIO_IM_OFFSET) +# define LM_GPIOG_RIS (LM_GPIOG_BASE + LM_GPIO_RIS_OFFSET) +# define LM_GPIOG_MIS (LM_GPIOG_BASE + LM_GPIO_MIS_OFFSET) +# define LM_GPIOG_ICR (LM_GPIOG_BASE + LM_GPIO_ICR_OFFSET) +# define LM_GPIOG_AFSEL (LM_GPIOG_BASE + LM_GPIO_AFSEL_OFFSET) +# define LM_GPIOG_DR2R (LM_GPIOG_BASE + LM_GPIO_DR2R_OFFSET) +# define LM_GPIOG_DR4R (LM_GPIOG_BASE + LM_GPIO_DR4R_OFFSET) +# define LM_GPIOG_DR8R (LM_GPIOG_BASE + LM_GPIO_DR8R_OFFSET) +# define LM_GPIOG_ODR (LM_GPIOG_BASE + LM_GPIO_ODR_OFFSET) +# define LM_GPIOG_PUR (LM_GPIOG_BASE + LM_GPIO_PUR_OFFSET) +# define LM_GPIOG_PDR (LM_GPIOG_BASE + LM_GPIO_PDR_OFFSET) +# define LM_GPIOG_SLR (LM_GPIOG_BASE + LM_GPIO_SLR_OFFSET) +# define LM_GPIOG_DEN (LM_GPIOG_BASE + LM_GPIO_DEN_OFFSET) +# define LM_GPIOG_LOCK (LM_GPIOG_BASE + LM_GPIO_LOCK_OFFSET) +# define LM_GPIOG_CR (LM_GPIOG_BASE + LM_GPIO_CR_OFFSET) + +# ifdef LM4F +# define LM_GPIOG_AMSEL (LM_GPIOA_BASE + LM_GPIO_AMSEL_OFFSET) +# define LM_GPIOG_PCTL (LM_GPIOA_BASE + LM_GPIO_PCTL_OFFSET) +# define LM_GPIOG_ADCCTL (LM_GPIOA_BASE + LM_GPIO_ADCCTL_OFFSET) +# define LM_GPIOG_DMACTL (LM_GPIOA_BASE + LM_GPIO_DMACTL_OFFSET) +# endif + +# define LM_GPIOG_PERIPHID4 (LM_GPIOG_BASE + LM_GPIO_PERIPHID4_OFFSET) +# define LM_GPIOG_PERIPHID5 (LM_GPIOG_BASE + LM_GPIO_PERIPHID5_OFFSET) +# define LM_GPIOG_PERIPHID6 (LM_GPIOG_BASE + LM_GPIO_PERIPHID6_OFFSET) +# define LM_GPIOG_PERIPHID7 (LM_GPIOG_BASE + LM_GPIO_PERIPHID7_OFFSET) +# define LM_GPIOG_PERIPHID0 (LM_GPIOG_BASE + LM_GPIO_PERIPHID0_OFFSET) +# define LM_GPIOG_PERIPHID1 (LM_GPIOG_BASE + LM_GPIO_PERIPHID1_OFFSET) +# define LM_GPIOG_PERIPHID2 (LM_GPIOG_BASE + LM_GPIO_PERIPHID2_OFFSET) +# define LM_GPIOG_PERIPHID3 (LM_GPIOG_BASE + LM_GPIO_PERIPHID3_OFFSET) +# define LM_GPIOG_PCELLID0 (LM_GPIOG_BASE + LM_GPIO_PCELLID0_OFFSET) +# define LM_GPIOG_PCELLID1 (LM_GPIOG_BASE + LM_GPIO_PCELLID1_OFFSET) +# define LM_GPIOG_PCELLID2 (LM_GPIOG_BASE + LM_GPIO_PCELLID2_OFFSET) +# define LM_GPIOG_PCELLID3 (LM_GPIOG_BASE + LM_GPIO_PCELLID3_OFFSET) + +#elif LM_NPORTS > 7 + +# define LM_GPIOH_DATA (LM_GPIOH_BASE + LM_GPIO_DATA_OFFSET) +# define LM_GPIOH_DIR (LM_GPIOH_BASE + LM_GPIO_DIR_OFFSET) +# define LM_GPIOH_IS (LM_GPIOH_BASE + LM_GPIO_IS_OFFSET) +# define LM_GPIOH_IBE (LM_GPIOH_BASE + LM_GPIO_IBE_OFFSET) +# define LM_GPIOH_IEV (LM_GPIOH_BASE + LM_GPIO_IEV_OFFSET) +# define LM_GPIOH_IM (LM_GPIOH_BASE + LM_GPIO_IM_OFFSET) +# define LM_GPIOH_RIS (LM_GPIOH_BASE + LM_GPIO_RIS_OFFSET) +# define LM_GPIOH_MIS (LM_GPIOH_BASE + LM_GPIO_MIS_OFFSET) +# define LM_GPIOH_ICR (LM_GPIOH_BASE + LM_GPIO_ICR_OFFSET) +# define LM_GPIOH_AFSEL (LM_GPIOH_BASE + LM_GPIO_AFSEL_OFFSET) +# define LM_GPIOH_DR2R (LM_GPIOH_BASE + LM_GPIO_DR2R_OFFSET) +# define LM_GPIOH_DR4R (LM_GPIOH_BASE + LM_GPIO_DR4R_OFFSET) +# define LM_GPIOH_DR8R (LM_GPIOH_BASE + LM_GPIO_DR8R_OFFSET) +# define LM_GPIOH_ODR (LM_GPIOH_BASE + LM_GPIO_ODR_OFFSET) +# define LM_GPIOH_PUR (LM_GPIOH_BASE + LM_GPIO_PUR_OFFSET) +# define LM_GPIOH_PDR (LM_GPIOH_BASE + LM_GPIO_PDR_OFFSET) +# define LM_GPIOH_SLR (LM_GPIOH_BASE + LM_GPIO_SLR_OFFSET) +# define LM_GPIOH_DEN (LM_GPIOH_BASE + LM_GPIO_DEN_OFFSET) +# define LM_GPIOH_LOCK (LM_GPIOH_BASE + LM_GPIO_LOCK_OFFSET) +# define LM_GPIOH_CR (LM_GPIOH_BASE + LM_GPIO_CR_OFFSET) + +# ifdef LM4F +# define LM_GPIOH_AMSEL (LM_GPIOA_BASE + LM_GPIO_AMSEL_OFFSET) +# define LM_GPIOH_PCTL (LM_GPIOA_BASE + LM_GPIO_PCTL_OFFSET) +# define LM_GPIOH_ADCCTL (LM_GPIOA_BASE + LM_GPIO_ADCCTL_OFFSET) +# define LM_GPIOH_DMACTL (LM_GPIOA_BASE + LM_GPIO_DMACTL_OFFSET) +# endif + +# define LM_GPIOH_PERIPHID4 (LM_GPIOH_BASE + LM_GPIO_PERIPHID4_OFFSET) +# define LM_GPIOH_PERIPHID5 (LM_GPIOH_BASE + LM_GPIO_PERIPHID5_OFFSET) +# define LM_GPIOH_PERIPHID6 (LM_GPIOH_BASE + LM_GPIO_PERIPHID6_OFFSET) +# define LM_GPIOH_PERIPHID7 (LM_GPIOH_BASE + LM_GPIO_PERIPHID7_OFFSET) +# define LM_GPIOH_PERIPHID0 (LM_GPIOH_BASE + LM_GPIO_PERIPHID0_OFFSET) +# define LM_GPIOH_PERIPHID1 (LM_GPIOH_BASE + LM_GPIO_PERIPHID1_OFFSET) +# define LM_GPIOH_PERIPHID2 (LM_GPIOH_BASE + LM_GPIO_PERIPHID2_OFFSET) +# define LM_GPIOH_PERIPHID3 (LM_GPIOH_BASE + LM_GPIO_PERIPHID3_OFFSET) +# define LM_GPIOH_PCELLID0 (LM_GPIOH_BASE + LM_GPIO_PCELLID0_OFFSET) +# define LM_GPIOH_PCELLID1 (LM_GPIOH_BASE + LM_GPIO_PCELLID1_OFFSET) +# define LM_GPIOH_PCELLID2 (LM_GPIOH_BASE + LM_GPIO_PCELLID2_OFFSET) +# define LM_GPIOH_PCELLID3 (LM_GPIOH_BASE + LM_GPIO_PCELLID3_OFFSET) + +#elif LM_NPORTS > 8 + +# define LM_GPIOJ_DATA (LM_GPIOJ_BASE + LM_GPIO_DATA_OFFSET) +# define LM_GPIOJ_DIR (LM_GPIOJ_BASE + LM_GPIO_DIR_OFFSET) +# define LM_GPIOJ_IS (LM_GPIOJ_BASE + LM_GPIO_IS_OFFSET) +# define LM_GPIOJ_IBE (LM_GPIOJ_BASE + LM_GPIO_IBE_OFFSET) +# define LM_GPIOJ_IEV (LM_GPIOJ_BASE + LM_GPIO_IEV_OFFSET) +# define LM_GPIOJ_IM (LM_GPIOJ_BASE + LM_GPIO_IM_OFFSET) +# define LM_GPIOJ_RIS (LM_GPIOJ_BASE + LM_GPIO_RIS_OFFSET) +# define LM_GPIOJ_MIS (LM_GPIOJ_BASE + LM_GPIO_MIS_OFFSET) +# define LM_GPIOJ_ICR (LM_GPIOJ_BASE + LM_GPIO_ICR_OFFSET) +# define LM_GPIOJ_AFSEL (LM_GPIOJ_BASE + LM_GPIO_AFSEL_OFFSET) +# define LM_GPIOJ_DR2R (LM_GPIOJ_BASE + LM_GPIO_DR2R_OFFSET) +# define LM_GPIOJ_DR4R (LM_GPIOJ_BASE + LM_GPIO_DR4R_OFFSET) +# define LM_GPIOJ_DR8R (LM_GPIOJ_BASE + LM_GPIO_DR8R_OFFSET) +# define LM_GPIOJ_ODR (LM_GPIOJ_BASE + LM_GPIO_ODR_OFFSET) +# define LM_GPIOJ_PUR (LM_GPIOJ_BASE + LM_GPIO_PUR_OFFSET) +# define LM_GPIOJ_PDR (LM_GPIOJ_BASE + LM_GPIO_PDR_OFFSET) +# define LM_GPIOJ_SLR (LM_GPIOJ_BASE + LM_GPIO_SLR_OFFSET) +# define LM_GPIOJ_DEN (LM_GPIOJ_BASE + LM_GPIO_DEN_OFFSET) +# define LM_GPIOJ_LOCK (LM_GPIOJ_BASE + LM_GPIO_LOCK_OFFSET) +# define LM_GPIOJ_CR (LM_GPIOJ_BASE + LM_GPIO_CR_OFFSET) + +# ifdef LM4F +# define LM_GPIOJ_AMSEL (LM_GPIOA_BASE + LM_GPIO_AMSEL_OFFSET) +# define LM_GPIOJ_PCTL (LM_GPIOA_BASE + LM_GPIO_PCTL_OFFSET) +# define LM_GPIOJ_ADCCTL (LM_GPIOA_BASE + LM_GPIO_ADCCTL_OFFSET) +# define LM_GPIOJ_DMACTL (LM_GPIOA_BASE + LM_GPIO_DMACTL_OFFSET) +# endif + +# define LM_GPIOJ_PERIPHID4 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID4_OFFSET) +# define LM_GPIOJ_PERIPHID5 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID5_OFFSET) +# define LM_GPIOJ_PERIPHID6 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID6_OFFSET) +# define LM_GPIOJ_PERIPHID7 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID7_OFFSET) +# define LM_GPIOJ_PERIPHID0 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID0_OFFSET) +# define LM_GPIOJ_PERIPHID1 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID1_OFFSET) +# define LM_GPIOJ_PERIPHID2 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID2_OFFSET) +# define LM_GPIOJ_PERIPHID3 (LM_GPIOJ_BASE + LM_GPIO_PERIPHID3_OFFSET) +# define LM_GPIOJ_PCELLID0 (LM_GPIOJ_BASE + LM_GPIO_PCELLID0_OFFSET) +# define LM_GPIOJ_PCELLID1 (LM_GPIOJ_BASE + LM_GPIO_PCELLID1_OFFSET) +# define LM_GPIOJ_PCELLID2 (LM_GPIOJ_BASE + LM_GPIO_PCELLID2_OFFSET) +# define LM_GPIOJ_PCELLID3 (LM_GPIOJ_BASE + LM_GPIO_PCELLID3_OFFSET) + +#endif /* LM_NPORTS */ /************************************************************************************ * Public Types diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c index 94772b693..9307545a3 100644 --- a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c +++ b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c @@ -184,8 +184,9 @@ #define STM32_TRACEERR_NOEP 0x18 #define STM32_TRACEERR_NOTCONFIGURED 0x19 #define STM32_TRACEERR_EPOUTQEMPTY 0x1a -#define STM32_TRACEERR_EPINQEMPTY 0x1b +#define STM32_TRACEERR_EPINREQEMPTY 0x1b #define STM32_TRACEERR_NOOUTSETUP 0x1c +#define STM32_TRACEERR_POLLTIMEOUT 0x1d /* Trace interrupt codes */ @@ -1084,6 +1085,7 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, uint32_t regval; #ifdef ENABLE_DTXFSTS_POLLHACK int32_t timeout; + int avail; #endif uint8_t *buf; int nbytes; @@ -1113,7 +1115,7 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, privreq = stm32_rqpeek(privep); if (!privreq) { - usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPINQEMPTY), privep->epphy); + usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPINREQEMPTY), privep->epphy); /* There is no TX transfer in progress and no new pending TX * requests to send. To stop transmitting any data on a particular @@ -1221,18 +1223,28 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, #ifdef ENABLE_DTXFSTS_POLLHACK /* If ENABLE_DTXFSTS_POLLHACK is enabled , then poll DTXFSTS until - * space in the TxFIFO is available. If it doesn't become available, - * in a reasonable amount of time, then just pretend that it is. + * space in the TxFIFO is available. */ for (timeout = 250000; timeout > 0; timeout--) { - regval = stm32_getreg(regaddr); - if ((regval & OTGFS_DTXFSTS_MASK) >= nwords) + avail = stm32_getreg(regaddr) & OTGFS_DTXFSTS_MASK; + if (avail >= nwords) { break; } } + + /* If it did not become available in a reasonable amount of time, + * then just return. We should come back through this logic later + * anyway. + */ + + if (avail < nwords) + { + usbtrace(TRACE_DEVERROR(STM32_TRACEERR_POLLTIMEOUT), avail); + return; + } #else /* If ENABLE_DTXFSTS_POLLHACK is not enabled, then check once for * space in the TxFIFO. If space in the TxFIFO is not available, @@ -1290,11 +1302,12 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, if (privreq->req.xfrd >= privreq->req.len && !privep->zlp) { usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd); - stm32_req_complete(privep, OK); - /* The endpoint is no longer transferring data */ + /* We are finished with the request (although the transfer has not + * yet completed). + */ - privep->active = false; + stm32_req_complete(privep, OK); } } diff --git a/nuttx/include/nuttx/usb/usbdev_trace.h b/nuttx/include/nuttx/usb/usbdev_trace.h index ab3a5f4be..860f48983 100644 --- a/nuttx/include/nuttx/usb/usbdev_trace.h +++ b/nuttx/include/nuttx/usb/usbdev_trace.h @@ -104,6 +104,7 @@ #define TRACE_DEVUNINIT TRACE_EVENT(TRACE_INIT_ID, 0x0002) #define TRACE_DEVREGISTER TRACE_EVENT(TRACE_INIT_ID, 0x0003) #define TRACE_DEVUNREGISTER TRACE_EVENT(TRACE_INIT_ID, 0x0004) +#define TRACE_DEVINIT_USER TRACE_EVENT(TRACE_INIT_ID, 0x0005) /* First user-defined */ /* API calls (see usbdev.h) */ @@ -117,6 +118,7 @@ #define TRACE_EPCANCEL TRACE_EVENT(TRACE_EP_ID, 0x0008) #define TRACE_EPSTALL TRACE_EVENT(TRACE_EP_ID, 0x0009) #define TRACE_EPRESUME TRACE_EVENT(TRACE_EP_ID, 0x000a) +#define TRACE_EPAPI_USER TRACE_EVENT(TRACE_EP_ID, 0x000b) /* First user-defined */ #define TRACE_DEVALLOCEP TRACE_EVENT(TRACE_DEV_ID, 0x0001) #define TRACE_DEVFREEEP TRACE_EVENT(TRACE_DEV_ID, 0x0002) @@ -124,6 +126,7 @@ #define TRACE_DEVWAKEUP TRACE_EVENT(TRACE_DEV_ID, 0x0004) #define TRACE_DEVSELFPOWERED TRACE_EVENT(TRACE_DEV_ID, 0x0005) #define TRACE_DEVPULLUP TRACE_EVENT(TRACE_DEV_ID, 0x0006) +#define TRACE_DEVAPI_USER TRACE_EVENT(TRACE_DEV_ID, 0x0007) /* First user-defined */ #define TRACE_CLASSBIND TRACE_EVENT(TRACE_CLASS_ID, 0x0001) #define TRACE_CLASSUNBIND TRACE_EVENT(TRACE_CLASS_ID, 0x0002) @@ -135,6 +138,8 @@ #define TRACE_CLASSRDCOMPLETE TRACE_EVENT(TRACE_CLASS_ID, 0x0007) #define TRACE_CLASSWRCOMPLETE TRACE_EVENT(TRACE_CLASS_ID, 0x0008) +#define TRACE_CLASSAPI_USER TRACE_EVENT(TRACE_CLASS_ID, 0x0009) /* First user-defined */ + #define TRACE_CLASSAPI(id) TRACE_EVENT(TRACE_CLASSAPI_ID, id) #define TRACE_CLASSSTATE(id) TRACE_EVENT(TRACE_CLASSSTATE_ID, id) -- cgit v1.2.3 From b433eca18dc2a8e09f22d95b0f13e32dd2193e1a Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 30 Jan 2013 22:25:25 +0000 Subject: The STM32 F2/4 OTG FS device driver seems to be functional git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5587 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/src/stm32/stm32_otgfsdev.c | 76 ++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c index 9307545a3..17aa7313d 100644 --- a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c +++ b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c @@ -509,7 +509,7 @@ static void stm32_ep0out_ctrlsetup(FAR struct stm32_usbdev_s *priv); static void stm32_txfifo_write(FAR struct stm32_ep_s *privep, FAR uint8_t *buf, int nbytes); static void stm32_epin_transfer(FAR struct stm32_ep_s *privep, - FAR uint8_t *buf, int nbytes); + FAR uint8_t *buf, int nbytes); static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, FAR struct stm32_ep_s *privep); @@ -556,7 +556,9 @@ static inline void stm32_epout_interrupt(FAR struct stm32_usbdev_s *priv); static inline void stm32_epin_runtestmode(FAR struct stm32_usbdev_s *priv); static inline void stm32_epin(FAR struct stm32_usbdev_s *priv, uint8_t epno); +#ifndef ENABLE_DTXFSTS_POLLHACK static inline void stm32_epin_txfifoempty(FAR struct stm32_usbdev_s *priv, int epno); +#endif static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv); /* Other second level interrupt processing */ @@ -963,7 +965,7 @@ static void stm32_txfifo_write(FAR struct stm32_ep_s *privep, regval |= ((uint32_t)*buf++) << 16; regval |= ((uint32_t)*buf++) << 24; - /* Then write the packed data to the TxFIFO */ + /* Then write the packet data to the TxFIFO */ stm32_putreg(regval, regaddr); } @@ -1153,13 +1155,20 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, privep->zlp = true; } - /* Loop while there are still bytes to be transferred (or a zero-length- - * packet, ZLP, to be sent). The loop will also be terminated if there - * is insufficient space remaining in the TxFIFO to send a complete - * packet. + /* Add one more packet to the TxFIFO. We will wait for the transfer + * complete event before we add the next packet (or part of a packet + * to the TxFIFO). + * + * The documentation says that we can can multiple packets to the TxFIFO, + * but it seems that we need to get the transfer complete event before + * we can add the next (or maybe I have got something wrong?) */ +#if 0 while (privreq->req.xfrd < privreq->req.len || privep->zlp) +#else + if (privreq->req.xfrd < privreq->req.len || privep->zlp) +#endif { /* Get the number of bytes left to be sent in the request */ @@ -1240,8 +1249,11 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, * anyway. */ + DEBUGASSERT(avail < nwords); if (avail < nwords) { + /* We will probably not recover from what we are about to do */ + usbtrace(TRACE_DEVERROR(STM32_TRACEERR_POLLTIMEOUT), avail); return; } @@ -1265,9 +1277,11 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, empmsk |= OTGFS_DIEPEMPMSK(privep->epphy); stm32_putreg(empmsk, STM32_OTGFS_DIEPEMPMSK); - /* Terminate the transfer loop */ + /* Terminate the transfer loop. We will try again when the + * TxFIFO empty interrupt is received. + */ - break; + return; } #endif @@ -2698,17 +2712,19 @@ static inline void stm32_epin(FAR struct stm32_usbdev_s *priv, uint8_t epno) * ****************************************************************************/ +#ifndef ENABLE_DTXFSTS_POLLHACK static inline void stm32_epin_txfifoempty(FAR struct stm32_usbdev_s *priv, int epno) { FAR struct stm32_ep_s *privep = &priv->epin[epno]; /* Continue processing the write request queue. This may mean sending - * more dat from the exisiting request or terminating the current requests + * more data from the exisiting request or terminating the current requests * and (perhaps) starting the IN transfer from the next write request. */ stm32_epin_request(priv, privep); } +#endif /******************************************************************************* * Name: stm32_epin_interrupt @@ -2754,16 +2770,20 @@ static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv) mask = stm32_getreg(STM32_OTGFS_DIEPMSK); - /* Check for FIFO not empty. Bits n corresponds to endpoint n. - * That condition corresponds to bit 7 of the DIEPINT interrupt - * status register. + /* Check if the TxFIFO not empty interrupt is enabled for this + * endpoint in the DIEPMSK register. Bits n corresponds to + * endpoint n in the register. That condition corresponds to + * bit 7 of the DIEPINT interrupt status register. There is + * no TXFE bit in the mask register, so we fake one here. */ +#ifndef ENABLE_DTXFSTS_POLLHACK empty = stm32_getreg(STM32_OTGFS_DIEPEMPMSK); if ((empty & OTGFS_DIEPEMPMSK(epno)) != 0) { mask |= OTGFS_DIEPINT_TXFE; } +#endif /* Now, read the interrupt status and mask out all disabled * interrupts. @@ -2776,15 +2796,19 @@ static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv) if ((diepint & OTGFS_DIEPINT_XFRC) != 0) { - usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_XFRC), (uint16_t)diepint); - - /* It is possible that logic may be waiting for a the TxFIFO to become - * empty. We disable the TxFIFO empty interrupt here; it will be - * re-enabled if there is still insufficient space in the TxFIFO. + usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_XFRC), + (uint16_t)diepint); + +#ifndef ENABLE_DTXFSTS_POLLHACK + /* It is possible that logic may be waiting for a the + * TxFIFO to become empty. We disable the TxFIFO empty + * interrupt here; it will be re-enabled if there is still + * insufficient space in the TxFIFO. */ empty &= ~OTGFS_DIEPEMPMSK(epno); stm32_putreg(empty, STM32_OTGFS_DIEPEMPMSK); +#endif stm32_putreg(OTGFS_DIEPINT_XFRC, STM32_OTGFS_DIEPINT(epno)); /* IN transfer complete */ @@ -2836,12 +2860,13 @@ static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv) #endif /* Transmit FIFO empty */ +#ifndef ENABLE_DTXFSTS_POLLHACK if ((diepint & OTGFS_DIEPINT_TXFE) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_TXFE), (uint16_t)diepint); /* If we were waiting for TxFIFO to become empty, the we might have both - * XFRC and TXFE interrups pending. Since we do the same thing for both + * XFRC and TXFE interrupts pending. Since we do the same thing for both * cases, ignore the TXFE if we have already processed the XFRC. */ @@ -2863,6 +2888,7 @@ static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv) stm32_putreg(OTGFS_DIEPINT_TXFE, STM32_OTGFS_DIEPINT(epno)); } +#endif } epno++; @@ -4970,8 +4996,9 @@ static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv) /* At startup the core is in FS mode. */ - /* Disable the USB global interrupt by clearing GINTMSK in the global OTG - * FS AHB configuration register. + /* Disable global interrupts by clearing the GINTMASK bit in the GAHBCFG + * register; Set the TXFELVL bit in the GAHBCFG register so that TxFIFO + * interrupts will occur when the TxFIFO is truly empty (not just half full). */ stm32_putreg(OTGFS_GAHBCFG_TXFELVL, STM32_OTGFS_GAHBCFG); @@ -5087,6 +5114,7 @@ static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv) stm32_putreg(0, STM32_OTGFS_DIEPMSK); stm32_putreg(0, STM32_OTGFS_DOEPMSK); + stm32_putreg(0, STM32_OTGFS_DIEPEMPMSK); stm32_putreg(0xffffffff, STM32_OTGFS_DAINT); stm32_putreg(0, STM32_OTGFS_DAINTMSK); @@ -5168,10 +5196,13 @@ static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv) stm32_putreg(regval, STM32_OTGFS_GINTMSK); /* Enable the USB global interrupt by setting GINTMSK in the global OTG - * FS AHB configuration register. + * FS AHB configuration register; Set the TXFELVL bit in the GAHBCFG + * register so that TxFIFO interrupts will occur when the TxFIFO is truly + * empty (not just half full). */ - stm32_putreg(OTGFS_GAHBCFG_GINTMSK | OTGFS_GAHBCFG_TXFELVL, STM32_OTGFS_GAHBCFG); + stm32_putreg(OTGFS_GAHBCFG_GINTMSK | OTGFS_GAHBCFG_TXFELVL, + STM32_OTGFS_GAHBCFG); } /******************************************************************************* @@ -5327,6 +5358,7 @@ void up_usbuninitialize(void) stm32_putreg(0, STM32_OTGFS_DIEPMSK); stm32_putreg(0, STM32_OTGFS_DOEPMSK); + stm32_putreg(0, STM32_OTGFS_DIEPEMPMSK); stm32_putreg(0, STM32_OTGFS_DAINTMSK); stm32_putreg(0xffffffff, STM32_OTGFS_DAINT); -- cgit v1.2.3 From 94360f34746f039953b1465a2590d2d70d396282 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 30 Jan 2013 23:22:51 +0000 Subject: With the last fixes to the STM32 OTG FS driver, the old poll hack no longer seems necessary git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5588 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/TODO | 7 +--- nuttx/arch/arm/src/stm32/stm32_otgfsdev.c | 61 +++---------------------------- 2 files changed, 6 insertions(+), 62 deletions(-) diff --git a/nuttx/TODO b/nuttx/TODO index 6b2c6c883..b5958f397 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated January 28, 2013) +NuttX TODO List (Last updated January 30, 2013) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -1505,11 +1505,6 @@ o ARM/STM32 (arch/arm/src/stm32/) Status: Open Priority: Low - Title: STM32 F4 USB OTG FS DEVICE-SIDE DRIVER - Description: This driver is reported to be buggy and to need some TLC. - Status: Open - Priority: High - o AVR (arch/avr) ^^^^^^^^^^^^^^ diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c index 17aa7313d..a2de6d138 100644 --- a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c +++ b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c @@ -146,15 +146,6 @@ # error "CONFIG_USBDEV_EP3_TXFIFO_SIZE is out of range" #endif -/* REVISIT! This forces a hack that polls DTXFSTS for space in the Tx FIFO. - * Enabling this option is a BAD thing. It will cause inline waits inside - * of the USB interrupt handler. The correct way to handle this is to - * enable the correct TxFIFO interrupt and wait until the Tx FIFO is empty. - * Unfortunately, the interrupt driven logic is not working... Please fix! - */ - -#define ENABLE_DTXFSTS_POLLHACK 1 - /* Debug ***********************************************************************/ /* Trace error codes */ @@ -556,9 +547,7 @@ static inline void stm32_epout_interrupt(FAR struct stm32_usbdev_s *priv); static inline void stm32_epin_runtestmode(FAR struct stm32_usbdev_s *priv); static inline void stm32_epin(FAR struct stm32_usbdev_s *priv, uint8_t epno); -#ifndef ENABLE_DTXFSTS_POLLHACK static inline void stm32_epin_txfifoempty(FAR struct stm32_usbdev_s *priv, int epno); -#endif static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv); /* Other second level interrupt processing */ @@ -1085,10 +1074,8 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, struct stm32_req_s *privreq; uint32_t regaddr; uint32_t regval; -#ifdef ENABLE_DTXFSTS_POLLHACK int32_t timeout; int avail; -#endif uint8_t *buf; int nbytes; int nwords; @@ -1230,38 +1217,9 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, regaddr = STM32_OTGFS_DTXFSTS(privep->epphy); -#ifdef ENABLE_DTXFSTS_POLLHACK - /* If ENABLE_DTXFSTS_POLLHACK is enabled , then poll DTXFSTS until - * space in the TxFIFO is available. - */ - - for (timeout = 250000; timeout > 0; timeout--) - { - avail = stm32_getreg(regaddr) & OTGFS_DTXFSTS_MASK; - if (avail >= nwords) - { - break; - } - } - - /* If it did not become available in a reasonable amount of time, - * then just return. We should come back through this logic later - * anyway. - */ - - DEBUGASSERT(avail < nwords); - if (avail < nwords) - { - /* We will probably not recover from what we are about to do */ - - usbtrace(TRACE_DEVERROR(STM32_TRACEERR_POLLTIMEOUT), avail); - return; - } -#else - /* If ENABLE_DTXFSTS_POLLHACK is not enabled, then check once for - * space in the TxFIFO. If space in the TxFIFO is not available, - * then set up an interrupt to resume the transfer when the TxFIFO - * is empty. + /* Check for space in the TxFIFO. If space in the TxFIFO is not + * available, then set up an interrupt to resume the transfer when + * the TxFIFO is empty. */ regval = stm32_getreg(regaddr); @@ -1277,13 +1235,12 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, empmsk |= OTGFS_DIEPEMPMSK(privep->epphy); stm32_putreg(empmsk, STM32_OTGFS_DIEPEMPMSK); - /* Terminate the transfer loop. We will try again when the - * TxFIFO empty interrupt is received. + /* Terminate the transfer. We will try again when the TxFIFO empty + * interrupt is received. */ return; } -#endif /* Transfer data to the TxFIFO */ @@ -2712,7 +2669,6 @@ static inline void stm32_epin(FAR struct stm32_usbdev_s *priv, uint8_t epno) * ****************************************************************************/ -#ifndef ENABLE_DTXFSTS_POLLHACK static inline void stm32_epin_txfifoempty(FAR struct stm32_usbdev_s *priv, int epno) { FAR struct stm32_ep_s *privep = &priv->epin[epno]; @@ -2724,7 +2680,6 @@ static inline void stm32_epin_txfifoempty(FAR struct stm32_usbdev_s *priv, int e stm32_epin_request(priv, privep); } -#endif /******************************************************************************* * Name: stm32_epin_interrupt @@ -2777,13 +2732,11 @@ static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv) * no TXFE bit in the mask register, so we fake one here. */ -#ifndef ENABLE_DTXFSTS_POLLHACK empty = stm32_getreg(STM32_OTGFS_DIEPEMPMSK); if ((empty & OTGFS_DIEPEMPMSK(epno)) != 0) { mask |= OTGFS_DIEPINT_TXFE; } -#endif /* Now, read the interrupt status and mask out all disabled * interrupts. @@ -2799,7 +2752,6 @@ static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv) usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_XFRC), (uint16_t)diepint); -#ifndef ENABLE_DTXFSTS_POLLHACK /* It is possible that logic may be waiting for a the * TxFIFO to become empty. We disable the TxFIFO empty * interrupt here; it will be re-enabled if there is still @@ -2808,7 +2760,6 @@ static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv) empty &= ~OTGFS_DIEPEMPMSK(epno); stm32_putreg(empty, STM32_OTGFS_DIEPEMPMSK); -#endif stm32_putreg(OTGFS_DIEPINT_XFRC, STM32_OTGFS_DIEPINT(epno)); /* IN transfer complete */ @@ -2860,7 +2811,6 @@ static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv) #endif /* Transmit FIFO empty */ -#ifndef ENABLE_DTXFSTS_POLLHACK if ((diepint & OTGFS_DIEPINT_TXFE) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_TXFE), (uint16_t)diepint); @@ -2888,7 +2838,6 @@ static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv) stm32_putreg(OTGFS_DIEPINT_TXFE, STM32_OTGFS_DIEPINT(epno)); } -#endif } epno++; -- cgit v1.2.3 From 9de6f4d501826f76a5cce3631c6b98b1a6c01d0a Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 31 Jan 2013 16:52:20 +0000 Subject: Fix readline return value; Add support for removable serial devices git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5589 42af7a65-404d-4744-a932-0658087f49c3 --- apps/ChangeLog.txt | 3 + apps/system/readline/readline.c | 53 ++++++--- nuttx/ChangeLog | 6 +- nuttx/configs/stm32f4discovery/usbnsh/defconfig | 12 ++- nuttx/drivers/serial/Kconfig | 3 + nuttx/drivers/serial/serial.c | 137 ++++++++++++++++++++++-- nuttx/drivers/usbdev/Kconfig | 2 + nuttx/drivers/usbdev/cdcacm.c | 47 ++++++-- nuttx/drivers/usbdev/pl2303.c | 45 ++++++-- nuttx/include/nuttx/serial/serial.h | 77 ++++++++----- 10 files changed, 320 insertions(+), 65 deletions(-) diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 6a2c1d4c9..e64509be9 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -502,3 +502,6 @@ once when NSH starts; the .nshrc script will be executed for each session: Once for serial, once for each USB connection, once for each Telnet session. + * apps/system/readline: Correct realine return value. Was not + any returning special values when end-of-file or read errors + occur (it would return an empty string which is not very useful). diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c index f64049ed7..11c53cb50 100644 --- a/apps/system/readline/readline.c +++ b/apps/system/readline/readline.c @@ -132,23 +132,34 @@ static inline int readline_rawgetc(int infd) nread = read(infd, &buffer, 1); - /* Return EOF if the end of file (0) or error (-1) occurs. */ + /* Check for end-of-file. */ - if (nread < 1) + if (nread == 0) + { + /* Return zero on end-of-file */ + + return 0; + } + + /* Check if an error occurred */ + + else if (nread < 0) { /* EINTR is not really an error; it simply means that a signal we * received while watiing for intput. */ - if (nread == 0 || errno != EINTR) + int errcode = errno; + if (errcode != EINTR) + { - return EOF; + return -errcode; } } } while (nread < 1); - /* On success, returnt he character that was read */ + /* On success, return the character that was read */ return (int)buffer; } @@ -275,9 +286,29 @@ ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream) int ch = readline_rawgetc(infd); + /* Check for end-of-file or read error */ + + if (ch <= 0) + { + /* Did we already received some data? */ + + if (nch > 0) + { + /* Yes.. Terminate the line (which might be zero length) + * and return the data that was received. The end-of-file + * or error condition will be reported next time. + */ + + buf[nch] = '\0'; + return nch; + } + + return ch; + } + /* Are we processing a VT100 escape sequence */ - if (escape) + else if (escape) { /* Yes, is it an [, 3 byte sequence */ @@ -366,16 +397,6 @@ ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream) return nch; } - /* Check for end-of-file */ - - else if (ch == EOF) - { - /* Terminate the line (which might be zero length) */ - - buf[nch] = '\0'; - return nch; - } - /* Otherwise, check if the character is printable and, if so, put the * character in the line buffer */ diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 759177fca..5c41a0e9c 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4069,4 +4069,8 @@ this. * arch/arm/src/lm/chip/lm4f_memorymap.h: More LM4F changes from Jose Pablo Carballo. - + * drivers/serial/serial.c, include/nuttx/serial/serial.h, + drivers/usbdev/cdcacm.c, and drivers/pl2303.c: Add support for + removable serial devices (like USB serial). This support is enabled + by CONFIG_SERIAL_REMOVABLE and requires VBUS sensing support from + the board-specific logic. diff --git a/nuttx/configs/stm32f4discovery/usbnsh/defconfig b/nuttx/configs/stm32f4discovery/usbnsh/defconfig index ba704001a..f5e8e7d31 100644 --- a/nuttx/configs/stm32f4discovery/usbnsh/defconfig +++ b/nuttx/configs/stm32f4discovery/usbnsh/defconfig @@ -95,9 +95,7 @@ CONFIG_BOARD_LOOPSPERMSEC=16717 # # CONFIG_ARMV7M_TOOLCHAIN_ATOLLIC is not set # CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set -# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set # CONFIG_ARMV7M_TOOLCHAIN_CODEREDW is not set -# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y # CONFIG_ARMV7M_TOOLCHAIN_DEVKITARM is not set # CONFIG_ARMV7M_TOOLCHAIN_GNU_EABI is not set @@ -374,6 +372,7 @@ CONFIG_SPI_EXCHANGE=y # CONFIG_SERCOMM_CONSOLE is not set CONFIG_SERIAL=y # CONFIG_DEV_LOWCONSOLE is not set +CONFIG_SERIAL_REMOVABLE=y # CONFIG_16550_UART is not set CONFIG_ARCH_HAVE_USART2=y CONFIG_MCU_SERIAL=y @@ -458,6 +457,7 @@ CONFIG_CDCACM_PRODUCTSTR="CDC/ACM Serial" # # System Logging # +# CONFIG_SYSLOG_ENABLE is not set CONFIG_SYSLOG=y CONFIG_SYSLOG_CHAR=y CONFIG_SYSLOG_DEVPATH="/dev/ttyS0" @@ -686,6 +686,10 @@ CONFIG_NSH_NESTDEPTH=3 # CONFIG_NSH_DISABLEBG is not set CONFIG_NSH_CONSOLE=y # CONFIG_NSH_USBCONSOLE is not set + +# +# USB Trace Support +# # CONFIG_NSH_CONDEV is not set CONFIG_NSH_ARCHINIT=y @@ -736,3 +740,7 @@ CONFIG_READLINE_ECHO=y # Sysinfo # # CONFIG_SYSTEM_SYSINFO is not set + +# +# USB Monitor +# diff --git a/nuttx/drivers/serial/Kconfig b/nuttx/drivers/serial/Kconfig index a1e0dff49..119923a69 100644 --- a/nuttx/drivers/serial/Kconfig +++ b/nuttx/drivers/serial/Kconfig @@ -10,6 +10,9 @@ config DEV_LOWCONSOLE ---help--- Use the simple, low-level, write-only serial console driver (minimal support) +config SERIAL_REMOVABLE + bool + config 16550_UART bool "16550 UART Chip support" default n diff --git a/nuttx/drivers/serial/serial.c b/nuttx/drivers/serial/serial.c index 9708eb5bc..0548d8c25 100644 --- a/nuttx/drivers/serial/serial.c +++ b/nuttx/drivers/serial/serial.c @@ -1,7 +1,7 @@ /************************************************************************************ * drivers/serial/serial.c * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -157,7 +157,11 @@ static void uart_pollnotify(FAR uart_dev_t *dev, pollevent_t eventset) struct pollfd *fds = dev->fds[i]; if (fds) { +#ifdef CONFIG_SERIAL_REMOVABLE + fds->revents |= ((fds->events | (POLLERR|POLLHUP)) & eventset); +#else fds->revents |= (fds->events & eventset); +#endif if (fds->revents != 0) { fvdbg("Report events: %02x\n", fds->revents); @@ -219,6 +223,15 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch) uart_disabletxint(dev); irqrestore(flags); +#ifdef CONFIG_SERIAL_REMOVABLE + /* Check if the removable device is no longer connected */ + + if (dev->disconnected) + { + return -ENOTCONN; + } +#endif + /* Check if we were awakened by signal. */ if (ret < 0) @@ -279,6 +292,15 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t ssize_t nread = buflen; int ret; +#ifdef CONFIG_SERIAL_REMOVABLE + /* If the removable device is no longer connected, refuse to write to the device */ + + if (dev->disconnected) + { + return -ENOTCONN; + } +#endif + /* We may receive console writes through this path from interrupt handlers and * from debug output in the IDLE task! In these cases, we will need to do things * a little differently. @@ -395,6 +417,15 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen int16_t tail; int ret; +#ifdef CONFIG_SERIAL_REMOVABLE + /* If the removable device is no longer connected, refuse to read from the device */ + + if (dev->disconnected) + { + return -ENOTCONN; + } +#endif + /* Only one user can access dev->recv.tail at a time */ ret = uart_takesem(&dev->recv.sem, true); @@ -525,9 +556,15 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen ret = uart_takesem(&dev->recvsem, true); irqrestore(flags); - /* Was a signal received while waiting for data to be received? */ + /* Was a signal received while waiting for data to be + * received? Was a removable device disconnected? + */ +#ifdef CONFIG_SERIAL_REMOVABLE + if (ret < 0 || dev->disconnected) +#else if (ret < 0) +#endif { /* POSIX requires that we return after a signal is received. * If some bytes were read, we need to return the number of bytes @@ -541,7 +578,11 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen * set the errno value appropriately. */ +#ifdef CONFIG_SERIAL_REMOVABLE + recvd = dev->disconnected ? -ENOTCONN : -EINTR; +#else recvd = -EINTR; +#endif } break; @@ -656,12 +697,12 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) if (ndx != dev->xmit.tail) { - eventset |= POLLOUT; + eventset |= (fds->events & POLLOUT); } uart_givesem(&dev->xmit.sem); - /* Check if the receive buffer is empty + /* Check if the receive buffer is empty. * * Get exclusive access to the recv buffer indices. NOTE: that we do not * let this wait be interrupted by a signal (we probably should, but that @@ -671,11 +712,20 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) (void)uart_takesem(&dev->recv.sem, false); if (dev->recv.head != dev->recv.tail) { - eventset |= POLLIN; + eventset |= (fds->events & POLLIN); } uart_givesem(&dev->recv.sem); +#ifdef CONFIG_SERIAL_REMOVABLE + /* Check if a removable device has been disconnected. */ + + if (dev->disconnected) + { + eventset |= (POLLERR|POLLHUP); + } +#endif + if (eventset) { uart_pollnotify(dev, eventset); @@ -796,6 +846,15 @@ static int uart_open(FAR struct file *filep) uint8_t tmp; int ret; +#ifdef CONFIG_SERIAL_REMOVABLE + /* If the removable device is no longer connected, refuse to open the device */ + + if (dev->disconnected) + { + return -ENOTCONN; + } +#endif + /* If the port is the middle of closing, wait until the close is finished. * If a signal is received while we are waiting, then return EINTR. */ @@ -915,10 +974,12 @@ int uart_register(FAR const char *path, FAR uart_dev_t *dev) void uart_datareceived(FAR uart_dev_t *dev) { - /* Awaken any awaiting read() operations */ + /* Is there a thread waiting for read data? */ if (dev->recvwaiting) { + /* Yes... wake it up */ + dev->recvwaiting = false; (void)sem_post(&dev->recvsem); } @@ -942,8 +1003,12 @@ void uart_datareceived(FAR uart_dev_t *dev) void uart_datasent(FAR uart_dev_t *dev) { + /* Is there a thread waiting for space in xmit.buffer? */ + if (dev->xmitwaiting) { + /* Yes... wake it up */ + dev->xmitwaiting = false; (void)sem_post(&dev->xmitsem); } @@ -953,4 +1018,64 @@ void uart_datasent(FAR uart_dev_t *dev) uart_pollnotify(dev, POLLOUT); } +/************************************************************************************ + * Name: uart_connected + * + * Description: + * Serial devices (like USB serial) can be removed. In that case, the "upper + * half" serial driver must be informed that there is no longer a valid serial + * channel associated with the driver. + * + * In this case, the driver will terminate all pending transfers wint ENOTCONN and + * will refuse all further transactions while the "lower half" is disconnected. + * The driver will continue to be registered, but will be in an unusable state. + * + * Conversely, the "upper half" serial driver needs to know when the serial + * device is reconnected so that it can resume normal operations. + * + * Assumptions/Limitations: + * This function may be called from an interrupt handler. + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_REMOVABLE +void uart_connected(FAR uart_dev_t *dev, bool connected) +{ + /* Is the device disconnected? */ + + dev->disconnected = !connected; + if (!connected) + { + /* Yes.. wake up all waiting threads. Each thread should detect the + * disconnection and return the ENOTCONN error. + */ + + /* Is there a thread waiting for space in xmit.buffer? */ + + if (dev->xmitwaiting) + { + /* Yes... wake it up */ + + dev->xmitwaiting = false; + (void)sem_post(&dev->xmitsem); + } + + /* Is there a thread waiting for read data? */ + + if (dev->recvwaiting) + { + /* Yes... wake it up */ + + dev->recvwaiting = false; + (void)sem_post(&dev->recvsem); + } + + /* Notify all poll/select waiters that and hangup/error occurred */ + + uart_pollnotify(dev, (POLLERR|POLLHUP)); + } +} +#endif + + diff --git a/nuttx/drivers/usbdev/Kconfig b/nuttx/drivers/usbdev/Kconfig index e17b38022..0752bb791 100644 --- a/nuttx/drivers/usbdev/Kconfig +++ b/nuttx/drivers/usbdev/Kconfig @@ -150,6 +150,7 @@ endif menuconfig PL2303 bool "Prolific PL2303 serial/USB converter emulation" default n + select SERIAL_REMOVABLE ---help--- This logic emulates the Prolific PL2303 serial/USB converter @@ -222,6 +223,7 @@ endif menuconfig CDCACM bool "USB Modem (CDC ACM) support" default n + select SERIAL_REMOVABLE ---help--- Enables USB Modem (CDC ACM) support diff --git a/nuttx/drivers/usbdev/cdcacm.c b/nuttx/drivers/usbdev/cdcacm.c index 97c9d7c77..9b6fae1d6 100644 --- a/nuttx/drivers/usbdev/cdcacm.c +++ b/nuttx/drivers/usbdev/cdcacm.c @@ -570,6 +570,14 @@ static void cdcacm_resetconfig(FAR struct cdcacm_dev_s *priv) priv->config = CDCACM_CONFIGIDNONE; + /* Inform the "upper half" driver that there is no (functional) USB + * connection. + */ + +#ifdef CONFIG_SERIAL_REMOVABLE + uart_connected(&priv->serdev, false); +#endif + /* Disable endpoints. This should force completion of all pending * transfers. */ @@ -731,10 +739,20 @@ static int cdcacm_setconfig(FAR struct cdcacm_dev_s *priv, uint8_t config) usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSUBMIT), (uint16_t)-ret); goto errout; } + priv->nrdq++; } + /* We are successfully configured */ + priv->config = config; + + /* Inform the "upper half" driver that we are "open for business" */ + +#ifdef CONFIG_SERIAL_REMOVABLE + uart_connected(&priv->serdev, true); +#endif + return OK; errout: @@ -1575,12 +1593,20 @@ static void cdcacm_disconnect(FAR struct usbdevclass_driver_s *driver, } #endif - /* Reset the configuration */ + /* Inform the "upper half serial driver that we have lost the USB serial + * connection. + */ flags = irqsave(); +#ifdef CONFIG_SERIAL_REMOVABLE + uart_connected(&priv->serdev, false); +#endif + + /* Reset the configuration */ + cdcacm_resetconfig(priv); - /* Clear out all data in the circular buffer */ + /* Clear out all outgoing data in the circular buffer */ priv->serdev.xmit.head = 0; priv->serdev.xmit.tail = 0; @@ -2045,12 +2071,17 @@ int cdcacm_classobject(int minor, FAR struct usbdevclass_driver_s **classdev) /* Initialize the serial driver sub-structure */ - priv->serdev.recv.size = CONFIG_CDCACM_RXBUFSIZE; - priv->serdev.recv.buffer = priv->rxbuffer; - priv->serdev.xmit.size = CONFIG_CDCACM_TXBUFSIZE; - priv->serdev.xmit.buffer = priv->txbuffer; - priv->serdev.ops = &g_uartops; - priv->serdev.priv = priv; + /* The initial state is disconnected */ + +#ifdef CONFIG_SERIAL_REMOVABLE + priv->serdev.disconnected = true; +#endif + priv->serdev.recv.size = CONFIG_CDCACM_RXBUFSIZE; + priv->serdev.recv.buffer = priv->rxbuffer; + priv->serdev.xmit.size = CONFIG_CDCACM_TXBUFSIZE; + priv->serdev.xmit.buffer = priv->txbuffer; + priv->serdev.ops = &g_uartops; + priv->serdev.priv = priv; /* Initialize the USB class driver structure */ diff --git a/nuttx/drivers/usbdev/pl2303.c b/nuttx/drivers/usbdev/pl2303.c index d10539fa7..98163f133 100644 --- a/nuttx/drivers/usbdev/pl2303.c +++ b/nuttx/drivers/usbdev/pl2303.c @@ -983,6 +983,14 @@ static void usbclass_resetconfig(FAR struct pl2303_dev_s *priv) priv->config = PL2303_CONFIGIDNONE; + /* Inform the "upper half" driver that there is no (functional) USB + * connection. + */ + +#ifdef CONFIG_SERIAL_REMOVABLE + uart_connected(&priv->serdev, false); +#endif + /* Disable endpoints. This should force completion of all pending * transfers. */ @@ -1112,10 +1120,20 @@ static int usbclass_setconfig(FAR struct pl2303_dev_s *priv, uint8_t config) usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSUBMIT), (uint16_t)-ret); goto errout; } + priv->nrdq++; } + /* We are successfully configured */ + priv->config = config; + + /* Inform the "upper half" driver that we are "open for business" */ + +#ifdef CONFIG_SERIAL_REMOVABLE + uart_connected(&priv->serdev, true); +#endif + return OK; errout: @@ -1844,12 +1862,20 @@ static void usbclass_disconnect(FAR struct usbdevclass_driver_s *driver, } #endif - /* Reset the configuration */ + /* Inform the "upper half serial driver that we have lost the USB serial + * connection. + */ flags = irqsave(); +#ifdef CONFIG_SERIAL_REMOVABLE + uart_connected(&priv->serdev, false); +#endif + + /* Reset the configuration */ + usbclass_resetconfig(priv); - /* Clear out all data in the circular buffer */ + /* Clear out all outgoing data in the circular buffer */ priv->serdev.xmit.head = 0; priv->serdev.xmit.tail = 0; @@ -2185,12 +2211,15 @@ int usbdev_serialinitialize(int minor) /* Initialize the serial driver sub-structure */ - priv->serdev.recv.size = CONFIG_PL2303_RXBUFSIZE; - priv->serdev.recv.buffer = priv->rxbuffer; - priv->serdev.xmit.size = CONFIG_PL2303_TXBUFSIZE; - priv->serdev.xmit.buffer = priv->txbuffer; - priv->serdev.ops = &g_uartops; - priv->serdev.priv = priv; +#ifdef CONFIG_SERIAL_REMOVABLE + priv->serdev.disconnected = true; +#endif + priv->serdev.recv.size = CONFIG_PL2303_RXBUFSIZE; + priv->serdev.recv.buffer = priv->rxbuffer; + priv->serdev.xmit.size = CONFIG_PL2303_TXBUFSIZE; + priv->serdev.xmit.buffer = priv->txbuffer; + priv->serdev.ops = &g_uartops; + priv->serdev.priv = priv; /* Initialize the USB class driver structure */ diff --git a/nuttx/include/nuttx/serial/serial.h b/nuttx/include/nuttx/serial/serial.h index 1c40f1b6b..57bcf1f27 100644 --- a/nuttx/include/nuttx/serial/serial.h +++ b/nuttx/include/nuttx/serial/serial.h @@ -1,7 +1,7 @@ /************************************************************************************ * include/nuttx/serial/serial.h * - * Copyright (C) 2007-2008, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2008, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,7 @@ #include #include #include + #include /************************************************************************************ @@ -190,20 +191,23 @@ struct uart_ops_s struct uart_dev_s { - uint8_t open_count; /* Number of times the device has been opened */ - volatile bool xmitwaiting; /* true: User waiting for space in xmit.buffer */ - volatile bool recvwaiting; /* true: User waiting for data in recv.buffer */ - bool isconsole; /* true: This is the serial console */ - sem_t closesem; /* Locks out new open while close is in progress */ - sem_t xmitsem; /* Wakeup user waiting for space in xmit.buffer */ - sem_t recvsem; /* Wakeup user waiting for data in recv.buffer */ + uint8_t open_count; /* Number of times the device has been opened */ + volatile bool xmitwaiting; /* true: User waiting for space in xmit.buffer */ + volatile bool recvwaiting; /* true: User waiting for data in recv.buffer */ +#ifdef CONFIG_SERIAL_REMOVABLE + volatile bool disconnected; /* true: Removable device is not connected */ +#endif + bool isconsole; /* true: This is the serial console */ + sem_t closesem; /* Locks out new open while close is in progress */ + sem_t xmitsem; /* Wakeup user waiting for space in xmit.buffer */ + sem_t recvsem; /* Wakeup user waiting for data in recv.buffer */ #ifndef CONFIG_DISABLE_POLL - sem_t pollsem; /* Manages exclusive access to fds[] */ + sem_t pollsem; /* Manages exclusive access to fds[] */ #endif - struct uart_buffer_s xmit; /* Describes transmit buffer */ - struct uart_buffer_s recv; /* Describes receive buffer */ - FAR const struct uart_ops_s *ops; /* Arch-specific operations */ - FAR void *priv; /* Used by the arch-specific logic */ + struct uart_buffer_s xmit; /* Describes transmit buffer */ + struct uart_buffer_s recv; /* Describes receive buffer */ + FAR const struct uart_ops_s *ops; /* Arch-specific operations */ + FAR void *priv; /* Used by the arch-specific logic */ /* The following is a list if poll structures of threads waiting for * driver events. The 'struct pollfd' reference for each open is also @@ -213,26 +217,27 @@ struct uart_dev_s #ifndef CONFIG_DISABLE_POLL struct pollfd *fds[CONFIG_SERIAL_NPOLLWAITERS]; #endif - }; + typedef struct uart_dev_s uart_dev_t; /************************************************************************************ * Public Data ************************************************************************************/ -/************************************************************************************ - * Public Functions - ************************************************************************************/ - #undef EXTERN #if defined(__cplusplus) #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif +/************************************************************************************ + * Public Functions + ************************************************************************************/ + /************************************************************************************ * Name: uart_register * @@ -241,7 +246,7 @@ extern "C" { * ************************************************************************************/ -EXTERN int uart_register(FAR const char *path, FAR uart_dev_t *dev); +int uart_register(FAR const char *path, FAR uart_dev_t *dev); /************************************************************************************ * Name: uart_xmitchars @@ -254,7 +259,7 @@ EXTERN int uart_register(FAR const char *path, FAR uart_dev_t *dev); * ************************************************************************************/ -EXTERN void uart_xmitchars(FAR uart_dev_t *dev); +void uart_xmitchars(FAR uart_dev_t *dev); /************************************************************************************ * Name: uart_receivechars @@ -267,7 +272,7 @@ EXTERN void uart_xmitchars(FAR uart_dev_t *dev); * ************************************************************************************/ -EXTERN void uart_recvchars(FAR uart_dev_t *dev); +void uart_recvchars(FAR uart_dev_t *dev); /************************************************************************************ * Name: uart_datareceived @@ -279,7 +284,7 @@ EXTERN void uart_recvchars(FAR uart_dev_t *dev); * ************************************************************************************/ -EXTERN void uart_datareceived(FAR uart_dev_t *dev); +void uart_datareceived(FAR uart_dev_t *dev); /************************************************************************************ * Name: uart_datasent @@ -292,7 +297,31 @@ EXTERN void uart_datareceived(FAR uart_dev_t *dev); * ************************************************************************************/ -EXTERN void uart_datasent(FAR uart_dev_t *dev); +void uart_datasent(FAR uart_dev_t *dev); + +/************************************************************************************ + * Name: uart_connected + * + * Description: + * Serial devices (like USB serial) can be removed. In that case, the "upper + * half" serial driver must be informed that there is no longer a valid serial + * channel associated with the driver. + * + * In this case, the driver will terminate all pending transfers wint ENOTCONN and + * will refuse all further transactions while the "lower half" is disconnected. + * The driver will continue to be registered, but will be in an unusable state. + * + * Conversely, the "upper half" serial driver needs to know when the serial + * device is reconnected so that it can resume normal operations. + * + * Assumptions/Limitations: + * This function may be called from an interrupt handler. + * + ************************************************************************************/ + +#ifdef CONFIG_SERIAL_REMOVABLE +void uart_connected(FAR uart_dev_t *dev, bool connected); +#endif #undef EXTERN #if defined(__cplusplus) -- cgit v1.2.3 From 28a0241ccd48963a13638c1dfbef161ab1bf557e Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 31 Jan 2013 19:20:26 +0000 Subject: Missing calls to class SUSPEND/RESUME methods in all USB drivers git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5590 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c | 16 +++++ nuttx/arch/arm/src/lpc214x/lpc214x_usbdev.c | 18 +++++- nuttx/arch/arm/src/lpc31xx/lpc31_usbdev.c | 51 +++++++++++++--- nuttx/arch/arm/src/lpc43xx/lpc43_usb0dev.c | 46 ++++++++++++-- nuttx/arch/arm/src/stm32/stm32_otgfsdev.c | 23 +++++-- nuttx/arch/arm/src/stm32/stm32_usbdev.c | 14 +++++ nuttx/arch/avr/src/at90usb/at90usb_usbdev.c | 16 +++++ nuttx/arch/mips/src/pic32mx/pic32mx-usbdev.c | 19 +++++- nuttx/drivers/usbdev/cdcacm.c | 90 +++++++++++++++++++++++++++- nuttx/drivers/usbdev/pl2303.c | 84 ++++++++++++++++++++++++++ 10 files changed, 353 insertions(+), 24 deletions(-) diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c b/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c index b1ddb5928..753f82326 100644 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c @@ -2175,6 +2175,22 @@ static int lpc17_usbinterrupt(int irq, FAR void *context) { usbtrace(TRACE_INTDECODE(LPC17_TRACEINTID_SUSPENDCHG), (uint16_t)g_usbdev.devstatus); + + /* Inform the Class driver of the change */ + + if (priv->driver) + { + if (DEVSTATUS_SUSPEND(g_usbdev.devstatus)) + { + CLASS_SUSPEND(priv->driver, &priv->usbdev); + } + else + { + CLASS_RESUME(priv->driver, &priv->usbdev); + } + } + + /* TODO: Perform power management operations here. */ } /* Device reset */ diff --git a/nuttx/arch/arm/src/lpc214x/lpc214x_usbdev.c b/nuttx/arch/arm/src/lpc214x/lpc214x_usbdev.c index 78a5fe1c3..78dc86992 100644 --- a/nuttx/arch/arm/src/lpc214x/lpc214x_usbdev.c +++ b/nuttx/arch/arm/src/lpc214x/lpc214x_usbdev.c @@ -1,7 +1,7 @@ /******************************************************************************* * arch/arm/src/lpc214x/lpc214x_usbdev.c * - * Copyright (C) 2008-2010, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2010, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -2139,6 +2139,22 @@ static int lpc214x_usbinterrupt(int irq, FAR void *context) { usbtrace(TRACE_INTDECODE(LPC214X_TRACEINTID_SUSPENDCHG), (uint16_t)g_usbdev.devstatus); + + /* Inform the Class driver of the change */ + + if (priv->driver) + { + if (DEVSTATUS_SUSPEND(g_usbdev.devstatus)) + { + CLASS_SUSPEND(priv->driver, &priv->usbdev); + } + else + { + CLASS_RESUME(priv->driver, &priv->usbdev); + } + } + + /* TODO: Perform power management operations here. */ } /* Device reset */ diff --git a/nuttx/arch/arm/src/lpc31xx/lpc31_usbdev.c b/nuttx/arch/arm/src/lpc31xx/lpc31_usbdev.c index 386abb5b8..ddeb1bf6b 100644 --- a/nuttx/arch/arm/src/lpc31xx/lpc31_usbdev.c +++ b/nuttx/arch/arm/src/lpc31xx/lpc31_usbdev.c @@ -6,7 +6,7 @@ * * Part of the NuttX OS and based, in part, on the LPC2148 USB driver: * - * Copyright (C) 2010-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -160,8 +160,9 @@ #define LPC31_TRACEINTID_IFGETSTATUS 0x0015 #define LPC31_TRACEINTID_SETCONFIG 0x0016 #define LPC31_TRACEINTID_SETFEATURE 0x0017 -#define LPC31_TRACEINTID_SUSPENDCHG 0x0018 -#define LPC31_TRACEINTID_SYNCHFRAME 0x0019 +#define LPC31_TRACEINTID_SUSPENDED 0x0018 +#define LPC31_TRACEINTID_RESUMED 0x0019 +#define LPC31_TRACEINTID_SYNCHFRAME 0x001a /* Hardware interface **********************************************************/ @@ -309,6 +310,7 @@ struct lpc31_usbdev_s uint8_t selfpowered:1; /* 1: Device is self powered */ uint8_t paddrset:1; /* 1: Peripheral addr has been set */ uint8_t attached:1; /* 1: Host attached */ + uint8_t suspended:1; /* 1: Suspended */ uint32_t softprio; /* Bitset of high priority interrupts */ uint32_t epavail; /* Bitset of available endpoints */ #ifdef CONFIG_LPC31_USBDEV_FRAME_INTERRUPT @@ -1065,7 +1067,9 @@ static void lpc31_usbreset(struct lpc31_usbdev_s *priv) * driver should then accept any new configurations. */ if (priv->driver) + { CLASS_DISCONNECT(priv->driver, &priv->usbdev); + } /* Set the interrupt Threshold control interval to 0 */ lpc31_chgbits(USBDEV_USBCMD_ITC_MASK, USBDEV_USBCMD_ITCIMME, LPC31_USBDEV_USBCMD); @@ -1649,6 +1653,7 @@ static int lpc31_usbinterrupt(int irq, FAR void *context) usbtrace(TRACE_INTENTRY(LPC31_TRACEINTID_USB), 0); /* Read the interrupts and then clear them */ + disr = lpc31_getreg(LPC31_USBDEV_USBSTS); lpc31_putreg(disr, LPC31_USBDEV_USBSTS); @@ -1661,11 +1666,43 @@ static int lpc31_usbinterrupt(int irq, FAR void *context) usbtrace(TRACE_INTEXIT(LPC31_TRACEINTID_USB), 0); return OK; } - - if (disr & USBDEV_USBSTS_SLI) + + /* When the device controller enters a suspend state from an active state, + * the SLI bit will be set to a one. + */ + + if (!priv->suspended && (disr & USBDEV_USBSTS_SLI) != 0) { - // FIXME: what do we need to do here... - usbtrace(TRACE_INTDECODE(LPC31_TRACEINTID_SUSPENDCHG),0); + usbtrace(TRACE_INTDECODE(LPC31_TRACEINTID_SUSPENDED),0); + + /* Inform the Class driver of the suspend event */ + + priv->suspended = 1; + if (priv->driver) + { + CLASS_SUSPEND(priv->driver, &priv->usbdev); + } + + /* TODO: Perform power management operations here. */ + } + + /* The device controller clears the SLI bit upon exiting from a suspend + * state. This bit can also be cleared by software writing a one to it. + */ + + else if (priv->suspended && (disr & USBDEV_USBSTS_SLI) == 0) + { + usbtrace(TRACE_INTDECODE(LPC31_TRACEINTID_RESUMED),0); + + /* Inform the Class driver of the resume event */ + + priv->suspended = 0; + if (priv->driver) + { + CLASS_RESUME(priv->driver, &priv->usbdev); + } + + /* TODO: Perform power management operations here. */ } if (disr & USBDEV_USBSTS_PCI) diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_usb0dev.c b/nuttx/arch/arm/src/lpc43xx/lpc43_usb0dev.c index a40d6492d..d0af116d6 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_usb0dev.c +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_usb0dev.c @@ -1,7 +1,7 @@ /******************************************************************************* * arch/arm/src/lpc43xx/lpc43_usbdev.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Part of the NuttX OS and based, in part, on the LPC31xx USB driver: @@ -163,8 +163,9 @@ #define LPC43_TRACEINTID_IFGETSTATUS 0x0015 #define LPC43_TRACEINTID_SETCONFIG 0x0016 #define LPC43_TRACEINTID_SETFEATURE 0x0017 -#define LPC43_TRACEINTID_SUSPENDCHG 0x0018 -#define LPC43_TRACEINTID_SYNCHFRAME 0x0019 +#define LPC43_TRACEINTID_SUSPENDED 0x0018 +#define LPC43_TRACEINTID_RESUMED 0x0019 +#define LPC43_TRACEINTID_SYNCHFRAME 0x001a /* Hardware interface **********************************************************/ @@ -312,6 +313,7 @@ struct lpc43_usbdev_s uint8_t selfpowered:1; /* 1: Device is self powered */ uint8_t paddrset:1; /* 1: Peripheral addr has been set */ uint8_t attached:1; /* 1: Host attached */ + uint8_t suspended:1; /* 1: Suspended */ uint32_t softprio; /* Bitset of high priority interrupts */ uint32_t epavail; /* Bitset of available endpoints */ #ifdef CONFIG_LPC43_USBDEV_FRAME_INTERRUPT @@ -1665,10 +1667,42 @@ static int lpc43_usbinterrupt(int irq, FAR void *context) return OK; } - if (disr & USBDEV_USBSTS_SLI) + /* When the device controller enters a suspend state from an active state, + * the SLI bit will be set to a one. + */ + + if (!priv->suspended && (disr & USBDEV_USBSTS_SLI) != 0) + { + usbtrace(TRACE_INTDECODE(LPC43_TRACEINTID_SUSPENDED),0); + + /* Inform the Class driver of the suspend event */ + + priv->suspended = 1; + if (priv->driver) + { + CLASS_SUSPEND(priv->driver, &priv->usbdev); + } + + /* TODO: Perform power management operations here. */ + } + + /* The device controller clears the SLI bit upon exiting from a suspend + * state. This bit can also be cleared by software writing a one to it. + */ + + else if (priv->suspended && (disr & USBDEV_USBSTS_SLI) == 0) { - // FIXME: what do we need to do here... - usbtrace(TRACE_INTDECODE(LPC43_TRACEINTID_SUSPENDCHG),0); + usbtrace(TRACE_INTDECODE(LPC43_TRACEINTID_RESUMED),0); + + /* Inform the Class driver of the resume event */ + + priv->suspended = 0; + if (priv->driver) + { + CLASS_RESUME(priv->driver, &priv->usbdev); + } + + /* TODO: Perform power management operations here. */ } if (disr & USBDEV_USBSTS_PCI) diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c index a2de6d138..bcce3ce60 100644 --- a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c +++ b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c @@ -424,7 +424,6 @@ struct stm32_usbdev_s uint8_t stalled:1; /* 1: Protocol stalled */ uint8_t selfpowered:1; /* 1: Device is self powered */ - uint8_t connected:1; /* 1: Host connected */ uint8_t addressed:1; /* 1: Peripheral address has been set */ uint8_t configured:1; /* 1: Class driver has been configured */ uint8_t wakeup:1; /* 1: Device remote wake-up */ @@ -1074,8 +1073,6 @@ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, struct stm32_req_s *privreq; uint32_t regaddr; uint32_t regval; - int32_t timeout; - int avail; uint8_t *buf; int nbytes; int nwords; @@ -2874,6 +2871,13 @@ static inline void stm32_resumeinterrupt(FAR struct stm32_usbdev_s *priv) /* Restore full power -- whatever that means for this particular board */ stm32_usbsuspend((struct usbdev_s *)priv, true); + + /* Notify the class driver of the resume event */ + + if (priv->driver) + { + CLASS_RESUME(priv->driver, &priv->usbdev); + } } /******************************************************************************* @@ -2888,7 +2892,16 @@ static inline void stm32_suspendinterrupt(FAR struct stm32_usbdev_s *priv) { #ifdef CONFIG_USBDEV_LOWPOWER uint32_t regval; +#endif + /* Notify the class driver of the suspend event */ + + if (priv->driver) + { + CLASS_SUSPEND(priv->driver, &priv->usbdev); + } + +#ifdef CONFIG_USBDEV_LOWPOWER /* OTGFS_DSTS_SUSPSTS is set as long as the suspend condition is detected * on USB. Check if we are still have the suspend condition, that we are * connected to the host, and that we have been configured. @@ -2896,9 +2909,7 @@ static inline void stm32_suspendinterrupt(FAR struct stm32_usbdev_s *priv) regval = stm32_getreg(STM32_OTGFS_DSTS); - if ((regval & OTGFS_DSTS_SUSPSTS) != 0 && - priv->connected && - devstate == DEVSTATE_CONFIGURED) + if ((regval & OTGFS_DSTS_SUSPSTS) != 0 && devstate == DEVSTATE_CONFIGURED) { /* Switch off OTG FS clocking. Setting OTGFS_PCGCCTL_STPPCLK stops the * PHY clock. diff --git a/nuttx/arch/arm/src/stm32/stm32_usbdev.c b/nuttx/arch/arm/src/stm32/stm32_usbdev.c index 602de3824..d13ac8f96 100644 --- a/nuttx/arch/arm/src/stm32/stm32_usbdev.c +++ b/nuttx/arch/arm/src/stm32/stm32_usbdev.c @@ -2346,6 +2346,13 @@ static void stm32_suspend(struct stm32_usbdev_s *priv) { uint16_t regval; + /* Notify the class driver of the suspend event */ + + if (priv->driver) + { + CLASS_SUSPEND(priv->driver, &priv->usbdev); + } + /* Disable ESOF polling, disable the SUSP interrupt, and enable the WKUP * interrupt. Clear any pending WKUP interrupt. */ @@ -2411,6 +2418,13 @@ static void stm32_initresume(struct stm32_usbdev_s *priv) /* Reset FSUSP bit and enable normal interrupt handling */ stm32_putreg(STM32_CNTR_SETUP, STM32_USB_CNTR); + + /* Notify the class driver of the resume event */ + + if (priv->driver) + { + CLASS_RESUME(priv->driver, &priv->usbdev); + } } /**************************************************************************** diff --git a/nuttx/arch/avr/src/at90usb/at90usb_usbdev.c b/nuttx/arch/avr/src/at90usb/at90usb_usbdev.c index 89949e662..0e3ac6487 100644 --- a/nuttx/arch/avr/src/at90usb/at90usb_usbdev.c +++ b/nuttx/arch/avr/src/at90usb/at90usb_usbdev.c @@ -1955,6 +1955,15 @@ static inline void avr_gensuspend(void) { usbtrace(TRACE_INTENTRY(AVR_TRACEINTID_SUSPEND), UDIEN); + /* Notify the class driver of the suspend event */ + + if (g_usbdev.driver) + { + CLASS_SUSPEND(g_usbdev.driver, &g_usbdev.usbdev); + } + + /* Disable suspend event interrupts; enable wakeup event interrupt */ + UDIEN &= ~(1 << SUSPE); UDIEN |= (1 << WAKEUPE); @@ -1992,6 +2001,13 @@ static void avr_genwakeup(void) USBCON &= ~(1 << FRZCLK); UDIEN &= ~(1 << WAKEUPE); UDIEN |= (1 << SUSPE); + + /* Notify the class driver of the resume event */ + + if (g_usbdev.driver) + { + CLASS_RESUME(g_usbdev.driver, &g_usbdev.usbdev); + } } /******************************************************************************* diff --git a/nuttx/arch/mips/src/pic32mx/pic32mx-usbdev.c b/nuttx/arch/mips/src/pic32mx/pic32mx-usbdev.c index dafd35aa0..8d9f7c058 100644 --- a/nuttx/arch/mips/src/pic32mx/pic32mx-usbdev.c +++ b/nuttx/arch/mips/src/pic32mx/pic32mx-usbdev.c @@ -2901,6 +2901,13 @@ static void pic32mx_suspend(struct pic32mx_usbdev_s *priv) { uint16_t regval; + /* Notify the class driver of the suspend event */ + + if (priv->driver) + { + CLASS_SUSPEND(priv->driver, &priv->usbdev); + } + /* Enable the ACTV interrupt. * * NOTE: Do not clear UIRbits.ACTVIF here! Reason: ACTVIF is only @@ -2977,8 +2984,16 @@ static void pic32mx_resume(struct pic32mx_usbdev_s *priv) * PLL to lock. */ - pic32mx_putreg(USB_INT_IDLE, PIC32MX_USBOTG_IR); - irqrestore(flags); + pic32mx_putreg(USB_INT_IDLE, PIC32MX_USBOTG_IR); + + /* Notify the class driver of the resume event */ + + if (priv->driver) + { + CLASS_RESUME(priv->driver, &priv->usbdev); + } + + irqrestore(flags); } /**************************************************************************** diff --git a/nuttx/drivers/usbdev/cdcacm.c b/nuttx/drivers/usbdev/cdcacm.c index 9b6fae1d6..cb8679976 100644 --- a/nuttx/drivers/usbdev/cdcacm.c +++ b/nuttx/drivers/usbdev/cdcacm.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/usbdev/cdcacm.c * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -188,6 +188,12 @@ static int cdcacm_setup(FAR struct usbdevclass_driver_s *driver, size_t outlen); static void cdcacm_disconnect(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev); +#ifdef CONFIG_SERIAL_REMOVABLE +static void cdcacm_suspend(FAR struct usbdevclass_driver_s *driver, + FAR struct usbdev_s *dev); +static void cdcacm_resume(FAR struct usbdevclass_driver_s *driver, + FAR struct usbdev_s *dev); +#endif /* UART Operations **********************************************************/ @@ -211,8 +217,13 @@ static const struct usbdevclass_driverops_s g_driverops = cdcacm_unbind, /* unbind */ cdcacm_setup, /* setup */ cdcacm_disconnect, /* disconnect */ +#ifdef CONFIG_SERIAL_REMOVABLE + cdcacm_suspend, /* suspend */ + cdcacm_resume, /* resume */ +#else NULL, /* suspend */ NULL, /* resume */ +#endif }; /* Serial port **************************************************************/ @@ -841,6 +852,7 @@ static void cdcacm_rdcomplete(FAR struct usbdev_ep_s *ep, { usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDSUBMIT), (uint16_t)-req->result); } + irqrestore(flags); } @@ -950,6 +962,7 @@ static int cdcacm_bind(FAR struct usbdevclass_driver_s *driver, ret = -ENOMEM; goto errout; } + priv->ctrlreq->callback = cdcacm_ep0incomplete; /* Pre-allocate all endpoints... the endpoints will not be functional @@ -1621,6 +1634,79 @@ static void cdcacm_disconnect(FAR struct usbdevclass_driver_s *driver, #endif } +/**************************************************************************** + * Name: cdcacm_suspend + * + * Description: + * Handle the USB suspend event. + * + ****************************************************************************/ + +#ifdef CONFIG_SERIAL_REMOVABLE +static void cdcacm_suspend(FAR struct usbdevclass_driver_s *driver, + FAR struct usbdev_s *dev) +{ + FAR struct cdcacm_dev_s *priv; + + usbtrace(TRACE_CLASSSUSPEND, 0); + +#ifdef CONFIG_DEBUG + if (!driver || !dev) + { + usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); + return; + } +#endif + + /* Extract reference to private data */ + + priv = ((FAR struct cdcacm_driver_s*)driver)->dev; + + /* And let the "upper half" driver now that we are suspended */ + + uart_connected(&priv->serdev, false); +} +#endif + +/**************************************************************************** + * Name: cdcacm_resume + * + * Description: + * Handle the USB resume event. + * + ****************************************************************************/ + +#ifdef CONFIG_SERIAL_REMOVABLE +static void cdcacm_resume(FAR struct usbdevclass_driver_s *driver, + FAR struct usbdev_s *dev) +{ + FAR struct cdcacm_dev_s *priv; + + usbtrace(TRACE_CLASSRESUME, 0); + +#ifdef CONFIG_DEBUG + if (!driver || !dev) + { + usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); + return; + } +#endif + + /* Extract reference to private data */ + + priv = ((FAR struct cdcacm_driver_s*)driver)->dev; + + /* Are we still configured? */ + + if (priv->config != CDCACM_CONFIGIDNONE) + { + /* Yes.. let the "upper half" know that have resumed */ + + uart_connected(&priv->serdev, true); + } +} +#endif + /**************************************************************************** * Serial Device Methods ****************************************************************************/ @@ -2179,7 +2265,7 @@ int cdcacm_initialize(int minor, FAR void **handle) * * Description: * Un-initialize the USB storage class driver. This function is used - * internally by the USB composite driver to unitialized the CDC/ACM + * internally by the USB composite driver to unitialize the CDC/ACM * driver. This same interface is available (with an untyped input * parameter) when the CDC/ACM driver is used standalone. * diff --git a/nuttx/drivers/usbdev/pl2303.c b/nuttx/drivers/usbdev/pl2303.c index 98163f133..7b07a9cba 100644 --- a/nuttx/drivers/usbdev/pl2303.c +++ b/nuttx/drivers/usbdev/pl2303.c @@ -343,6 +343,12 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, size_t outlen); static void usbclass_disconnect(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev); +#ifdef CONFIG_SERIAL_REMOVABLE +static void usbclass_suspend(FAR struct usbdevclass_driver_s *driver, + FAR struct usbdev_s *dev); +static void usbclass_resume(FAR struct usbdevclass_driver_s *driver, + FAR struct usbdev_s *dev); +#endif /* Serial port *************************************************************/ @@ -366,8 +372,13 @@ static const struct usbdevclass_driverops_s g_driverops = usbclass_unbind, /* unbind */ usbclass_setup, /* setup */ usbclass_disconnect, /* disconnect */ +#ifdef CONFIG_SERIAL_REMOVABLE + usbclass_suspend, /* suspend */ + usbclass_resume, /* resume */ +#else NULL, /* suspend */ NULL, /* resume */ +#endif }; /* Serial port *************************************************************/ @@ -1888,6 +1899,79 @@ static void usbclass_disconnect(FAR struct usbdevclass_driver_s *driver, DEV_CONNECT(dev); } +/**************************************************************************** + * Name: usbclass_suspend + * + * Description: + * Handle the USB suspend event. + * + ****************************************************************************/ + +#ifdef CONFIG_SERIAL_REMOVABLE +static void usbclass_suspend(FAR struct usbdevclass_driver_s *driver, + FAR struct usbdev_s *dev) +{ + FAR struct cdcacm_dev_s *priv; + + usbtrace(TRACE_CLASSSUSPEND, 0); + +#ifdef CONFIG_DEBUG + if (!driver || !dev) + { + usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); + return; + } +#endif + + /* Extract reference to private data */ + + priv = ((FAR struct cdcacm_driver_s*)driver)->dev; + + /* And let the "upper half" driver now that we are suspended */ + + uart_connected(&priv->serdev, false); +} +#endif + +/**************************************************************************** + * Name: usbclass_resume + * + * Description: + * Handle the USB resume event. + * + ****************************************************************************/ + +#ifdef CONFIG_SERIAL_REMOVABLE +static void usbclass_resume(FAR struct usbdevclass_driver_s *driver, + FAR struct usbdev_s *dev) +{ + FAR struct cdcacm_dev_s *priv; + + usbtrace(TRACE_CLASSRESUME, 0); + +#ifdef CONFIG_DEBUG + if (!driver || !dev) + { + usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0); + return; + } +#endif + + /* Extract reference to private data */ + + priv = ((FAR struct cdcacm_driver_s*)driver)->dev; + + /* Are we still configured? */ + + if (priv->config != PL2303_CONFIGIDNONE) + { + /* Yes.. let the "upper half" know that have resumed */ + + uart_connected(&priv->serdev, true); + } +} +#endif + /**************************************************************************** * Serial Device Methods ****************************************************************************/ -- cgit v1.2.3 From 966e801032745429ec2f28f9e5ab0b3fc8a68d3d Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 31 Jan 2013 23:29:34 +0000 Subject: Misc clean; mark assertions as non-returning; allow toolchain prefix to be overriden from make command line git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5591 42af7a65-404d-4744-a932-0658087f49c3 --- apps/system/readline/readline.c | 1 - nuttx/ChangeLog | 5 ++++ nuttx/README.txt | 11 ++++++-- nuttx/arch/8051/src/up_assert.c | 3 ++- nuttx/arch/arm/src/arm/Toolchain.defs | 26 +++++++++---------- nuttx/arch/arm/src/arm/up_assert.c | 3 ++- nuttx/arch/arm/src/armv7-m/Toolchain.defs | 42 +++++++++++++++---------------- nuttx/arch/arm/src/armv7-m/up_assert.c | 3 ++- nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c | 2 +- nuttx/arch/avr/src/avr/Toolchain.defs | 10 ++++---- nuttx/arch/avr/src/common/up_assert.c | 3 ++- nuttx/arch/hc/src/m9s12/m9s12_assert.c | 3 ++- nuttx/arch/mips/src/mips32/Toolchain.defs | 24 +++++++++--------- nuttx/arch/mips/src/mips32/up_assert.c | 5 ++-- nuttx/arch/sh/src/common/up_assert.c | 3 ++- nuttx/arch/x86/src/common/up_assert.c | 3 ++- nuttx/drivers/serial/serial.c | 7 +++++- nuttx/include/assert.h | 21 ++++++++++------ 18 files changed, 102 insertions(+), 73 deletions(-) diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c index 11c53cb50..bac7eee8c 100644 --- a/apps/system/readline/readline.c +++ b/apps/system/readline/readline.c @@ -151,7 +151,6 @@ static inline int readline_rawgetc(int infd) int errcode = errno; if (errcode != EINTR) - { return -errcode; } diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 5c41a0e9c..26b82fde4 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4074,3 +4074,8 @@ removable serial devices (like USB serial). This support is enabled by CONFIG_SERIAL_REMOVABLE and requires VBUS sensing support from the board-specific logic. + * arch/*/src/*/Toolchain.defs: Change assignment so that we can + override CROSSDEV with a make command line argument. + * include/assert.h: Mark assertion functions as non-returning. + * arch/*/src/*/up_assert.h: Mark _up_assert() as non-returning. + diff --git a/nuttx/README.txt b/nuttx/README.txt index 340087791..571f8e04e 100644 --- a/nuttx/README.txt +++ b/nuttx/README.txt @@ -523,8 +523,15 @@ NuttX Buildroot Toolchain Disadvantages: This tool chain is not was well supported as some other toolchains. GNU tools are not my priority and so the buildroot tools - often get behind. For example, the is still no EABI support in the - NuttX buildroot toolchain for ARM. + often get behind. For example, until recently there was no EABI support + in the NuttX buildroot toolchain for ARM. + + NOTE: For Cortex-M3/4, there are OABI and EABI versions of the buildroot + toolchains. If you are using the older OABI toolchain the prefix for + the tools will be arm-nuttx-elf-; for the EABI toolchin the prefix will + be arm-nuttx-eabi-. If you are using the older OABI toolchain with + an ARM Cortex-M3/4, you will need to set CONFIG_ARMV7M_OABI_TOOLCHAIN + in the .config file in order to pick the right tool prefix. SHELLS ^^^^^^ diff --git a/nuttx/arch/8051/src/up_assert.c b/nuttx/arch/8051/src/up_assert.c index 46d731041..5e59d6af0 100644 --- a/nuttx/arch/8051/src/up_assert.c +++ b/nuttx/arch/8051/src/up_assert.c @@ -65,7 +65,8 @@ * Name: _up_assert ************************************************************************/ -static void _up_assert(int errorcode) /* noreturn_function */ +static void _up_assert(int errorcode) noreturn_function; +static void _up_assert(int errorcode) { /* Are we in an interrupt handler or the idle task? */ diff --git a/nuttx/arch/arm/src/arm/Toolchain.defs b/nuttx/arch/arm/src/arm/Toolchain.defs index daa825842..cd16d7ec9 100644 --- a/nuttx/arch/arm/src/arm/Toolchain.defs +++ b/nuttx/arch/arm/src/arm/Toolchain.defs @@ -1,7 +1,7 @@ ############################################################################ # arch/arm/src/armv/Toolchain.defs # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -103,11 +103,11 @@ endif ifeq ($(CONFIG_ARM_TOOLCHAIN),BUILDROOT) ifeq ($(CONFIG_ARM_OABI_TOOLCHAIN),y) - CROSSDEV = arm-nuttx-elf- - ARCROSSDEV = arm-nuttx-elf- + CROSSDEV ?= arm-nuttx-elf- + ARCROSSDEV ?= arm-nuttx-elf- else - CROSSDEV = arm-nuttx-eabi- - ARCROSSDEV = arm-nuttx-eabi- + CROSSDEV ?= arm-nuttx-eabi- + ARCROSSDEV ?= arm-nuttx-eabi- endif MAXOPTIMIZATION = -Os endif @@ -115,16 +115,16 @@ endif # CodeSourcery under Linux ifeq ($(CONFIG_ARM_TOOLCHAIN),CODESOURCERYL) - CROSSDEV = arm-none-eabi- - ARCROSSDEV = arm-none-eabi- + CROSSDEV ?= arm-none-eabi- + ARCROSSDEV ?= arm-none-eabi- MAXOPTIMIZATION = -O2 endif # CodeSourcery under Windows ifeq ($(CONFIG_ARM_TOOLCHAIN),CODESOURCERYW) - CROSSDEV = arm-none-eabi- - ARCROSSDEV = arm-none-eabi- + CROSSDEV ?= arm-none-eabi- + ARCROSSDEV ?= arm-none-eabi- MAXOPTIMIZATION = -O2 ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y @@ -134,8 +134,8 @@ endif # devkitARM under Windows ifeq ($(CONFIG_ARM_TOOLCHAIN),DEVKITARM) - CROSSDEV = arm-eabi- - ARCROSSDEV = arm-eabi- + CROSSDEV ?= arm-eabi- + ARCROSSDEV ?= arm-eabi- ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y endif @@ -144,8 +144,8 @@ endif # Generic GNU EABI toolchain on OS X, Linux or any typical Posix system ifeq ($(CONFIG_ARM_TOOLCHAIN),GNU_EABI) - CROSSDEV = arm-none-eabi- - ARCROSSDEV = arm-none-eabi- + CROSSDEV ?= arm-none-eabi- + ARCROSSDEV ?= arm-none-eabi- MAXOPTIMIZATION = -O3 endif diff --git a/nuttx/arch/arm/src/arm/up_assert.c b/nuttx/arch/arm/src/arm/up_assert.c index 3cc79df01..5f713c34d 100644 --- a/nuttx/arch/arm/src/arm/up_assert.c +++ b/nuttx/arch/arm/src/arm/up_assert.c @@ -252,7 +252,8 @@ static void up_dumpstate(void) * Name: _up_assert ****************************************************************************/ -static void _up_assert(int errorcode) /* noreturn_function */ +static void _up_assert(int errorcode) noreturn_function; +static void _up_assert(int errorcode) { /* Are we in an interrupt handler or the idle task? */ diff --git a/nuttx/arch/arm/src/armv7-m/Toolchain.defs b/nuttx/arch/arm/src/armv7-m/Toolchain.defs index 45ee9e36c..4de5b49f4 100644 --- a/nuttx/arch/arm/src/armv7-m/Toolchain.defs +++ b/nuttx/arch/arm/src/armv7-m/Toolchain.defs @@ -1,7 +1,7 @@ ############################################################################ # arch/arm/src/armv7-m/Toolchain.defs # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -141,8 +141,8 @@ endif # Atollic toolchain under Windows ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),ATOLLIC) - CROSSDEV = arm-atollic-eabi- - ARCROSSDEV = arm-atollic-eabi- + CROSSDEV ?= arm-atollic-eabi- + ARCROSSDEV ?= arm-atollic-eabi- ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y endif @@ -161,12 +161,12 @@ endif ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),BUILDROOT) ifeq ($(CONFIG_ARMV7M_OABI_TOOLCHAIN),y) - CROSSDEV = arm-nuttx-elf- - ARCROSSDEV = arm-nuttx-elf- + CROSSDEV ?= arm-nuttx-elf- + ARCROSSDEV ?= arm-nuttx-elf- ARCHCPUFLAGS = -mtune=cortex-m3 -march=armv7-m -mfloat-abi=soft else - CROSSDEV = arm-nuttx-eabi- - ARCROSSDEV = arm-nuttx-eabi- + CROSSDEV ?= arm-nuttx-eabi- + ARCROSSDEV ?= arm-nuttx-eabi- ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft endif MAXOPTIMIZATION = -Os @@ -175,8 +175,8 @@ endif # Code Red RedSuite under Linux ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODEREDL) - CROSSDEV = arm-none-eabi- - ARCROSSDEV = arm-none-eabi- + CROSSDEV ?= arm-none-eabi- + ARCROSSDEV ?= arm-none-eabi- ifeq ($(CONFIG_ARCH_CORTEXM4),y) ifeq ($(CONFIG_ARCH_FPU),y) ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard @@ -191,8 +191,8 @@ endif # Code Red RedSuite under Windows ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODEREDW) - CROSSDEV = arm-none-eabi- - ARCROSSDEV = arm-none-eabi- + CROSSDEV ?= arm-none-eabi- + ARCROSSDEV ?= arm-none-eabi- ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y endif @@ -210,8 +210,8 @@ endif # CodeSourcery under Linux ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODESOURCERYL) - CROSSDEV = arm-none-eabi- - ARCROSSDEV = arm-none-eabi- + CROSSDEV ?= arm-none-eabi- + ARCROSSDEV ?= arm-none-eabi- ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft MAXOPTIMIZATION = -O2 endif @@ -219,8 +219,8 @@ endif # CodeSourcery under Windows ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODESOURCERYW) - CROSSDEV = arm-none-eabi- - ARCROSSDEV = arm-none-eabi- + CROSSDEV ?= arm-none-eabi- + ARCROSSDEV ?= arm-none-eabi- ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y endif @@ -230,8 +230,8 @@ endif # devkitARM under Windows ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),DEVKITARM) - CROSSDEV = arm-eabi- - ARCROSSDEV = arm-eabi- + CROSSDEV ?= arm-eabi- + ARCROSSDEV ?= arm-eabi- ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y endif @@ -241,8 +241,8 @@ endif # Generic GNU EABI toolchain on OS X, Linux or any typical Posix system ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),GNU_EABI) - CROSSDEV = arm-none-eabi- - ARCROSSDEV = arm-none-eabi- + CROSSDEV ?= arm-none-eabi- + ARCROSSDEV ?= arm-none-eabi- MAXOPTIMIZATION = -O3 ifeq ($(CONFIG_ARCH_CORTEXM4),y) ifeq ($(CONFIG_ARCH_FPU),y) @@ -258,8 +258,8 @@ endif # Raisonance RIDE7 under Windows ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),RAISONANCE) - CROSSDEV = arm-none-eabi- - ARCROSSDEV = arm-none-eabi- + CROSSDEV ?= arm-none-eabi- + ARCROSSDEV ?= arm-none-eabi- ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y endif diff --git a/nuttx/arch/arm/src/armv7-m/up_assert.c b/nuttx/arch/arm/src/armv7-m/up_assert.c index 8e29bfe80..b40b1090c 100644 --- a/nuttx/arch/arm/src/armv7-m/up_assert.c +++ b/nuttx/arch/arm/src/armv7-m/up_assert.c @@ -267,7 +267,8 @@ static void up_dumpstate(void) * Name: _up_assert ****************************************************************************/ -static void _up_assert(int errorcode) /* noreturn_function */ +static void _up_assert(int errorcode) noreturn_function; +static void _up_assert(int errorcode) { /* Are we in an interrupt handler or the idle task? */ diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c b/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c index e3085ff78..84c4e7951 100644 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_gpio.c @@ -452,7 +452,7 @@ static inline int lpc17_configinput(lpc17_pinset_t cfgset, unsigned int port, un #endif } -#ifdef defined(LPC176x) +#if defined(LPC176x) /* Set up PINSEL registers */ /* Configure as GPIO */ diff --git a/nuttx/arch/avr/src/avr/Toolchain.defs b/nuttx/arch/avr/src/avr/Toolchain.defs index 96eb273f6..09035a30f 100644 --- a/nuttx/arch/avr/src/avr/Toolchain.defs +++ b/nuttx/arch/avr/src/avr/Toolchain.defs @@ -1,7 +1,7 @@ ############################################################################ # arch/avr/src/avr/Toolchain.defs # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -82,7 +82,7 @@ endif # NuttX buildroot GCC toolchain under Linux or Cygwin ifeq ($(CONFIG_AVR_TOOLCHAIN),BUILDROOT) - CROSSDEV = avr-nuttx-elf- + CROSSDEV ?= avr-nuttx-elf- MAXOPTIMIZATION = -O2 LDFLAGS += -nostartfiles -nodefaultlibs endif @@ -90,7 +90,7 @@ endif # AVR CrossPack under OS X ifeq ($(CONFIG_AVR_TOOLCHAIN),CROSSPACK) - CROSSDEV = avr- + CROSSDEV ?= avr- MAXOPTIMIZATION = -O2 LDFLAGS += -nostartfiles -nodefaultlibs endif @@ -98,7 +98,7 @@ endif # GCC toolchain under Linux ifeq ($(CONFIG_AVR_TOOLCHAIN),LINUXGCC) - CROSSDEV = avr- + CROSSDEV ?= avr- MAXOPTIMIZATION = -O2 LDFLAGS += -nostartfiles -nodefaultlibs endif @@ -106,7 +106,7 @@ endif # WinAVR toolchain under Windows/Cygwin ifeq ($(CONFIG_AVR_TOOLCHAIN),WINAVR) - CROSSDEV = avr- + CROSSDEV ?= avr- ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y endif diff --git a/nuttx/arch/avr/src/common/up_assert.c b/nuttx/arch/avr/src/common/up_assert.c index 3e90094eb..be7f635e8 100644 --- a/nuttx/arch/avr/src/common/up_assert.c +++ b/nuttx/arch/avr/src/common/up_assert.c @@ -90,7 +90,8 @@ * Name: _up_assert ****************************************************************************/ -static void _up_assert(int errorcode) /* noreturn_function */ +static void _up_assert(int errorcode) noreturn_function; +static void _up_assert(int errorcode) { /* Are we in an interrupt handler or the idle task? */ diff --git a/nuttx/arch/hc/src/m9s12/m9s12_assert.c b/nuttx/arch/hc/src/m9s12/m9s12_assert.c index 65cc75590..37ad5e30d 100644 --- a/nuttx/arch/hc/src/m9s12/m9s12_assert.c +++ b/nuttx/arch/hc/src/m9s12/m9s12_assert.c @@ -247,7 +247,8 @@ static void up_dumpstate(void) * Name: _up_assert ****************************************************************************/ -static void _up_assert(int errorcode) /* noreturn_function */ +static void _up_assert(int errorcode) noreturn_function; +static void _up_assert(int errorcode) { /* Are we in an interrupt handler or the idle task? */ diff --git a/nuttx/arch/mips/src/mips32/Toolchain.defs b/nuttx/arch/mips/src/mips32/Toolchain.defs index bd509b86c..09c68db12 100644 --- a/nuttx/arch/mips/src/mips32/Toolchain.defs +++ b/nuttx/arch/mips/src/mips32/Toolchain.defs @@ -1,7 +1,7 @@ ############################################################################ # arch/mips/src/mips32/Toolchain.defs # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -103,7 +103,7 @@ endif # including Pinguino mips-elf toolchain ifeq ($(CONFIG_MIPS32_TOOLCHAIN),GNU_ELF) - CROSSDEV = mips-elf- + CROSSDEV ?= mips-elf- MAXOPTIMIZATION = -O2 ARCHCPUFLAGS = -mlong32 -membedded-data -msoft-float -march=24kc -EL ARCHPICFLAGS = -fpic -membedded-pic @@ -114,8 +114,8 @@ endif # Microchip C32 toolchain under Linux ifeq ($(CONFIG_MIPS32_TOOLCHAIN),MICROCHIPL) - CROSSDEV = pic32- - # CROSSDEV = xc32- + CROSSDEV ?= pic32- + # CROSSDEV ?= xc32- MAXOPTIMIZATION = -O2 ARCHCPUFLAGS = -mprocessor=elf32pic32mx -mno-float -mlong32 -membedded-data ARCHPICFLAGS = -fpic -membedded-pic @@ -126,8 +126,8 @@ endif # Microchip C32 toolchain under Windows ifeq ($(CONFIG_MIPS32_TOOLCHAIN),MICROCHIPW) - CROSSDEV = pic32- - # CROSSDEV = xc32- + CROSSDEV ?= pic32- + # CROSSDEV ?= xc32- ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y endif @@ -141,8 +141,8 @@ endif # Microchip C32 toolchain under Linux ifeq ($(CONFIG_MIPS32_TOOLCHAIN),MICROCHIPL_LITE) - CROSSDEV = pic32- - # CROSSDEV = xc32- + CROSSDEV ?= pic32- + # CROSSDEV ?= xc32- # MAXOPTIMIZATION = -O2 ARCHCPUFLAGS = -mprocessor=elf32pic32mx -mno-float -mlong32 -membedded-data ARCHPICFLAGS = -fpic -membedded-pic @@ -153,8 +153,8 @@ endif # Microchip C32 toolchain under Windows ifeq ($(CONFIG_MIPS32_TOOLCHAIN),MICROCHIPW_LITE) - CROSSDEV = pic32- - # CROSSDEV = xc32- + CROSSDEV ?= pic32- + # CROSSDEV ?= xc32- ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y endif @@ -168,7 +168,7 @@ endif # microchipOpen toolchain under Linux ifeq ($(CONFIG_MIPS32_TOOLCHAIN),MICROCHIPOPENL) - CROSSDEV = mypic32- + CROSSDEV ?= mypic32- # MAXOPTIMIZATION = -O2 ARCHCPUFLAGS = -mprocessor=elf32pic32mx -mno-float -mlong32 -membedded-data ARCHPICFLAGS = -fpic -membedded-pic @@ -179,7 +179,7 @@ endif # Pinguino mips-elf toolchain under Windows ifeq ($(CONFIG_MIPS32_TOOLCHAIN),PINGUINOW) - CROSSDEV = mips- + CROSSDEV ?= mips- ifneq ($(CONFIG_WINDOWS_NATIVE),y) WINTOOL = y endif diff --git a/nuttx/arch/mips/src/mips32/up_assert.c b/nuttx/arch/mips/src/mips32/up_assert.c index 7d98e7427..f27bc0ebe 100644 --- a/nuttx/arch/mips/src/mips32/up_assert.c +++ b/nuttx/arch/mips/src/mips32/up_assert.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/mips/src/mips32/up_assert.c * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -90,7 +90,8 @@ * Name: _up_assert ****************************************************************************/ -static void _up_assert(int errorcode) /* noreturn_function */ +static void _up_assert(int errorcode) noreturn_function; +static void _up_assert(int errorcode) { /* Are we in an interrupt handler or the idle task? */ diff --git a/nuttx/arch/sh/src/common/up_assert.c b/nuttx/arch/sh/src/common/up_assert.c index 5b56e7731..62889fa5a 100644 --- a/nuttx/arch/sh/src/common/up_assert.c +++ b/nuttx/arch/sh/src/common/up_assert.c @@ -76,7 +76,8 @@ * Name: _up_assert ****************************************************************************/ -static void _up_assert(int errorcode) /* noreturn_function */ +static void _up_assert(int errorcode) noreturn_function; +static void _up_assert(int errorcode) { /* Are we in an interrupt handler or the idle task? */ diff --git a/nuttx/arch/x86/src/common/up_assert.c b/nuttx/arch/x86/src/common/up_assert.c index 87958baa6..653e8e562 100644 --- a/nuttx/arch/x86/src/common/up_assert.c +++ b/nuttx/arch/x86/src/common/up_assert.c @@ -209,7 +209,8 @@ static void up_dumpstate(void) * Name: _up_assert ****************************************************************************/ -static void _up_assert(int errorcode) /* noreturn_function */ +static void _up_assert(int errorcode) noreturn_function; +static void _up_assert(int errorcode) { /* Are we in an interrupt handler or the idle task? */ diff --git a/nuttx/drivers/serial/serial.c b/nuttx/drivers/serial/serial.c index 0548d8c25..9c6acf2ee 100644 --- a/nuttx/drivers/serial/serial.c +++ b/nuttx/drivers/serial/serial.c @@ -1041,8 +1041,11 @@ void uart_datasent(FAR uart_dev_t *dev) #ifdef CONFIG_SERIAL_REMOVABLE void uart_connected(FAR uart_dev_t *dev, bool connected) { + irqstate_t flags; + /* Is the device disconnected? */ + flags = irqsave(); dev->disconnected = !connected; if (!connected) { @@ -1070,10 +1073,12 @@ void uart_connected(FAR uart_dev_t *dev, bool connected) (void)sem_post(&dev->recvsem); } - /* Notify all poll/select waiters that and hangup/error occurred */ + /* Notify all poll/select waiters that and hangup occurred */ uart_pollnotify(dev, (POLLERR|POLLHUP)); } + + irqrestore(flags); } #endif diff --git a/nuttx/include/assert.h b/nuttx/include/assert.h index 31c9edf48..62ffb3a6e 100644 --- a/nuttx/include/assert.h +++ b/nuttx/include/assert.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/assert.h * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -100,23 +100,28 @@ ****************************************************************************/ /**************************************************************************** - * Global Function Prototypes + * Public Data ****************************************************************************/ #ifdef __cplusplus #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + #ifdef CONFIG_HAVE_FILENAME -EXTERN void up_assert(FAR const uint8_t *filename, int linenum); -EXTERN void up_assert_code(FAR const uint8_t *filename, int linenum, - int errcode); +void up_assert(FAR const uint8_t *filename, int linenum) noreturn_function; +void up_assert_code(FAR const uint8_t *filename, int linenum, int errcode) + noreturn_function; #else -EXTERN void up_assert(void); -EXTERN void up_assert_code(int errcode); +void up_assert(void) noreturn_function; +void up_assert_code(int errcode) noreturn_function; #endif #undef EXTERN -- cgit v1.2.3 From 7ccc57f3c0c5616347f42a41ae06fc17486ac49e Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Fri, 1 Feb 2013 13:02:20 +0100 Subject: Fixed test outputs, decoupled tests from NuttX low-level output via message() macro --- apps/px4/tests/test_adc.c | 8 +++++--- apps/px4/tests/tests_main.c | 12 ++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/px4/tests/test_adc.c b/apps/px4/tests/test_adc.c index 4c021303f..030ac6e23 100644 --- a/apps/px4/tests/test_adc.c +++ b/apps/px4/tests/test_adc.c @@ -60,8 +60,10 @@ int test_adc(int argc, char *argv[]) { int fd = open(ADC_DEVICE_PATH, O_RDONLY); - if (fd < 0) - err(1, "can't open ADC device"); + if (fd < 0) { + warnx("ERROR: can't open ADC device"); + return 1; + } for (unsigned i = 0; i < 5; i++) { /* make space for a maximum of eight channels */ @@ -82,7 +84,7 @@ int test_adc(int argc, char *argv[]) usleep(150000); } - message("\t ADC test successful.\n"); + warnx("\t ADC test successful.\n"); errout_with_dev: diff --git a/apps/px4/tests/tests_main.c b/apps/px4/tests/tests_main.c index ad6828f20..9f8c5c9ea 100644 --- a/apps/px4/tests/tests_main.c +++ b/apps/px4/tests/tests_main.c @@ -135,6 +135,7 @@ test_all(int argc, char *argv[]) unsigned i; char *args[2] = {"all", NULL}; unsigned int failcount = 0; + unsigned int testcount = 0; bool passed[NTESTS]; printf("\nRunning all tests...\n\n"); @@ -156,6 +157,7 @@ test_all(int argc, char *argv[]) fflush(stdout); passed[i] = true; } + testcount++; } } @@ -178,7 +180,7 @@ test_all(int argc, char *argv[]) printf(" \\ \\_\\ \\_\\ \\ \\_____\\ \\ \\_____\\ \\ \\_____\\ \\ \\_\\ \\_\\ \n"); printf(" \\/_/\\/_/ \\/_____/ \\/_____/ \\/_____/ \\/_/\\/_/ \n"); printf("\n"); - printf(" All tests passed (%d of %d)\n", i, i); + printf(" All tests passed (%d of %d)\n", testcount, testcount); } else { printf(" ______ ______ __ __ \n"); @@ -187,7 +189,7 @@ test_all(int argc, char *argv[]) printf(" \\ \\_\\ \\ \\_\\ \\_\\ \\ \\_\\ \\ \\_____\\ \n"); printf(" \\/_/ \\/_/\\/_/ \\/_/ \\/_____/ \n"); printf("\n"); - printf(" Some tests failed (%d of %d)\n", failcount, i); + printf(" Some tests failed (%d of %d)\n", failcount, testcount); } printf("\n"); @@ -245,6 +247,7 @@ int test_jig(int argc, char *argv[]) unsigned i; char *args[2] = {"jig", NULL}; unsigned int failcount = 0; + unsigned int testcount = 0; bool passed[NTESTS]; printf("\nRunning all tests...\n\n"); @@ -264,6 +267,7 @@ int test_jig(int argc, char *argv[]) fflush(stdout); passed[i] = true; } + testcount++; } } @@ -284,7 +288,7 @@ int test_jig(int argc, char *argv[]) printf(" \\ \\_\\ \\_\\ \\ \\_____\\ \\ \\_____\\ \\ \\_____\\ \\ \\_\\ \\_\\ \n"); printf(" \\/_/\\/_/ \\/_____/ \\/_____/ \\/_____/ \\/_/\\/_/ \n"); printf("\n"); - printf(" All tests passed (%d of %d)\n", i, i); + printf(" All tests passed (%d of %d)\n", testcount, testcount); } else { printf(" ______ ______ __ __ \n"); printf(" /\\ ___\\ /\\ __ \\ /\\ \\ /\\ \\ \n"); @@ -292,7 +296,7 @@ int test_jig(int argc, char *argv[]) printf(" \\ \\_\\ \\ \\_\\ \\_\\ \\ \\_\\ \\ \\_____\\ \n"); printf(" \\/_/ \\/_/\\/_/ \\/_/ \\/_____/ \n"); printf("\n"); - printf(" Some tests failed (%d of %d)\n", failcount, i); + printf(" Some tests failed (%d of %d)\n", failcount, testcount); } printf("\n"); -- cgit v1.2.3 From 04a4ef84f01ca2bed9cda2a58f583f7a9428949d Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 1 Feb 2013 14:53:38 +0000 Subject: NxWidgets updates from Petteri Aimonen; buildroot GDB build fix from Ken Bannister git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5592 42af7a65-404d-4744-a932-0658087f49c3 --- NxWidgets/ChangeLog.txt | 11 ++ NxWidgets/libnxwidgets/Makefile | 2 +- NxWidgets/libnxwidgets/include/cgraphicsport.hxx | 7 +- NxWidgets/libnxwidgets/include/cnxwidget.hxx | 2 +- NxWidgets/libnxwidgets/include/ctabpanel.hxx | 108 ++++++++++++++++++ NxWidgets/libnxwidgets/src/cgraphicsport.cxx | 19 ++-- NxWidgets/libnxwidgets/src/cnxwidget.cxx | 14 +++ NxWidgets/libnxwidgets/src/ctabpanel.cxx | 133 +++++++++++++++++++++++ misc/buildroot/ChangeLog | 3 + misc/buildroot/toolchain/gdb/Config.in | 2 +- nuttx/README.txt | 6 + nuttx/libc/stdio/lib_fgets.c | 2 +- 12 files changed, 293 insertions(+), 16 deletions(-) create mode 100644 NxWidgets/libnxwidgets/include/ctabpanel.hxx create mode 100644 NxWidgets/libnxwidgets/src/ctabpanel.cxx diff --git a/NxWidgets/ChangeLog.txt b/NxWidgets/ChangeLog.txt index 744584ed4..be55a2e78 100644 --- a/NxWidgets/ChangeLog.txt +++ b/NxWidgets/ChangeLog.txt @@ -252,3 +252,14 @@ around this, I added several "enabling" settings to override the default setting. This is awkward and I preferred the configuration as it was before, but this avoids the mconf errors and warnings. +* UnitTests: Changed occurrences of lib_rawprintf() and lib_lowprintf() + to match recent changes to NuttX (will be in NuttX-6.25) +* CGraphicsPort::_drawText: Renamed from CGraphicsPort::drawText in order + to eliminate some naming collisions when overloaded in some configurations + (i.e., when both bool and nx_pixel_t are uint8_t). From Petteri Aimonen. +* CNxWidgets::drawContents: Change base drawContents from a do-nothing + function to a function that fills the widget with the background color. + This is useful when using CNxWidgets as a "panel" , i.e. a container + for other widgets. Subclasses will override drawContents and decide + themselves how to draw the background. +* CNxWidgets::CTabPanel: A new widget contributed by Petteri Aimonen. diff --git a/NxWidgets/libnxwidgets/Makefile b/NxWidgets/libnxwidgets/Makefile index 0c7c922ea..84b377edd 100644 --- a/NxWidgets/libnxwidgets/Makefile +++ b/NxWidgets/libnxwidgets/Makefile @@ -63,7 +63,7 @@ CXXSRCS += cprogressbar.cxx cradiobutton.cxx cradiobuttongroup.cxx cscrollbarhor CXXSRCS += cscrollbarpanel.cxx cscrollbarvertical.cxx cscrollinglistbox.cxx CXXSRCS += cscrollingpanel.cxx cscrollingtextbox.cxx csliderhorizontal.cxx CXXSRCS += csliderhorizontalgrip.cxx cslidervertical.cxx csliderverticalgrip.cxx -CXXSRCS += cstickybutton.cxx cstickybuttonarray.cxx ctextbox.cxx +CXXSRCS += cstickybutton.cxx cstickybuttonarray.cxx ctabpanel.cxx ctextbox.cxx # Images CXXSRCS += glyph_nxlogo.cxx CXXSRCS += glyph_arrowdown.cxx glyph_checkboxon.cxx glyph_screendepthup.cxx diff --git a/NxWidgets/libnxwidgets/include/cgraphicsport.hxx b/NxWidgets/libnxwidgets/include/cgraphicsport.hxx index d3d9e6114..006a56d51 100644 --- a/NxWidgets/libnxwidgets/include/cgraphicsport.hxx +++ b/NxWidgets/libnxwidgets/include/cgraphicsport.hxx @@ -123,9 +123,10 @@ namespace NXWidgets * @param background Color to use for background if transparent is false. * @param transparent Whether to fill the background. */ - void drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font, - const CNxString &string, int startIndex, int length, - nxgl_mxpixel_t background, bool transparent); + + void _drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font, + const CNxString &string, int startIndex, int length, + nxgl_mxpixel_t background, bool transparent); public: /** diff --git a/NxWidgets/libnxwidgets/include/cnxwidget.hxx b/NxWidgets/libnxwidgets/include/cnxwidget.hxx index dda8efc1d..32e3dfbc6 100644 --- a/NxWidgets/libnxwidgets/include/cnxwidget.hxx +++ b/NxWidgets/libnxwidgets/include/cnxwidget.hxx @@ -222,7 +222,7 @@ namespace NXWidgets * @see redraw(). */ - virtual inline void drawContents(CGraphicsPort* port) { } + virtual void drawContents(CGraphicsPort* port); /** * Draw the area of this widget that falls within the clipping region. diff --git a/NxWidgets/libnxwidgets/include/ctabpanel.hxx b/NxWidgets/libnxwidgets/include/ctabpanel.hxx new file mode 100644 index 000000000..aa6eb20f8 --- /dev/null +++ b/NxWidgets/libnxwidgets/include/ctabpanel.hxx @@ -0,0 +1,108 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/include/ctabpanel.hxx + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Petteri Aimonen + * + * 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, NxWidgets, nor the names of its contributors + * me 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 __INCLUDE_CTABPANEL_HXX +#define __INCLUDE_CTABPANEL_HXX + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "cnxwidget.hxx" +#include "cwidgetstyle.hxx" +#include "cnxstring.hxx" +#include "tnxarray.hxx" +#include "clatchbuttonarray.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Implementation Classes + ****************************************************************************/ + +#if defined(__cplusplus) + +namespace NXWidgets +{ + /** + * Forward references + */ + + class CWidgetControl; + class CRect; + class CStickyButtonArray; + + /** + * Tab panel, with tabs at the top and a panel at the bottom. + */ + + class CTabPanel : public CNxWidget, public CWidgetEventHandler + { + protected: + TNxArray m_tabpages; + CLatchButtonArray *m_buttonbar; + + virtual void handleActionEvent(const CWidgetEventArgs &e); + + virtual void drawContents(CGraphicsPort* port) {} + virtual void drawBorder(CGraphicsPort* port) {} + + public: + CTabPanel(CWidgetControl *pWidgetControl, uint8_t numPages, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + nxgl_coord_t buttonHeight, + FAR const CWidgetStyle *style = (FAR const CWidgetStyle *)NULL + ); + + inline CNxWidget &page(uint8_t index) { return *m_tabpages.at(index); } + + void setPageName(uint8_t index, const CNxString &name); + + void showPage(uint8_t index); + }; +} + +#endif +#endif diff --git a/NxWidgets/libnxwidgets/src/cgraphicsport.cxx b/NxWidgets/libnxwidgets/src/cgraphicsport.cxx index 73f2352eb..f295483a9 100644 --- a/NxWidgets/libnxwidgets/src/cgraphicsport.cxx +++ b/NxWidgets/libnxwidgets/src/cgraphicsport.cxx @@ -604,7 +604,7 @@ void CGraphicsPort::drawBitmapGreyScale(nxgl_coord_t x, nxgl_coord_t y, void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font, const CNxString &string) { - drawText(pos, bound, font, string, 0, string.getLength()); + _drawText(pos, bound, font, string, 0, string.getLength(), 0, true); } /** @@ -632,7 +632,7 @@ void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, // Draw the string with this new color - drawText(pos, bound, font, string, startIndex, length); + _drawText(pos, bound, font, string, startIndex, length, 0, true); // Restore the font color @@ -654,7 +654,7 @@ void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font, const CNxString &string, int startIndex, int length) { - drawText(pos, bound, font, string, startIndex, length, 0, true); + _drawText(pos, bound, font, string, startIndex, length, 0, true); } /** @@ -680,7 +680,7 @@ void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, nxgl_mxpixel_t savedColor = font->getColor(); font->setColor(color); - drawText(pos, bound, font, string, startIndex, length, background, false); + _drawText(pos, bound, font, string, startIndex, length, background, false); font->setColor(savedColor); } @@ -697,11 +697,12 @@ void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, * @param background Color to use for background if transparent is false. * @param transparent Whether to fill the background. */ -void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, - CNxFont *font, const CNxString &string, - int startIndex, int length, - nxgl_mxpixel_t background, - bool transparent) + +void CGraphicsPort::_drawText(struct nxgl_point_s *pos, CRect *bound, + CNxFont *font, const CNxString &string, + int startIndex, int length, + nxgl_mxpixel_t background, + bool transparent) { // Verify index and length diff --git a/NxWidgets/libnxwidgets/src/cnxwidget.cxx b/NxWidgets/libnxwidgets/src/cnxwidget.cxx index ab4a09b4e..15ed501e6 100644 --- a/NxWidgets/libnxwidgets/src/cnxwidget.cxx +++ b/NxWidgets/libnxwidgets/src/cnxwidget.cxx @@ -1443,6 +1443,20 @@ void CNxWidget::useWidgetStyle(const CWidgetStyle *style) m_style.font = style->font; } +/** + * Draw the area of this widget that falls within the clipping region. + * Called by the redraw() function to draw all visible regions. + * + * @param port The CGraphicsPort to draw to. + * @see redraw(). + */ + +void CNxWidget::drawContents(CGraphicsPort* port) +{ + port->drawFilledRect(getX(), getY(), getWidth(), getHeight(), + getBackgroundColor()); +} + /** * Draw all visible regions of this widget's children. */ diff --git a/NxWidgets/libnxwidgets/src/ctabpanel.cxx b/NxWidgets/libnxwidgets/src/ctabpanel.cxx new file mode 100644 index 000000000..f1723fdba --- /dev/null +++ b/NxWidgets/libnxwidgets/src/ctabpanel.cxx @@ -0,0 +1,133 @@ +/**************************************************************************** + * NxWidgets/libnxwidgets/src/ctabpanel.hxx + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Petteri Aimonen + * + * 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, NxWidgets, nor the names of its contributors + * me be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "ctabpanel.hxx" +#include "cgraphicsport.hxx" +#include "cwidgetstyle.hxx" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * CTabPanel Method Implementations + ****************************************************************************/ + +using namespace NXWidgets; + +CTabPanel::CTabPanel(CWidgetControl *pWidgetControl, uint8_t numPages, + nxgl_coord_t x, nxgl_coord_t y, + nxgl_coord_t width, nxgl_coord_t height, + nxgl_coord_t buttonHeight, + FAR const CWidgetStyle *style + ): + CNxWidget(pWidgetControl, x, y, width, height, 0, style) +{ + m_buttonbar = new CLatchButtonArray(pWidgetControl, x, y, + numPages, 1, + width / numPages, + buttonHeight, + 0); + m_buttonbar->addWidgetEventHandler(this); + this->addWidget(m_buttonbar); + + for (int i = 0; i < numPages; i++) + { + CNxWidget *tabpage = new CNxWidget(pWidgetControl, x, y + buttonHeight, + width, height - buttonHeight, 0); + tabpage->setBackgroundColor(getBackgroundColor()); + tabpage->setBorderless(true); + m_tabpages.push_back(tabpage); + this->addWidget(tabpage); + } + + // Activate the first page + + showPage(0); +} + +void CTabPanel::setPageName(uint8_t index, const CNxString &name) +{ + m_buttonbar->setText(index, 0, name); +} + +void CTabPanel::showPage(uint8_t index) +{ + if (!m_buttonbar->isThisButtonStuckDown(index, 0)) + { + m_buttonbar->stickDown(index, 0); + } + + for (int i = 0; i < m_tabpages.size(); i++) + { + if (i == index) + { + m_tabpages.at(i)->enable(); + m_tabpages.at(i)->show(); + m_tabpages.at(i)->redraw(); + } + else + { + m_tabpages.at(i)->hide(); + m_tabpages.at(i)->disable(); + } + } +} + +void CTabPanel::handleActionEvent(const CWidgetEventArgs &e) +{ + if (e.getSource() == m_buttonbar) + { + int x = 0; + int y = 0; + + m_buttonbar->isAnyButtonStuckDown(x, y); + showPage(x); + } +} + + + diff --git a/misc/buildroot/ChangeLog b/misc/buildroot/ChangeLog index 6b09b8b94..0053b1e92 100644 --- a/misc/buildroot/ChangeLog +++ b/misc/buildroot/ChangeLog @@ -128,3 +128,6 @@ buildroot-1.11 2011-11-05 logic. There are lots of issues that I still do not understand here. buildroot-1.12 2011-xx-xx + + * Fix typo toolchain/gdb/Config.in that prevented GDB 7.4 from building + (from Ken Bannister). diff --git a/misc/buildroot/toolchain/gdb/Config.in b/misc/buildroot/toolchain/gdb/Config.in index ebe8578a9..1fc1ecd8b 100644 --- a/misc/buildroot/toolchain/gdb/Config.in +++ b/misc/buildroot/toolchain/gdb/Config.in @@ -41,7 +41,7 @@ choice depends on !BR2_avr32 config BR2_GDB_VERSION_7_4 - config BR2_GDB_VERSION_7_4 + bool "gdb 7.4" depends on !BR2_bfin endchoice diff --git a/nuttx/README.txt b/nuttx/README.txt index 571f8e04e..da1ed10c6 100644 --- a/nuttx/README.txt +++ b/nuttx/README.txt @@ -533,6 +533,12 @@ NuttX Buildroot Toolchain an ARM Cortex-M3/4, you will need to set CONFIG_ARMV7M_OABI_TOOLCHAIN in the .config file in order to pick the right tool prefix. + If the make system ever picks the wrong prefix for your toolchain, you + can always specify the prefix on the command to override the default + like: + + make CROSSDEV=arm-nuttx-elf + SHELLS ^^^^^^ diff --git a/nuttx/libc/stdio/lib_fgets.c b/nuttx/libc/stdio/lib_fgets.c index 35d024ebb..87eed285d 100644 --- a/nuttx/libc/stdio/lib_fgets.c +++ b/nuttx/libc/stdio/lib_fgets.c @@ -150,7 +150,7 @@ char *fgets(FAR char *buf, int buflen, FILE *stream) if (ch == '\n') #elif defined(CONFIG_EOL_IS_CR) if (ch == '\r') -#else /* elif CONFIG_EOL_IS_EITHER_CRLF */ +#else /* elif defined(CONFIG_EOL_IS_EITHER_CRLF) */ if (ch == '\n' || ch == '\r') #endif { -- cgit v1.2.3 From a6d4497461d9a129572ab0d4327dd88c1f99986a Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 1 Feb 2013 15:32:39 +0000 Subject: Additional patches from Petteri Aimonen for FAT, STM32 SPI, and AT25 git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5593 42af7a65-404d-4744-a932-0658087f49c3 --- NxWidgets/ChangeLog.txt | 3 ++ nuttx/ChangeLog | 19 +++++++++++- nuttx/arch/arm/src/stm32/chip/stm32_spi.h | 8 ++++- nuttx/arch/arm/src/stm32/stm32_spi.c | 51 +++++++++++++++++++++++++------ nuttx/drivers/mmcsd/mmcsd_spi.c | 10 ++++-- nuttx/drivers/mtd/at25.c | 16 +++++----- nuttx/fs/fat/fs_configfat.c | 14 ++++----- nuttx/fs/fat/fs_fat32.c | 3 ++ nuttx/fs/fat/fs_fat32util.c | 4 +-- 9 files changed, 97 insertions(+), 31 deletions(-) diff --git a/NxWidgets/ChangeLog.txt b/NxWidgets/ChangeLog.txt index be55a2e78..88e15d7db 100644 --- a/NxWidgets/ChangeLog.txt +++ b/NxWidgets/ChangeLog.txt @@ -263,3 +263,6 @@ for other widgets. Subclasses will override drawContents and decide themselves how to draw the background. * CNxWidgets::CTabPanel: A new widget contributed by Petteri Aimonen. + This widget provides a tab panel, which has a button bar at the top + and panels below it. Pressing a button will select the corresponding + panel. diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 26b82fde4..db62b9cf4 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4078,4 +4078,21 @@ override CROSSDEV with a make command line argument. * include/assert.h: Mark assertion functions as non-returning. * arch/*/src/*/up_assert.h: Mark _up_assert() as non-returning. - + * drivers/mtd/at25.c: When the AT25 device was not available the + initialization did not fail like it should. From Petteri Aimonen. + * fs/fat/fs_configfat.c: Fix some errors in FAT formatting logic + for large devices and for FAT32. From Petteri Aimonen. + * fs/fat/fs_fat32util.c: Fix an initialization error found by + Petteri Aimonen. freecount and next freecount initialization were + reversed. + * drivers/mmcsd/mmcsd_spi.c: Some SD cards will appear busy until + switched to SPI mode for first time. Having a pull-up resistor on + MISO may avoid this problem, but this patch makes it work also + without pull-up. From Petteri Aimonen. + * fs/fat/fs_fat32.c: Fix a compilation error when FAT_DMAMEMORY=y. + From Petteri Aimonen. + * arch/arm/src/stm32/chip/stm32_spi.h: STM32F4 max SPI clock freq is + 37.5 MHz. Patch from Petteri Aimonen. + * arch/arm/src/stm32/stm32_spi.c: Fixes for SPI DMA work on the + STM32F4. Includes untested additions for the F1 implementation as + well. From Petteri Aimonen. diff --git a/nuttx/arch/arm/src/stm32/chip/stm32_spi.h b/nuttx/arch/arm/src/stm32/chip/stm32_spi.h index d80c447bb..7731d03b0 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32_spi.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32_spi.h @@ -47,7 +47,13 @@ * Pre-processor Definitions ************************************************************************************/ -#define STM32_SPI_CLK_MAX 18000000UL /* Maximum allowed speed as per specifications for all SPIs */ +/* Maximum allowed speed as per specifications for all SPIs */ + +#if defined(CONFIG_STM32_STM32F40XX) +# define STM32_SPI_CLK_MAX 37500000UL +#else +# define STM32_SPI_CLK_MAX 18000000UL +#endif /* Register Offsets *****************************************************************/ diff --git a/nuttx/arch/arm/src/stm32/stm32_spi.c b/nuttx/arch/arm/src/stm32/stm32_spi.c index 8de698cd5..b4a4f36ab 100644 --- a/nuttx/arch/arm/src/stm32/stm32_spi.c +++ b/nuttx/arch/arm/src/stm32/stm32_spi.c @@ -130,14 +130,28 @@ /* DMA channel configuration */ -#define SPI_RXDMA16_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_16BITS|DMA_CCR_PSIZE_16BITS|DMA_CCR_MINC ) -#define SPI_RXDMA8_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_8BITS |DMA_CCR_MINC ) -#define SPI_RXDMA16NULL_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_16BITS ) -#define SPI_RXDMA8NULL_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_8BITS ) -#define SPI_TXDMA16_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_16BITS|DMA_CCR_PSIZE_16BITS|DMA_CCR_MINC|DMA_CCR_DIR) -#define SPI_TXDMA8_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_8BITS |DMA_CCR_MINC|DMA_CCR_DIR) -#define SPI_TXDMA16NULL_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_16BITS |DMA_CCR_DIR) -#define SPI_TXDMA8NULL_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_8BITS |DMA_CCR_DIR) +#if defined(CONFIG_STM32_STM32F10XX) +# define SPI_RXDMA16_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_16BITS|DMA_CCR_PSIZE_16BITS|DMA_CCR_MINC ) +# define SPI_RXDMA8_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_8BITS |DMA_CCR_MINC ) +# define SPI_RXDMA16NULL_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_16BITS ) +# define SPI_RXDMA8NULL_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_8BITS ) +# define SPI_TXDMA16_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_16BITS|DMA_CCR_PSIZE_16BITS|DMA_CCR_MINC|DMA_CCR_DIR) +# define SPI_TXDMA8_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_8BITS |DMA_CCR_MINC|DMA_CCR_DIR) +# define SPI_TXDMA16NULL_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_16BITS |DMA_CCR_DIR) +# define SPI_TXDMA8NULL_CONFIG (SPI_DMA_PRIO|DMA_CCR_MSIZE_8BITS |DMA_CCR_PSIZE_8BITS |DMA_CCR_DIR) +#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) +# define SPI_RXDMA16_CONFIG (SPI_DMA_PRIO|DMA_SCR_MSIZE_16BITS|DMA_SCR_PSIZE_16BITS|DMA_SCR_MINC|DMA_SCR_DIR_P2M) +# define SPI_RXDMA8_CONFIG (SPI_DMA_PRIO|DMA_SCR_MSIZE_8BITS |DMA_SCR_PSIZE_8BITS |DMA_SCR_MINC|DMA_SCR_DIR_P2M) +# define SPI_RXDMA16NULL_CONFIG (SPI_DMA_PRIO|DMA_SCR_MSIZE_8BITS |DMA_SCR_PSIZE_16BITS |DMA_SCR_DIR_P2M) +# define SPI_RXDMA8NULL_CONFIG (SPI_DMA_PRIO|DMA_SCR_MSIZE_8BITS |DMA_SCR_PSIZE_8BITS |DMA_SCR_DIR_P2M) +# define SPI_TXDMA16_CONFIG (SPI_DMA_PRIO|DMA_SCR_MSIZE_16BITS|DMA_SCR_PSIZE_16BITS|DMA_SCR_MINC|DMA_SCR_DIR_M2P) +# define SPI_TXDMA8_CONFIG (SPI_DMA_PRIO|DMA_SCR_MSIZE_8BITS |DMA_SCR_PSIZE_8BITS |DMA_SCR_MINC|DMA_SCR_DIR_M2P) +# define SPI_TXDMA16NULL_CONFIG (SPI_DMA_PRIO|DMA_SCR_MSIZE_8BITS |DMA_SCR_PSIZE_16BITS |DMA_SCR_DIR_M2P) +# define SPI_TXDMA8NULL_CONFIG (SPI_DMA_PRIO|DMA_SCR_MSIZE_8BITS |DMA_SCR_PSIZE_8BITS |DMA_SCR_DIR_M2P) +#else +# error "Unknown STM32 DMA" +#endif + /* Debug ****************************************************************************/ /* Check if (non-standard) SPI debug is enabled */ @@ -549,6 +563,21 @@ static inline void spi_dmarxwakeup(FAR struct stm32_spidev_s *priv) } #endif +/************************************************************************************ + * Name: spi_dmatxwakeup + * + * Description: + * Signal that DMA is complete + * + ************************************************************************************/ + +#ifdef CONFIG_STM32_SPI_DMA +static inline void spi_dmatxwakeup(FAR struct stm32_spidev_s *priv) +{ + (void)sem_post(&priv->txsem); +} +#endif + /************************************************************************************ * Name: spi_dmarxcallback * @@ -1183,8 +1212,8 @@ static void spi_exchange(FAR struct spi_dev_s *dev, FAR const void *txbuffer, FAR void *rxbuffer, size_t nwords) { FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev; - uint16_t rxdummy = 0xffff; - uint16_t txdummy; + static uint16_t rxdummy = 0xffff; + static const uint16_t txdummy = 0xffff; spivdbg("txbuffer=%p rxbuffer=%p nwords=%d\n", txbuffer, rxbuffer, nwords); DEBUGASSERT(priv && priv->spibase); @@ -1330,6 +1359,8 @@ static void spi_portinitialize(FAR struct stm32_spidev_s *priv) priv->rxdma = stm32_dmachannel(priv->rxch); priv->txdma = stm32_dmachannel(priv->txch); DEBUGASSERT(priv->rxdma && priv->txdma); + + spi_putreg(priv, STM32_SPI_CR2_OFFSET, SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN); #endif /* Enable spi */ diff --git a/nuttx/drivers/mmcsd/mmcsd_spi.c b/nuttx/drivers/mmcsd/mmcsd_spi.c index d437b7fea..3d4cf1dd1 100644 --- a/nuttx/drivers/mmcsd/mmcsd_spi.c +++ b/nuttx/drivers/mmcsd/mmcsd_spi.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/mmcsd/mmcsd_spi.c * - * Copyright (C) 2008-2010, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2010, 2011-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -409,10 +409,14 @@ static uint32_t mmcsd_sendcmd(FAR struct mmcsd_slot_s *slot, int ret; int i; - /* Wait until the card is not busy */ + /* Wait until the card is not busy. Some SD cards will not enter the IDLE + * state until CMD0 is sent for the first time, switching the card to SPI + * mode. Having a pull-up resistor on MISO may avoid this problem, but + * this check makes it work also without the pull-up. + */ ret = mmcsd_waitready(slot); - if (ret != OK) + if (ret != OK && cmd != &g_cmd0) { return ret; } diff --git a/nuttx/drivers/mtd/at25.c b/nuttx/drivers/mtd/at25.c index e35b794a5..c58b16122 100644 --- a/nuttx/drivers/mtd/at25.c +++ b/nuttx/drivers/mtd/at25.c @@ -691,14 +691,16 @@ FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev) kfree(priv); priv = NULL; } - - /* Unprotect all sectors */ + else + { + /* Unprotect all sectors */ - at25_writeenable(priv); - SPI_SELECT(priv->dev, SPIDEV_FLASH, true); - (void)SPI_SEND(priv->dev, AT25_WRSR); - (void)SPI_SEND(priv->dev, AT25_SR_UNPROT); - SPI_SELECT(priv->dev, SPIDEV_FLASH, false); + at25_writeenable(priv); + SPI_SELECT(priv->dev, SPIDEV_FLASH, true); + (void)SPI_SEND(priv->dev, AT25_WRSR); + (void)SPI_SEND(priv->dev, AT25_SR_UNPROT); + SPI_SELECT(priv->dev, SPIDEV_FLASH, false); + } } /* Return the implementation-specific state structure as the MTD device */ diff --git a/nuttx/fs/fat/fs_configfat.c b/nuttx/fs/fat/fs_configfat.c index 2075caa9f..04141ee2b 100644 --- a/nuttx/fs/fat/fs_configfat.c +++ b/nuttx/fs/fat/fs_configfat.c @@ -406,7 +406,7 @@ mkfatfs_clustersearchlimits(FAR struct fat_format_s *fmt, FAR struct fat_var_s * } /**************************************************************************** - * Name: mkfatfs_try12 + * Name: mkfatfs_tryfat12 * * Description: * Try to define a FAT12 filesystem on the device using the candidate @@ -462,7 +462,7 @@ mkfatfs_tryfat12(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * FAT12 (remembering that two FAT cluster slots are reserved). */ - if (config->fc_nclusters > maxnclusters - 2) + if (config->fc_nclusters + 2 > maxnclusters) { fvdbg("Too many clusters for FAT12\n"); return -ENFILE; @@ -472,7 +472,7 @@ mkfatfs_tryfat12(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, } /**************************************************************************** - * Name: mkfatfs_try16 + * Name: mkfatfs_tryfat16 * * Description: * Try to define a FAT16 filesystem on the device using the candidate @@ -532,7 +532,7 @@ mkfatfs_tryfat16(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * be confused as a FAT12 at mount time. */ - if ((config->fc_nclusters > maxnclusters - 2) || + if ((config->fc_nclusters + 2 > maxnclusters) || (config->fc_nclusters < FAT_MINCLUST16)) { fvdbg("Too few or too many clusters for FAT16\n"); @@ -543,7 +543,7 @@ mkfatfs_tryfat16(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, } /**************************************************************************** - * Name: mkfatfs_try32 + * Name: mkfatfs_tryfat32 * * Description: * Try to define a FAT32 filesystem on the device using the candidate @@ -587,7 +587,7 @@ mkfatfs_tryfat32(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * maxnclusters = nfatsects * sectorsize / 4 - 2 */ - maxnclusters = (config->fc_nfatsects >> (var->fv_sectshift - 2)); + maxnclusters = (config->fc_nfatsects << (var->fv_sectshift - 2)); if (maxnclusters > FAT_MAXCLUST32) { maxnclusters = FAT_MAXCLUST32; @@ -599,7 +599,7 @@ mkfatfs_tryfat32(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * FAT32 (remembering that two FAT cluster slots are reserved). */ - if ((config->fc_nclusters > maxnclusters - 3) || + if ((config->fc_nclusters + 3 > maxnclusters) || (config->fc_nclusters < FAT_MINCLUST32 && fmt->ff_fattype != 32)) { fvdbg("Too few or too many clusters for FAT32\n"); diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c index c10c28a5c..df8962b51 100644 --- a/nuttx/fs/fat/fs_fat32.c +++ b/nuttx/fs/fat/fs_fat32.c @@ -381,6 +381,7 @@ static int fat_close(FAR struct file *filep) { struct inode *inode; struct fat_file_s *ff; + struct fat_mountpt_s *fs; int ret = OK; /* Sanity checks */ @@ -391,6 +392,7 @@ static int fat_close(FAR struct file *filep) ff = filep->f_priv; inode = filep->f_inode; + fs = inode->i_private; /* Do not check if the mount is healthy. We must support closing of * the file even when there is healthy mount. @@ -408,6 +410,7 @@ static int fat_close(FAR struct file *filep) if (ff->ff_buffer) { + (void)fs; /* Unused if fat_io_free == free(). */ fat_io_free(ff->ff_buffer, fs->fs_hwsectorsize); } diff --git a/nuttx/fs/fat/fs_fat32util.c b/nuttx/fs/fat/fs_fat32util.c index 9aa1d3992..8edef7735 100644 --- a/nuttx/fs/fat/fs_fat32util.c +++ b/nuttx/fs/fat/fs_fat32util.c @@ -106,8 +106,8 @@ static int fat_checkfsinfo(struct fat_mountpt_s *fs) FSI_GETSTRUCTSIG(fs->fs_buffer) == 0x61417272 && FSI_GETTRAILSIG(fs->fs_buffer) == BOOT_SIGNATURE32) { - fs->fs_fsinextfree = FSI_GETFREECOUNT(fs->fs_buffer); - fs->fs_fsifreecount = FSI_GETNXTFREE(fs->fs_buffer); + fs->fs_fsifreecount = FSI_GETFREECOUNT(fs->fs_buffer); + fs->fs_fsinextfree = FSI_GETNXTFREE(fs->fs_buffer); return OK; } } -- cgit v1.2.3 From 85417c1a51ae433380fafd86b05806cd8929c54e Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 1 Feb 2013 22:37:52 +0000 Subject: Prep for 6.25 release git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5594 42af7a65-404d-4744-a932-0658087f49c3 --- NxWidgets/ChangeLog.txt | 4 +- NxWidgets/ReleaseNotes.txt | 43 ++ apps/ChangeLog.txt | 10 +- nuttx/ChangeLog | 27 +- nuttx/Documentation/NuttX.html | 1207 +++++++++++++++++++++++++++------------- nuttx/ReleaseNotes | 320 +++++++++++ 6 files changed, 1191 insertions(+), 420 deletions(-) diff --git a/NxWidgets/ChangeLog.txt b/NxWidgets/ChangeLog.txt index 88e15d7db..7e2acdea1 100644 --- a/NxWidgets/ChangeLog.txt +++ b/NxWidgets/ChangeLog.txt @@ -219,7 +219,7 @@ * NxWidgets::CNxWidgets and NxWM::CStartWindow: Small changes to make sub- classing easier (from Petteri Aimonen). -1.5 2013-xx-xx Gregory Nutt +1.5 2013-02-01 Gregory Nutt * NxWidgets::CGraphicsPort::move(): Fix typo bug in bounding rectangle calculation (from Petteri Aimonen). @@ -266,3 +266,5 @@ This widget provides a tab panel, which has a button bar at the top and panels below it. Pressing a button will select the corresponding panel. + +1.6 2013-xx-xx Gregory Nutt diff --git a/NxWidgets/ReleaseNotes.txt b/NxWidgets/ReleaseNotes.txt index aaaefe6eb..431d2796c 100644 --- a/NxWidgets/ReleaseNotes.txt +++ b/NxWidgets/ReleaseNotes.txt @@ -144,3 +144,46 @@ Bugfixes (see the change log for details). Some of these are very important * NxWidgets:CText and NxWidgets:CNumericEdite: Fix some memory freeing bugs * NxWidgets::CScrollingPanel: It is borderless for now because there was no easy way to redraw only the required part of the border. + +NxWidgets-1.5 +============= + +The 6th release of the NxWidgets package was made on February 1, 2013. This +release depends on NuttX-6.25 or above and should not be used with older +NuttX releases. This release corresponds to SVN revision r5594. + +Note: Nearly all of the changes between 1.4 and 1.5 were the result of the +efforts of Petteri Aimonen. + +Additional new features and extended functionality in Version 1.5: + +* CNxWidgets::CTabPanel: A new widget contributed by Petteri Aimonen. + This widget provides a tab panel, which has a button bar at the top + and panels below it. Pressing a button will select the corresponding + panel. +* NxWidgets::CGraphicsPort: Many times we only want a constant background. + In that case the old code filled the background, read it back, rendered + the text and then wrote it back. When used with an LCD this causes + some screen flicker. Added a variant of drawText that takes background + color, so that the background and text can both be rendered at one go. +* NxWM::CScrollingPanel::scrollChildren(): Avoid unnecessary redraws in + CScrollingPanel +* Kconfig: Added several "enabling" settings that must be selected to + override the default setting. +* UnitTests: Changes for compatibility with NuttX-6.25 + +Bugfixes: + +* NxWidgets::CGraphicsPort::move(): Fix typo bug in bounding rectangle + calculation. +* NxWM::CCycleButton: Remove the separator from CCycleButton. It draws in + wrong place, and doesn't look very good in the correct place either. +* NxWidgets::CLabel: The label was drawn as a single rectangular region, + then a text was added to the on top of this. The result is that the + text would flicker when the CLabel was updated. With this change, the + two step update is replaced with a five step update: The background + is updated as four rectangulear regions (leaving the previous text in + place), then the new text is updated. This eliminates the flicker. +* CGraphicsPort::_drawText: Renamed from CGraphicsPort::drawText in order + to eliminate some naming collisions when overloaded in some configurations + (i.e., when both bool and nx_pixel_t are uint8_t). diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index e64509be9..05cd6176a 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -434,7 +434,7 @@ tests will now use a relative path to the program and expect the binfmt/ logic to find the absolute path to the program using the PATH variable. -6.25 2013-xx-xx Gregory Nutt +6.25 2013-02-01 Gregory Nutt * Makefiles: Removed dependency of distclean on clean in most top-level files. It makes sense for 'leaf' Makefiles to have this dependency, @@ -461,7 +461,7 @@ the USB HID keyboard report data. * apps/examples/wlan: Remove non-functional example. * apps/examples/ostest/vfork.c: Added a test of vfork(). - * apps/exampes/posix_spawn: Added a test of poxis_spawn(). + * apps/exampes/posix_spawn: Added a test of posix_spawn(). * apps/examples/ostest: Extend signal handler test to catch death-of-child signals (SIGCHLD). * apps/examples/ostest/waitpid.c: Add a test for waitpid(), waitid(), @@ -478,7 +478,7 @@ * apps/include/builtin.h: Some of the content of apps/include/apps.h moved to include/nuttx/binfmt/builtin.h. apps/include/apps.h renamed builtin.h - * apps/builtin/exec_builtins.c: Move utility builtin + * apps/builtin/exec_builtins.c: Move builtin utility functions from apps/builtin/exec_builtins.c to binfmt/libbuiltin/libbuiltin_utils.c * apps/nshlib/nsh_mountcmds.c: The block driver/source @@ -502,6 +502,8 @@ once when NSH starts; the .nshrc script will be executed for each session: Once for serial, once for each USB connection, once for each Telnet session. - * apps/system/readline: Correct realine return value. Was not + * apps/system/readline: Correct readline() return value. Was not any returning special values when end-of-file or read errors occur (it would return an empty string which is not very useful). + +6.26 2013-xx-xx Gregory Nutt diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index db62b9cf4..e2e7ae29b 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -3800,7 +3800,7 @@ * configs/stm32f4discovery/elf: Enable support/test of the PATH to find executables using a relative path. -6.25 2013-xx-xx Gregory Nutt +6.25 2013-02-01 Gregory Nutt * graphics/: Adds 5x8 monospace font. This tiny font is useful for graph labels and for small bitmapped display. Contributed by Petteri @@ -3833,7 +3833,7 @@ * drivers/usbhost/usbhost_hidkbd.c: Correct a logic error in how tasks waiting for read data are awakened. * libc/misc/lib_kbdencode.c and lib_kbddecode.c: Now handles keypress - events too. However, the USB HID keyboard drier has not yet been + events too. However, the USB HID keyboard driver has not yet been updated to detect key release events. That is kind of tricky in the USB HID keyboard report data. * configs/mcu123-214x/nsh: Converted to use the kconfig-frontends @@ -3857,7 +3857,7 @@ buildroot toolchains: They may be EABI or OABI. * include/nuttx/progmem and arch/arm/src/stm32/stm32_flash.c: Fix a counting bug plus change interface to use either relative - or absolut FLASH addressing (from Freddie Chopin). + or absolute FLASH addressing (from Freddie Chopin). * libc/misc/Make.defs: Fix error in conditional for KBD CODEC. * libc/Kconfig and configs/*/defconfig (several): The default setting should be CONFIG_LIB_KBDCODEC=n @@ -3868,7 +3868,7 @@ * tools/configure.bat: configure.bat is a small Windows batch file that can be used as a replacement for configure.sh in a Windows native environment. configure.bat is actually just a - thin layer that execuates configure.exe if it is available. If + thin layer that executes configure.exe if it is available. If configure.exe is not available, then configure.bat will attempt to build it first. * arch/arm/src/lpc17xx/lpc17_syscon.h: Correct some typos in bit @@ -3918,12 +3918,12 @@ the scenario: (1) sched_lock() is called increments the lockcount on the current TCB (i.e., the one at the head of the ready to run list), (2) sched_mergepending is called which may change the task - at the head of the readytorun list, then (2) sched_unlock() is called + at the head of the ready-to-run list, then (3) sched_unlock() is called which decrements the lockcount on the wrong TCB. The failure case that I saw was that pre-emption got disabled in the IDLE thread, locking up the whole system. * sched/sched_waitpid.c: Use SIGCHLD instead of a semaphore. This - is a much more spec-compliant implemenation. However, there are + is a much more spec-compliant implementation. However, there are some issues with overruning signals because NuttX does not support queueing of signals (POSIX does not require it). I think it may need to. @@ -3959,7 +3959,7 @@ CONFIG_APPS_BINDIR rename CONFIG_FS_BINFS * include/nuttx/binfmt/builtin.h: Some of the content of apps/include/apps.h moved to include/nuttx/binfmt/builtin.h - * binfmt/libbuiltin/libbuiltin_utils.c: Move utility builtin + * binfmt/libbuiltin/libbuiltin_utils.c: Move builtin utility functions from apps/builtin/exec_builtins.c to binfmt/libbuiltin/libbuiltin_utils.c * binfmt/builtin.c and binfmt/libbuiltin: Add a binary "loader" @@ -3985,7 +3985,7 @@ * arch/arm/src/[many]: More LPC1788 definitions from Rommel Marcelo incorporated. * configs/open1788: Board configuration for the Wave Share - Open1788 board. Still fragmentary (contribnuted by Rommel + Open1788 board. Still fragmentary (contributed by Rommel Marcelo, adapted to use kconfig-frontends. * net/send(): Add logic to work around delayed ACKs by splitting packets (contributed by Yan T.). @@ -4011,7 +4011,7 @@ * arch/armv7-m/up_hardfault.c: Fail if a hardfault occurs while CONFIG_ARM7VM_USEBASEPRI=y. * arch/arm/src/stm32/stm32_serial.c: Add support for USART - single wire more (Contributed by the PX4 team). + single wire mode (Contributed by the PX4 team). * sched/: Implement support for retaining child task status after the child task exists. This is behavior required by POSIX. But in NuttX is only enabled with CONFIG_SCHED_HAVE_PARENT and @@ -4022,7 +4022,7 @@ use the kconfig-frontends tools. * net/net_poll.c: Split net_poll() to create psock_poll() too. * net/net_poll.c: Fix poll/select issure reported by Qiang: - poll_interrupt() must cat call net_lostconnection() when a + poll_interrupt() must call net_lostconnection() when a loss of connection is reported. Otherwise, the system will not know that the connection has been lost. * sched/group_create.c, group_join.c, and group_leave.c: Add @@ -4051,7 +4051,7 @@ * configs/stm32f4discovery/nsh: Converted to use the kconfig-frontends tools. * configs/*/src/up_userleds.c: Fix a error that was cloned into - all STM32 user LED code. The wrong defintions were being used + all STM32 user LED code. The wrong definitions were being used to set LEDs on or off. * arch/*/common/up_internal.h and arch/*/common/up_initialize.c: Serial was driver was not being built if there is no console @@ -4072,8 +4072,7 @@ * drivers/serial/serial.c, include/nuttx/serial/serial.h, drivers/usbdev/cdcacm.c, and drivers/pl2303.c: Add support for removable serial devices (like USB serial). This support is enabled - by CONFIG_SERIAL_REMOVABLE and requires VBUS sensing support from - the board-specific logic. + by CONFIG_SERIAL_REMOVABLE. * arch/*/src/*/Toolchain.defs: Change assignment so that we can override CROSSDEV with a make command line argument. * include/assert.h: Mark assertion functions as non-returning. @@ -4096,3 +4095,5 @@ * arch/arm/src/stm32/stm32_spi.c: Fixes for SPI DMA work on the STM32F4. Includes untested additions for the F1 implementation as well. From Petteri Aimonen. + +6.26 2013-xx-xx Gregory Nutt diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index c5f1ebc9c..b4015bab7 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@

    NuttX RTOS

    -

    Last Updated: January 4, 2013

    +

    Last Updated: February 2, 2013

    @@ -456,6 +456,13 @@
  • ROMFS filesystem support.
  • + +
    + +

    +

  • BINFS pseudo-filesystem support.
  • +

    +
    @@ -468,6 +475,9 @@ Separately linked NXFLAT modules. NXFLAT is a binary format that can be XIP from a file system. +
  • + "Built-In" applications.
  • +

    @@ -1054,311 +1064,594 @@ -

    NuttX-6.24 Release Notes

    +

    nuttx-6.25 Release Notes

    - The 91st release of NuttX, Version 6.24, was made on December 20, 2012, and is available for download from the + The 92nd release of NuttX, Version 6.25, was made on February 1, 2013, and is available for download from the SourceForge website. - Note that the release consists of two tarballs: nuttx-6.24.tar.gz and apps-6.24.tar.gz. + Note that the release consists of two tarballs: nuttx-6.25.tar.gz and apps-6.25.tar.gz. Both may be needed (see the top-level nuttx/README.txt file for build information) The change log associated with the release is available here. Unreleased changes after this release are available in SVN. These unreleased changes are also listed here.

    - This release corresponds with SVN release number: r5447, + This release corresponds with SVN release number: r5594, Note that all SVN information has been stripped from the tarballs. If you need the SVN configuration, you should check out directly from SVN. - Revision r5447 should equivalent to release 6.24 of NuttX: + Revision r5594 should equivalent to release 6.25 of NuttX:

      -svn checkout -r5447 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
      +svn checkout -r5594 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
       

    Or (HTTP):

      -svn checkout -r5447 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
      +svn checkout -r5594 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
       

    Additional new features and extended functionality

    -
    • - RTOS: + OS Initialization +

      +
        +
      • + Removed support for CONFIG_BUILTIN_APP_START. + This is not really a useful feature and creates a violation of the OS layered architecture. +
      +
    • +
    • +

      + Task Creation +

      +
        +
      • + Implement a simple vfork()). + In NuttX-6.25, this interface is available only for ARM7/9, ARMv7-M (Cortext-M3/4), and MIPS32 (PIC32MX) platforms. +
      • +
      • + exec() now sets the priority of the new task to the same priority as the parent task (instead of the arbirtrary value of 50). +
      • +
      • + New, partially complient implementations of execv() and execl(). + These are only partially compliant because they do not overlay any existing "process space" but rather create the new task and exit(). +
      • +
      • + Add a complete implementation of posix_spawn(). + This standard interface is a better match for an MMU-less architecture than are vfork()) plus execv() or execl(). +
      • +
      • + Add a task start hook that will be called before the task main executes. + This can be used, for example, to schedule C++ static constructors to run automatically in the context of the new task. +
      • +
      +
    • +
    • +

      + Task Parentage

      • - Implemented the POSIX pause() function (still has some compiance issues). + Repartitioned tasking data structures. + All shared resources are now collected together in a "task group". + A "task group" includes the resource for the original task that are shared with all of the pthreads created by the task. +
      • +
      • + Added support for remember the parent "task group" when a new task is started. +
      • +
      • + Added optional support to record the membership of each thread in the "task group".
      • - Tasking logic is extended to support the notion of address environments. - An address environment is the key notion underlying "process" vs. tasks. - If tasks are created with address environments (by binfmt), the OS will propogate that environment to child threads and will destroy the address environment when all threads in the "process" exists. + Implement support for retaining child task status in the "task group" after the child task exists. + This is behavior required by POSIX. + But in NuttX is only enabled with CONFIG_SCHED_HAVE_PARENT and CONFIG_SCHED_CHILD_STATUS.
      • - If support for the PATH variable is enabled, the OS start up logic will create an initial environment containing the default PATH setting (CONFIG_PATH_INITIAL). - This initial PATH will then be inherited by all tasks. + Add internal logic to "reparent" a task. + This is useful, for example, where the child task is created through a trampoline task that redirects I/O. + Reparenting allows the caller of posix_spawn() to be reparented for the eventual child thread. +
      • +
      • + Added support for SIGCHLD. + Sent to all members of the parent "task group" when the finall member of the child task group exits. +
      • +
      • + If SIGCHLD and retention of child task exist status are enabled, then a more spec-compliant version of waitpid() is enabled. +
      • +
      • + New interfaces waitid() and wait() are also enabled when SIGCHLD is enabled.
    • - Binfmt: + File System

      • - The NuttX binary loaders have been updated to support the PATH environment variable. - Now, if the PATH is properly defined, programs can be executed from mass storage using only the file name. - This feature is added to support more standard behavior (eventually, NSH will support execution of programs in file systems by just entering the file name, perhaps in 6.25?). + dup() and dup2() can new be used with opened files in a mounted file system. + This supports re-direction of output in NSH to files. +
      • +
      • + The binfs file system was moved from apps/builtin to fs/binfs. + The binfs file system was extended to support execution of "builtin applications" using exec(), execv(), execl(), or posix_spawn().
      • - The NXFLAT and ELF binary loaders have been extended to create address environments for any new tasks executed from the file system. - This feature requires that the architecture support a memory management unit (MMU) and the address environment interfaces declared in include/nuttx/arch.h (currently, this is only supported by the z180). + Added logic based on SIGCHLD to automatically unload and clean-up after running a task that was loaded into memory.
    • - Drivers: - LCD driver for the Univision UG-2864AMBAG01 OLED + Binary Formats +

      +
        +
      • + Much of the logic for "builtin applications" was moved from apps/builtin to nuttx/binfmt/libbuiltin. + Includes some extensions contributed by Mike Smith. +
      • +
      • + A binary loader was added for builtin applications to support execution of "builtin applications" using exec(), execv(), execl(), or posix_spawn(). +
      • +
    • - STM32: - Support for STM32F100 high density chips contributed by Freddie Chopin. + Drivers +

      +
        +
      • + Added logic to marshal and serialized "out-of-band" keyboard commands (such as cursor controls and key release events) intermixed with normal ASCII keypress data. + The encoding is partially integrated in the HID keyboard driver and the decoding is fully integrated into the apps/examples hidkbd/ and keypadtest/ (the latter contributed by Denis Carlikli). +
      • +
      • + Driver for the UG-2864HSWEG01 OLED contributed by Darcy Gong. +
      • +
      • + Add support for removable serial devices (like USB serial). + This support is enabled by CONFIG_SERIAL_REMOVABLE. +
      • +
    • - STM32 Drivers: - Added optional RS-485 direction bit control (from Freddie Chopin). + ARMv7-M +

      +
        +
      • + Added an option to use the BASEPRI register to disable interrupts (instead of the PRIMASK register). + This eliminates some innocuous hardfaults that interfere with some debug tools. + You need to switch to the BASEPRI method only if you have such tool interference. +
      • +
    • - STM32 Boards: + STM32 Drivers

      • - Support for generic STM32F100RC board contributed by Freddie Chopin. + Bring STM32 F1 DMA capabilities up to par with the STM32 F2/F4 (contributed by Mike Smith).
      • - stm32f4discovery/nxlines: STM32F4Discovery support for the UG-2864AMBAG01 OLED. + Add support for USART single wire mode (Contributed by the PX4 team).
      • - stm32f4discovery/winbuild: A version of the NuttX OS test configured to build natively on Windows. + Updates to support for SPI DMA on the STM32 F1/F2/F4. + From Petteri Aimonen.
      • +
      +
    • +
    • +

      + STM32 Boards +

      +
      • - stm32f4discovery/elf: Now uses the PATH variable to find ELF executables. + New configuration to support the UG-2864HSWEG01 OLED on the STM32F4Discovery board.
      • - configs/cloudctrl: Added for Darcy Gong's CloudController board + Added a posix_spawn() test configuration for the STM32F4Discovery.
    • - PIC32 Boards: - Update the Mirtoo configuration for Release 2 of the Mirtoo module. + LM3S/LM4F +

      +
        +
      • + Files and directories repartitioned to support both LM3S and LM4F using the STM32 organization as a model. +
      • +
      • + Partial definitions for the LM4F contributed by Jose Pablo Carballo (this is still a work in progress). +
      • +
    • - Calypso: - Add Calypso keypad driver (from Denis Carilki). + LM3S Boards +

      +
        +
      • + Added scripts and documentation to use OpenOCD with the LM3S (from Jose Pablo Carballo). +
      • +
    • - ZiLOG: + LPC176x/LPC178x

      • - Add support for the z180 chip family and, specifically, for the P112 retro hardware (see http://p112.feedle.net/). + Files and directories repartitioned to support both LPC175x/LPC176x and the LPC177x/LPC178x families using the STM32 organization as a model. + The LPC1788 port is a work in progress by Rommel Marcelo.
      • +
      +
    • +
    • +

      + LPC176x/LPC178x Boards +

      +
      • - All ZiLOG configurations updated to use the current ZDS-II and/or SDCC toolchains. + Added a configuration to support the Wave Share Open1788 board. + This is still a work in progress by Rommel Marcelo.
    • - Graphics: + LPC2148 Boards

      • - Add a semaphore handshake so that operations on buffers from the NXMU client will be blocked until the NX server operates on the buffer data (from Petteri Aimonen). + Add basic support for the The0.net ZP213x/4xPA board (with the LPC2148 and the UG_2864AMBAG01 OLED).
      • - nxtk_subwindowmove() and nxtk_getwindow(): Improvements to clipping logic from Petteri Aimonen. -
      • + Add an nxlines configuration for the ZP213x/4xPA (with the LPC2148 and the UG_2864AMBAG01). +
    • - C Library: - lib/ sub-directory renamed libc/ (there is a new lib/ sub-directory that is used to hold all archives). + Simulator +

      +
        +
      • + Add an nxlines configuration for the simulator. +
      • +
    • - C++: - Exception stubs from Petteri Aimonen. + Networking +

      +
        +
      • + Add logic to work around delayed ACKs by splitting packets (contributed by Yan T.). +
      • +
      • + Split net_poll() to create the internal interface psock_poll(). +
      • +
    • - Applications: + LCDs

      • - Add NSH hexdump command to dump the contents of a file (or character device) to the console (contributed by Petteri Aimonen). -
      • -
      • - Extend the NSH ifconfig command plus various DHCPC improvements (from Darcy Gong). + Added support for LCD1602 alphanumeric LCD (HD4468OU controller).
    • - apps/examples: + Graphics

      • - ostest: Replace large tables with algorithmic prime number generation. - This allows the roundrobin test to run on platforms with minimal SRAM (Freddie Chopin). + Added 5x8 monospace font. + This tiny font is useful for graph labels and for small bitmapped display. + Contributed by Petteri Aimonen.
      • +
      +
    • +
    • +

      + Build System +

      +
      • - keypadtest: A new keypad test example contributed by Denis Carikli. + Add an options to better manage toolchain prefixes.
      • - elf and nxflat: If CONFIG_BINFMT_EXEPATH is defined, these examples will now use a relative path to the program and expect the binfmt/ logic to find the absolute path to the program using the PATH variable. + Redesigned how the context targer works in the apps/ directory. + The old design caused lots of problems when changing configurations because there is no easy way to get the system to rebuild the context. + This change should solve most the problems and eliminate questions like "Why don't I see my builtin application in NSH?"
    • - Build system: + Kconfig Files

      • - New top-level Makefiles: Makefile.unix and Makefile.win (along with numerous changes to other make-related files). - This adds basic support for building NuttX natively under from Windows console (rather than in a POSIX-like environment). - This build: (1) Uses all Windows style paths, (2) Uses primarily standard Windows batch commands with (3) a few additional commands from GNUWin32 (such as GNU make). + There are several new configurations that use the kconfig-frontends tools and several older configurations that have been converted to use these tools. + There is still a long way to go before the conversion is complete:

        -

        - This capability should still be considered a work in progress because: (1) It has not been verfied on all targets and tools, and (2) it still lacks some of the creature-comforts of the more mature environments (like a functional configure.sh script and make menuconfig support). +

          +
        • + configs/sim/nxwm +
        • +
        • + configs/sim/nsh +
        • +
        • + configs/stm3220g-eval/nxwm +
        • +
        • + configs/stm32f4discovery/posix_spawn +
        • +
        • + configs/olimex-lpc1766stk/nsh +
        • +
        • + configs/olimex-lpc1766stk/hidkbd +
        • +
        • + configs/olimex-lpc1766stk/nettest +
        • +
        • + configs/open1788/ostest +
        • +
        • + configs/stm32f4discovery/nsh +
        • +
        • + configs/stm32f4discovery/usbnsh +
        • +
        • + configs/lm326965-ek (all configurations) +
        • +
        • + configs/mcu123-214x/nsh +
        • +
        • + configs/ubw32/ostest +
        • +
      • +
      +
    • +
    • +

      + Tools +

      +
      • - Example Windows native builds for STM32F4Discovery, eZ80, z16f, z8, Z80, and Z180. + tools/kconfig.bat: Kludge to run kconfig-frontends from a DOS shell.
      • - Several configurations have been converted to work the kconfig-frontends mconf configuration tool: stm32f4discovery/nxlines, and all eZ80, z16f, z8, Z80, and Z180 configurations. + tools/configure.c: configure.c can be used to build a work-alike program as a replacement for configure.sh. + This work-alike program would be used in environments that do not support Bash scripting (such as the Windows native environment).
      • - Architectures now include a common Toolchain.defs file that can be used to manage toolchains in a more configurable way (most of this contributed by Mike Smith). + tools/configure.bat: configure.bat is a small Windows batch file that can be used as a replacement for configure.sh in a Windows native environment. + configure.bat is actually just a thin layer that executes configure.exe if it is available. + If configure.exe is not available, then configure.bat will attempt to build it first (assumes the MinGW-GCC is available).
    • - Build tools: + Applications

      • - Renamed tools/winlink.sh to tools/copydir.sh. + New and modified examples: +

        +

          +
        • + apps/examples/wlan: Remove non-functional example. +
        • +
        • + apps/examples/ostest: Added a test of vfork()). + Extend signal handler test to catch death-of-child signals (SIGCHLD). + Add a test for waitpid(), waitid(), and wait(). +
        • +
        • + apps/exampes/posix_spawn: Added a test of posix_spawn(). +
        • +
        +

      • - Several new tools/scripts to support the Windows native build: tools/mkdeps.bat, tools/mkdeps.c, tools/link.bat, tools/unlink.bat, and tools/ copydir.bat. + NSH: +

        +

          +
        • + NSH now supports re-direction of I/O to files (but still not from). +
        • +
        • + The block driver source argument to the mount command is now optional for file systems that do not require a block driver. +
        • +
        +

        +
      • +
      • + NSH can now execute a program from a file system using posix_spawn(). +
      • +
      • + Added support for a login script. + The init.d/rcS script will be executed once when NSH starts; + the .nshrc script will be executed for each session: + Once for a serial console, once for each USB connection, and once for each Telnet session.
      • - tools/incdir.sh and tools/incdir.bat now support an -s option to generate system header file paths. + Supports a new daemon that can be used to monitor USB trace outpout.
      • - tools/b16.c: Fixed precision math conversion utility. + Removed non-functional wlan example.
    -

    Bugfixes (see the change log for details). - Some of these are very important (marked critical): + Some of these are very important:

    • - RTOS: - Fix some backward conditional compilation in the work queue logic (Freddie Chopin). + Tasking +

      +
        +
      • + Fixed a *critical* task exit bug. + Here is the failure scenario: + (1) sched_lock() is called increments the lockcount on the current TCB (i.e., the one at the head of the ready to run list), + (2) sched_mergepending() is called which may change the task at the head of the ready-to-run list, then + (3) sched_unlock() is called which decrements the lockcount on the wrong TCB. + The failure case that I saw was that pre-emption got disabled in the IDLE thread, locking up the whole system. +
      • +
    • - File System: - Uninitialized variable caused assertions (from Lorenz Meier). + Signals +

      +
        +
      • + sigtimedwait() would return a bad signal number if the signal was already pending when the function was called. +
      • +
    • - Drivers: - Partial fix for STM32 OTG FS device drivers and fix for short, unaligned writes in the flash translation layer (drivers/mtd/ftl.c), both from Petteri Aimonen. + Drivers +

      +
        +
      • + Some SD cards will appear busy until switched to SPI mode for first time. + Having a pull-up resistor on MISO may avoid this problem, but this fix from Petteri Aimonen makes it work also without pull-up. +
      • +
    • - STM32 Drivers: + STM32 Drivers

      • - Qencoder driver and TIM3 driver fixes from Ryan Sundberg. + STM32 FLASH driver counting error (from Freddie Chopin).
      • - Fix timeout delay calculation in the STM32 OTG FS host driver. + STM32 F4 maximum SPI frequency was wrong (corrected by Petteri Aimonen).
    • - LPC17xx Drivers: - Resources not being properly released when I2C driver is un-initialized. + STM32 Boards +

      +
        +
      • + Due to cloning of untested code, the logic to control on-board LEDs did not work on any STM32 boards. +
      • +
      • + Serial devices number /dev/ttyS0-5 is there is a serial console, but /dev/ttyS1-6 if there is no serial console. +
      • +
    • - Graphics: + Binary Formats

      • - Fix logic when the mouse drags outside of the window; fix another "blocked message" handling case (both from Petteri Aimonen). + C++ static constructors execute now using a start taskhook so that they execute in the context of the child task (instead of in the context of the parent task).
      • +
      +
    • +
    • +

      + File Systems +

      +
      • - nxtk_filltrapwindow(): Correct an offset problem (also from Peterri Aimonen). + Several FAT-related bugs fixed by Petteri Aimonen.
      • +
      +
    • +
    • +

      + Networking +

      +
      • - nxglib_splitline(): Correct the "fat flat line" bug. + Fix poll/select issure reported by Qiang: poll_interrupt() must call net_lostconnection() when a loss of connection is reported. + Otherwise, the system will not remember that the connection has been lost and will hang waiting on a unconnected socket later. +
      • +
      • + Similar issues corrected for recvfrom() and send(). +
      • +
      • + Telnetd would hang in a loop if recv() ever returned a value <= 0.
    • - C Library: + Libraries

      • - nrand() changes to prevent coefficients from becoming zero which would "lock up" the random number generate. + fread() could hang on certain error conditions.
      • - Add rounding functions to the math library (contributed by Petteri Aimonen). + Can't handle SYSLOG output to a character device from the IDLE task (because the IDLE task can't block).
    • - Build system: - Changes to MIN definitions in all limit.h header files to avoid integer overflows. - For example from (-128) to (-127 - 1) (from Petteri Aimonen). + Build System +

      +
        +
      • + Serial was driver was not being built if there is no console device. + Obviously, the serial driver may be needed even in this case. +
      • +
    • - Applications: - Modbus fixes from Freddie Chopin. + Additional Bugfixes +

      +
        +
      • + sig_timedwait() and clock_time2ticks.c: Timing "rounding" logic +
      • +
      • + ARM9 Compilation issue with low vectors. +
      • +
      • + readline() return value +
      • +
      • + As well as other, less critical bugs as detailed in the ChangeLog: HID keyboard, LPC17xx bit definitions, strndup(), PL2303, SYSLOG error handling, AT25, apps/examples. +
      • +
    -

    - As well as other, less critical bugs. See the ChangeLog for additional, detailed changes.

    @@ -3432,311 +3725,421 @@ Other memory:
      -nuttx-6.24 2012-12-20 Gregory Nutt <gnutt@nuttx.org>
      -
      -    * arch/arm/src/stm32:  Support for STM32F100 high density chips
      -      added by Freddie Chopin.
      -    * configs/stm32f100_generic:  Support for generic STM32F100RC board
      -      contributed by Freddie Chopin.
      -    * arch/arm/src/stm32_otgfsdev.c:  Partial fix from Petteri Aimonen.
      -    * drivers/lcd/ug-2864ambag01.c and include/nuttx/lcd/ug_2864ambag01.h:
      -      LCD driver for the Univision OLED of the same name (untested on
      -      initial check-in).
      -    * configs/stm32f4discovery/nxlines:  Configure to use mconf/Kconfig
      -      tool.
      -    * configs/stm32f4discovery/src/up_ug2864ambag01.c:  Board-specific
      -      initialization for UG-2864AMBAG01 OLED connecte to STM32F4Disovery.
      -    * libxx/libxx_stdthrow.cxx:  Exception stubs from Petteri Aimonen.
      -    * configs/stm32f4discovery/src/up_ug2864ambag01.c: Driver has been
      -      verified on the STM32F4Discovery platform.  Some tuning of the
      -      configuration could improve the presentation.  Lower resolution displays
      -      are also more subject to the "fat, flat line bug" that I need to fix
      -      someday.  See http://www.nuttx.org/doku.php?id=wiki:graphics:nxgraphics
      -      for a description of the fat, flat line bug.
      -    * libc:  Renamed nuttx/lib to nuttx/libc to make space for a true lib/
      -      directory that will be forthcoming.  Also rename libraries:  liblib.a -> libc.a,
      -      libulib.a -> libuc.a, libklib.a -> libkc.a, liblibxx.a ->libcxx.a.
      -      (I will probably, eventually rename libxx to libcxx for consistency)
      -    * Makefile, lib/: A new, empty directory that will hold generated libraries.
      -      This simplifies the library patch calculations and lets me get rid of some
      -      bash logic.  The change is functional, but only partially complete;
      -      additional logic is needed in the arch/*/src/Makefile's as well.  Right
      -      now that logic generate multiple library paths, all pointing to the lib/
      -      directory.
      -    * arch/*/src/Makefile:  Now uses only the libraries in lib/
      -      Replace bash fragments that test for board/Makefile.
      -    * Makefile.win:  The beginnings of a Windows-native build.  This is just
      -      the beginning and not yet ready for prime time use.
      -    * configs/stm32f4discovery/winbuild:  This is a version of the standard
      -      NuttX OS test, but configured to build natively on Windows.  Its only
      -      real purpose is to very the native Windows build logic.
      -    * tools/mkdeps.bat and tools/mkdeps.c:  mkdeps.bat is a failed attempt
      -      to leverage mkdeps.sh to CMD.exe.  It fails because the are certain
      -      critical CFLAG values that cannot be passed on the CMD.exe command line
      -      (like '=').  mkdeps.c is a work in progress that will, hopefully,
      -      replace both mkdeps.sh and mkdeps.bat.
      -    * tools/Config.mk:  Centralize the definition of the script that will be
      -      used to generated header file include paths for the compiler.  This
      -      needs to be centralized in order to support the Windows native build.
      -    * tools/incdir.bat:  A replacement for tools/incdir.sh for use with the
      -      the Windows native build.
      -    * Makefile.unix:  The existing top-level Makefile has been renamed
      -      Makefile.unix.
      -    * Makefile:  This is a new top-level Makefile that just includes
      -      either Makefile.unix or Makefile.win
      -    * configs/stm3240g-eval/src:  Qencoder fixes from Ryan Sundberg.
      -    * arch/arm/src/stm32/stm32_qencoder.c: TIM3 bug fix from Ryan Sundberg.
      -    * tools/mkromfsimg.sh: Correct typo in an error message (Ryan Sundberg)
      -    * arch/*/src/Makefile:  Remove tftboot install and creation of System.map
      -      for Windows native build.  The first is a necessary change, the second
      -      just needs re-implemented.
      -    * configs/mirtoo: Update Mirtoo pin definitions for Release 2.  Provided
      -      by Konstantin Dimitrov.
      -    * Fixed an uninitialized variable in the file system that can cause 
      -      assertions if DEBUG on (contributed by Lorenz Meier).
      -    * Config.mk:  Defined DELIM to be either / or \, depending upon
      -      CONFIG_WINDOWS_NATIVE.  This will allow me to eliminate a lot of
      -      conditional logic elsewhere.
      -    * nuttx/graphics: One a mouse button is pressed, continue to report all
      -      mouse button events to the first window that received the the initial
      -      button down event, even if the mouse attempts to drag outside the
      -      window. From Petteri Aimonen.
      -    * nuttx/graphics/nxmu/nx_block.c:  One more fix to the NX block message
      -      logic from Petteri Aimonen.
      -    * include/nuttx/wqueue.h: Some basic definitions to support a user-
      -      space work queue (someday in the future).
      -    * graphics/nxmu:  Add semaphores so buffers messages that send buffers
      -      will block until the buffer data has been acted upon.
      -    * graphics/nxmw:  Extended the blocked messages to cover mouse movement
      -      and redraw events.  These will also cause problems if sent to a window
      -      while it is closing.
      -    * arch/several:  Change UARTs are enabled for i.MX, LM3S, ez80, and M16C to
      -      match how they are enabled for other architectures.
      -    * configs/ez80f910200kitg:  Convert to use mconf configuration.
      -    * sched/pause.c:  Implements the POSIX pause() function.
      -    * ez80: Lots of changes to ez80 configurations and build logic as I
      -      struggle to get a clean Windows build (still not working).
      -    * configs/cloudctrl:   Darcy Gong's CloudController board.  This is a
      -      small network relay development board. Based on the Shenzhou IV development
      -      board design.  It is based on the STM32F107VC MCU.
      -    * arch/arm/src/stm32_serial.c and stm32_lowputc.c:  Added optional RS-485
      -      direction bit control. From Freddie Chopin.
      -    * Lots of build files:  ARMv7-M and MIPS32 Make.defs now include a common
      -      Toolchain.defs file that can be used to manage toolchains in a more
      -      configurable way.  Contributed by Mike Smith
      -    * configs/stm32f4discovery/winbuild and configs/cloudctrl:  Adapted to use
      -      Mike's Toolchain.defs.
      -    * tools/configure.sh:  Adapted to handle paths and setenv.bat files correctly
      -      for native Windows builds.
      -    * More of build files:  AVR and AVR32 Make.defs now include a common
      -      Toolchain.defs file that can be used to manage toolchains in a more
      -      configurable way.  Contributed by Mike Smith
      -    * tools/incdir.sh and incdir.bat: Add -s option to generate system header
      -      file paths.
      -    * nuttx/arch/arm/src/arm/Toolchain.defs: Add support for more ARM toolchains
      -      (from Mike Smith).
      -    * arch/arm/src/stm32/stm32f40xxx_rcc.c:  Enabled FLASH prefetch (from Petteri
      -      Aimonen).
      -    * graphics/nxtk/nxtk_filltrapwindow.c:  Correct an offset problem (from
      -      Peterri Aimonen).
      -    * graphics/nxglib/nxglib_splitline.c:  Fix error in drawing of near horizontal
      -      lines (from Peterri Aimonen).
      -    * sched/task_exithook.c:  Missing right bracket with certain conditional
      -      compilation (thanks James Goppert).
      -    * arch/arm/srch/stm32/stm32_otgfshost.c:  Replace timeout handling; use
      -      system tick instead of frame counter.  The frame counter gets reset to
      -      zero at 0x3fff making it error prone.
      -    * arch/arm/src/stm32/stm32f20xx_rcc.c and stm32f40xx_rcc.c: Added option
      -      CONFIG_STM32_FLASH_PREFETCH.  FLASH prefetch will now only be enabled
      -      if this option is selected.
      -    * confgs/ez80f910200zco/ostest:  Now uses Kconfig/mconf configuration
      -      tool. Updated to build in native Windows environment.  Other ez80f910200zco
      -      build scripts also updated.
      -    * configs/z8f64200100kit/ostest: Update to same level as ez80 configurations.
      -    * nuttx/configs/z8f64200100kit/scripts/setenv.bat: Add support for native
      -      Windows build.
      -    * nuttx/arch/arm/src/lpc17xx/lpc17_i2c.c: Resources not being released when
      -      I2C is uninitialized.
      -    * cloudctrl/src/up_chipid.c and shenzhou/src/up_chipid.c:  Add functions to
      -      get chip ID.  Contributed by Darcy Gong.  These should not be board-dependent,
      -      but should be in arch/arm/src/stm32 where they can be used from any board.
      -    * sched/work_thread.c: Fix backward conditional compilation.  This might
      -      has caused a memory leak.  From Freddie Chopin.
      -    * configs/<many>/Make.defs:  Fix typo -wstrict-prototypes should be
      -      -Wstrict-prototypes (From Denis Carilki).
      -    * arch/arm/src/calapyso/calypso_keypad.c:  Add Calypso keypad driver.  From
      -      Denis Carilki.
      -    * z8encore000zco/ostest and z8f64200100kit/ostest:  Converted to use Kconfig/
      -      mconf configuration tool.
      -    * arch/arm/src/armv7-m/up_exception.S: missing curly braces for push/pop
      -      From Freddie Chopin.
      -    * z8encore000zco/ostest and z8f64200100kit/ostest:  Can now be modified to
      -      support the Windows native builds (see corresponding README.txt files).
      -    * configs/z16f2800100zcog - All configurations updated to use the ZDS-II
      -      5.0.1 toolchain.
      -    * configs/z16f2800100zcog - All configurations updated to use Kconfig/mconf
      -      configuration tools.
      -    * configs/z16f2800100zcog/ostest - Now supports a native Windows build
      -      (other ZNEO configs may also support the native build, but this has not
      -      been verfiied).
      -    * include/nuttx/input/keypad.h, arch/arm/src/calypso/calypso_keypad.c, and
      -      configs/compal_e99/nsh_highram: First cut at a standard keypad interface
      -      definition.  Contributed by Denis Carikli.
      -    * libc/stdlib/lib_rand.c:  Always add one to result congruential generators
      -      to avoid the value zero.  Suggested by Freddie Chopin.
      -    * tools/b16.c:  Fixed precision math conversion utility.
      -    * graphics/nxglib/nxglib_splitline.c:  Fix the "fat, flat line bug"
      -    * arch/z80/src/*/Toolchain.defs:  Add dummy Toolchain.defs files for the
      -      z80 family.
      -    * configs/z80sim/ostest:  Converted to build with the Kconfig/mconf tool.
      -      Current configuration failed to build for me (Ubuntu 12.10, SDCC 3.2.0
      -      pre-built for Linux) due to a glibc memory corruptionerror in SDCC.
      -    * configs/z80sim/ostest: Default is now the Windows native build.  See
      -      configs/z80sim/README.txt for instructions to convert back to a Linux or
      -      or Cygwin build.
      -    * arch/z80/src/Makefile.sdccw:  Renamed makefiles with extensions zdiil,
      -      zdiiw, sdccl, and sdccw for the ZDS-II vs SDCC compilers and for the
      -      POSIX vs Windows native builds.
      -    * nuttx/drivers/mtd/ftl.c:  Fix for the flash translation layer. Short
      -      unaligned writes were buggy.  From Petteri Aimonen.
      -    * nuttx/libc/math/lib_round*.c:  Add rounding functions to the math
      -      library.  Contributed by Petteri Aimonen.
      -    * include/cxx/cstdlib:  Add stroul().  From Petteri Aimonen.
      -    * arch/*/include/limits.h:  Change signed minimum values from, for example,
      -      (-128) to (-127 - 1) to avoid overflows under certain conditions.  From
      -      Peterri Aimonen.
      -    * graphics/nxtk/nxtk_subwindowmove.c: Previously it was very difficult to
      -      do e.g. "scroll by dx, dy". When given the full window area, nxtk_subwindowmove
      -      would clip the offset always to 0,0. It makes more sense for it to clip the
      -      source area and not modify the offset.  From Petteri Aimonen.
      -    * graphics/nxtk/nxtk_getwindow.c: Clipping would change the offset of returned
      -      data, and caller has no way to know what the new offset would be. This messes
      -      up font drawing when the text is partially out of window, e.g. when scrolling.
      -      Also from Petteri Aimonen.
      -    * include/stdbool.h: Can now be disabled for C++ files if CONFIG_C99_BOOL8 is
      -      defined.  CONFIG_C99_BOOL8 indicates (1) that the sizeof(_Bool) is one in both
      -      C and C++, and (2) the the C compiler is C99 and supports the _Bool intrinsic
      -      type. Requested by Freddie Chopin.
      -    * include/stdlib/lib_rand.c:  Various additional changes so that the integer
      -      value zero can be returned.  Requested by Freddie Chopin.
      -    * arch/z80/src/Makefile.sdcc*, z80/up_mem.h:  Redesign Z80 build so that it
      -      no longer depends on Bash scripts.
      -    * configs/z80sim/nsh and pashello:  Converted to (1) use the kconfig-frontends
      -      configuration tool, and (2) to build natively under Windows.  The NSH
      -      configuration is verified; the pashello configuration needs a more TLC.
      -    * tools/copydir.sh:  Rename tools/winlink.sh to tools/copydir.sh
      -    * tools/link.bat, unlink.bat, and copydir.bat:  Add Windows counterparts
      -      to the link.sh, unlink.sh, and copydir.sh Bash scripts.
      -    * configs/z80sim/pashello:  Now builds correctly.
      -    * configs/xtrs/ostest, nsh, and pashello:  Converted to (1) use the kconfig-
      -      frontends configuration tool, and (2) to build natively under Windows.
      -    * drivers/serial/Kconfig and sched/Kconfig:  Two names for same configuration:
      -      CONFIG_LOWLEVEL_CONSOLE is bogus and CONFIG_DEV_LOWCONSOLE is in the wrong
      -      Kconfig file.  Moved to drivers/serial/Kconfig replacing CONFIG_LOWLEVEL_CONSOLE.
      -    * arch/z80/include/z180:  Add header files for z180 chips.  Initial versions
      -      are just clones of z80 header files.
      -    * arch/z80/src/z180:  Add source files for z180 chips.  Initial versions
      -      are just clones of z80 source files.
      -    * include/nuttx/arch.h:  Add address environment control interfaces (for use
      -      with CPUs the provide MCUs and support process-like address environments).
      -    * arch/z80/src/z180/z180_mmu.*:  Add MMU support for z180 tasks.
      -    * configs/p112:  Add very basic board support and an examples/ostest
      -      configuration for the venerable P112 board.
      -    * sched/os_bringup.c: If CONFIG_PATH_INITIAL is defined, then the initial
      -      environment of the task started by os_bringup() will have the PATH
      -      environment variable defined to be that string.
      -    * binfmt/binfmt_exepath.c:  If CONFIG_BINFMT_EXEPATH is defined, then this
      -      file will be built.  It contains logic to search for regular files at
      -      the absolutes paths found in the current PATH environment variable
      -      setting.  This is untested and not yet hooked into the binfmt exec()
      -      logic on initial check-in
      -    * binfmt/binfmt_loadmodule.c: load_module() will now traverse the PATH
      -      variable to locate files from their relative path.
      -    * include/nuttx/arch.h and arch/z80/src/z180/z180_mmu.c:  Restructure the
      -      address environment interfaces so that they will better integrate with
      -      binfmt/.
      -    * binfmt/libelf/*, binfmt/libnxflat/* and other files:  Integrate the
      -      address environment interfaces.  If CONFIG_ADDRENV=y, then binfmt/
      -      will now create an address environment for new tasks (instead of
      -      just malloc'ing the task memory).
      -    * configs/stm32f4discovery/elf:  Enable support/test of the PATH
      -      to find executables using a relative path.
      -
      -apps-6.24 2012-12-20 Gregory Nutt <gnutt@nuttx.org>
      -
      -    * apps/examples/ostest/roundrobin.c:  Replace large tables with
      -      algorithmic prime number generation.  This allows the roundrobin
      -      test to run on platforms with minimal SRAM (Freddie Chopin).
      -    * apps/nshlib/nsh_dbgcmds.c:  Add hexdump command to dump the contents
      -      of a file (or character device) to the console  Contributed by Petteri
      +nuttx-6.25 2013-02-01 Gregory Nutt <gnutt@nuttx.org>
      +
      +    * graphics/: Adds 5x8 monospace font. This tiny font is useful for graph
      +      labels and for small bitmapped display.  Contributed by Petteri
             Aimonen.
      -    * apps/examples/modbus:  Fixes from Freddie Chopin
      -    * apps/examples/modbus/Kconfig: Kconfig logic for FreeModBus contributed
      -      by Freddie Chopin.
      -    * Makefile, */Makefile:  Various fixes for Windows native build.  Now uses
      -      make foreach loops instead of shell loops.
      -    * apps/examples/elf/test/*/Makefile: OSX doesn't support install -D, use
      -      mkdir -p then install without the -D.  From Mike Smith.
      -    * apps/examples/relays/Makefile: Reduced stack requirement (Darcy Gong).
      -    * apps/nshlib and apps/netutils/dhcpc:  Extend the NSH ifconfig command plus
      -      various DHCPC improvements(Darcy Gong).
      -    * apps/nshlib/nsh_apps.c: Fix compilation errors when CONFIG_NSH_DISABLEBG=y.
      -      From Freddie Chopin.
      -    * Rename CONFIG_PCODE and CONFIG_FICL as CONFIG_INTERPRETERS_PCODE and
      -      CONFIG_INTERPRETERS_FICL for consistency with other configuration naming.
      -    * apps/examples/keypadtest:  A keypad test example contributed by Denis
      -      Carikli.
      -    * apps/examples/elf and nxflat:  If CONFIG_BINFMT_EXEPATH is defined, these
      -      tests will now use a relative path to the program and expect the binfmt/
      -      logic to find the absolute path to the program using the PATH variable.
      -
      -NxWidgets-1.4 2012-12-20 Gregory Nutt <gnutt@nuttx.org>
      -
      -    * libnxwidgets/Makefile, NxWidgets/nxwm/Makefile, and
      -      NxWidgets/UnitTests/nxwm/Makefile:  Makefile improvements from
      -      submitted by Petteri Aimonen.  Other Makefiles in the UnitTests
      -      directory probably also need these changes.
      -    * libnxwidgets/src/ccallback.cxx: Fix misplaced #endif.  Provided
      -      by Petteri Aimonen.
      -    * libnxwidgets/src/cnxserver.cxx:  Reduce delay to allow NX server
      -      to start.  One second was un-necessarily long.  Reduced to 50 MS.
      -      Reduction suggested by Petteri Aimonen.
      -    * tools/bitmap_converter.py:  This script converts from any image type
      -      supported by Python imaging library to the RLE-encoded format used by
      -      NxWidgets.
      -    * NxWidgets/nxwm/src/capplicationwindow.cxx: If the "desktop" is empty,
      -      users have no need to minimize any windows. If the buttons are small,
      -      it's easy to hit minimize button accidentally when trying to close an
      -      application.  Contributed by Petteri Aimonen.
      -    * NxWidgets/nxwm/src/ctaskbar.cxx:  Add an option to eliminate the
      -      background image.  Contributed by Petteri Aimonen.
      -    * NxWidgets/nxwm/src/chexcalculator.cxx and NxWidgets/nxwm/src/cstartwindow.cxx:
      -      The config settings CONFIG_NXWM_STARTWINDOW_ICON and CONFIG_NXWM_HEXCALCULATOR_ICON
      -      allow changing the icons used for these applications. However, to declare symbols
      -      for these icons user would need to modify NxWidgets header files.
      -      This commit adds a simple forward declaration to the relevant files, based on the
      -      configured icon. If the icon does not exist, linker will give an error about it.
      -      Contributed by Petteri Aimonen.
      -    * NxWidgets::CTaskBar: Highlight the current window in the task bar.
      -      Contributed by Petteri Aimonen.
      -    * NxWidgets/libnxwidgets/src/glyph_cycle.cxx:  Width of glyph_cycle was wrong;
      -      Destructor needs to by public.  From Petteri Aimonen.
      -    * NxWidgets::CNumericEdit.  This is basically a label with plus and minus buttons.
      -      Contributed by Petteri, Aimonen.
      -    * NxWM::CStartWindow:  Fix mq_receive error handling with signal is recieved.
      +    * configs/stm3220g-eval/nxwm:  Converted to use the kconfig-frontends
      +      configuration tool.
      +    * configs/sim/nxwm:  Converted to use the kconfig-frontends configuration
      +      tool.
      +    * include/pthread.h:  In sys/prctl.h because it is needed by
      +      pthread_[set|get]name_np()
      +    * tools/kconfig.bat:  Kludge to run kconfig-frontends from a DOS shell.
      +    * sched/sig_timedwait.c:  Should always move the time up to the next
      +      largest number of system ticks.  The logic was rounding.  Noted by
      +      Petteri Aimonen.
      +    * arch/arm/src/up_head.S:  Fix backward conditional compilation.  NOTE
      +      there is a issue of ARM9 systems with low vectors and large memories
      +      that will have to be addressed in the future.
      +    * libc/misc/lib_kbdencode.c and lib_kbddecode.c:  Add logic to marshal
      +      and serialized "out-of-band" keyboard commands intermixed with normal
      +      ASCII data (not yet hooked into anything).
      +    * drivers/usbhost/usbhost_hidkbd.c:  If CONFIG_HIDKBD_ENCODED is
      +      defined, this driver will now use libc/misc/lib_kbdencode.c to
      +      encode special function keys.
      +    * configs/olimex-lpc1766stk/hidkbd:  This configuration has been
      +      converted to use the kconfig-frontends configuration tool.
      +    * drivers/lcd/ug-2864hsweg01.c and include/nuttx/lcd/ug-2864hsweg01.h:
      +      Driver for UG-2864HSWEG01 OLED contributed by Darcy Gong.
      +    * configs/stm32f4discovery/src/up_ug2864hsweg01.c: Support for the
      +      UG-2864HSWEG01 OLED for the STM32F4Discovery board.
      +    * drivers/usbhost/usbhost_hidkbd.c:  Correct a logic error in how
      +      tasks waiting for read data are awakened.
      +    * libc/misc/lib_kbdencode.c and lib_kbddecode.c:  Now handles keypress
      +      events too.  However, the USB HID keyboard driver has not yet been
      +      updated to detect key release events.  That is kind of tricky in
      +      the USB HID keyboard report data.
      +    * configs/mcu123-214x/nsh:  Converted to use the kconfig-frontends
      +      configuration tool.
      +    * configs/zp214xpa:  Add basic support for the The0.net ZP213x/4xPA
      +      board (with the LPC2148 and the UG_2864AMBAG01).
      +    * configs/sim/nxlines:  Add an nxlines configuration for the
      +      simulator.
      +    * configs/zp214xpa/nxlines:  Add an nxlines configuration for the
      +      ZP213x/4xPA (with the LPC2148 and the UG_2864AMBAG01).  Working
      +      as of 2012-12-30.
      +    * configs/olimex-lpc1766stk/wlan:  Remove non-functional
      +      configuration.
      +    * configs/stm32f4discovery/src and nuttx/drivers/lcd/ug-2864hsweg01.c:
      +      Updates and correctinos for the UG-2864HSWEG01 from Darcy Gong.
      +    * configs/lm326965-ek:  All configurations converted to use the
      +      kconfig-frontends configuration tool.
      +    * configs/Kconfig: NSH_MMCSDSPIPORTNO should depend on MMCSD_SPI,
      +      not just SPI (from Jose Pablo Carballo).
      +    * arch/arm/src/arm/Kconfig and armv7m/Kconfig:  Add an option for
      +      buildroot toolchains:  They may be EABI or OABI.
      +    * include/nuttx/progmem and arch/arm/src/stm32/stm32_flash.c:
      +      Fix a counting bug plus change interface to use either relative
      +      or absolute FLASH addressing (from Freddie Chopin).
      +    * libc/misc/Make.defs:  Fix error in conditional for KBD CODEC.
      +    * libc/Kconfig and configs/*/defconfig (several):  The default
      +      setting should be CONFIG_LIB_KBDCODEC=n
      +    * tools/configure.c:  configure.c can be used to build a work-alike
      +      program as a replacement for configure.sh.  This work-alike
      +      program would be used in environments that do not support Bash
      +      scripting (such as the Windows native environment).
      +    * tools/configure.bat: configure.bat is a small Windows batch
      +      file that can be used as a replacement for configure.sh in a
      +      Windows native environment.  configure.bat is actually just a
      +      thin layer that executes configure.exe if it is available. If
      +      configure.exe is not available, then configure.bat will attempt
      +      to build it first.
      +    * arch/arm/src/lpc17xx/lpc17_syscon.h:  Correct some typos in bit
      +      definitions (from Rommel Marcelo).
      +    * libc/string/lib_strndup.c: strndup() should use strnlen(), not
      +      strlen(), to determine the size of the string.
      +    * sched/os_bringup.c:  Remove support for CONFIG_BUILTIN_APP_START.
      +      This is not really a useful feature and creates a violation of the
      +      OS layered architecture.
      +    * include/unistd.h, arch/arch/src/*:  Implement a simple vfork().
      +      On initial checkin, this API is available only for ARM platforms.
      +    * binfmt/binfmt_exec.c: exec() now sets the priority of the new task
      +      to the same priority as the current task (instead of the arbirtrary
      +      value of 50).
      +    * libc/unisted/lib_execv.c and lib_execl.c:  New, somewhat flawed,
      +      implementations of execv() and execl().
      +    * tools/cfgdefine.c:  Strips quotes from CONFIG_EXECFUNCS_SYMTAB
      +      value.
      +    * arch/arm/include/lm3s/chip.h:  Move chip definitions into
      +      public include area for compatibility with other architectures.
      +    * arch/arm/src/lm3s/chip:  Move register definition header files
      +      into a new chip/ sub-directory.
      +    * arch/arm/src/lm3s/lm3s_internal.h:  Broke up into several
      +      smaller header files.
      +    * arch/arm/src/lm:  Rename the arch/arm/src/lm3s directory to
      +      arch/arm/src/lm so that is can support other members of the
      +      Stellaris family.
      +    * libc/spawn:  Add file action interfaces needed by posix_spawn().
      +    * sched/clock_time2ticks.c:  Another case where time was being
      +      rounded down instead of up (from Mike Smith).
      +    * libc/spawn:  Implementation of posix_spawn() is complete but
      +      untested and undocumented.
      +    * drivers/usbdev/pl2303.c:  Fix typols in the PL2303 driver
      +      (from Max Holtzberg).
      +    * configs/stm32f4discovery/posix_spawn:  Added a configuration
      +      that can be used for testing posix_spawn().
      +    * arch/arm/src/stm32: Bring F1 support for general DMA and serial
      +      DMA in paricular up to parity with F2/F4 (from Mike Smith).
      +    * libc/stdio/lib_libfread.c:  Correct some error handling when
      +      lib_fread() was passed a bad stream.  Needed to move the
      +      releasing of a semaphore inside of some conditional logic
      +      (cosmetic).
      +    * include/nuttx/sched.h, sched/task_setup.c, and sched/task_exithook.c:
      +      Add support for remembering the parent task and sending
      +      SIGCHLD to the parent when the task exists.
      +    * sched/task_exithook.c:  Fixed a *critical* bug.  Here is
      +      the scenario: (1) sched_lock() is called increments the lockcount
      +      on the current TCB (i.e., the one at the head of the ready to run
      +      list), (2) sched_mergepending is called which may change the task
      +      at the head of the ready-to-run list, then (3) sched_unlock() is called
      +      which decrements the lockcount on the wrong TCB.  The failure case
      +      that I saw was that pre-emption got disabled in the IDLE thread,
      +      locking up the whole system.
      +    * sched/sched_waitpid.c:  Use SIGCHLD instead of a semaphore.  This
      +      is a much more spec-compliant implementation.  However, there are
      +      some issues with overruning signals because NuttX does not support
      +      queueing of signals (POSIX does not require it).  I think it may
      +      need to.
      +    * sched/sched_waitid.c and sched_wait.c:  Add support for waitid()
      +      and wait().  See issues with waitpid() above.
      +    * include/nuttx/fs/fs.h and fs/fs_files.c:  Add a dup() method to
      +      the struct mountpt_operations.  When dup'ing a file that resides
      +      on a mounted volume, let the file system's dup() method do the
      +      work.
      +    * fs/romfs/fs_romfs.c: Implemented the dup() method for the ROMFS
      +      file system.
      +    * fs/fat/fs_fat32.c, fs/nxffs/nxffs_initialize, and
      +      fs/nfs/nfs_vfsops.c:  Add hooks for dup() method (not yet
      +      implemented).
      +    * fs/romfs:  Remove the rf_open flag.  It looks good, but actually
      +      does nothing.
      +    * fs/fat:  Remove the ff_open flag.  Same story as for the ROMFS
      +      rf_open flag.
      +    * fs/fat/fs_fat32.c, fs/nxffs/nxffs_initialize, and
      +      fs/nfs/nfs_vfsops.c:  Completed implementation of the dup() methods.
      +      There is still no good test available.
      +    * sched/sig_timedwait.c:  sigtimedwait() would return a bad signal
      +      number if the signal was already pending when the function was
      +      called.
      +    * configs/ubw32/scripts:  All common linker scripts moved to this
      +      scripts sub-directory
      +    * configs/ubw32/ostest:  Configuration configured to use the
      +      kconfig-frontends tools.
      +    * arch/mips/src/mips32/up_vfork.c, up_vfork.h, and vfork.S:
      +      Implement vfork() for MIPS32 (no floating point support)
      +    * configs/ubw32/ostest: Enable the vfork() test.
      +    * fs/binfs:  Move apps/builtin/binfs.c to fs/binfs/fs_binfs.c
      +      CONFIG_APPS_BINDIR rename CONFIG_FS_BINFS
      +    * include/nuttx/binfmt/builtin.h:  Some of the content of
      +      apps/include/apps.h moved to include/nuttx/binfmt/builtin.h
      +    * binfmt/libbuiltin/libbuiltin_utils.c:  Move builtin
      +      utility functions from apps/builtin/exec_builtins.c to
      +      binfmt/libbuiltin/libbuiltin_utils.c
      +    * binfmt/builtin.c and binfmt/libbuiltin:  Add a binary "loader"
      +      that can be used to execute builtin programs from the BINFS
      +      file system.
      +    * configs/sim/nsh: Convert to use kconfig-frontends configuration
      +      tool.
      +    * binfmt/binfmt_schedunload.c:  Add logic based on SIGCHLD to
      +      automatically unload and clean-up after running a task that
      +      was loaded into memory.
      +    * binfmt/libbuiltin: Extensions from Mike Smith
      +    * sched/task_reparent.c:  Add internal interface to change the
      +      parent task.
      +    * sched/task_posixspawn():  Move libc/spawn/lib_ps.c to
      +      sched/task_posixspawn() now it requires internal, reparenting
      +      interfaces
      +    * include/nuttx/spawn():  Move libc/spawn.h to include/nuttx/spawn.h
      +    * arch/arm/include/lpc17xx/chip.h, irq178x.h:  Integrate Marcelo
      +      Rommel's LPC1788 definitions into the base LPC17xx.
      +    * configs/olimex-lpc1766stk/nsh:  Convert configuration to use
      +      the kconfig-frontends tools.
      +    * sched/task_reparent.c:  Simplify reparenting interface.
      +    * arch/arm/src/[many]: More LPC1788 definitions from Rommel
      +      Marcelo incorporated.
      +    * configs/open1788:  Board configuration for the Wave Share
      +      Open1788 board.  Still fragmentary (contributed by Rommel
      +      Marcelo, adapted to use kconfig-frontends.
      +    * net/send():  Add logic to work around delayed ACKs by splitting
      +      packets (contributed by Yan T.).
      +    * net/recvfrom():  Fix a bug.  When the host closes a connection
      +      (gracefully).  recv[from]() returned success and the closure
      +      was never detected.  Hmmm.. I don't know why the network monitor
      +      did not catch this event.  This is an important bug fix.
      +    * net/recvfrom():  Fix a introduced with the last bugfix.  If
      +      the peer does an orderly closure of the socket, report 0 not
      +      -ENOTCONN
      +    * configs/lm3s6965-ek/README.txt and tools/:  Add an OpenOCD
      +      configuration for the LM3S (from Jose Pablo Carballo).
      +    * nuttx/lcd/hd4478ou.h and configs/pcblogic-pic32mx/src/up_lcd1602:
      +      Start of support of LCD1602 alphanumeric LCD.  I need a few
      +      more parts before I can finish integrating this one.
      +    * arch/arm/src/*/chip.h and arch/arm/include/*/chip.h:  Move all
      +      priority ranges from the src to the include chip.h header file.
      +    * arch/arm/include/armv7-m/irq.h:  Add inline functions to enable
      +      and disable interrupts via the BASEPRI register.
      +    * arch/arm/Kconfig:  Add new option CONFIG_ARM7VM_USEBASEI
      +    * arch/arm/src/*/*_irq.c:  Set the priority of the SVCALL exception
      +      to the highest possible value.
      +    * arch/armv7-m/up_hardfault.c:  Fail if a hardfault occurs
      +      while CONFIG_ARM7VM_USEBASEPRI=y.
      +    * arch/arm/src/stm32/stm32_serial.c:  Add support for USART
      +      single wire mode (Contributed by the PX4 team).
      +    * sched/: Implement support for retaining child task status after
      +      the child task exists.  This is behavior required by POSIX.
      +      But in NuttX is only enabled with CONFIG_SCHED_HAVE_PARENT and
      +      CONFIG_SCHED_CHILD_STATUS
      +    * Add support for keyboard encode to the keypad test (from
      +      Denis Carikli).
      +    * configs/olimex-lpc1766stk/nettest:  Configuration converted to
      +      use the kconfig-frontends tools.
      +    * net/net_poll.c:  Split net_poll() to create psock_poll() too.
      +    * net/net_poll.c:  Fix poll/select issure reported by Qiang:
      +      poll_interrupt() must call net_lostconnection() when a
      +      loss of connection is reported.  Otherwise, the system will
      +      not know that the connection has been lost.
      +    * sched/group_create.c, group_join.c, and group_leave.c:  Add
      +      support for task groups.
      +    * sched/group_signal.c and task_exithook.c:  Send signal to all
      +      members for the parent task group.
      +    * include/nuttx/sched.h and sched/env_*.c:  Move environment
      +      variables into task group structure.
      +    * sched/: Lots of file changed.  Don't keep the parent task's
      +      task ID in the child task's TCB.  Instead, keep the parent
      +      task group IN the child task's task group.
      +    * fs/, sched/, include/nuttx/sched.h, and include/nutts/fs/fs.h:
      +      Move file data from the TCB to the task group structure.
      +    * libc/stdio/, sched/, include/nuttx/lib.h, and include/nutts/fs/fs.h:
      +      Move stream data from the TCB to the task group structure.
      +    * net/, sched/, and include/nuttx/net/net.h:  Move socket data
      +      from the TCB to the task group structure.
      +    * sched/task_starthook.c, sched/task_start.c, and include/nuttx/sched.h:
      +      Add a task start hook that will be called before the task main
      +      is started. This can be used to schedule C++ constructors to run
      +      automatically in the context of the new task.
      +    * binfmt/binfmt_execmodule: Execute constructors as a start hook.
      +    * sched/os_start.c: Fix ordering of group initialization.
      +    * configs/stm32f4discovery/usbnsh:  Add an NSH STM32F4Discovery
      +      configuration that uses USB CDC/ACM for the NSH console.
      +    * configs/stm32f4discovery/nsh: Converted to use the kconfig-frontends
      +      tools.
      +    * configs/*/src/up_userleds.c: Fix a error that was cloned into
      +      all STM32 user LED code.  The wrong definitions were being used
      +      to set LEDs on or off.
      +    * arch/*/common/up_internal.h and arch/*/common/up_initialize.c:
      +      Serial was driver was not being built if there is no console
      +      device.  Obviously, the serial driver may be needed even in
      +      this case.
      +    * arch/arm/src/stm32/stm32_serial.c: If there is a serial console,
      +      it would be ttyS0 and the others would be ttyS1-5.  If there
      +      is not serial console, was labeling them ttyS1-6; now labels them
      +      ttyS0-5.
      +    * fs/fs_syslog.c: Can't handle SYSLOG output to character device from
      +      the IDLE task (because it can't block). syslog_putc now returns EOF
      +      on failure and sets errno.  Fixed some errors in error handling.
      +    * libc/stdio/lib_syslogstream.c:  Checking of return value from
      +      syslog_putc was bogus.  Switching to EOF for all errors solves
      +      this.
      +    * arch/arm/src/lm/chip/lm4f_memorymap.h: More LM4F changes from
      +      Jose Pablo Carballo.
      +    * drivers/serial/serial.c, include/nuttx/serial/serial.h,
      +      drivers/usbdev/cdcacm.c, and drivers/pl2303.c: Add support for
      +      removable serial devices (like USB serial).  This support is enabled
      +      by CONFIG_SERIAL_REMOVABLE.
      +    * arch/*/src/*/Toolchain.defs: Change assignment so that we can
      +      override CROSSDEV with a make command line argument.
      +    * include/assert.h:  Mark assertion functions as non-returning.
      +    * arch/*/src/*/up_assert.h:  Mark _up_assert() as non-returning.
      +    * drivers/mtd/at25.c: When the AT25 device was not available the
      +      initialization did not fail like it should. From Petteri Aimonen.
      +    * fs/fat/fs_configfat.c:  Fix some errors in FAT formatting logic
      +      for large devices and for FAT32. From Petteri Aimonen.
      +    * fs/fat/fs_fat32util.c:  Fix an initialization error found by
      +      Petteri Aimonen.  freecount and next freecount initialization were
      +      reversed.
      +    * drivers/mmcsd/mmcsd_spi.c: Some SD cards will appear busy until
      +      switched to SPI mode for first time.  Having a pull-up resistor on
      +      MISO may avoid this problem, but this patch makes it work also
      +      without pull-up.  From Petteri Aimonen.
      +    * fs/fat/fs_fat32.c: Fix a compilation error when FAT_DMAMEMORY=y. 
             From Petteri Aimonen.
      -    * NxWidgets::CNxTimer:  Replace the original (apparently non-functional) signal-
      -      based solution with a work queue-based solution.  This raises some isses about
      -      using the internal work queues from user space.  I have decided to implemented
      -      user-space work queues (someday) in order to accomplish that functionaliy.
      -      Submitted by Petteri Aimonen.
      -    * NxWidgets:CText and NxWidgets:CNumericEdite:  Fix some memory freeing bugs
      +    * arch/arm/src/stm32/chip/stm32_spi.h: STM32F4 max SPI clock freq is
      +      37.5 MHz.  Patch from Petteri Aimonen.
      +    * arch/arm/src/stm32/stm32_spi.c: Fixes for SPI DMA work on the
      +      STM32F4. Includes untested additions for the F1 implementation as
      +      well.  From Petteri Aimonen.
      +
      +apps-6.25 2013-02-01 Gregory Nutt <gnutt@nuttx.org>
      +
      +    * Makefiles: Removed dependency of distclean on clean in most top-level
      +      files.  It makes sense for 'leaf' Makefiles to have this dependency,
      +      but it does not make sense for upper-level Makefiles.
      +    * apps/namedapp/: Renamed to builtins in preparation for another change.
      +    * .context:  Removed the .context kludge.  This caused lots of problems
      +      when changing configurations because there is no easy way to get the
      +      system to rebuild the context.  Now, the context will be rebuilt
      +      whenever there is a change in either .config or the Makefile.
      +    * apps/builtin/registry:  Updated new built-in registration logic to handle
      +      cases where (1) old apps/.config is used, and (2) applications ared
      +      removed, not just added.
      +    * apps/examples/nettest/Makefile:  Fix an error that crept in during
      +      some of the recent, massive build system changes.
      +    * apps/builtin/Makefile:  Need to have auto-generated header files
      +      in place early in the dependency generation phase to avoid warnings.
      +      It is not important if they are only stubbed out header files at
      +      this build phase.
      +    * apps/examples/hidbkd: Now supports decoding of encoded special keys
      +      if CONFIG_EXAMPLES_HIDKBD_ENCODED is defined.
      +    * apps/examples/hidbkd:  Add support for decoding key release events
      +      as well.  However, the USB HID keyboard drier has not yet been
      +      updated to detect key release events.  That is kind of tricky in
      +      the USB HID keyboard report data.
      +    * apps/examples/wlan: Remove non-functional example.
      +    * apps/examples/ostest/vfork.c:  Added a test of vfork().
      +    * apps/exampes/posix_spawn: Added a test of posix_spawn().
      +    * apps/examples/ostest:  Extend signal handler test to catch
      +      death-of-child signals (SIGCHLD).
      +    * apps/examples/ostest/waitpid.c:  Add a test for waitpid(), waitid(),
      +      and wait().
      +    * builtin/binfs.c:  Add hooks for dup() method (not implemented).
      +    * builtin/exec_builtin.c, nshlib/nsh_parse.c, and nshlib/nsh_builtin.c:
      +      NSH now supports re-direction of I/O to files (but still not from).
      +    * builtin/binfs.c:  Greatly simplified (it is going to need to be
      +      very lightweight).  Now supports open, close, and a new ioctl to recover
      +      the builtin filename.  The latter will be needed to support a binfs
      +      binfmt.
      +    * builtin/binfs.c:  Move apps/builtin/binfs.c to fs/binfs/fs_binfs.c
      +      CONFIG_APPS_BINDIR rename CONFIG_FS_BINFS
      +    * apps/include/builtin.h:  Some of the content of
      +      apps/include/apps.h moved to include/nuttx/binfmt/builtin.h.
      +      apps/include/apps.h renamed builtin.h
      +    * apps/builtin/exec_builtins.c:  Move builtin
      +      utility functions from apps/builtin/exec_builtins.c to
      +      binfmt/libbuiltin/libbuiltin_utils.c
      +    * apps/nshlib/nsh_mountcmds.c:  The block driver/source
      +      argument is now optional.  Many files systems do not need
      +      a source and it is really stupid to have to enter a bogus
      +      source parameter.
      +    * apps/nshlib/nsh_fileapp.c:  Add the ability to execute a file
      +      from a file system using posix_spawn().
      +    * apps/builtin/: Extensions from Mike Smith.
      +    * apps/examples/ftpd/Makefile: Name ftpd_start is not the name of
      +      the entrypoint.  Should be ftpd_main (from Yan T.)
      +    * apps/netutils/telnetd/telnetd_driver: Was stuck in a loop if
      +      recv[from]() ever returned a value <= 0.
      +    * apps/examples/nettest and poll:  Complete Kconfig files.
      +    * apps/examples/ostest/waitpid.c:  Need to use WEXITSTATUS()
      +      to decode the correct exit status.
      +    * apps/system/usbmonitor:  A daemon that can be used to monitor USB
      +      trace outpout.
      +    * apps/nshlib/nsh_usbdev.c, nsh_consolemain.c, nsh_session.c, nsh_script.c:
      +      Add support for a login script.  The init.d/rcS script will be executed
      +      once when NSH starts; the .nshrc script will be executed for each session:
      +      Once for serial, once for each USB connection, once for each Telnet
      +      session.
      +    * apps/system/readline: Correct readline() return value.  Was not
      +      any returning special values when end-of-file or read errors
      +      occur (it would return an empty string which is not very useful).
      +
      +NxWidgets-1.5 2013-02-01 Gregory Nutt <gnutt@nuttx.org>
      +
      +    * NxWidgets::CGraphicsPort::move():  Fix typo bug in bounding rectangle
      +      calculation (from Petteri Aimonen).
      +    * NxWM::CScrollingPanel::scrollChildren(): Avoid unnecessary redraws in
      +      CScrollingPanel (contributed by Petteri Aimonen).
      +    * NxWM::CCycleButton:  Remove the separator from CCycleButton. It draws in
      +      wrong place, and doesnt look very good in the correct place either.
             (from Petteri Aimonen).
      -    * NxWidgets::CScrollingPanel:  Usability improvements.  It is borderless for now,
      -      because there was no easy way to redraw only the required part of the border.
      -      Contributed by Petteri Aimonen.
      -    * NxWidgets::CNxWidgets and NxWM::CStartWindow: Small changes to make sub-
      -      classing easier (from Petteri Aimonen).
      +    * NxWidgets::CGraphicsPort: Many times we only want a constant background.
      +      In that case the old code fills the background, reads it back, renders
      +      the text and then writes it back. When used with LCD's (instead of
      +      framebuffers) this causes unnecessary delay and screen flicker.
      +      This commit adds a variant of drawText that takes background color,
      +      so that the background and text can both be rendered at one go.
      +      The old functions still function as before (Petteri Aimonen).
      +    * NxWidgets::CLabel: The label was drawn as a single rectangular region,
      +      then a text was added to the on top of this.  The result is that the
      +      text would flicker when the CLabel was updated. With this change, the
      +      two step update is replaced with a five step update:  The background
      +      is updated as four rectangulear regions (leaving the previous text in
      +      place), then the new text is updated.  This eliminates the flicker
      +      (Petteri Aimonen).
      +    * Kconfig: Many NxWidgets/NxWM settings do not have meaningful, generic
      +      default values.  Colors, for example, depend on pixel depth.  Some
      +      geometry settings depending on other geometry settings.  Font IDs are
      +      not know-able by the configuration system.  etc.  In these cases, it
      +      is best if the settings are just not undefined so that the system can
      +      calculate a reasonable default.  however, if no default is provided
      +      in the .config file, mconf will complain and generate errors.  So work
      +      around this, I added several "enabling" settings to override the
      +      default setting.  This is awkward and I preferred the configuration as
      +      it was before, but this avoids the mconf errors and warnings.
      +    * UnitTests:  Changed occurrences of lib_rawprintf() and lib_lowprintf()
      +      to match recent changes to NuttX (will be in NuttX-6.25)
      +    * CGraphicsPort::_drawText:  Renamed from CGraphicsPort::drawText in order
      +      to eliminate some naming collisions when overloaded in some configurations
      +      (i.e., when both bool and nx_pixel_t are uint8_t).  From Petteri Aimonen.
      +    * CNxWidgets::drawContents: Change base drawContents from a do-nothing
      +      function to a function that fills the widget with the background color.
      +      This is useful when using CNxWidgets as a "panel" , i.e. a container
      +      for other widgets. Subclasses will override drawContents and decide
      +      themselves how to draw the background.
      +    * CNxWidgets::CTabPanel:  A new widget contributed by Petteri Aimonen.
      +      This widget provides a tab panel, which has a button bar at the top
      +      and panels below it. Pressing a button will select the corresponding
      +      panel.
       
       uClibc++-1.0 2011-11-05 <gnutt@nuttx.org>
       
      diff --git a/nuttx/ReleaseNotes b/nuttx/ReleaseNotes
      index 02cb8158d..9d146e90a 100644
      --- a/nuttx/ReleaseNotes
      +++ b/nuttx/ReleaseNotes
      @@ -3440,3 +3440,323 @@ Bugfixes (see the change log for details).  Some of these are very important
           * Applications: Modbus fixes from Freddie Chopin.
       
       As well as other, less critical bugs (see the ChangeLog for details)
      +
      +NuttX-6.25
      +^^^^^^^^^^
      +
      +The 92nd release of NuttX, Version 6.25, was made on February 1, 2013,
      +and is available for download from the SourceForge website.  Note
      +that release consists of two tarballs:  nuttx-6.25.tar.gz and
      +apps-6.25.tar.gz.  Both may be needed (see the top-level nuttx/README.txt
      +file for build information).
      +
      +This release corresponds with SVN release number: r5594
      +
      +Note that all SVN information has been stripped from the tarballs.  If you
      +need the SVN configuration information, you should check out directly from
      +SVN.  Revision r5594 should equivalent to release 6.25 of NuttX:
      +
      +    svn checkout -r5594 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
      +
      +Or (HTTP):
      +
      +    svn checkout -r5594 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
      +
      +Additional new features and extended functionality:
      +
      +    * OS Initialization
      +
      +      - Removed support for CONFIG_BUILTIN_APP_START.  This is not really a
      +        useful feature and creates a violation of the OS layered
      +        architecture.
      +
      +    * Task Creation:
      +
      +      - Implement a simple vfork().  In NuttX-6.25, this interface is
      +        available only for ARM7/9, ARMv7-M (Cortext-M3/4), and MIPS32
      +        (PIC32MX) platforms.
      +      - exec() now sets the priority of the new task to the same priority as
      +        the parent task (instead of the arbirtrary value of 50).
      +      - New, partially complient implementations of execv() and execl().
      +        These are only partially compliant because they do not overlay any
      +        existing "process space" but rather create the new task and exit().
      +      - Add a complete implementation of posix_spawn().  This standard
      +        interface is a better match for an MMU-less architecture than are
      +        vfork() plus execv() or execl().
      +      - Add a task start hook that will be called before the task main
      +        is started.  This can be used, for example, to schedule C++
      +        static constructors to run automatically in the context of the
      +        new task.
      +
      +    * Task Parentage
      +
      +      - Repartitioned tasking data structures.  All shared resources are now
      +        collected together in a "task group".  A task group includes the
      +        original task plus all of the pthreads created by the task.
      +      - Added support for remember the parent "task group" when a new task is
      +        started.
      +      - Added optional support to record the membership of each thread in
      +        the "task group".
      +      - Implement support for retaining child task status in the "task group"
      +        after the child task exists.  This is behavior required by POSIX.
      +        But in NuttX is only enabled with CONFIG_SCHED_HAVE_PARENT and
      +        CONFIG_SCHED_CHILD_STATUS
      +      - Add internal logic to "reparent" a task.  This is useful,
      +        for example, where the child task is created through a trampoline
      +        task that redirects I/O.  Reparenting allows the caller of posix_spawn()
      +        to be reparented for the eventual child thread.
      +      - Added support for SIGCHLD.  Sent to all members of the parent task
      +        group when the file member of the child task group exits.
      +      - If SIGCHLD and retention of child task exist status are enabled, then
      +        a more spec-compliant version of waitpid() is enabled.
      +      - New interfaces waitid() and wait() are also enabled when SIGCHLD
      +        is enabled.
      +
      +    * File System
      + 
      +      - dup() and dup2() can new be used with opened files in a mounted file
      +        system.  This supports re-direction of output in NSH to files.
      +      - The binfs file system was moved from apps/builtin to fs/binfs.  The
      +        binfs file system was extended to support execution of "builtin
      +        applications" using exec(), execv(), execl(), or posix_spawn().
      +      - Added logic based on SIGCHLD to automatically unload and clean-up
      +        after running a task that was loaded into memory.
      +
      +    * Binary Formats
      +
      +      - Much of the logic for "builtin applications" was moved from
      +        apps/builtin to nuttx/binfmt/libbuiltin.  Includes some extensions
      +        contributed by Mike Smith.
      +      - A binary loader was added for builtin applications to support
      +        execution of "builtin applications" using exec(), execv(),
      +        execl(), or posix_spawn().
      +
      +    * Drivers:
      + 
      +      - Added logic to marshal and serialized "out-of-band" keyboard
      +        commands (such as cursor controls and key release events) intermixed
      +        with normal ASCII keypress data.  The encoding is partially integrated
      +        in the HID keyboard driver and the decoding full integrated into the
      +        apps/examples hidkbd and keypadtest (the latter contributed by Denis
      +        Carlikli).
      +      - Driver for the UG-2864HSWEG01 OLED contributed by Darcy Gong.
      +      - Add support for removable serial devices (like USB serial).  This
      +        support is enabled by CONFIG_SERIAL_REMOVABLE.
      +
      +    * ARMv7-M:
      +
      +      - Added an option to use the BASEPRI register to disable interrupts
      +        (instead of the PRIMASK).  This eliminates some innocuous hardfaults
      +        that interfere with some debug tools.  You need to switch to the
      +        BASEPRI method only if you have such tool interference.
      +
      +    * STM32 Drivers
      +
      +      - Bring STM32 F1 DMA capabilities up to par with the STM32 F2/F4
      +        (contributed by Mike Smith).
      +      - Add support for USART single wire mode (Contributed by the PX4
      +        team).
      +      - Updates to support for SPI DMA on the STM32 F1/F2/F4.  From
      +        Petteri Aimonen.
      +
      +    * STM32 Boards:
      +
      +      - New configuration to support the UG-2864HSWEG01 OLED on the
      +        STM32F4Discovery board.
      +      - Added a posix_spawn() test configuration for the STM32F4Discovery.
      +
      +    * LM3S/LM4F
      +
      +       - Files and directories repartitioned to support both LM3S and LM4F
      +         using the STM32 organization as a model.
      +       - Partial definitions for the LM4F contributed by Jose Pablo Carballo
      +         (this is still a work in progress).
      +
      +    * LM3S Boards
      + 
      +       - Added scripts and documentation to use OpenOCD with the LM3S (from
      +         Jose Pablo Carballo).
      +
      +    * LPC176x/LPC178x
      +
      +       - Files and directories repartitioned to support both LPC175x/LPC176x
      +         and the LPC177x/LPC178x families using the STM32 organization as a
      +         model.  The LPC1788 port is a work in progress by Rommel Marcelo.
      +
      +    * LPC176x/LPC178x Boards:
      +
      +      - Added a configuration to support the Wave Share Open1788 board.
      +        This is still a work in progress by Rommel Marcelo.
      +
      +    * LPC2148 Boards:
      + 
      +      - Add basic support for the The0.net ZP213x/4xPA board (with the LPC2148
      +        and the UG_2864AMBAG01 OLED).
      +      - Add an nxlines configuration for the ZP213x/4xPA (with the LPC2148
      +        and the UG_2864AMBAG01).
      + 
      +    * Simulator:
      + 
      +      - Add an nxlines configuration for the simulator.
      +
      +    * Networking:
      +
      +      - Add logic to work around delayed ACKs by splitting packets
      +        (contributed by Yan T.).
      +      - Split net_poll() to create the internal interface psock_poll().
      +
      +    * LCDs:
      +
      +      - Added support for LCD1602 alphanumeric LCD (HD4468OU controller).
      +
      +    * Graphics:
      +
      +      - Added 5x8 monospace font. This tiny font is useful for graph
      +        labels and for small bitmapped display.  Contributed by Petteri
      +        Aimonen.
      +
      +    * Build System:
      +
      +      - Add an options to better manage toolchain prefixes.
      +      - Redesigned how the context targer works in the apps/ directory.
      +        The old design caused lots of problems when changing configurations
      +        because there is no easy way to get the system to rebuild the
      +        context.  This change should solve most the problems and eliminate
      +        questions like "Why don't I see my builtin application in NSH?"
      +
      +    * Kconfig Files:
      +
      +      - There are several new configurations that use the kconfig-frontends
      +        tools and several older configurations that have been converted to
      +        use these tools.  There is still a long way to go before the conversion
      +        is complete:
      +
      +        configs/sim/nxwm
      +        configs/sim/nsh
      +        configs/stm3220g-eval/nxwm
      +        configs/stm32f4discovery/posix_spawn
      +        configs/olimex-lpc1766stk/nsh
      +        configs/olimex-lpc1766stk/hidkbd
      +        configs/olimex-lpc1766stk/nettest
      +        configs/open1788/ostest
      +        configs/stm32f4discovery/nsh
      +        configs/stm32f4discovery/usbnsh
      +        configs/lm326965-ek (all configurations)
      +        configs/mcu123-214x/nsh
      +        configs/ubw32/ostest
      +
      +    * Tools:
      +
      +      - tools/kconfig.bat:  Kludge to run kconfig-frontends from a DOS shell.
      +      - tools/configure.c:  configure.c can be used to build a work-alike
      +        program as a replacement for configure.sh.  This work-alike
      +        program would be used in environments that do not support Bash
      +        scripting (such as the Windows native environment).
      +      - tools/configure.bat: configure.bat is a small Windows batch
      +        file that can be used as a replacement for configure.sh in a
      +        Windows native environment.  configure.bat is actually just a
      +        thin layer that executes configure.exe if it is available. If
      +        configure.exe is not available, then configure.bat will attempt
      +        to build it first.
      +
      +    * Applications:
      +
      +      - New and modified examples:
      +      
      +        apps/examples/wlan: Remove non-functional example.
      +        apps/examples/ostest: Added a test of vfork(). Extend signal
      +          handler test to catch death-of-child signals (SIGCHLD). Add a
      +          test for waitpid(), waitid(), and wait().
      +        apps/exampes/posix_spawn: Added a test of posix_spawn().
      +
      +      - NSH:
      +
      +        NSH now supports re-direction of I/O to files (but still not from).
      +        The block driver source argument to the mount command is now
      +          optional for file systems that do not require a block driver.
      +        NSH can now execute a program from a file system using posix_spawn().
      +        Added support for a login script.  The init.d/rcS script will be
      +          executed once when NSH starts; the .nshrc script will be executed
      +          for each session:  Once for serial, once for each USB connection,
      +          once for each Telnet session.
      +
      +      - Supports a new daemon that can be used to monitor USB trace outpout.
      +      - Removed non-functional wlan example.
      +
      +Bugfixes (see the ChangeLog for details).  Some of these are very important:
      +
      +    * Tasking:
      +
      +      - Fixed a *critical* task exit bug.  Here is the failure scenario:
      +        (1) sched_lock() is called increments the lockcount on the current
      +        TCB (i.e., the one at the head of the ready to run list), (2)
      +        sched_mergepending is called which may change the task at the head
      +        of the ready-to-run list, then (3) sched_unlock() is called which
      +        decrements the lockcount on the wrong TCB.  The failure case that
      +        I saw was that pre-emption got disabled in the IDLE thread, locking
      +        up the whole system.
      +
      +    * Signals:
      +
      +      - sigtimedwait() would return a bad signal number if the signal was
      +        already pending when the function was called.
      +
      +    * Drivers:
      +
      +      - Some SD cards will appear busy until switched to SPI mode for
      +        first time.  Having a pull-up resistor on MISO may avoid this
      +        problem, but this fix from Petteri Aimonen makes it work also
      +        without pull-up.
      +
      +    * STM32 Drivers:
      +
      +      - STM32 FLASH driver counting error (from Freddie Chopin).
      +      - STM32 F4 maximum SPI frequency was wrong (corrected by Petteri
      +        Aimonen).
      +
      +    * STM32 Boards
      +
      +      - Due to cloning of untested code, the logic to control on-board
      +        LEDs did not work on any STM32 boards.
      +      - Serial devices number /dev/ttyS0-5 is there is a serial console,
      +        but /dev/ttyS1-6 if there is no serial console.
      +
      +    * Binary Formats
      +
      +      - C++ static constructors execute now using a start taskhook
      +        so that they execute in the context of the child task (instead
      +        of in the context of the parent task).
      +
      +    * File Systems:
      +
      +      - Several FAT-related bugs fixed by Petteri Aimonen.
      +
      +    * Networking:
      +
      +      - Fix poll/select issure reported by Qiang: poll_interrupt() must call
      +        net_lostconnection() when a loss of connection is reported.  Otherwise,
      +        the system will not remember that the connection has been lost and will
      +        hang waiting on a unconnected socket later.
      +      - Similar issues corrected for recvfrom() and send().
      +      - Telnetd would hang in a loop if recv() ever returned a value <= 0.
      +
      +    * Libraries:
      +
      +      - fread() could hang on certain error conditions.
      +      - Can't handle SYSLOG output to a character device from  the IDLE task
      +        (because the IDLE task can't block). 
      +
      +    * Build System:
      +
      +      - Serial was driver was not being built if there is no console
      +        device.  Obviously, the serial driver may be needed even in
      +        this case.
      +
      +    * Additional Bugfixes:
      +
      +      - sig_timedwait() and clock_time2ticks.c: Timing "rounding" logic
      +      - ARM9 Compilation issue with low vectors.
      +      - readline() return value
      +      - Others as detailed in the ChangeLog: HID keyboard, LPC17xx bit
      +        definitions, strndup(), PL2303, SYSLOG error handling, AT25,
      +        apps/examples.
      -- 
      cgit v1.2.3
      
      
      From c058d847959ab397dd640e71c05e713eb77885a3 Mon Sep 17 00:00:00 2001
      From: patacongo 
      Date: Fri, 1 Feb 2013 22:51:34 +0000
      Subject: Last minute 6.25 change
      
      git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5595 42af7a65-404d-4744-a932-0658087f49c3
      ---
       NxWidgets/ReleaseNotes.txt     |  2 +-
       nuttx/Documentation/NuttX.html |  8 +++----
       nuttx/ReleaseNotes             |  8 +++----
       nuttx/drivers/serial/serial.c  | 51 +++++++++++++++++++++++++++---------------
       4 files changed, 42 insertions(+), 27 deletions(-)
      
      diff --git a/NxWidgets/ReleaseNotes.txt b/NxWidgets/ReleaseNotes.txt
      index 431d2796c..3b3a8531d 100644
      --- a/NxWidgets/ReleaseNotes.txt
      +++ b/NxWidgets/ReleaseNotes.txt
      @@ -150,7 +150,7 @@ NxWidgets-1.5
       
       The 6th release of the NxWidgets package was made on February 1, 2013.  This
       release depends on NuttX-6.25 or above and should not be used with older
      -NuttX releases.  This release corresponds to SVN revision r5594.
      +NuttX releases.  This release corresponds to SVN revision r5595.
       
       Note: Nearly all of the changes between 1.4 and 1.5 were the result of the
       efforts of Petteri Aimonen.
      diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html
      index b4015bab7..b04150e1b 100644
      --- a/nuttx/Documentation/NuttX.html
      +++ b/nuttx/Documentation/NuttX.html
      @@ -1075,17 +1075,17 @@
         These unreleased changes are also listed here.
       

      - This release corresponds with SVN release number: r5594, + This release corresponds with SVN release number: r5595, Note that all SVN information has been stripped from the tarballs. If you need the SVN configuration, you should check out directly from SVN. - Revision r5594 should equivalent to release 6.25 of NuttX: + Revision r5595 should equivalent to release 6.25 of NuttX:

        -svn checkout -r5594 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
        +svn checkout -r5595 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
         

      Or (HTTP):

        -svn checkout -r5594 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
        +svn checkout -r5595 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
         

      diff --git a/nuttx/ReleaseNotes b/nuttx/ReleaseNotes index 9d146e90a..4e8768b96 100644 --- a/nuttx/ReleaseNotes +++ b/nuttx/ReleaseNotes @@ -3450,17 +3450,17 @@ that release consists of two tarballs: nuttx-6.25.tar.gz and apps-6.25.tar.gz. Both may be needed (see the top-level nuttx/README.txt file for build information). -This release corresponds with SVN release number: r5594 +This release corresponds with SVN release number: r5595 Note that all SVN information has been stripped from the tarballs. If you need the SVN configuration information, you should check out directly from -SVN. Revision r5594 should equivalent to release 6.25 of NuttX: +SVN. Revision r5595 should equivalent to release 6.25 of NuttX: - svn checkout -r5594 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code + svn checkout -r5595 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code Or (HTTP): - svn checkout -r5594 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code + svn checkout -r5595 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code Additional new features and extended functionality: diff --git a/nuttx/drivers/serial/serial.c b/nuttx/drivers/serial/serial.c index 9c6acf2ee..cc1c697c0 100644 --- a/nuttx/drivers/serial/serial.c +++ b/nuttx/drivers/serial/serial.c @@ -292,15 +292,6 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t ssize_t nread = buflen; int ret; -#ifdef CONFIG_SERIAL_REMOVABLE - /* If the removable device is no longer connected, refuse to write to the device */ - - if (dev->disconnected) - { - return -ENOTCONN; - } -#endif - /* We may receive console writes through this path from interrupt handlers and * from debug output in the IDLE task! In these cases, we will need to do things * a little differently. @@ -308,6 +299,17 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t if (up_interrupt_context() || getpid() == 0) { +#ifdef CONFIG_SERIAL_REMOVABLE + /* If the removable device is no longer connected, refuse to write to + * the device. + */ + + if (dev->disconnected) + { + return -ENOTCONN; + } +#endif + /* up_putc() will be used to generate the output in a busy-wait loop. * up_putc() is only available for the console device. */ @@ -338,6 +340,18 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t return ret; } +#ifdef CONFIG_SERIAL_REMOVABLE + /* If the removable device is no longer connected, refuse to write to the + * device. + */ + + if (dev->disconnected) + { + uart_givesem(&dev->xmit.sem); + return -ENOTCONN; + } +#endif + /* Loop while we still have data to copy to the transmit buffer. * we add data to the head of the buffer; uart_xmitchars takes the * data from the end of the buffer. @@ -417,15 +431,6 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen int16_t tail; int ret; -#ifdef CONFIG_SERIAL_REMOVABLE - /* If the removable device is no longer connected, refuse to read from the device */ - - if (dev->disconnected) - { - return -ENOTCONN; - } -#endif - /* Only one user can access dev->recv.tail at a time */ ret = uart_takesem(&dev->recv.sem, true); @@ -439,6 +444,16 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen return ret; } +#ifdef CONFIG_SERIAL_REMOVABLE + /* If the removable device is no longer connected, refuse to read from the device */ + + if (dev->disconnected) + { + uart_givesem(&dev->recv.sem); + return -ENOTCONN; + } +#endif + /* Loop while we still have data to copy to the receive buffer. * we add data to the head of the buffer; uart_xmitchars takes the * data from the end of the buffer. -- cgit v1.2.3 From 049c93446561c6ad3e59183c139f3916230ddee5 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 2 Feb 2013 00:29:55 +0000 Subject: drivers/serial.c: Fix some race conditions. Some bad things code happen if we lost a USB connection at certain times. git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5596 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/ChangeLog | 3 ++ nuttx/drivers/serial/serial.c | 104 ++++++++++++++++++++++++++++++------------ 2 files changed, 78 insertions(+), 29 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index e2e7ae29b..5bdd1aad8 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4097,3 +4097,6 @@ well. From Petteri Aimonen. 6.26 2013-xx-xx Gregory Nutt + + * drivers/serial/serial.c: Correct some race conditions when checking + for disconnection of a removable serial device. diff --git a/nuttx/drivers/serial/serial.c b/nuttx/drivers/serial/serial.c index cc1c697c0..68f0f43a2 100644 --- a/nuttx/drivers/serial/serial.c +++ b/nuttx/drivers/serial/serial.c @@ -211,27 +211,40 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch) */ flags = irqsave(); - dev->xmitwaiting = true; +#ifdef CONFIG_SERIAL_REMOVABLE + /* Check if the removable device is no longer connected while we + * have interrupts off. We do not want the transition to occur + * as a race condition before we begin the wait. + */ + + if (dev->disconnected) + { + irqrestore(flags); + return -ENOTCONN; + } +#endif /* Wait for some characters to be sent from the buffer with the TX * interrupt enabled. When the TX interrupt is enabled, uart_xmitchars * should execute and remove some of the data from the TX buffer. */ + dev->xmitwaiting = true; uart_enabletxint(dev); ret = uart_takesem(&dev->xmitsem, true); uart_disabletxint(dev); irqrestore(flags); #ifdef CONFIG_SERIAL_REMOVABLE - /* Check if the removable device is no longer connected */ + /* Check if the removable device was disconnected while we were + * waiting. + */ if (dev->disconnected) { return -ENOTCONN; } #endif - /* Check if we were awakened by signal. */ if (ret < 0) @@ -342,7 +355,9 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t #ifdef CONFIG_SERIAL_REMOVABLE /* If the removable device is no longer connected, refuse to write to the - * device. + * device. This check occurs after taking the xmit.sem because the + * disconnection event might have occurred while we were waiting for + * access to the transmit buffers. */ if (dev->disconnected) @@ -377,8 +392,12 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t ret = uart_putxmitchar(dev, ch); } - /* Were we awakened by a signal? That should be the only condition that - * uart_putxmitchar() should return an error. + /* uart_putxmitchar() might return an error under one of two + * conditions: (1) The wait for buffer space might have been + * interrupted by a signal (ret should be -EINTR), or (2) if + * CONFIG_SERIAL_REMOVABLE is defined, then uart_putxmitchar() + * might also return if the serial device was disconnected + * (wtih -ENOTCONN). */ if (ret < 0) @@ -402,7 +421,7 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t * set the errno value appropriately). */ - nread = -EINTR; + nread = ret; } break; @@ -444,16 +463,6 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen return ret; } -#ifdef CONFIG_SERIAL_REMOVABLE - /* If the removable device is no longer connected, refuse to read from the device */ - - if (dev->disconnected) - { - uart_givesem(&dev->recv.sem); - return -ENOTCONN; - } -#endif - /* Loop while we still have data to copy to the receive buffer. * we add data to the head of the buffer; uart_xmitchars takes the * data from the end of the buffer. @@ -461,6 +470,22 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen while (recvd < buflen) { +#ifdef CONFIG_SERIAL_REMOVABLE + /* If the removable device is no longer connected, refuse to read any + * further from the device. + */ + + if (dev->disconnected) + { + if (recvd == 0) + { + recvd = -ENOTCONN; + } + + break; + } +#endif + /* Check if there is more data to return in the circular buffer. * NOTE: Rx interrupt handling logic may aynchronously increment * the head index but must not modify the tail index. The tail @@ -509,6 +534,7 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen { recvd = -EAGAIN; } + break; } #else @@ -560,19 +586,34 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen */ flags = irqsave(); - dev->recvwaiting = true; - uart_enablerxint(dev); +#ifdef CONFIG_SERIAL_REMOVABLE + /* Check if the removable device is no longer connected while + * we have interrupts off. We do not want the transition to + * occur as a race condition before we begin the wait. + */ + + if (dev->disconnected) + { + uart_enablerxint(dev); + irqrestore(flags); + ret = -ENOTCONN; + break; + } +#endif /* Now wait with the Rx interrupt re-enabled. NuttX will * automatically re-enable global interrupts when this thread * goes to sleep. */ + dev->recvwaiting = true; + uart_enablerxint(dev); ret = uart_takesem(&dev->recvsem, true); irqrestore(flags); /* Was a signal received while waiting for data to be - * received? Was a removable device disconnected? + * received? Was a removable device disconnected while + * we were waiting? */ #ifdef CONFIG_SERIAL_REMOVABLE @@ -840,6 +881,7 @@ static int uart_close(FAR struct file *filep) { uart_shutdown(dev); /* Disable the UART */ } + irqrestore(flags); uart_givesem(&dev->closesem); @@ -861,15 +903,6 @@ static int uart_open(FAR struct file *filep) uint8_t tmp; int ret; -#ifdef CONFIG_SERIAL_REMOVABLE - /* If the removable device is no longer connected, refuse to open the device */ - - if (dev->disconnected) - { - return -ENOTCONN; - } -#endif - /* If the port is the middle of closing, wait until the close is finished. * If a signal is received while we are waiting, then return EINTR. */ @@ -882,6 +915,19 @@ static int uart_open(FAR struct file *filep) return ret; } +#ifdef CONFIG_SERIAL_REMOVABLE + /* If the removable device is no longer connected, refuse to open the + * device. We check this after obtaining the close semaphore because + * we might have been waiting when the device was disconnected. + */ + + if (dev->disconnected) + { + ret = -ENOTCONN; + goto errout_with_sem; + } +#endif + /* Start up serial port */ /* Increment the count of references to the device. */ -- cgit v1.2.3 From 50b736333f97761e4613354ee853071c652736ca Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 4 Feb 2013 15:57:12 +0100 Subject: Reduced, but functional u-blox series driver --- apps/drivers/drv_gps.h | 80 +++++ apps/drivers/gps/Makefile | 42 +++ apps/drivers/gps/gps.cpp | 627 ++++++++++++++++++++++++++++++++ apps/drivers/gps/gps_helper.h | 47 +++ apps/drivers/gps/ubx.cpp | 818 ++++++++++++++++++++++++++++++++++++++++++ apps/drivers/gps/ubx.h | 369 +++++++++++++++++++ 6 files changed, 1983 insertions(+) create mode 100644 apps/drivers/drv_gps.h create mode 100644 apps/drivers/gps/Makefile create mode 100644 apps/drivers/gps/gps.cpp create mode 100644 apps/drivers/gps/gps_helper.h create mode 100644 apps/drivers/gps/ubx.cpp create mode 100644 apps/drivers/gps/ubx.h diff --git a/apps/drivers/drv_gps.h b/apps/drivers/drv_gps.h new file mode 100644 index 000000000..89fc54b0d --- /dev/null +++ b/apps/drivers/drv_gps.h @@ -0,0 +1,80 @@ +/**************************************************************************** + * + * Copyright (C) 2012 PX4 Development Team. 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 PX4 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. + * + ****************************************************************************/ + +/** + * @file GPS driver interface. + */ + +#ifndef _DRV_GPS_H +#define _DRV_GPS_H + +#include +#include + +#include "drv_sensor.h" +#include "drv_orb_dev.h" + +#define GPS_DEVICE_PATH "/dev/gps" + +typedef enum { + GPS_DRIVER_MODE_UBX = 0, + GPS_DRIVER_MODE_MTK19, + GPS_DRIVER_MODE_MTK16, + GPS_DRIVER_MODE_NMEA, +} gps_driver_mode_t; + + + + +/* + * ObjDev tag for GPS data. + */ +ORB_DECLARE(gps); + +/* + * ioctl() definitions + */ +#define _GPSIOCBASE (0x2800) //TODO: arbitrary choice... +#define _GPSIOC(_n) (_IOC(_GPSIOCBASE, _n)) + +/** configure ubx mode */ +#define GPS_CONFIGURE_UBX _GPSIOC(0) + +/** configure mtk mode */ +#define GPS_CONFIGURE_MTK19 _GPSIOC(1) +#define GPS_CONFIGURE_MTK16 _GPSIOC(2) + +/** configure mtk mode */ +#define GPS_CONFIGURE_NMEA _GPSIOC(3) + +#endif /* _DRV_GPS_H */ diff --git a/apps/drivers/gps/Makefile b/apps/drivers/gps/Makefile new file mode 100644 index 000000000..3859a88a5 --- /dev/null +++ b/apps/drivers/gps/Makefile @@ -0,0 +1,42 @@ +############################################################################ +# +# Copyright (C) 2012 PX4 Development Team. 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 PX4 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. +# +############################################################################ + +# +# GPS driver +# + +APPNAME = gps +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 + +include $(APPDIR)/mk/app.mk diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp new file mode 100644 index 000000000..7d6f7144e --- /dev/null +++ b/apps/drivers/gps/gps.cpp @@ -0,0 +1,627 @@ +/**************************************************************************** + * + * Copyright (C) 2013 PX4 Development Team. 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 PX4 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. + * + ****************************************************************************/ + +/** + * @file gps.cpp + * Driver for the GPS on UART6 + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include +#include +#include + +#include + +#include + +#include "ubx.h" + +#define SEND_BUFFER_LENGTH 100 +#define TIMEOUT 1000000 //1s + +#define NUMBER_OF_BAUDRATES 4 +#define CONFIG_TIMEOUT 2000000 + +/* oddly, ERROR is not defined for c++ */ +#ifdef ERROR +# undef ERROR +#endif +static const int ERROR = -1; + +#ifndef CONFIG_SCHED_WORKQUEUE +# error This requires CONFIG_SCHED_WORKQUEUE. +#endif + + + +class GPS : public device::CDev +{ +public: + GPS(); + ~GPS(); + + virtual int init(); + + virtual int ioctl(struct file *filp, int cmd, unsigned long arg); + + /** + * Diagnostics - print some basic information about the driver. + */ + void print_info(); + +private: + + int _task_should_exit; + int _serial_fd; ///< serial interface to GPS + unsigned _baudrate; + unsigned _baudrates_to_try[NUMBER_OF_BAUDRATES]; + uint8_t _send_buffer[SEND_BUFFER_LENGTH]; + perf_counter_t _sample_perf; + perf_counter_t _comms_errors; + perf_counter_t _buffer_overflows; + volatile int _task; ///< worker task + + bool _response_received; + bool _config_needed; + bool _baudrate_changed; + bool _mode_changed; + bool _healthy; + gps_driver_mode_t _mode; + unsigned _messages_received; + + GPS_Helper *_Helper; ///< Class for either UBX, MTK or NMEA helper + + struct vehicle_gps_position_s _report; + orb_advert_t _report_pub; + + orb_advert_t _gps_topic; + + void recv(); + + void config(); + + static void task_main_trampoline(void *arg); + + + /** + * worker task + */ + void task_main(void); + + int set_baudrate(unsigned baud); + + /** + * Send a reset command to the GPS + */ + void cmd_reset(); + +}; + + +/* + * Driver 'main' command. + */ +extern "C" __EXPORT int gps_main(int argc, char *argv[]); + +namespace +{ + +GPS *g_dev; + +} + + +GPS::GPS() : + CDev("gps", GPS_DEVICE_PATH), + _task_should_exit(false), + _baudrates_to_try({9600, 38400, 57600, 115200}), + _config_needed(true), + _baudrate_changed(false), + _mode_changed(true), + _healthy(false), + _mode(GPS_DRIVER_MODE_UBX), + _messages_received(0), + _Helper(nullptr) +{ + /* we need this potentially before it could be set in task_main */ + g_dev = this; + + _debug_enabled = true; + debug("[gps driver] instantiated"); +} + +GPS::~GPS() +{ + /* tell the task we want it to go away */ + _task_should_exit = true; + + /* spin waiting for the task to stop */ + for (unsigned i = 0; (i < 10) && (_task != -1); i++) { + /* give it another 100ms */ + usleep(100000); + } + + /* well, kill it anyway, though this will probably crash */ + if (_task != -1) + task_delete(_task); + g_dev = nullptr; +} + +int +GPS::init() +{ + int ret = ERROR; + + /* do regular cdev init */ + if (CDev::init() != OK) + goto out; + + /* start the IO interface task */ + _task = task_create("gps", SCHED_PRIORITY_SLOW_DRIVER, 4096, (main_t)&GPS::task_main_trampoline, nullptr); + + if (_task < 0) { + debug("task start failed: %d", errno); + return -errno; + } + +// if (_gps_topic < 0) +// debug("failed to create GPS object"); + + ret = OK; +out: + return ret; +} + +int +GPS::ioctl(struct file *filp, int cmd, unsigned long arg) +{ + int ret = OK; + + switch (cmd) { + case GPS_CONFIGURE_UBX: + if (_mode != GPS_DRIVER_MODE_UBX) { + _mode = GPS_DRIVER_MODE_UBX; + _mode_changed = true; + } + break; + case GPS_CONFIGURE_MTK19: + if (_mode != GPS_DRIVER_MODE_MTK19) { + _mode = GPS_DRIVER_MODE_MTK19; + _mode_changed = true; + } + break; + case GPS_CONFIGURE_MTK16: + if (_mode != GPS_DRIVER_MODE_MTK16) { + _mode = GPS_DRIVER_MODE_MTK16; + _mode_changed = true; + } + break; + case GPS_CONFIGURE_NMEA: + if (_mode != GPS_DRIVER_MODE_NMEA) { + _mode = GPS_DRIVER_MODE_NMEA; + _mode_changed = true; + } + break; + case SENSORIOCRESET: + cmd_reset(); + break; + } + + return ret; +} + +void +GPS::config() +{ + int length = 0; + + _Helper->configure(_config_needed, _baudrate_changed, _baudrate, _send_buffer, length, SEND_BUFFER_LENGTH); + + /* the message needs to be sent at the old baudrate */ + if (length > 0) { + if (length != ::write(_serial_fd, _send_buffer, length)) { + debug("write config failed"); + return; + } + } + + if (_baudrate_changed) { + set_baudrate(_baudrate); + _baudrate_changed = false; + } +} + +void +GPS::task_main_trampoline(void *arg) +{ + g_dev->task_main(); +} + +void +GPS::task_main() +{ + log("starting"); + + _report_pub = orb_advertise(ORB_ID(vehicle_gps_position), &_report); + + memset(&_report, 0, sizeof(_report)); + + /* open the serial port */ + _serial_fd = ::open("/dev/ttyS3", O_RDWR); + + uint8_t buf[256]; + int baud_i = 0; + uint64_t time_before_configuration; + + if (_serial_fd < 0) { + log("failed to open serial port: %d", errno); + goto out; + } + + /* poll descriptor */ + pollfd fds[1]; + fds[0].fd = _serial_fd; + fds[0].events = POLLIN; + debug("ready"); + + /* lock against the ioctl handler */ + lock(); + + + _baudrate = _baudrates_to_try[baud_i]; + set_baudrate(_baudrate); + + time_before_configuration = hrt_absolute_time(); + + /* loop handling received serial bytes */ + while (!_task_should_exit) { + + if (_mode_changed) { + if (_Helper != nullptr) { + delete(_Helper); + _Helper = nullptr; // XXX is this needed? + } + + switch (_mode) { + case GPS_DRIVER_MODE_UBX: + _Helper = new UBX(); + break; + case GPS_DRIVER_MODE_MTK19: + //_Helper = new MTK19(); + break; + case GPS_DRIVER_MODE_MTK16: + //_Helper = new MTK16(); + break; + case GPS_DRIVER_MODE_NMEA: + //_Helper = new NMEA(); + break; + default: + break; + } + _mode_changed = false; + } + + if (_config_needed && time_before_configuration + CONFIG_TIMEOUT < hrt_absolute_time()) { + baud_i = (baud_i+1)%NUMBER_OF_BAUDRATES; + _baudrate = _baudrates_to_try[baud_i]; + set_baudrate(_baudrate); + time_before_configuration = hrt_absolute_time(); + } + + + int poll_timeout; + if (_config_needed) { + poll_timeout = 50; + } else { + poll_timeout = 250; + } + /* sleep waiting for data, but no more than 1000ms */ + unlock(); + int ret = ::poll(fds, sizeof(fds) / sizeof(fds[0]), poll_timeout); + lock(); + + + + + /* this would be bad... */ + if (ret < 0) { + log("poll error %d", errno); + } else if (ret == 0) { + config(); + if (_config_needed == false) { + _config_needed = true; + debug("Lost GPS module"); + } + } else if (ret > 0) { + /* if we have new data from GPS, go handle it */ + if (fds[0].revents & POLLIN) { + int count; + + /* + * We are here because poll says there is some data, so this + * won't block even on a blocking device. If more bytes are + * available, we'll go back to poll() again... + */ + count = ::read(_serial_fd, buf, sizeof(buf)); + + /* pass received bytes to the packet decoder */ + int j; + for (j = 0; j < count; j++) { + _messages_received += _Helper->parse(buf[j], &_report); + } + if (_messages_received > 0) { + if (_config_needed == true) { + _config_needed = false; + debug("Found GPS module"); + } + + orb_publish(ORB_ID(vehicle_gps_position), _report_pub, &_report); + _messages_received = 0; + } + } + } + } +out: + debug("exiting"); + + ::close(_serial_fd); + + /* tell the dtor that we are exiting */ + _task = -1; + _exit(0); +} + +int +GPS::set_baudrate(unsigned baud) +{ + /* process baud rate */ + int speed; + + switch (baud) { + case 9600: speed = B9600; break; + + case 19200: speed = B19200; break; + + case 38400: speed = B38400; break; + + case 57600: speed = B57600; break; + + case 115200: speed = B115200; break; + + default: + warnx("ERROR: Unsupported baudrate: %d\n", baud); + return -EINVAL; + } + + struct termios uart_config; + int termios_state; + + /* fill the struct for the new configuration */ + tcgetattr(_serial_fd, &uart_config); + + /* clear ONLCR flag (which appends a CR for every LF) */ + uart_config.c_oflag &= ~ONLCR; + /* no parity, one stop bit */ + uart_config.c_cflag &= ~(CSTOPB | PARENB); + + /* set baud rate */ + if (cfsetispeed(&uart_config, speed) < 0 || cfsetospeed(&uart_config, speed) < 0) { + warnx("ERROR setting config: %d (cfsetispeed, cfsetospeed)\n", termios_state); + return -1; + } + + + if ((termios_state = tcsetattr(_serial_fd, TCSANOW, &uart_config)) < 0) { + warnx("ERROR setting baudrate (tcsetattr)\n"); + return -1; + } +} + +void +GPS::cmd_reset() +{ + _healthy = false; +} + +void +GPS::print_info() +{ + +} + +/** + * Local functions in support of the shell command. + */ +namespace gps +{ + +GPS *g_dev; + +void start(); +void stop(); +void test(); +void reset(); +void info(); + +/** + * Start the driver. + */ +void +start() +{ + int fd; + + if (g_dev != nullptr) + errx(1, "already started"); + + /* create the driver */ + g_dev = new GPS; + + if (g_dev == nullptr) + goto fail; + + if (OK != g_dev->init()) + goto fail; + + /* set the poll rate to default, starts automatic data collection */ + fd = open(GPS_DEVICE_PATH, O_RDONLY); + + if (fd < 0) { + printf("Could not open device path: %s\n", GPS_DEVICE_PATH); + goto fail; + } + exit(0); + +fail: + + if (g_dev != nullptr) { + delete g_dev; + g_dev = nullptr; + } + + errx(1, "driver start failed"); +} + +void +stop() +{ + delete g_dev; + g_dev = nullptr; + + exit(0); +} + +/** + * Perform some basic functional tests on the driver; + * make sure we can collect data from the sensor in polled + * and automatic modes. + */ +void +test() +{ + + errx(0, "PASS"); +} + +/** + * Reset the driver. + */ +void +reset() +{ + int fd = open(GPS_DEVICE_PATH, O_RDONLY); + + if (fd < 0) + err(1, "failed "); + + if (ioctl(fd, SENSORIOCRESET, 0) < 0) + err(1, "driver reset failed"); + + exit(0); +} + +/** + * Print the status of the driver. + */ +void +info() +{ + if (g_dev == nullptr) + errx(1, "driver not running"); + + printf("state @ %p\n", g_dev); + g_dev->print_info(); + + exit(0); +} + +} // namespace + + +int +gps_main(int argc, char *argv[]) +{ + /* + * Start/load the driver. + */ + if (!strcmp(argv[1], "start")) + gps::start(); + + if (!strcmp(argv[1], "stop")) + gps::stop(); + /* + * Test the driver/device. + */ + if (!strcmp(argv[1], "test")) + gps::test(); + + /* + * Reset the driver. + */ + if (!strcmp(argv[1], "reset")) + gps::reset(); + + /* + * Print driver status. + */ + if (!strcmp(argv[1], "status")) + gps::info(); + + errx(1, "unrecognized command, try 'start', 'stop', 'test', 'reset' or 'status'"); +} diff --git a/apps/drivers/gps/gps_helper.h b/apps/drivers/gps/gps_helper.h new file mode 100644 index 000000000..baacf7cb4 --- /dev/null +++ b/apps/drivers/gps/gps_helper.h @@ -0,0 +1,47 @@ +/**************************************************************************** + * + * Copyright (C) 2008-2013 PX4 Development Team. All rights reserved. + * Author: Thomas Gubler + * Julian Oes + * + * 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 PX4 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. + * + ****************************************************************************/ + +/* @file U-Blox protocol definitions */ + +#ifndef GPS_HELPER_H + +class GPS_Helper +{ +public: + virtual void configure(bool&, bool&, unsigned&, uint8_t*, int&, const unsigned) = 0; + virtual int parse(uint8_t, struct vehicle_gps_position_s*) = 0; +}; + +#endif /* GPS_HELPER_H */ diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp new file mode 100644 index 000000000..981b023e5 --- /dev/null +++ b/apps/drivers/gps/ubx.cpp @@ -0,0 +1,818 @@ +/**************************************************************************** + * + * Copyright (C) 2013 PX4 Development Team. All rights reserved. + * Author: Thomas Gubler + * Julian Oes + * + * 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 PX4 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. + * + ****************************************************************************/ + +/* @file U-Blox protocol implementation */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ubx.h" + + +UBX::UBX() : +_waited(0), +_config_state(UBX_CONFIG_STATE_PRT), +_new_nav_posllh(false), +_new_nav_timeutc(false), +_new_nav_dop(false), +_new_nav_sol(false), +_new_nav_velned(false) +{ + decodeInit(); + _waiting_for_ack = false; +} + +UBX::~UBX() +{ +} + +void +UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, uint8_t *buffer, int &length, const unsigned max_length) +{ + /* make sure the buffer to write the message is long enough */ + assert(sizeof(type_gps_bin_cfg_prt_packet_t)+2 <= max_length); + + /* try again after 10 times */ + if (_waited > 10) { + _waiting_for_ack = false; + } + + if (!_waiting_for_ack) { + _waiting_for_ack = true; + _waited = 0; + if (_config_state == UBX_CONFIG_STATE_CONFIGURED) { + config_needed = false; + length = 0; + _config_state = UBX_CONFIG_STATE_PRT; /* set the state for next time */ + _waiting_for_ack = false; + return; + } else if (_config_state == UBX_CONFIG_STATE_PRT) { + /* send a CFT-PRT message to define set ubx protocol and leave the baudrate as is, we just want an ACK-ACK from this */ + type_gps_bin_cfg_prt_packet_t cfg_prt_packet; + memset(&cfg_prt_packet, 0, sizeof(cfg_prt_packet)); + + cfg_prt_packet.clsID = UBX_CLASS_CFG; + cfg_prt_packet.msgID = UBX_MESSAGE_CFG_PRT; + cfg_prt_packet.length = UBX_CFG_PRT_LENGTH; + cfg_prt_packet.portID = UBX_CFG_PRT_PAYLOAD_PORTID; + cfg_prt_packet.mode = UBX_CFG_PRT_PAYLOAD_MODE; + cfg_prt_packet.baudRate = baudrate; + cfg_prt_packet.inProtoMask = UBX_CFG_PRT_PAYLOAD_INPROTOMASK; + cfg_prt_packet.outProtoMask = UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK; + + addChecksumToMessage((uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); + + buffer[0] = UBX_SYNC1; + buffer[1] = UBX_SYNC2; + memcpy(&(buffer[2]), &cfg_prt_packet, sizeof(cfg_prt_packet)); + length = sizeof(cfg_prt_packet)+2; + + } else if (_config_state == UBX_CONFIG_STATE_PRT_NEW_BAUDRATE) { + +// printf("Send change of baudrate now\n"); + + /* send a CFT-PRT message to define set ubx protocol and and baudrate, now let's try to switch the baudrate */ + type_gps_bin_cfg_prt_packet_t cfg_prt_packet; + memset(&cfg_prt_packet, 0, sizeof(cfg_prt_packet)); + + cfg_prt_packet.clsID = UBX_CLASS_CFG; + cfg_prt_packet.msgID = UBX_MESSAGE_CFG_PRT; + cfg_prt_packet.length = UBX_CFG_PRT_LENGTH; + cfg_prt_packet.portID = UBX_CFG_PRT_PAYLOAD_PORTID; + cfg_prt_packet.mode = UBX_CFG_PRT_PAYLOAD_MODE; + cfg_prt_packet.baudRate = UBX_CFG_PRT_PAYLOAD_BAUDRATE; + cfg_prt_packet.inProtoMask = UBX_CFG_PRT_PAYLOAD_INPROTOMASK; + cfg_prt_packet.outProtoMask = UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK; + + addChecksumToMessage((uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); + + buffer[0] = UBX_SYNC1; + buffer[1] = UBX_SYNC2; + memcpy(&(buffer[2]), &cfg_prt_packet, sizeof(cfg_prt_packet)); + length = sizeof(cfg_prt_packet)+2; + + /* detection when the baudrate has been changed in the first step */ + if (UBX_CFG_PRT_PAYLOAD_BAUDRATE != baudrate) { + /* set a flag and exit */ + baudrate=UBX_CFG_PRT_PAYLOAD_BAUDRATE; + baudrate_changed = true; + _config_state = UBX_CONFIG_STATE_RATE; + _waiting_for_ack = false; + return; + } + + + + } else if (_config_state == UBX_CONFIG_STATE_RATE) { + + /* send a CFT-RATE message to define update rate */ + type_gps_bin_cfg_rate_packet_t cfg_rate_packet; + memset(&cfg_rate_packet, 0, sizeof(cfg_rate_packet)); + + cfg_rate_packet.clsID = UBX_CLASS_CFG; + cfg_rate_packet.msgID = UBX_MESSAGE_CFG_RATE; + cfg_rate_packet.length = UBX_CFG_RATE_LENGTH; + cfg_rate_packet.measRate = UBX_CFG_RATE_PAYLOAD_MEASRATE; + cfg_rate_packet.navRate = UBX_CFG_RATE_PAYLOAD_NAVRATE; + cfg_rate_packet.timeRef = UBX_CFG_RATE_PAYLOAD_TIMEREF; + + addChecksumToMessage((uint8_t*)&cfg_rate_packet, sizeof(cfg_rate_packet)); + + buffer[0] = UBX_SYNC1; + buffer[1] = UBX_SYNC2; + memcpy(&(buffer[2]), &cfg_rate_packet, sizeof(cfg_rate_packet)); + length = sizeof(cfg_rate_packet)+2; + + } else if (_config_state == UBX_CONFIG_STATE_NAV5) { + /* send a NAV5 message to set the options for the internal estimator */ + type_gps_bin_cfg_nav5_packet_t cfg_nav5_packet; + memset(&cfg_nav5_packet, 0, sizeof(cfg_nav5_packet)); //set everything to 0 + + cfg_nav5_packet.clsID = UBX_CLASS_CFG; + cfg_nav5_packet.msgID = UBX_MESSAGE_CFG_NAV5; + cfg_nav5_packet.length = UBX_CFG_NAV5_LENGTH; + cfg_nav5_packet.mask = UBX_CFG_NAV5_PAYLOAD_MASK; + cfg_nav5_packet.dynModel = UBX_CFG_NAV5_PAYLOAD_DYNMODEL; + cfg_nav5_packet.fixMode = UBX_CFG_NAV5_PAYLOAD_FIXMODE; + + addChecksumToMessage((uint8_t*)&cfg_nav5_packet, sizeof(cfg_nav5_packet)); + + buffer[0] = UBX_SYNC1; + buffer[1] = UBX_SYNC2; + memcpy(&(buffer[2]), &cfg_nav5_packet, sizeof(cfg_nav5_packet)); + length = sizeof(cfg_nav5_packet)+2; + + } else { + /* catch the remaining config states here */ + + type_gps_bin_cfg_msg_packet_t cfg_msg_packet; + memset(&cfg_msg_packet, 0, sizeof(cfg_msg_packet)); //set everything to 0 + + cfg_msg_packet.clsID = UBX_CLASS_CFG; + cfg_msg_packet.msgID = UBX_MESSAGE_CFG_MSG; + cfg_msg_packet.length = UBX_CFG_MSG_LENGTH; + cfg_msg_packet.rate[1] = UBX_CFG_MSG_PAYLOAD_RATE1; + + switch (_config_state) { + case UBX_CONFIG_STATE_MSG_NAV_POSLLH: + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_POSLLH; + break; + case UBX_CONFIG_STATE_MSG_NAV_TIMEUTC: + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_TIMEUTC; + break; + case UBX_CONFIG_STATE_MSG_NAV_DOP: + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_DOP; + break; + case UBX_CONFIG_STATE_MSG_NAV_SVINFO: + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_SVINFO; + cfg_msg_packet.rate[1] = 5; + break; + case UBX_CONFIG_STATE_MSG_NAV_SOL: + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_SOL; + break; + case UBX_CONFIG_STATE_MSG_NAV_VELNED: + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_VELNED; + break; +// case UBX_CONFIG_STATE_MSG_RXM_SVSI: +// cfg_msg_packet.msgClass_payload = UBX_CLASS_RXM; +// cfg_msg_packet.msgID_payload = UBX_MESSAGE_RXM_SVSI; +// break; + default: + break; + } + + addChecksumToMessage((uint8_t*)&cfg_msg_packet, sizeof(cfg_msg_packet)); + + buffer[0] = UBX_SYNC1; + buffer[1] = UBX_SYNC2; + memcpy(&(buffer[2]), &cfg_msg_packet, sizeof(cfg_msg_packet)); + length = sizeof(cfg_msg_packet)+2; + } + } else { + _waited++; + } +} + +int +UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) +{ + int ret = 0; + //printf("Received char: %c\n", b); + + switch (_decode_state) { + /* First, look for sync1 */ + case UBX_DECODE_UNINIT: + if (b == UBX_SYNC1) { + _decode_state = UBX_DECODE_GOT_SYNC1; + } + break; + /* Second, look for sync2 */ + case UBX_DECODE_GOT_SYNC1: + if (b == UBX_SYNC2) { + _decode_state = UBX_DECODE_GOT_SYNC2; + } else { + /* Second start symbol was wrong, reset state machine */ + decodeInit(); + } + break; + /* Now look for class */ + case UBX_DECODE_GOT_SYNC2: + /* everything except sync1 and sync2 needs to be added to the checksum */ + addByteToChecksum(b); + /* check for known class */ + switch (b) { + case UBX_CLASS_ACK: + _decode_state = UBX_DECODE_GOT_CLASS; + _message_class = ACK; + break; + + case UBX_CLASS_NAV: + _decode_state = UBX_DECODE_GOT_CLASS; + _message_class = NAV; + break; + +// case UBX_CLASS_RXM: +// _decode_state = UBX_DECODE_GOT_CLASS; +// _message_class = RXM; +// break; + + case UBX_CLASS_CFG: + _decode_state = UBX_DECODE_GOT_CLASS; + _message_class = CFG; + break; + default: //unknown class: reset state machine + decodeInit(); + break; + } + break; + case UBX_DECODE_GOT_CLASS: + addByteToChecksum(b); + switch (_message_class) { + case NAV: + switch (b) { + case UBX_MESSAGE_NAV_POSLLH: + _decode_state = UBX_DECODE_GOT_MESSAGEID; + _message_id = NAV_POSLLH; + break; + + case UBX_MESSAGE_NAV_SOL: + _decode_state = UBX_DECODE_GOT_MESSAGEID; + _message_id = NAV_SOL; + break; + + case UBX_MESSAGE_NAV_TIMEUTC: + _decode_state = UBX_DECODE_GOT_MESSAGEID; + _message_id = NAV_TIMEUTC; + break; + + case UBX_MESSAGE_NAV_DOP: + _decode_state = UBX_DECODE_GOT_MESSAGEID; + _message_id = NAV_DOP; + break; + + case UBX_MESSAGE_NAV_SVINFO: + _decode_state = UBX_DECODE_GOT_MESSAGEID; + _message_id = NAV_SVINFO; + break; + + case UBX_MESSAGE_NAV_VELNED: + _decode_state = UBX_DECODE_GOT_MESSAGEID; + _message_id = NAV_VELNED; + break; + + default: //unknown class: reset state machine, should not happen + decodeInit(); + break; + } + break; +// case RXM: +// switch (b) { +// case UBX_MESSAGE_RXM_SVSI: +// _decode_state = UBX_DECODE_GOT_MESSAGEID; +// _message_id = RXM_SVSI; +// break; +// +// default: //unknown class: reset state machine, should not happen +// decodeInit(); +// break; +// } +// break; + + case CFG: + switch (b) { + case UBX_MESSAGE_CFG_NAV5: + _decode_state = UBX_DECODE_GOT_MESSAGEID; + _message_id = CFG_NAV5; + break; + + default: //unknown class: reset state machine, should not happen + decodeInit(); + break; + } + break; + + case ACK: + switch (b) { + case UBX_MESSAGE_ACK_ACK: + _decode_state = UBX_DECODE_GOT_MESSAGEID; + _message_id = ACK_ACK; + break; + case UBX_MESSAGE_ACK_NAK: + _decode_state = UBX_DECODE_GOT_MESSAGEID; + _message_id = ACK_NAK; + break; + default: //unknown class: reset state machine, should not happen + decodeInit(); + break; + } + break; + default: //should not happen because we set the class + printf("UBX Error, we set a class that we don't know\n"); + decodeInit(); + break; + } + break; + case UBX_DECODE_GOT_MESSAGEID: + addByteToChecksum(b); + _payload_size = b; //this is the first length byte + _decode_state = UBX_DECODE_GOT_LENGTH1; + break; + case UBX_DECODE_GOT_LENGTH1: + addByteToChecksum(b); + _payload_size += b << 8; // here comes the second byte of length + _decode_state = UBX_DECODE_GOT_LENGTH2; + break; + case UBX_DECODE_GOT_LENGTH2: + /* Add to checksum if not yet at checksum byte */ + if (_rx_count < _payload_size) + addByteToChecksum(b); + _rx_buffer[_rx_count] = b; + /* once the payload has arrived, we can process the information */ + if (_rx_count >= _payload_size + 1) { //+1 because of 2 checksum bytes + switch (_message_id) { //this enum is unique for all ids --> no need to check the class + case NAV_POSLLH: { +// printf("GOT NAV_POSLLH MESSAGE\n"); + gps_bin_nav_posllh_packet_t *packet = (gps_bin_nav_posllh_packet_t *) _rx_buffer; + + //Check if checksum is valid and the store the gps information + if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { + gps_position->lat = packet->lat; + gps_position->lon = packet->lon; + gps_position->alt = packet->height_msl; + + gps_position->counter_pos_valid++; + gps_position->counter++; + + _new_nav_posllh = true; + + } else { + printf("[gps] NAV_POSLLH: checksum invalid\n"); + } + + // Reset state machine to decode next packet + decodeInit(); + return ret; + + break; + } + + case NAV_SOL: { +// printf("GOT NAV_SOL MESSAGE\n"); + gps_bin_nav_sol_packet_t *packet = (gps_bin_nav_sol_packet_t *) _rx_buffer; + + //Check if checksum is valid and the store the gps information + if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { + + gps_position->fix_type = packet->gpsFix; + + gps_position->timestamp = hrt_absolute_time(); + gps_position->counter++; + gps_position->s_variance = packet->sAcc; + gps_position->p_variance = packet->pAcc; + + _new_nav_sol = true; + + } else { + printf("[gps] NAV_SOL: checksum invalid\n"); + } + + // Reset state machine to decode next packet + decodeInit(); + return ret; + + break; + } + + case NAV_DOP: { +// printf("GOT NAV_DOP MESSAGE\n"); + gps_bin_nav_dop_packet_t *packet = (gps_bin_nav_dop_packet_t *) _rx_buffer; + + //Check if checksum is valid and the store the gps information + if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { + + gps_position->eph = packet->hDOP; + gps_position->epv = packet->vDOP; + + gps_position->timestamp = hrt_absolute_time(); + gps_position->counter++; + + _new_nav_dop = true; + + } else { + printf("[gps] NAV_DOP: checksum invalid\n"); + } + + // Reset state machine to decode next packet + decodeInit(); + return ret; + + break; + } + + case NAV_TIMEUTC: { +// printf("GOT NAV_TIMEUTC MESSAGE\n"); + gps_bin_nav_timeutc_packet_t *packet = (gps_bin_nav_timeutc_packet_t *) _rx_buffer; + + //Check if checksum is valid and the store the gps information + if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { + //convert to unix timestamp + struct tm timeinfo; + timeinfo.tm_year = packet->year - 1900; + timeinfo.tm_mon = packet->month - 1; + timeinfo.tm_mday = packet->day; + timeinfo.tm_hour = packet->hour; + timeinfo.tm_min = packet->min; + timeinfo.tm_sec = packet->sec; + + time_t epoch = mktime(&timeinfo); + + gps_position->time_gps_usec = (uint64_t)epoch * 1000000; //TODO: test this + gps_position->time_gps_usec += (uint64_t)(packet->time_nanoseconds * 1e-3f); + + gps_position->timestamp = hrt_absolute_time(); + gps_position->counter++; + + _new_nav_timeutc = true; + + } else { + printf("\t[gps] NAV_TIMEUTC: checksum invalid\n"); + } + + // Reset state machine to decode next packet + decodeInit(); + return ret; + + break; + } + + case NAV_SVINFO: { +// printf("GOT NAV_SVINFO MESSAGE\n"); + + //this is a more complicated message: the length depends on the number of satellites. This number is extracted from the first part of the message + const int length_part1 = 8; + char _rx_buffer_part1[length_part1]; + memcpy(_rx_buffer_part1, _rx_buffer, length_part1); + gps_bin_nav_svinfo_part1_packet_t *packet_part1 = (gps_bin_nav_svinfo_part1_packet_t *) _rx_buffer_part1; + + //read checksum + const int length_part3 = 2; + char _rx_buffer_part3[length_part3]; + memcpy(_rx_buffer_part3, &(_rx_buffer[_rx_count - 1]), length_part3); + gps_bin_nav_svinfo_part3_packet_t *packet_part3 = (gps_bin_nav_svinfo_part3_packet_t *) _rx_buffer_part3; + + //Check if checksum is valid and then store the gps information + if (_rx_ck_a == packet_part3->ck_a && _rx_ck_b == packet_part3->ck_b) { + //definitions needed to read numCh elements from the buffer: + const int length_part2 = 12; + gps_bin_nav_svinfo_part2_packet_t *packet_part2; + char _rx_buffer_part2[length_part2]; //for temporal storage + + uint8_t satellites_used = 0; + int i; + + for (i = 0; i < packet_part1->numCh; i++) { //for each channel + + /* Get satellite information from the buffer */ + memcpy(_rx_buffer_part2, &(_rx_buffer[length_part1 + i * length_part2]), length_part2); + packet_part2 = (gps_bin_nav_svinfo_part2_packet_t *) _rx_buffer_part2; + + + /* Write satellite information in the global storage */ + gps_position->satellite_prn[i] = packet_part2->svid; + + //if satellite information is healthy store the data + uint8_t unhealthy = packet_part2->flags & 1 << 4; //flags is a bitfield + + if (!unhealthy) { + if ((packet_part2->flags) & 1) { //flags is a bitfield + gps_position->satellite_used[i] = 1; + satellites_used++; + + } else { + gps_position->satellite_used[i] = 0; + } + + gps_position->satellite_snr[i] = packet_part2->cno; + gps_position->satellite_elevation[i] = (uint8_t)(packet_part2->elev); + gps_position->satellite_azimuth[i] = (uint8_t)((float)packet_part2->azim * 255.0f / 360.0f); + + } else { + gps_position->satellite_used[i] = 0; + gps_position->satellite_snr[i] = 0; + gps_position->satellite_elevation[i] = 0; + gps_position->satellite_azimuth[i] = 0; + } + + } + + for (i = packet_part1->numCh; i < 20; i++) { //these channels are unused + /* Unused channels have to be set to zero for e.g. MAVLink */ + gps_position->satellite_prn[i] = 0; + gps_position->satellite_used[i] = 0; + gps_position->satellite_snr[i] = 0; + gps_position->satellite_elevation[i] = 0; + gps_position->satellite_azimuth[i] = 0; + } + + /* set flag if any sat info is available */ + if (!packet_part1->numCh > 0) { + gps_position->satellite_info_available = 1; + + } else { + gps_position->satellite_info_available = 0; + } + + gps_position->satellites_visible = satellites_used++; // visible ~= used but we are interested in the used ones + gps_position->timestamp = hrt_absolute_time(); + gps_position->counter++; + + // as this message arrives only with 1Hz and is not essential, we don't take it into account for the report + + } else { + printf("\t[gps] NAV_SVINFO: checksum invalid\n"); + } + + // Reset state machine to decode next packet + decodeInit(); + return ret; + + break; + } + + case NAV_VELNED: { +// printf("GOT NAV_VELNED MESSAGE\n"); + gps_bin_nav_velned_packet_t *packet = (gps_bin_nav_velned_packet_t *) _rx_buffer; + + //Check if checksum is valid and the store the gps information + if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { + + gps_position->vel = (uint16_t)packet->speed; + gps_position->vel_n = packet->velN / 100.0f; + gps_position->vel_e = packet->velE / 100.0f; + gps_position->vel_d = packet->velD / 100.0f; + gps_position->vel_ned_valid = true; + gps_position->cog = (uint16_t)((float)(packet->heading) * 1e-3f); + + gps_position->timestamp = hrt_absolute_time(); + gps_position->counter++; + + + _new_nav_velned = true; + + } else { + printf("[gps] NAV_VELNED: checksum invalid\n"); + } + + // Reset state machine to decode next packet + decodeInit(); + return ret; + + break; + } + +// case RXM_SVSI: { +// printf("GOT RXM_SVSI MESSAGE\n"); +// const int length_part1 = 7; +// char _rx_buffer_part1[length_part1]; +// memcpy(_rx_buffer_part1, _rx_buffer, length_part1); +// gps_bin_rxm_svsi_packet_t *packet = (gps_bin_rxm_svsi_packet_t *) _rx_buffer_part1; +// +// //Check if checksum is valid and the store the gps information +// if (_rx_ck_a == _rx_buffer[_rx_count - 1] && _rx_ck_b == _rx_buffer[_rx_count]) { +// +// gps_position->satellites_visible = packet->numVis; +// gps_position->timestamp = hrt_absolute_time(); +// gps_position->counter++; +// _last_message_timestamps[RXM_SVSI - 1] = hrt_absolute_time(); +// ret = 1; +// +// } else { +// printf("[gps] RXM_SVSI: checksum invalid\n"); +// } +// +// // Reset state machine to decode next packet +// decodeInit(); +// return ret; +// +// break; +// } + + case ACK_ACK: { +// printf("GOT ACK_ACK\n"); + gps_bin_ack_ack_packet_t *packet = (gps_bin_ack_ack_packet_t *) _rx_buffer; + + //Check if checksum is valid + if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { + + _waiting_for_ack = false; + + switch (_config_state) { + case UBX_CONFIG_STATE_PRT: + if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_PRT) + _config_state = UBX_CONFIG_STATE_PRT_NEW_BAUDRATE; + break; + case UBX_CONFIG_STATE_PRT_NEW_BAUDRATE: + if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_PRT) + _config_state = UBX_CONFIG_STATE_RATE; + break; + case UBX_CONFIG_STATE_RATE: + if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_RATE) + _config_state = UBX_CONFIG_STATE_NAV5; + break; + case UBX_CONFIG_STATE_NAV5: + if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_NAV5) + _config_state = UBX_CONFIG_STATE_MSG_NAV_POSLLH; + break; + case UBX_CONFIG_STATE_MSG_NAV_POSLLH: + if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) + _config_state = UBX_CONFIG_STATE_MSG_NAV_TIMEUTC; + break; + case UBX_CONFIG_STATE_MSG_NAV_TIMEUTC: + if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) + _config_state = UBX_CONFIG_STATE_MSG_NAV_DOP; + break; + case UBX_CONFIG_STATE_MSG_NAV_DOP: + if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) + _config_state = UBX_CONFIG_STATE_MSG_NAV_SVINFO; + break; + case UBX_CONFIG_STATE_MSG_NAV_SVINFO: + if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) + _config_state = UBX_CONFIG_STATE_MSG_NAV_SOL; + break; + case UBX_CONFIG_STATE_MSG_NAV_SOL: + if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) + _config_state = UBX_CONFIG_STATE_MSG_NAV_VELNED; + break; + case UBX_CONFIG_STATE_MSG_NAV_VELNED: + if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) + _config_state = UBX_CONFIG_STATE_CONFIGURED; + break; +// case UBX_CONFIG_STATE_MSG_RXM_SVSI: +// if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) +// _config_state = UBX_CONFIG_STATE_CONFIGURED; +// break; + default: + break; + } + } else { + printf("[gps] ACK_ACK: checksum invalid\n"); + } + + // Reset state machine to decode next packet + decodeInit(); + return ret; + + break; + } + + case ACK_NAK: { +// printf("GOT ACK_NAK\n"); + gps_bin_ack_nak_packet_t *packet = (gps_bin_ack_nak_packet_t *) _rx_buffer; + + //Check if checksum is valid + if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { + + printf("[gps] the ubx gps returned: not acknowledged\n"); + ret = 1; + + } else { + printf("[gps] ACK_NAK: checksum invalid\n"); + } + + // Reset state machine to decode next packet + decodeInit(); + return ret; + + break; + } + + default: //we don't know the message + printf("Unknown message received: %d-%d\n",_message_class,_message_id); + decodeInit(); + + break; + } + } // end if _rx_count high enough + if (_rx_count < RECV_BUFFER_SIZE) { + _rx_count++; + } else { + printf("Buffer full"); + decodeInit(); + } + break; + default: + break; + } + + /* return 1 when all needed messages have arrived */ + if(_new_nav_posllh &&_new_nav_timeutc && _new_nav_dop && _new_nav_sol && _new_nav_velned) { + + gps_position->timestamp = hrt_absolute_time(); + ret = 1; + _new_nav_posllh = false; + _new_nav_timeutc = false; + _new_nav_dop = false; + _new_nav_sol = false; + _new_nav_velned = false; + } + + return ret; +} + +void +UBX::decodeInit(void) +{ + _rx_ck_a = 0; + _rx_ck_b = 0; + _rx_count = 0; + _decode_state = UBX_DECODE_UNINIT; + _message_class = CLASS_UNKNOWN; + _message_id = ID_UNKNOWN; + _payload_size = 0; +} + +void +UBX::addByteToChecksum(uint8_t b) +{ + _rx_ck_a = _rx_ck_a + b; + _rx_ck_b = _rx_ck_b + _rx_ck_a; +} + +void +UBX::addChecksumToMessage(uint8_t* message, const unsigned length) +{ + uint8_t ck_a = 0; + uint8_t ck_b = 0; + unsigned i; + + for (i = 0; i < length-2; i++) { + ck_a = ck_a + message[i]; + ck_b = ck_b + ck_a; + } + message[length-2] = ck_a; + message[length-1] = ck_b; +} diff --git a/apps/drivers/gps/ubx.h b/apps/drivers/gps/ubx.h new file mode 100644 index 000000000..dff25a518 --- /dev/null +++ b/apps/drivers/gps/ubx.h @@ -0,0 +1,369 @@ +/**************************************************************************** + * + * Copyright (C) 2008-2013 PX4 Development Team. All rights reserved. + * Author: Thomas Gubler + * Julian Oes + * + * 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 PX4 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. + * + ****************************************************************************/ + +/* @file U-Blox protocol definitions */ + +#ifndef UBX_H_ +#define UBX_H_ + +#include "gps_helper.h" + +#define UBX_NO_OF_MESSAGES 7 /**< Read 7 UBX GPS messages */ + +#define UBX_SYNC1 0xB5 +#define UBX_SYNC2 0x62 + +//UBX Protocol definitions (this is the subset of the messages that are parsed) +#define UBX_CLASS_NAV 0x01 +//#define UBX_CLASS_RXM 0x02 +#define UBX_CLASS_ACK 0x05 +#define UBX_CLASS_CFG 0x06 +#define UBX_MESSAGE_NAV_POSLLH 0x02 +#define UBX_MESSAGE_NAV_SOL 0x06 +#define UBX_MESSAGE_NAV_TIMEUTC 0x21 +#define UBX_MESSAGE_NAV_DOP 0x04 +#define UBX_MESSAGE_NAV_SVINFO 0x30 +#define UBX_MESSAGE_NAV_VELNED 0x12 +//#define UBX_MESSAGE_RXM_SVSI 0x20 +#define UBX_MESSAGE_ACK_ACK 0x01 +#define UBX_MESSAGE_ACK_NAK 0x00 +#define UBX_MESSAGE_CFG_PRT 0x00 +#define UBX_MESSAGE_CFG_NAV5 0x24 +#define UBX_MESSAGE_CFG_MSG 0x01 +#define UBX_MESSAGE_CFG_RATE 0x08 + +#define UBX_CFG_PRT_LENGTH 20 +#define UBX_CFG_PRT_PAYLOAD_PORTID 0x01 /**< port 1 */ +#define UBX_CFG_PRT_PAYLOAD_MODE 0x000008D0 /**< 0b0000100011010000: 8N1 */ +#define UBX_CFG_PRT_PAYLOAD_BAUDRATE 38400 /**< always choose 38400 as GPS baudrate */ +#define UBX_CFG_PRT_PAYLOAD_INPROTOMASK 0x01 /**< ubx in */ +#define UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK 0x01 /**< ubx out */ + +#define UBX_CFG_RATE_LENGTH 6 +#define UBX_CFG_RATE_PAYLOAD_MEASRATE 200 /**< 200ms for 5Hz */ +#define UBX_CFG_RATE_PAYLOAD_NAVRATE 1 /**< cannot be changed */ +#define UBX_CFG_RATE_PAYLOAD_TIMEREF 0 /**< 0: UTC, 1: GPS time */ + + +#define UBX_CFG_NAV5_LENGTH 36 +#define UBX_CFG_NAV5_PAYLOAD_MASK 0x0001 /**< only update dynamic model and fix mode */ +#define UBX_CFG_NAV5_PAYLOAD_DYNMODEL 7 /**< 0: portable, 2: stationary, 3: pedestrian, 4: automotive, 5: sea, 6: airborne <1g, 7: airborne <2g, 8: airborne <4g */ +#define UBX_CFG_NAV5_PAYLOAD_FIXMODE 2 /**< 1: 2D only, 2: 3D only, 3: Auto 2D/3D */ + +#define UBX_CFG_MSG_LENGTH 8 +#define UBX_CFG_MSG_PAYLOAD_RATE1 0x01 /**< {0x00, 0x01, 0x00, 0x00, 0x00, 0x00} UART1 chosen */ + + +// ************ +/** the structures of the binary packets */ +#pragma pack(push, 1) + +typedef struct { + uint32_t time_milliseconds; // GPS Millisecond Time of Week + int32_t lon; // Longitude * 1e-7, deg + int32_t lat; // Latitude * 1e-7, deg + int32_t height; // Height above Ellipsoid, mm + int32_t height_msl; // Height above mean sea level, mm + uint32_t hAcc; // Horizontal Accuracy Estimate, mm + uint32_t vAcc; // Vertical Accuracy Estimate, mm + uint8_t ck_a; + uint8_t ck_b; +} gps_bin_nav_posllh_packet_t; + +typedef struct { + uint32_t time_milliseconds; // GPS Millisecond Time of Week + int32_t time_nanoseconds; // Fractional Nanoseconds remainder of rounded ms above, range -500000 .. 500000 + int16_t week; // GPS week (GPS time) + uint8_t gpsFix; //GPS Fix: 0 = No fix, 1 = Dead Reckoning only, 2 = 2D fix, 3 = 3d-fix, 4 = GPS + dead reckoning, 5 = time only fix + uint8_t flags; + int32_t ecefX; + int32_t ecefY; + int32_t ecefZ; + uint32_t pAcc; + int32_t ecefVX; + int32_t ecefVY; + int32_t ecefVZ; + uint32_t sAcc; + uint16_t pDOP; + uint8_t reserved1; + uint8_t numSV; + uint32_t reserved2; + uint8_t ck_a; + uint8_t ck_b; +} gps_bin_nav_sol_packet_t; + +typedef struct { + uint32_t time_milliseconds; // GPS Millisecond Time of Week + uint32_t time_accuracy; //Time Accuracy Estimate, ns + int32_t time_nanoseconds; //Nanoseconds of second, range -1e9 .. 1e9 (UTC) + uint16_t year; //Year, range 1999..2099 (UTC) + uint8_t month; //Month, range 1..12 (UTC) + uint8_t day; //Day of Month, range 1..31 (UTC) + uint8_t hour; //Hour of Day, range 0..23 (UTC) + uint8_t min; //Minute of Hour, range 0..59 (UTC) + uint8_t sec; //Seconds of Minute, range 0..59 (UTC) + uint8_t valid_flag; //Validity Flags (see ubx documentation) + uint8_t ck_a; + uint8_t ck_b; +} gps_bin_nav_timeutc_packet_t; + +typedef struct { + uint32_t time_milliseconds; // GPS Millisecond Time of Week + uint16_t gDOP; //Geometric DOP (scaling 0.01) + uint16_t pDOP; //Position DOP (scaling 0.01) + uint16_t tDOP; //Time DOP (scaling 0.01) + uint16_t vDOP; //Vertical DOP (scaling 0.01) + uint16_t hDOP; //Horizontal DOP (scaling 0.01) + uint16_t nDOP; //Northing DOP (scaling 0.01) + uint16_t eDOP; //Easting DOP (scaling 0.01) + uint8_t ck_a; + uint8_t ck_b; +} gps_bin_nav_dop_packet_t; + +typedef struct { + uint32_t time_milliseconds; // GPS Millisecond Time of Week + uint8_t numCh; //Number of channels + uint8_t globalFlags; + uint16_t reserved2; + +} gps_bin_nav_svinfo_part1_packet_t; + +typedef struct { + uint8_t chn; //Channel number, 255 for SVs not assigned to a channel + uint8_t svid; //Satellite ID + uint8_t flags; + uint8_t quality; + uint8_t cno; //Carrier to Noise Ratio (Signal Strength), dbHz + int8_t elev; //Elevation in integer degrees + int16_t azim; //Azimuth in integer degrees + int32_t prRes; //Pseudo range residual in centimetres + +} gps_bin_nav_svinfo_part2_packet_t; + +typedef struct { + uint8_t ck_a; + uint8_t ck_b; +} gps_bin_nav_svinfo_part3_packet_t; + +typedef struct { + uint32_t time_milliseconds; // GPS Millisecond Time of Week + int32_t velN; //NED north velocity, cm/s + int32_t velE; //NED east velocity, cm/s + int32_t velD; //NED down velocity, cm/s + uint32_t speed; //Speed (3-D), cm/s + uint32_t gSpeed; //Ground Speed (2-D), cm/s + int32_t heading; //Heading of motion 2-D, deg, scaling: 1e-5 + uint32_t sAcc; //Speed Accuracy Estimate, cm/s + uint32_t cAcc; //Course / Heading Accuracy Estimate, scaling: 1e-5 + uint8_t ck_a; + uint8_t ck_b; +} gps_bin_nav_velned_packet_t; + +//typedef struct { +// int32_t time_milliseconds; // Measurement integer millisecond GPS time of week +// int16_t week; //Measurement GPS week number +// uint8_t numVis; //Number of visible satellites +// +// //... rest of package is not used in this implementation +// +//} gps_bin_rxm_svsi_packet_t; + +typedef struct { + uint8_t clsID; + uint8_t msgID; + uint8_t ck_a; + uint8_t ck_b; +} gps_bin_ack_ack_packet_t; + +typedef struct { + uint8_t clsID; + uint8_t msgID; + + uint8_t ck_a; + uint8_t ck_b; +} gps_bin_ack_nak_packet_t; + +typedef struct { + uint8_t clsID; + uint8_t msgID; + uint16_t length; + uint8_t portID; + uint8_t res0; + uint16_t res1; + uint32_t mode; + uint32_t baudRate; + uint16_t inProtoMask; + uint16_t outProtoMask; + uint16_t flags; + uint16_t pad; + uint8_t ck_a; + uint8_t ck_b; +} type_gps_bin_cfg_prt_packet_t; + +typedef struct { + uint8_t clsID; + uint8_t msgID; + uint16_t length; + uint16_t measRate; + uint16_t navRate; + uint16_t timeRef; + uint8_t ck_a; + uint8_t ck_b; +} type_gps_bin_cfg_rate_packet_t; + +typedef struct { + uint8_t clsID; + uint8_t msgID; + uint16_t length; + uint16_t mask; + uint8_t dynModel; + uint8_t fixMode; + int32_t fixedAlt; + uint32_t fixedAltVar; + int8_t minElev; + uint8_t drLimit; + uint16_t pDop; + uint16_t tDop; + uint16_t pAcc; + uint16_t tAcc; + uint8_t staticHoldThresh; + uint8_t dgpsTimeOut; + uint32_t reserved2; + uint32_t reserved3; + uint32_t reserved4; + uint8_t ck_a; + uint8_t ck_b; +} type_gps_bin_cfg_nav5_packet_t; + +typedef struct { + uint8_t clsID; + uint8_t msgID; + uint16_t length; + uint8_t msgClass_payload; + uint8_t msgID_payload; + uint8_t rate[6]; + uint8_t ck_a; + uint8_t ck_b; +} type_gps_bin_cfg_msg_packet_t; + + +// END the structures of the binary packets +// ************ + +typedef enum { + UBX_CONFIG_STATE_PRT = 0, + UBX_CONFIG_STATE_PRT_NEW_BAUDRATE, + UBX_CONFIG_STATE_RATE, + UBX_CONFIG_STATE_NAV5, + UBX_CONFIG_STATE_MSG_NAV_POSLLH, + UBX_CONFIG_STATE_MSG_NAV_TIMEUTC, + UBX_CONFIG_STATE_MSG_NAV_DOP, + UBX_CONFIG_STATE_MSG_NAV_SVINFO, + UBX_CONFIG_STATE_MSG_NAV_SOL, + UBX_CONFIG_STATE_MSG_NAV_VELNED, +// UBX_CONFIG_STATE_MSG_RXM_SVSI, + UBX_CONFIG_STATE_CONFIGURED +} ubx_config_state_t; + +typedef enum { + CLASS_UNKNOWN = 0, + NAV = 1, + RXM = 2, + ACK = 3, + CFG = 4 +} ubx_message_class_t; + +typedef enum { + //these numbers do NOT correspond to the message id numbers of the ubx protocol + ID_UNKNOWN = 0, + NAV_POSLLH, + NAV_SOL, + NAV_TIMEUTC, + NAV_DOP, + NAV_SVINFO, + NAV_VELNED, +// RXM_SVSI, + CFG_NAV5, + ACK_ACK, + ACK_NAK, +} ubx_message_id_t; + +typedef enum { + UBX_DECODE_UNINIT = 0, + UBX_DECODE_GOT_SYNC1, + UBX_DECODE_GOT_SYNC2, + UBX_DECODE_GOT_CLASS, + UBX_DECODE_GOT_MESSAGEID, + UBX_DECODE_GOT_LENGTH1, + UBX_DECODE_GOT_LENGTH2 +} ubx_decode_state_t; + +//typedef type_gps_bin_ubx_state gps_bin_ubx_state_t; +#pragma pack(pop) + +#define RECV_BUFFER_SIZE 500 //The NAV-SOL messages really need such a big buffer + +class UBX : public GPS_Helper +{ +public: + UBX(); + ~UBX(); + + void configure(bool&, bool&, unsigned&, uint8_t*, int&, const unsigned); + int parse(uint8_t, struct vehicle_gps_position_s*); + +private: + void decodeInit(void); + void addByteToChecksum(uint8_t); + void addChecksumToMessage(uint8_t*, const unsigned); + unsigned _waited; + bool _waiting_for_ack; + ubx_config_state_t _config_state; + ubx_decode_state_t _decode_state; + uint8_t _rx_buffer[RECV_BUFFER_SIZE]; + unsigned _rx_count; + uint8_t _rx_ck_a; + uint8_t _rx_ck_b; + ubx_message_class_t _message_class; + ubx_message_id_t _message_id; + unsigned _payload_size; + bool _new_nav_posllh; + bool _new_nav_timeutc; + bool _new_nav_dop; + bool _new_nav_sol; + bool _new_nav_velned; +}; + +#endif /* UBX_H_ */ -- cgit v1.2.3 From 3fd8c73bfbdad1fdb9b5b31337cf6eb3fa46c34c Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 4 Feb 2013 15:58:53 +0100 Subject: Disabled old-style gps interface, enabled GPS driver --- apps/drivers/gps/gps.cpp | 2 ++ nuttx/configs/px4fmu/nsh/appconfig | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 7d6f7144e..9fd679240 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -471,6 +471,8 @@ GPS::set_baudrate(unsigned baud) warnx("ERROR setting baudrate (tcsetattr)\n"); return -1; } + + /* XXX if resetting the parser here, ensure it does exist (check for null pointer) */ } void diff --git a/nuttx/configs/px4fmu/nsh/appconfig b/nuttx/configs/px4fmu/nsh/appconfig index 653f97de1..710e2fb5f 100644 --- a/nuttx/configs/px4fmu/nsh/appconfig +++ b/nuttx/configs/px4fmu/nsh/appconfig @@ -80,7 +80,6 @@ CONFIGURED_APPS += uORB CONFIGURED_APPS += mavlink CONFIGURED_APPS += mavlink_onboard -CONFIGURED_APPS += gps CONFIGURED_APPS += commander CONFIGURED_APPS += sdlog CONFIGURED_APPS += sensors @@ -114,6 +113,7 @@ CONFIGURED_APPS += drivers/stm32/tone_alarm CONFIGURED_APPS += drivers/stm32/adc CONFIGURED_APPS += drivers/px4fmu CONFIGURED_APPS += drivers/hil +CONFIGURED_APPS += drivers/gps # Testing stuff CONFIGURED_APPS += px4/sensors_bringup -- cgit v1.2.3 From 12f4cb2dc38303b58750a8f3b120738a291ac8d1 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 4 Feb 2013 16:13:17 +0100 Subject: Tuned GPS update rates --- apps/mavlink/mavlink.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/mavlink/mavlink.c b/apps/mavlink/mavlink.c index ceb7c2554..09abcf269 100644 --- a/apps/mavlink/mavlink.c +++ b/apps/mavlink/mavlink.c @@ -625,7 +625,9 @@ int mavlink_thread_main(int argc, char *argv[]) /* 20 Hz / 50 ms */ set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_NAMED_VALUE_FLOAT, 10); set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, 50); - /* 2 Hz */ + /* 10 Hz */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_GPS_RAW, 100); + /* 10 Hz */ set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 100); } else if (baudrate >= 115200) { @@ -634,8 +636,10 @@ int mavlink_thread_main(int argc, char *argv[]) set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_RAW_IMU, 50); set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_ATTITUDE, 50); set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_NAMED_VALUE_FLOAT, 50); - /* 5 Hz / 100 ms */ + /* 5 Hz / 200 ms */ set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, 200); + /* 5 Hz / 200 ms */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_GPS_RAW, 200); /* 2 Hz */ set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 500); @@ -651,6 +655,8 @@ int mavlink_thread_main(int argc, char *argv[]) set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, 500); /* 2 Hz */ set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 500); + /* 2 Hz */ + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_GPS_RAW, 500); } else { /* very low baud rate, limit to 1 Hz / 1000 ms */ -- cgit v1.2.3 From 30f028908a69db058c05b9af7e31c8c52c3bc339 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 4 Feb 2013 16:15:48 +0100 Subject: Fixed typo --- apps/mavlink/mavlink.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/mavlink/mavlink.c b/apps/mavlink/mavlink.c index 09abcf269..b958d5f96 100644 --- a/apps/mavlink/mavlink.c +++ b/apps/mavlink/mavlink.c @@ -626,7 +626,7 @@ int mavlink_thread_main(int argc, char *argv[]) set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_NAMED_VALUE_FLOAT, 10); set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, 50); /* 10 Hz */ - set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_GPS_RAW, 100); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_GPS_RAW_INT, 100); /* 10 Hz */ set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 100); @@ -639,7 +639,7 @@ int mavlink_thread_main(int argc, char *argv[]) /* 5 Hz / 200 ms */ set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_SERVO_OUTPUT_RAW, 200); /* 5 Hz / 200 ms */ - set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_GPS_RAW, 200); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_GPS_RAW_INT, 200); /* 2 Hz */ set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 500); @@ -656,7 +656,7 @@ int mavlink_thread_main(int argc, char *argv[]) /* 2 Hz */ set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_MANUAL_CONTROL, 500); /* 2 Hz */ - set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_GPS_RAW, 500); + set_mavlink_interval_limit(&mavlink_subs, MAVLINK_MSG_ID_GPS_RAW_INT, 500); } else { /* very low baud rate, limit to 1 Hz / 1000 ms */ -- cgit v1.2.3 From 13ec0675703ecc9c7bccb22ef3cd049888dd1abb Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 4 Feb 2013 17:55:58 +0100 Subject: Minor quick cleanups --- apps/drivers/gps/gps.cpp | 108 ++++++++++++++++++++++++++++++++--------------- apps/drivers/gps/ubx.cpp | 28 ++++++------ 2 files changed, 89 insertions(+), 47 deletions(-) diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 9fd679240..6f7310cc5 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -107,30 +107,29 @@ public: private: - int _task_should_exit; - int _serial_fd; ///< serial interface to GPS + int _task_should_exit; + int _serial_fd; ///< serial interface to GPS unsigned _baudrate; unsigned _baudrates_to_try[NUMBER_OF_BAUDRATES]; uint8_t _send_buffer[SEND_BUFFER_LENGTH]; - perf_counter_t _sample_perf; - perf_counter_t _comms_errors; - perf_counter_t _buffer_overflows; - volatile int _task; ///< worker task + perf_counter_t _sample_perf; + perf_counter_t _comms_errors; + perf_counter_t _buffer_overflows; + volatile int _task; ///< worker task bool _response_received; bool _config_needed; bool _baudrate_changed; bool _mode_changed; bool _healthy; - gps_driver_mode_t _mode; + gps_driver_mode_t _mode; unsigned _messages_received; + float _rate; ///< position update rate - GPS_Helper *_Helper; ///< Class for either UBX, MTK or NMEA helper + GPS_Helper *_Helper; ///< class for either UBX, MTK or NMEA helper - struct vehicle_gps_position_s _report; - orb_advert_t _report_pub; - - orb_advert_t _gps_topic; + struct vehicle_gps_position_s _report; ///< the current GPS report + orb_advert_t _report_pub; ///< the publication topic, only valid on first valid GPS module message void recv(); @@ -140,16 +139,19 @@ private: /** - * worker task + * Worker task. */ - void task_main(void); + void task_main(void); - int set_baudrate(unsigned baud); + /** + * Set the module baud rate + */ + int set_baudrate(unsigned baud); /** * Send a reset command to the GPS */ - void cmd_reset(); + void cmd_reset(); }; @@ -177,13 +179,15 @@ GPS::GPS() : _healthy(false), _mode(GPS_DRIVER_MODE_UBX), _messages_received(0), - _Helper(nullptr) + _Helper(nullptr), + _rate(0.0f), + _report_pub(-1) { /* we need this potentially before it could be set in task_main */ g_dev = this; + memset(&_report, 0, sizeof(_report)); _debug_enabled = true; - debug("[gps driver] instantiated"); } GPS::~GPS() @@ -213,16 +217,13 @@ GPS::init() goto out; /* start the IO interface task */ - _task = task_create("gps", SCHED_PRIORITY_SLOW_DRIVER, 4096, (main_t)&GPS::task_main_trampoline, nullptr); + _task = task_create("gps", SCHED_PRIORITY_SLOW_DRIVER, 2048, (main_t)&GPS::task_main_trampoline, nullptr); if (_task < 0) { - debug("task start failed: %d", errno); + warnx("task start failed: %d", errno); return -errno; } -// if (_gps_topic < 0) -// debug("failed to create GPS object"); - ret = OK; out: return ret; @@ -231,6 +232,8 @@ out: int GPS::ioctl(struct file *filp, int cmd, unsigned long arg) { + lock(); + int ret = OK; switch (cmd) { @@ -263,6 +266,8 @@ GPS::ioctl(struct file *filp, int cmd, unsigned long arg) break; } + unlock(); + return ret; } @@ -298,10 +303,6 @@ GPS::task_main() { log("starting"); - _report_pub = orb_advertise(ORB_ID(vehicle_gps_position), &_report); - - memset(&_report, 0, sizeof(_report)); - /* open the serial port */ _serial_fd = ::open("/dev/ttyS3", O_RDWR); @@ -311,7 +312,9 @@ GPS::task_main() if (_serial_fd < 0) { log("failed to open serial port: %d", errno); - goto out; + /* tell the dtor that we are exiting, set error code */ + _task = -1; + _exit(1); } /* poll descriptor */ @@ -329,6 +332,9 @@ GPS::task_main() time_before_configuration = hrt_absolute_time(); + uint64_t last_rate_measurement = hrt_absolute_time(); + unsigned last_rate_count = 0; + /* loop handling received serial bytes */ while (!_task_should_exit) { @@ -369,9 +375,9 @@ GPS::task_main() if (_config_needed) { poll_timeout = 50; } else { - poll_timeout = 250; + poll_timeout = 400; } - /* sleep waiting for data, but no more than 1000ms */ + /* sleep waiting for data, but no more than the poll timeout */ unlock(); int ret = ::poll(fds, sizeof(fds) / sizeof(fds[0]), poll_timeout); lock(); @@ -386,7 +392,7 @@ GPS::task_main() config(); if (_config_needed == false) { _config_needed = true; - debug("Lost GPS module"); + warnx("lost GPS module"); } } else if (ret > 0) { /* if we have new data from GPS, go handle it */ @@ -411,8 +417,22 @@ GPS::task_main() debug("Found GPS module"); } - orb_publish(ORB_ID(vehicle_gps_position), _report_pub, &_report); + /* opportunistic publishing - else invalid data would end up on the bus */ + if (_report_pub > 0) { + orb_publish(ORB_ID(vehicle_gps_position), _report_pub, &_report); + } else { + _report_pub = orb_advertise(ORB_ID(vehicle_gps_position), &_report); + } + _messages_received = 0; + last_rate_count++; + + /* measure update rate every 5 seconds */ + if (hrt_absolute_time() - last_rate_measurement > 5000000) { + _rate = last_rate_count / (float)((hrt_absolute_time() - last_rate_measurement)) / 1000000.0f; + last_rate_measurement = hrt_absolute_time(); + last_rate_count = 0; + } } } } @@ -484,7 +504,29 @@ GPS::cmd_reset() void GPS::print_info() { - + switch (_mode) { + case GPS_DRIVER_MODE_UBX: + warnx("protocol: UBX"); + break; + case GPS_DRIVER_MODE_MTK19: + warnx("protocol: MTK 1.9"); + break; + case GPS_DRIVER_MODE_MTK16: + warnx("protocol: MTK 1.6"); + break; + case GPS_DRIVER_MODE_NMEA: + warnx("protocol: NMEA"); + break; + default: + break; + } + warnx("baudrate: %d, status: %s", _baudrate, (_config_needed) ? "NOT OK" : "OK"); + if (_report.timestamp != 0) { + warnx("position lock: %dD, last update %d seconds ago", (int)_report.fix_type, + int((hrt_absolute_time() - _report.timestamp) / 1000000)); + warnx("lat: %d, lon: %d, alt: %d", _report.lat, _report.lon, _report.alt); + warnx("update rate: %6.2f Hz", (double)_rate); + } } /** diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp index 981b023e5..7e95514dd 100644 --- a/apps/drivers/gps/ubx.cpp +++ b/apps/drivers/gps/ubx.cpp @@ -371,7 +371,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) } break; default: //should not happen because we set the class - printf("UBX Error, we set a class that we don't know\n"); + warnx("UBX Error, we set a class that we don't know\n"); decodeInit(); break; } @@ -410,7 +410,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) _new_nav_posllh = true; } else { - printf("[gps] NAV_POSLLH: checksum invalid\n"); + warnx("NAV_POSLLH: checksum invalid\n"); } // Reset state machine to decode next packet @@ -437,7 +437,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) _new_nav_sol = true; } else { - printf("[gps] NAV_SOL: checksum invalid\n"); + warnx("NAV_SOL: checksum invalid\n"); } // Reset state machine to decode next packet @@ -463,7 +463,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) _new_nav_dop = true; } else { - printf("[gps] NAV_DOP: checksum invalid\n"); + warnx("NAV_DOP: checksum invalid\n"); } // Reset state machine to decode next packet @@ -624,7 +624,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) _new_nav_velned = true; } else { - printf("[gps] NAV_VELNED: checksum invalid\n"); + warnx("NAV_VELNED: checksum invalid\n"); } // Reset state machine to decode next packet @@ -651,7 +651,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) // ret = 1; // // } else { -// printf("[gps] RXM_SVSI: checksum invalid\n"); +// warnx("RXM_SVSI: checksum invalid\n"); // } // // // Reset state machine to decode next packet @@ -719,7 +719,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) break; } } else { - printf("[gps] ACK_ACK: checksum invalid\n"); + warnx("ACK_ACK: checksum invalid\n"); } // Reset state machine to decode next packet @@ -736,11 +736,11 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) //Check if checksum is valid if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - printf("[gps] the ubx gps returned: not acknowledged\n"); + warnx("the ubx gps returned: not acknowledged\n"); ret = 1; } else { - printf("[gps] ACK_NAK: checksum invalid\n"); + warnx("ACK_NAK: checksum invalid\n"); } // Reset state machine to decode next packet @@ -768,16 +768,16 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) break; } - /* return 1 when all needed messages have arrived */ + /* return 1 when position updates and the remaining packets updated at least once */ if(_new_nav_posllh &&_new_nav_timeutc && _new_nav_dop && _new_nav_sol && _new_nav_velned) { gps_position->timestamp = hrt_absolute_time(); ret = 1; _new_nav_posllh = false; - _new_nav_timeutc = false; - _new_nav_dop = false; - _new_nav_sol = false; - _new_nav_velned = false; + // _new_nav_timeutc = false; + // _new_nav_dop = false; + // _new_nav_sol = false; + // _new_nav_velned = false; } return ret; -- cgit v1.2.3 From d4bd7225baa8c46e6a93dcd063f66ce53fe88e69 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 4 Feb 2013 18:00:10 +0100 Subject: More cleanup --- apps/drivers/gps/gps.cpp | 3 ++- apps/drivers/gps/ubx.cpp | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 6f7310cc5..bd77e8969 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -341,7 +341,8 @@ GPS::task_main() if (_mode_changed) { if (_Helper != nullptr) { delete(_Helper); - _Helper = nullptr; // XXX is this needed? + /* set to zero to ensure parser is not used while not instantiated */ + _Helper = nullptr; } switch (_mode) { diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp index 7e95514dd..fe4758d8c 100644 --- a/apps/drivers/gps/ubx.cpp +++ b/apps/drivers/gps/ubx.cpp @@ -371,7 +371,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) } break; default: //should not happen because we set the class - warnx("UBX Error, we set a class that we don't know\n"); + warnx("UBX Error, we set a class that we don't know"); decodeInit(); break; } @@ -410,7 +410,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) _new_nav_posllh = true; } else { - warnx("NAV_POSLLH: checksum invalid\n"); + warnx("NAV_POSLLH: checksum invalid"); } // Reset state machine to decode next packet @@ -437,7 +437,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) _new_nav_sol = true; } else { - warnx("NAV_SOL: checksum invalid\n"); + warnx("NAV_SOL: checksum invalid"); } // Reset state machine to decode next packet @@ -463,7 +463,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) _new_nav_dop = true; } else { - warnx("NAV_DOP: checksum invalid\n"); + warnx("NAV_DOP: checksum invalid"); } // Reset state machine to decode next packet @@ -499,7 +499,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) _new_nav_timeutc = true; } else { - printf("\t[gps] NAV_TIMEUTC: checksum invalid\n"); + warnx("NAV_TIMEUTC: checksum invalid"); } // Reset state machine to decode next packet @@ -593,7 +593,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) // as this message arrives only with 1Hz and is not essential, we don't take it into account for the report } else { - printf("\t[gps] NAV_SVINFO: checksum invalid\n"); + warnx("NAV_SVINFO: checksum invalid"); } // Reset state machine to decode next packet @@ -624,7 +624,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) _new_nav_velned = true; } else { - warnx("NAV_VELNED: checksum invalid\n"); + warnx("NAV_VELNED: checksum invalid"); } // Reset state machine to decode next packet @@ -719,7 +719,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) break; } } else { - warnx("ACK_ACK: checksum invalid\n"); + warnx("ACK_ACK: checksum invalid"); } // Reset state machine to decode next packet @@ -736,7 +736,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) //Check if checksum is valid if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - warnx("the ubx gps returned: not acknowledged\n"); + warnx("UBX: NO ACK"); ret = 1; } else { @@ -751,7 +751,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) } default: //we don't know the message - printf("Unknown message received: %d-%d\n",_message_class,_message_id); + warnx("UBX: Unknown message received: %d-%d\n",_message_class,_message_id); decodeInit(); break; @@ -760,7 +760,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) if (_rx_count < RECV_BUFFER_SIZE) { _rx_count++; } else { - printf("Buffer full"); + warnx("buffer overflow"); decodeInit(); } break; -- cgit v1.2.3 From cb0fd834ae15c45cf6993f8c9eea9c99b2b153dd Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 4 Feb 2013 18:14:55 +0100 Subject: Minor polishing, fixed rate and last measurement indication --- apps/drivers/gps/gps.cpp | 6 +++--- apps/drivers/gps/ubx.cpp | 6 ------ apps/mavlink/orb_listener.c | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index bd77e8969..49b94fc2e 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -430,7 +430,7 @@ GPS::task_main() /* measure update rate every 5 seconds */ if (hrt_absolute_time() - last_rate_measurement > 5000000) { - _rate = last_rate_count / (float)((hrt_absolute_time() - last_rate_measurement)) / 1000000.0f; + _rate = last_rate_count / ((float)((hrt_absolute_time() - last_rate_measurement)) / 1000000.0f); last_rate_measurement = hrt_absolute_time(); last_rate_count = 0; } @@ -523,8 +523,8 @@ GPS::print_info() } warnx("baudrate: %d, status: %s", _baudrate, (_config_needed) ? "NOT OK" : "OK"); if (_report.timestamp != 0) { - warnx("position lock: %dD, last update %d seconds ago", (int)_report.fix_type, - int((hrt_absolute_time() - _report.timestamp) / 1000000)); + warnx("position lock: %dD, last update %4.2f seconds ago", (int)_report.fix_type, + ((float)(hrt_absolute_time() - _report.timestamp) / 1000000.0f)); warnx("lat: %d, lon: %d, alt: %d", _report.lat, _report.lon, _report.alt); warnx("update rate: %6.2f Hz", (double)_rate); } diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp index fe4758d8c..1105e0da4 100644 --- a/apps/drivers/gps/ubx.cpp +++ b/apps/drivers/gps/ubx.cpp @@ -429,7 +429,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) gps_position->fix_type = packet->gpsFix; - gps_position->timestamp = hrt_absolute_time(); gps_position->counter++; gps_position->s_variance = packet->sAcc; gps_position->p_variance = packet->pAcc; @@ -457,7 +456,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) gps_position->eph = packet->hDOP; gps_position->epv = packet->vDOP; - gps_position->timestamp = hrt_absolute_time(); gps_position->counter++; _new_nav_dop = true; @@ -493,7 +491,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) gps_position->time_gps_usec = (uint64_t)epoch * 1000000; //TODO: test this gps_position->time_gps_usec += (uint64_t)(packet->time_nanoseconds * 1e-3f); - gps_position->timestamp = hrt_absolute_time(); gps_position->counter++; _new_nav_timeutc = true; @@ -587,7 +584,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) } gps_position->satellites_visible = satellites_used++; // visible ~= used but we are interested in the used ones - gps_position->timestamp = hrt_absolute_time(); gps_position->counter++; // as this message arrives only with 1Hz and is not essential, we don't take it into account for the report @@ -617,7 +613,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) gps_position->vel_ned_valid = true; gps_position->cog = (uint16_t)((float)(packet->heading) * 1e-3f); - gps_position->timestamp = hrt_absolute_time(); gps_position->counter++; @@ -645,7 +640,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) // if (_rx_ck_a == _rx_buffer[_rx_count - 1] && _rx_ck_b == _rx_buffer[_rx_count]) { // // gps_position->satellites_visible = packet->numVis; -// gps_position->timestamp = hrt_absolute_time(); // gps_position->counter++; // _last_message_timestamps[RXM_SVSI - 1] = hrt_absolute_time(); // ret = 1; diff --git a/apps/mavlink/orb_listener.c b/apps/mavlink/orb_listener.c index ec5149745..18da70f61 100644 --- a/apps/mavlink/orb_listener.c +++ b/apps/mavlink/orb_listener.c @@ -698,7 +698,7 @@ uorb_receive_start(void) /* --- GPS VALUE --- */ mavlink_subs.gps_sub = orb_subscribe(ORB_ID(vehicle_gps_position)); - orb_set_interval(mavlink_subs.gps_sub, 1000); /* 1Hz updates */ + orb_set_interval(mavlink_subs.gps_sub, 200); /* 5Hz updates */ /* --- HOME POSITION --- */ mavlink_subs.home_sub = orb_subscribe(ORB_ID(home_position)); -- cgit v1.2.3 From 039d394c207830a2c9c3a22e03302c867bd57af6 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Mon, 4 Feb 2013 16:27:01 -0800 Subject: Merged with newer, cleaned up code, fixed the checksum error --- apps/drivers/drv_gps.h | 2 - apps/drivers/gps/gps.cpp | 130 +++++++++++++++++++++++------------------- apps/drivers/gps/gps_helper.h | 5 +- apps/drivers/gps/ubx.cpp | 107 +++++++++++++++++----------------- apps/drivers/gps/ubx.h | 114 +++++++++++++++++++----------------- 5 files changed, 191 insertions(+), 167 deletions(-) diff --git a/apps/drivers/drv_gps.h b/apps/drivers/drv_gps.h index 89fc54b0d..1ae27ed2f 100644 --- a/apps/drivers/drv_gps.h +++ b/apps/drivers/drv_gps.h @@ -54,8 +54,6 @@ typedef enum { } gps_driver_mode_t; - - /* * ObjDev tag for GPS data. */ diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 49b94fc2e..450b3091b 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -33,7 +33,7 @@ /** * @file gps.cpp - * Driver for the GPS on UART6 + * Driver for the GPS on a serial port */ #include @@ -107,46 +107,41 @@ public: private: - int _task_should_exit; - int _serial_fd; ///< serial interface to GPS - unsigned _baudrate; - unsigned _baudrates_to_try[NUMBER_OF_BAUDRATES]; - uint8_t _send_buffer[SEND_BUFFER_LENGTH]; - perf_counter_t _sample_perf; - perf_counter_t _comms_errors; - perf_counter_t _buffer_overflows; - volatile int _task; ///< worker task + bool _task_should_exit; ///< flag to make the main worker task exit + int _serial_fd; ///< serial interface to GPS + unsigned _baudrate; ///< current baudrate + unsigned _baudrates_to_try[NUMBER_OF_BAUDRATES]; ///< try different baudrates that GPS could be set to + volatile int _task; ///< worker task + bool _config_needed; ///< flag to signal that configuration of GPS is needed + bool _baudrate_changed; ///< flag to signal that the baudrate with the GPS has changed + bool _mode_changed; ///< flag that the GPS mode has changed + gps_driver_mode_t _mode; ///< current mode + GPS_Helper *_Helper; ///< Class for either UBX, MTK or NMEA helper + struct vehicle_gps_position_s _report; ///< uORB topic for gps position + orb_advert_t _report_pub; ///< uORB pub for gps position + float _rate; ///< position update rate - bool _response_received; - bool _config_needed; - bool _baudrate_changed; - bool _mode_changed; - bool _healthy; - gps_driver_mode_t _mode; - unsigned _messages_received; - float _rate; ///< position update rate - - GPS_Helper *_Helper; ///< class for either UBX, MTK or NMEA helper - - struct vehicle_gps_position_s _report; ///< the current GPS report - orb_advert_t _report_pub; ///< the publication topic, only valid on first valid GPS module message - - void recv(); + /** + * Try to configure the GPS, handle outgoing communication to the GPS + */ void config(); + /** + * Trampoline to the worker task + */ static void task_main_trampoline(void *arg); /** - * Worker task. + * Worker task: main GPS thread that configures the GPS and parses incoming data, always running */ void task_main(void); /** - * Set the module baud rate + * Set the baudrate of the UART to the GPS */ - int set_baudrate(unsigned baud); + int set_baudrate(unsigned baud); /** * Send a reset command to the GPS @@ -176,12 +171,10 @@ GPS::GPS() : _config_needed(true), _baudrate_changed(false), _mode_changed(true), - _healthy(false), _mode(GPS_DRIVER_MODE_UBX), - _messages_received(0), _Helper(nullptr), - _rate(0.0f), - _report_pub(-1) + _report_pub(-1), + _rate(0.0f) { /* we need this potentially before it could be set in task_main */ g_dev = this; @@ -216,7 +209,7 @@ GPS::init() if (CDev::init() != OK) goto out; - /* start the IO interface task */ + /* start the GPS driver worker task */ _task = task_create("gps", SCHED_PRIORITY_SLOW_DRIVER, 2048, (main_t)&GPS::task_main_trampoline, nullptr); if (_task < 0) { @@ -275,17 +268,22 @@ void GPS::config() { int length = 0; + uint8_t send_buffer[SEND_BUFFER_LENGTH]; - _Helper->configure(_config_needed, _baudrate_changed, _baudrate, _send_buffer, length, SEND_BUFFER_LENGTH); + _Helper->configure(_config_needed, _baudrate_changed, _baudrate, send_buffer, length, SEND_BUFFER_LENGTH); - /* the message needs to be sent at the old baudrate */ + /* The config message is sent sent at the old baudrate */ if (length > 0) { - if (length != ::write(_serial_fd, _send_buffer, length)) { + + if (length != ::write(_serial_fd, send_buffer, length)) { debug("write config failed"); return; } } + /* Sometimes the baudrate needs to be changed, for instance UBX with factory settings are changed + * from 9600 to 38400 + */ if (_baudrate_changed) { set_baudrate(_baudrate); _baudrate_changed = false; @@ -304,11 +302,10 @@ GPS::task_main() log("starting"); /* open the serial port */ - _serial_fd = ::open("/dev/ttyS3", O_RDWR); + _serial_fd = ::open("/dev/ttyS3", O_RDWR); //TODO make the device dynamic depending on startup parameters - uint8_t buf[256]; - int baud_i = 0; - uint64_t time_before_configuration; + /* buffer to read from the serial port */ + uint8_t buf[32]; if (_serial_fd < 0) { log("failed to open serial port: %d", errno); @@ -326,16 +323,16 @@ GPS::task_main() /* lock against the ioctl handler */ lock(); - + unsigned baud_i = 0; _baudrate = _baudrates_to_try[baud_i]; set_baudrate(_baudrate); - time_before_configuration = hrt_absolute_time(); + uint64_t time_before_configuration = hrt_absolute_time(); uint64_t last_rate_measurement = hrt_absolute_time(); unsigned last_rate_count = 0; - /* loop handling received serial bytes */ + /* loop handling received serial bytes and also configuring in between */ while (!_task_should_exit) { if (_mode_changed) { @@ -364,14 +361,17 @@ GPS::task_main() _mode_changed = false; } + /* If a configuration does not finish in the config timeout, change the baudrate */ if (_config_needed && time_before_configuration + CONFIG_TIMEOUT < hrt_absolute_time()) { baud_i = (baud_i+1)%NUMBER_OF_BAUDRATES; _baudrate = _baudrates_to_try[baud_i]; set_baudrate(_baudrate); + _Helper->reset(); time_before_configuration = hrt_absolute_time(); } - + /* during configuration, the timeout should be small, so that we can send config messages in between parsing, + * but during normal operation, it should never timeout because updates should arrive with 5Hz */ int poll_timeout; if (_config_needed) { poll_timeout = 50; @@ -409,11 +409,21 @@ GPS::task_main() /* pass received bytes to the packet decoder */ int j; + int ret_parse = 0; for (j = 0; j < count; j++) { - _messages_received += _Helper->parse(buf[j], &_report); + ret_parse += _Helper->parse(buf[j], &_report); } - if (_messages_received > 0) { - if (_config_needed == true) { + + if (ret_parse < 0) { + /* This means something went wrong in the parser, let's reconfigure */ + if (!_config_needed) { + _config_needed = true; + debug("Lost GPS module"); + } + config(); + } else if (ret_parse > 0) { + /* Looks like we got a valid position update, stop configuring and publish it */ + if (_config_needed) { _config_needed = false; debug("Found GPS module"); } @@ -424,8 +434,6 @@ GPS::task_main() } else { _report_pub = orb_advertise(ORB_ID(vehicle_gps_position), &_report); } - - _messages_received = 0; last_rate_count++; /* measure update rate every 5 seconds */ @@ -435,10 +443,10 @@ GPS::task_main() last_rate_count = 0; } } + /* else if ret_parse == 0: just keep parsing */ } } } -out: debug("exiting"); ::close(_serial_fd); @@ -469,7 +477,6 @@ GPS::set_baudrate(unsigned baud) warnx("ERROR: Unsupported baudrate: %d\n", baud); return -EINVAL; } - struct termios uart_config; int termios_state; @@ -482,24 +489,26 @@ GPS::set_baudrate(unsigned baud) uart_config.c_cflag &= ~(CSTOPB | PARENB); /* set baud rate */ - if (cfsetispeed(&uart_config, speed) < 0 || cfsetospeed(&uart_config, speed) < 0) { - warnx("ERROR setting config: %d (cfsetispeed, cfsetospeed)\n", termios_state); + if ((termios_state = cfsetispeed(&uart_config, speed)) < 0) { + warnx("ERROR setting config: %d (cfsetispeed)\n", termios_state); + return -1; + } + if ((termios_state = cfsetospeed(&uart_config, speed)) < 0) { + warnx("ERROR setting config: %d (cfsetospeed)\n", termios_state); return -1; } - - if ((termios_state = tcsetattr(_serial_fd, TCSANOW, &uart_config)) < 0) { warnx("ERROR setting baudrate (tcsetattr)\n"); return -1; } - /* XXX if resetting the parser here, ensure it does exist (check for null pointer) */ + return 0; } void GPS::cmd_reset() { - _healthy = false; + _config_needed = true; } void @@ -524,10 +533,12 @@ GPS::print_info() warnx("baudrate: %d, status: %s", _baudrate, (_config_needed) ? "NOT OK" : "OK"); if (_report.timestamp != 0) { warnx("position lock: %dD, last update %4.2f seconds ago", (int)_report.fix_type, - ((float)(hrt_absolute_time() - _report.timestamp) / 1000000.0f)); + (double)((float)(hrt_absolute_time() - _report.timestamp) / 1000000.0f)); warnx("lat: %d, lon: %d, alt: %d", _report.lat, _report.lon, _report.alt); warnx("update rate: %6.2f Hz", (double)_rate); } + + usleep(100000); } /** @@ -583,6 +594,9 @@ fail: errx(1, "driver start failed"); } +/** + * Stop the driver. + */ void stop() { diff --git a/apps/drivers/gps/gps_helper.h b/apps/drivers/gps/gps_helper.h index baacf7cb4..8a6b0148b 100644 --- a/apps/drivers/gps/gps_helper.h +++ b/apps/drivers/gps/gps_helper.h @@ -40,8 +40,9 @@ class GPS_Helper { public: - virtual void configure(bool&, bool&, unsigned&, uint8_t*, int&, const unsigned) = 0; - virtual int parse(uint8_t, struct vehicle_gps_position_s*) = 0; + virtual void reset() = 0; + virtual void configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, uint8_t *buffer, int &length, const unsigned max_length) = 0; + virtual int parse(uint8_t b, struct vehicle_gps_position_s *gps_position) = 0; }; #endif /* GPS_HELPER_H */ diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp index 1105e0da4..66a891da4 100644 --- a/apps/drivers/gps/ubx.cpp +++ b/apps/drivers/gps/ubx.cpp @@ -48,36 +48,41 @@ UBX::UBX() : -_waited(0), _config_state(UBX_CONFIG_STATE_PRT), +_waiting_for_ack(false), _new_nav_posllh(false), _new_nav_timeutc(false), _new_nav_dop(false), _new_nav_sol(false), _new_nav_velned(false) { - decodeInit(); - _waiting_for_ack = false; + reset(); } UBX::~UBX() { } +void +UBX::reset() +{ + decodeInit(); + _config_state = UBX_CONFIG_STATE_PRT; + _waiting_for_ack = false; +} + void UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, uint8_t *buffer, int &length, const unsigned max_length) { - /* make sure the buffer to write the message is long enough */ + /* make sure the buffer, where the message is written to, is long enough */ assert(sizeof(type_gps_bin_cfg_prt_packet_t)+2 <= max_length); - /* try again after 10 times */ - if (_waited > 10) { - _waiting_for_ack = false; - } - + /* Only send a new config message when we got the ACK of the last one, + * otherwise we might not configure all the messages because the ACK comes from an older/previos CFD command + * reason being that the ACK only includes CFG-MSG but not to which NAV MSG it belongs. + */ if (!_waiting_for_ack) { _waiting_for_ack = true; - _waited = 0; if (_config_state == UBX_CONFIG_STATE_CONFIGURED) { config_needed = false; length = 0; @@ -85,10 +90,15 @@ UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, _waiting_for_ack = false; return; } else if (_config_state == UBX_CONFIG_STATE_PRT) { - /* send a CFT-PRT message to define set ubx protocol and leave the baudrate as is, we just want an ACK-ACK from this */ + + /* Send a CFG-PRT message to set the UBX protocol for in and out + * and leave the baudrate as it is, we just want an ACK-ACK from this + */ type_gps_bin_cfg_prt_packet_t cfg_prt_packet; + /* Set everything else of the packet to 0, otherwise the module wont accept it */ memset(&cfg_prt_packet, 0, sizeof(cfg_prt_packet)); + /* Define the package contents, don't change the baudrate */ cfg_prt_packet.clsID = UBX_CLASS_CFG; cfg_prt_packet.msgID = UBX_MESSAGE_CFG_PRT; cfg_prt_packet.length = UBX_CFG_PRT_LENGTH; @@ -98,18 +108,20 @@ UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, cfg_prt_packet.inProtoMask = UBX_CFG_PRT_PAYLOAD_INPROTOMASK; cfg_prt_packet.outProtoMask = UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK; + /* Calculate the checksum now */ addChecksumToMessage((uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); + /* Start with the two sync bytes */ buffer[0] = UBX_SYNC1; buffer[1] = UBX_SYNC2; + /* Copy it to the buffer that will be written back in the main gps driver */ memcpy(&(buffer[2]), &cfg_prt_packet, sizeof(cfg_prt_packet)); + /* Set the length of the packet (plus the 2 sync bytes) */ length = sizeof(cfg_prt_packet)+2; } else if (_config_state == UBX_CONFIG_STATE_PRT_NEW_BAUDRATE) { -// printf("Send change of baudrate now\n"); - - /* send a CFT-PRT message to define set ubx protocol and and baudrate, now let's try to switch the baudrate */ + /* Send a CFG-PRT message again, this time change the baudrate */ type_gps_bin_cfg_prt_packet_t cfg_prt_packet; memset(&cfg_prt_packet, 0, sizeof(cfg_prt_packet)); @@ -129,18 +141,15 @@ UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, memcpy(&(buffer[2]), &cfg_prt_packet, sizeof(cfg_prt_packet)); length = sizeof(cfg_prt_packet)+2; - /* detection when the baudrate has been changed in the first step */ + /* If the new baudrate will be different from the current one, we should report that back to the driver */ if (UBX_CFG_PRT_PAYLOAD_BAUDRATE != baudrate) { - /* set a flag and exit */ baudrate=UBX_CFG_PRT_PAYLOAD_BAUDRATE; baudrate_changed = true; - _config_state = UBX_CONFIG_STATE_RATE; - _waiting_for_ack = false; - return; + /* Don't wait for an ACK, we're switching baudrate and we might never get, + * after that, start fresh */ + reset(); } - - } else if (_config_state == UBX_CONFIG_STATE_RATE) { /* send a CFT-RATE message to define update rate */ @@ -162,9 +171,9 @@ UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, length = sizeof(cfg_rate_packet)+2; } else if (_config_state == UBX_CONFIG_STATE_NAV5) { - /* send a NAV5 message to set the options for the internal estimator */ + /* send a NAV5 message to set the options for the internal filter */ type_gps_bin_cfg_nav5_packet_t cfg_nav5_packet; - memset(&cfg_nav5_packet, 0, sizeof(cfg_nav5_packet)); //set everything to 0 + memset(&cfg_nav5_packet, 0, sizeof(cfg_nav5_packet)); cfg_nav5_packet.clsID = UBX_CLASS_CFG; cfg_nav5_packet.msgID = UBX_MESSAGE_CFG_NAV5; @@ -181,15 +190,16 @@ UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, length = sizeof(cfg_nav5_packet)+2; } else { - /* catch the remaining config states here */ + /* Catch the remaining config states here, they all need the same packet type */ type_gps_bin_cfg_msg_packet_t cfg_msg_packet; - memset(&cfg_msg_packet, 0, sizeof(cfg_msg_packet)); //set everything to 0 + memset(&cfg_msg_packet, 0, sizeof(cfg_msg_packet)); cfg_msg_packet.clsID = UBX_CLASS_CFG; cfg_msg_packet.msgID = UBX_MESSAGE_CFG_MSG; cfg_msg_packet.length = UBX_CFG_MSG_LENGTH; - cfg_msg_packet.rate[1] = UBX_CFG_MSG_PAYLOAD_RATE1; + /* Choose fast 5Hz rate for all messages except SVINFO which is big and not important */ + cfg_msg_packet.rate[1] = UBX_CFG_MSG_PAYLOAD_RATE1_5HZ; switch (_config_state) { case UBX_CONFIG_STATE_MSG_NAV_POSLLH: @@ -207,7 +217,8 @@ UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, case UBX_CONFIG_STATE_MSG_NAV_SVINFO: cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_SVINFO; - cfg_msg_packet.rate[1] = 5; + /* For satelites info 1Hz is enough */ + cfg_msg_packet.rate[1] = UBX_CFG_MSG_PAYLOAD_RATE1_1HZ; break; case UBX_CONFIG_STATE_MSG_NAV_SOL: cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; @@ -232,16 +243,14 @@ UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, memcpy(&(buffer[2]), &cfg_msg_packet, sizeof(cfg_msg_packet)); length = sizeof(cfg_msg_packet)+2; } - } else { - _waited++; } } int -UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) +UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) { + /* if no error happens and no new report is ready yet, ret will stay 0 */ int ret = 0; - //printf("Received char: %c\n", b); switch (_decode_state) { /* First, look for sync1 */ @@ -373,6 +382,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) default: //should not happen because we set the class warnx("UBX Error, we set a class that we don't know"); decodeInit(); + ret = -1; break; } break; @@ -415,8 +425,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) // Reset state machine to decode next packet decodeInit(); - return ret; - break; } @@ -441,8 +449,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) // Reset state machine to decode next packet decodeInit(); - return ret; - break; } @@ -466,8 +472,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) // Reset state machine to decode next packet decodeInit(); - return ret; - break; } @@ -501,8 +505,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) // Reset state machine to decode next packet decodeInit(); - return ret; - break; } @@ -594,8 +596,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) // Reset state machine to decode next packet decodeInit(); - return ret; - break; } @@ -615,7 +615,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) gps_position->counter++; - _new_nav_velned = true; } else { @@ -624,8 +623,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) // Reset state machine to decode next packet decodeInit(); - return ret; - break; } @@ -718,7 +715,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) // Reset state machine to decode next packet decodeInit(); - return ret; break; } @@ -730,7 +726,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) //Check if checksum is valid if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - warnx("UBX: NO ACK"); + warnx("UBX: Received: Not Acknowledged"); ret = 1; } else { @@ -751,11 +747,12 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) break; } } // end if _rx_count high enough - if (_rx_count < RECV_BUFFER_SIZE) { + else if (_rx_count < RECV_BUFFER_SIZE) { _rx_count++; } else { - warnx("buffer overflow"); + warnx("buffer full, restarting"); decodeInit(); + ret = -1; } break; default: @@ -765,13 +762,16 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s* gps_position) /* return 1 when position updates and the remaining packets updated at least once */ if(_new_nav_posllh &&_new_nav_timeutc && _new_nav_dop && _new_nav_sol && _new_nav_velned) { + /* Add timestamp to finish the report */ gps_position->timestamp = hrt_absolute_time(); - ret = 1; + /* Reset the flags */ _new_nav_posllh = false; - // _new_nav_timeutc = false; - // _new_nav_dop = false; - // _new_nav_sol = false; - // _new_nav_velned = false; + _new_nav_timeutc = false; + _new_nav_dop = false; + _new_nav_sol = false; + _new_nav_velned = false; + + ret = 1; } return ret; @@ -807,6 +807,7 @@ UBX::addChecksumToMessage(uint8_t* message, const unsigned length) ck_a = ck_a + message[i]; ck_b = ck_b + ck_a; } + /* The checksum is written to the last to bytes of a message */ message[length-2] = ck_a; message[length-1] = ck_b; } diff --git a/apps/drivers/gps/ubx.h b/apps/drivers/gps/ubx.h index dff25a518..0cac10f0a 100644 --- a/apps/drivers/gps/ubx.h +++ b/apps/drivers/gps/ubx.h @@ -40,16 +40,17 @@ #include "gps_helper.h" -#define UBX_NO_OF_MESSAGES 7 /**< Read 7 UBX GPS messages */ #define UBX_SYNC1 0xB5 #define UBX_SYNC2 0x62 -//UBX Protocol definitions (this is the subset of the messages that are parsed) +/* ClassIDs (the ones that are used) */ #define UBX_CLASS_NAV 0x01 //#define UBX_CLASS_RXM 0x02 #define UBX_CLASS_ACK 0x05 #define UBX_CLASS_CFG 0x06 + +/* MessageIDs (the ones that are used) */ #define UBX_MESSAGE_NAV_POSLLH 0x02 #define UBX_MESSAGE_NAV_SOL 0x06 #define UBX_MESSAGE_NAV_TIMEUTC 0x21 @@ -65,11 +66,11 @@ #define UBX_MESSAGE_CFG_RATE 0x08 #define UBX_CFG_PRT_LENGTH 20 -#define UBX_CFG_PRT_PAYLOAD_PORTID 0x01 /**< port 1 */ +#define UBX_CFG_PRT_PAYLOAD_PORTID 0x01 /**< UART1 */ #define UBX_CFG_PRT_PAYLOAD_MODE 0x000008D0 /**< 0b0000100011010000: 8N1 */ #define UBX_CFG_PRT_PAYLOAD_BAUDRATE 38400 /**< always choose 38400 as GPS baudrate */ -#define UBX_CFG_PRT_PAYLOAD_INPROTOMASK 0x01 /**< ubx in */ -#define UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK 0x01 /**< ubx out */ +#define UBX_CFG_PRT_PAYLOAD_INPROTOMASK 0x01 /**< UBX in */ +#define UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK 0x01 /**< UBX out */ #define UBX_CFG_RATE_LENGTH 6 #define UBX_CFG_RATE_PAYLOAD_MEASRATE 200 /**< 200ms for 5Hz */ @@ -83,30 +84,30 @@ #define UBX_CFG_NAV5_PAYLOAD_FIXMODE 2 /**< 1: 2D only, 2: 3D only, 3: Auto 2D/3D */ #define UBX_CFG_MSG_LENGTH 8 -#define UBX_CFG_MSG_PAYLOAD_RATE1 0x01 /**< {0x00, 0x01, 0x00, 0x00, 0x00, 0x00} UART1 chosen */ - +#define UBX_CFG_MSG_PAYLOAD_RATE1_5HZ 0x01 /**< {0x00, 0x01, 0x00, 0x00, 0x00, 0x00} the second entry is for UART1 */ +#define UBX_CFG_MSG_PAYLOAD_RATE1_1HZ 0x05 /**< {0x00, 0x05, 0x00, 0x00, 0x00, 0x00} the second entry is for UART1 */ // ************ /** the structures of the binary packets */ #pragma pack(push, 1) typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - int32_t lon; // Longitude * 1e-7, deg - int32_t lat; // Latitude * 1e-7, deg - int32_t height; // Height above Ellipsoid, mm - int32_t height_msl; // Height above mean sea level, mm - uint32_t hAcc; // Horizontal Accuracy Estimate, mm - uint32_t vAcc; // Vertical Accuracy Estimate, mm + uint32_t time_milliseconds; /**< GPS Millisecond Time of Week */ + int32_t lon; /**< Longitude * 1e-7, deg */ + int32_t lat; /**< Latitude * 1e-7, deg */ + int32_t height; /**< Height above Ellipsoid, mm */ + int32_t height_msl; /**< Height above mean sea level, mm */ + uint32_t hAcc; /**< Horizontal Accuracy Estimate, mm */ + uint32_t vAcc; /**< Vertical Accuracy Estimate, mm */ uint8_t ck_a; uint8_t ck_b; } gps_bin_nav_posllh_packet_t; typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - int32_t time_nanoseconds; // Fractional Nanoseconds remainder of rounded ms above, range -500000 .. 500000 - int16_t week; // GPS week (GPS time) - uint8_t gpsFix; //GPS Fix: 0 = No fix, 1 = Dead Reckoning only, 2 = 2D fix, 3 = 3d-fix, 4 = GPS + dead reckoning, 5 = time only fix + uint32_t time_milliseconds; /**< GPS Millisecond Time of Week */ + int32_t time_nanoseconds; /**< Fractional Nanoseconds remainder of rounded ms above, range -500000 .. 500000 */ + int16_t week; /**< GPS week (GPS time) */ + uint8_t gpsFix; /**< GPS Fix: 0 = No fix, 1 = Dead Reckoning only, 2 = 2D fix, 3 = 3d-fix, 4 = GPS + dead reckoning, 5 = time only fix */ uint8_t flags; int32_t ecefX; int32_t ecefY; @@ -125,50 +126,50 @@ typedef struct { } gps_bin_nav_sol_packet_t; typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - uint32_t time_accuracy; //Time Accuracy Estimate, ns - int32_t time_nanoseconds; //Nanoseconds of second, range -1e9 .. 1e9 (UTC) - uint16_t year; //Year, range 1999..2099 (UTC) - uint8_t month; //Month, range 1..12 (UTC) - uint8_t day; //Day of Month, range 1..31 (UTC) - uint8_t hour; //Hour of Day, range 0..23 (UTC) - uint8_t min; //Minute of Hour, range 0..59 (UTC) - uint8_t sec; //Seconds of Minute, range 0..59 (UTC) - uint8_t valid_flag; //Validity Flags (see ubx documentation) + uint32_t time_milliseconds; /**< GPS Millisecond Time of Week */ + uint32_t time_accuracy; /**< Time Accuracy Estimate, ns */ + int32_t time_nanoseconds; /**< Nanoseconds of second, range -1e9 .. 1e9 (UTC) */ + uint16_t year; /**< Year, range 1999..2099 (UTC) */ + uint8_t month; /**< Month, range 1..12 (UTC) */ + uint8_t day; /**< Day of Month, range 1..31 (UTC) */ + uint8_t hour; /**< Hour of Day, range 0..23 (UTC) */ + uint8_t min; /**< Minute of Hour, range 0..59 (UTC) */ + uint8_t sec; /**< Seconds of Minute, range 0..59 (UTC) */ + uint8_t valid_flag; /**< Validity Flags (see ubx documentation) */ uint8_t ck_a; uint8_t ck_b; } gps_bin_nav_timeutc_packet_t; typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - uint16_t gDOP; //Geometric DOP (scaling 0.01) - uint16_t pDOP; //Position DOP (scaling 0.01) - uint16_t tDOP; //Time DOP (scaling 0.01) - uint16_t vDOP; //Vertical DOP (scaling 0.01) - uint16_t hDOP; //Horizontal DOP (scaling 0.01) - uint16_t nDOP; //Northing DOP (scaling 0.01) - uint16_t eDOP; //Easting DOP (scaling 0.01) + uint32_t time_milliseconds; /**< GPS Millisecond Time of Week */ + uint16_t gDOP; /**< Geometric DOP (scaling 0.01) */ + uint16_t pDOP; /**< Position DOP (scaling 0.01) */ + uint16_t tDOP; /**< Time DOP (scaling 0.01) */ + uint16_t vDOP; /**< Vertical DOP (scaling 0.01) */ + uint16_t hDOP; /**< Horizontal DOP (scaling 0.01) */ + uint16_t nDOP; /**< Northing DOP (scaling 0.01) */ + uint16_t eDOP; /**< Easting DOP (scaling 0.01) */ uint8_t ck_a; uint8_t ck_b; } gps_bin_nav_dop_packet_t; typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - uint8_t numCh; //Number of channels + uint32_t time_milliseconds; /**< GPS Millisecond Time of Week */ + uint8_t numCh; /**< Number of channels */ uint8_t globalFlags; uint16_t reserved2; } gps_bin_nav_svinfo_part1_packet_t; typedef struct { - uint8_t chn; //Channel number, 255 for SVs not assigned to a channel - uint8_t svid; //Satellite ID + uint8_t chn; /**< Channel number, 255 for SVs not assigned to a channel */ + uint8_t svid; /**< Satellite ID */ uint8_t flags; uint8_t quality; - uint8_t cno; //Carrier to Noise Ratio (Signal Strength), dbHz - int8_t elev; //Elevation in integer degrees - int16_t azim; //Azimuth in integer degrees - int32_t prRes; //Pseudo range residual in centimetres + uint8_t cno; /**< Carrier to Noise Ratio (Signal Strength), dbHz */ + int8_t elev; /**< Elevation in integer degrees */ + int16_t azim; /**< Azimuth in integer degrees */ + int32_t prRes; /**< Pseudo range residual in centimetres */ } gps_bin_nav_svinfo_part2_packet_t; @@ -192,9 +193,9 @@ typedef struct { } gps_bin_nav_velned_packet_t; //typedef struct { -// int32_t time_milliseconds; // Measurement integer millisecond GPS time of week -// int16_t week; //Measurement GPS week number -// uint8_t numVis; //Number of visible satellites +// int32_t time_milliseconds; /**< Measurement integer millisecond GPS time of week */ +// int16_t week; /**< Measurement GPS week number */ +// uint8_t numVis; /**< Number of visible satellites */ // // //... rest of package is not used in this implementation // @@ -210,7 +211,6 @@ typedef struct { typedef struct { uint8_t clsID; uint8_t msgID; - uint8_t ck_a; uint8_t ck_b; } gps_bin_ack_nak_packet_t; @@ -340,17 +340,27 @@ class UBX : public GPS_Helper public: UBX(); ~UBX(); - - void configure(bool&, bool&, unsigned&, uint8_t*, int&, const unsigned); + void reset(void); + void configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, uint8_t *buffer, int &length, const unsigned max_length); int parse(uint8_t, struct vehicle_gps_position_s*); private: + /** + * Reset the parse state machine for a fresh start + */ void decodeInit(void); + + /** + * While parsing add every byte (except the sync bytes) to the checksum + */ void addByteToChecksum(uint8_t); + + /** + * Add the two checksum bytes to an outgoing message + */ void addChecksumToMessage(uint8_t*, const unsigned); - unsigned _waited; - bool _waiting_for_ack; ubx_config_state_t _config_state; + bool _waiting_for_ack; ubx_decode_state_t _decode_state; uint8_t _rx_buffer[RECV_BUFFER_SIZE]; unsigned _rx_count; -- cgit v1.2.3 From 53c11f87cb9b231cfb9199ce797d983f4e2c6a40 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Mon, 4 Feb 2013 17:57:30 -0800 Subject: Small corrections --- apps/drivers/gps/gps.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 450b3091b..f4fd7b88e 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -110,13 +110,13 @@ private: bool _task_should_exit; ///< flag to make the main worker task exit int _serial_fd; ///< serial interface to GPS unsigned _baudrate; ///< current baudrate - unsigned _baudrates_to_try[NUMBER_OF_BAUDRATES]; ///< try different baudrates that GPS could be set to + const unsigned _baudrates_to_try[NUMBER_OF_BAUDRATES]; ///< try different baudrates that GPS could be set to volatile int _task; ///< worker task bool _config_needed; ///< flag to signal that configuration of GPS is needed bool _baudrate_changed; ///< flag to signal that the baudrate with the GPS has changed bool _mode_changed; ///< flag that the GPS mode has changed gps_driver_mode_t _mode; ///< current mode - GPS_Helper *_Helper; ///< Class for either UBX, MTK or NMEA helper + GPS_Helper *_Helper; ///< Class for a GPS interface struct vehicle_gps_position_s _report; ///< uORB topic for gps position orb_advert_t _report_pub; ///< uORB pub for gps position float _rate; ///< position update rate -- cgit v1.2.3 From 368ba0056f4a4597c13781b6b5fd6e65930f9fee Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 5 Feb 2013 13:47:31 +0100 Subject: Added option to select port name, minor tweaks to status printing, sacrificied 20 bytes for better status / user debuggability --- apps/drivers/gps/gps.cpp | 76 ++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index f4fd7b88e..5905db6b8 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -93,7 +94,7 @@ static const int ERROR = -1; class GPS : public device::CDev { public: - GPS(); + GPS(const char* uart_path); ~GPS(); virtual int init(); @@ -107,19 +108,20 @@ public: private: - bool _task_should_exit; ///< flag to make the main worker task exit - int _serial_fd; ///< serial interface to GPS - unsigned _baudrate; ///< current baudrate - const unsigned _baudrates_to_try[NUMBER_OF_BAUDRATES]; ///< try different baudrates that GPS could be set to - volatile int _task; ///< worker task - bool _config_needed; ///< flag to signal that configuration of GPS is needed - bool _baudrate_changed; ///< flag to signal that the baudrate with the GPS has changed - bool _mode_changed; ///< flag that the GPS mode has changed - gps_driver_mode_t _mode; ///< current mode - GPS_Helper *_Helper; ///< Class for a GPS interface - struct vehicle_gps_position_s _report; ///< uORB topic for gps position - orb_advert_t _report_pub; ///< uORB pub for gps position - float _rate; ///< position update rate + bool _task_should_exit; ///< flag to make the main worker task exit + int _serial_fd; ///< serial interface to GPS + unsigned _baudrate; ///< current baudrate + char _port[20]; ///< device / serial port path + const unsigned _baudrates_to_try[NUMBER_OF_BAUDRATES]; ///< try different baudrates that GPS could be set to + volatile int _task; //< worker task + bool _config_needed; ///< flag to signal that configuration of GPS is needed + bool _baudrate_changed; ///< flag to signal that the baudrate with the GPS has changed + bool _mode_changed; ///< flag that the GPS mode has changed + gps_driver_mode_t _mode; ///< current mode + GPS_Helper *_Helper; ///< instance of GPS parser + struct vehicle_gps_position_s _report; ///< uORB topic for gps position + orb_advert_t _report_pub; ///< uORB pub for gps position + float _rate; ///< position update rate /** @@ -141,7 +143,7 @@ private: /** * Set the baudrate of the UART to the GPS */ - int set_baudrate(unsigned baud); + int set_baudrate(unsigned baud); /** * Send a reset command to the GPS @@ -164,7 +166,7 @@ GPS *g_dev; } -GPS::GPS() : +GPS::GPS(const char* uart_path) : CDev("gps", GPS_DEVICE_PATH), _task_should_exit(false), _baudrates_to_try({9600, 38400, 57600, 115200}), @@ -176,6 +178,11 @@ GPS::GPS() : _report_pub(-1), _rate(0.0f) { + /* store port name */ + strncpy(_port, uart_path, sizeof(_port)); + /* enforce null termination */ + _port[sizeof(_port) - 1] = '\0'; + /* we need this potentially before it could be set in task_main */ g_dev = this; memset(&_report, 0, sizeof(_report)); @@ -198,6 +205,7 @@ GPS::~GPS() if (_task != -1) task_delete(_task); g_dev = nullptr; + } int @@ -302,13 +310,13 @@ GPS::task_main() log("starting"); /* open the serial port */ - _serial_fd = ::open("/dev/ttyS3", O_RDWR); //TODO make the device dynamic depending on startup parameters + _serial_fd = ::open(_port, O_RDWR); //TODO make the device dynamic depending on startup parameters /* buffer to read from the serial port */ uint8_t buf[32]; if (_serial_fd < 0) { - log("failed to open serial port: %d", errno); + log("failed to open serial port: %s err: %d", _port, errno); /* tell the dtor that we are exiting, set error code */ _task = -1; _exit(1); @@ -318,7 +326,6 @@ GPS::task_main() pollfd fds[1]; fds[0].fd = _serial_fd; fds[0].events = POLLIN; - debug("ready"); /* lock against the ioctl handler */ lock(); @@ -418,14 +425,12 @@ GPS::task_main() /* This means something went wrong in the parser, let's reconfigure */ if (!_config_needed) { _config_needed = true; - debug("Lost GPS module"); } config(); } else if (ret_parse > 0) { /* Looks like we got a valid position update, stop configuring and publish it */ if (_config_needed) { _config_needed = false; - debug("Found GPS module"); } /* opportunistic publishing - else invalid data would end up on the bus */ @@ -530,7 +535,7 @@ GPS::print_info() default: break; } - warnx("baudrate: %d, status: %s", _baudrate, (_config_needed) ? "NOT OK" : "OK"); + warnx("port: %s, baudrate: %d, status: %s", _port, _baudrate, (_config_needed) ? "NOT OK" : "OK"); if (_report.timestamp != 0) { warnx("position lock: %dD, last update %4.2f seconds ago", (int)_report.fix_type, (double)((float)(hrt_absolute_time() - _report.timestamp) / 1000000.0f)); @@ -549,7 +554,7 @@ namespace gps GPS *g_dev; -void start(); +void start(const char *uart_path); void stop(); void test(); void reset(); @@ -559,7 +564,7 @@ void info(); * Start the driver. */ void -start() +start(const char *uart_path) { int fd; @@ -567,7 +572,7 @@ start() errx(1, "already started"); /* create the driver */ - g_dev = new GPS; + g_dev = new GPS(uart_path); if (g_dev == nullptr) goto fail; @@ -644,7 +649,6 @@ info() if (g_dev == nullptr) errx(1, "driver not running"); - printf("state @ %p\n", g_dev); g_dev->print_info(); exit(0); @@ -656,11 +660,24 @@ info() int gps_main(int argc, char *argv[]) { + + /* set to default */ + char* device_name = "/dev/ttyS3"; + /* * Start/load the driver. */ - if (!strcmp(argv[1], "start")) - gps::start(); + if (!strcmp(argv[1], "start")) { + /* work around getopt unreliability */ + if (argc > 3) { + if (!strcmp(argv[2], "-d")) { + device_name = argv[3]; + } else { + goto out; + } + } + gps::start(device_name); + } if (!strcmp(argv[1], "stop")) gps::stop(); @@ -682,5 +699,6 @@ gps_main(int argc, char *argv[]) if (!strcmp(argv[1], "status")) gps::info(); - errx(1, "unrecognized command, try 'start', 'stop', 'test', 'reset' or 'status'"); +out: + errx(1, "unrecognized command, try 'start', 'stop', 'test', 'reset' or 'status' [-d /dev/ttyS0-n]"); } -- cgit v1.2.3 From fbbeef7e29cc6aa82e653916b7d5e8005948b815 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 5 Feb 2013 18:54:06 +0100 Subject: Update on every position change, do not wait for other measurements --- apps/drivers/gps/ubx.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp index 66a891da4..a6f181a73 100644 --- a/apps/drivers/gps/ubx.cpp +++ b/apps/drivers/gps/ubx.cpp @@ -765,11 +765,13 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) /* Add timestamp to finish the report */ gps_position->timestamp = hrt_absolute_time(); /* Reset the flags */ + + /* update on every position change, accept minor delay on other measurements */ _new_nav_posllh = false; - _new_nav_timeutc = false; - _new_nav_dop = false; - _new_nav_sol = false; - _new_nav_velned = false; + // _new_nav_timeutc = false; + // _new_nav_dop = false; + // _new_nav_sol = false; + // _new_nav_velned = false; ret = 1; } -- cgit v1.2.3 From a79ad17f09ac69bf2a19a4f617fa1df16bcaa6be Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Tue, 5 Feb 2013 23:16:32 -0800 Subject: Changed parse interface, differentiation between config needed and position updated, working but might be solved more elegant --- apps/drivers/drv_gps.h | 2 ++ apps/drivers/gps/gps.cpp | 73 ++++++++++++++++++++++++------------------- apps/drivers/gps/gps_helper.h | 6 ++-- apps/drivers/gps/ubx.cpp | 65 ++++++++++++++++++++------------------ apps/drivers/gps/ubx.h | 4 +-- 5 files changed, 81 insertions(+), 69 deletions(-) diff --git a/apps/drivers/drv_gps.h b/apps/drivers/drv_gps.h index 1ae27ed2f..dfde115ef 100644 --- a/apps/drivers/drv_gps.h +++ b/apps/drivers/drv_gps.h @@ -44,6 +44,8 @@ #include "drv_sensor.h" #include "drv_orb_dev.h" +#define GPS_DEFAULT_UART_PORT "/dev/ttyS3" + #define GPS_DEVICE_PATH "/dev/gps" typedef enum { diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 5905db6b8..28dc949d4 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -278,7 +278,7 @@ GPS::config() int length = 0; uint8_t send_buffer[SEND_BUFFER_LENGTH]; - _Helper->configure(_config_needed, _baudrate_changed, _baudrate, send_buffer, length, SEND_BUFFER_LENGTH); + _Helper->configure(send_buffer, length, SEND_BUFFER_LENGTH, _baudrate_changed, _baudrate); /* The config message is sent sent at the old baudrate */ if (length > 0) { @@ -339,6 +339,9 @@ GPS::task_main() uint64_t last_rate_measurement = hrt_absolute_time(); unsigned last_rate_count = 0; + bool pos_updated; + bool config_needed_res; + /* loop handling received serial bytes and also configuring in between */ while (!_task_should_exit) { @@ -391,17 +394,17 @@ GPS::task_main() lock(); - - /* this would be bad... */ if (ret < 0) { log("poll error %d", errno); } else if (ret == 0) { - config(); + /* no response from the GPS */ if (_config_needed == false) { _config_needed = true; - warnx("lost GPS module"); + warnx("GPS module timeout"); + _Helper->reset(); } + config(); } else if (ret > 0) { /* if we have new data from GPS, go handle it */ if (fds[0].revents & POLLIN) { @@ -416,39 +419,43 @@ GPS::task_main() /* pass received bytes to the packet decoder */ int j; - int ret_parse = 0; for (j = 0; j < count; j++) { - ret_parse += _Helper->parse(buf[j], &_report); - } + pos_updated = false; + config_needed_res = _config_needed; + _Helper->parse(buf[j], &_report, config_needed_res, pos_updated); + + if (pos_updated) { + /* opportunistic publishing - else invalid data would end up on the bus */ + if (_report_pub > 0) { + orb_publish(ORB_ID(vehicle_gps_position), _report_pub, &_report); + } else { + _report_pub = orb_advertise(ORB_ID(vehicle_gps_position), &_report); + } + last_rate_count++; + + /* measure update rate every 5 seconds */ + if (hrt_absolute_time() - last_rate_measurement > 5000000) { + _rate = last_rate_count / ((float)((hrt_absolute_time() - last_rate_measurement)) / 1000000.0f); + last_rate_measurement = hrt_absolute_time(); + last_rate_count = 0; + } - if (ret_parse < 0) { - /* This means something went wrong in the parser, let's reconfigure */ - if (!_config_needed) { - _config_needed = true; } - config(); - } else if (ret_parse > 0) { - /* Looks like we got a valid position update, stop configuring and publish it */ - if (_config_needed) { + if (config_needed_res == true && _config_needed == false) { + /* the parser told us that an error happened and reconfiguration is needed */ + _config_needed = true; + warnx("GPS module lost"); + _Helper->reset(); + config(); + } else if (config_needed_res == true && _config_needed == true) { + /* we are still configuring */ + config(); + } else if (config_needed_res == false && _config_needed == true) { + /* the parser is happy, stop configuring */ + warnx("GPS module found"); _config_needed = false; } - - /* opportunistic publishing - else invalid data would end up on the bus */ - if (_report_pub > 0) { - orb_publish(ORB_ID(vehicle_gps_position), _report_pub, &_report); - } else { - _report_pub = orb_advertise(ORB_ID(vehicle_gps_position), &_report); - } - last_rate_count++; - - /* measure update rate every 5 seconds */ - if (hrt_absolute_time() - last_rate_measurement > 5000000) { - _rate = last_rate_count / ((float)((hrt_absolute_time() - last_rate_measurement)) / 1000000.0f); - last_rate_measurement = hrt_absolute_time(); - last_rate_count = 0; - } } - /* else if ret_parse == 0: just keep parsing */ } } } @@ -662,7 +669,7 @@ gps_main(int argc, char *argv[]) { /* set to default */ - char* device_name = "/dev/ttyS3"; + char* device_name = GPS_DEFAULT_UART_PORT; /* * Start/load the driver. diff --git a/apps/drivers/gps/gps_helper.h b/apps/drivers/gps/gps_helper.h index 8a6b0148b..176b7eba8 100644 --- a/apps/drivers/gps/gps_helper.h +++ b/apps/drivers/gps/gps_helper.h @@ -40,9 +40,9 @@ class GPS_Helper { public: - virtual void reset() = 0; - virtual void configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, uint8_t *buffer, int &length, const unsigned max_length) = 0; - virtual int parse(uint8_t b, struct vehicle_gps_position_s *gps_position) = 0; + virtual void reset(void) = 0; + virtual void configure(uint8_t *buffer, int &length, const unsigned max_length, bool &baudrate_changed, unsigned &baudrate) = 0; + virtual void parse(uint8_t, struct vehicle_gps_position_s*, bool &config_needed, bool &pos_updated) = 0; }; #endif /* GPS_HELPER_H */ diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp index a6f181a73..440ec74c5 100644 --- a/apps/drivers/gps/ubx.cpp +++ b/apps/drivers/gps/ubx.cpp @@ -72,7 +72,7 @@ UBX::reset() } void -UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, uint8_t *buffer, int &length, const unsigned max_length) +UBX::configure(uint8_t *buffer, int &length, const unsigned max_length, bool &baudrate_changed, unsigned &baudrate) { /* make sure the buffer, where the message is written to, is long enough */ assert(sizeof(type_gps_bin_cfg_prt_packet_t)+2 <= max_length); @@ -84,9 +84,10 @@ UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, if (!_waiting_for_ack) { _waiting_for_ack = true; if (_config_state == UBX_CONFIG_STATE_CONFIGURED) { - config_needed = false; - length = 0; - _config_state = UBX_CONFIG_STATE_PRT; /* set the state for next time */ + /* This should never happen, the parser should set the flag, + * if it should be reconfigured, reset() should be called first. + */ + warnx("ubx: already configured"); _waiting_for_ack = false; return; } else if (_config_state == UBX_CONFIG_STATE_PRT) { @@ -246,12 +247,9 @@ UBX::configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, } } -int -UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) +void +UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_needed, bool &pos_updated) { - /* if no error happens and no new report is ready yet, ret will stay 0 */ - int ret = 0; - switch (_decode_state) { /* First, look for sync1 */ case UBX_DECODE_UNINIT: @@ -382,7 +380,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) default: //should not happen because we set the class warnx("UBX Error, we set a class that we don't know"); decodeInit(); - ret = -1; + config_needed = true; break; } break; @@ -417,7 +415,12 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) gps_position->counter_pos_valid++; gps_position->counter++; + /* Add timestamp to finish the report */ + gps_position->timestamp = hrt_absolute_time(); + _new_nav_posllh = true; + /* set flag to trigger publishing of new position */ + pos_updated = true; } else { warnx("NAV_POSLLH: checksum invalid"); @@ -436,11 +439,13 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { gps_position->fix_type = packet->gpsFix; - - gps_position->counter++; gps_position->s_variance = packet->sAcc; gps_position->p_variance = packet->pAcc; + gps_position->counter++; + gps_position->timestamp = hrt_absolute_time(); + + _new_nav_sol = true; } else { @@ -463,6 +468,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) gps_position->epv = packet->vDOP; gps_position->counter++; + gps_position->timestamp = hrt_absolute_time(); _new_nav_dop = true; @@ -496,6 +502,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) gps_position->time_gps_usec += (uint64_t)(packet->time_nanoseconds * 1e-3f); gps_position->counter++; + gps_position->timestamp = hrt_absolute_time(); _new_nav_timeutc = true; @@ -587,6 +594,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) gps_position->satellites_visible = satellites_used++; // visible ~= used but we are interested in the used ones gps_position->counter++; + gps_position->timestamp = hrt_absolute_time(); // as this message arrives only with 1Hz and is not essential, we don't take it into account for the report @@ -614,6 +622,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) gps_position->cog = (uint16_t)((float)(packet->heading) * 1e-3f); gps_position->counter++; + gps_position->timestamp = hrt_absolute_time(); _new_nav_velned = true; @@ -647,8 +656,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) // // // Reset state machine to decode next packet // decodeInit(); -// return ret; -// // break; // } @@ -701,6 +708,8 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) case UBX_CONFIG_STATE_MSG_NAV_VELNED: if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) _config_state = UBX_CONFIG_STATE_CONFIGURED; + /* set the flag to tell the driver that configuration was successful */ + config_needed = false; break; // case UBX_CONFIG_STATE_MSG_RXM_SVSI: // if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) @@ -715,7 +724,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) // Reset state machine to decode next packet decodeInit(); - break; } @@ -727,16 +735,14 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { warnx("UBX: Received: Not Acknowledged"); - ret = 1; - + /* configuration obviously not successful */ + config_needed = true; } else { warnx("ACK_NAK: checksum invalid\n"); } // Reset state machine to decode next packet decodeInit(); - return ret; - break; } @@ -752,7 +758,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) } else { warnx("buffer full, restarting"); decodeInit(); - ret = -1; + config_needed = true; } break; default: @@ -762,21 +768,18 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position) /* return 1 when position updates and the remaining packets updated at least once */ if(_new_nav_posllh &&_new_nav_timeutc && _new_nav_dop && _new_nav_sol && _new_nav_velned) { - /* Add timestamp to finish the report */ - gps_position->timestamp = hrt_absolute_time(); - /* Reset the flags */ + /* we have received everything, this most probably means that the configuration is fine */ + config_needed = false; - /* update on every position change, accept minor delay on other measurements */ + /* Reset the flags */ _new_nav_posllh = false; - // _new_nav_timeutc = false; - // _new_nav_dop = false; - // _new_nav_sol = false; - // _new_nav_velned = false; + _new_nav_timeutc = false; + _new_nav_dop = false; + _new_nav_sol = false; + _new_nav_velned = false; - ret = 1; } - - return ret; + return; } void diff --git a/apps/drivers/gps/ubx.h b/apps/drivers/gps/ubx.h index 0cac10f0a..d3c6c6d4c 100644 --- a/apps/drivers/gps/ubx.h +++ b/apps/drivers/gps/ubx.h @@ -341,8 +341,8 @@ public: UBX(); ~UBX(); void reset(void); - void configure(bool &config_needed, bool &baudrate_changed, unsigned &baudrate, uint8_t *buffer, int &length, const unsigned max_length); - int parse(uint8_t, struct vehicle_gps_position_s*); + void configure(uint8_t *buffer, int &length, const unsigned max_length, bool &baudrate_changed, unsigned &baudrate); + void parse(uint8_t, struct vehicle_gps_position_s*, bool &config_needed, bool &pos_updated); private: /** -- cgit v1.2.3 From fc4be3e7280db480b67b7c6cec11e35481969bbb Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 6 Feb 2013 12:41:05 -0800 Subject: Changed gps position topic mostly to SI units and float, removed counters and added specifig timestamps --- apps/commander/commander.c | 14 ++-- apps/drivers/gps/gps.cpp | 4 +- apps/drivers/gps/ubx.cpp | 110 +++++++++++++++----------------- apps/drivers/gps/ubx.h | 30 ++++----- apps/examples/kalman_demo/KalmanNav.cpp | 23 +++---- apps/mavlink/mavlink_receiver.c | 24 +++---- apps/mavlink/orb_listener.c | 10 +-- apps/uORB/topics/home_position.h | 8 +-- apps/uORB/topics/vehicle_gps_position.h | 55 ++++++++-------- 9 files changed, 139 insertions(+), 139 deletions(-) diff --git a/apps/commander/commander.c b/apps/commander/commander.c index 3a6fecf74..f19f1d0e6 100644 --- a/apps/commander/commander.c +++ b/apps/commander/commander.c @@ -1678,8 +1678,8 @@ int commander_thread_main(int argc, char *argv[]) orb_copy(ORB_ID(vehicle_gps_position), gps_sub, &gps_position); /* check for first, long-term and valid GPS lock -> set home position */ - float hdop_m = gps_position.eph / 100.0f; - float vdop_m = gps_position.epv / 100.0f; + float hdop_m = gps_position.eph_m; + float vdop_m = gps_position.epv_m; /* check if gps fix is ok */ // XXX magic number @@ -1697,7 +1697,7 @@ int commander_thread_main(int argc, char *argv[]) if (gps_position.fix_type == GPS_FIX_TYPE_3D && (hdop_m < dop_threshold_m) && (vdop_m < dop_threshold_m) && !home_position_set - && (hrt_absolute_time() - gps_position.timestamp < 2000000) + && (hrt_absolute_time() - gps_position.timestamp_position < 2000000) && !current_status.flag_system_armed) { warnx("setting home position"); @@ -1706,11 +1706,11 @@ int commander_thread_main(int argc, char *argv[]) home.lon = gps_position.lon; home.alt = gps_position.alt; - home.eph = gps_position.eph; - home.epv = gps_position.epv; + home.eph_m = gps_position.eph_m; + home.epv_m = gps_position.epv_m; - home.s_variance = gps_position.s_variance; - home.p_variance = gps_position.p_variance; + home.s_variance_m_s = gps_position.s_variance_m_s; + home.p_variance_m = gps_position.p_variance_m; /* announce new home position */ if (home_pub > 0) { diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 28dc949d4..8c2775adb 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -543,9 +543,9 @@ GPS::print_info() break; } warnx("port: %s, baudrate: %d, status: %s", _port, _baudrate, (_config_needed) ? "NOT OK" : "OK"); - if (_report.timestamp != 0) { + if (_report.timestamp_position != 0) { warnx("position lock: %dD, last update %4.2f seconds ago", (int)_report.fix_type, - (double)((float)(hrt_absolute_time() - _report.timestamp) / 1000000.0f)); + (double)((float)(hrt_absolute_time() - _report.timestamp_position) / 1000000.0f)); warnx("lat: %d, lon: %d, alt: %d", _report.lat, _report.lon, _report.alt); warnx("update rate: %6.2f Hz", (double)_rate); } diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp index 440ec74c5..eec1df980 100644 --- a/apps/drivers/gps/ubx.cpp +++ b/apps/drivers/gps/ubx.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -52,7 +53,7 @@ _config_state(UBX_CONFIG_STATE_PRT), _waiting_for_ack(false), _new_nav_posllh(false), _new_nav_timeutc(false), -_new_nav_dop(false), +//_new_nav_dop(false), _new_nav_sol(false), _new_nav_velned(false) { @@ -211,10 +212,10 @@ UBX::configure(uint8_t *buffer, int &length, const unsigned max_length, bool &ba cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_TIMEUTC; break; - case UBX_CONFIG_STATE_MSG_NAV_DOP: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_DOP; - break; +// case UBX_CONFIG_STATE_MSG_NAV_DOP: +// cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; +// cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_DOP; +// break; case UBX_CONFIG_STATE_MSG_NAV_SVINFO: cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_SVINFO; @@ -316,10 +317,10 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ _message_id = NAV_TIMEUTC; break; - case UBX_MESSAGE_NAV_DOP: - _decode_state = UBX_DECODE_GOT_MESSAGEID; - _message_id = NAV_DOP; - break; +// case UBX_MESSAGE_NAV_DOP: +// _decode_state = UBX_DECODE_GOT_MESSAGEID; +// _message_id = NAV_DOP; +// break; case UBX_MESSAGE_NAV_SVINFO: _decode_state = UBX_DECODE_GOT_MESSAGEID; @@ -412,11 +413,11 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ gps_position->lon = packet->lon; gps_position->alt = packet->height_msl; - gps_position->counter_pos_valid++; - gps_position->counter++; + gps_position->eph_m = (float)packet->hAcc * 1e-2f; // from mm to m + gps_position->epv_m = (float)packet->vAcc * 1e-2f; // from mm to m /* Add timestamp to finish the report */ - gps_position->timestamp = hrt_absolute_time(); + gps_position->timestamp_position = hrt_absolute_time(); _new_nav_posllh = true; /* set flag to trigger publishing of new position */ @@ -439,11 +440,10 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { gps_position->fix_type = packet->gpsFix; - gps_position->s_variance = packet->sAcc; - gps_position->p_variance = packet->pAcc; + gps_position->s_variance_m_s = packet->sAcc; + gps_position->p_variance_m = packet->pAcc; - gps_position->counter++; - gps_position->timestamp = hrt_absolute_time(); + gps_position->timestamp_variance = hrt_absolute_time(); _new_nav_sol = true; @@ -457,29 +457,28 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ break; } - case NAV_DOP: { -// printf("GOT NAV_DOP MESSAGE\n"); - gps_bin_nav_dop_packet_t *packet = (gps_bin_nav_dop_packet_t *) _rx_buffer; - - //Check if checksum is valid and the store the gps information - if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - - gps_position->eph = packet->hDOP; - gps_position->epv = packet->vDOP; - - gps_position->counter++; - gps_position->timestamp = hrt_absolute_time(); - - _new_nav_dop = true; - - } else { - warnx("NAV_DOP: checksum invalid"); - } - - // Reset state machine to decode next packet - decodeInit(); - break; - } +// case NAV_DOP: { +//// printf("GOT NAV_DOP MESSAGE\n"); +// gps_bin_nav_dop_packet_t *packet = (gps_bin_nav_dop_packet_t *) _rx_buffer; +// +// //Check if checksum is valid and the store the gps information +// if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { +// +// gps_position->eph_m = packet->hDOP; +// gps_position->epv = packet->vDOP; +// +// gps_position->timestamp_posdilution = hrt_absolute_time(); +// +// _new_nav_dop = true; +// +// } else { +// warnx("NAV_DOP: checksum invalid"); +// } +// +// // Reset state machine to decode next packet +// decodeInit(); +// break; +// } case NAV_TIMEUTC: { // printf("GOT NAV_TIMEUTC MESSAGE\n"); @@ -501,8 +500,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ gps_position->time_gps_usec = (uint64_t)epoch * 1000000; //TODO: test this gps_position->time_gps_usec += (uint64_t)(packet->time_nanoseconds * 1e-3f); - gps_position->counter++; - gps_position->timestamp = hrt_absolute_time(); + gps_position->timestamp_time = hrt_absolute_time(); _new_nav_timeutc = true; @@ -593,8 +591,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ } gps_position->satellites_visible = satellites_used++; // visible ~= used but we are interested in the used ones - gps_position->counter++; - gps_position->timestamp = hrt_absolute_time(); + gps_position->timestamp_satellites = hrt_absolute_time(); // as this message arrives only with 1Hz and is not essential, we don't take it into account for the report @@ -614,18 +611,17 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ //Check if checksum is valid and the store the gps information if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - gps_position->vel = (uint16_t)packet->speed; - gps_position->vel_n = packet->velN / 100.0f; - gps_position->vel_e = packet->velE / 100.0f; - gps_position->vel_d = packet->velD / 100.0f; + gps_position->vel_m_s = (float)packet->speed * 1e-2f; + gps_position->vel_n_m_s = (float)packet->velN * 1e-2f; + gps_position->vel_e_m_s = (float)packet->velE * 1e-2f; + gps_position->vel_d_m_s = (float)packet->velD * 1e-2f; + gps_position->cog_rad = (float)packet->heading * M_DEG_TO_RAD_F * 1e-5f; gps_position->vel_ned_valid = true; - gps_position->cog = (uint16_t)((float)(packet->heading) * 1e-3f); - - gps_position->counter++; - gps_position->timestamp = hrt_absolute_time(); + gps_position->timestamp_velocity = hrt_absolute_time(); _new_nav_velned = true; + } else { warnx("NAV_VELNED: checksum invalid"); } @@ -690,13 +686,13 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ _config_state = UBX_CONFIG_STATE_MSG_NAV_TIMEUTC; break; case UBX_CONFIG_STATE_MSG_NAV_TIMEUTC: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) - _config_state = UBX_CONFIG_STATE_MSG_NAV_DOP; - break; - case UBX_CONFIG_STATE_MSG_NAV_DOP: if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) _config_state = UBX_CONFIG_STATE_MSG_NAV_SVINFO; break; +// case UBX_CONFIG_STATE_MSG_NAV_DOP: +// if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) +// _config_state = UBX_CONFIG_STATE_MSG_NAV_SVINFO; +// break; case UBX_CONFIG_STATE_MSG_NAV_SVINFO: if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) _config_state = UBX_CONFIG_STATE_MSG_NAV_SOL; @@ -766,7 +762,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ } /* return 1 when position updates and the remaining packets updated at least once */ - if(_new_nav_posllh &&_new_nav_timeutc && _new_nav_dop && _new_nav_sol && _new_nav_velned) { + if(_new_nav_posllh &&_new_nav_timeutc /*&& _new_nav_dop*/ && _new_nav_sol && _new_nav_velned) { /* we have received everything, this most probably means that the configuration is fine */ config_needed = false; @@ -774,7 +770,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ /* Reset the flags */ _new_nav_posllh = false; _new_nav_timeutc = false; - _new_nav_dop = false; +// _new_nav_dop = false; _new_nav_sol = false; _new_nav_velned = false; diff --git a/apps/drivers/gps/ubx.h b/apps/drivers/gps/ubx.h index d3c6c6d4c..43cded02f 100644 --- a/apps/drivers/gps/ubx.h +++ b/apps/drivers/gps/ubx.h @@ -54,7 +54,7 @@ #define UBX_MESSAGE_NAV_POSLLH 0x02 #define UBX_MESSAGE_NAV_SOL 0x06 #define UBX_MESSAGE_NAV_TIMEUTC 0x21 -#define UBX_MESSAGE_NAV_DOP 0x04 +//#define UBX_MESSAGE_NAV_DOP 0x04 #define UBX_MESSAGE_NAV_SVINFO 0x30 #define UBX_MESSAGE_NAV_VELNED 0x12 //#define UBX_MESSAGE_RXM_SVSI 0x20 @@ -140,18 +140,18 @@ typedef struct { uint8_t ck_b; } gps_bin_nav_timeutc_packet_t; -typedef struct { - uint32_t time_milliseconds; /**< GPS Millisecond Time of Week */ - uint16_t gDOP; /**< Geometric DOP (scaling 0.01) */ - uint16_t pDOP; /**< Position DOP (scaling 0.01) */ - uint16_t tDOP; /**< Time DOP (scaling 0.01) */ - uint16_t vDOP; /**< Vertical DOP (scaling 0.01) */ - uint16_t hDOP; /**< Horizontal DOP (scaling 0.01) */ - uint16_t nDOP; /**< Northing DOP (scaling 0.01) */ - uint16_t eDOP; /**< Easting DOP (scaling 0.01) */ - uint8_t ck_a; - uint8_t ck_b; -} gps_bin_nav_dop_packet_t; +//typedef struct { +// uint32_t time_milliseconds; /**< GPS Millisecond Time of Week */ +// uint16_t gDOP; /**< Geometric DOP (scaling 0.01) */ +// uint16_t pDOP; /**< Position DOP (scaling 0.01) */ +// uint16_t tDOP; /**< Time DOP (scaling 0.01) */ +// uint16_t vDOP; /**< Vertical DOP (scaling 0.01) */ +// uint16_t hDOP; /**< Horizontal DOP (scaling 0.01) */ +// uint16_t nDOP; /**< Northing DOP (scaling 0.01) */ +// uint16_t eDOP; /**< Easting DOP (scaling 0.01) */ +// uint8_t ck_a; +// uint8_t ck_b; +//} gps_bin_nav_dop_packet_t; typedef struct { uint32_t time_milliseconds; /**< GPS Millisecond Time of Week */ @@ -311,7 +311,7 @@ typedef enum { NAV_POSLLH, NAV_SOL, NAV_TIMEUTC, - NAV_DOP, +// NAV_DOP, NAV_SVINFO, NAV_VELNED, // RXM_SVSI, @@ -371,7 +371,7 @@ private: unsigned _payload_size; bool _new_nav_posllh; bool _new_nav_timeutc; - bool _new_nav_dop; +// bool _new_nav_dop; bool _new_nav_sol; bool _new_nav_velned; }; diff --git a/apps/examples/kalman_demo/KalmanNav.cpp b/apps/examples/kalman_demo/KalmanNav.cpp index 7e89dffb2..b7f651d8a 100644 --- a/apps/examples/kalman_demo/KalmanNav.cpp +++ b/apps/examples/kalman_demo/KalmanNav.cpp @@ -190,11 +190,12 @@ void KalmanNav::update() if (!_positionInitialized && _attitudeInitialized && // wait for attitude first gpsUpdate && - _gps.fix_type > 2 && - _gps.counter_pos_valid > 10) { - vN = _gps.vel_n; - vE = _gps.vel_e; - vD = _gps.vel_d; + _gps.fix_type > 2 + //&& _gps.counter_pos_valid > 10 + ) { + vN = _gps.vel_n_m_s; + vE = _gps.vel_e_m_s; + vD = _gps.vel_d_m_s; setLatDegE7(_gps.lat); setLonDegE7(_gps.lon); setAltE3(_gps.alt); @@ -259,7 +260,7 @@ void KalmanNav::updatePublications() // position publication _pos.timestamp = _pubTimeStamp; - _pos.time_gps_usec = _gps.timestamp; + _pos.time_gps_usec = _gps.timestamp_position; _pos.valid = true; _pos.lat = getLatDegE7(); _pos.lon = getLonDegE7(); @@ -631,8 +632,8 @@ int KalmanNav::correctPos() // residual Vector y(5); - y(0) = _gps.vel_n - vN; - y(1) = _gps.vel_e - vE; + y(0) = _gps.vel_n_m_s - vN; + y(1) = _gps.vel_e_m_s - vE; y(2) = double(_gps.lat) - lat * 1.0e7 * M_RAD_TO_DEG; y(3) = double(_gps.lon) - lon * 1.0e7 * M_RAD_TO_DEG; y(4) = double(_gps.alt) / 1.0e3 - alt; @@ -651,9 +652,9 @@ int KalmanNav::correctPos() // abort correction and return printf("[kalman_demo] numerical failure in gps correction\n"); // fallback to GPS - vN = _gps.vel_n; - vE = _gps.vel_e; - vD = _gps.vel_d; + vN = _gps.vel_n_m_s; + vE = _gps.vel_e_m_s; + vD = _gps.vel_d_m_s; setLatDegE7(_gps.lat); setLonDegE7(_gps.lon); setAltE3(_gps.alt); diff --git a/apps/mavlink/mavlink_receiver.c b/apps/mavlink/mavlink_receiver.c index 86732d07c..b3b4b1e0b 100644 --- a/apps/mavlink/mavlink_receiver.c +++ b/apps/mavlink/mavlink_receiver.c @@ -387,22 +387,22 @@ handle_message(mavlink_message_t *msg) static uint64_t old_timestamp = 0; /* gps */ - hil_gps.timestamp = gps.time_usec; - hil_gps.counter = hil_counter++; + hil_gps.timestamp_position = gps.time_usec; +// hil_gps.counter = hil_counter++; hil_gps.time_gps_usec = gps.time_usec; hil_gps.lat = gps.lat; hil_gps.lon = gps.lon; hil_gps.alt = gps.alt; - hil_gps.counter_pos_valid = hil_counter++; - hil_gps.eph = gps.eph; - hil_gps.epv = gps.epv; - hil_gps.s_variance = 100; - hil_gps.p_variance = 100; - hil_gps.vel = gps.vel; - hil_gps.vel_n = gps.vel / 100.0f * cosf(gps.cog / M_RAD_TO_DEG_F / 100.0f); - hil_gps.vel_e = gps.vel / 100.0f * sinf(gps.cog / M_RAD_TO_DEG_F / 100.0f); - hil_gps.vel_d = 0.0f; - hil_gps.cog = gps.cog; +// hil_gps.counter_pos_valid = hil_counter++; + hil_gps.eph_m = (float)gps.eph * 1e-2f; // from cm to m + hil_gps.epv_m = (float)gps.epv * 1e-2f; // from cm to m + hil_gps.s_variance_m_s = 100; // XXX 100 m/s variance? + hil_gps.p_variance_m = 100; // XXX 100 m variance? + hil_gps.vel_m_s = (float)gps.vel * 1e-2f; // from cm/s to m/s + hil_gps.vel_n_m_s = (float)gps.vel * 1e-2f * cosf(gps.cog * M_DEG_TO_RAD_F * 1e-2f); + hil_gps.vel_e_m_s = (float)gps.vel * 1e-2f * sinf(gps.cog * M_DEG_TO_RAD_F * 1e-2f); + hil_gps.vel_d_m_s = 0.0f; + hil_gps.cog_rad = gps.cog * M_DEG_TO_RAD_F * 1e-2f; // from deg*100 to rad hil_gps.fix_type = gps.fix_type; hil_gps.satellites_visible = gps.satellites_visible; diff --git a/apps/mavlink/orb_listener.c b/apps/mavlink/orb_listener.c index 18da70f61..9f85d5801 100644 --- a/apps/mavlink/orb_listener.c +++ b/apps/mavlink/orb_listener.c @@ -231,15 +231,15 @@ l_vehicle_gps_position(struct listener *l) /* GPS position */ mavlink_msg_gps_raw_int_send(MAVLINK_COMM_0, - gps.timestamp, + gps.timestamp_position, gps.fix_type, gps.lat, gps.lon, gps.alt, - gps.eph, - gps.epv, - gps.vel, - gps.cog, + (uint16_t)(gps.eph_m * 1e2f), // from m to cm + (uint16_t)(gps.epv_m * 1e2f), // from m to cm + (uint16_t)(gps.vel_m_s * 1e2f), // from m/s to cm/s + (uint16_t)(gps.cog_rad * M_RAD_TO_DEG_F * 1e2f), // from rad to deg * 100 gps.satellites_visible); if (gps.satellite_info_available && (gps_counter % 4 == 0)) { diff --git a/apps/uORB/topics/home_position.h b/apps/uORB/topics/home_position.h index dec34b6ab..7e1b82a0f 100644 --- a/apps/uORB/topics/home_position.h +++ b/apps/uORB/topics/home_position.h @@ -61,10 +61,10 @@ struct home_position_s int32_t lat; /**< Latitude in 1E7 degrees */ int32_t lon; /**< Longitude in 1E7 degrees */ int32_t alt; /**< Altitude in 1E3 meters (millimeters) above MSL */ - uint16_t eph; /**< GPS HDOP horizontal dilution of position in cm (m*100). If unknown, set to: 65535 */ - uint16_t epv; /**< GPS VDOP horizontal dilution of position in cm (m*100). If unknown, set to: 65535 */ - float s_variance; /**< speed accuracy estimate cm/s */ - float p_variance; /**< position accuracy estimate cm */ + float eph_m; /**< GPS HDOP horizontal dilution of position in m */ + float epv_m; /**< GPS VDOP horizontal dilution of position in m */ + float s_variance_m_s; /**< speed accuracy estimate m/s */ + float p_variance_m; /**< position accuracy estimate m */ }; /** diff --git a/apps/uORB/topics/vehicle_gps_position.h b/apps/uORB/topics/vehicle_gps_position.h index db529da06..aa75c22ac 100644 --- a/apps/uORB/topics/vehicle_gps_position.h +++ b/apps/uORB/topics/vehicle_gps_position.h @@ -55,35 +55,38 @@ */ struct vehicle_gps_position_s { - uint64_t timestamp; /**< Timestamp (microseconds since system boot) */ - uint32_t counter; /**< Count of GPS messages */ - uint64_t time_gps_usec; /**< Timestamp (microseconds in GPS format), this is the timestamp which comes from the gps module */ + uint64_t timestamp_position; /**< Timestamp for position information */ + int32_t lat; /**< Latitude in 1E7 degrees */ + int32_t lon; /**< Longitude in 1E7 degrees */ + int32_t alt; /**< Altitude in 1E3 meters (millimeters) above MSL */ - int32_t lat; /**< Latitude in 1E7 degrees //LOGME */ - int32_t lon; /**< Longitude in 1E7 degrees //LOGME */ - int32_t alt; /**< Altitude in 1E3 meters (millimeters) above MSL //LOGME */ - uint16_t counter_pos_valid; /**< is only increased when new lat/lon/alt information was added */ - uint16_t eph; /**< GPS HDOP horizontal dilution of position in cm (m*100). If unknown, set to: 65535 //LOGME */ - uint16_t epv; /**< GPS VDOP horizontal dilution of position in cm (m*100). If unknown, set to: 65535 */ - float s_variance; /**< speed accuracy estimate cm/s */ - float p_variance; /**< position accuracy estimate cm */ - uint16_t vel; /**< GPS ground speed (m/s * 100). If unknown, set to: 65535 */ - float vel_n; /**< GPS ground speed in m/s */ - float vel_e; /**< GPS ground speed in m/s */ - float vel_d; /**< GPS ground speed in m/s */ - uint16_t cog; /**< Course over ground (NOT heading, but direction of movement) in degrees * 100, 0.0..359.99 degrees. If unknown, set to: 65535 */ - uint8_t fix_type; /**< 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. */ - uint8_t satellites_visible; /**< Number of satellites visible. If unknown, set to 255 */ + uint64_t timestamp_variance; + float s_variance_m_s; /**< speed accuracy estimate m/s */ + float p_variance_m; /**< position accuracy estimate m */ + uint8_t fix_type; /**< 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. */ - uint8_t satellite_prn[20]; /**< Global satellite ID */ - uint8_t satellite_used[20]; /**< 0: Satellite not used, 1: used for localization */ - uint8_t satellite_elevation[20]; /**< Elevation (0: right on top of receiver, 90: on the horizon) of satellite */ - uint8_t satellite_azimuth[20]; /**< Direction of satellite, 0: 0 deg, 255: 360 deg. */ - uint8_t satellite_snr[20]; /**< Signal to noise ratio of satellite */ - uint8_t satellite_info_available; /**< 0 for no info, 1 for info available */ + float eph_m; /**< GPS HDOP horizontal dilution of position in m */ + float epv_m; /**< GPS VDOP horizontal dilution of position in m */ - /* flags */ - float vel_ned_valid; /**< Flag to indicate if NED speed is valid */ + uint64_t timestamp_velocity; /**< Timestamp for velocity informations */ + float vel_m_s; /**< GPS ground speed (m/s) */ + float vel_n_m_s; /**< GPS ground speed in m/s */ + float vel_e_m_s; /**< GPS ground speed in m/s */ + float vel_d_m_s; /**< GPS ground speed in m/s */ + float cog_rad; /**< Course over ground (NOT heading, but direction of movement) in rad */ + bool vel_ned_valid; /**< Flag to indicate if NED speed is valid */ + + uint64_t timestamp_time; /**< Timestamp for time information */ + uint64_t time_gps_usec; /**< Timestamp (microseconds in GPS format), this is the timestamp which comes from the gps module */ + + uint64_t timestamp_satellites; /**< Timestamp for sattelite information */ + uint8_t satellites_visible; /**< Number of satellites visible. If unknown, set to 255 */ + uint8_t satellite_prn[20]; /**< Global satellite ID */ + uint8_t satellite_used[20]; /**< 0: Satellite not used, 1: used for localization */ + uint8_t satellite_elevation[20]; /**< Elevation (0: right on top of receiver, 90: on the horizon) of satellite */ + uint8_t satellite_azimuth[20]; /**< Direction of satellite, 0: 0 deg, 255: 360 deg. */ + uint8_t satellite_snr[20]; /**< Signal to noise ratio of satellite */ + uint8_t satellite_info_available; /**< 0 for no info, 1 for info available */ }; /** -- cgit v1.2.3 From d962e6c403678e14a64a6b01be8773e98660bb24 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 6 Feb 2013 13:50:32 -0800 Subject: Removed some unnecessairy flags, home position back working --- apps/commander/commander.c | 9 ++++-- apps/drivers/gps/gps.cpp | 2 +- apps/drivers/gps/ubx.cpp | 49 ++++++--------------------------- apps/drivers/gps/ubx.h | 5 ---- apps/uORB/topics/vehicle_gps_position.h | 2 +- 5 files changed, 16 insertions(+), 51 deletions(-) diff --git a/apps/commander/commander.c b/apps/commander/commander.c index f19f1d0e6..6b1bc0f9b 100644 --- a/apps/commander/commander.c +++ b/apps/commander/commander.c @@ -1683,7 +1683,8 @@ int commander_thread_main(int argc, char *argv[]) /* check if gps fix is ok */ // XXX magic number - float dop_threshold_m = 2.0f; + float hdop_threshold_m = 4.0f; + float vdop_threshold_m = 8.0f; /* * If horizontal dilution of precision (hdop / eph) @@ -1694,8 +1695,10 @@ int commander_thread_main(int argc, char *argv[]) * the system is currently not armed, set home * position to the current position. */ - if (gps_position.fix_type == GPS_FIX_TYPE_3D && (hdop_m < dop_threshold_m) - && (vdop_m < dop_threshold_m) + + if (gps_position.fix_type == GPS_FIX_TYPE_3D + && (hdop_m < hdop_threshold_m) + && (vdop_m < vdop_threshold_m) && !home_position_set && (hrt_absolute_time() - gps_position.timestamp_position < 2000000) && !current_status.flag_system_armed) { diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 8c2775adb..45f18158f 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -591,7 +591,7 @@ start(const char *uart_path) fd = open(GPS_DEVICE_PATH, O_RDONLY); if (fd < 0) { - printf("Could not open device path: %s\n", GPS_DEVICE_PATH); + errx(1, "Could not open device path: %s\n", GPS_DEVICE_PATH); goto fail; } exit(0); diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp index eec1df980..a82327175 100644 --- a/apps/drivers/gps/ubx.cpp +++ b/apps/drivers/gps/ubx.cpp @@ -50,12 +50,7 @@ UBX::UBX() : _config_state(UBX_CONFIG_STATE_PRT), -_waiting_for_ack(false), -_new_nav_posllh(false), -_new_nav_timeutc(false), -//_new_nav_dop(false), -_new_nav_sol(false), -_new_nav_velned(false) +_waiting_for_ack(false) { reset(); } @@ -413,13 +408,12 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ gps_position->lon = packet->lon; gps_position->alt = packet->height_msl; - gps_position->eph_m = (float)packet->hAcc * 1e-2f; // from mm to m - gps_position->epv_m = (float)packet->vAcc * 1e-2f; // from mm to m + gps_position->eph_m = (float)packet->hAcc * 1e-3f; // from mm to m + gps_position->epv_m = (float)packet->vAcc * 1e-3f; // from mm to m /* Add timestamp to finish the report */ gps_position->timestamp_position = hrt_absolute_time(); - _new_nav_posllh = true; /* set flag to trigger publishing of new position */ pos_updated = true; @@ -445,9 +439,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ gps_position->timestamp_variance = hrt_absolute_time(); - - _new_nav_sol = true; - } else { warnx("NAV_SOL: checksum invalid"); } @@ -502,8 +493,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ gps_position->timestamp_time = hrt_absolute_time(); - _new_nav_timeutc = true; - } else { warnx("NAV_TIMEUTC: checksum invalid"); } @@ -581,20 +570,16 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ gps_position->satellite_elevation[i] = 0; gps_position->satellite_azimuth[i] = 0; } + gps_position->satellites_visible = satellites_used; // visible ~= used but we are interested in the used ones - /* set flag if any sat info is available */ - if (!packet_part1->numCh > 0) { - gps_position->satellite_info_available = 1; - + /* set timestamp if any sat info is available */ + if (packet_part1->numCh > 0) { + gps_position->satellite_info_available = true; } else { - gps_position->satellite_info_available = 0; + gps_position->satellite_info_available = false; } - - gps_position->satellites_visible = satellites_used++; // visible ~= used but we are interested in the used ones gps_position->timestamp_satellites = hrt_absolute_time(); - // as this message arrives only with 1Hz and is not essential, we don't take it into account for the report - } else { warnx("NAV_SVINFO: checksum invalid"); } @@ -619,9 +604,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ gps_position->vel_ned_valid = true; gps_position->timestamp_velocity = hrt_absolute_time(); - _new_nav_velned = true; - - } else { warnx("NAV_VELNED: checksum invalid"); } @@ -760,21 +742,6 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ default: break; } - - /* return 1 when position updates and the remaining packets updated at least once */ - if(_new_nav_posllh &&_new_nav_timeutc /*&& _new_nav_dop*/ && _new_nav_sol && _new_nav_velned) { - - /* we have received everything, this most probably means that the configuration is fine */ - config_needed = false; - - /* Reset the flags */ - _new_nav_posllh = false; - _new_nav_timeutc = false; -// _new_nav_dop = false; - _new_nav_sol = false; - _new_nav_velned = false; - - } return; } diff --git a/apps/drivers/gps/ubx.h b/apps/drivers/gps/ubx.h index 43cded02f..a23bb5502 100644 --- a/apps/drivers/gps/ubx.h +++ b/apps/drivers/gps/ubx.h @@ -369,11 +369,6 @@ private: ubx_message_class_t _message_class; ubx_message_id_t _message_id; unsigned _payload_size; - bool _new_nav_posllh; - bool _new_nav_timeutc; -// bool _new_nav_dop; - bool _new_nav_sol; - bool _new_nav_velned; }; #endif /* UBX_H_ */ diff --git a/apps/uORB/topics/vehicle_gps_position.h b/apps/uORB/topics/vehicle_gps_position.h index aa75c22ac..5463a460d 100644 --- a/apps/uORB/topics/vehicle_gps_position.h +++ b/apps/uORB/topics/vehicle_gps_position.h @@ -86,7 +86,7 @@ struct vehicle_gps_position_s uint8_t satellite_elevation[20]; /**< Elevation (0: right on top of receiver, 90: on the horizon) of satellite */ uint8_t satellite_azimuth[20]; /**< Direction of satellite, 0: 0 deg, 255: 360 deg. */ uint8_t satellite_snr[20]; /**< Signal to noise ratio of satellite */ - uint8_t satellite_info_available; /**< 0 for no info, 1 for info available */ + bool satellite_info_available; /**< 0 for no info, 1 for info available */ }; /** -- cgit v1.2.3 From 6ed5d97aea29a284015708a6089b7910afea8369 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 6 Feb 2013 18:47:32 -0800 Subject: Merged mtk16 and mtk19 helper classes, configure() now writes directly instead of buffering --- apps/drivers/drv_gps.h | 13 +-------- apps/drivers/gps/gps.cpp | 53 +++++------------------------------- apps/drivers/gps/gps_helper.h | 3 ++- apps/drivers/gps/ubx.cpp | 62 +++++++++++++++++-------------------------- apps/drivers/gps/ubx.h | 11 +++++--- 5 files changed, 41 insertions(+), 101 deletions(-) diff --git a/apps/drivers/drv_gps.h b/apps/drivers/drv_gps.h index dfde115ef..67248efcd 100644 --- a/apps/drivers/drv_gps.h +++ b/apps/drivers/drv_gps.h @@ -50,8 +50,7 @@ typedef enum { GPS_DRIVER_MODE_UBX = 0, - GPS_DRIVER_MODE_MTK19, - GPS_DRIVER_MODE_MTK16, + GPS_DRIVER_MODE_MTK, GPS_DRIVER_MODE_NMEA, } gps_driver_mode_t; @@ -67,14 +66,4 @@ ORB_DECLARE(gps); #define _GPSIOCBASE (0x2800) //TODO: arbitrary choice... #define _GPSIOC(_n) (_IOC(_GPSIOCBASE, _n)) -/** configure ubx mode */ -#define GPS_CONFIGURE_UBX _GPSIOC(0) - -/** configure mtk mode */ -#define GPS_CONFIGURE_MTK19 _GPSIOC(1) -#define GPS_CONFIGURE_MTK16 _GPSIOC(2) - -/** configure mtk mode */ -#define GPS_CONFIGURE_NMEA _GPSIOC(3) - #endif /* _DRV_GPS_H */ diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 45f18158f..3e1aca810 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -72,6 +72,7 @@ #include #include "ubx.h" +#include "mtk.h" #define SEND_BUFFER_LENGTH 100 #define TIMEOUT 1000000 //1s @@ -238,30 +239,6 @@ GPS::ioctl(struct file *filp, int cmd, unsigned long arg) int ret = OK; switch (cmd) { - case GPS_CONFIGURE_UBX: - if (_mode != GPS_DRIVER_MODE_UBX) { - _mode = GPS_DRIVER_MODE_UBX; - _mode_changed = true; - } - break; - case GPS_CONFIGURE_MTK19: - if (_mode != GPS_DRIVER_MODE_MTK19) { - _mode = GPS_DRIVER_MODE_MTK19; - _mode_changed = true; - } - break; - case GPS_CONFIGURE_MTK16: - if (_mode != GPS_DRIVER_MODE_MTK16) { - _mode = GPS_DRIVER_MODE_MTK16; - _mode_changed = true; - } - break; - case GPS_CONFIGURE_NMEA: - if (_mode != GPS_DRIVER_MODE_NMEA) { - _mode = GPS_DRIVER_MODE_NMEA; - _mode_changed = true; - } - break; case SENSORIOCRESET: cmd_reset(); break; @@ -275,19 +252,7 @@ GPS::ioctl(struct file *filp, int cmd, unsigned long arg) void GPS::config() { - int length = 0; - uint8_t send_buffer[SEND_BUFFER_LENGTH]; - - _Helper->configure(send_buffer, length, SEND_BUFFER_LENGTH, _baudrate_changed, _baudrate); - - /* The config message is sent sent at the old baudrate */ - if (length > 0) { - - if (length != ::write(_serial_fd, send_buffer, length)) { - debug("write config failed"); - return; - } - } + _Helper->configure(_serial_fd, _baudrate_changed, _baudrate); /* Sometimes the baudrate needs to be changed, for instance UBX with factory settings are changed * from 9600 to 38400 @@ -356,11 +321,8 @@ GPS::task_main() case GPS_DRIVER_MODE_UBX: _Helper = new UBX(); break; - case GPS_DRIVER_MODE_MTK19: - //_Helper = new MTK19(); - break; - case GPS_DRIVER_MODE_MTK16: - //_Helper = new MTK16(); + case GPS_DRIVER_MODE_MTK: + _Helper = new MTK(); break; case GPS_DRIVER_MODE_NMEA: //_Helper = new NMEA(); @@ -530,11 +492,8 @@ GPS::print_info() case GPS_DRIVER_MODE_UBX: warnx("protocol: UBX"); break; - case GPS_DRIVER_MODE_MTK19: - warnx("protocol: MTK 1.9"); - break; - case GPS_DRIVER_MODE_MTK16: - warnx("protocol: MTK 1.6"); + case GPS_DRIVER_MODE_MTK: + warnx("protocol: MTK"); break; case GPS_DRIVER_MODE_NMEA: warnx("protocol: NMEA"); diff --git a/apps/drivers/gps/gps_helper.h b/apps/drivers/gps/gps_helper.h index 176b7eba8..576692c2a 100644 --- a/apps/drivers/gps/gps_helper.h +++ b/apps/drivers/gps/gps_helper.h @@ -36,12 +36,13 @@ /* @file U-Blox protocol definitions */ #ifndef GPS_HELPER_H +#define GPS_HELPER_H class GPS_Helper { public: virtual void reset(void) = 0; - virtual void configure(uint8_t *buffer, int &length, const unsigned max_length, bool &baudrate_changed, unsigned &baudrate) = 0; + virtual void configure(const int &fd, bool &baudrate_changed, unsigned &baudrate) = 0; virtual void parse(uint8_t, struct vehicle_gps_position_s*, bool &config_needed, bool &pos_updated) = 0; }; diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp index a82327175..8e2396564 100644 --- a/apps/drivers/gps/ubx.cpp +++ b/apps/drivers/gps/ubx.cpp @@ -68,11 +68,8 @@ UBX::reset() } void -UBX::configure(uint8_t *buffer, int &length, const unsigned max_length, bool &baudrate_changed, unsigned &baudrate) +UBX::configure(const int &fd, bool &baudrate_changed, unsigned &baudrate) { - /* make sure the buffer, where the message is written to, is long enough */ - assert(sizeof(type_gps_bin_cfg_prt_packet_t)+2 <= max_length); - /* Only send a new config message when we got the ACK of the last one, * otherwise we might not configure all the messages because the ACK comes from an older/previos CFD command * reason being that the ACK only includes CFG-MSG but not to which NAV MSG it belongs. @@ -105,16 +102,7 @@ UBX::configure(uint8_t *buffer, int &length, const unsigned max_length, bool &ba cfg_prt_packet.inProtoMask = UBX_CFG_PRT_PAYLOAD_INPROTOMASK; cfg_prt_packet.outProtoMask = UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK; - /* Calculate the checksum now */ - addChecksumToMessage((uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); - - /* Start with the two sync bytes */ - buffer[0] = UBX_SYNC1; - buffer[1] = UBX_SYNC2; - /* Copy it to the buffer that will be written back in the main gps driver */ - memcpy(&(buffer[2]), &cfg_prt_packet, sizeof(cfg_prt_packet)); - /* Set the length of the packet (plus the 2 sync bytes) */ - length = sizeof(cfg_prt_packet)+2; + sendConfigPacket(fd, (uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); } else if (_config_state == UBX_CONFIG_STATE_PRT_NEW_BAUDRATE) { @@ -131,12 +119,7 @@ UBX::configure(uint8_t *buffer, int &length, const unsigned max_length, bool &ba cfg_prt_packet.inProtoMask = UBX_CFG_PRT_PAYLOAD_INPROTOMASK; cfg_prt_packet.outProtoMask = UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK; - addChecksumToMessage((uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); - - buffer[0] = UBX_SYNC1; - buffer[1] = UBX_SYNC2; - memcpy(&(buffer[2]), &cfg_prt_packet, sizeof(cfg_prt_packet)); - length = sizeof(cfg_prt_packet)+2; + sendConfigPacket(fd, (uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); /* If the new baudrate will be different from the current one, we should report that back to the driver */ if (UBX_CFG_PRT_PAYLOAD_BAUDRATE != baudrate) { @@ -160,12 +143,7 @@ UBX::configure(uint8_t *buffer, int &length, const unsigned max_length, bool &ba cfg_rate_packet.navRate = UBX_CFG_RATE_PAYLOAD_NAVRATE; cfg_rate_packet.timeRef = UBX_CFG_RATE_PAYLOAD_TIMEREF; - addChecksumToMessage((uint8_t*)&cfg_rate_packet, sizeof(cfg_rate_packet)); - - buffer[0] = UBX_SYNC1; - buffer[1] = UBX_SYNC2; - memcpy(&(buffer[2]), &cfg_rate_packet, sizeof(cfg_rate_packet)); - length = sizeof(cfg_rate_packet)+2; + sendConfigPacket(fd, (uint8_t*)&cfg_rate_packet, sizeof(cfg_rate_packet)); } else if (_config_state == UBX_CONFIG_STATE_NAV5) { /* send a NAV5 message to set the options for the internal filter */ @@ -179,12 +157,7 @@ UBX::configure(uint8_t *buffer, int &length, const unsigned max_length, bool &ba cfg_nav5_packet.dynModel = UBX_CFG_NAV5_PAYLOAD_DYNMODEL; cfg_nav5_packet.fixMode = UBX_CFG_NAV5_PAYLOAD_FIXMODE; - addChecksumToMessage((uint8_t*)&cfg_nav5_packet, sizeof(cfg_nav5_packet)); - - buffer[0] = UBX_SYNC1; - buffer[1] = UBX_SYNC2; - memcpy(&(buffer[2]), &cfg_nav5_packet, sizeof(cfg_nav5_packet)); - length = sizeof(cfg_nav5_packet)+2; + sendConfigPacket(fd, (uint8_t*)&cfg_nav5_packet, sizeof(cfg_nav5_packet)); } else { /* Catch the remaining config states here, they all need the same packet type */ @@ -233,12 +206,7 @@ UBX::configure(uint8_t *buffer, int &length, const unsigned max_length, bool &ba break; } - addChecksumToMessage((uint8_t*)&cfg_msg_packet, sizeof(cfg_msg_packet)); - - buffer[0] = UBX_SYNC1; - buffer[1] = UBX_SYNC2; - memcpy(&(buffer[2]), &cfg_msg_packet, sizeof(cfg_msg_packet)); - length = sizeof(cfg_msg_packet)+2; + sendConfigPacket(fd, (uint8_t*)&cfg_msg_packet, sizeof(cfg_msg_packet)); } } } @@ -779,3 +747,21 @@ UBX::addChecksumToMessage(uint8_t* message, const unsigned length) message[length-2] = ck_a; message[length-1] = ck_b; } + +void +UBX::sendConfigPacket(const int &fd, uint8_t *packet, const unsigned length) +{ + ssize_t ret = 0; + + /* Calculate the checksum now */ + addChecksumToMessage(packet, length); + + const uint8_t sync_bytes[] = {UBX_SYNC1, UBX_SYNC2}; + + /* Start with the two sync bytes */ + ret += write(fd, sync_bytes, sizeof(sync_bytes)); + ret += write(fd, packet, length); + + if (ret != (int)length + (int)sizeof(sync_bytes)) // XXX is there a neater way to get rid of the unsigned signed warning? + warnx("ubx: config write fail"); +} diff --git a/apps/drivers/gps/ubx.h b/apps/drivers/gps/ubx.h index a23bb5502..c420e83b9 100644 --- a/apps/drivers/gps/ubx.h +++ b/apps/drivers/gps/ubx.h @@ -40,7 +40,6 @@ #include "gps_helper.h" - #define UBX_SYNC1 0xB5 #define UBX_SYNC2 0x62 @@ -341,7 +340,7 @@ public: UBX(); ~UBX(); void reset(void); - void configure(uint8_t *buffer, int &length, const unsigned max_length, bool &baudrate_changed, unsigned &baudrate); + void configure(const int &fd, bool &baudrate_changed, unsigned &baudrate); void parse(uint8_t, struct vehicle_gps_position_s*, bool &config_needed, bool &pos_updated); private: @@ -358,7 +357,13 @@ private: /** * Add the two checksum bytes to an outgoing message */ - void addChecksumToMessage(uint8_t*, const unsigned); + void addChecksumToMessage(uint8_t* message, const unsigned length); + + /** + * Helper to send a config packet + */ + void sendConfigPacket(const int &fd, uint8_t *packet, const unsigned length); + ubx_config_state_t _config_state; bool _waiting_for_ack; ubx_decode_state_t _decode_state; -- cgit v1.2.3 From 0d54661ce90dfe2440daea2639a9853520d8366c Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 6 Feb 2013 20:04:49 -0800 Subject: Added MTK 1.6, works after some seconds, work in progress --- apps/drivers/gps/gps.cpp | 43 +++++++---- apps/drivers/gps/mtk.cpp | 184 +++++++++++++++++++++++++++++++++++++++++++++++ apps/drivers/gps/mtk.h | 108 ++++++++++++++++++++++++++++ 3 files changed, 320 insertions(+), 15 deletions(-) create mode 100644 apps/drivers/gps/mtk.cpp create mode 100644 apps/drivers/gps/mtk.h diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 3e1aca810..c749e8b7f 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -77,7 +77,7 @@ #define SEND_BUFFER_LENGTH 100 #define TIMEOUT 1000000 //1s -#define NUMBER_OF_BAUDRATES 4 +#define NUMBER_OF_TRIES 5 #define CONFIG_TIMEOUT 2000000 /* oddly, ERROR is not defined for c++ */ @@ -113,7 +113,8 @@ private: int _serial_fd; ///< serial interface to GPS unsigned _baudrate; ///< current baudrate char _port[20]; ///< device / serial port path - const unsigned _baudrates_to_try[NUMBER_OF_BAUDRATES]; ///< try different baudrates that GPS could be set to + const unsigned _baudrates_to_try[NUMBER_OF_TRIES]; ///< try different baudrates that GPS could be set to + const gps_driver_mode_t _modes_to_try[NUMBER_OF_TRIES]; ///< try different modes volatile int _task; //< worker task bool _config_needed; ///< flag to signal that configuration of GPS is needed bool _baudrate_changed; ///< flag to signal that the baudrate with the GPS has changed @@ -170,11 +171,11 @@ GPS *g_dev; GPS::GPS(const char* uart_path) : CDev("gps", GPS_DEVICE_PATH), _task_should_exit(false), - _baudrates_to_try({9600, 38400, 57600, 115200}), + _baudrates_to_try({9600, 38400, 57600, 115200, 38400}), + _modes_to_try({GPS_DRIVER_MODE_UBX, GPS_DRIVER_MODE_UBX, GPS_DRIVER_MODE_UBX, GPS_DRIVER_MODE_UBX, GPS_DRIVER_MODE_MTK}), _config_needed(true), _baudrate_changed(false), - _mode_changed(true), - _mode(GPS_DRIVER_MODE_UBX), + _mode_changed(false), _Helper(nullptr), _report_pub(-1), _rate(0.0f) @@ -295,8 +296,10 @@ GPS::task_main() /* lock against the ioctl handler */ lock(); - unsigned baud_i = 0; - _baudrate = _baudrates_to_try[baud_i]; + unsigned try_i = 0; + _baudrate = _baudrates_to_try[try_i]; + _mode = _modes_to_try[try_i]; + _mode_changed = true; set_baudrate(_baudrate); uint64_t time_before_configuration = hrt_absolute_time(); @@ -310,6 +313,23 @@ GPS::task_main() /* loop handling received serial bytes and also configuring in between */ while (!_task_should_exit) { + /* If a configuration does not finish in the config timeout, change the baudrate */ + if (_config_needed && time_before_configuration + CONFIG_TIMEOUT < hrt_absolute_time()) { + /* loop through possible modes/baudrates */ + try_i = (try_i + 1) % NUMBER_OF_TRIES; + _baudrate = _baudrates_to_try[try_i]; + set_baudrate(_baudrate); + if (_mode != _modes_to_try[try_i]) { + _mode_changed = true; + } + _mode = _modes_to_try[try_i]; + + if (_Helper != nullptr) { + _Helper->reset(); + } + time_before_configuration = hrt_absolute_time(); + } + if (_mode_changed) { if (_Helper != nullptr) { delete(_Helper); @@ -333,14 +353,7 @@ GPS::task_main() _mode_changed = false; } - /* If a configuration does not finish in the config timeout, change the baudrate */ - if (_config_needed && time_before_configuration + CONFIG_TIMEOUT < hrt_absolute_time()) { - baud_i = (baud_i+1)%NUMBER_OF_BAUDRATES; - _baudrate = _baudrates_to_try[baud_i]; - set_baudrate(_baudrate); - _Helper->reset(); - time_before_configuration = hrt_absolute_time(); - } + /* during configuration, the timeout should be small, so that we can send config messages in between parsing, * but during normal operation, it should never timeout because updates should arrive with 5Hz */ diff --git a/apps/drivers/gps/mtk.cpp b/apps/drivers/gps/mtk.cpp new file mode 100644 index 000000000..555fb7a51 --- /dev/null +++ b/apps/drivers/gps/mtk.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** + * + * Copyright (C) 2013 PX4 Development Team. All rights reserved. + * Author: Thomas Gubler + * Julian Oes + * + * 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 PX4 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. + * + ****************************************************************************/ + +/* @file mkt.cpp */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mtk.h" + + +MTK::MTK() +{ + decodeInit(); +} + +MTK::~MTK() +{ +} + +void +MTK::reset() +{ + +} + +void +MTK::configure(const int &fd, bool &baudrate_changed, unsigned &baudrate) +{ + if (strlen(MTK_OUTPUT_5HZ) != write(fd, MTK_OUTPUT_5HZ, strlen(MTK_OUTPUT_5HZ))) + warnx("mtk: config write failed"); + usleep(10000); + + if (strlen(MTK_SET_BINARY) != write(fd, MTK_SET_BINARY, strlen(MTK_SET_BINARY))) + warnx("mtk: config write failed"); + usleep(10000); + + if (strlen(SBAS_ON) != write(fd, SBAS_ON, strlen(SBAS_ON))) + warnx("mtk: config write failed"); + usleep(10000); + + if (strlen(WAAS_ON) != write(fd, WAAS_ON, strlen(WAAS_ON))) + warnx("mtk: config write failed"); + usleep(10000); + + if (strlen(MTK_NAVTHRES_OFF) != write(fd, MTK_NAVTHRES_OFF, strlen(MTK_NAVTHRES_OFF))) + warnx("mtk: config write failed"); + + return; +} + +void +MTK::decodeInit(void) +{ + _rx_ck_a = 0; + _rx_ck_b = 0; + _rx_count = 0; + _decode_state = MTK_DECODE_UNINIT; +} + +void +MTK::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_needed, bool &pos_updated) +{ + if (_decode_state == MTK_DECODE_UNINIT) { + + if (b == 0xd0) { + _decode_state = MTK_DECODE_GOT_CK_A; + config_needed = false; + } + + } else if (_decode_state == MTK_DECODE_GOT_CK_A) { + if (b == 0xdd) { + _decode_state = MTK_DECODE_GOT_CK_B; + + } else { + // Second start symbol was wrong, reset state machine + decodeInit(); + } + + } else if (_decode_state == MTK_DECODE_GOT_CK_B) { + // Add to checksum + if (_rx_count < 33) + addByteToChecksum(b); + + // Fill packet buffer + _rx_buffer[_rx_count] = b; + _rx_count++; + + /* Packet size minus checksum */ + if (_rx_count >= 35) { + type_gps_mtk_packet *packet = (type_gps_mtk_packet *) _rx_buffer;; + + /* Check if checksum is valid */ + if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { + gps_position->lat = packet->latitude * 10; // from degrees*1e6 to degrees*1e7 + gps_position->lon = packet->longitude * 10; // from degrees*1e6 to degrees*1e7 + gps_position->alt = (int32_t)(packet->msl_altitude * 10); // from cm to mm + gps_position->fix_type = packet->fix_type; + gps_position->eph_m = packet->hdop; + gps_position->epv_m = 0.0; //unknown in mtk custom mode + gps_position->vel_m_s = ((float)packet->ground_speed)*1e-2f; // from cm/s to m/s + gps_position->cog_rad = ((float)packet->heading) * M_DEG_TO_RAD_F * 1e-2f; //from deg *100 to rad + gps_position->satellites_visible = packet->satellites; + + /* convert time and date information to unix timestamp */ + struct tm timeinfo; //TODO: test this conversion + uint32_t timeinfo_conversion_temp; + + timeinfo.tm_mday = packet->date * 1e-4; + timeinfo_conversion_temp = packet->date - timeinfo.tm_mday * 1e4; + timeinfo.tm_mon = timeinfo_conversion_temp * 1e-2 - 1; + timeinfo.tm_year = (timeinfo_conversion_temp - (timeinfo.tm_mon + 1) * 1e2) + 100; + + timeinfo.tm_hour = packet->utc_time * 1e-7; + timeinfo_conversion_temp = packet->utc_time - timeinfo.tm_hour * 1e7; + timeinfo.tm_min = timeinfo_conversion_temp * 1e-5; + timeinfo_conversion_temp -= timeinfo.tm_min * 1e5; + timeinfo.tm_sec = timeinfo_conversion_temp * 1e-3; + timeinfo_conversion_temp -= timeinfo.tm_sec * 1e3; + time_t epoch = mktime(&timeinfo); + + gps_position->time_gps_usec = epoch * 1e6; //TODO: test this + gps_position->time_gps_usec += timeinfo_conversion_temp * 1e3; + gps_position->timestamp_position = gps_position->timestamp_time = hrt_absolute_time(); + + pos_updated = true; + + + } else { + warnx("mtk Checksum invalid, 0x%x, 0x%x instead of 0x%x, 0x%x", _rx_ck_a, packet->ck_a, _rx_ck_b, packet->ck_b); + } + + // Reset state machine to decode next packet + decodeInit(); + } + } + return; +} + +void +MTK::addByteToChecksum(uint8_t b) +{ + _rx_ck_a = _rx_ck_a + b; + _rx_ck_b = _rx_ck_b + _rx_ck_a; +} diff --git a/apps/drivers/gps/mtk.h b/apps/drivers/gps/mtk.h new file mode 100644 index 000000000..8929eb041 --- /dev/null +++ b/apps/drivers/gps/mtk.h @@ -0,0 +1,108 @@ +/**************************************************************************** + * + * Copyright (C) 2008-2013 PX4 Development Team. All rights reserved. + * Author: Thomas Gubler + * Julian Oes + * + * 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 PX4 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. + * + ****************************************************************************/ + +/* @file mtk.h */ + +#ifndef MTK_H_ +#define MTK_H_ + +#include "gps_helper.h" + +#define MTK_SYNC1 0xd0 +#define MTK_SYNC2 0xdd + +#define MTK_OUTPUT_5HZ "$PMTK220,200*2C\r\n" +#define MTK_SET_BINARY "$PGCMD,16,0,0,0,0,0*6A\r\n" +#define SBAS_ON "$PMTK313,1*2E\r\n" +#define WAAS_ON "$PMTK301,2*2E\r\n" +#define MTK_NAVTHRES_OFF "$PMTK397,0*23\r\n" + +typedef enum { + MTK_DECODE_UNINIT = 0, + MTK_DECODE_GOT_CK_A = 1, + MTK_DECODE_GOT_CK_B = 2 +} mtk_decode_state_t; + +/** the structures of the binary packets */ +#pragma pack(push, 1) + +typedef struct { + uint8_t payload; ///< Number of payload bytes + int32_t latitude; ///< Latitude in degrees * 10^7 + int32_t longitude; ///< Longitude in degrees * 10^7 + uint32_t msl_altitude; ///< MSL altitude in meters * 10^2 + uint32_t ground_speed; ///< FIXME SPEC UNCLEAR + int32_t heading; + uint8_t satellites; + uint8_t fix_type; + uint32_t date; + uint32_t utc_time; + uint16_t hdop; + uint8_t ck_a; + uint8_t ck_b; +} type_gps_mtk_packet; + +#pragma pack(pop) + +#define MTK_RECV_BUFFER_SIZE 40 + +class MTK : public GPS_Helper +{ +public: + MTK(); + ~MTK(); + void reset(void); + void configure(const int &fd, bool &baudrate_changed, unsigned &baudrate); + void parse(uint8_t, struct vehicle_gps_position_s*, bool &config_needed, bool &pos_updated); + +private: + /** + * Reset the parse state machine for a fresh start + */ + void decodeInit(void); + + /** + * While parsing add every byte (except the sync bytes) to the checksum + */ + void addByteToChecksum(uint8_t); + + mtk_decode_state_t _decode_state; + uint8_t _rx_buffer[MTK_RECV_BUFFER_SIZE]; + unsigned _rx_count; + uint8_t _rx_ck_a; + uint8_t _rx_ck_b; +}; + +#endif /* MTK_H_ */ -- cgit v1.2.3 From b620136af4f8de913fd12872a91a80f62861dc4c Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 6 Feb 2013 22:58:52 -0800 Subject: Added support for MTK revision 19, working condition but configuration of MTK is very slow and needs improvement --- apps/drivers/gps/mtk.cpp | 25 +++++++++++++++++++------ apps/drivers/gps/mtk.h | 4 +++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/apps/drivers/gps/mtk.cpp b/apps/drivers/gps/mtk.cpp index 555fb7a51..bed388c49 100644 --- a/apps/drivers/gps/mtk.cpp +++ b/apps/drivers/gps/mtk.cpp @@ -48,7 +48,8 @@ #include "mtk.h" -MTK::MTK() +MTK::MTK() : +_mtk_revision(0) { decodeInit(); } @@ -102,13 +103,18 @@ MTK::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ { if (_decode_state == MTK_DECODE_UNINIT) { - if (b == 0xd0) { + if (b == MTK_SYNC1_V16) { _decode_state = MTK_DECODE_GOT_CK_A; config_needed = false; + _mtk_revision = 16; + } else if (b == MTK_SYNC1_V19) { + _decode_state = MTK_DECODE_GOT_CK_A; + config_needed = false; + _mtk_revision = 19; } } else if (_decode_state == MTK_DECODE_GOT_CK_A) { - if (b == 0xdd) { + if (b == MTK_SYNC2) { _decode_state = MTK_DECODE_GOT_CK_B; } else { @@ -131,11 +137,18 @@ MTK::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ /* Check if checksum is valid */ if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - gps_position->lat = packet->latitude * 10; // from degrees*1e6 to degrees*1e7 - gps_position->lon = packet->longitude * 10; // from degrees*1e6 to degrees*1e7 + if (_mtk_revision == 16) { + gps_position->lat = packet->latitude * 10; // from degrees*1e6 to degrees*1e7 + gps_position->lon = packet->longitude * 10; // from degrees*1e6 to degrees*1e7 + } else if (_mtk_revision == 19) { + gps_position->lat = packet->latitude; // both degrees*1e7 + gps_position->lon = packet->longitude; // both degrees*1e7 + } else { + warnx("mtk: unknown revision"); + } gps_position->alt = (int32_t)(packet->msl_altitude * 10); // from cm to mm gps_position->fix_type = packet->fix_type; - gps_position->eph_m = packet->hdop; + gps_position->eph_m = packet->hdop; // XXX: Check this because eph_m is in m and hdop is without unit gps_position->epv_m = 0.0; //unknown in mtk custom mode gps_position->vel_m_s = ((float)packet->ground_speed)*1e-2f; // from cm/s to m/s gps_position->cog_rad = ((float)packet->heading) * M_DEG_TO_RAD_F * 1e-2f; //from deg *100 to rad diff --git a/apps/drivers/gps/mtk.h b/apps/drivers/gps/mtk.h index 8929eb041..7a4b4f197 100644 --- a/apps/drivers/gps/mtk.h +++ b/apps/drivers/gps/mtk.h @@ -40,7 +40,8 @@ #include "gps_helper.h" -#define MTK_SYNC1 0xd0 +#define MTK_SYNC1_V16 0xd0 +#define MTK_SYNC1_V19 0xd1 #define MTK_SYNC2 0xdd #define MTK_OUTPUT_5HZ "$PMTK220,200*2C\r\n" @@ -99,6 +100,7 @@ private: void addByteToChecksum(uint8_t); mtk_decode_state_t _decode_state; + uint8_t _mtk_revision; uint8_t _rx_buffer[MTK_RECV_BUFFER_SIZE]; unsigned _rx_count; uint8_t _rx_ck_a; -- cgit v1.2.3 From d36eb8a3fcce358409a7205bbd75576a447ac7b4 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 6 Feb 2013 23:25:09 -0800 Subject: Sped up MTK configuration but the detection time can still be improved: timeouts/usleeps --- apps/drivers/gps/mtk.cpp | 34 ++++++++++++++++++++-------------- apps/drivers/gps/mtk.h | 3 ++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/apps/drivers/gps/mtk.cpp b/apps/drivers/gps/mtk.cpp index bed388c49..026b0660b 100644 --- a/apps/drivers/gps/mtk.cpp +++ b/apps/drivers/gps/mtk.cpp @@ -49,6 +49,7 @@ MTK::MTK() : +_config_sent(false), _mtk_revision(0) { decodeInit(); @@ -67,24 +68,29 @@ MTK::reset() void MTK::configure(const int &fd, bool &baudrate_changed, unsigned &baudrate) { - if (strlen(MTK_OUTPUT_5HZ) != write(fd, MTK_OUTPUT_5HZ, strlen(MTK_OUTPUT_5HZ))) - warnx("mtk: config write failed"); - usleep(10000); + if (_config_sent == false) { - if (strlen(MTK_SET_BINARY) != write(fd, MTK_SET_BINARY, strlen(MTK_SET_BINARY))) - warnx("mtk: config write failed"); - usleep(10000); + if (strlen(MTK_OUTPUT_5HZ) != write(fd, MTK_OUTPUT_5HZ, strlen(MTK_OUTPUT_5HZ))) + warnx("mtk: config write failed"); + usleep(10000); - if (strlen(SBAS_ON) != write(fd, SBAS_ON, strlen(SBAS_ON))) - warnx("mtk: config write failed"); - usleep(10000); + if (strlen(MTK_SET_BINARY) != write(fd, MTK_SET_BINARY, strlen(MTK_SET_BINARY))) + warnx("mtk: config write failed"); + usleep(10000); - if (strlen(WAAS_ON) != write(fd, WAAS_ON, strlen(WAAS_ON))) - warnx("mtk: config write failed"); - usleep(10000); + if (strlen(SBAS_ON) != write(fd, SBAS_ON, strlen(SBAS_ON))) + warnx("mtk: config write failed"); + usleep(10000); - if (strlen(MTK_NAVTHRES_OFF) != write(fd, MTK_NAVTHRES_OFF, strlen(MTK_NAVTHRES_OFF))) - warnx("mtk: config write failed"); + if (strlen(WAAS_ON) != write(fd, WAAS_ON, strlen(WAAS_ON))) + warnx("mtk: config write failed"); + usleep(10000); + + if (strlen(MTK_NAVTHRES_OFF) != write(fd, MTK_NAVTHRES_OFF, strlen(MTK_NAVTHRES_OFF))) + warnx("mtk: config write failed"); + + _config_sent = true; + } return; } diff --git a/apps/drivers/gps/mtk.h b/apps/drivers/gps/mtk.h index 7a4b4f197..e43637195 100644 --- a/apps/drivers/gps/mtk.h +++ b/apps/drivers/gps/mtk.h @@ -99,7 +99,8 @@ private: */ void addByteToChecksum(uint8_t); - mtk_decode_state_t _decode_state; + mtk_decode_state_t _decode_state; + bool _config_sent; uint8_t _mtk_revision; uint8_t _rx_buffer[MTK_RECV_BUFFER_SIZE]; unsigned _rx_count; -- cgit v1.2.3 From 5f52d3dc7fe8dee773eb67cb2541ef1d061478e6 Mon Sep 17 00:00:00 2001 From: px4dev Date: Sun, 3 Feb 2013 19:19:57 -0800 Subject: lib_lowprintf -> lowsyslog --- apps/px4io/mixer.cpp | 4 ++-- apps/systemlib/mixer/mixer_group.cpp | 2 +- apps/systemlib/mixer/mixer_multirotor.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/px4io/mixer.cpp b/apps/px4io/mixer.cpp index c24cb8e52..8e00781a0 100644 --- a/apps/px4io/mixer.cpp +++ b/apps/px4io/mixer.cpp @@ -144,7 +144,7 @@ mixer_tick(void) rc_channel_data[THROTTLE] = 1000; } - // lib_lowprintf("Tmin: %d Ttrim: %d Tmax: %d T: %d \n", + // lowsyslog("Tmin: %d Ttrim: %d Tmax: %d T: %d \n", // (int)(system_state.rc_min[THROTTLE]), (int)(system_state.rc_trim[THROTTLE]), // (int)(system_state.rc_max[THROTTLE]), (int)(rc_channel_data[THROTTLE])); @@ -156,7 +156,7 @@ mixer_tick(void) // XXX builtin failsafe would activate here control_count = 0; } - //lib_lowprintf("R: %d P: %d Y: %d T: %d \n", control_values[0], control_values[1], control_values[2], control_values[3]); + //lowsyslog("R: %d P: %d Y: %d T: %d \n", control_values[0], control_values[1], control_values[2], control_values[3]); /* this is for multicopters, etc. where manual override does not make sense */ } else { diff --git a/apps/systemlib/mixer/mixer_group.cpp b/apps/systemlib/mixer/mixer_group.cpp index 25d19f9ad..60eeff225 100644 --- a/apps/systemlib/mixer/mixer_group.cpp +++ b/apps/systemlib/mixer/mixer_group.cpp @@ -56,7 +56,7 @@ #define debug(fmt, args...) do { } while(0) //#define debug(fmt, args...) do { printf("[mixer] " fmt "\n", ##args); } while(0) //#include -//#define debug(fmt, args...) lib_lowprintf(fmt "\n", ##args) +//#define debug(fmt, args...) lowsyslog(fmt "\n", ##args) MixerGroup::MixerGroup(ControlCallback control_cb, uintptr_t cb_handle) : Mixer(control_cb, cb_handle), diff --git a/apps/systemlib/mixer/mixer_multirotor.cpp b/apps/systemlib/mixer/mixer_multirotor.cpp index f6e91b1bf..4b9cfc023 100644 --- a/apps/systemlib/mixer/mixer_multirotor.cpp +++ b/apps/systemlib/mixer/mixer_multirotor.cpp @@ -57,7 +57,7 @@ #define debug(fmt, args...) do { } while(0) //#define debug(fmt, args...) do { printf("[mixer] " fmt "\n", ##args); } while(0) //#include -//#define debug(fmt, args...) lib_lowprintf(fmt "\n", ##args) +//#define debug(fmt, args...) lowsyslog(fmt "\n", ##args) /* * Clockwise: 1 @@ -217,11 +217,11 @@ unsigned MultirotorMixer::mix(float *outputs, unsigned space) { float roll = get_control(0, 0) * _roll_scale; - //lib_lowprintf("roll: %d, get_control0: %d, %d\n", (int)(roll), (int)(get_control(0, 0)), (int)(_roll_scale)); + //lowsyslog("roll: %d, get_control0: %d, %d\n", (int)(roll), (int)(get_control(0, 0)), (int)(_roll_scale)); float pitch = get_control(0, 1) * _pitch_scale; float yaw = get_control(0, 2) * _yaw_scale; float thrust = get_control(0, 3); - //lib_lowprintf("thrust: %d, get_control3: %d\n", (int)(thrust), (int)(get_control(0, 3))); + //lowsyslog("thrust: %d, get_control3: %d\n", (int)(thrust), (int)(get_control(0, 3))); float max = 0.0f; float fixup_scale; -- cgit v1.2.3 From 7791704ef2784de04a7dadd7389e200ede78d738 Mon Sep 17 00:00:00 2001 From: px4dev Date: Sun, 3 Feb 2013 19:36:10 -0800 Subject: Back out the ADC DMA support. We aren't using or maintaining it, and it doesn't work "right" either. --- nuttx/arch/arm/src/stm32/stm32_adc.c | 315 +++++------------------------------ nuttx/arch/arm/src/stm32/stm32_adc.h | 6 + 2 files changed, 48 insertions(+), 273 deletions(-) diff --git a/nuttx/arch/arm/src/stm32/stm32_adc.c b/nuttx/arch/arm/src/stm32/stm32_adc.c index 844f1fd0f..b5033b057 100644 --- a/nuttx/arch/arm/src/stm32/stm32_adc.c +++ b/nuttx/arch/arm/src/stm32/stm32_adc.c @@ -118,25 +118,12 @@ struct stm32_dev_s uint32_t freq; /* The desired frequency of conversions */ #endif uint8_t chanlist[ADC_MAX_SAMPLES]; -#ifdef CONFIG_ADC_DMA - const unsigned int rxdma_channel; /* DMA channel assigned */ - DMA_HANDLE rxdma; /* currently-open receive DMA stream */ - bool rxenable; /* DMA-based reception en/disable */ - uint32_t rxdmanext; /* Next byte in the DMA buffer to be read */ - int32_t *const rxfifo; /* Receive DMA buffer */ -#endif }; /**************************************************************************** * Private Function Prototypes ****************************************************************************/ -# ifdef CONFIG_ADC_DMA -static int16_t g_adc3dmarxfifo[ADC_MAX_SAMPLES]; -# endif - - - /* ADC Register access */ static uint32_t adc_getreg(struct stm32_dev_s *priv, int offset); @@ -179,15 +166,6 @@ static int adc_timinit(FAR struct stm32_dev_s *priv); static void adc_startconv(FAR struct stm32_dev_s *priv, bool enable); #endif -#ifdef CONFIG_ADC_DMA -static int up_dma_setup(struct adc_dev_s *dev); -static void up_dma_shutdown(struct adc_dev_s *dev); -//static int up_dma_receive(struct uart_dev_s *dev, uint32_t *status); -//static void up_dma_rxint(struct uart_dev_s *dev, bool enable); -//static bool up_dma_rxavailable(struct uart_dev_s *dev); -static void up_dma_rxcallback(DMA_HANDLE handle, uint8_t status, FAR struct adc_dev_s *dev); -#endif - /**************************************************************************** * Private Data ****************************************************************************/ @@ -284,10 +262,6 @@ static struct stm32_dev_s g_adcpriv3 = .pclck = ADC3_TIMER_PCLK_FREQUENCY, .freq = CONFIG_STM32_ADC3_SAMPLE_FREQUENCY, #endif -#ifdef CONFIG_ADC_DMA - .rxdma_channel = DMAMAP_ADC3_2, - .rxfifo = g_adc3dmarxfifo, -#endif }; static struct adc_dev_s g_adcdev3 = @@ -569,7 +543,7 @@ static int adc_timinit(FAR struct stm32_dev_s *priv) * So ( prescaler = pclck / 65535 / freq ) would be optimal. */ - prescaler = 128;//(priv->pclck / priv->freq + 65534) / 65535; + prescaler = (priv->pclck / priv->freq + 65534) / 65535; /* We need to decrement the prescaler value by one, but only, the value does * not underflow. @@ -591,7 +565,7 @@ static int adc_timinit(FAR struct stm32_dev_s *priv) timclk = priv->pclck / prescaler; - reload = priv->freq;//timclk / priv->freq; + reload = timclk / priv->freq; if (reload < 1) { adbg("WARNING: Reload value underflowed.\n"); @@ -720,10 +694,10 @@ static int adc_timinit(FAR struct stm32_dev_s *priv) case 4: /* TimerX TRGO event */ { -#warning "TRGO support not yet implemented" - + /* TODO: TRGO support not yet implemented */ /* Set the event TRGO */ + ccenable = 0; egr = GTIM_EGR_TG; /* Set the duty cycle by writing to the CCR register for this channel */ @@ -936,139 +910,6 @@ static void adc_rccreset(struct stm32_dev_s *priv, bool reset) irqrestore(flags); } -/**************************************************************************** - * Name: up_dma_setup - * - * Description: - * - ****************************************************************************/ - -#ifdef CONFIG_ADC_DMA -static int up_dma_setup(FAR struct adc_dev_s *dev) -{ - - FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv; - int result; - uint32_t regval; - -// -// result = up_setup(dev); -// if (result != OK) -// { -// return result; -// } - - /* Acquire the DMA channel. This should always succeed. */ - - priv->rxdma = stm32_dmachannel(priv->rxdma_channel); - - /* Configure for circular DMA reception into the RX fifo */ - - stm32_dmasetup(priv->rxdma, - priv->base + STM32_ADC_DR_OFFSET, - (uint32_t)priv->rxfifo, - 4,//buffersize - DMA_SCR_DIR_P2M | - DMA_SCR_CIRC | - DMA_SCR_MINC | - DMA_SCR_PSIZE_16BITS | - DMA_SCR_MSIZE_16BITS | - DMA_SCR_PBURST_SINGLE | - DMA_SCR_MBURST_SINGLE); - - /* Reset our DMA shadow pointer to match the address just - * programmed above. - */ - - //priv->rxdmanext = 0; - - /* Enable DMA for the ADC */ - - /* Start the DMA channel, and arrange for callbacks at the half and - * full points in the FIFO. This ensures that we have half a FIFO - * worth of time to claim bytes before they are overwritten. - */ - - stm32_dmastart(priv->rxdma, up_dma_rxcallback, (void *)dev, false); - - return OK; -} -#endif -/**************************************************************************** - * Name: up_dma_rxcallback - * - * Description: - - * - ****************************************************************************/ - -#ifdef CONFIG_ADC_DMA -static void up_dma_rxcallback(DMA_HANDLE handle, uint8_t status, FAR struct adc_dev_s *dev) -{ - //struct up_dev_s *priv = (struct up_dev_s*)arg; - //uint32_t regval; - FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv; - //struct stm32_dma_s *dmast = (struct stm32_dma_s *)handle; - - //if (priv->rxenable && up_dma_rxavailable(&priv->dev)) - { - /* Give the ADC data to the ADC driver. adc_receive accepts 3 parameters: - * - * 1) The first is the ADC device instance for this ADC block. - * 2) The second is the channel number for the data, and - * 3) The third is the converted data for the channel. - */ - - - adc_receive(dev, 10, (int32_t)g_adc3dmarxfifo[1]); - adc_receive(dev, 11, (int32_t)g_adc3dmarxfifo[2]); - adc_receive(dev, 12, (int32_t)g_adc3dmarxfifo[3]); - adc_receive(dev, 13, (int32_t)g_adc3dmarxfifo[0]); - - - /* Set the channel number of the next channel that will complete conversion */ - - priv->current++; - - if (priv->current >= priv->nchannels) - { - /* Restart the conversion sequence from the beginning */ - - priv->current = 0; - } - - - } -} -#endif - -/**************************************************************************** - * Name: up_dma_shutdown - * - * Description: - * Disable the DMA - * - ****************************************************************************/ - -#ifdef CONFIG_ADC_DMA -static void up_dma_shutdown(struct adc_dev_s *dev) -{ - - FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv; - - - /* Stop the DMA channel */ - - stm32_dmastop(priv->rxdma); - - /* Release the DMA channel */ - - stm32_dmafree(priv->rxdma); - priv->rxdma = NULL; -} -#endif - - /******************************************************************************* * Name: adc_enable * @@ -1089,7 +930,7 @@ static void adc_enable(FAR struct stm32_dev_s *priv, bool enable) { uint32_t regval; - // avdbg("enable: %d\n", enable); + avdbg("enable: %d\n", enable); regval = adc_getreg(priv, STM32_ADC_CR2_OFFSET); if (enable) @@ -1123,12 +964,14 @@ static void adc_reset(FAR struct adc_dev_s *dev) uint32_t regval; int offset; int i; +#ifdef ADC_HAVE_TIMER int ret; +#endif avdbg("intf: ADC%d\n", priv->intf); flags = irqsave(); - /* Enable ADC reset state */ + /* Enable ADC reset state */ adc_rccreset(priv, true); @@ -1146,7 +989,6 @@ static void adc_reset(FAR struct adc_dev_s *dev) adc_putreg(priv, STM32_ADC_LTR_OFFSET, 0x00000000); - /* Initialize the same sample time for each ADC 55.5 cycles * * During sample cycles channel selection bits must remain unchanged. @@ -1179,8 +1021,16 @@ static void adc_reset(FAR struct adc_dev_s *dev) regval |= ADC_CR1_AWDEN; regval |= (priv->chanlist[0] << ADC_CR1_AWDCH_SHIFT); + /* Enable interrupt flags */ + + regval |= ADC_CR1_ALLINTS; + #if defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) + /* Enable or disable Overrun interrupt */ + + regval &= ~ADC_CR1_OVRIE; + /* Set the resolution of the conversion */ regval |= ACD_CR1_RES_12BIT; @@ -1229,12 +1079,6 @@ static void adc_reset(FAR struct adc_dev_s *dev) { regval |= (uint32_t)priv->chanlist[i] << offset; } - /* Set the number of conversions */ - - DEBUGASSERT(priv->nchannels <= ADC_MAX_SAMPLES); - - regval |= (((uint32_t)priv->nchannels-1) << ADC_SQR1_L_SHIFT); - adc_putreg(priv, STM32_ADC_SQR1_OFFSET, regval); /* ADC CCR configuration */ @@ -1246,7 +1090,12 @@ static void adc_reset(FAR struct adc_dev_s *dev) putreg32(regval, STM32_ADC_CCR); #endif + /* Set the number of conversions */ + DEBUGASSERT(priv->nchannels <= ADC_MAX_SAMPLES); + + regval |= (((uint32_t)priv->nchannels-1) << ADC_SQR1_L_SHIFT); + adc_putreg(priv, STM32_ADC_SQR1_OFFSET, regval); /* Set the channel index of the first conversion */ @@ -1269,30 +1118,25 @@ static void adc_reset(FAR struct adc_dev_s *dev) */ adc_enable(priv, true); -#else -#ifdef CONFIG_ADC_DMA - //nothing #else adc_startconv(priv, true); -#endif #endif /* CONFIG_STM32_STM32F10XX */ #endif /* ADC_HAVE_TIMER */ - irqrestore(flags); -// avdbg("SR: 0x%08x CR1: 0x%08x CR2: 0x%08x\n", -// adc_getreg(priv, STM32_ADC_SR_OFFSET), -// adc_getreg(priv, STM32_ADC_CR1_OFFSET), -// adc_getreg(priv, STM32_ADC_CR2_OFFSET)); -// avdbg("SQR1: 0x%08x SQR2: 0x%08x SQR3: 0x%08x\n", -// adc_getreg(priv, STM32_ADC_SQR1_OFFSET), -// adc_getreg(priv, STM32_ADC_SQR2_OFFSET), -// adc_getreg(priv, STM32_ADC_SQR3_OFFSET)); -//#if defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) -// avdbg("CCR: 0x%08x\n", -// getreg32(STM32_ADC_CCR)); -//#endif + avdbg("SR: 0x%08x CR1: 0x%08x CR2: 0x%08x\n", + adc_getreg(priv, STM32_ADC_SR_OFFSET), + adc_getreg(priv, STM32_ADC_CR1_OFFSET), + adc_getreg(priv, STM32_ADC_CR2_OFFSET)); + avdbg("SQR1: 0x%08x SQR2: 0x%08x SQR3: 0x%08x\n", + adc_getreg(priv, STM32_ADC_SQR1_OFFSET), + adc_getreg(priv, STM32_ADC_SQR2_OFFSET), + adc_getreg(priv, STM32_ADC_SQR3_OFFSET)); +#if defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) + avdbg("CCR: 0x%08x\n", + getreg32(STM32_ADC_CCR)); +#endif } /**************************************************************************** @@ -1314,86 +1158,21 @@ static int adc_setup(FAR struct adc_dev_s *dev) { FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv; int ret; - uint32_t regval; - - - /* the adc seems to need a full reset to be enabled correctly */ - adc_reset(dev); -#ifndef CONFIG_ADC_DMA /* Attach the ADC interrupt */ ret = irq_attach(priv->irq, priv->isr); if (ret == OK) { + /* Make sure that the ADC device is in the powered up, reset state */ + + adc_reset(dev); + /* Enable the ADC interrupt */ avdbg("Enable the ADC interrupt: irq=%d\n", priv->irq); up_enable_irq(priv->irq); } -#endif - -#ifdef CONFIG_ADC_DMA - up_dma_setup(dev); - - -//#ifndef ADC_HAVE_TIMER -// /*disable external trigger*/ -// regval = adc_getreg(priv, STM32_ADC_CR2_OFFSET); -// regval |= ACD_CR2_EXTEN_NONE; -// //regval |= ADC_CR1_DISCEN; -// adc_putreg(priv, STM32_ADC_CR2_OFFSET, regval); -//#else -// /*enable external trigger*/ -// regval = adc_getreg(priv, STM32_ADC_CR2_OFFSET); -// regval |=ADC_CR2_EXTSEL_T4CC4; -// regval |=ACD_CR2_EXTEN_BOTH; -// //regval |= ADC_CR2_CONT; -// adc_putreg(priv, STM32_ADC_CR2_OFFSET, regval); -//#endif - - - /*enable scan mode*/ - regval = adc_getreg(priv, STM32_ADC_CR1_OFFSET); - regval |= ADC_CR1_SCAN; - //regval |= ADC_CR1_DISCEN; - adc_putreg(priv, STM32_ADC_CR1_OFFSET, regval); - - /* Enable DMA request after last transfer (Single-ADC mode) */ - //ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE); - regval = adc_getreg(priv, STM32_ADC_CR2_OFFSET); - regval |= ADC_CR2_DDS; - adc_putreg(priv, STM32_ADC_CR2_OFFSET, regval); - - /* Enable ADC3 DMA */ - // ADC_DMACmd(ADC3, ENABLE); - regval = adc_getreg(priv, STM32_ADC_CR2_OFFSET); - regval |= ADC_CR2_DMA; - adc_putreg(priv, STM32_ADC_CR2_OFFSET, regval); -#endif - - -#ifndef ADC_HAVE_TIMER - /*set continuous conversion */ - regval = adc_getreg(priv, STM32_ADC_CR2_OFFSET); - regval |= ADC_CR2_CONT; - adc_putreg(priv, STM32_ADC_CR2_OFFSET, regval); -#endif - - /* Enable ADC3 */ - //ADC_Cmd(ADC3, ENABLE); - regval = adc_getreg(priv, STM32_ADC_CR2_OFFSET); - regval |= ADC_CR2_ADON; - adc_putreg(priv, STM32_ADC_CR2_OFFSET, regval); - -//// /*start conversion*/ -// regval = adc_getreg(priv, STM32_ADC_CR2_OFFSET); -// regval |= ADC_CR2_SWSTART; -// adc_putreg(priv, STM32_ADC_CR2_OFFSET, regval); - - - - return ret; } @@ -1415,24 +1194,14 @@ static void adc_shutdown(FAR struct adc_dev_s *dev) { FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv; -#ifdef CONFIG_ADC_DMA - up_dma_shutdown(dev); -#endif - -#ifdef ADC_HAVE_TIMER - /* stop adc timer */ - adc_timstart(priv, false); -#endif + /* Disable ADC interrupts and detach the ADC interrupt handler */ - /* power down ADC */ - adc_enable(priv, false); + up_disable_irq(priv->irq); + irq_detach(priv->irq); - adc_rxint(dev, false); + /* Disable and reset the ADC module */ - /* Disable ADC interrupts and detach the ADC interrupt handler */ - up_disable_irq(priv->irq); -// irq_detach(priv->irq); - // XXX Why is irq_detach here commented out? + adc_rccreset(priv, true); } /**************************************************************************** diff --git a/nuttx/arch/arm/src/stm32/stm32_adc.h b/nuttx/arch/arm/src/stm32/stm32_adc.h index 7b6c13b33..060fcdfb9 100644 --- a/nuttx/arch/arm/src/stm32/stm32_adc.h +++ b/nuttx/arch/arm/src/stm32/stm32_adc.h @@ -161,6 +161,12 @@ #if defined(CONFIG_STM32_ADC1) || defined(CONFIG_STM32_ADC2) || defined(CONFIG_STM32_ADC3) +/* DMA support is not yet implemented for this driver */ + +#ifdef CONFIG_ADC_DMA +# warning "DMA is not supported by the current driver" +#endif + /* Timer configuration: If a timer trigger is specified, then get information * about the timer. */ -- cgit v1.2.3 From 0c7c32ce95e2643d44fb41784c354cd6a852335c Mon Sep 17 00:00:00 2001 From: px4dev Date: Sun, 3 Feb 2013 19:36:54 -0800 Subject: Merge whitespace and comments so that we are closer to in sync with trunk. --- nuttx/arch/arm/src/stm32/stm32_i2c.c | 85 ++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/nuttx/arch/arm/src/stm32/stm32_i2c.c b/nuttx/arch/arm/src/stm32/stm32_i2c.c index 0062c072b..82ae6af5f 100644 --- a/nuttx/arch/arm/src/stm32/stm32_i2c.c +++ b/nuttx/arch/arm/src/stm32/stm32_i2c.c @@ -107,11 +107,11 @@ #if !defined(CONFIG_STM32_I2CTIMEOSEC) && !defined(CONFIG_STM32_I2CTIMEOMS) # define CONFIG_STM32_I2CTIMEOSEC 0 -# define CONFIG_STM32_I2CTIMEOMS 500 /* Default is 500 milliseconds */ +# define CONFIG_STM32_I2CTIMEOMS 500 /* Default is 500 milliseconds */ #elif !defined(CONFIG_STM32_I2CTIMEOSEC) # define CONFIG_STM32_I2CTIMEOSEC 0 /* User provided milliseconds */ #elif !defined(CONFIG_STM32_I2CTIMEOMS) -# define CONFIG_STM32_I2CTIMEOMS 0 /* User provided seconds */ +# define CONFIG_STM32_I2CTIMEOMS 0 /* User provided seconds */ #endif /* Interrupt wait time timeout in system timer ticks */ @@ -219,31 +219,31 @@ struct stm32_i2c_config_s struct stm32_i2c_priv_s { const struct stm32_i2c_config_s *config; /* Port configuration */ - int refs; /* Referernce count */ - sem_t sem_excl; /* Mutual exclusion semaphore */ + int refs; /* Referernce count */ + sem_t sem_excl; /* Mutual exclusion semaphore */ #ifndef CONFIG_I2C_POLLED - sem_t sem_isr; /* Interrupt wait semaphore */ + sem_t sem_isr; /* Interrupt wait semaphore */ #endif - volatile uint8_t intstate; /* Interrupt handshake (see enum stm32_intstate_e) */ + volatile uint8_t intstate; /* Interrupt handshake (see enum stm32_intstate_e) */ - uint8_t msgc; /* Message count */ - struct i2c_msg_s *msgv; /* Message list */ - uint8_t *ptr; /* Current message buffer */ - int dcnt; /* Current message length */ - uint16_t flags; /* Current message flags */ + uint8_t msgc; /* Message count */ + struct i2c_msg_s *msgv; /* Message list */ + uint8_t *ptr; /* Current message buffer */ + int dcnt; /* Current message length */ + uint16_t flags; /* Current message flags */ /* I2C trace support */ #ifdef CONFIG_I2C_TRACE - int tndx; /* Trace array index */ - uint32_t start_time; /* Time when the trace was started */ + int tndx; /* Trace array index */ + uint32_t start_time; /* Time when the trace was started */ /* The actual trace data */ struct stm32_trace_s trace[CONFIG_I2C_NTRACE]; #endif - uint32_t status; /* End of transfer SR2|SR1 status */ + uint32_t status; /* End of transfer SR2|SR1 status */ }; /* I2C Device, Instance */ @@ -281,7 +281,7 @@ static void stm32_i2c_tracenew(FAR struct stm32_i2c_priv_s *priv, uint32_t statu static void stm32_i2c_traceevent(FAR struct stm32_i2c_priv_s *priv, enum stm32_trace_e event, uint32_t parm); static void stm32_i2c_tracedump(FAR struct stm32_i2c_priv_s *priv); -#endif +#endif /* CONFIG_I2C_TRACE */ static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequency); static inline void stm32_i2c_sendstart(FAR struct stm32_i2c_priv_s *priv); @@ -291,7 +291,7 @@ static inline uint32_t stm32_i2c_getstatus(FAR struct stm32_i2c_priv_s *priv); #ifdef I2C1_FSMC_CONFLICT static inline uint32_t stm32_i2c_disablefsmc(FAR struct stm32_i2c_priv_s *priv); static inline void stm32_i2c_enablefsmc(uint32_t ahbenr); -#endif +#endif /* I2C1_FSMC_CONFLICT */ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv); #ifndef CONFIG_I2C_POLLED #ifdef CONFIG_STM32_I2C1 @@ -582,15 +582,14 @@ static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int abstime.tv_sec++; abstime.tv_nsec -= 1000 * 1000 * 1000; } -#else - #if CONFIG_STM32_I2CTIMEOMS > 0 - abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000; - if (abstime.tv_nsec > 1000 * 1000 * 1000) - { - abstime.tv_sec++; - abstime.tv_nsec -= 1000 * 1000 * 1000; - } - #endif + +#elif CONFIG_STM32_I2CTIMEOMS > 0 + abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000; + if (abstime.tv_nsec > 1000 * 1000 * 1000) + { + abstime.tv_sec++; + abstime.tv_nsec -= 1000 * 1000 * 1000; + } #endif /* Wait until either the transfer is complete or the timeout expires */ @@ -932,7 +931,7 @@ static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequ { /* Fast mode speed calculation with Tlow/Thigh = 16/9 */ -#ifdef CONFIG_I2C_DUTY16_9 +#ifdef CONFIG_STM32_I2C_DUTY16_9 speed = (uint16_t)(STM32_PCLK1_FREQUENCY / (frequency * 25)); /* Set DUTY and fast speed bits */ @@ -1071,7 +1070,7 @@ static inline uint32_t stm32_i2c_disablefsmc(FAR struct stm32_i2c_priv_s *priv) /* Is this I2C1 */ -#ifdef CONFIG_STM32_I2C2 +#if defined(CONFIG_STM32_I2C2) || defined(CONFIG_STM32_I2C3) if (priv->config->base == STM32_I2C1_BASE) #endif { @@ -1198,26 +1197,29 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv) { stm32_i2c_traceevent(priv, I2CEVENT_RCVBYTE, priv->dcnt); + /* No interrupts or context switches may occur in the following + * sequence. Otherwise, additional bytes may be sent by the + * device. + */ + #ifdef CONFIG_I2C_POLLED irqstate_t state = irqsave(); #endif - /* Receive a byte */ *priv->ptr++ = stm32_i2c_getreg(priv, STM32_I2C_DR_OFFSET); /* Disable acknowledge when last byte is to be received */ + priv->dcnt--; if (priv->dcnt == 1) { stm32_i2c_modifyreg(priv, STM32_I2C_CR1_OFFSET, I2C_CR1_ACK, 0); } - priv->dcnt--; #ifdef CONFIG_I2C_POLLED irqrestore(state); #endif - } } @@ -1408,7 +1410,6 @@ static int stm32_i2c_init(FAR struct stm32_i2c_priv_s *priv) /* Enable power and reset the peripheral */ modifyreg32(STM32_RCC_APB1ENR, 0, priv->config->clk_bit); - modifyreg32(STM32_RCC_APB1RSTR, 0, priv->config->reset_bit); modifyreg32(STM32_RCC_APB1RSTR, priv->config->reset_bit, 0); @@ -1428,10 +1429,10 @@ static int stm32_i2c_init(FAR struct stm32_i2c_priv_s *priv) /* Attach ISRs */ #ifndef CONFIG_I2C_POLLED - irq_attach(priv->config->ev_irq, priv->config->isr); - irq_attach(priv->config->er_irq, priv->config->isr); - up_enable_irq(priv->config->ev_irq); - up_enable_irq(priv->config->er_irq); + irq_attach(priv->config->ev_irq, priv->config->isr); + irq_attach(priv->config->er_irq, priv->config->isr); + up_enable_irq(priv->config->ev_irq); + up_enable_irq(priv->config->er_irq); #endif /* Set peripheral frequency, where it must be at least 2 MHz for 100 kHz @@ -1461,17 +1462,23 @@ static int stm32_i2c_deinit(FAR struct stm32_i2c_priv_s *priv) stm32_i2c_putreg(priv, STM32_I2C_CR1_OFFSET, 0); + /* Unconfigure GPIO pins */ + stm32_unconfiggpio(priv->config->scl_pin); stm32_unconfiggpio(priv->config->sda_pin); + /* Disable and detach interrupts */ + #ifndef CONFIG_I2C_POLLED up_disable_irq(priv->config->ev_irq); up_disable_irq(priv->config->er_irq); irq_detach(priv->config->ev_irq); irq_detach(priv->config->er_irq); #endif - modifyreg32(STM32_RCC_APB1ENR, priv->config->clk_bit, 0); + /* Disable clocking */ + + modifyreg32(STM32_RCC_APB1ENR, priv->config->clk_bit, 0); return OK; } @@ -1623,7 +1630,9 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms */ stm32_i2c_clrstart(priv); - // XXX also clear busy flag in case of timeout + + /* Clear busy flag in case of timeout */ + status = priv->status & 0xffff; } else @@ -2070,4 +2079,4 @@ out: return ret; } -#endif /* defined(CONFIG_STM32_I2C1) || defined(CONFIG_STM32_I2C2) || defined(CONFIG_STM32_I2C3) */ +#endif /* CONFIG_STM32_I2C1 || CONFIG_STM32_I2C2 || CONFIG_STM32_I2C3 */ -- cgit v1.2.3 From 8cb583cf8031f4e7db77e1b88ea164e7ff5994c9 Mon Sep 17 00:00:00 2001 From: px4dev Date: Wed, 6 Feb 2013 23:50:55 -0800 Subject: Assorted compile fixes. --- apps/drivers/boards/px4fmu/px4fmu_init.c | 4 ++-- apps/px4/tests/tests.h | 4 ++-- apps/px4io/px4io.c | 4 ++-- apps/px4io/px4io.h | 2 +- apps/systemlib/err.c | 8 ++++---- nuttx/include/nuttx/serial/serial.h | 3 --- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/apps/drivers/boards/px4fmu/px4fmu_init.c b/apps/drivers/boards/px4fmu/px4fmu_init.c index e88d2861e..9960c6bbd 100644 --- a/apps/drivers/boards/px4fmu/px4fmu_init.c +++ b/apps/drivers/boards/px4fmu/px4fmu_init.c @@ -79,13 +79,13 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_lowprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif #else # ifdef CONFIG_DEBUG -# define message lib_lowprintf +# define message lowsyslog # else # define message printf # endif diff --git a/apps/px4/tests/tests.h b/apps/px4/tests/tests.h index cc3f5493a..c02ea6808 100644 --- a/apps/px4/tests/tests.h +++ b/apps/px4/tests/tests.h @@ -48,7 +48,7 @@ #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG -# define message(...) lib_rawprintf(__VA_ARGS__) +# define message(...) lowsyslog(__VA_ARGS__) # define msgflush() # else # define message(...) printf(__VA_ARGS__) @@ -56,7 +56,7 @@ # endif #else # ifdef CONFIG_DEBUG -# define message lib_rawprintf +# define message lowsyslog # define msgflush() # else # define message printf diff --git a/apps/px4io/px4io.c b/apps/px4io/px4io.c index bea9d59bc..88342816e 100644 --- a/apps/px4io/px4io.c +++ b/apps/px4io/px4io.c @@ -73,7 +73,7 @@ int user_start(int argc, char *argv[]) hrt_init(); /* print some startup info */ - lib_lowprintf("\nPX4IO: starting\n"); + lowsyslog("\nPX4IO: starting\n"); /* default all the LEDs to off while we start */ LED_AMBER(false); @@ -98,7 +98,7 @@ int user_start(int argc, char *argv[]) struct mallinfo minfo = mallinfo(); - lib_lowprintf("free %u largest %u\n", minfo.mxordblk, minfo.fordblks); + lowsyslog("free %u largest %u\n", minfo.mxordblk, minfo.fordblks); /* we're done here, go run the communications loop */ comms_main(); diff --git a/apps/px4io/px4io.h b/apps/px4io/px4io.h index e388f65e3..3ce6afc31 100644 --- a/apps/px4io/px4io.h +++ b/apps/px4io/px4io.h @@ -58,7 +58,7 @@ #ifdef DEBUG # include -# define debug(fmt, args...) lib_lowprintf(fmt "\n", ##args) +# define debug(fmt, args...) lowsyslog(fmt "\n", ##args) #else # define debug(fmt, args...) do {} while(0) #endif diff --git a/apps/systemlib/err.c b/apps/systemlib/err.c index 3011743a1..daf17ef8b 100644 --- a/apps/systemlib/err.c +++ b/apps/systemlib/err.c @@ -85,17 +85,17 @@ warnerr_core(int errcode, const char *fmt, va_list args) fprintf(stderr, "\n"); #elif CONFIG_ARCH_LOWPUTC - lib_lowprintf("%s: ", getprogname()); - lib_lowvprintf(fmt, args); + lowsyslog("%s: ", getprogname()); + lowvyslog(fmt, args); /* convenience as many parts of NuttX use negative errno */ if (errcode < 0) errcode = -errcode; if (errcode < NOCODE) - lib_lowprintf(": %s", strerror(errcode)); + lowsyslog(": %s", strerror(errcode)); - lib_lowprintf("\n"); + lowsyslog("\n"); #endif } diff --git a/nuttx/include/nuttx/serial/serial.h b/nuttx/include/nuttx/serial/serial.h index d72038e17..4ee2005ef 100644 --- a/nuttx/include/nuttx/serial/serial.h +++ b/nuttx/include/nuttx/serial/serial.h @@ -220,7 +220,6 @@ struct uart_dev_s #ifndef CONFIG_DISABLE_POLL struct pollfd *fds[CONFIG_SERIAL_NPOLLWAITERS]; #endif -<<<<<<< HEAD /* Terminal control flags */ @@ -230,8 +229,6 @@ struct uart_dev_s tcflag_t tc_lflag; /* Local modes */ #endif -======= ->>>>>>> 049c93446561c6ad3e59183c139f3916230ddee5 }; typedef struct uart_dev_s uart_dev_t; -- cgit v1.2.3 From caa11f0bbb7f30679c5c01a64e1d0f6d8627db9d Mon Sep 17 00:00:00 2001 From: px4dev Date: Wed, 6 Feb 2013 23:52:57 -0800 Subject: New option to ensure serial stack is always included. --- nuttx/configs/px4fmu/nsh/defconfig | 1 + nuttx/configs/px4io/io/defconfig | 1 + 2 files changed, 2 insertions(+) diff --git a/nuttx/configs/px4fmu/nsh/defconfig b/nuttx/configs/px4fmu/nsh/defconfig index fd783dec5..5a54e350c 100755 --- a/nuttx/configs/px4fmu/nsh/defconfig +++ b/nuttx/configs/px4fmu/nsh/defconfig @@ -246,6 +246,7 @@ CONFIG_AT24XX_MTD_BLOCKSIZE=256 # CONFIG_SERIAL_TERMIOS=y CONFIG_SERIAL_CONSOLE_REINIT=y +CONFIG_STANDARD_SERIAL=y CONFIG_USART1_SERIAL_CONSOLE=y CONFIG_USART2_SERIAL_CONSOLE=n diff --git a/nuttx/configs/px4io/io/defconfig b/nuttx/configs/px4io/io/defconfig index 30ec5be08..1185813db 100755 --- a/nuttx/configs/px4io/io/defconfig +++ b/nuttx/configs/px4io/io/defconfig @@ -159,6 +159,7 @@ CONFIG_STM32_ADC3=n # CONFIG_USARTn_2STOP - Two stop bits # CONFIG_SERIAL_TERMIOS=y +CONFIG_STANDARD_SERIAL=y CONFIG_USART1_SERIAL_CONSOLE=y CONFIG_USART2_SERIAL_CONSOLE=n -- cgit v1.2.3 From a88b9f4eefe8315cb692779dd300400d8052eb44 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 7 Feb 2013 14:48:00 -0800 Subject: Restructered the parsing/configuring, MTK working --- apps/drivers/gps/gps.cpp | 243 ++++++++-------------------------------- apps/drivers/gps/gps_helper.cpp | 90 +++++++++++++++ apps/drivers/gps/gps_helper.h | 11 +- apps/drivers/gps/mtk.cpp | 238 ++++++++++++++++++++++++--------------- apps/drivers/gps/mtk.h | 35 ++++-- 5 files changed, 314 insertions(+), 303 deletions(-) create mode 100644 apps/drivers/gps/gps_helper.cpp diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index c749e8b7f..76b5f4533 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -53,7 +53,6 @@ #include #include #include -#include #include #include @@ -71,7 +70,7 @@ #include -#include "ubx.h" +//#include "ubx.h" #include "mtk.h" #define SEND_BUFFER_LENGTH 100 @@ -113,10 +112,8 @@ private: int _serial_fd; ///< serial interface to GPS unsigned _baudrate; ///< current baudrate char _port[20]; ///< device / serial port path - const unsigned _baudrates_to_try[NUMBER_OF_TRIES]; ///< try different baudrates that GPS could be set to - const gps_driver_mode_t _modes_to_try[NUMBER_OF_TRIES]; ///< try different modes volatile int _task; //< worker task - bool _config_needed; ///< flag to signal that configuration of GPS is needed + bool _healthy; ///< flag to signal if the GPS is ok bool _baudrate_changed; ///< flag to signal that the baudrate with the GPS has changed bool _mode_changed; ///< flag that the GPS mode has changed gps_driver_mode_t _mode; ///< current mode @@ -171,11 +168,9 @@ GPS *g_dev; GPS::GPS(const char* uart_path) : CDev("gps", GPS_DEVICE_PATH), _task_should_exit(false), - _baudrates_to_try({9600, 38400, 57600, 115200, 38400}), - _modes_to_try({GPS_DRIVER_MODE_UBX, GPS_DRIVER_MODE_UBX, GPS_DRIVER_MODE_UBX, GPS_DRIVER_MODE_UBX, GPS_DRIVER_MODE_MTK}), - _config_needed(true), - _baudrate_changed(false), + _healthy(false), _mode_changed(false), + _mode(GPS_DRIVER_MODE_MTK), _Helper(nullptr), _report_pub(-1), _rate(0.0f) @@ -250,20 +245,6 @@ GPS::ioctl(struct file *filp, int cmd, unsigned long arg) return ret; } -void -GPS::config() -{ - _Helper->configure(_serial_fd, _baudrate_changed, _baudrate); - - /* Sometimes the baudrate needs to be changed, for instance UBX with factory settings are changed - * from 9600 to 38400 - */ - if (_baudrate_changed) { - set_baudrate(_baudrate); - _baudrate_changed = false; - } -} - void GPS::task_main_trampoline(void *arg) { @@ -276,10 +257,7 @@ GPS::task_main() log("starting"); /* open the serial port */ - _serial_fd = ::open(_port, O_RDWR); //TODO make the device dynamic depending on startup parameters - - /* buffer to read from the serial port */ - uint8_t buf[32]; + _serial_fd = ::open(_port, O_RDWR); if (_serial_fd < 0) { log("failed to open serial port: %s err: %d", _port, errno); @@ -288,151 +266,65 @@ GPS::task_main() _exit(1); } - /* poll descriptor */ - pollfd fds[1]; - fds[0].fd = _serial_fd; - fds[0].events = POLLIN; - - /* lock against the ioctl handler */ - lock(); - - unsigned try_i = 0; - _baudrate = _baudrates_to_try[try_i]; - _mode = _modes_to_try[try_i]; - _mode_changed = true; - set_baudrate(_baudrate); - - uint64_t time_before_configuration = hrt_absolute_time(); - uint64_t last_rate_measurement = hrt_absolute_time(); unsigned last_rate_count = 0; - bool pos_updated; - bool config_needed_res; - /* loop handling received serial bytes and also configuring in between */ while (!_task_should_exit) { - /* If a configuration does not finish in the config timeout, change the baudrate */ - if (_config_needed && time_before_configuration + CONFIG_TIMEOUT < hrt_absolute_time()) { - /* loop through possible modes/baudrates */ - try_i = (try_i + 1) % NUMBER_OF_TRIES; - _baudrate = _baudrates_to_try[try_i]; - set_baudrate(_baudrate); - if (_mode != _modes_to_try[try_i]) { - _mode_changed = true; - } - _mode = _modes_to_try[try_i]; - - if (_Helper != nullptr) { - _Helper->reset(); - } - time_before_configuration = hrt_absolute_time(); + if (_Helper != nullptr) { + delete(_Helper); + /* set to zero to ensure parser is not used while not instantiated */ + _Helper = nullptr; } - if (_mode_changed) { - if (_Helper != nullptr) { - delete(_Helper); - /* set to zero to ensure parser is not used while not instantiated */ - _Helper = nullptr; - } - - switch (_mode) { - case GPS_DRIVER_MODE_UBX: - _Helper = new UBX(); - break; + switch (_mode) { +// case GPS_DRIVER_MODE_UBX: +// _Helper = new UBX(); +// break; case GPS_DRIVER_MODE_MTK: + printf("try new mtk\n"); _Helper = new MTK(); break; case GPS_DRIVER_MODE_NMEA: - //_Helper = new NMEA(); + //_Helper = new NMEA(); //TODO: add NMEA break; default: break; - } - _mode_changed = false; } - - - - /* during configuration, the timeout should be small, so that we can send config messages in between parsing, - * but during normal operation, it should never timeout because updates should arrive with 5Hz */ - int poll_timeout; - if (_config_needed) { - poll_timeout = 50; - } else { - poll_timeout = 400; - } - /* sleep waiting for data, but no more than the poll timeout */ + // XXX unlock/lock makes sense? unlock(); - int ret = ::poll(fds, sizeof(fds) / sizeof(fds[0]), poll_timeout); - lock(); + if (_Helper->configure(_serial_fd, _baudrate) == 0) { + + while (_Helper->receive(_serial_fd, _report) > 0 && !_task_should_exit) { + /* opportunistic publishing - else invalid data would end up on the bus */ + if (_report_pub > 0) { + orb_publish(ORB_ID(vehicle_gps_position), _report_pub, &_report); + } else { + _report_pub = orb_advertise(ORB_ID(vehicle_gps_position), &_report); + } + last_rate_count++; - /* this would be bad... */ - if (ret < 0) { - log("poll error %d", errno); - } else if (ret == 0) { - /* no response from the GPS */ - if (_config_needed == false) { - _config_needed = true; - warnx("GPS module timeout"); - _Helper->reset(); - } - config(); - } else if (ret > 0) { - /* if we have new data from GPS, go handle it */ - if (fds[0].revents & POLLIN) { - int count; - - /* - * We are here because poll says there is some data, so this - * won't block even on a blocking device. If more bytes are - * available, we'll go back to poll() again... - */ - count = ::read(_serial_fd, buf, sizeof(buf)); - - /* pass received bytes to the packet decoder */ - int j; - for (j = 0; j < count; j++) { - pos_updated = false; - config_needed_res = _config_needed; - _Helper->parse(buf[j], &_report, config_needed_res, pos_updated); - - if (pos_updated) { - /* opportunistic publishing - else invalid data would end up on the bus */ - if (_report_pub > 0) { - orb_publish(ORB_ID(vehicle_gps_position), _report_pub, &_report); - } else { - _report_pub = orb_advertise(ORB_ID(vehicle_gps_position), &_report); - } - last_rate_count++; - - /* measure update rate every 5 seconds */ - if (hrt_absolute_time() - last_rate_measurement > 5000000) { - _rate = last_rate_count / ((float)((hrt_absolute_time() - last_rate_measurement)) / 1000000.0f); - last_rate_measurement = hrt_absolute_time(); - last_rate_count = 0; - } - - } - if (config_needed_res == true && _config_needed == false) { - /* the parser told us that an error happened and reconfiguration is needed */ - _config_needed = true; - warnx("GPS module lost"); - _Helper->reset(); - config(); - } else if (config_needed_res == true && _config_needed == true) { - /* we are still configuring */ - config(); - } else if (config_needed_res == false && _config_needed == true) { - /* the parser is happy, stop configuring */ - warnx("GPS module found"); - _config_needed = false; - } + /* measure update rate every 5 seconds */ + if (hrt_absolute_time() - last_rate_measurement > 5000000) { + _rate = last_rate_count / ((float)((hrt_absolute_time() - last_rate_measurement)) / 1000000.0f); + last_rate_measurement = hrt_absolute_time(); + last_rate_count = 0; + } + + if (!_healthy) { + warnx("module found"); + _healthy = true; } } + if (_healthy) { + warnx("module lost"); + _healthy = false; + _rate = 0.0f; + } } + lock(); } debug("exiting"); @@ -443,59 +335,12 @@ GPS::task_main() _exit(0); } -int -GPS::set_baudrate(unsigned baud) -{ - /* process baud rate */ - int speed; - - switch (baud) { - case 9600: speed = B9600; break; - - case 19200: speed = B19200; break; - case 38400: speed = B38400; break; - - case 57600: speed = B57600; break; - - case 115200: speed = B115200; break; - - default: - warnx("ERROR: Unsupported baudrate: %d\n", baud); - return -EINVAL; - } - struct termios uart_config; - int termios_state; - - /* fill the struct for the new configuration */ - tcgetattr(_serial_fd, &uart_config); - - /* clear ONLCR flag (which appends a CR for every LF) */ - uart_config.c_oflag &= ~ONLCR; - /* no parity, one stop bit */ - uart_config.c_cflag &= ~(CSTOPB | PARENB); - - /* set baud rate */ - if ((termios_state = cfsetispeed(&uart_config, speed)) < 0) { - warnx("ERROR setting config: %d (cfsetispeed)\n", termios_state); - return -1; - } - if ((termios_state = cfsetospeed(&uart_config, speed)) < 0) { - warnx("ERROR setting config: %d (cfsetospeed)\n", termios_state); - return -1; - } - if ((termios_state = tcsetattr(_serial_fd, TCSANOW, &uart_config)) < 0) { - warnx("ERROR setting baudrate (tcsetattr)\n"); - return -1; - } - /* XXX if resetting the parser here, ensure it does exist (check for null pointer) */ - return 0; -} void GPS::cmd_reset() { - _config_needed = true; + //XXX add reset? } void @@ -514,7 +359,7 @@ GPS::print_info() default: break; } - warnx("port: %s, baudrate: %d, status: %s", _port, _baudrate, (_config_needed) ? "NOT OK" : "OK"); + warnx("port: %s, baudrate: %d, status: %s", _port, _baudrate, (_healthy) ? "OK" : "NOT OK"); if (_report.timestamp_position != 0) { warnx("position lock: %dD, last update %4.2f seconds ago", (int)_report.fix_type, (double)((float)(hrt_absolute_time() - _report.timestamp_position) / 1000000.0f)); diff --git a/apps/drivers/gps/gps_helper.cpp b/apps/drivers/gps/gps_helper.cpp new file mode 100644 index 000000000..2caa82af1 --- /dev/null +++ b/apps/drivers/gps/gps_helper.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** + * + * Copyright (C) 2008-2013 PX4 Development Team. All rights reserved. + * Author: Thomas Gubler + * Julian Oes + * + * 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 PX4 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 +#include +#include +#include "gps_helper.h" + +/* @file gps_helper.cpp */ + +int +GPS_Helper::set_baudrate(const int &fd, unsigned baud) +{ + /* process baud rate */ + int speed; + + switch (baud) { + case 9600: speed = B9600; break; + + case 19200: speed = B19200; break; + + case 38400: speed = B38400; break; + + case 57600: speed = B57600; break; + + case 115200: speed = B115200; break; + + default: + warnx("ERROR: Unsupported baudrate: %d\n", baud); + return -EINVAL; + } + struct termios uart_config; + int termios_state; + + /* fill the struct for the new configuration */ + tcgetattr(fd, &uart_config); + + /* clear ONLCR flag (which appends a CR for every LF) */ + uart_config.c_oflag &= ~ONLCR; + /* no parity, one stop bit */ + uart_config.c_cflag &= ~(CSTOPB | PARENB); + + /* set baud rate */ + if ((termios_state = cfsetispeed(&uart_config, speed)) < 0) { + warnx("ERROR setting config: %d (cfsetispeed)\n", termios_state); + return -1; + } + if ((termios_state = cfsetospeed(&uart_config, speed)) < 0) { + warnx("ERROR setting config: %d (cfsetospeed)\n", termios_state); + return -1; + } + if ((termios_state = tcsetattr(fd, TCSANOW, &uart_config)) < 0) { + warnx("ERROR setting baudrate (tcsetattr)\n"); + return -1; + } + /* XXX if resetting the parser here, ensure it does exist (check for null pointer) */ + return 0; +} diff --git a/apps/drivers/gps/gps_helper.h b/apps/drivers/gps/gps_helper.h index 576692c2a..537ca819c 100644 --- a/apps/drivers/gps/gps_helper.h +++ b/apps/drivers/gps/gps_helper.h @@ -33,17 +33,20 @@ * ****************************************************************************/ -/* @file U-Blox protocol definitions */ +/* @file gps_helper.h */ #ifndef GPS_HELPER_H #define GPS_HELPER_H +#include +#include + class GPS_Helper { public: - virtual void reset(void) = 0; - virtual void configure(const int &fd, bool &baudrate_changed, unsigned &baudrate) = 0; - virtual void parse(uint8_t, struct vehicle_gps_position_s*, bool &config_needed, bool &pos_updated) = 0; + virtual int configure(const int &fd, unsigned &baud) = 0; + virtual int receive(const int &fd, struct vehicle_gps_position_s &gps_position) = 0; + int set_baudrate(const int &fd, unsigned baud); }; #endif /* GPS_HELPER_H */ diff --git a/apps/drivers/gps/mtk.cpp b/apps/drivers/gps/mtk.cpp index 026b0660b..4ccbbfbe4 100644 --- a/apps/drivers/gps/mtk.cpp +++ b/apps/drivers/gps/mtk.cpp @@ -37,85 +37,143 @@ #include #include +#include #include #include #include #include -#include -#include #include #include "mtk.h" MTK::MTK() : -_config_sent(false), _mtk_revision(0) { - decodeInit(); + decode_init(); } MTK::~MTK() { } -void -MTK::reset() +int +MTK::configure(const int &fd, unsigned &baudrate) { + /* set baudrate first */ + if (GPS_Helper::set_baudrate(fd, MTK_BAUDRATE) != 0) + return -1; -} + baudrate = MTK_BAUDRATE; -void -MTK::configure(const int &fd, bool &baudrate_changed, unsigned &baudrate) -{ - if (_config_sent == false) { + /* Write config messages, don't wait for an answer */ + if (strlen(MTK_OUTPUT_5HZ) != write(fd, MTK_OUTPUT_5HZ, strlen(MTK_OUTPUT_5HZ))) { + warnx("mtk: config write failed"); + return -1; + } + usleep(10000); - if (strlen(MTK_OUTPUT_5HZ) != write(fd, MTK_OUTPUT_5HZ, strlen(MTK_OUTPUT_5HZ))) - warnx("mtk: config write failed"); - usleep(10000); + if (strlen(MTK_SET_BINARY) != write(fd, MTK_SET_BINARY, strlen(MTK_SET_BINARY))) { + warnx("mtk: config write failed"); + return -1; + } + usleep(10000); - if (strlen(MTK_SET_BINARY) != write(fd, MTK_SET_BINARY, strlen(MTK_SET_BINARY))) - warnx("mtk: config write failed"); - usleep(10000); + if (strlen(SBAS_ON) != write(fd, SBAS_ON, strlen(SBAS_ON))) { + warnx("mtk: config write failed"); + return -1; + } + usleep(10000); - if (strlen(SBAS_ON) != write(fd, SBAS_ON, strlen(SBAS_ON))) - warnx("mtk: config write failed"); - usleep(10000); + if (strlen(WAAS_ON) != write(fd, WAAS_ON, strlen(WAAS_ON))) { + warnx("mtk: config write failed"); + return -1; + } + usleep(10000); - if (strlen(WAAS_ON) != write(fd, WAAS_ON, strlen(WAAS_ON))) - warnx("mtk: config write failed"); - usleep(10000); + if (strlen(MTK_NAVTHRES_OFF) != write(fd, MTK_NAVTHRES_OFF, strlen(MTK_NAVTHRES_OFF))) { + warnx("mtk: config write failed"); + return -1; + } - if (strlen(MTK_NAVTHRES_OFF) != write(fd, MTK_NAVTHRES_OFF, strlen(MTK_NAVTHRES_OFF))) - warnx("mtk: config write failed"); + return 0; +} - _config_sent = true; - } +int +MTK::receive(const int &fd, struct vehicle_gps_position_s &gps_position) +{ + /* poll descriptor */ + pollfd fds[1]; + fds[0].fd = fd; + fds[0].events = POLLIN; + + uint8_t buf[32]; + gps_mtk_packet_t packet; + + int j = 0; + ssize_t count = 0; + + while (true) { + + /* first read whatever is left */ + if (j < count) { + /* pass received bytes to the packet decoder */ + while (j < count) { + if (parse_char(buf[j], packet) > 0) { + handle_message(packet, gps_position); + return 1; + } + j++; + } + /* everything is read */ + j = count = 0; + } - return; + /* then poll for new data */ + int ret = ::poll(fds, sizeof(fds) / sizeof(fds[0]), MTK_TIMEOUT_5HZ); + + if (ret < 0) { + /* something went wrong when polling */ + return -1; + + } else if (ret == 0) { + /* Timeout */ + return -1; + + } else if (ret > 0) { + /* if we have new data from GPS, go handle it */ + if (fds[0].revents & POLLIN) { + /* + * We are here because poll says there is some data, so this + * won't block even on a blocking device. If more bytes are + * available, we'll go back to poll() again... + */ + count = ::read(fd, buf, sizeof(buf)); + } + } + } } void -MTK::decodeInit(void) +MTK::decode_init(void) { _rx_ck_a = 0; _rx_ck_b = 0; _rx_count = 0; _decode_state = MTK_DECODE_UNINIT; } - -void -MTK::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_needed, bool &pos_updated) +int +MTK::parse_char(uint8_t b, gps_mtk_packet_t &packet) { + int ret = 0; + if (_decode_state == MTK_DECODE_UNINIT) { if (b == MTK_SYNC1_V16) { _decode_state = MTK_DECODE_GOT_CK_A; - config_needed = false; _mtk_revision = 16; } else if (b == MTK_SYNC1_V19) { _decode_state = MTK_DECODE_GOT_CK_A; - config_needed = false; _mtk_revision = 19; } @@ -125,78 +183,82 @@ MTK::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ } else { // Second start symbol was wrong, reset state machine - decodeInit(); + decode_init(); } } else if (_decode_state == MTK_DECODE_GOT_CK_B) { // Add to checksum if (_rx_count < 33) - addByteToChecksum(b); + add_byte_to_checksum(b); // Fill packet buffer - _rx_buffer[_rx_count] = b; + ((uint8_t*)(&packet))[_rx_count] = b; _rx_count++; - /* Packet size minus checksum */ - if (_rx_count >= 35) { - type_gps_mtk_packet *packet = (type_gps_mtk_packet *) _rx_buffer;; - - /* Check if checksum is valid */ - if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - if (_mtk_revision == 16) { - gps_position->lat = packet->latitude * 10; // from degrees*1e6 to degrees*1e7 - gps_position->lon = packet->longitude * 10; // from degrees*1e6 to degrees*1e7 - } else if (_mtk_revision == 19) { - gps_position->lat = packet->latitude; // both degrees*1e7 - gps_position->lon = packet->longitude; // both degrees*1e7 - } else { - warnx("mtk: unknown revision"); - } - gps_position->alt = (int32_t)(packet->msl_altitude * 10); // from cm to mm - gps_position->fix_type = packet->fix_type; - gps_position->eph_m = packet->hdop; // XXX: Check this because eph_m is in m and hdop is without unit - gps_position->epv_m = 0.0; //unknown in mtk custom mode - gps_position->vel_m_s = ((float)packet->ground_speed)*1e-2f; // from cm/s to m/s - gps_position->cog_rad = ((float)packet->heading) * M_DEG_TO_RAD_F * 1e-2f; //from deg *100 to rad - gps_position->satellites_visible = packet->satellites; - - /* convert time and date information to unix timestamp */ - struct tm timeinfo; //TODO: test this conversion - uint32_t timeinfo_conversion_temp; - - timeinfo.tm_mday = packet->date * 1e-4; - timeinfo_conversion_temp = packet->date - timeinfo.tm_mday * 1e4; - timeinfo.tm_mon = timeinfo_conversion_temp * 1e-2 - 1; - timeinfo.tm_year = (timeinfo_conversion_temp - (timeinfo.tm_mon + 1) * 1e2) + 100; - - timeinfo.tm_hour = packet->utc_time * 1e-7; - timeinfo_conversion_temp = packet->utc_time - timeinfo.tm_hour * 1e7; - timeinfo.tm_min = timeinfo_conversion_temp * 1e-5; - timeinfo_conversion_temp -= timeinfo.tm_min * 1e5; - timeinfo.tm_sec = timeinfo_conversion_temp * 1e-3; - timeinfo_conversion_temp -= timeinfo.tm_sec * 1e3; - time_t epoch = mktime(&timeinfo); - - gps_position->time_gps_usec = epoch * 1e6; //TODO: test this - gps_position->time_gps_usec += timeinfo_conversion_temp * 1e3; - gps_position->timestamp_position = gps_position->timestamp_time = hrt_absolute_time(); - - pos_updated = true; - - + /* Packet size minus checksum, XXX ? */ + if (_rx_count >= sizeof(packet)) { + /* Compare checksum */ + if (_rx_ck_a == packet.ck_a && _rx_ck_b == packet.ck_b) { + ret = 1; } else { - warnx("mtk Checksum invalid, 0x%x, 0x%x instead of 0x%x, 0x%x", _rx_ck_a, packet->ck_a, _rx_ck_b, packet->ck_b); + warnx("MTK Checksum invalid"); + ret = -1; } - // Reset state machine to decode next packet - decodeInit(); + decode_init(); } } + return ret; +} + +void +MTK::handle_message(gps_mtk_packet_t &packet, struct vehicle_gps_position_s &gps_position) +{ + if (_mtk_revision == 16) { + gps_position.lat = packet.latitude * 10; // from degrees*1e6 to degrees*1e7 + gps_position.lon = packet.longitude * 10; // from degrees*1e6 to degrees*1e7 + } else if (_mtk_revision == 19) { + gps_position.lat = packet.latitude; // both degrees*1e7 + gps_position.lon = packet.longitude; // both degrees*1e7 + } else { + warnx("mtk: unknown revision"); + gps_position.lat = 0; + gps_position.lon = 0; + } + gps_position.alt = (int32_t)(packet.msl_altitude * 10); // from cm to mm + gps_position.fix_type = packet.fix_type; + gps_position.eph_m = packet.hdop; // XXX: Check this because eph_m is in m and hdop is without unit + gps_position.epv_m = 0.0; //unknown in mtk custom mode + gps_position.vel_m_s = ((float)packet.ground_speed)*1e-2f; // from cm/s to m/s + gps_position.cog_rad = ((float)packet.heading) * M_DEG_TO_RAD_F * 1e-2f; //from deg *100 to rad + gps_position.satellites_visible = packet.satellites; + + /* convert time and date information to unix timestamp */ + struct tm timeinfo; //TODO: test this conversion + uint32_t timeinfo_conversion_temp; + + timeinfo.tm_mday = packet.date * 1e-4; + timeinfo_conversion_temp = packet.date - timeinfo.tm_mday * 1e4; + timeinfo.tm_mon = timeinfo_conversion_temp * 1e-2 - 1; + timeinfo.tm_year = (timeinfo_conversion_temp - (timeinfo.tm_mon + 1) * 1e2) + 100; + + timeinfo.tm_hour = packet.utc_time * 1e-7; + timeinfo_conversion_temp = packet.utc_time - timeinfo.tm_hour * 1e7; + timeinfo.tm_min = timeinfo_conversion_temp * 1e-5; + timeinfo_conversion_temp -= timeinfo.tm_min * 1e5; + timeinfo.tm_sec = timeinfo_conversion_temp * 1e-3; + timeinfo_conversion_temp -= timeinfo.tm_sec * 1e3; + time_t epoch = mktime(&timeinfo); + + gps_position.time_gps_usec = epoch * 1e6; //TODO: test this + gps_position.time_gps_usec += timeinfo_conversion_temp * 1e3; + gps_position.timestamp_position = gps_position.timestamp_time = hrt_absolute_time(); + return; } void -MTK::addByteToChecksum(uint8_t b) +MTK::add_byte_to_checksum(uint8_t b) { _rx_ck_a = _rx_ck_a + b; _rx_ck_b = _rx_ck_b + _rx_ck_a; diff --git a/apps/drivers/gps/mtk.h b/apps/drivers/gps/mtk.h index e43637195..39063beab 100644 --- a/apps/drivers/gps/mtk.h +++ b/apps/drivers/gps/mtk.h @@ -50,6 +50,9 @@ #define WAAS_ON "$PMTK301,2*2E\r\n" #define MTK_NAVTHRES_OFF "$PMTK397,0*23\r\n" +#define MTK_TIMEOUT_5HZ 400 +#define MTK_BAUDRATE 38400 + typedef enum { MTK_DECODE_UNINIT = 0, MTK_DECODE_GOT_CK_A = 1, @@ -64,16 +67,16 @@ typedef struct { int32_t latitude; ///< Latitude in degrees * 10^7 int32_t longitude; ///< Longitude in degrees * 10^7 uint32_t msl_altitude; ///< MSL altitude in meters * 10^2 - uint32_t ground_speed; ///< FIXME SPEC UNCLEAR - int32_t heading; - uint8_t satellites; - uint8_t fix_type; + uint32_t ground_speed; ///< velocity in m/s + int32_t heading; ///< heading in degrees * 10^2 + uint8_t satellites; ///< number of sattelites used + uint8_t fix_type; ///< fix type: XXX correct for that uint32_t date; uint32_t utc_time; - uint16_t hdop; + uint16_t hdop; ///< horizontal dilution of position (without unit) uint8_t ck_a; uint8_t ck_b; -} type_gps_mtk_packet; +} gps_mtk_packet_t; #pragma pack(pop) @@ -84,23 +87,31 @@ class MTK : public GPS_Helper public: MTK(); ~MTK(); - void reset(void); - void configure(const int &fd, bool &baudrate_changed, unsigned &baudrate); - void parse(uint8_t, struct vehicle_gps_position_s*, bool &config_needed, bool &pos_updated); + int receive(const int &fd, struct vehicle_gps_position_s &gps_position); + int configure(const int &fd, unsigned &baudrate); private: + /** + * Parse the binary MTK packet + */ + int parse_char(uint8_t b, gps_mtk_packet_t &packet); + + /** + * Handle the package once it has arrived + */ + void handle_message(gps_mtk_packet_t &packet, struct vehicle_gps_position_s &gps_position); + /** * Reset the parse state machine for a fresh start */ - void decodeInit(void); + void decode_init(void); /** * While parsing add every byte (except the sync bytes) to the checksum */ - void addByteToChecksum(uint8_t); + void add_byte_to_checksum(uint8_t); mtk_decode_state_t _decode_state; - bool _config_sent; uint8_t _mtk_revision; uint8_t _rx_buffer[MTK_RECV_BUFFER_SIZE]; unsigned _rx_count; -- cgit v1.2.3 From df6cf142e7d67fa8c868245ff144f4e1d4ebdfb3 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Fri, 8 Feb 2013 11:05:57 -0800 Subject: Another rewrite: most of the polling, reading and writing is now inside the GPS classes --- apps/drivers/drv_gps.h | 3 +- apps/drivers/gps/gps.cpp | 62 +-- apps/drivers/gps/gps_helper.cpp | 2 + apps/drivers/gps/gps_helper.h | 4 +- apps/drivers/gps/mtk.cpp | 69 +-- apps/drivers/gps/mtk.h | 10 +- apps/drivers/gps/ubx.cpp | 930 ++++++++++++++++++++-------------------- apps/drivers/gps/ubx.h | 32 +- 8 files changed, 564 insertions(+), 548 deletions(-) diff --git a/apps/drivers/drv_gps.h b/apps/drivers/drv_gps.h index 67248efcd..1dda8ef0b 100644 --- a/apps/drivers/drv_gps.h +++ b/apps/drivers/drv_gps.h @@ -49,7 +49,8 @@ #define GPS_DEVICE_PATH "/dev/gps" typedef enum { - GPS_DRIVER_MODE_UBX = 0, + GPS_DRIVER_MODE_NONE = 0, + GPS_DRIVER_MODE_UBX, GPS_DRIVER_MODE_MTK, GPS_DRIVER_MODE_NMEA, } gps_driver_mode_t; diff --git a/apps/drivers/gps/gps.cpp b/apps/drivers/gps/gps.cpp index 76b5f4533..6d7cfcc68 100644 --- a/apps/drivers/gps/gps.cpp +++ b/apps/drivers/gps/gps.cpp @@ -36,10 +36,7 @@ * Driver for the GPS on a serial port */ -#include - -#include - +#include #include #include #include @@ -54,30 +51,24 @@ #include #include #include - +#include #include -#include - #include - #include - +#include #include #include #include - #include - +#include #include -//#include "ubx.h" +#include "ubx.h" #include "mtk.h" -#define SEND_BUFFER_LENGTH 100 -#define TIMEOUT 1000000 //1s -#define NUMBER_OF_TRIES 5 -#define CONFIG_TIMEOUT 2000000 +#define TIMEOUT_5HZ 400 +#define RATE_MEASUREMENT_PERIOD 5000000 /* oddly, ERROR is not defined for c++ */ #ifdef ERROR @@ -170,7 +161,7 @@ GPS::GPS(const char* uart_path) : _task_should_exit(false), _healthy(false), _mode_changed(false), - _mode(GPS_DRIVER_MODE_MTK), + _mode(GPS_DRIVER_MODE_UBX), _Helper(nullptr), _report_pub(-1), _rate(0.0f) @@ -279,12 +270,11 @@ GPS::task_main() } switch (_mode) { -// case GPS_DRIVER_MODE_UBX: -// _Helper = new UBX(); -// break; + case GPS_DRIVER_MODE_UBX: + _Helper = new UBX(_serial_fd, &_report); + break; case GPS_DRIVER_MODE_MTK: - printf("try new mtk\n"); - _Helper = new MTK(); + _Helper = new MTK(_serial_fd, &_report); break; case GPS_DRIVER_MODE_NMEA: //_Helper = new NMEA(); //TODO: add NMEA @@ -292,11 +282,11 @@ GPS::task_main() default: break; } - // XXX unlock/lock makes sense? unlock(); - if (_Helper->configure(_serial_fd, _baudrate) == 0) { - - while (_Helper->receive(_serial_fd, _report) > 0 && !_task_should_exit) { + if (_Helper->configure(_baudrate) == 0) { + unlock(); + while (_Helper->receive(TIMEOUT_5HZ) > 0 && !_task_should_exit) { +// lock(); /* opportunistic publishing - else invalid data would end up on the bus */ if (_report_pub > 0) { orb_publish(ORB_ID(vehicle_gps_position), _report_pub, &_report); @@ -307,7 +297,7 @@ GPS::task_main() last_rate_count++; /* measure update rate every 5 seconds */ - if (hrt_absolute_time() - last_rate_measurement > 5000000) { + if (hrt_absolute_time() - last_rate_measurement > RATE_MEASUREMENT_PERIOD) { _rate = last_rate_count / ((float)((hrt_absolute_time() - last_rate_measurement)) / 1000000.0f); last_rate_measurement = hrt_absolute_time(); last_rate_count = 0; @@ -323,8 +313,26 @@ GPS::task_main() _healthy = false; _rate = 0.0f; } + + lock(); } lock(); + + /* select next mode */ + switch (_mode) { + case GPS_DRIVER_MODE_UBX: + _mode = GPS_DRIVER_MODE_MTK; + break; + case GPS_DRIVER_MODE_MTK: + _mode = GPS_DRIVER_MODE_UBX; + break; + // case GPS_DRIVER_MODE_NMEA: + // _mode = GPS_DRIVER_MODE_UBX; + // break; + default: + break; + } + } debug("exiting"); diff --git a/apps/drivers/gps/gps_helper.cpp b/apps/drivers/gps/gps_helper.cpp index 2caa82af1..9c1fad569 100644 --- a/apps/drivers/gps/gps_helper.cpp +++ b/apps/drivers/gps/gps_helper.cpp @@ -57,6 +57,8 @@ GPS_Helper::set_baudrate(const int &fd, unsigned baud) case 115200: speed = B115200; break; + warnx("try baudrate: %d\n", speed); + default: warnx("ERROR: Unsupported baudrate: %d\n", baud); return -EINVAL; diff --git a/apps/drivers/gps/gps_helper.h b/apps/drivers/gps/gps_helper.h index 537ca819c..f3d3bc40b 100644 --- a/apps/drivers/gps/gps_helper.h +++ b/apps/drivers/gps/gps_helper.h @@ -44,8 +44,8 @@ class GPS_Helper { public: - virtual int configure(const int &fd, unsigned &baud) = 0; - virtual int receive(const int &fd, struct vehicle_gps_position_s &gps_position) = 0; + virtual int configure(unsigned &baud) = 0; + virtual int receive(unsigned timeout) = 0; int set_baudrate(const int &fd, unsigned baud); }; diff --git a/apps/drivers/gps/mtk.cpp b/apps/drivers/gps/mtk.cpp index 4ccbbfbe4..4762bd503 100644 --- a/apps/drivers/gps/mtk.cpp +++ b/apps/drivers/gps/mtk.cpp @@ -47,7 +47,9 @@ #include "mtk.h" -MTK::MTK() : +MTK::MTK(const int &fd, struct vehicle_gps_position_s *gps_position) : +_fd(fd), +_gps_position(gps_position), _mtk_revision(0) { decode_init(); @@ -58,40 +60,40 @@ MTK::~MTK() } int -MTK::configure(const int &fd, unsigned &baudrate) +MTK::configure(unsigned &baudrate) { /* set baudrate first */ - if (GPS_Helper::set_baudrate(fd, MTK_BAUDRATE) != 0) + if (GPS_Helper::set_baudrate(_fd, MTK_BAUDRATE) != 0) return -1; baudrate = MTK_BAUDRATE; /* Write config messages, don't wait for an answer */ - if (strlen(MTK_OUTPUT_5HZ) != write(fd, MTK_OUTPUT_5HZ, strlen(MTK_OUTPUT_5HZ))) { + if (strlen(MTK_OUTPUT_5HZ) != write(_fd, MTK_OUTPUT_5HZ, strlen(MTK_OUTPUT_5HZ))) { warnx("mtk: config write failed"); return -1; } usleep(10000); - if (strlen(MTK_SET_BINARY) != write(fd, MTK_SET_BINARY, strlen(MTK_SET_BINARY))) { + if (strlen(MTK_SET_BINARY) != write(_fd, MTK_SET_BINARY, strlen(MTK_SET_BINARY))) { warnx("mtk: config write failed"); return -1; } usleep(10000); - if (strlen(SBAS_ON) != write(fd, SBAS_ON, strlen(SBAS_ON))) { + if (strlen(SBAS_ON) != write(_fd, SBAS_ON, strlen(SBAS_ON))) { warnx("mtk: config write failed"); return -1; } usleep(10000); - if (strlen(WAAS_ON) != write(fd, WAAS_ON, strlen(WAAS_ON))) { + if (strlen(WAAS_ON) != write(_fd, WAAS_ON, strlen(WAAS_ON))) { warnx("mtk: config write failed"); return -1; } usleep(10000); - if (strlen(MTK_NAVTHRES_OFF) != write(fd, MTK_NAVTHRES_OFF, strlen(MTK_NAVTHRES_OFF))) { + if (strlen(MTK_NAVTHRES_OFF) != write(_fd, MTK_NAVTHRES_OFF, strlen(MTK_NAVTHRES_OFF))) { warnx("mtk: config write failed"); return -1; } @@ -100,16 +102,19 @@ MTK::configure(const int &fd, unsigned &baudrate) } int -MTK::receive(const int &fd, struct vehicle_gps_position_s &gps_position) +MTK::receive(unsigned timeout) { /* poll descriptor */ pollfd fds[1]; - fds[0].fd = fd; + fds[0].fd = _fd; fds[0].events = POLLIN; uint8_t buf[32]; gps_mtk_packet_t packet; + /* timeout additional to poll */ + uint64_t time_started = hrt_absolute_time(); + int j = 0; ssize_t count = 0; @@ -120,9 +125,13 @@ MTK::receive(const int &fd, struct vehicle_gps_position_s &gps_position) /* pass received bytes to the packet decoder */ while (j < count) { if (parse_char(buf[j], packet) > 0) { - handle_message(packet, gps_position); + handle_message(packet); return 1; } + /* in case we keep trying but only get crap from GPS */ + if (time_started + timeout*1000 < hrt_absolute_time() ) { + return -1; + } j++; } /* everything is read */ @@ -130,7 +139,7 @@ MTK::receive(const int &fd, struct vehicle_gps_position_s &gps_position) } /* then poll for new data */ - int ret = ::poll(fds, sizeof(fds) / sizeof(fds[0]), MTK_TIMEOUT_5HZ); + int ret = ::poll(fds, sizeof(fds) / sizeof(fds[0]), timeout); if (ret < 0) { /* something went wrong when polling */ @@ -148,7 +157,7 @@ MTK::receive(const int &fd, struct vehicle_gps_position_s &gps_position) * won't block even on a blocking device. If more bytes are * available, we'll go back to poll() again... */ - count = ::read(fd, buf, sizeof(buf)); + count = ::read(_fd, buf, sizeof(buf)); } } } @@ -212,26 +221,26 @@ MTK::parse_char(uint8_t b, gps_mtk_packet_t &packet) } void -MTK::handle_message(gps_mtk_packet_t &packet, struct vehicle_gps_position_s &gps_position) +MTK::handle_message(gps_mtk_packet_t &packet) { if (_mtk_revision == 16) { - gps_position.lat = packet.latitude * 10; // from degrees*1e6 to degrees*1e7 - gps_position.lon = packet.longitude * 10; // from degrees*1e6 to degrees*1e7 + _gps_position->lat = packet.latitude * 10; // from degrees*1e6 to degrees*1e7 + _gps_position->lon = packet.longitude * 10; // from degrees*1e6 to degrees*1e7 } else if (_mtk_revision == 19) { - gps_position.lat = packet.latitude; // both degrees*1e7 - gps_position.lon = packet.longitude; // both degrees*1e7 + _gps_position->lat = packet.latitude; // both degrees*1e7 + _gps_position->lon = packet.longitude; // both degrees*1e7 } else { warnx("mtk: unknown revision"); - gps_position.lat = 0; - gps_position.lon = 0; + _gps_position->lat = 0; + _gps_position->lon = 0; } - gps_position.alt = (int32_t)(packet.msl_altitude * 10); // from cm to mm - gps_position.fix_type = packet.fix_type; - gps_position.eph_m = packet.hdop; // XXX: Check this because eph_m is in m and hdop is without unit - gps_position.epv_m = 0.0; //unknown in mtk custom mode - gps_position.vel_m_s = ((float)packet.ground_speed)*1e-2f; // from cm/s to m/s - gps_position.cog_rad = ((float)packet.heading) * M_DEG_TO_RAD_F * 1e-2f; //from deg *100 to rad - gps_position.satellites_visible = packet.satellites; + _gps_position->alt = (int32_t)(packet.msl_altitude * 10); // from cm to mm + _gps_position->fix_type = packet.fix_type; + _gps_position->eph_m = packet.hdop; // XXX: Check this because eph_m is in m and hdop is without unit + _gps_position->epv_m = 0.0; //unknown in mtk custom mode + _gps_position->vel_m_s = ((float)packet.ground_speed)*1e-2f; // from cm/s to m/s + _gps_position->cog_rad = ((float)packet.heading) * M_DEG_TO_RAD_F * 1e-2f; //from deg *100 to rad + _gps_position->satellites_visible = packet.satellites; /* convert time and date information to unix timestamp */ struct tm timeinfo; //TODO: test this conversion @@ -250,9 +259,9 @@ MTK::handle_message(gps_mtk_packet_t &packet, struct vehicle_gps_position_s &gps timeinfo_conversion_temp -= timeinfo.tm_sec * 1e3; time_t epoch = mktime(&timeinfo); - gps_position.time_gps_usec = epoch * 1e6; //TODO: test this - gps_position.time_gps_usec += timeinfo_conversion_temp * 1e3; - gps_position.timestamp_position = gps_position.timestamp_time = hrt_absolute_time(); + _gps_position->time_gps_usec = epoch * 1e6; //TODO: test this + _gps_position->time_gps_usec += timeinfo_conversion_temp * 1e3; + _gps_position->timestamp_position = _gps_position->timestamp_time = hrt_absolute_time(); return; } diff --git a/apps/drivers/gps/mtk.h b/apps/drivers/gps/mtk.h index 39063beab..d4e390b01 100644 --- a/apps/drivers/gps/mtk.h +++ b/apps/drivers/gps/mtk.h @@ -85,10 +85,10 @@ typedef struct { class MTK : public GPS_Helper { public: - MTK(); + MTK(const int &fd, struct vehicle_gps_position_s *gps_position); ~MTK(); - int receive(const int &fd, struct vehicle_gps_position_s &gps_position); - int configure(const int &fd, unsigned &baudrate); + int receive(unsigned timeout); + int configure(unsigned &baudrate); private: /** @@ -99,7 +99,7 @@ private: /** * Handle the package once it has arrived */ - void handle_message(gps_mtk_packet_t &packet, struct vehicle_gps_position_s &gps_position); + void handle_message(gps_mtk_packet_t &packet); /** * Reset the parse state machine for a fresh start @@ -111,6 +111,8 @@ private: */ void add_byte_to_checksum(uint8_t); + int _fd; + struct vehicle_gps_position_s *_gps_position; mtk_decode_state_t _decode_state; uint8_t _mtk_revision; uint8_t _rx_buffer[MTK_RECV_BUFFER_SIZE]; diff --git a/apps/drivers/gps/ubx.cpp b/apps/drivers/gps/ubx.cpp index 8e2396564..74cbc5aaf 100644 --- a/apps/drivers/gps/ubx.cpp +++ b/apps/drivers/gps/ubx.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -47,172 +48,251 @@ #include "ubx.h" +#define UBX_CONFIG_TIMEOUT 100 -UBX::UBX() : -_config_state(UBX_CONFIG_STATE_PRT), +UBX::UBX(const int &fd, struct vehicle_gps_position_s *gps_position) : +_fd(fd), +_gps_position(gps_position), _waiting_for_ack(false) { - reset(); + decode_init(); } UBX::~UBX() { } -void -UBX::reset() +int +UBX::configure(unsigned &baudrate) { - decodeInit(); - _config_state = UBX_CONFIG_STATE_PRT; - _waiting_for_ack = false; -} + _waiting_for_ack = true; + + /* try different baudrates */ + const unsigned baudrates_to_try[] = {9600, 38400, 19200, 57600, 115200}; + + for (int baud_i = 0; baud_i < 5; baud_i++) { + baudrate = baudrates_to_try[baud_i]; + set_baudrate(_fd, baudrate); + + /* Send a CFG-PRT message to set the UBX protocol for in and out + * and leave the baudrate as it is, we just want an ACK-ACK from this + */ + type_gps_bin_cfg_prt_packet_t cfg_prt_packet; + /* Set everything else of the packet to 0, otherwise the module wont accept it */ + memset(&cfg_prt_packet, 0, sizeof(cfg_prt_packet)); + + _clsID_needed = UBX_CLASS_CFG; + _msgID_needed = UBX_MESSAGE_CFG_PRT; + + /* Define the package contents, don't change the baudrate */ + cfg_prt_packet.clsID = UBX_CLASS_CFG; + cfg_prt_packet.msgID = UBX_MESSAGE_CFG_PRT; + cfg_prt_packet.length = UBX_CFG_PRT_LENGTH; + cfg_prt_packet.portID = UBX_CFG_PRT_PAYLOAD_PORTID; + cfg_prt_packet.mode = UBX_CFG_PRT_PAYLOAD_MODE; + cfg_prt_packet.baudRate = baudrate; + cfg_prt_packet.inProtoMask = UBX_CFG_PRT_PAYLOAD_INPROTOMASK; + cfg_prt_packet.outProtoMask = UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK; + + send_config_packet(_fd, (uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); + + if (receive(UBX_CONFIG_TIMEOUT) < 0) { + /* try next baudrate */ + continue; + } -void -UBX::configure(const int &fd, bool &baudrate_changed, unsigned &baudrate) -{ - /* Only send a new config message when we got the ACK of the last one, - * otherwise we might not configure all the messages because the ACK comes from an older/previos CFD command - * reason being that the ACK only includes CFG-MSG but not to which NAV MSG it belongs. - */ - if (!_waiting_for_ack) { - _waiting_for_ack = true; - if (_config_state == UBX_CONFIG_STATE_CONFIGURED) { - /* This should never happen, the parser should set the flag, - * if it should be reconfigured, reset() should be called first. - */ - warnx("ubx: already configured"); - _waiting_for_ack = false; - return; - } else if (_config_state == UBX_CONFIG_STATE_PRT) { - - /* Send a CFG-PRT message to set the UBX protocol for in and out - * and leave the baudrate as it is, we just want an ACK-ACK from this - */ - type_gps_bin_cfg_prt_packet_t cfg_prt_packet; - /* Set everything else of the packet to 0, otherwise the module wont accept it */ - memset(&cfg_prt_packet, 0, sizeof(cfg_prt_packet)); - - /* Define the package contents, don't change the baudrate */ - cfg_prt_packet.clsID = UBX_CLASS_CFG; - cfg_prt_packet.msgID = UBX_MESSAGE_CFG_PRT; - cfg_prt_packet.length = UBX_CFG_PRT_LENGTH; - cfg_prt_packet.portID = UBX_CFG_PRT_PAYLOAD_PORTID; - cfg_prt_packet.mode = UBX_CFG_PRT_PAYLOAD_MODE; - cfg_prt_packet.baudRate = baudrate; - cfg_prt_packet.inProtoMask = UBX_CFG_PRT_PAYLOAD_INPROTOMASK; - cfg_prt_packet.outProtoMask = UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK; - - sendConfigPacket(fd, (uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); - - } else if (_config_state == UBX_CONFIG_STATE_PRT_NEW_BAUDRATE) { - - /* Send a CFG-PRT message again, this time change the baudrate */ - type_gps_bin_cfg_prt_packet_t cfg_prt_packet; - memset(&cfg_prt_packet, 0, sizeof(cfg_prt_packet)); - - cfg_prt_packet.clsID = UBX_CLASS_CFG; - cfg_prt_packet.msgID = UBX_MESSAGE_CFG_PRT; - cfg_prt_packet.length = UBX_CFG_PRT_LENGTH; - cfg_prt_packet.portID = UBX_CFG_PRT_PAYLOAD_PORTID; - cfg_prt_packet.mode = UBX_CFG_PRT_PAYLOAD_MODE; - cfg_prt_packet.baudRate = UBX_CFG_PRT_PAYLOAD_BAUDRATE; - cfg_prt_packet.inProtoMask = UBX_CFG_PRT_PAYLOAD_INPROTOMASK; - cfg_prt_packet.outProtoMask = UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK; - - sendConfigPacket(fd, (uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); - - /* If the new baudrate will be different from the current one, we should report that back to the driver */ - if (UBX_CFG_PRT_PAYLOAD_BAUDRATE != baudrate) { - baudrate=UBX_CFG_PRT_PAYLOAD_BAUDRATE; - baudrate_changed = true; - /* Don't wait for an ACK, we're switching baudrate and we might never get, - * after that, start fresh */ - reset(); - } + /* Send a CFG-PRT message again, this time change the baudrate */ + + cfg_prt_packet.clsID = UBX_CLASS_CFG; + cfg_prt_packet.msgID = UBX_MESSAGE_CFG_PRT; + cfg_prt_packet.length = UBX_CFG_PRT_LENGTH; + cfg_prt_packet.portID = UBX_CFG_PRT_PAYLOAD_PORTID; + cfg_prt_packet.mode = UBX_CFG_PRT_PAYLOAD_MODE; + cfg_prt_packet.baudRate = UBX_CFG_PRT_PAYLOAD_BAUDRATE; + cfg_prt_packet.inProtoMask = UBX_CFG_PRT_PAYLOAD_INPROTOMASK; + cfg_prt_packet.outProtoMask = UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK; + + send_config_packet(_fd, (uint8_t*)&cfg_prt_packet, sizeof(cfg_prt_packet)); + if (UBX_CFG_PRT_PAYLOAD_BAUDRATE != baudrate) { + set_baudrate(_fd, UBX_CFG_PRT_PAYLOAD_BAUDRATE); + baudrate = UBX_CFG_PRT_PAYLOAD_BAUDRATE; + } - } else if (_config_state == UBX_CONFIG_STATE_RATE) { + /* no ack is ecpected here, keep going configuring */ - /* send a CFT-RATE message to define update rate */ - type_gps_bin_cfg_rate_packet_t cfg_rate_packet; - memset(&cfg_rate_packet, 0, sizeof(cfg_rate_packet)); + /* send a CFT-RATE message to define update rate */ + type_gps_bin_cfg_rate_packet_t cfg_rate_packet; + memset(&cfg_rate_packet, 0, sizeof(cfg_rate_packet)); - cfg_rate_packet.clsID = UBX_CLASS_CFG; - cfg_rate_packet.msgID = UBX_MESSAGE_CFG_RATE; - cfg_rate_packet.length = UBX_CFG_RATE_LENGTH; - cfg_rate_packet.measRate = UBX_CFG_RATE_PAYLOAD_MEASRATE; - cfg_rate_packet.navRate = UBX_CFG_RATE_PAYLOAD_NAVRATE; - cfg_rate_packet.timeRef = UBX_CFG_RATE_PAYLOAD_TIMEREF; + _clsID_needed = UBX_CLASS_CFG; + _msgID_needed = UBX_MESSAGE_CFG_RATE; - sendConfigPacket(fd, (uint8_t*)&cfg_rate_packet, sizeof(cfg_rate_packet)); + cfg_rate_packet.clsID = UBX_CLASS_CFG; + cfg_rate_packet.msgID = UBX_MESSAGE_CFG_RATE; + cfg_rate_packet.length = UBX_CFG_RATE_LENGTH; + cfg_rate_packet.measRate = UBX_CFG_RATE_PAYLOAD_MEASRATE; + cfg_rate_packet.navRate = UBX_CFG_RATE_PAYLOAD_NAVRATE; + cfg_rate_packet.timeRef = UBX_CFG_RATE_PAYLOAD_TIMEREF; - } else if (_config_state == UBX_CONFIG_STATE_NAV5) { - /* send a NAV5 message to set the options for the internal filter */ - type_gps_bin_cfg_nav5_packet_t cfg_nav5_packet; - memset(&cfg_nav5_packet, 0, sizeof(cfg_nav5_packet)); + send_config_packet(_fd, (uint8_t*)&cfg_rate_packet, sizeof(cfg_rate_packet)); + if (receive(UBX_CONFIG_TIMEOUT) < 0) { + /* try next baudrate */ + continue; + } - cfg_nav5_packet.clsID = UBX_CLASS_CFG; - cfg_nav5_packet.msgID = UBX_MESSAGE_CFG_NAV5; - cfg_nav5_packet.length = UBX_CFG_NAV5_LENGTH; - cfg_nav5_packet.mask = UBX_CFG_NAV5_PAYLOAD_MASK; - cfg_nav5_packet.dynModel = UBX_CFG_NAV5_PAYLOAD_DYNMODEL; - cfg_nav5_packet.fixMode = UBX_CFG_NAV5_PAYLOAD_FIXMODE; + /* send a NAV5 message to set the options for the internal filter */ + type_gps_bin_cfg_nav5_packet_t cfg_nav5_packet; + memset(&cfg_nav5_packet, 0, sizeof(cfg_nav5_packet)); - sendConfigPacket(fd, (uint8_t*)&cfg_nav5_packet, sizeof(cfg_nav5_packet)); + _clsID_needed = UBX_CLASS_CFG; + _msgID_needed = UBX_MESSAGE_CFG_NAV5; - } else { - /* Catch the remaining config states here, they all need the same packet type */ + cfg_nav5_packet.clsID = UBX_CLASS_CFG; + cfg_nav5_packet.msgID = UBX_MESSAGE_CFG_NAV5; + cfg_nav5_packet.length = UBX_CFG_NAV5_LENGTH; + cfg_nav5_packet.mask = UBX_CFG_NAV5_PAYLOAD_MASK; + cfg_nav5_packet.dynModel = UBX_CFG_NAV5_PAYLOAD_DYNMODEL; + cfg_nav5_packet.fixMode = UBX_CFG_NAV5_PAYLOAD_FIXMODE; - type_gps_bin_cfg_msg_packet_t cfg_msg_packet; - memset(&cfg_msg_packet, 0, sizeof(cfg_msg_packet)); + send_config_packet(_fd, (uint8_t*)&cfg_nav5_packet, sizeof(cfg_nav5_packet)); + if (receive(UBX_CONFIG_TIMEOUT) < 0) { + /* try next baudrate */ + continue; + } - cfg_msg_packet.clsID = UBX_CLASS_CFG; - cfg_msg_packet.msgID = UBX_MESSAGE_CFG_MSG; - cfg_msg_packet.length = UBX_CFG_MSG_LENGTH; - /* Choose fast 5Hz rate for all messages except SVINFO which is big and not important */ - cfg_msg_packet.rate[1] = UBX_CFG_MSG_PAYLOAD_RATE1_5HZ; + type_gps_bin_cfg_msg_packet_t cfg_msg_packet; + memset(&cfg_msg_packet, 0, sizeof(cfg_msg_packet)); - switch (_config_state) { - case UBX_CONFIG_STATE_MSG_NAV_POSLLH: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_POSLLH; - break; - case UBX_CONFIG_STATE_MSG_NAV_TIMEUTC: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_TIMEUTC; - break; -// case UBX_CONFIG_STATE_MSG_NAV_DOP: -// cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; -// cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_DOP; -// break; - case UBX_CONFIG_STATE_MSG_NAV_SVINFO: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_SVINFO; - /* For satelites info 1Hz is enough */ - cfg_msg_packet.rate[1] = UBX_CFG_MSG_PAYLOAD_RATE1_1HZ; - break; - case UBX_CONFIG_STATE_MSG_NAV_SOL: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_SOL; - break; - case UBX_CONFIG_STATE_MSG_NAV_VELNED: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_VELNED; - break; -// case UBX_CONFIG_STATE_MSG_RXM_SVSI: -// cfg_msg_packet.msgClass_payload = UBX_CLASS_RXM; -// cfg_msg_packet.msgID_payload = UBX_MESSAGE_RXM_SVSI; -// break; - default: - break; + _clsID_needed = UBX_CLASS_CFG; + _msgID_needed = UBX_MESSAGE_CFG_MSG; + + cfg_msg_packet.clsID = UBX_CLASS_CFG; + cfg_msg_packet.msgID = UBX_MESSAGE_CFG_MSG; + cfg_msg_packet.length = UBX_CFG_MSG_LENGTH; + /* Choose fast 5Hz rate for all messages except SVINFO which is big and not important */ + cfg_msg_packet.rate[1] = UBX_CFG_MSG_PAYLOAD_RATE1_5HZ; + + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_POSLLH; + + send_config_packet(_fd, (uint8_t*)&cfg_msg_packet, sizeof(cfg_msg_packet)); + if (receive(UBX_CONFIG_TIMEOUT) < 0) { + /* try next baudrate */ + continue; + } + + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_TIMEUTC; + + send_config_packet(_fd, (uint8_t*)&cfg_msg_packet, sizeof(cfg_msg_packet)); + if (receive(UBX_CONFIG_TIMEOUT) < 0) { + /* try next baudrate */ + continue; + } + + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_SVINFO; + /* For satelites info 1Hz is enough */ + cfg_msg_packet.rate[1] = UBX_CFG_MSG_PAYLOAD_RATE1_1HZ; + + send_config_packet(_fd, (uint8_t*)&cfg_msg_packet, sizeof(cfg_msg_packet)); + if (receive(UBX_CONFIG_TIMEOUT) < 0) { + /* try next baudrate */ + continue; + } + + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_SOL; + + send_config_packet(_fd, (uint8_t*)&cfg_msg_packet, sizeof(cfg_msg_packet)); + if (receive(UBX_CONFIG_TIMEOUT) < 0) { + /* try next baudrate */ + continue; + } + + cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; + cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_VELNED; + + send_config_packet(_fd, (uint8_t*)&cfg_msg_packet, sizeof(cfg_msg_packet)); + if (receive(UBX_CONFIG_TIMEOUT) < 0) { + /* try next baudrate */ + continue; + } +// cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; +// cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_DOP; + +// cfg_msg_packet.msgClass_payload = UBX_CLASS_RXM; +// cfg_msg_packet.msgID_payload = UBX_MESSAGE_RXM_SVSI; + + _waiting_for_ack = false; + return 0; + } + return -1; +} + +int +UBX::receive(unsigned timeout) +{ + /* poll descriptor */ + pollfd fds[1]; + fds[0].fd = _fd; + fds[0].events = POLLIN; + + uint8_t buf[32]; + + /* timeout additional to poll */ + uint64_t time_started = hrt_absolute_time(); + + int j = 0; + ssize_t count = 0; + + while (true) { + + /* pass received bytes to the packet decoder */ + while (j < count) { + if (parse_char(buf[j]) > 0) { + /* return to configure during configuration or to the gps driver during normal work + * if a packet has arrived */ + if (handle_message() > 0) + return 1; + } + /* in case we keep trying but only get crap from GPS */ + if (time_started + timeout*1000 < hrt_absolute_time() ) { + return -1; } + j++; + } - sendConfigPacket(fd, (uint8_t*)&cfg_msg_packet, sizeof(cfg_msg_packet)); + /* everything is read */ + j = count = 0; + + /* then poll for new data */ + int ret = ::poll(fds, sizeof(fds) / sizeof(fds[0]), timeout); + + if (ret < 0) { + /* something went wrong when polling */ + return -1; + + } else if (ret == 0) { + /* Timeout */ + return -1; + + } else if (ret > 0) { + /* if we have new data from GPS, go handle it */ + if (fds[0].revents & POLLIN) { + /* + * We are here because poll says there is some data, so this + * won't block even on a blocking device. If more bytes are + * available, we'll go back to poll() again... + */ + count = ::read(_fd, buf, sizeof(buf)); + } } } } -void -UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_needed, bool &pos_updated) +int +UBX::parse_char(uint8_t b) { switch (_decode_state) { /* First, look for sync1 */ @@ -227,13 +307,13 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ _decode_state = UBX_DECODE_GOT_SYNC2; } else { /* Second start symbol was wrong, reset state machine */ - decodeInit(); + decode_init(); } break; /* Now look for class */ case UBX_DECODE_GOT_SYNC2: /* everything except sync1 and sync2 needs to be added to the checksum */ - addByteToChecksum(b); + add_byte_to_checksum(b); /* check for known class */ switch (b) { case UBX_CLASS_ACK: @@ -256,12 +336,12 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ _message_class = CFG; break; default: //unknown class: reset state machine - decodeInit(); + decode_init(); break; } break; case UBX_DECODE_GOT_CLASS: - addByteToChecksum(b); + add_byte_to_checksum(b); switch (_message_class) { case NAV: switch (b) { @@ -296,7 +376,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ break; default: //unknown class: reset state machine, should not happen - decodeInit(); + decode_init(); break; } break; @@ -308,7 +388,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ // break; // // default: //unknown class: reset state machine, should not happen -// decodeInit(); +// decode_init(); // break; // } // break; @@ -321,7 +401,7 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ break; default: //unknown class: reset state machine, should not happen - decodeInit(); + decode_init(); break; } break; @@ -337,384 +417,282 @@ UBX::parse(uint8_t b, struct vehicle_gps_position_s *gps_position, bool &config_ _message_id = ACK_NAK; break; default: //unknown class: reset state machine, should not happen - decodeInit(); + decode_init(); break; } break; default: //should not happen because we set the class warnx("UBX Error, we set a class that we don't know"); - decodeInit(); - config_needed = true; + decode_init(); +// config_needed = true; break; } break; case UBX_DECODE_GOT_MESSAGEID: - addByteToChecksum(b); + add_byte_to_checksum(b); _payload_size = b; //this is the first length byte _decode_state = UBX_DECODE_GOT_LENGTH1; break; case UBX_DECODE_GOT_LENGTH1: - addByteToChecksum(b); + add_byte_to_checksum(b); _payload_size += b << 8; // here comes the second byte of length _decode_state = UBX_DECODE_GOT_LENGTH2; break; case UBX_DECODE_GOT_LENGTH2: /* Add to checksum if not yet at checksum byte */ if (_rx_count < _payload_size) - addByteToChecksum(b); + add_byte_to_checksum(b); _rx_buffer[_rx_count] = b; /* once the payload has arrived, we can process the information */ if (_rx_count >= _payload_size + 1) { //+1 because of 2 checksum bytes - switch (_message_id) { //this enum is unique for all ids --> no need to check the class - case NAV_POSLLH: { -// printf("GOT NAV_POSLLH MESSAGE\n"); - gps_bin_nav_posllh_packet_t *packet = (gps_bin_nav_posllh_packet_t *) _rx_buffer; - //Check if checksum is valid and the store the gps information - if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - gps_position->lat = packet->lat; - gps_position->lon = packet->lon; - gps_position->alt = packet->height_msl; - - gps_position->eph_m = (float)packet->hAcc * 1e-3f; // from mm to m - gps_position->epv_m = (float)packet->vAcc * 1e-3f; // from mm to m + /* compare checksum */ + if (_rx_ck_a == _rx_buffer[_rx_count-1] && _rx_ck_b == _rx_buffer[_rx_count]) { + return 1; + } else { + decode_init(); + return -1; + warnx("ubx: Checksum wrong"); + } - /* Add timestamp to finish the report */ - gps_position->timestamp_position = hrt_absolute_time(); + return 1; + } else if (_rx_count < RECV_BUFFER_SIZE) { + _rx_count++; + } else { + warnx("ubx: buffer full"); + decode_init(); + return -1; + } + break; + default: + break; + } + return 0; //XXX ? +} - /* set flag to trigger publishing of new position */ - pos_updated = true; - } else { - warnx("NAV_POSLLH: checksum invalid"); - } +int +UBX::handle_message() +{ + int ret = 0; - // Reset state machine to decode next packet - decodeInit(); - break; - } + switch (_message_id) { //this enum is unique for all ids --> no need to check the class + case NAV_POSLLH: { +// printf("GOT NAV_POSLLH MESSAGE\n"); + if (!_waiting_for_ack) { + gps_bin_nav_posllh_packet_t *packet = (gps_bin_nav_posllh_packet_t *) _rx_buffer; - case NAV_SOL: { -// printf("GOT NAV_SOL MESSAGE\n"); - gps_bin_nav_sol_packet_t *packet = (gps_bin_nav_sol_packet_t *) _rx_buffer; + _gps_position->lat = packet->lat; + _gps_position->lon = packet->lon; + _gps_position->alt = packet->height_msl; - //Check if checksum is valid and the store the gps information - if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { + _gps_position->eph_m = (float)packet->hAcc * 1e-3f; // from mm to m + _gps_position->epv_m = (float)packet->vAcc * 1e-3f; // from mm to m - gps_position->fix_type = packet->gpsFix; - gps_position->s_variance_m_s = packet->sAcc; - gps_position->p_variance_m = packet->pAcc; + /* Add timestamp to finish the report */ + _gps_position->timestamp_position = hrt_absolute_time(); + /* only return 1 when new position is available */ + ret = 1; + } + break; + } - gps_position->timestamp_variance = hrt_absolute_time(); + case NAV_SOL: { +// printf("GOT NAV_SOL MESSAGE\n"); + if (!_waiting_for_ack) { + gps_bin_nav_sol_packet_t *packet = (gps_bin_nav_sol_packet_t *) _rx_buffer; - } else { - warnx("NAV_SOL: checksum invalid"); - } + _gps_position->fix_type = packet->gpsFix; + _gps_position->s_variance_m_s = packet->sAcc; + _gps_position->p_variance_m = packet->pAcc; - // Reset state machine to decode next packet - decodeInit(); - break; - } + _gps_position->timestamp_variance = hrt_absolute_time(); + } + break; + } -// case NAV_DOP: { -//// printf("GOT NAV_DOP MESSAGE\n"); -// gps_bin_nav_dop_packet_t *packet = (gps_bin_nav_dop_packet_t *) _rx_buffer; -// -// //Check if checksum is valid and the store the gps information -// if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { -// -// gps_position->eph_m = packet->hDOP; -// gps_position->epv = packet->vDOP; -// -// gps_position->timestamp_posdilution = hrt_absolute_time(); -// -// _new_nav_dop = true; +// case NAV_DOP: { +//// printf("GOT NAV_DOP MESSAGE\n"); +// gps_bin_nav_dop_packet_t *packet = (gps_bin_nav_dop_packet_t *) _rx_buffer; // -// } else { -// warnx("NAV_DOP: checksum invalid"); -// } +// _gps_position->eph_m = packet->hDOP; +// _gps_position->epv = packet->vDOP; // -// // Reset state machine to decode next packet -// decodeInit(); -// break; -// } - - case NAV_TIMEUTC: { -// printf("GOT NAV_TIMEUTC MESSAGE\n"); - gps_bin_nav_timeutc_packet_t *packet = (gps_bin_nav_timeutc_packet_t *) _rx_buffer; - - //Check if checksum is valid and the store the gps information - if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - //convert to unix timestamp - struct tm timeinfo; - timeinfo.tm_year = packet->year - 1900; - timeinfo.tm_mon = packet->month - 1; - timeinfo.tm_mday = packet->day; - timeinfo.tm_hour = packet->hour; - timeinfo.tm_min = packet->min; - timeinfo.tm_sec = packet->sec; - - time_t epoch = mktime(&timeinfo); - - gps_position->time_gps_usec = (uint64_t)epoch * 1000000; //TODO: test this - gps_position->time_gps_usec += (uint64_t)(packet->time_nanoseconds * 1e-3f); - - gps_position->timestamp_time = hrt_absolute_time(); - - } else { - warnx("NAV_TIMEUTC: checksum invalid"); - } - - // Reset state machine to decode next packet - decodeInit(); - break; - } - - case NAV_SVINFO: { -// printf("GOT NAV_SVINFO MESSAGE\n"); - - //this is a more complicated message: the length depends on the number of satellites. This number is extracted from the first part of the message - const int length_part1 = 8; - char _rx_buffer_part1[length_part1]; - memcpy(_rx_buffer_part1, _rx_buffer, length_part1); - gps_bin_nav_svinfo_part1_packet_t *packet_part1 = (gps_bin_nav_svinfo_part1_packet_t *) _rx_buffer_part1; - - //read checksum - const int length_part3 = 2; - char _rx_buffer_part3[length_part3]; - memcpy(_rx_buffer_part3, &(_rx_buffer[_rx_count - 1]), length_part3); - gps_bin_nav_svinfo_part3_packet_t *packet_part3 = (gps_bin_nav_svinfo_part3_packet_t *) _rx_buffer_part3; - - //Check if checksum is valid and then store the gps information - if (_rx_ck_a == packet_part3->ck_a && _rx_ck_b == packet_part3->ck_b) { - //definitions needed to read numCh elements from the buffer: - const int length_part2 = 12; - gps_bin_nav_svinfo_part2_packet_t *packet_part2; - char _rx_buffer_part2[length_part2]; //for temporal storage - - uint8_t satellites_used = 0; - int i; - - for (i = 0; i < packet_part1->numCh; i++) { //for each channel - - /* Get satellite information from the buffer */ - memcpy(_rx_buffer_part2, &(_rx_buffer[length_part1 + i * length_part2]), length_part2); - packet_part2 = (gps_bin_nav_svinfo_part2_packet_t *) _rx_buffer_part2; - - - /* Write satellite information in the global storage */ - gps_position->satellite_prn[i] = packet_part2->svid; - - //if satellite information is healthy store the data - uint8_t unhealthy = packet_part2->flags & 1 << 4; //flags is a bitfield - - if (!unhealthy) { - if ((packet_part2->flags) & 1) { //flags is a bitfield - gps_position->satellite_used[i] = 1; - satellites_used++; - - } else { - gps_position->satellite_used[i] = 0; - } - - gps_position->satellite_snr[i] = packet_part2->cno; - gps_position->satellite_elevation[i] = (uint8_t)(packet_part2->elev); - gps_position->satellite_azimuth[i] = (uint8_t)((float)packet_part2->azim * 255.0f / 360.0f); - - } else { - gps_position->satellite_used[i] = 0; - gps_position->satellite_snr[i] = 0; - gps_position->satellite_elevation[i] = 0; - gps_position->satellite_azimuth[i] = 0; - } - - } - - for (i = packet_part1->numCh; i < 20; i++) { //these channels are unused - /* Unused channels have to be set to zero for e.g. MAVLink */ - gps_position->satellite_prn[i] = 0; - gps_position->satellite_used[i] = 0; - gps_position->satellite_snr[i] = 0; - gps_position->satellite_elevation[i] = 0; - gps_position->satellite_azimuth[i] = 0; - } - gps_position->satellites_visible = satellites_used; // visible ~= used but we are interested in the used ones - - /* set timestamp if any sat info is available */ - if (packet_part1->numCh > 0) { - gps_position->satellite_info_available = true; - } else { - gps_position->satellite_info_available = false; - } - gps_position->timestamp_satellites = hrt_absolute_time(); - - } else { - warnx("NAV_SVINFO: checksum invalid"); - } - - // Reset state machine to decode next packet - decodeInit(); - break; - } - - case NAV_VELNED: { -// printf("GOT NAV_VELNED MESSAGE\n"); - gps_bin_nav_velned_packet_t *packet = (gps_bin_nav_velned_packet_t *) _rx_buffer; - - //Check if checksum is valid and the store the gps information - if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - - gps_position->vel_m_s = (float)packet->speed * 1e-2f; - gps_position->vel_n_m_s = (float)packet->velN * 1e-2f; - gps_position->vel_e_m_s = (float)packet->velE * 1e-2f; - gps_position->vel_d_m_s = (float)packet->velD * 1e-2f; - gps_position->cog_rad = (float)packet->heading * M_DEG_TO_RAD_F * 1e-5f; - gps_position->vel_ned_valid = true; - gps_position->timestamp_velocity = hrt_absolute_time(); - - } else { - warnx("NAV_VELNED: checksum invalid"); - } - - // Reset state machine to decode next packet - decodeInit(); - break; - } - -// case RXM_SVSI: { -// printf("GOT RXM_SVSI MESSAGE\n"); -// const int length_part1 = 7; -// char _rx_buffer_part1[length_part1]; -// memcpy(_rx_buffer_part1, _rx_buffer, length_part1); -// gps_bin_rxm_svsi_packet_t *packet = (gps_bin_rxm_svsi_packet_t *) _rx_buffer_part1; +// _gps_position->timestamp_posdilution = hrt_absolute_time(); // -// //Check if checksum is valid and the store the gps information -// if (_rx_ck_a == _rx_buffer[_rx_count - 1] && _rx_ck_b == _rx_buffer[_rx_count]) { +// _new_nav_dop = true; // -// gps_position->satellites_visible = packet->numVis; -// gps_position->counter++; -// _last_message_timestamps[RXM_SVSI - 1] = hrt_absolute_time(); -// ret = 1; -// -// } else { -// warnx("RXM_SVSI: checksum invalid\n"); -// } -// -// // Reset state machine to decode next packet -// decodeInit(); -// break; -// } - - case ACK_ACK: { -// printf("GOT ACK_ACK\n"); - gps_bin_ack_ack_packet_t *packet = (gps_bin_ack_ack_packet_t *) _rx_buffer; - - //Check if checksum is valid - if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { - - _waiting_for_ack = false; - - switch (_config_state) { - case UBX_CONFIG_STATE_PRT: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_PRT) - _config_state = UBX_CONFIG_STATE_PRT_NEW_BAUDRATE; - break; - case UBX_CONFIG_STATE_PRT_NEW_BAUDRATE: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_PRT) - _config_state = UBX_CONFIG_STATE_RATE; - break; - case UBX_CONFIG_STATE_RATE: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_RATE) - _config_state = UBX_CONFIG_STATE_NAV5; - break; - case UBX_CONFIG_STATE_NAV5: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_NAV5) - _config_state = UBX_CONFIG_STATE_MSG_NAV_POSLLH; - break; - case UBX_CONFIG_STATE_MSG_NAV_POSLLH: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) - _config_state = UBX_CONFIG_STATE_MSG_NAV_TIMEUTC; - break; - case UBX_CONFIG_STATE_MSG_NAV_TIMEUTC: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) - _config_state = UBX_CONFIG_STATE_MSG_NAV_SVINFO; - break; -// case UBX_CONFIG_STATE_MSG_NAV_DOP: -// if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) -// _config_state = UBX_CONFIG_STATE_MSG_NAV_SVINFO; -// break; - case UBX_CONFIG_STATE_MSG_NAV_SVINFO: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) - _config_state = UBX_CONFIG_STATE_MSG_NAV_SOL; - break; - case UBX_CONFIG_STATE_MSG_NAV_SOL: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) - _config_state = UBX_CONFIG_STATE_MSG_NAV_VELNED; - break; - case UBX_CONFIG_STATE_MSG_NAV_VELNED: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) - _config_state = UBX_CONFIG_STATE_CONFIGURED; - /* set the flag to tell the driver that configuration was successful */ - config_needed = false; - break; -// case UBX_CONFIG_STATE_MSG_RXM_SVSI: -// if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) -// _config_state = UBX_CONFIG_STATE_CONFIGURED; -// break; - default: - break; - } - } else { - warnx("ACK_ACK: checksum invalid"); - } - - // Reset state machine to decode next packet - decodeInit(); - break; - } +// break; +// } - case ACK_NAK: { -// printf("GOT ACK_NAK\n"); - gps_bin_ack_nak_packet_t *packet = (gps_bin_ack_nak_packet_t *) _rx_buffer; + case NAV_TIMEUTC: { +// printf("GOT NAV_TIMEUTC MESSAGE\n"); - //Check if checksum is valid - if (_rx_ck_a == packet->ck_a && _rx_ck_b == packet->ck_b) { + if (!_waiting_for_ack) { + gps_bin_nav_timeutc_packet_t *packet = (gps_bin_nav_timeutc_packet_t *) _rx_buffer; - warnx("UBX: Received: Not Acknowledged"); - /* configuration obviously not successful */ - config_needed = true; - } else { - warnx("ACK_NAK: checksum invalid\n"); - } + //convert to unix timestamp + struct tm timeinfo; + timeinfo.tm_year = packet->year - 1900; + timeinfo.tm_mon = packet->month - 1; + timeinfo.tm_mday = packet->day; + timeinfo.tm_hour = packet->hour; + timeinfo.tm_min = packet->min; + timeinfo.tm_sec = packet->sec; - // Reset state machine to decode next packet - decodeInit(); - break; - } + time_t epoch = mktime(&timeinfo); - default: //we don't know the message - warnx("UBX: Unknown message received: %d-%d\n",_message_class,_message_id); - decodeInit(); + _gps_position->time_gps_usec = (uint64_t)epoch * 1000000; //TODO: test this + _gps_position->time_gps_usec += (uint64_t)(packet->time_nanoseconds * 1e-3f); + + _gps_position->timestamp_time = hrt_absolute_time(); + } + break; + } - break; + case NAV_SVINFO: { +// printf("GOT NAV_SVINFO MESSAGE\n"); + + if (!_waiting_for_ack) { + //this is a more complicated message: the length depends on the number of satellites. This number is extracted from the first part of the message + const int length_part1 = 8; + char _rx_buffer_part1[length_part1]; + memcpy(_rx_buffer_part1, _rx_buffer, length_part1); + gps_bin_nav_svinfo_part1_packet_t *packet_part1 = (gps_bin_nav_svinfo_part1_packet_t *) _rx_buffer_part1; + + //read checksum + const int length_part3 = 2; + char _rx_buffer_part3[length_part3]; + memcpy(_rx_buffer_part3, &(_rx_buffer[_rx_count - 1]), length_part3); + + //definitions needed to read numCh elements from the buffer: + const int length_part2 = 12; + gps_bin_nav_svinfo_part2_packet_t *packet_part2; + char _rx_buffer_part2[length_part2]; //for temporal storage + + uint8_t satellites_used = 0; + int i; + + for (i = 0; i < packet_part1->numCh; i++) { //for each channel + + /* Get satellite information from the buffer */ + memcpy(_rx_buffer_part2, &(_rx_buffer[length_part1 + i * length_part2]), length_part2); + packet_part2 = (gps_bin_nav_svinfo_part2_packet_t *) _rx_buffer_part2; + + + /* Write satellite information in the global storage */ + _gps_position->satellite_prn[i] = packet_part2->svid; + + //if satellite information is healthy store the data + uint8_t unhealthy = packet_part2->flags & 1 << 4; //flags is a bitfield + + if (!unhealthy) { + if ((packet_part2->flags) & 1) { //flags is a bitfield + _gps_position->satellite_used[i] = 1; + satellites_used++; + + } else { + _gps_position->satellite_used[i] = 0; } - } // end if _rx_count high enough - else if (_rx_count < RECV_BUFFER_SIZE) { - _rx_count++; + + _gps_position->satellite_snr[i] = packet_part2->cno; + _gps_position->satellite_elevation[i] = (uint8_t)(packet_part2->elev); + _gps_position->satellite_azimuth[i] = (uint8_t)((float)packet_part2->azim * 255.0f / 360.0f); + } else { - warnx("buffer full, restarting"); - decodeInit(); - config_needed = true; + _gps_position->satellite_used[i] = 0; + _gps_position->satellite_snr[i] = 0; + _gps_position->satellite_elevation[i] = 0; + _gps_position->satellite_azimuth[i] = 0; } - break; - default: + + } + + for (i = packet_part1->numCh; i < 20; i++) { //these channels are unused + /* Unused channels have to be set to zero for e.g. MAVLink */ + _gps_position->satellite_prn[i] = 0; + _gps_position->satellite_used[i] = 0; + _gps_position->satellite_snr[i] = 0; + _gps_position->satellite_elevation[i] = 0; + _gps_position->satellite_azimuth[i] = 0; + } + _gps_position->satellites_visible = satellites_used; // visible ~= used but we are interested in the used ones + + /* set timestamp if any sat info is available */ + if (packet_part1->numCh > 0) { + _gps_position->satellite_info_available = true; + } else { + _gps_position->satellite_info_available = false; + } + _gps_position->timestamp_satellites = hrt_absolute_time(); + } + break; - } - return; + } + + case NAV_VELNED: { +// printf("GOT NAV_VELNED MESSAGE\n"); + + if (!_waiting_for_ack) { + gps_bin_nav_velned_packet_t *packet = (gps_bin_nav_velned_packet_t *) _rx_buffer; + + _gps_position->vel_m_s = (float)packet->speed * 1e-2f; + _gps_position->vel_n_m_s = (float)packet->velN * 1e-2f; + _gps_position->vel_e_m_s = (float)packet->velE * 1e-2f; + _gps_position->vel_d_m_s = (float)packet->velD * 1e-2f; + _gps_position->cog_rad = (float)packet->heading * M_DEG_TO_RAD_F * 1e-5f; + _gps_position->vel_ned_valid = true; + _gps_position->timestamp_velocity = hrt_absolute_time(); + } + + break; + } + +// case RXM_SVSI: { +// printf("GOT RXM_SVSI MESSAGE\n"); +// const int length_part1 = 7; +// char _rx_buffer_part1[length_part1]; +// memcpy(_rx_buffer_part1, _rx_buffer, length_part1); +// gps_bin_rxm_svsi_packet_t *packet = (gps_bin_rxm_svsi_packet_t *) _rx_buffer_part1; +// +// _gps_position->satellites_visible = packet->numVis; +// _gps_position->counter++; +// _last_message_timestamps[RXM_SVSI - 1] = hrt_absolute_time(); +// +// break; +// } + case ACK_ACK: { +// printf("GOT ACK_ACK\n"); + gps_bin_ack_ack_packet_t *packet = (gps_bin_ack_ack_packet_t *) _rx_buffer; + + if (_waiting_for_ack) { + if (packet->clsID == _clsID_needed && packet->msgID == _msgID_needed) { + ret = 1; + } + } + } + break; + + case ACK_NAK: { +// printf("GOT ACK_NAK\n"); + warnx("UBX: Received: Not Acknowledged"); + /* configuration obviously not successful */ + ret = -1; + break; + } + + default: //we don't know the message + warnx("UBX: Unknown message received: %d-%d\n",_message_class,_message_id); + ret = -1; + break; + } + // end if _rx_count high enough + decode_init(); + return ret; //XXX? } void -UBX::decodeInit(void) +UBX::decode_init(void) { _rx_ck_a = 0; _rx_ck_b = 0; @@ -726,14 +704,14 @@ UBX::decodeInit(void) } void -UBX::addByteToChecksum(uint8_t b) +UBX::add_byte_to_checksum(uint8_t b) { _rx_ck_a = _rx_ck_a + b; _rx_ck_b = _rx_ck_b + _rx_ck_a; } void -UBX::addChecksumToMessage(uint8_t* message, const unsigned length) +UBX::add_checksum_to_message(uint8_t* message, const unsigned length) { uint8_t ck_a = 0; uint8_t ck_b = 0; @@ -749,12 +727,12 @@ UBX::addChecksumToMessage(uint8_t* message, const unsigned length) } void -UBX::sendConfigPacket(const int &fd, uint8_t *packet, const unsigned length) +UBX::send_config_packet(const int &fd, uint8_t *packet, const unsigned length) { ssize_t ret = 0; /* Calculate the checksum now */ - addChecksumToMessage(packet, length); + add_checksum_to_message(packet, length); const uint8_t sync_bytes[] = {UBX_SYNC1, UBX_SYNC2}; diff --git a/apps/drivers/gps/ubx.h b/apps/drivers/gps/ubx.h index c420e83b9..e3dd1c7ea 100644 --- a/apps/drivers/gps/ubx.h +++ b/apps/drivers/gps/ubx.h @@ -86,6 +86,8 @@ #define UBX_CFG_MSG_PAYLOAD_RATE1_5HZ 0x01 /**< {0x00, 0x01, 0x00, 0x00, 0x00, 0x00} the second entry is for UART1 */ #define UBX_CFG_MSG_PAYLOAD_RATE1_1HZ 0x05 /**< {0x00, 0x05, 0x00, 0x00, 0x00, 0x00} the second entry is for UART1 */ +#define UBX_MAX_PAYLOAD_LENGTH 500 + // ************ /** the structures of the binary packets */ #pragma pack(push, 1) @@ -337,35 +339,49 @@ typedef enum { class UBX : public GPS_Helper { public: - UBX(); + UBX(const int &fd, struct vehicle_gps_position_s *gps_position); ~UBX(); - void reset(void); - void configure(const int &fd, bool &baudrate_changed, unsigned &baudrate); - void parse(uint8_t, struct vehicle_gps_position_s*, bool &config_needed, bool &pos_updated); + int receive(unsigned timeout); + int configure(unsigned &baudrate); private: + + /** + * Parse the binary MTK packet + */ + int parse_char(uint8_t b); + + /** + * Handle the package once it has arrived + */ + int handle_message(void); + /** * Reset the parse state machine for a fresh start */ - void decodeInit(void); + void decode_init(void); /** * While parsing add every byte (except the sync bytes) to the checksum */ - void addByteToChecksum(uint8_t); + void add_byte_to_checksum(uint8_t); /** * Add the two checksum bytes to an outgoing message */ - void addChecksumToMessage(uint8_t* message, const unsigned length); + void add_checksum_to_message(uint8_t* message, const unsigned length); /** * Helper to send a config packet */ - void sendConfigPacket(const int &fd, uint8_t *packet, const unsigned length); + void send_config_packet(const int &fd, uint8_t *packet, const unsigned length); + int _fd; + struct vehicle_gps_position_s *_gps_position; ubx_config_state_t _config_state; bool _waiting_for_ack; + uint8_t _clsID_needed; + uint8_t _msgID_needed; ubx_decode_state_t _decode_state; uint8_t _rx_buffer[RECV_BUFFER_SIZE]; unsigned _rx_count; -- cgit v1.2.3 From a0780a20b5e10eafa1ddf7e16bce788b94514bba Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 16 Feb 2013 18:00:58 +0100 Subject: Fixed default airspeed for fixed wing control app --- apps/examples/control_demo/params.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/examples/control_demo/params.c b/apps/examples/control_demo/params.c index 6525b70f5..8cefc298f 100644 --- a/apps/examples/control_demo/params.c +++ b/apps/examples/control_demo/params.c @@ -52,9 +52,9 @@ PARAM_DEFINE_FLOAT(FWB_XT2YAW_MAX, 1.57f); // cross-track to yaw angle limit 90 PARAM_DEFINE_FLOAT(FWB_XT2YAW, 0.005f); // cross-track to yaw angle gain // speed command -PARAM_DEFINE_FLOAT(FWB_V_MIN, 20.0f); // minimum commanded velocity -PARAM_DEFINE_FLOAT(FWB_V_CMD, 22.0f); // commanded velocity -PARAM_DEFINE_FLOAT(FWB_V_MAX, 24.0f); // maximum commanded velocity +PARAM_DEFINE_FLOAT(FWB_V_MIN, 10.0f); // minimum commanded velocity +PARAM_DEFINE_FLOAT(FWB_V_CMD, 12.0f); // commanded velocity +PARAM_DEFINE_FLOAT(FWB_V_MAX, 16.0f); // maximum commanded velocity // trim PARAM_DEFINE_FLOAT(FWB_TRIM_AIL, 0.0f); // trim aileron, normalized (-1,1) -- cgit v1.2.3 From 2d1009a89727582bc38093c67b930015cdbcc353 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 16 Feb 2013 18:35:36 +0100 Subject: Fixed log conversion file --- ROMFS/logging/logconv.m | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ROMFS/logging/logconv.m b/ROMFS/logging/logconv.m index c405410de..5ea2aeb95 100755 --- a/ROMFS/logging/logconv.m +++ b/ROMFS/logging/logconv.m @@ -65,10 +65,9 @@ logFormat{17} = struct('name', 'rot_matrix', 'bytes', 4, 'array', 9, ' logFormat{18} = struct('name', 'vicon_position', 'bytes', 4, 'array', 6, 'precision', 'float', 'machineformat', 'ieee-le'); logFormat{19} = struct('name', 'actuator_control', 'bytes', 4, 'array', 4, 'precision', 'float', 'machineformat', 'ieee-le'); logFormat{20} = struct('name', 'optical_flow', 'bytes', 4, 'array', 6, 'precision', 'float', 'machineformat', 'ieee-le'); -logFormat{21} = struct('name', 'omnidirectional_flow', 'bytes', 4, 'array', 22,'precision', 'float', 'machineformat', 'ieee-le'); -logFormat{22} = struct('name', 'diff_pressure', 'bytes', 4, 'array', 1, 'precision', 'float', 'machineformat', 'ieee-le'); -logFormat{23} = struct('name', 'ind_airspeed', 'bytes', 4, 'array', 1, 'precision', 'float', 'machineformat', 'ieee-le'); -logFormat{24} = struct('name', 'true_airspeed', 'bytes', 4, 'array', 1, 'precision', 'float', 'machineformat', 'ieee-le'); +logFormat{21} = struct('name', 'diff_pressure', 'bytes', 4, 'array', 1, 'precision', 'float', 'machineformat', 'ieee-le'); +logFormat{22} = struct('name', 'ind_airspeed', 'bytes', 4, 'array', 1, 'precision', 'float', 'machineformat', 'ieee-le'); +logFormat{23} = struct('name', 'true_airspeed', 'bytes', 4, 'array', 1, 'precision', 'float', 'machineformat', 'ieee-le'); % First get length of one line columns = length(logFormat); -- cgit v1.2.3 From 9fb024b1f236ff63c70c9942a2775cec2fb0ddec Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sun, 17 Feb 2013 13:07:40 +0100 Subject: Removed old GPS app --- apps/gps/.context | 0 apps/gps/.gitignore | 3 - apps/gps/Makefile | 59 --- apps/gps/gps.c | 589 --------------------- apps/gps/gps.h | 18 - apps/gps/mtk.c | 432 ---------------- apps/gps/mtk.h | 98 ---- apps/gps/nmea_helper.c | 345 ------------- apps/gps/nmea_helper.h | 47 -- apps/gps/nmealib/LICENSE.TXT | 506 ------------------ apps/gps/nmealib/README.TXT | 26 - apps/gps/nmealib/context.c | 67 --- apps/gps/nmealib/generate.c | 229 --------- apps/gps/nmealib/generator.c | 399 --------------- apps/gps/nmealib/gmath.c | 376 -------------- apps/gps/nmealib/info.c | 21 - apps/gps/nmealib/nmea/config.h | 51 -- apps/gps/nmealib/nmea/context.h | 44 -- apps/gps/nmealib/nmea/generate.h | 44 -- apps/gps/nmealib/nmea/generator.h | 79 --- apps/gps/nmealib/nmea/gmath.h | 92 ---- apps/gps/nmealib/nmea/info.h | 112 ---- apps/gps/nmealib/nmea/nmea.h | 25 - apps/gps/nmealib/nmea/parse.h | 39 -- apps/gps/nmealib/nmea/parser.h | 59 --- apps/gps/nmealib/nmea/sentence.h | 128 ----- apps/gps/nmealib/nmea/time.h | 47 -- apps/gps/nmealib/nmea/tok.h | 31 -- apps/gps/nmealib/nmea/units.h | 30 -- apps/gps/nmealib/parse.c | 501 ------------------ apps/gps/nmealib/parser.c | 400 --------------- apps/gps/nmealib/sentence.c | 54 -- apps/gps/nmealib/time.c | 63 --- apps/gps/nmealib/tok.c | 267 ---------- apps/gps/ubx.c | 1022 ------------------------------------- apps/gps/ubx.h | 415 --------------- 36 files changed, 6718 deletions(-) delete mode 100644 apps/gps/.context delete mode 100644 apps/gps/.gitignore delete mode 100644 apps/gps/Makefile delete mode 100644 apps/gps/gps.c delete mode 100644 apps/gps/gps.h delete mode 100644 apps/gps/mtk.c delete mode 100644 apps/gps/mtk.h delete mode 100644 apps/gps/nmea_helper.c delete mode 100644 apps/gps/nmea_helper.h delete mode 100644 apps/gps/nmealib/LICENSE.TXT delete mode 100644 apps/gps/nmealib/README.TXT delete mode 100644 apps/gps/nmealib/context.c delete mode 100644 apps/gps/nmealib/generate.c delete mode 100644 apps/gps/nmealib/generator.c delete mode 100644 apps/gps/nmealib/gmath.c delete mode 100644 apps/gps/nmealib/info.c delete mode 100644 apps/gps/nmealib/nmea/config.h delete mode 100644 apps/gps/nmealib/nmea/context.h delete mode 100644 apps/gps/nmealib/nmea/generate.h delete mode 100644 apps/gps/nmealib/nmea/generator.h delete mode 100644 apps/gps/nmealib/nmea/gmath.h delete mode 100644 apps/gps/nmealib/nmea/info.h delete mode 100644 apps/gps/nmealib/nmea/nmea.h delete mode 100644 apps/gps/nmealib/nmea/parse.h delete mode 100644 apps/gps/nmealib/nmea/parser.h delete mode 100644 apps/gps/nmealib/nmea/sentence.h delete mode 100644 apps/gps/nmealib/nmea/time.h delete mode 100644 apps/gps/nmealib/nmea/tok.h delete mode 100644 apps/gps/nmealib/nmea/units.h delete mode 100644 apps/gps/nmealib/parse.c delete mode 100644 apps/gps/nmealib/parser.c delete mode 100644 apps/gps/nmealib/sentence.c delete mode 100644 apps/gps/nmealib/time.c delete mode 100644 apps/gps/nmealib/tok.c delete mode 100644 apps/gps/ubx.c delete mode 100644 apps/gps/ubx.h diff --git a/apps/gps/.context b/apps/gps/.context deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/gps/.gitignore b/apps/gps/.gitignore deleted file mode 100644 index a02827195..000000000 --- a/apps/gps/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -include -mavlink-* -pymavlink-* diff --git a/apps/gps/Makefile b/apps/gps/Makefile deleted file mode 100644 index 7aaaf50cb..000000000 --- a/apps/gps/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -############################################################################ -# -# Copyright (C) 2012 PX4 Development Team. 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 PX4 nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -# -# Makefile to build the GPS receiver application -# - -APPNAME = gps -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 - -CSRCS = gps.c \ - ubx.c \ - mtk.c \ - nmea_helper.c \ - nmealib/context.c \ - nmealib/generate.c \ - nmealib/generator.c \ - nmealib/gmath.c \ - nmealib/info.c \ - nmealib/parse.c \ - nmealib/parser.c \ - nmealib/sentence.c \ - nmealib/time.c \ - nmealib/tok.c - -INCLUDES = $(TOPDIR)/../mavlink/include/mavlink - -include $(APPDIR)/mk/app.mk diff --git a/apps/gps/gps.c b/apps/gps/gps.c deleted file mode 100644 index 8a9512054..000000000 --- a/apps/gps/gps.c +++ /dev/null @@ -1,589 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Thomas Gubler - * Julian Oes - * - * 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 PX4 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. - * - ****************************************************************************/ - -/* @file gps.c - * GPS app main loop. - */ - -#include "gps.h" -#include -#include -#include -#include -#include -#include -#include "nmealib/nmea/nmea.h" // the nmea library -#include "nmea_helper.h" //header files for interacting with the nmea library -#include "mtk.h" //header files for the custom protocol for the mediatek diydrones chip -#include "ubx.h" //header files for the ubx protocol -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -static bool thread_should_exit; /**< Deamon status flag */ -static bool thread_running = false; /**< Deamon status flag */ -static int deamon_task; /**< Handle of deamon task / thread */ - -/** - * GPS module readout and publishing. - * - * This function reads the onboard gps and publishes the vehicle_gps_positon topic. - * - * @see vehicle_gps_position_s - * @ingroup apps - */ -__EXPORT int gps_main(int argc, char *argv[]); - -/** - * Mainloop of deamon. - */ -int gps_thread_main(int argc, char *argv[]); - -/** - * Print the correct usage. - */ -static void usage(const char *reason); - -/**************************************************************************** - * Definitions - ****************************************************************************/ -#define IMPORTANT_GPS_BAUD_RATES_N 2 -#define RETRY_INTERVAL_SECONDS 10 - -//gps_bin_ubx_state_t * ubx_state; -bool gps_mode_try_all; -bool gps_baud_try_all; -bool gps_mode_success; -bool terminate_gps_thread; -bool gps_verbose; -int current_gps_speed; - -enum GPS_MODES { - GPS_MODE_START = 0, - GPS_MODE_UBX = 1, - GPS_MODE_MTK = 2, - GPS_MODE_NMEA = 3, - GPS_MODE_END = 4 -}; - - -#define AUTO_DETECTION_COUNT 8 -const int autodetection_baudrates[] = {B38400, B9600, B38400, B9600, B38400, B9600, B38400, B9600}; -const enum GPS_MODES autodetection_gpsmodes[] = {GPS_MODE_UBX, GPS_MODE_UBX, GPS_MODE_MTK, GPS_MODE_MTK, GPS_MODE_UBX, GPS_MODE_UBX, GPS_MODE_NMEA, GPS_MODE_NMEA}; //nmea is the fall-back if nothing else works, therefore we try the standard modes again before finally trying nmea - -/**************************************************************************** - * Private functions - ****************************************************************************/ -int open_port(char *port); - -void close_port(int *fd); - -void setup_port(char *device, int speed, int *fd); - - -/** - * The deamon app only briefly exists to start - * the background job. The stack size assigned in the - * Makefile does only apply to this management task. - * - * The actual stack size should be set in the call - * to task_create(). - */ -int gps_main(int argc, char *argv[]) -{ - if (argc < 1) - usage("missing command"); - - if (!strcmp(argv[1], "start")) { - - if (thread_running) { - printf("gps already running\n"); - /* this is not an error */ - exit(0); - } - - thread_should_exit = false; - deamon_task = task_spawn("gps", - SCHED_DEFAULT, - SCHED_PRIORITY_DEFAULT, - 4096, - gps_thread_main, - (argv) ? (const char **)&argv[2] : (const char **)NULL); - thread_running = true; - exit(0); - } - - if (!strcmp(argv[1], "stop")) { - thread_should_exit = true; - exit(0); - } - - if (!strcmp(argv[1], "status")) { - if (thread_running) { - printf("\tgps is running\n"); - } else { - printf("\tgps not started\n"); - } - exit(0); - } - - usage("unrecognized command"); - exit(1); -} - -/* - * Main function of gps app. - */ -int gps_thread_main(int argc, char *argv[]) { - - /* welcome message */ - printf("[gps] Initialized. Searching for GPS receiver..\n"); - - /* default values */ - const char *commandline_usage = "\tusage: %s {start|stop|status} -d devicename -b baudrate -m mode\n\tmodes are:\n\t\tubx\n\t\tmtkcustom\n\t\tnmea\n\t\tall\n"; - char *device = "/dev/ttyS3"; - char mode[10]; - strcpy(mode, "all"); - int baudrate = -1; - gps_mode_try_all = false; - gps_baud_try_all = false; - gps_mode_success = true; - terminate_gps_thread = false; - bool retry = false; - gps_verbose = false; - - int mavlink_fd = open(MAVLINK_LOG_DEVICE, 0); - - /* read arguments */ - int i; - - for (i = 0; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { //device set - printf(commandline_usage, argv[0]); - thread_running = false; - return 0; - } - - if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--device") == 0) { //device set - if (argc > i + 1) { - device = argv[i + 1]; - - } else { - printf(commandline_usage, argv[0]); - thread_running = false; - return 0; - } - } - - if (strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--retry") == 0) { - if (argc > i + 1) { - retry = atoi(argv[i + 1]); - - } else { - printf(commandline_usage, argv[0]); - thread_running = false; - return 0; - } - } - - if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--baud") == 0) { - if (argc > i + 1) { - baudrate = atoi(argv[i + 1]); - - } else { - printf(commandline_usage, argv[0]); - thread_running = false; - return 0; - } - } - - if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--mode") == 0) { - if (argc > i + 1) { - strcpy(mode, argv[i + 1]); - - } else { - printf(commandline_usage, argv[0]); - thread_running = false; - return 0; - } - } - - if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) { - gps_verbose = true; - } - } - - /* - * In case a baud rate is set only this baud rate will be tried, - * otherwise a array of usual baud rates for gps receivers is used - */ - - -// printf("baudrate = %d\n",baudrate); - switch (baudrate) { - case -1: gps_baud_try_all = true; break; - - case 0: current_gps_speed = B0; break; - case 50: current_gps_speed = B50; break; - case 75: current_gps_speed = B75; break; - case 110: current_gps_speed = B110; break; - case 134: current_gps_speed = B134; break; - case 150: current_gps_speed = B150; break; - case 200: current_gps_speed = B200; break; - case 300: current_gps_speed = B300; break; - case 600: current_gps_speed = B600; break; - case 1200: current_gps_speed = B1200; break; - case 1800: current_gps_speed = B1800; break; - case 2400: current_gps_speed = B2400; break; - case 4800: current_gps_speed = B4800; break; - case 9600: current_gps_speed = B9600; break; - case 19200: current_gps_speed = B19200; break; - case 38400: current_gps_speed = B38400; break; - case 57600: current_gps_speed = B57600; break; - case 115200: current_gps_speed = B115200; break; - case 230400: current_gps_speed = B230400; break; - case 460800: current_gps_speed = B460800; break; - case 921600: current_gps_speed = B921600; break; - - default: - fprintf(stderr, "[gps] ERROR: Unsupported baudrate: %d\n", baudrate); - fflush(stdout); - return -EINVAL; - } - - - enum GPS_MODES current_gps_mode = GPS_MODE_UBX; - - if (strcmp(mode, "ubx") == 0) { - current_gps_mode = GPS_MODE_UBX; - - } else if (strcmp(mode, "mtkcustom") == 0) { - current_gps_mode = GPS_MODE_MTK; - - } else if (strcmp(mode, "nmea") == 0) { - current_gps_mode = GPS_MODE_NMEA; - - } else if (strcmp(mode, "all") == 0) { - gps_mode_try_all = true; - - } else { - fprintf(stderr, "\t[gps] Invalid mode argument\n"); - printf(commandline_usage); - thread_running = false; - return ERROR; - } - - /* Declare file descriptor for gps here, open port later in setup_port */ - int fd; - - while (!thread_should_exit) { - /* Infinite retries or break if retry == false */ - - /* Loop over all configurations of baud rate and protocol */ - for (i = 0; i < AUTO_DETECTION_COUNT; i++) { - if (gps_mode_try_all) { - current_gps_mode = autodetection_gpsmodes[i]; - - if (false == gps_baud_try_all && autodetection_baudrates[i] != current_gps_speed) //there is no need to try modes which are not configured to run with the selcted baud rate - continue; - } - - if (gps_baud_try_all) { - current_gps_speed = autodetection_baudrates[i]; - - if (false == gps_mode_try_all && autodetection_gpsmodes[i] != current_gps_mode) //there is no need to try baud rates which are not usual for the selected mode - continue; - } - - - /* - * The watchdog_thread will return and set gps_mode_success to false if no data can be parsed. - * if the gps was once running the wtachdog thread will not return but instead try to reconfigure the gps (depending on the mode/protocol) - */ - - if (current_gps_mode == GPS_MODE_UBX) { - - if (gps_verbose) printf("[gps] Trying UBX mode at %d baud\n", current_gps_speed); - - mavlink_log_info(mavlink_fd, "[gps] trying to connect to a ubx module"); - - setup_port(device, current_gps_speed, &fd); - - /* start ubx thread and watchdog */ - pthread_t ubx_thread; - pthread_t ubx_watchdog_thread; - - pthread_mutex_t ubx_mutex_d; - ubx_mutex = &ubx_mutex_d; - pthread_mutex_init(ubx_mutex, NULL); - gps_bin_ubx_state_t ubx_state_d; - ubx_state = &ubx_state_d; - ubx_decode_init(); - - pthread_attr_t ubx_loop_attr; - pthread_attr_init(&ubx_loop_attr); - pthread_attr_setstacksize(&ubx_loop_attr, 3000); - - struct arg_struct args; - args.fd_ptr = &fd; - args.thread_should_exit_ptr = &thread_should_exit; - - pthread_create(&ubx_thread, &ubx_loop_attr, ubx_loop, (void *)&args); - - pthread_attr_t ubx_wd_attr; - pthread_attr_init(&ubx_wd_attr); - pthread_attr_setstacksize(&ubx_wd_attr, 1400); - int pthread_create_res = pthread_create(&ubx_watchdog_thread, &ubx_wd_attr, ubx_watchdog_loop, (void *)&args); - - if (pthread_create_res != 0) fprintf(stderr, "[gps] ERROR: could not create ubx watchdog thread, pthread_create =%d\n", pthread_create_res); - - /* wait for threads to complete */ - pthread_join(ubx_watchdog_thread, NULL); - - if (gps_mode_success == false) { - if (gps_verbose) printf("[gps] no success with UBX mode and %d baud\n", current_gps_speed); - - terminate_gps_thread = true; - pthread_join(ubx_thread, NULL); - - gps_mode_success = true; - terminate_gps_thread = false; - - /* maybe the watchdog was stopped through the thread_should_exit flag */ - } else if (thread_should_exit) { - pthread_join(ubx_thread, NULL); - if (gps_verbose) printf("[gps] ubx watchdog and ubx loop threads have been terminated, exiting."); - close(mavlink_fd); - close_port(&fd); - thread_running = false; - return 0; - } - - close_port(&fd); - } else if (current_gps_mode == GPS_MODE_MTK) { - if (gps_verbose) printf("[gps] trying MTK binary mode at %d baud\n", current_gps_speed); - - mavlink_log_info(mavlink_fd, "[gps] trying to connect to a MTK module"); - - setup_port(device, current_gps_speed, &fd); - - /* start mtk thread and watchdog */ - pthread_t mtk_thread; - pthread_t mtk_watchdog_thread; - - pthread_mutex_t mtk_mutex_d; - mtk_mutex = &mtk_mutex_d; - pthread_mutex_init(mtk_mutex, NULL); - - - gps_bin_mtk_state_t mtk_state_d; - mtk_state = &mtk_state_d; - mtk_decode_init(); - - - pthread_attr_t mtk_loop_attr; - pthread_attr_init(&mtk_loop_attr); - pthread_attr_setstacksize(&mtk_loop_attr, 2048); - - struct arg_struct args; - args.fd_ptr = &fd; - args.thread_should_exit_ptr = &thread_should_exit; - - pthread_create(&mtk_thread, &mtk_loop_attr, mtk_loop, (void *)&args); - sleep(2); - pthread_create(&mtk_watchdog_thread, NULL, mtk_watchdog_loop, (void *)&args); - - /* wait for threads to complete */ - pthread_join(mtk_watchdog_thread, (void *)&fd); - - if (gps_mode_success == false) { - if (gps_verbose) printf("[gps] No success with MTK binary mode and %d baud\n", current_gps_speed); - - terminate_gps_thread = true; - pthread_join(mtk_thread, NULL); - - //if(true == gps_mode_try_all) - //strcpy(mode, "nmea"); - - gps_mode_success = true; - terminate_gps_thread = false; - } - - close_port(&fd); - - } else if (current_gps_mode == GPS_MODE_NMEA) { - if (gps_verbose) printf("[gps] Trying NMEA mode at %d baud\n", current_gps_speed); - - mavlink_log_info(mavlink_fd, "[gps] trying to connect to a NMEA module"); - - - setup_port(device, current_gps_speed, &fd); - - /* start nmea thread and watchdog */ - pthread_t nmea_thread; - pthread_t nmea_watchdog_thread; - - pthread_mutex_t nmea_mutex_d; - nmea_mutex = &nmea_mutex_d; - pthread_mutex_init(nmea_mutex, NULL); - - gps_bin_nmea_state_t nmea_state_d; - nmea_state = &nmea_state_d; - - pthread_attr_t nmea_loop_attr; - pthread_attr_init(&nmea_loop_attr); - pthread_attr_setstacksize(&nmea_loop_attr, 4096); - - struct arg_struct args; - args.fd_ptr = &fd; - args.thread_should_exit_ptr = &thread_should_exit; - - pthread_create(&nmea_thread, &nmea_loop_attr, nmea_loop, (void *)&args); - sleep(2); - pthread_create(&nmea_watchdog_thread, NULL, nmea_watchdog_loop, (void *)&args); - - /* wait for threads to complete */ - pthread_join(nmea_watchdog_thread, (void *)&fd); - - if (gps_mode_success == false) { - if (gps_verbose) printf("[gps] No success with NMEA mode and %d baud\r\n", current_gps_speed); - - terminate_gps_thread = true; - pthread_join(nmea_thread, NULL); - - gps_mode_success = true; - terminate_gps_thread = false; - } - - close_port(&fd); - } - - /* exit quickly if stop command has been received */ - if (thread_should_exit) { - printf("[gps] stopped, exiting.\n"); - close(mavlink_fd); - thread_running = false; - return 0; - } - - /* if both, mode and baud is set by argument, we only need one loop*/ - if (gps_mode_try_all == false && gps_baud_try_all == false) - break; - } - - - if (retry) { - printf("[gps] No configuration was successful, retrying in %d seconds \n", RETRY_INTERVAL_SECONDS); - mavlink_log_info(mavlink_fd, "[gps] No configuration was successful, retrying..."); - fflush(stdout); - - } else { - fprintf(stderr, "[gps] No configuration was successful, exiting... \n"); - fflush(stdout); - mavlink_log_info(mavlink_fd, "[gps] No configuration was successful, exiting..."); - break; - } - - sleep(RETRY_INTERVAL_SECONDS); - } - - printf("[gps] exiting.\n"); - close(mavlink_fd); - thread_running = false; - return 0; -} - - -static void usage(const char *reason) -{ - if (reason) - fprintf(stderr, "%s\n", reason); - fprintf(stderr, "\tusage: gps {start|status|stop} -d devicename -b baudrate -m mode\n\tmodes are:\n\t\tubx\n\t\tmtkcustom\n\t\tnmea\n\t\tall\n"); - exit(1); -} - -int open_port(char *port) -{ - int fd; /**< File descriptor for the gps port */ - - /* Open serial port */ - fd = open(port, O_CREAT | O_RDWR | O_NOCTTY); /* O_RDWR - Read and write O_NOCTTY - Ignore special chars like CTRL-C */ - return (fd); -} - - -void close_port(int *fd) -{ - /* Close serial port */ - close(*fd); -} - -void setup_port(char *device, int speed, int *fd) -{ - /* open port (baud rate is set in defconfig file) */ - *fd = open_port(device); - - if (*fd != -1) { - if (gps_verbose) printf("[gps] Port opened: %s at %d baud\n", device, speed); - - } else { - fprintf(stderr, "[gps] Could not open port, exiting gps app!\n"); - fflush(stdout); - } - - /* Try to set baud rate */ - struct termios uart_config; - int termios_state; - - if ((termios_state = tcgetattr(*fd, &uart_config)) < 0) { - fprintf(stderr, "[gps] ERROR getting baudrate / termios config for %s: %d\n", device, termios_state); - close(*fd); - } - if (gps_verbose) printf("[gps] Try to set baud rate %d now\n",speed); - /* Set baud rate */ - cfsetispeed(&uart_config, speed); - cfsetospeed(&uart_config, speed); - if ((termios_state = tcsetattr(*fd, TCSANOW, &uart_config)) < 0) { - fprintf(stderr, "[gps] ERROR setting baudrate / termios config for %s (tcsetattr)\n", device); - close(*fd); - } -} diff --git a/apps/gps/gps.h b/apps/gps/gps.h deleted file mode 100644 index 499a6164f..000000000 --- a/apps/gps/gps.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * gps.h - * - * Created on: Mar 8, 2012 - * Author: thomasgubler - */ - -#ifndef GPS_H_ -#define GPS_H - -#include - -struct arg_struct { - int *fd_ptr; - bool *thread_should_exit_ptr; -}; - -#endif /* GPS_H_ */ diff --git a/apps/gps/mtk.c b/apps/gps/mtk.c deleted file mode 100644 index 3b0ee4565..000000000 --- a/apps/gps/mtk.c +++ /dev/null @@ -1,432 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: Julian Oes - * Thomas Gubler - * - * 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 PX4 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. - * - ****************************************************************************/ - -/* @file MTK custom binary (3DR) protocol implementation */ - -#include "gps.h" -#include "mtk.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MTK_HEALTH_SUCCESS_COUNTER_LIMIT 2 -#define MTK_HEALTH_FAIL_COUNTER_LIMIT 2 - -// XXX decrease this substantially, it should be only a few dozen bytes max. -#warning XXX trying 128 for now -#define MTK_BUFFER_SIZE 128 - -pthread_mutex_t *mtk_mutex; -gps_bin_mtk_state_t *mtk_state; -static struct vehicle_gps_position_s *mtk_gps; - -extern bool gps_mode_try_all; -extern bool gps_mode_success; -extern bool terminate_gps_thread; -extern bool gps_baud_try_all; -extern bool gps_verbose; -extern int current_gps_speed; - - -void mtk_decode_init(void) -{ - mtk_state->ck_a = 0; - mtk_state->ck_b = 0; - mtk_state->rx_count = 0; - mtk_state->decode_state = MTK_DECODE_UNINIT; - mtk_state->print_errors = false; -} - -void mtk_checksum(uint8_t b, uint8_t *ck_a, uint8_t *ck_b) -{ - *(ck_a) = *(ck_a) + b; - *(ck_b) = *(ck_b) + *(ck_a); -// printf("Checksum now: %d\n",*(ck_b)); -} - - - -int mtk_parse(uint8_t b, char *gps_rx_buffer) -{ -// printf("b=%x\n",b); - // Debug output to telemetry port - // PIOS_COM_SendBufferNonBlocking(PIOS_COM_TELEM_RF, &b, 1); - if (mtk_state->decode_state == MTK_DECODE_UNINIT) { - - if (b == 0xd0) { - mtk_state->decode_state = MTK_DECODE_GOT_CK_A; - } - - } else if (mtk_state->decode_state == MTK_DECODE_GOT_CK_A) { - if (b == 0xdd) { - mtk_state->decode_state = MTK_DECODE_GOT_CK_B; - - } else { - // Second start symbol was wrong, reset state machine - mtk_decode_init(); - } - - } else if (mtk_state->decode_state == MTK_DECODE_GOT_CK_B) { - // Add to checksum - if (mtk_state->rx_count < 33) mtk_checksum(b, &(mtk_state->ck_a), &(mtk_state->ck_b)); - - // Fill packet buffer - gps_rx_buffer[mtk_state->rx_count] = b; - (mtk_state->rx_count)++; -// printf("Rx count: %d\n",mtk_state->rx_count); - uint8_t ret = 0; - - /* Packet size minus checksum */ - if (mtk_state->rx_count >= 35) { - gps_bin_mtk_packet_t *packet = (gps_bin_mtk_packet_t *) gps_rx_buffer; - - /* Check if checksum is valid */ - if (mtk_state->ck_a == packet->ck_a && mtk_state->ck_b == packet->ck_b) { - mtk_gps->lat = packet->latitude * 10; // mtk: degrees*1e6, mavlink/ubx: degrees*1e7 - mtk_gps->lon = packet->longitude * 10; // mtk: degrees*1e6, mavlink/ubx: degrees*1e7 - mtk_gps->alt = (int32_t)(packet->msl_altitude * 10); // conversion from centimeters to millimeters, and from uint32_t to int16_t - mtk_gps->fix_type = packet->fix_type; - mtk_gps->eph = packet->hdop; - mtk_gps->epv = 65535; //unknown in mtk custom mode - mtk_gps->vel = packet->ground_speed; - mtk_gps->cog = (uint16_t)packet->heading; //mtk: degrees *1e2, mavlink/ubx: degrees *1e2 - mtk_gps->satellites_visible = packet->satellites; - - /* convert time and date information to unix timestamp */ - struct tm timeinfo; //TODO: test this conversion - uint32_t timeinfo_conversion_temp; - - timeinfo.tm_mday = packet->date * 1e-4; - timeinfo_conversion_temp = packet->date - timeinfo.tm_mday * 1e4; - timeinfo.tm_mon = timeinfo_conversion_temp * 1e-2 - 1; - timeinfo.tm_year = (timeinfo_conversion_temp - (timeinfo.tm_mon + 1) * 1e2) + 100; - - timeinfo.tm_hour = packet->utc_time * 1e-7; - timeinfo_conversion_temp = packet->utc_time - timeinfo.tm_hour * 1e7; - timeinfo.tm_min = timeinfo_conversion_temp * 1e-5; - timeinfo_conversion_temp -= timeinfo.tm_min * 1e5; - timeinfo.tm_sec = timeinfo_conversion_temp * 1e-3; - timeinfo_conversion_temp -= timeinfo.tm_sec * 1e3; - time_t epoch = mktime(&timeinfo); - mtk_gps->timestamp = hrt_absolute_time(); - mtk_gps->time_gps_usec = epoch * 1e6; //TODO: test this - mtk_gps->time_gps_usec += timeinfo_conversion_temp * 1e3; - - mtk_gps->counter_pos_valid++; - - mtk_gps->timestamp = hrt_absolute_time(); - -// printf("%lu; %lu; %d.%d.%d %d:%d:%d:%d\n", packet->date, packet->utc_time,timeinfo.tm_year, timeinfo.tm_mon, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, timeinfo_conversion_temp); - - pthread_mutex_lock(mtk_mutex); -// printf("Write timestamp /n"); - mtk_state->last_message_timestamp = hrt_absolute_time(); - pthread_mutex_unlock(mtk_mutex); - - ret = 1; -// printf("found package\n"); - - } else { - if (gps_verbose) printf("[gps] Checksum invalid\r\n"); - - ret = 0; - } - - // Reset state machine to decode next packet - mtk_decode_init(); -// printf("prepared for next state\n"); - return ret; - } - } - - return 0; // no valid packet found - -} - -int read_gps_mtk(int *fd, char *gps_rx_buffer, int buffer_size) // returns 1 if the thread should terminate -{ -// printf("in read_gps_mtk\n"); - uint8_t ret = 0; - - uint8_t c; - - int rx_count = 0; - int gpsRxOverflow = 0; - - struct pollfd fds; - fds.fd = *fd; - fds.events = POLLIN; - - // This blocks the task until there is something on the buffer - while (1) { - //check if the thread should terminate - if (terminate_gps_thread == true) { -// printf("terminate_gps_thread=%u ", terminate_gps_thread); -// printf("exiting mtk thread\n"); -// fflush(stdout); - ret = 1; - break; - } - - if (poll(&fds, 1, 1000) > 0) { - if (read(*fd, &c, 1) > 0) { -// printf("Read %x\n",c); - if (rx_count >= buffer_size) { - // The buffer is already full and we haven't found a valid NMEA sentence. - // Flush the buffer and note the overflow event. - gpsRxOverflow++; - rx_count = 0; - mtk_decode_init(); - - if (gps_verbose) printf("[gps] Buffer full\r\n"); - - } else { - //gps_rx_buffer[rx_count] = c; - rx_count++; - - } - - int msg_read = mtk_parse(c, gps_rx_buffer); - - if (msg_read > 0) { - // printf("Found sequence\n"); - break; - } - - } else { - break; - } - - } else { - break; - } - - } - - return ret; -} - -int configure_gps_mtk(int *fd) -{ - int success = 0; - size_t result_write; - result_write = write(*fd, MEDIATEK_REFRESH_RATE_10HZ, strlen(MEDIATEK_REFRESH_RATE_10HZ)); - - if (result_write != strlen(MEDIATEK_REFRESH_RATE_10HZ)) { - printf("[gps] Set update speed to 10 Hz failed\r\n"); - success = 1; - - } else { - if (gps_verbose) printf("[gps] Attempted to set update speed to 10 Hz..\r\n"); - } - - //set custom mode - result_write = write(*fd, MEDIATEK_CUSTOM_BINARY_MODE, strlen(MEDIATEK_CUSTOM_BINARY_MODE)); - - if (result_write != strlen(MEDIATEK_CUSTOM_BINARY_MODE)) { - //global_data_send_subsystem_info(&mtk_present); - printf("[gps] Set MTK custom mode failed\r\n"); - success = 1; - - } else { - //global_data_send_subsystem_info(&mtk_present_enabled); - if (gps_verbose) printf("[gps] Attempted to set MTK custom mode..\r\n"); - } - - return success; -} - -void *mtk_loop(void *args) -{ -// int oldstate; -// pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, oldstate); -// -// printf("in mtk loop\n"); - /* Set thread name */ - prctl(PR_SET_NAME, "gps mtk read", getpid()); - - /* Retrieve file descriptor and thread flag */ - struct arg_struct *arguments = (struct arg_struct *)args; - int *fd = arguments->fd_ptr; - bool *thread_should_exit = arguments->thread_should_exit_ptr; - - /* Initialize gps stuff */ -// int buffer_size = 1000; -// char * gps_rx_buffer = malloc(buffer_size*sizeof(char)); - char gps_rx_buffer[MTK_BUFFER_SIZE]; - - /* set parameters for mtk custom */ - - if (configure_gps_mtk(fd) != 0) { - printf("[gps] Could not write serial port..\r\n"); - - /* Write shared variable sys_status */ - - //global_data_send_subsystem_info(&mtk_present); - - } else { - if (gps_verbose) printf("[gps] Configuration finished, awaiting GPS data..\r\n"); - - - /* Write shared variable sys_status */ - - //global_data_send_subsystem_info(&mtk_present_enabled); - } - - /* advertise GPS topic */ - struct vehicle_gps_position_s mtk_gps_d; - mtk_gps = &mtk_gps_d; - orb_advert_t gps_handle = orb_advertise(ORB_ID(vehicle_gps_position), mtk_gps); - - while (!(*thread_should_exit)) { - /* Parse a message from the gps receiver */ - if (OK == read_gps_mtk(fd, gps_rx_buffer, MTK_BUFFER_SIZE)) { - - /* publish new GPS position */ - orb_publish(ORB_ID(vehicle_gps_position), gps_handle, mtk_gps); - - } else { - /* de-advertise */ - close(gps_handle); - break; - } - - } - - close(gps_handle); - if(gps_verbose) printf("[gps] mtk loop is going to terminate\n"); - return NULL; -} - -void *mtk_watchdog_loop(void *args) -{ -// printf("in mtk watchdog loop\n"); - fflush(stdout); - - /* Set thread name */ - prctl(PR_SET_NAME, "gps mtk watchdog", getpid()); - - /* Retrieve file descriptor and thread flag */ - struct arg_struct *arguments = (struct arg_struct *)args; - int *fd = arguments->fd_ptr; - bool *thread_should_exit = arguments->thread_should_exit_ptr; - - bool mtk_healthy = false; - - uint8_t mtk_fail_count = 0; - uint8_t mtk_success_count = 0; - bool once_ok = false; - - int mavlink_fd = open(MAVLINK_LOG_DEVICE, 0); - - - while (!(*thread_should_exit)) { - fflush(stdout); - - /* if we have no update for a long time reconfigure gps */ - pthread_mutex_lock(mtk_mutex); - uint64_t timestamp_now = hrt_absolute_time(); - bool all_okay = true; - - if (timestamp_now - mtk_state->last_message_timestamp > MTK_WATCHDOG_CRITICAL_TIME_MICROSECONDS) { - all_okay = false; - } - - pthread_mutex_unlock(mtk_mutex); - - if (!all_okay) { -// printf("mtk unhealthy\n"); - mtk_fail_count++; - /* gps error */ -// if (err_skip_counter == 0) -// { -// printf("[gps] GPS module not connected or not responding..\n"); -// err_skip_counter = 20; -// } -// err_skip_counter--; - -// printf("gps_mode_try_all =%u, mtk_fail_count=%u, mtk_healthy=%u, once_ok=%u\n", gps_mode_try_all, mtk_fail_count, mtk_healthy, once_ok); - - /* If we have too many failures and another mode or baud should be tried, exit... */ - if ((gps_mode_try_all == true || gps_baud_try_all == true) && (mtk_fail_count >= MTK_HEALTH_FAIL_COUNTER_LIMIT) && (mtk_healthy == false) && once_ok == false) { - if (gps_verbose) printf("[gps] Connection attempt failed, no MTK module found\r\n"); - - gps_mode_success = false; - break; - } - - if (mtk_healthy && mtk_fail_count >= MTK_HEALTH_FAIL_COUNTER_LIMIT) { - printf("[gps] ERROR: MTK GPS module stopped responding\r\n"); - // global_data_send_subsystem_info(&mtk_present_enabled); - mavlink_log_critical(mavlink_fd, "[gps] MTK module stopped responding\n"); - mtk_healthy = false; - mtk_success_count = 0; - - } - - /* trying to reconfigure the gps configuration */ - configure_gps_mtk(fd); - fflush(stdout); - - } else { - /* gps healthy */ - mtk_success_count++; - mtk_fail_count = 0; - once_ok = true; // XXX Should this be true on a single success, or on same criteria as mtk_healthy? - - if (!mtk_healthy && mtk_success_count >= MTK_HEALTH_SUCCESS_COUNTER_LIMIT) { - printf("[gps] MTK module found, status ok (baud=%d)\r\n", current_gps_speed); - /* MTK never has sat info */ - // XXX Check if lock makes sense here - mtk_gps->satellite_info_available = 0; - // global_data_send_subsystem_info(&mtk_present_enabled_healthy); - mavlink_log_info(mavlink_fd, "[gps] MTK custom binary module found, status ok\n"); - mtk_healthy = true; - } - } - - usleep(MTK_WATCHDOG_WAIT_TIME_MICROSECONDS); - } - if(gps_verbose) printf("[gps] mtk watchdog is going to terminate\n"); - close(mavlink_fd); - return NULL; -} diff --git a/apps/gps/mtk.h b/apps/gps/mtk.h deleted file mode 100644 index 9fc1caec8..000000000 --- a/apps/gps/mtk.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * mtk.h - * - * Created on: Mar 6, 2012 - * Author: thomasgubler - */ - -#ifndef MTK_H_ -#define MTK_H_ - -#include -#include -#include -#include -#include -#include -#include - -//Definition for mtk custom mode -#define MEDIATEK_REFRESH_RATE_4HZ "$PMTK220,250*29\r\n" //refresh rate - 4Hz - 250 milliseconds -#define MEDIATEK_REFRESH_RATE_5HZ "$PMTK220,200*2C\r\n" -#define MEDIATEK_REFRESH_RATE_10HZ "$PMTK220,100*2F\r\n" //refresh rate - 10Hz - 100 milliseconds -#define MEDIATEK_FACTORY_RESET "$PMTK104*37\r\n" //clear current settings -#define MEDIATEK_CUSTOM_BINARY_MODE "$PGCMD,16,0,0,0,0,0*6A\r\n" -#define MEDIATEK_FULL_COLD_RESTART "$PMTK104*37\r\n" -//#define NMEA_GGA_ENABLE "$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0*27\r\n" //Set GGA messages - -//definitions for watchdog -#define MTK_WATCHDOG_CRITICAL_TIME_MICROSECONDS 2000000 -#define MTK_WATCHDOG_WAIT_TIME_MICROSECONDS 800000 - - - - -// ************ -// the structure of the binary packet - -typedef struct { - uint8_t payload; ///< Number of payload bytes - int32_t latitude; ///< Latitude in degrees * 10^7 - int32_t longitude; ///< Longitude in degrees * 10^7 - uint32_t msl_altitude; ///< MSL altitude in meters * 10^2 - uint32_t ground_speed; ///< FIXME SPEC UNCLEAR - int32_t heading; - uint8_t satellites; - uint8_t fix_type; - uint32_t date; - uint32_t utc_time; - uint16_t hdop; - uint8_t ck_a; - uint8_t ck_b; -} __attribute__((__packed__)) type_gps_bin_mtk_packet; - -typedef type_gps_bin_mtk_packet gps_bin_mtk_packet_t; - -enum MTK_DECODE_STATES { - MTK_DECODE_UNINIT = 0, - MTK_DECODE_GOT_CK_A = 1, - MTK_DECODE_GOT_CK_B = 2 -}; - -typedef struct { - union { - uint16_t ck; - struct { - uint8_t ck_a; - uint8_t ck_b; - }; - }; - uint8_t decode_state; -// bool new_data; -// uint8_t fix; - bool print_errors; - int16_t rx_count; - - uint64_t last_message_timestamp; -} __attribute__((__packed__)) type_gps_bin_mtk_state; - -typedef type_gps_bin_mtk_state gps_bin_mtk_state_t; - -extern pthread_mutex_t *mtk_mutex; -extern gps_bin_mtk_state_t *mtk_state; - -void mtk_decode_init(void); - -void mtk_checksum(uint8_t b, uint8_t *ck_a, uint8_t *ck_b); - -int mtk_parse(uint8_t b, char *gps_rx_buffer); - -int read_gps_mtk(int *fd, char *gps_rx_buffer, int buffer_size); - -int configure_gps_mtk(int *fd); - -void *mtk_loop(void *args); - -void *mtk_watchdog_loop(void *args); - -#endif /* MTK_H_ */ diff --git a/apps/gps/nmea_helper.c b/apps/gps/nmea_helper.c deleted file mode 100644 index 1a50371c1..000000000 --- a/apps/gps/nmea_helper.c +++ /dev/null @@ -1,345 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: Julian Oes - * Thomas Gubler - * - * 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 PX4 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. - * - ****************************************************************************/ - -/* @file NMEA protocol implementation */ -#include "gps.h" -#include "nmea_helper.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define NMEA_HEALTH_SUCCESS_COUNTER_LIMIT 2 -#define NMEA_HEALTH_FAIL_COUNTER_LIMIT 2 - -#define NMEA_BUFFER_SIZE 1000 - -pthread_mutex_t *nmea_mutex; -gps_bin_nmea_state_t *nmea_state; -static struct vehicle_gps_position_s *nmea_gps; - -extern bool gps_mode_try_all; -extern bool gps_mode_success; -extern bool terminate_gps_thread; -extern bool gps_baud_try_all; -extern bool gps_verbose; -extern int current_gps_speed; - - -int read_gps_nmea(int *fd, char *gps_rx_buffer, int buffer_size, nmeaINFO *info, nmeaPARSER *parser) -{ - int ret = 1; - char c; - int start_flag = 0; - int found_cr = 0; - int rx_count = 0; - int gpsRxOverflow = 0; - - struct pollfd fds; - fds.fd = *fd; - fds.events = POLLIN; - - // NMEA or SINGLE-SENTENCE GPS mode - - - while (1) { - //check if the thread should terminate - if (terminate_gps_thread == true) { -// printf("terminate_gps_thread=%u ", terminate_gps_thread); -// printf("exiting mtk thread\n"); -// fflush(stdout); - ret = 2; - break; - } - - if (poll(&fds, 1, 1000) > 0) { - if (read(*fd, &c, 1) > 0) { - // detect start while acquiring stream - // printf("Char = %c\n", c); - if (!start_flag && (c == '$')) { - start_flag = 1; - found_cr = 0; - rx_count = 0; - - } else if (!start_flag) { // keep looking for start sign - continue; - } - - if (rx_count >= buffer_size) { - // The buffer is already full and we haven't found a valid NMEA sentence. - // Flush the buffer and note the overflow event. - gpsRxOverflow++; - start_flag = 0; - found_cr = 0; - rx_count = 0; - - if (gps_verbose) printf("\t[gps] Buffer full\n"); - - } else { - // store chars in buffer - gps_rx_buffer[rx_count] = c; - rx_count++; - } - - // look for carriage return CR - if (start_flag && c == 0x0d) { - found_cr = 1; - } - - // and then look for line feed LF - if (start_flag && found_cr && c == 0x0a) { - // parse one NMEA line, use buffer up to rx_count - if (nmea_parse(parser, gps_rx_buffer, rx_count, info) > 0) { - ret = 0; - } - - break; - } - - } else { - break; - } - - } else { - break; - } - } - - - - // As soon as one NMEA message has been parsed, we break out of the loop and end here - return(ret); -} - - -/** - * \brief Convert NDEG (NMEA degree) to fractional degree - */ -float ndeg2degree(float val) -{ - float deg = ((int)(val / 100)); - val = deg + (val - deg * 100) / 60; - return val; -} - -void *nmea_loop(void *args) -{ - /* Set thread name */ - prctl(PR_SET_NAME, "gps nmea read", getpid()); - - /* Retrieve file descriptor and thread flag */ - struct arg_struct *arguments = (struct arg_struct *)args; - int *fd = arguments->fd_ptr; - bool *thread_should_exit = arguments->thread_should_exit_ptr; - - /* Initialize gps stuff */ - nmeaINFO info_d; - nmeaINFO *info = &info_d; - char gps_rx_buffer[NMEA_BUFFER_SIZE]; - - /* gps parser (nmea) */ - nmeaPARSER parser; - nmea_parser_init(&parser); - nmea_zero_INFO(info); - - /* advertise GPS topic */ - struct vehicle_gps_position_s nmea_gps_d = {.counter=0}; - nmea_gps = &nmea_gps_d; - orb_advert_t gps_handle = orb_advertise(ORB_ID(vehicle_gps_position), nmea_gps); - - while (!(*thread_should_exit)) { - /* Parse a message from the gps receiver */ - uint8_t read_res = read_gps_nmea(fd, gps_rx_buffer, NMEA_BUFFER_SIZE, info, &parser); - - if (0 == read_res) { - - /* convert data, ready it for publishing */ - - /* convert nmea utc time to usec */ - struct tm timeinfo; - timeinfo.tm_year = info->utc.year; - timeinfo.tm_mon = info->utc.mon; - timeinfo.tm_mday = info->utc.day; - timeinfo.tm_hour = info->utc.hour; - timeinfo.tm_min = info->utc.min; - timeinfo.tm_sec = info->utc.sec; - - time_t epoch = mktime(&timeinfo); - - // printf("%d.%d.%d %d:%d:%d:%d\n", timeinfo.tm_year, timeinfo.tm_mon, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, info->utc.hsec); - - nmea_gps->timestamp = hrt_absolute_time(); - nmea_gps->time_gps_usec = (uint64_t)((epoch)*1000000 + (info->utc.hsec)*10000); - nmea_gps->fix_type = (uint8_t)info->fix; - nmea_gps->lat = (int32_t)(ndeg2degree(info->lat) * 1e7f); - nmea_gps->lon = (int32_t)(ndeg2degree(info->lon) * 1e7f); - nmea_gps->alt = (int32_t)(info->elv * 1000.0f); - nmea_gps->eph = (uint16_t)(info->HDOP * 100); //TODO:test scaling - nmea_gps->epv = (uint16_t)(info->VDOP * 100); //TODO:test scaling - nmea_gps->vel = (uint16_t)(info->speed * 1000 / 36); //*1000/3600*100 - nmea_gps->cog = (uint16_t)info->direction*100; //nmea: degrees float, ubx/mavlink: degrees*1e2 - nmea_gps->satellites_visible = (uint8_t)info->satinfo.inview; - - int i = 0; - - /* Write info about individual satellites */ - for (i = 0; i < 12; i++) { - nmea_gps->satellite_prn[i] = (uint8_t)info->satinfo.sat[i].id; - nmea_gps->satellite_used[i] = (uint8_t)info->satinfo.sat[i].in_use; - nmea_gps->satellite_elevation[i] = (uint8_t)info->satinfo.sat[i].elv; - nmea_gps->satellite_azimuth[i] = (uint8_t)info->satinfo.sat[i].azimuth; - nmea_gps->satellite_snr[i] = (uint8_t)info->satinfo.sat[i].sig; - } - - if (nmea_gps->satellites_visible > 0) { - nmea_gps->satellite_info_available = 1; - - } else { - nmea_gps->satellite_info_available = 0; - } - - nmea_gps->counter_pos_valid++; - - nmea_gps->timestamp = hrt_absolute_time(); - nmea_gps->counter++; - - pthread_mutex_lock(nmea_mutex); - nmea_state->last_message_timestamp = hrt_absolute_time(); - pthread_mutex_unlock(nmea_mutex); - - /* publish new GPS position */ - orb_publish(ORB_ID(vehicle_gps_position), gps_handle, nmea_gps); - - } else if (read_res == 2) { //termination - /* de-advertise */ - close(gps_handle); - break; - } - - } - - //destroy gps parser - nmea_parser_destroy(&parser); - if(gps_verbose) printf("[gps] nmea loop is going to terminate\n"); - return NULL; - -} - -void *nmea_watchdog_loop(void *args) -{ - /* Set thread name */ - prctl(PR_SET_NAME, "gps nmea watchdog", getpid()); - - bool nmea_healthy = false; - - uint8_t nmea_fail_count = 0; - uint8_t nmea_success_count = 0; - bool once_ok = false; - - /* Retrieve file descriptor and thread flag */ - struct arg_struct *arguments = (struct arg_struct *)args; - //int *fd = arguments->fd_ptr; - bool *thread_should_exit = arguments->thread_should_exit_ptr; - - int mavlink_fd = open(MAVLINK_LOG_DEVICE, 0); - - while (!(*thread_should_exit)) { -// printf("nmea_watchdog_loop : while "); - /* if we have no update for a long time print warning (in nmea mode there is no reconfigure) */ - pthread_mutex_lock(nmea_mutex); - uint64_t timestamp_now = hrt_absolute_time(); - bool all_okay = true; - - if (timestamp_now - nmea_state->last_message_timestamp > NMEA_WATCHDOG_CRITICAL_TIME_MICROSECONDS) { - all_okay = false; - } - - pthread_mutex_unlock(nmea_mutex); - - if (!all_okay) { - /* gps error */ - nmea_fail_count++; -// printf("nmea error, nmea_fail_count=%u\n", nmea_fail_count); -// fflush(stdout); - - /* If we have too many failures and another mode or baud should be tried, exit... */ - if ((gps_mode_try_all == true || gps_baud_try_all == true) && (nmea_fail_count >= NMEA_HEALTH_FAIL_COUNTER_LIMIT) && (nmea_healthy == false) && once_ok == false) { - if (gps_verbose) printf("\t[gps] no NMEA module found\n"); - - gps_mode_success = false; - break; - } - - if (nmea_healthy && nmea_fail_count >= NMEA_HEALTH_FAIL_COUNTER_LIMIT) { - printf("\t[gps] ERROR: NMEA GPS module stopped responding\n"); - // global_data_send_subsystem_info(&nmea_present_enabled); - mavlink_log_critical(mavlink_fd, "[gps] NMEA module stopped responding\n"); - nmea_healthy = false; - nmea_success_count = 0; - - } - - - - fflush(stdout); - sleep(1); - - } else { - /* gps healthy */ -// printf("\t[gps] nmea success\n"); - nmea_success_count++; - - if (!nmea_healthy && nmea_success_count >= NMEA_HEALTH_SUCCESS_COUNTER_LIMIT) { - printf("[gps] NMEA module found, status ok (baud=%d)\r\n", current_gps_speed); - // global_data_send_subsystem_info(&nmea_present_enabled_healthy); - mavlink_log_info(mavlink_fd, "[gps] NMEA module found, status ok\n"); - nmea_healthy = true; - nmea_fail_count = 0; - once_ok = true; - } - - } - - usleep(NMEA_WATCHDOG_WAIT_TIME_MICROSECONDS); - } - if(gps_verbose) printf("[gps] nmea watchdog loop is going to terminate\n"); - close(mavlink_fd); - return NULL; -} diff --git a/apps/gps/nmea_helper.h b/apps/gps/nmea_helper.h deleted file mode 100644 index 3a853dd13..000000000 --- a/apps/gps/nmea_helper.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * nmea_helper.h - * - * Created on: Mar 15, 2012 - * Author: thomasgubler - */ - -#ifndef NMEA_H_ -#define NMEA_H_ - -#include -#include -#include -#include -#include "nmealib/nmea/nmea.h" - - -//definitions for watchdog -#define NMEA_WATCHDOG_CRITICAL_TIME_MICROSECONDS 2000000 -#define NMEA_WATCHDOG_WAIT_TIME_MICROSECONDS 800000 - -typedef struct { - uint64_t last_message_timestamp; -} __attribute__((__packed__)) type_gps_bin_nmea_state; - -typedef type_gps_bin_nmea_state gps_bin_nmea_state_t; - -extern gps_bin_nmea_state_t *nmea_state; -extern pthread_mutex_t *nmea_mutex; - - - -int read_gps_nmea(int *fd, char *gps_rx_buffer, int buffer_size, nmeaINFO *info, nmeaPARSER *parser); - -void *nmea_loop(void *arg); - -void *nmea_watchdog_loop(void *arg); - -/** - * \brief Convert NDEG (NMEA degree) to fractional degree - */ -float ndeg2degree(float val); - -void nmea_init(void); - - -#endif /* NMEA_H_ */ diff --git a/apps/gps/nmealib/LICENSE.TXT b/apps/gps/nmealib/LICENSE.TXT deleted file mode 100644 index 807db7916..000000000 --- a/apps/gps/nmealib/LICENSE.TXT +++ /dev/null @@ -1,506 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - - - diff --git a/apps/gps/nmealib/README.TXT b/apps/gps/nmealib/README.TXT deleted file mode 100644 index 8ede6a036..000000000 --- a/apps/gps/nmealib/README.TXT +++ /dev/null @@ -1,26 +0,0 @@ -NMEA library see: http://nmea.sourceforge.net/ - -Disclaimer - -The National Marine Electronics Association (NMEA) has developed a specification that defines the interface between various pieces of marine electronic equipment. The standard permits marine electronics to send information to computers and to other marine equipment. -Most computer programs that provide real time position information understand and expect data to be in NMEA format. This data includes the complete PVT (position, velocity, time) solution computed by the GPS receiver. The idea of NMEA is to send a line of data called a sentence that is totally self contained and independent from other sentences. All NMEA sentences is sequences of ACSII symbols begins with a '$' and ends with a carriage return/line feed sequence and can be no longer than 80 characters of visible text (plus the line terminators). - -Introduction - -We present library in 'C' programming language for work with NMEA protocol. Small and easy to use. The library build on different compilers under different platforms (see below). The code was tested in real projects. Just download and try... - -Features - -- Analysis NMEA sentences and granting GPS data in C structures -- Generate NMEA sentences -- Supported sentences: GPGGA, GPGSA, GPGSV, GPRMC, GPVTG -- Multilevel architecture of algorithms -- Additional functions of geographical mathematics and work with navigation data - -Supported (tested) platforms - -- Microsoft Windows (MS Visual Studio 8.0, GCC) -- Windows Mobile, Windows CE (MS Visual Studio 8.0) -- UNIX (GCC) - -Licence: LGPL diff --git a/apps/gps/nmealib/context.c b/apps/gps/nmealib/context.c deleted file mode 100644 index 6ee2f5ad3..000000000 --- a/apps/gps/nmealib/context.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: context.c 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -#include "nmea/context.h" - -#include -#include -#include - -nmeaPROPERTY * nmea_property(void) -{ - static nmeaPROPERTY prop = { - 0, 0, NMEA_DEF_PARSEBUFF - }; - - return ∝ -} - -void nmea_trace(const char *str, ...) -{ - int size; - va_list arg_list; - char buff[NMEA_DEF_PARSEBUFF]; - nmeaTraceFunc func = nmea_property()->trace_func; - - if(func) - { - va_start(arg_list, str); - size = NMEA_POSIX(vsnprintf)(&buff[0], NMEA_DEF_PARSEBUFF - 1, str, arg_list); - va_end(arg_list); - - if(size > 0) - (*func)(&buff[0], size); - } -} - -void nmea_trace_buff(const char *buff, int buff_size) -{ - nmeaTraceFunc func = nmea_property()->trace_func; - if(func && buff_size) - (*func)(buff, buff_size); -} - -void nmea_error(const char *str, ...) -{ - int size; - va_list arg_list; - char buff[NMEA_DEF_PARSEBUFF]; - nmeaErrorFunc func = nmea_property()->error_func; - - if(func) - { - va_start(arg_list, str); - size = NMEA_POSIX(vsnprintf)(&buff[0], NMEA_DEF_PARSEBUFF - 1, str, arg_list); - va_end(arg_list); - - if(size > 0) - (*func)(&buff[0], size); - } -} diff --git a/apps/gps/nmealib/generate.c b/apps/gps/nmealib/generate.c deleted file mode 100644 index 4c9389300..000000000 --- a/apps/gps/nmealib/generate.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: generate.c 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -#include "nmea/tok.h" -#include "nmea/sentence.h" -#include "nmea/generate.h" -#include "nmea/units.h" - -#include -#include -#include - -int nmea_gen_GPGGA(char *buff, int buff_sz, nmeaGPGGA *pack) -{ - return nmea_printf(buff, buff_sz, - "$GPGGA,%02d%02d%02d.%02d,%07.4f,%C,%07.4f,%C,%1d,%02d,%03.1f,%03.1f,%C,%03.1f,%C,%03.1f,%04d", - pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec, - pack->lat, pack->ns, pack->lon, pack->ew, - pack->sig, pack->satinuse, pack->HDOP, pack->elv, pack->elv_units, - pack->diff, pack->diff_units, pack->dgps_age, pack->dgps_sid); -} - -int nmea_gen_GPGSA(char *buff, int buff_sz, nmeaGPGSA *pack) -{ - return nmea_printf(buff, buff_sz, - "$GPGSA,%C,%1d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%03.1f,%03.1f,%03.1f", - pack->fix_mode, pack->fix_type, - pack->sat_prn[0], pack->sat_prn[1], pack->sat_prn[2], pack->sat_prn[3], pack->sat_prn[4], pack->sat_prn[5], - pack->sat_prn[6], pack->sat_prn[7], pack->sat_prn[8], pack->sat_prn[9], pack->sat_prn[10], pack->sat_prn[11], - pack->PDOP, pack->HDOP, pack->VDOP); -} - -int nmea_gen_GPGSV(char *buff, int buff_sz, nmeaGPGSV *pack) -{ - return nmea_printf(buff, buff_sz, - "$GPGSV,%1d,%1d,%02d," - "%02d,%02d,%03d,%02d," - "%02d,%02d,%03d,%02d," - "%02d,%02d,%03d,%02d," - "%02d,%02d,%03d,%02d", - pack->pack_count, pack->pack_index + 1, pack->sat_count, - pack->sat_data[0].id, pack->sat_data[0].elv, pack->sat_data[0].azimuth, pack->sat_data[0].sig, - pack->sat_data[1].id, pack->sat_data[1].elv, pack->sat_data[1].azimuth, pack->sat_data[1].sig, - pack->sat_data[2].id, pack->sat_data[2].elv, pack->sat_data[2].azimuth, pack->sat_data[2].sig, - pack->sat_data[3].id, pack->sat_data[3].elv, pack->sat_data[3].azimuth, pack->sat_data[3].sig); -} - -int nmea_gen_GPRMC(char *buff, int buff_sz, nmeaGPRMC *pack) -{ - return nmea_printf(buff, buff_sz, - "$GPRMC,%02d%02d%02d.%02d,%C,%07.4f,%C,%07.4f,%C,%03.1f,%03.1f,%02d%02d%02d,%03.1f,%C,%C", - pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec, - pack->status, pack->lat, pack->ns, pack->lon, pack->ew, - pack->speed, pack->direction, - pack->utc.day, pack->utc.mon + 1, pack->utc.year - 100, - pack->declination, pack->declin_ew, pack->mode); -} - -int nmea_gen_GPVTG(char *buff, int buff_sz, nmeaGPVTG *pack) -{ - return nmea_printf(buff, buff_sz, - "$GPVTG,%.1f,%C,%.1f,%C,%.1f,%C,%.1f,%C", - pack->dir, pack->dir_t, - pack->dec, pack->dec_m, - pack->spn, pack->spn_n, - pack->spk, pack->spk_k); -} - -void nmea_info2GPGGA(const nmeaINFO *info, nmeaGPGGA *pack) -{ - nmea_zero_GPGGA(pack); - - pack->utc = info->utc; - pack->lat = fabs(info->lat); - pack->ns = ((info->lat > 0)?'N':'S'); - pack->lon = fabs(info->lon); - pack->ew = ((info->lon > 0)?'E':'W'); - pack->sig = info->sig; - pack->satinuse = info->satinfo.inuse; - pack->HDOP = info->HDOP; - pack->elv = info->elv; -} - -void nmea_info2GPGSA(const nmeaINFO *info, nmeaGPGSA *pack) -{ - int it; - - nmea_zero_GPGSA(pack); - - pack->fix_type = info->fix; - pack->PDOP = info->PDOP; - pack->HDOP = info->HDOP; - pack->VDOP = info->VDOP; - - for(it = 0; it < NMEA_MAXSAT; ++it) - { - pack->sat_prn[it] = - ((info->satinfo.sat[it].in_use)?info->satinfo.sat[it].id:0); - } -} - -int nmea_gsv_npack(int sat_count) -{ - int pack_count = (int)ceil(((float)sat_count) / NMEA_SATINPACK); - - if(0 == pack_count) - pack_count = 1; - - return pack_count; -} - -void nmea_info2GPGSV(const nmeaINFO *info, nmeaGPGSV *pack, int pack_idx) -{ - int sit, pit; - - nmea_zero_GPGSV(pack); - - pack->sat_count = (info->satinfo.inview <= NMEA_MAXSAT)?info->satinfo.inview:NMEA_MAXSAT; - pack->pack_count = nmea_gsv_npack(pack->sat_count); - - if(pack->pack_count == 0) - pack->pack_count = 1; - - if(pack_idx >= pack->pack_count) - pack->pack_index = pack_idx % pack->pack_count; - else - pack->pack_index = pack_idx; - - for(pit = 0, sit = pack->pack_index * NMEA_SATINPACK; pit < NMEA_SATINPACK; ++pit, ++sit) - pack->sat_data[pit] = info->satinfo.sat[sit]; -} - -void nmea_info2GPRMC(const nmeaINFO *info, nmeaGPRMC *pack) -{ - nmea_zero_GPRMC(pack); - - pack->utc = info->utc; - pack->status = ((info->sig > 0)?'A':'V'); - pack->lat = fabs(info->lat); - pack->ns = ((info->lat > 0)?'N':'S'); - pack->lon = fabs(info->lon); - pack->ew = ((info->lon > 0)?'E':'W'); - pack->speed = info->speed / NMEA_TUD_KNOTS; - pack->direction = info->direction; - pack->declination = info->declination; - pack->declin_ew = 'E'; - pack->mode = ((info->sig > 0)?'A':'N'); -} - -void nmea_info2GPVTG(const nmeaINFO *info, nmeaGPVTG *pack) -{ - nmea_zero_GPVTG(pack); - - pack->dir = info->direction; - pack->dec = info->declination; - pack->spn = info->speed / NMEA_TUD_KNOTS; - pack->spk = info->speed; -} - -int nmea_generate( - char *buff, int buff_sz, - const nmeaINFO *info, - int generate_mask - ) -{ - int gen_count = 0, gsv_it, gsv_count; - int pack_mask = generate_mask; - - nmeaGPGGA gga; - nmeaGPGSA gsa; - nmeaGPGSV gsv; - nmeaGPRMC rmc; - nmeaGPVTG vtg; - - if(!buff) - return 0; - - while(pack_mask) - { - if(pack_mask & GPGGA) - { - nmea_info2GPGGA(info, &gga); - gen_count += nmea_gen_GPGGA(buff + gen_count, buff_sz - gen_count, &gga); - pack_mask &= ~GPGGA; - } - else if(pack_mask & GPGSA) - { - nmea_info2GPGSA(info, &gsa); - gen_count += nmea_gen_GPGSA(buff + gen_count, buff_sz - gen_count, &gsa); - pack_mask &= ~GPGSA; - } - else if(pack_mask & GPGSV) - { - gsv_count = nmea_gsv_npack(info->satinfo.inview); - for(gsv_it = 0; gsv_it < gsv_count && buff_sz - gen_count > 0; ++gsv_it) - { - nmea_info2GPGSV(info, &gsv, gsv_it); - gen_count += nmea_gen_GPGSV(buff + gen_count, buff_sz - gen_count, &gsv); - } - pack_mask &= ~GPGSV; - } - else if(pack_mask & GPRMC) - { - nmea_info2GPRMC(info, &rmc); - gen_count += nmea_gen_GPRMC(buff + gen_count, buff_sz - gen_count, &rmc); - pack_mask &= ~GPRMC; - } - else if(pack_mask & GPVTG) - { - nmea_info2GPVTG(info, &vtg); - gen_count += nmea_gen_GPVTG(buff + gen_count, buff_sz - gen_count, &vtg); - pack_mask &= ~GPVTG; - } - else - break; - - if(buff_sz - gen_count <= 0) - break; - } - - return gen_count; -} diff --git a/apps/gps/nmealib/generator.c b/apps/gps/nmealib/generator.c deleted file mode 100644 index ce40b0f1a..000000000 --- a/apps/gps/nmealib/generator.c +++ /dev/null @@ -1,399 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: generator.c 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -#include "nmea/gmath.h" -#include "nmea/generate.h" -#include "nmea/generator.h" -#include "nmea/context.h" - -#include -#include - -#if defined(NMEA_WIN) && defined(_MSC_VER) -# pragma warning(disable: 4100) /* unreferenced formal parameter */ -#endif - -float nmea_random(float min, float max) -{ - static float rand_max = MAX_RAND;//RAND_MAX; //nuttx defines MAX_RAND instead of RAND_MAX - float rand_val = rand(); - float bounds = max - min; - return min + (rand_val * bounds) / rand_max; -} - -/* - * low level - */ - -int nmea_gen_init(nmeaGENERATOR *gen, nmeaINFO *info) -{ - int RetVal = 1; int smask = info->smask; - nmeaGENERATOR *igen = gen; - - nmea_zero_INFO(info); - info->smask = smask; - - info->lat = NMEA_DEF_LAT; - info->lon = NMEA_DEF_LON; - - while(RetVal && igen) - { - if(igen->init_call) - RetVal = (*igen->init_call)(igen, info); - igen = igen->next; - } - - return RetVal; -} - -int nmea_gen_loop(nmeaGENERATOR *gen, nmeaINFO *info) -{ - int RetVal = 1; - - if(gen->loop_call) - RetVal = (*gen->loop_call)(gen, info); - - if(RetVal && gen->next) - RetVal = nmea_gen_loop(gen->next, info); - - return RetVal; -} - -int nmea_gen_reset(nmeaGENERATOR *gen, nmeaINFO *info) -{ - int RetVal = 1; - - if(gen->reset_call) - RetVal = (*gen->reset_call)(gen, info); - - return RetVal; -} - -void nmea_gen_destroy(nmeaGENERATOR *gen) -{ - if(gen->next) - { - nmea_gen_destroy(gen->next); - gen->next = 0; - } - - if(gen->destroy_call) - (*gen->destroy_call)(gen); - - free(gen); -} - -void nmea_gen_add(nmeaGENERATOR *to, nmeaGENERATOR *gen) -{ - if(to->next) - nmea_gen_add(to->next, gen); - else - to->next = gen; -} - -int nmea_generate_from( - char *buff, int buff_sz, - nmeaINFO *info, - nmeaGENERATOR *gen, - int generate_mask - ) -{ - int retval; - - if(0 != (retval = nmea_gen_loop(gen, info))) - retval = nmea_generate(buff, buff_sz, info, generate_mask); - - return retval; -} - -/* - * NOISE generator - */ - -int nmea_igen_noise_init(nmeaGENERATOR *gen, nmeaINFO *info) -{ - return 1; -} - -int nmea_igen_noise_loop(nmeaGENERATOR *gen, nmeaINFO *info) -{ - int it; - int in_use; - - info->sig = (int)nmea_random(1, 3); - info->PDOP = nmea_random(0, 9); - info->HDOP = nmea_random(0, 9); - info->VDOP = nmea_random(0, 9); - info->fix = (int)nmea_random(2, 3); - info->lat = nmea_random(0, 100); - info->lon = nmea_random(0, 100); - info->speed = nmea_random(0, 100); - info->direction = nmea_random(0, 360); - info->declination = nmea_random(0, 360); - info->elv = (int)nmea_random(-100, 100); - - info->satinfo.inuse = 0; - info->satinfo.inview = 0; - - for(it = 0; it < 12; ++it) - { - info->satinfo.sat[it].id = it; - info->satinfo.sat[it].in_use = in_use = (int)nmea_random(0, 3); - info->satinfo.sat[it].elv = (int)nmea_random(0, 90); - info->satinfo.sat[it].azimuth = (int)nmea_random(0, 359); - info->satinfo.sat[it].sig = (int)(in_use?nmea_random(40, 99):nmea_random(0, 40)); - - if(in_use) - info->satinfo.inuse++; - if(info->satinfo.sat[it].sig > 0) - info->satinfo.inview++; - } - - return 1; -} - -int nmea_igen_noise_reset(nmeaGENERATOR *gen, nmeaINFO *info) -{ - return 1; -} - -/* - * STATIC generator - */ - -int nmea_igen_static_loop(nmeaGENERATOR *gen, nmeaINFO *info) -{ - nmea_time_now(&info->utc); - return 1; -}; - -int nmea_igen_static_reset(nmeaGENERATOR *gen, nmeaINFO *info) -{ - info->satinfo.inuse = 4; - info->satinfo.inview = 4; - - info->satinfo.sat[0].id = 1; - info->satinfo.sat[0].in_use = 1; - info->satinfo.sat[0].elv = 50; - info->satinfo.sat[0].azimuth = 0; - info->satinfo.sat[0].sig = 99; - - info->satinfo.sat[1].id = 2; - info->satinfo.sat[1].in_use = 1; - info->satinfo.sat[1].elv = 50; - info->satinfo.sat[1].azimuth = 90; - info->satinfo.sat[1].sig = 99; - - info->satinfo.sat[2].id = 3; - info->satinfo.sat[2].in_use = 1; - info->satinfo.sat[2].elv = 50; - info->satinfo.sat[2].azimuth = 180; - info->satinfo.sat[2].sig = 99; - - info->satinfo.sat[3].id = 4; - info->satinfo.sat[3].in_use = 1; - info->satinfo.sat[3].elv = 50; - info->satinfo.sat[3].azimuth = 270; - info->satinfo.sat[3].sig = 99; - - return 1; -} - -int nmea_igen_static_init(nmeaGENERATOR *gen, nmeaINFO *info) -{ - info->sig = 3; - info->fix = 3; - - nmea_igen_static_reset(gen, info); - - return 1; -} - -/* - * SAT_ROTATE generator - */ - -int nmea_igen_rotate_loop(nmeaGENERATOR *gen, nmeaINFO *info) -{ - int it; - int count = info->satinfo.inview; - float deg = 360 / (count?count:1); - float srt = (count?(info->satinfo.sat[0].azimuth):0) + 5; - - nmea_time_now(&info->utc); - - for(it = 0; it < count; ++it) - { - info->satinfo.sat[it].azimuth = - (int)((srt >= 360)?srt - 360:srt); - srt += deg; - } - - return 1; -}; - -int nmea_igen_rotate_reset(nmeaGENERATOR *gen, nmeaINFO *info) -{ - int it; - float deg = 360 / 8; - float srt = 0; - - info->satinfo.inuse = 8; - info->satinfo.inview = 8; - - for(it = 0; it < info->satinfo.inview; ++it) - { - info->satinfo.sat[it].id = it + 1; - info->satinfo.sat[it].in_use = 1; - info->satinfo.sat[it].elv = 5; - info->satinfo.sat[it].azimuth = (int)srt; - info->satinfo.sat[it].sig = 80; - srt += deg; - } - - return 1; -} - -int nmea_igen_rotate_init(nmeaGENERATOR *gen, nmeaINFO *info) -{ - info->sig = 3; - info->fix = 3; - - nmea_igen_rotate_reset(gen, info); - - return 1; -} - -/* - * POS_RANDMOVE generator - */ - -int nmea_igen_pos_rmove_init(nmeaGENERATOR *gen, nmeaINFO *info) -{ - info->sig = 3; - info->fix = 3; - info->direction = info->declination = 0; - info->speed = 20; - return 1; -} - -int nmea_igen_pos_rmove_loop(nmeaGENERATOR *gen, nmeaINFO *info) -{ - nmeaPOS crd; - - info->direction += nmea_random(-10, 10); - info->speed += nmea_random(-2, 3); - - if(info->direction < 0) - info->direction = 359 + info->direction; - if(info->direction > 359) - info->direction -= 359; - - if(info->speed > 40) - info->speed = 40; - if(info->speed < 1) - info->speed = 1; - - nmea_info2pos(info, &crd); - nmea_move_horz(&crd, &crd, info->direction, info->speed / 3600); - nmea_pos2info(&crd, info); - - info->declination = info->direction; - - return 1; -}; - -int nmea_igen_pos_rmove_destroy(nmeaGENERATOR *gen) -{ - return 1; -}; - -/* - * generator create - */ - -nmeaGENERATOR * __nmea_create_generator(int type, nmeaINFO *info) -{ - nmeaGENERATOR *gen = 0; - - switch(type) - { - case NMEA_GEN_NOISE: - if(0 == (gen = malloc(sizeof(nmeaGENERATOR)))) - nmea_error("Insufficient memory!"); - else - { - memset(gen, 0, sizeof(nmeaGENERATOR)); - gen->init_call = &nmea_igen_noise_init; - gen->loop_call = &nmea_igen_noise_loop; - gen->reset_call = &nmea_igen_noise_reset; - } - break; - case NMEA_GEN_STATIC: - case NMEA_GEN_SAT_STATIC: - if(0 == (gen = malloc(sizeof(nmeaGENERATOR)))) - nmea_error("Insufficient memory!"); - else - { - memset(gen, 0, sizeof(nmeaGENERATOR)); - gen->init_call = &nmea_igen_static_init; - gen->loop_call = &nmea_igen_static_loop; - gen->reset_call = &nmea_igen_static_reset; - } - break; - case NMEA_GEN_SAT_ROTATE: - if(0 == (gen = malloc(sizeof(nmeaGENERATOR)))) - nmea_error("Insufficient memory!"); - else - { - memset(gen, 0, sizeof(nmeaGENERATOR)); - gen->init_call = &nmea_igen_rotate_init; - gen->loop_call = &nmea_igen_rotate_loop; - gen->reset_call = &nmea_igen_rotate_reset; - } - break; - case NMEA_GEN_POS_RANDMOVE: - if(0 == (gen = malloc(sizeof(nmeaGENERATOR)))) - nmea_error("Insufficient memory!"); - else - { - memset(gen, 0, sizeof(nmeaGENERATOR)); - gen->init_call = &nmea_igen_pos_rmove_init; - gen->loop_call = &nmea_igen_pos_rmove_loop; - gen->destroy_call = &nmea_igen_pos_rmove_destroy; - } - break; - case NMEA_GEN_ROTATE: - gen = __nmea_create_generator(NMEA_GEN_SAT_ROTATE, info); - nmea_gen_add(gen, __nmea_create_generator(NMEA_GEN_POS_RANDMOVE, info)); - break; - }; - - return gen; -} - -nmeaGENERATOR * nmea_create_generator(int type, nmeaINFO *info) -{ - nmeaGENERATOR *gen = __nmea_create_generator(type, info); - - if(gen) - nmea_gen_init(gen, info); - - return gen; -} - -void nmea_destroy_generator(nmeaGENERATOR *gen) -{ - nmea_gen_destroy(gen); -} - -#if defined(NMEA_WIN) && defined(_MSC_VER) -# pragma warning(default: 4100) -#endif diff --git a/apps/gps/nmealib/gmath.c b/apps/gps/nmealib/gmath.c deleted file mode 100644 index 327b982ef..000000000 --- a/apps/gps/nmealib/gmath.c +++ /dev/null @@ -1,376 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: gmath.c 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -/*! \file gmath.h */ -#include "nmea/gmath.h" - -#include -#include - -/** - * \fn nmea_degree2radian - * \brief Convert degree to radian - */ -float nmea_degree2radian(float val) -{ return (val * NMEA_PI180); } - -/** - * \fn nmea_radian2degree - * \brief Convert radian to degree - */ -float nmea_radian2degree(float val) -{ return (val / NMEA_PI180); } - -/** - * \brief Convert NDEG (NMEA degree) to fractional degree - */ -float nmea_ndeg2degree(float val) -{ - float deg = ((int)(val / 100)); - val = deg + (val - deg * 100) / 60; - return val; -} - -/** - * \brief Convert fractional degree to NDEG (NMEA degree) - */ -float nmea_degree2ndeg(float val) -{ - float int_part; - float fra_part; - fra_part = modf(val, &int_part); - val = int_part * 100 + fra_part * 60; - return val; -} - -/** - * \fn nmea_ndeg2radian - * \brief Convert NDEG (NMEA degree) to radian - */ -float nmea_ndeg2radian(float val) -{ return nmea_degree2radian(nmea_ndeg2degree(val)); } - -/** - * \fn nmea_radian2ndeg - * \brief Convert radian to NDEG (NMEA degree) - */ -float nmea_radian2ndeg(float val) -{ return nmea_degree2ndeg(nmea_radian2degree(val)); } - -/** - * \brief Calculate PDOP (Position Dilution Of Precision) factor - */ -float nmea_calc_pdop(float hdop, float vdop) -{ - return sqrt(pow(hdop, 2) + pow(vdop, 2)); -} - -float nmea_dop2meters(float dop) -{ return (dop * NMEA_DOP_FACTOR); } - -float nmea_meters2dop(float meters) -{ return (meters / NMEA_DOP_FACTOR); } - -/** - * \brief Calculate distance between two points - * \return Distance in meters - */ -float nmea_distance( - const nmeaPOS *from_pos, /**< From position in radians */ - const nmeaPOS *to_pos /**< To position in radians */ - ) -{ - float dist = ((float)NMEA_EARTHRADIUS_M) * acos( - sin(to_pos->lat) * sin(from_pos->lat) + - cos(to_pos->lat) * cos(from_pos->lat) * cos(to_pos->lon - from_pos->lon) - ); - return dist; -} - -/** - * \brief Calculate distance between two points - * This function uses an algorithm for an oblate spheroid earth model. - * The algorithm is described here: - * http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf - * \return Distance in meters - */ -float nmea_distance_ellipsoid( - const nmeaPOS *from_pos, /**< From position in radians */ - const nmeaPOS *to_pos, /**< To position in radians */ - float *from_azimuth, /**< (O) azimuth at "from" position in radians */ - float *to_azimuth /**< (O) azimuth at "to" position in radians */ - ) -{ - /* All variables */ - float f, a, b, sqr_a, sqr_b; - float L, phi1, phi2, U1, U2, sin_U1, sin_U2, cos_U1, cos_U2; - float sigma, sin_sigma, cos_sigma, cos_2_sigmam, sqr_cos_2_sigmam, sqr_cos_alpha, lambda, sin_lambda, cos_lambda, delta_lambda; - int remaining_steps; - float sqr_u, A, B, delta_sigma; - - /* Check input */ - //NMEA_ASSERT(from_pos != 0); - //NMEA_ASSERT(to_pos != 0); - - if ((from_pos->lat == to_pos->lat) && (from_pos->lon == to_pos->lon)) - { /* Identical points */ - if ( from_azimuth != 0 ) - *from_azimuth = 0; - if ( to_azimuth != 0 ) - *to_azimuth = 0; - return 0; - } /* Identical points */ - - /* Earth geometry */ - f = NMEA_EARTH_FLATTENING; - a = NMEA_EARTH_SEMIMAJORAXIS_M; - b = (1 - f) * a; - sqr_a = a * a; - sqr_b = b * b; - - /* Calculation */ - L = to_pos->lon - from_pos->lon; - phi1 = from_pos->lat; - phi2 = to_pos->lat; - U1 = atan((1 - f) * tan(phi1)); - U2 = atan((1 - f) * tan(phi2)); - sin_U1 = sin(U1); - sin_U2 = sin(U2); - cos_U1 = cos(U1); - cos_U2 = cos(U2); - - /* Initialize iteration */ - sigma = 0; - sin_sigma = sin(sigma); - cos_sigma = cos(sigma); - cos_2_sigmam = 0; - sqr_cos_2_sigmam = cos_2_sigmam * cos_2_sigmam; - sqr_cos_alpha = 0; - lambda = L; - sin_lambda = sin(lambda); - cos_lambda = cos(lambda); - delta_lambda = lambda; - remaining_steps = 20; - - while ((delta_lambda > 1e-12) && (remaining_steps > 0)) - { /* Iterate */ - /* Variables */ - float tmp1, tmp2, tan_sigma, sin_alpha, cos_alpha, C, lambda_prev; - - /* Calculation */ - tmp1 = cos_U2 * sin_lambda; - tmp2 = cos_U1 * sin_U2 - sin_U1 * cos_U2 * cos_lambda; - sin_sigma = sqrt(tmp1 * tmp1 + tmp2 * tmp2); - cos_sigma = sin_U1 * sin_U2 + cos_U1 * cos_U2 * cos_lambda; - tan_sigma = sin_sigma / cos_sigma; - sin_alpha = cos_U1 * cos_U2 * sin_lambda / sin_sigma; - cos_alpha = cos(asin(sin_alpha)); - sqr_cos_alpha = cos_alpha * cos_alpha; - cos_2_sigmam = cos_sigma - 2 * sin_U1 * sin_U2 / sqr_cos_alpha; - sqr_cos_2_sigmam = cos_2_sigmam * cos_2_sigmam; - C = f / 16 * sqr_cos_alpha * (4 + f * (4 - 3 * sqr_cos_alpha)); - lambda_prev = lambda; - sigma = asin(sin_sigma); - lambda = L + - (1 - C) * f * sin_alpha - * (sigma + C * sin_sigma * (cos_2_sigmam + C * cos_sigma * (-1 + 2 * sqr_cos_2_sigmam))); - delta_lambda = lambda_prev - lambda; - if ( delta_lambda < 0 ) delta_lambda = -delta_lambda; - sin_lambda = sin(lambda); - cos_lambda = cos(lambda); - remaining_steps--; - } /* Iterate */ - - /* More calculation */ - sqr_u = sqr_cos_alpha * (sqr_a - sqr_b) / sqr_b; - A = 1 + sqr_u / 16384 * (4096 + sqr_u * (-768 + sqr_u * (320 - 175 * sqr_u))); - B = sqr_u / 1024 * (256 + sqr_u * (-128 + sqr_u * (74 - 47 * sqr_u))); - delta_sigma = B * sin_sigma * ( - cos_2_sigmam + B / 4 * ( - cos_sigma * (-1 + 2 * sqr_cos_2_sigmam) - - B / 6 * cos_2_sigmam * (-3 + 4 * sin_sigma * sin_sigma) * (-3 + 4 * sqr_cos_2_sigmam) - )); - - /* Calculate result */ - if ( from_azimuth != 0 ) - { - float tan_alpha_1 = cos_U2 * sin_lambda / (cos_U1 * sin_U2 - sin_U1 * cos_U2 * cos_lambda); - *from_azimuth = atan(tan_alpha_1); - } - if ( to_azimuth != 0 ) - { - float tan_alpha_2 = cos_U1 * sin_lambda / (-sin_U1 * cos_U2 + cos_U1 * sin_U2 * cos_lambda); - *to_azimuth = atan(tan_alpha_2); - } - - return b * A * (sigma - delta_sigma); -} - -/** - * \brief Horizontal move of point position - */ -int nmea_move_horz( - const nmeaPOS *start_pos, /**< Start position in radians */ - nmeaPOS *end_pos, /**< Result position in radians */ - float azimuth, /**< Azimuth (degree) [0, 359] */ - float distance /**< Distance (km) */ - ) -{ - nmeaPOS p1 = *start_pos; - int RetVal = 1; - - distance /= NMEA_EARTHRADIUS_KM; /* Angular distance covered on earth's surface */ - azimuth = nmea_degree2radian(azimuth); - - end_pos->lat = asin( - sin(p1.lat) * cos(distance) + cos(p1.lat) * sin(distance) * cos(azimuth)); - end_pos->lon = p1.lon + atan2( - sin(azimuth) * sin(distance) * cos(p1.lat), cos(distance) - sin(p1.lat) * sin(end_pos->lat)); - - if(NMEA_POSIX(isnan)(end_pos->lat) || NMEA_POSIX(isnan)(end_pos->lon)) - { - end_pos->lat = 0; end_pos->lon = 0; - RetVal = 0; - } - - return RetVal; -} - -/** - * \brief Horizontal move of point position - * This function uses an algorithm for an oblate spheroid earth model. - * The algorithm is described here: - * http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf - */ -int nmea_move_horz_ellipsoid( - const nmeaPOS *start_pos, /**< Start position in radians */ - nmeaPOS *end_pos, /**< (O) Result position in radians */ - float azimuth, /**< Azimuth in radians */ - float distance, /**< Distance (km) */ - float *end_azimuth /**< (O) Azimuth at end position in radians */ - ) -{ - /* Variables */ - float f, a, b, sqr_a, sqr_b; - float phi1, tan_U1, sin_U1, cos_U1, s, alpha1, sin_alpha1, cos_alpha1; - float tan_sigma1, sigma1, sin_alpha, cos_alpha, sqr_cos_alpha, sqr_u, A, B; - float sigma_initial, sigma, sigma_prev, sin_sigma, cos_sigma, cos_2_sigmam, sqr_cos_2_sigmam, delta_sigma; - int remaining_steps; - float tmp1, phi2, lambda, C, L; - - /* Check input */ - //NMEA_ASSERT(start_pos != 0); - //NMEA_ASSERT(end_pos != 0); - - if (fabs(distance) < 1e-12) - { /* No move */ - *end_pos = *start_pos; - if ( end_azimuth != 0 ) *end_azimuth = azimuth; - return ! (NMEA_POSIX(isnan)(end_pos->lat) || NMEA_POSIX(isnan)(end_pos->lon)); - } /* No move */ - - /* Earth geometry */ - f = NMEA_EARTH_FLATTENING; - a = NMEA_EARTH_SEMIMAJORAXIS_M; - b = (1 - f) * a; - sqr_a = a * a; - sqr_b = b * b; - - /* Calculation */ - phi1 = start_pos->lat; - tan_U1 = (1 - f) * tan(phi1); - cos_U1 = 1 / sqrt(1 + tan_U1 * tan_U1); - sin_U1 = tan_U1 * cos_U1; - s = distance; - alpha1 = azimuth; - sin_alpha1 = sin(alpha1); - cos_alpha1 = cos(alpha1); - tan_sigma1 = tan_U1 / cos_alpha1; - sigma1 = atan2(tan_U1, cos_alpha1); - sin_alpha = cos_U1 * sin_alpha1; - sqr_cos_alpha = 1 - sin_alpha * sin_alpha; - cos_alpha = sqrt(sqr_cos_alpha); - sqr_u = sqr_cos_alpha * (sqr_a - sqr_b) / sqr_b; - A = 1 + sqr_u / 16384 * (4096 + sqr_u * (-768 + sqr_u * (320 - 175 * sqr_u))); - B = sqr_u / 1024 * (256 + sqr_u * (-128 + sqr_u * (74 - 47 * sqr_u))); - - /* Initialize iteration */ - sigma_initial = s / (b * A); - sigma = sigma_initial; - sin_sigma = sin(sigma); - cos_sigma = cos(sigma); - cos_2_sigmam = cos(2 * sigma1 + sigma); - sqr_cos_2_sigmam = cos_2_sigmam * cos_2_sigmam; - delta_sigma = 0; - sigma_prev = 2 * NMEA_PI; - remaining_steps = 20; - - while ((fabs(sigma - sigma_prev) > 1e-12) && (remaining_steps > 0)) - { /* Iterate */ - cos_2_sigmam = cos(2 * sigma1 + sigma); - sqr_cos_2_sigmam = cos_2_sigmam * cos_2_sigmam; - sin_sigma = sin(sigma); - cos_sigma = cos(sigma); - delta_sigma = B * sin_sigma * ( - cos_2_sigmam + B / 4 * ( - cos_sigma * (-1 + 2 * sqr_cos_2_sigmam) - - B / 6 * cos_2_sigmam * (-3 + 4 * sin_sigma * sin_sigma) * (-3 + 4 * sqr_cos_2_sigmam) - )); - sigma_prev = sigma; - sigma = sigma_initial + delta_sigma; - remaining_steps --; - } /* Iterate */ - - /* Calculate result */ - tmp1 = (sin_U1 * sin_sigma - cos_U1 * cos_sigma * cos_alpha1); - phi2 = atan2( - sin_U1 * cos_sigma + cos_U1 * sin_sigma * cos_alpha1, - (1 - f) * sqrt(sin_alpha * sin_alpha + tmp1 * tmp1) - ); - lambda = atan2( - sin_sigma * sin_alpha1, - cos_U1 * cos_sigma - sin_U1 * sin_sigma * cos_alpha1 - ); - C = f / 16 * sqr_cos_alpha * (4 + f * (4 - 3 * sqr_cos_alpha)); - L = lambda - - (1 - C) * f * sin_alpha * ( - sigma + C * sin_sigma * - (cos_2_sigmam + C * cos_sigma * (-1 + 2 * sqr_cos_2_sigmam)) - ); - - /* Result */ - end_pos->lon = start_pos->lon + L; - end_pos->lat = phi2; - if ( end_azimuth != 0 ) - { - *end_azimuth = atan2( - sin_alpha, -sin_U1 * sin_sigma + cos_U1 * cos_sigma * cos_alpha1 - ); - } - return ! (NMEA_POSIX(isnan)(end_pos->lat) || NMEA_POSIX(isnan)(end_pos->lon)); -} - -/** - * \brief Convert position from INFO to radians position - */ -void nmea_info2pos(const nmeaINFO *info, nmeaPOS *pos) -{ - pos->lat = nmea_ndeg2radian(info->lat); - pos->lon = nmea_ndeg2radian(info->lon); -} - -/** - * \brief Convert radians position to INFOs position - */ -void nmea_pos2info(const nmeaPOS *pos, nmeaINFO *info) -{ - info->lat = nmea_radian2ndeg(pos->lat); - info->lon = nmea_radian2ndeg(pos->lon); -} diff --git a/apps/gps/nmealib/info.c b/apps/gps/nmealib/info.c deleted file mode 100644 index 1d531ffc4..000000000 --- a/apps/gps/nmealib/info.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: info.c 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -#include - -#include "nmea/info.h" - -void nmea_zero_INFO(nmeaINFO *info) -{ - memset(info, 0, sizeof(nmeaINFO)); - nmea_time_now(&info->utc); - info->sig = NMEA_SIG_BAD; - info->fix = NMEA_FIX_BAD; -} diff --git a/apps/gps/nmealib/nmea/config.h b/apps/gps/nmealib/nmea/config.h deleted file mode 100644 index 501466218..000000000 --- a/apps/gps/nmealib/nmea/config.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: config.h 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -#ifndef __NMEA_CONFIG_H__ -#define __NMEA_CONFIG_H__ - -#define NMEA_VERSION ("0.5.3") -#define NMEA_VERSION_MAJOR (0) -#define NMEA_VERSION_MINOR (5) -#define NMEA_VERSION_PATCH (3) - -#define NMEA_CONVSTR_BUF (256) -#define NMEA_TIMEPARSE_BUF (256) - -#if defined(WINCE) || defined(UNDER_CE) -# define NMEA_CE -#endif - -#if defined(WIN32) || defined(NMEA_CE) -# define NMEA_WIN -#else -# define NMEA_UNI -#endif - -#if defined(NMEA_WIN) && (_MSC_VER >= 1400) -# pragma warning(disable: 4996) /* declared deprecated */ -#endif - -#if defined(_MSC_VER) -# define NMEA_POSIX(x) _##x -# define NMEA_INLINE __inline -#else -# define NMEA_POSIX(x) x -# define NMEA_INLINE inline -#endif - -#if !defined(NDEBUG) && !defined(NMEA_CE) -# include -# define NMEA_ASSERT(x) assert(x) -#else -# define NMEA_ASSERT(x) -#endif - -#endif /* __NMEA_CONFIG_H__ */ diff --git a/apps/gps/nmealib/nmea/context.h b/apps/gps/nmealib/nmea/context.h deleted file mode 100644 index 06e558327..000000000 --- a/apps/gps/nmealib/nmea/context.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: context.h 4 2007-08-27 13:11:03Z xtimor $ - * - */ - -#ifndef __NMEA_CONTEXT_H__ -#define __NMEA_CONTEXT_H__ - -#include "config.h" - -#define NMEA_DEF_PARSEBUFF (1024) -#define NMEA_MIN_PARSEBUFF (256) - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void (*nmeaTraceFunc)(const char *str, int str_size); -typedef void (*nmeaErrorFunc)(const char *str, int str_size); - -typedef struct _nmeaPROPERTY -{ - nmeaTraceFunc trace_func; - nmeaErrorFunc error_func; - int parse_buff_size; - -} nmeaPROPERTY; - -nmeaPROPERTY * nmea_property(void); - -void nmea_trace(const char *str, ...); -void nmea_trace_buff(const char *buff, int buff_size); -void nmea_error(const char *str, ...); - -#ifdef __cplusplus -} -#endif - -#endif /* __NMEA_CONTEXT_H__ */ diff --git a/apps/gps/nmealib/nmea/generate.h b/apps/gps/nmealib/nmea/generate.h deleted file mode 100644 index 9d7fdee51..000000000 --- a/apps/gps/nmealib/nmea/generate.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: generate.h 4 2007-08-27 13:11:03Z xtimor $ - * - */ - -#ifndef __NMEA_GENERATE_H__ -#define __NMEA_GENERATE_H__ - -#include "sentence.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int nmea_generate( - char *buff, int buff_sz, /* buffer */ - const nmeaINFO *info, /* source info */ - int generate_mask /* mask of sentence`s (e.g. GPGGA | GPGSA) */ - ); - -int nmea_gen_GPGGA(char *buff, int buff_sz, nmeaGPGGA *pack); -int nmea_gen_GPGSA(char *buff, int buff_sz, nmeaGPGSA *pack); -int nmea_gen_GPGSV(char *buff, int buff_sz, nmeaGPGSV *pack); -int nmea_gen_GPRMC(char *buff, int buff_sz, nmeaGPRMC *pack); -int nmea_gen_GPVTG(char *buff, int buff_sz, nmeaGPVTG *pack); - -void nmea_info2GPGGA(const nmeaINFO *info, nmeaGPGGA *pack); -void nmea_info2GPGSA(const nmeaINFO *info, nmeaGPGSA *pack); -void nmea_info2GPRMC(const nmeaINFO *info, nmeaGPRMC *pack); -void nmea_info2GPVTG(const nmeaINFO *info, nmeaGPVTG *pack); - -int nmea_gsv_npack(int sat_count); -void nmea_info2GPGSV(const nmeaINFO *info, nmeaGPGSV *pack, int pack_idx); - -#ifdef __cplusplus -} -#endif - -#endif /* __NMEA_GENERATE_H__ */ diff --git a/apps/gps/nmealib/nmea/generator.h b/apps/gps/nmealib/nmea/generator.h deleted file mode 100644 index a97b91b13..000000000 --- a/apps/gps/nmealib/nmea/generator.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: generator.h 4 2007-08-27 13:11:03Z xtimor $ - * - */ - -#ifndef __NMEA_GENERATOR_H__ -#define __NMEA_GENERATOR_H__ - -#include "info.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * high level - */ - -struct _nmeaGENERATOR; - -enum nmeaGENTYPE -{ - NMEA_GEN_NOISE = 0, - NMEA_GEN_STATIC, - NMEA_GEN_ROTATE, - - NMEA_GEN_SAT_STATIC, - NMEA_GEN_SAT_ROTATE, - NMEA_GEN_POS_RANDMOVE, - - NMEA_GEN_LAST -}; - -struct _nmeaGENERATOR * nmea_create_generator(int type, nmeaINFO *info); -void nmea_destroy_generator(struct _nmeaGENERATOR *gen); - -int nmea_generate_from( - char *buff, int buff_sz, /* buffer */ - nmeaINFO *info, /* source info */ - struct _nmeaGENERATOR *gen, /* generator */ - int generate_mask /* mask of sentence`s (e.g. GPGGA | GPGSA) */ - ); - -/* - * low level - */ - -typedef int (*nmeaNMEA_GEN_INIT)(struct _nmeaGENERATOR *gen, nmeaINFO *info); -typedef int (*nmeaNMEA_GEN_LOOP)(struct _nmeaGENERATOR *gen, nmeaINFO *info); -typedef int (*nmeaNMEA_GEN_RESET)(struct _nmeaGENERATOR *gen, nmeaINFO *info); -typedef int (*nmeaNMEA_GEN_DESTROY)(struct _nmeaGENERATOR *gen); - -typedef struct _nmeaGENERATOR -{ - void *gen_data; - nmeaNMEA_GEN_INIT init_call; - nmeaNMEA_GEN_LOOP loop_call; - nmeaNMEA_GEN_RESET reset_call; - nmeaNMEA_GEN_DESTROY destroy_call; - struct _nmeaGENERATOR *next; - -} nmeaGENERATOR; - -int nmea_gen_init(nmeaGENERATOR *gen, nmeaINFO *info); -int nmea_gen_loop(nmeaGENERATOR *gen, nmeaINFO *info); -int nmea_gen_reset(nmeaGENERATOR *gen, nmeaINFO *info); -void nmea_gen_destroy(nmeaGENERATOR *gen); -void nmea_gen_add(nmeaGENERATOR *to, nmeaGENERATOR *gen); - -#ifdef __cplusplus -} -#endif - -#endif /* __NMEA_GENERATOR_H__ */ diff --git a/apps/gps/nmealib/nmea/gmath.h b/apps/gps/nmealib/nmea/gmath.h deleted file mode 100644 index 3133b7228..000000000 --- a/apps/gps/nmealib/nmea/gmath.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: gmath.h 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -#ifndef __NMEA_GMATH_H__ -#define __NMEA_GMATH_H__ - -#include "info.h" - -#define NMEA_PI (3.141592653589793) /**< PI value */ -#define NMEA_PI180 (NMEA_PI / 180) /**< PI division by 180 */ -#define NMEA_EARTHRADIUS_KM (6378) /**< Earth's mean radius in km */ -#define NMEA_EARTHRADIUS_M (NMEA_EARTHRADIUS_KM * 1000) /**< Earth's mean radius in m */ -#define NMEA_EARTH_SEMIMAJORAXIS_M (6378137.0) /**< Earth's semi-major axis in m according WGS84 */ -#define NMEA_EARTH_SEMIMAJORAXIS_KM (NMEA_EARTHMAJORAXIS_KM / 1000) /**< Earth's semi-major axis in km according WGS 84 */ -#define NMEA_EARTH_FLATTENING (1 / 298.257223563) /**< Earth's flattening according WGS 84 */ -#define NMEA_DOP_FACTOR (5) /**< Factor for translating DOP to meters */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * degree VS radian - */ - -float nmea_degree2radian(float val); -float nmea_radian2degree(float val); - -/* - * NDEG (NMEA degree) - */ - -float nmea_ndeg2degree(float val); -float nmea_degree2ndeg(float val); - -float nmea_ndeg2radian(float val); -float nmea_radian2ndeg(float val); - -/* - * DOP - */ - -float nmea_calc_pdop(float hdop, float vdop); -float nmea_dop2meters(float dop); -float nmea_meters2dop(float meters); - -/* - * positions work - */ - -void nmea_info2pos(const nmeaINFO *info, nmeaPOS *pos); -void nmea_pos2info(const nmeaPOS *pos, nmeaINFO *info); - -float nmea_distance( - const nmeaPOS *from_pos, - const nmeaPOS *to_pos - ); - -float nmea_distance_ellipsoid( - const nmeaPOS *from_pos, - const nmeaPOS *to_pos, - float *from_azimuth, - float *to_azimuth - ); - -int nmea_move_horz( - const nmeaPOS *start_pos, - nmeaPOS *end_pos, - float azimuth, - float distance - ); - -int nmea_move_horz_ellipsoid( - const nmeaPOS *start_pos, - nmeaPOS *end_pos, - float azimuth, - float distance, - float *end_azimuth - ); - -#ifdef __cplusplus -} -#endif - -#endif /* __NMEA_GMATH_H__ */ diff --git a/apps/gps/nmealib/nmea/info.h b/apps/gps/nmealib/nmea/info.h deleted file mode 100644 index 09ccd4c09..000000000 --- a/apps/gps/nmealib/nmea/info.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: info.h 10 2007-11-15 14:50:15Z xtimor $ - * - */ - -/*! \file */ - -#ifndef __NMEA_INFO_H__ -#define __NMEA_INFO_H__ - -#include "time.h" - -#define NMEA_SIG_BAD (0) -#define NMEA_SIG_LOW (1) -#define NMEA_SIG_MID (2) -#define NMEA_SIG_HIGH (3) - -#define NMEA_FIX_BAD (1) -#define NMEA_FIX_2D (2) -#define NMEA_FIX_3D (3) - -#define NMEA_MAXSAT (12) -#define NMEA_SATINPACK (4) -#define NMEA_NSATPACKS (NMEA_MAXSAT / NMEA_SATINPACK) - -#define NMEA_DEF_LAT (5001.2621) -#define NMEA_DEF_LON (3613.0595) - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Position data in fractional degrees or radians - */ -typedef struct _nmeaPOS -{ - float lat; /**< Latitude */ - float lon; /**< Longitude */ - -} nmeaPOS; - -/** - * Information about satellite - * @see nmeaSATINFO - * @see nmeaGPGSV - */ -typedef struct _nmeaSATELLITE -{ - int id; /**< Satellite PRN number */ - int in_use; /**< Used in position fix */ - int elv; /**< Elevation in degrees, 90 maximum */ - int azimuth; /**< Azimuth, degrees from true north, 000 to 359 */ - int sig; /**< Signal, 00-99 dB */ - -} nmeaSATELLITE; - -/** - * Information about all satellites in view - * @see nmeaINFO - * @see nmeaGPGSV - */ -typedef struct _nmeaSATINFO -{ - int inuse; /**< Number of satellites in use (not those in view) */ - int inview; /**< Total number of satellites in view */ - nmeaSATELLITE sat[NMEA_MAXSAT]; /**< Satellites information */ - -} nmeaSATINFO; - -/** - * Summary GPS information from all parsed packets, - * used also for generating NMEA stream - * @see nmea_parse - * @see nmea_GPGGA2info, nmea_...2info - */ -typedef struct _nmeaINFO -{ - int smask; /**< Mask specifying types of packages from which data have been obtained */ - - nmeaTIME utc; /**< UTC of position */ - - int sig; /**< GPS quality indicator (0 = Invalid; 1 = Fix; 2 = Differential, 3 = Sensitive) */ - int fix; /**< Operating mode, used for navigation (1 = Fix not available; 2 = 2D; 3 = 3D) */ - - float PDOP; /**< Position Dilution Of Precision */ - float HDOP; /**< Horizontal Dilution Of Precision */ - float VDOP; /**< Vertical Dilution Of Precision */ - - float lat; /**< Latitude in NDEG - +/-[degree][min].[sec/60] */ - float lon; /**< Longitude in NDEG - +/-[degree][min].[sec/60] */ - float elv; /**< Antenna altitude above/below mean sea level (geoid) in meters */ - float speed; /**< Speed over the ground in kilometers/hour */ - float direction; /**< Track angle in degrees True */ - float declination; /**< Magnetic variation degrees (Easterly var. subtracts from true course) */ - - nmeaSATINFO satinfo; /**< Satellites information */ - -} nmeaINFO; - -void nmea_zero_INFO(nmeaINFO *info); - -#ifdef __cplusplus -} -#endif - -#endif /* __NMEA_INFO_H__ */ diff --git a/apps/gps/nmealib/nmea/nmea.h b/apps/gps/nmealib/nmea/nmea.h deleted file mode 100644 index 62692230f..000000000 --- a/apps/gps/nmealib/nmea/nmea.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: nmea.h 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -#ifndef __NMEA_H__ -#define __NMEA_H__ - -#include "./config.h" -#include "./units.h" -#include "./gmath.h" -#include "./info.h" -#include "./sentence.h" -#include "./generate.h" -#include "./generator.h" -#include "./parse.h" -#include "./parser.h" -#include "./context.h" - -#endif /* __NMEA_H__ */ diff --git a/apps/gps/nmealib/nmea/parse.h b/apps/gps/nmealib/nmea/parse.h deleted file mode 100644 index 3e6b425db..000000000 --- a/apps/gps/nmealib/nmea/parse.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: parse.h 4 2007-08-27 13:11:03Z xtimor $ - * - */ - -#ifndef __NMEA_PARSE_H__ -#define __NMEA_PARSE_H__ - -#include "sentence.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int nmea_pack_type(const char *buff, int buff_sz); -int nmea_find_tail(const char *buff, int buff_sz, int *res_crc); - -int nmea_parse_GPGGA(const char *buff, int buff_sz, nmeaGPGGA *pack); -int nmea_parse_GPGSA(const char *buff, int buff_sz, nmeaGPGSA *pack); -int nmea_parse_GPGSV(const char *buff, int buff_sz, nmeaGPGSV *pack); -int nmea_parse_GPRMC(const char *buff, int buff_sz, nmeaGPRMC *pack); -int nmea_parse_GPVTG(const char *buff, int buff_sz, nmeaGPVTG *pack); - -void nmea_GPGGA2info(nmeaGPGGA *pack, nmeaINFO *info); -void nmea_GPGSA2info(nmeaGPGSA *pack, nmeaINFO *info); -void nmea_GPGSV2info(nmeaGPGSV *pack, nmeaINFO *info); -void nmea_GPRMC2info(nmeaGPRMC *pack, nmeaINFO *info); -void nmea_GPVTG2info(nmeaGPVTG *pack, nmeaINFO *info); - -#ifdef __cplusplus -} -#endif - -#endif /* __NMEA_PARSE_H__ */ diff --git a/apps/gps/nmealib/nmea/parser.h b/apps/gps/nmealib/nmea/parser.h deleted file mode 100644 index 51a3fab7f..000000000 --- a/apps/gps/nmealib/nmea/parser.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: parser.h 4 2007-08-27 13:11:03Z xtimor $ - * - */ - -#ifndef __NMEA_PARSER_H__ -#define __NMEA_PARSER_H__ - -#include "info.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * high level - */ - -typedef struct _nmeaPARSER -{ - void *top_node; - void *end_node; - unsigned char *buffer; - int buff_size; - int buff_use; - -} nmeaPARSER; - -int nmea_parser_init(nmeaPARSER *parser); -void nmea_parser_destroy(nmeaPARSER *parser); - -int nmea_parse( - nmeaPARSER *parser, - const char *buff, int buff_sz, - nmeaINFO *info - ); - -/* - * low level - */ - -int nmea_parser_push(nmeaPARSER *parser, const char *buff, int buff_sz); -int nmea_parser_top(nmeaPARSER *parser); -int nmea_parser_pop(nmeaPARSER *parser, void **pack_ptr); -int nmea_parser_peek(nmeaPARSER *parser, void **pack_ptr); -int nmea_parser_drop(nmeaPARSER *parser); -int nmea_parser_buff_clear(nmeaPARSER *parser); -int nmea_parser_queue_clear(nmeaPARSER *parser); - -#ifdef __cplusplus -} -#endif - -#endif /* __NMEA_PARSER_H__ */ diff --git a/apps/gps/nmealib/nmea/sentence.h b/apps/gps/nmealib/nmea/sentence.h deleted file mode 100644 index 2aa975c71..000000000 --- a/apps/gps/nmealib/nmea/sentence.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: sentence.h 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -/*! \file */ - -#ifndef __NMEA_SENTENCE_H__ -#define __NMEA_SENTENCE_H__ - -#include "info.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * NMEA packets type which parsed and generated by library - */ -enum nmeaPACKTYPE -{ - GPNON = 0x0000, /**< Unknown packet type. */ - GPGGA = 0x0001, /**< GGA - Essential fix data which provide 3D location and accuracy data. */ - GPGSA = 0x0002, /**< GSA - GPS receiver operating mode, SVs used for navigation, and DOP values. */ - GPGSV = 0x0004, /**< GSV - Number of SVs in view, PRN numbers, elevation, azimuth & SNR values. */ - GPRMC = 0x0008, /**< RMC - Recommended Minimum Specific GPS/TRANSIT Data. */ - GPVTG = 0x0010 /**< VTG - Actual track made good and speed over ground. */ -}; - -/** - * GGA packet information structure (Global Positioning System Fix Data) - */ -typedef struct _nmeaGPGGA -{ - nmeaTIME utc; /**< UTC of position (just time) */ - float lat; /**< Latitude in NDEG - [degree][min].[sec/60] */ - char ns; /**< [N]orth or [S]outh */ - float lon; /**< Longitude in NDEG - [degree][min].[sec/60] */ - char ew; /**< [E]ast or [W]est */ - int sig; /**< GPS quality indicator (0 = Invalid; 1 = Fix; 2 = Differential, 3 = Sensitive) */ - int satinuse; /**< Number of satellites in use (not those in view) */ - float HDOP; /**< Horizontal dilution of precision */ - float elv; /**< Antenna altitude above/below mean sea level (geoid) */ - char elv_units; /**< [M]eters (Antenna height unit) */ - float diff; /**< Geoidal separation (Diff. between WGS-84 earth ellipsoid and mean sea level. '-' = geoid is below WGS-84 ellipsoid) */ - char diff_units; /**< [M]eters (Units of geoidal separation) */ - float dgps_age; /**< Time in seconds since last DGPS update */ - int dgps_sid; /**< DGPS station ID number */ - -} nmeaGPGGA; - -/** - * GSA packet information structure (Satellite status) - */ -typedef struct _nmeaGPGSA -{ - char fix_mode; /**< Mode (M = Manual, forced to operate in 2D or 3D; A = Automatic, 3D/2D) */ - int fix_type; /**< Type, used for navigation (1 = Fix not available; 2 = 2D; 3 = 3D) */ - int sat_prn[NMEA_MAXSAT]; /**< PRNs of satellites used in position fix (null for unused fields) */ - float PDOP; /**< Dilution of precision */ - float HDOP; /**< Horizontal dilution of precision */ - float VDOP; /**< Vertical dilution of precision */ - -} nmeaGPGSA; - -/** - * GSV packet information structure (Satellites in view) - */ -typedef struct _nmeaGPGSV -{ - int pack_count; /**< Total number of messages of this type in this cycle */ - int pack_index; /**< Message number */ - int sat_count; /**< Total number of satellites in view */ - nmeaSATELLITE sat_data[NMEA_SATINPACK]; - -} nmeaGPGSV; - -/** - * RMC packet information structure (Recommended Minimum sentence C) - */ -typedef struct _nmeaGPRMC -{ - nmeaTIME utc; /**< UTC of position */ - char status; /**< Status (A = active or V = void) */ - float lat; /**< Latitude in NDEG - [degree][min].[sec/60] */ - char ns; /**< [N]orth or [S]outh */ - float lon; /**< Longitude in NDEG - [degree][min].[sec/60] */ - char ew; /**< [E]ast or [W]est */ - float speed; /**< Speed over the ground in knots */ - float direction; /**< Track angle in degrees True */ - float declination; /**< Magnetic variation degrees (Easterly var. subtracts from true course) */ - char declin_ew; /**< [E]ast or [W]est */ - char mode; /**< Mode indicator of fix type (A = autonomous, D = differential, E = estimated, N = not valid, S = simulator) */ - -} nmeaGPRMC; - -/** - * VTG packet information structure (Track made good and ground speed) - */ -typedef struct _nmeaGPVTG -{ - float dir; /**< True track made good (degrees) */ - char dir_t; /**< Fixed text 'T' indicates that track made good is relative to true north */ - float dec; /**< Magnetic track made good */ - char dec_m; /**< Fixed text 'M' */ - float spn; /**< Ground speed, knots */ - char spn_n; /**< Fixed text 'N' indicates that speed over ground is in knots */ - float spk; /**< Ground speed, kilometers per hour */ - char spk_k; /**< Fixed text 'K' indicates that speed over ground is in kilometers/hour */ - -} nmeaGPVTG; - -void nmea_zero_GPGGA(nmeaGPGGA *pack); -void nmea_zero_GPGSA(nmeaGPGSA *pack); -void nmea_zero_GPGSV(nmeaGPGSV *pack); -void nmea_zero_GPRMC(nmeaGPRMC *pack); -void nmea_zero_GPVTG(nmeaGPVTG *pack); - -#ifdef __cplusplus -} -#endif - -#endif /* __NMEA_SENTENCE_H__ */ diff --git a/apps/gps/nmealib/nmea/time.h b/apps/gps/nmealib/nmea/time.h deleted file mode 100644 index bbe59f65c..000000000 --- a/apps/gps/nmealib/nmea/time.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: time.h 4 2007-08-27 13:11:03Z xtimor $ - * - */ - -/*! \file */ - -#ifndef __NMEA_TIME_H__ -#define __NMEA_TIME_H__ - -#include "config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Date and time data - * @see nmea_time_now - */ -typedef struct _nmeaTIME -{ - int year; /**< Years since 1900 */ - int mon; /**< Months since January - [0,11] */ - int day; /**< Day of the month - [1,31] */ - int hour; /**< Hours since midnight - [0,23] */ - int min; /**< Minutes after the hour - [0,59] */ - int sec; /**< Seconds after the minute - [0,59] */ - int hsec; /**< Hundredth part of second - [0,99] */ - -} nmeaTIME; - -/** - * \brief Get time now to nmeaTIME structure - */ -void nmea_time_now(nmeaTIME *t); - -#ifdef __cplusplus -} -#endif - -#endif /* __NMEA_TIME_H__ */ diff --git a/apps/gps/nmealib/nmea/tok.h b/apps/gps/nmealib/nmea/tok.h deleted file mode 100644 index 8f948dd2d..000000000 --- a/apps/gps/nmealib/nmea/tok.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: tok.h 4 2007-08-27 13:11:03Z xtimor $ - * - */ - -#ifndef __NMEA_TOK_H__ -#define __NMEA_TOK_H__ - -#include "config.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -int nmea_calc_crc(const char *buff, int buff_sz); -int nmea_atoi(const char *str, int str_sz, int radix); -float nmea_atof(const char *str, int str_sz); -int nmea_printf(char *buff, int buff_sz, const char *format, ...); -int nmea_scanf(const char *buff, int buff_sz, const char *format, ...); - -#ifdef __cplusplus -} -#endif - -#endif /* __NMEA_TOK_H__ */ diff --git a/apps/gps/nmealib/nmea/units.h b/apps/gps/nmealib/nmea/units.h deleted file mode 100644 index 767f980e2..000000000 --- a/apps/gps/nmealib/nmea/units.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: units.h 4 2007-08-27 13:11:03Z xtimor $ - * - */ - -#ifndef __NMEA_UNITS_H__ -#define __NMEA_UNITS_H__ - -#include "config.h" - -/* - * Distance units - */ - -#define NMEA_TUD_YARDS (1.0936) /**< Yeards, meter * NMEA_TUD_YARDS = yard */ -#define NMEA_TUD_KNOTS (1.852) /**< Knots, kilometer / NMEA_TUD_KNOTS = knot */ -#define NMEA_TUD_MILES (1.609) /**< Miles, kilometer / NMEA_TUD_MILES = mile */ - -/* - * Speed units - */ - -#define NMEA_TUS_MS (3.6) /**< Meters per seconds, (k/h) / NMEA_TUS_MS= (m/s) */ - -#endif /* __NMEA_UNITS_H__ */ diff --git a/apps/gps/nmealib/parse.c b/apps/gps/nmealib/parse.c deleted file mode 100644 index 99bdf075b..000000000 --- a/apps/gps/nmealib/parse.c +++ /dev/null @@ -1,501 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: parse.c 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -/** - * \file parse.h - * \brief Functions of a low level for analysis of - * packages of NMEA stream. - * - * \code - * ... - * ptype = nmea_pack_type( - * (const char *)parser->buffer + nparsed + 1, - * parser->buff_use - nparsed - 1); - * - * if(0 == (node = malloc(sizeof(nmeaParserNODE)))) - * goto mem_fail; - * - * node->pack = 0; - * - * switch(ptype) - * { - * case GPGGA: - * if(0 == (node->pack = malloc(sizeof(nmeaGPGGA)))) - * goto mem_fail; - * node->packType = GPGGA; - * if(!nmea_parse_GPGGA( - * (const char *)parser->buffer + nparsed, - * sen_sz, (nmeaGPGGA *)node->pack)) - * { - * free(node); - * node = 0; - * } - * break; - * case GPGSA: - * if(0 == (node->pack = malloc(sizeof(nmeaGPGSA)))) - * goto mem_fail; - * node->packType = GPGSA; - * if(!nmea_parse_GPGSA( - * (const char *)parser->buffer + nparsed, - * sen_sz, (nmeaGPGSA *)node->pack)) - * { - * free(node); - * node = 0; - * } - * break; - * ... - * \endcode - */ -#include "nmea/tok.h" -#include "nmea/parse.h" -#include "nmea/context.h" -#include "nmea/gmath.h" -#include "nmea/units.h" - -#include -#include - -int _nmea_parse_time(const char *buff, int buff_sz, nmeaTIME *res) -{ - int success = 0; - - switch(buff_sz) - { - case sizeof("hhmmss") - 1: - success = (3 == nmea_scanf(buff, buff_sz, - "%2d%2d%2d", &(res->hour), &(res->min), &(res->sec) - )); - break; - case sizeof("hhmmss.s") - 1: - case sizeof("hhmmss.ss") - 1: - case sizeof("hhmmss.sss") - 1: - success = (4 == nmea_scanf(buff, buff_sz, - "%2d%2d%2d.%d", &(res->hour), &(res->min), &(res->sec), &(res->hsec) - )); - break; - default: - nmea_error("Parse of time error (format error)!"); - success = 0; - break; - } - - return (success?0:-1); -} - -/** - * \brief Define packet type by header (nmeaPACKTYPE). - * @param buff a constant character pointer of packet buffer. - * @param buff_sz buffer size. - * @return The defined packet type - * @see nmeaPACKTYPE - */ -int nmea_pack_type(const char *buff, int buff_sz) -{ - static const char *pheads[] = { - "GPGGA", - "GPGSA", - "GPGSV", - "GPRMC", - "GPVTG", - }; - - //NMEA_ASSERT(buff); - - if(buff_sz < 5) - return GPNON; - else if(0 == memcmp(buff, pheads[0], 5)) - return GPGGA; - else if(0 == memcmp(buff, pheads[1], 5)) - return GPGSA; - else if(0 == memcmp(buff, pheads[2], 5)) - return GPGSV; - else if(0 == memcmp(buff, pheads[3], 5)) - return GPRMC; - else if(0 == memcmp(buff, pheads[4], 5)) - return GPVTG; - - return GPNON; -} - -/** - * \brief Find tail of packet ("\r\n") in buffer and check control sum (CRC). - * @param buff a constant character pointer of packets buffer. - * @param buff_sz buffer size. - * @param res_crc a integer pointer for return CRC of packet (must be defined). - * @return Number of bytes to packet tail. - */ -int nmea_find_tail(const char *buff, int buff_sz, int *res_crc) -{ - static const int tail_sz = 3 /* *[CRC] */ + 2 /* \r\n */; - - const char *end_buff = buff + buff_sz; - int nread = 0; - int crc = 0; - - //NMEA_ASSERT(buff && res_crc); - - *res_crc = -1; - - for(;buff < end_buff; ++buff, ++nread) - { - if(('$' == *buff) && nread) - { - buff = 0; - break; - } - else if('*' == *buff) - { - if(buff + tail_sz <= end_buff && '\r' == buff[3] && '\n' == buff[4]) - { - *res_crc = nmea_atoi(buff + 1, 2, 16); - nread = buff_sz - (int)(end_buff - (buff + tail_sz)); - if(*res_crc != crc) - { - *res_crc = -1; - buff = 0; - } - } - - break; - } - else if(nread) - crc ^= (int)*buff; - } - - if(*res_crc < 0 && buff) - nread = 0; - - return nread; -} - -/** - * \brief Parse GGA packet from buffer. - * @param buff a constant character pointer of packet buffer. - * @param buff_sz buffer size. - * @param pack a pointer of packet which will filled by function. - * @return 1 (true) - if parsed successfully or 0 (false) - if fail. - */ -int nmea_parse_GPGGA(const char *buff, int buff_sz, nmeaGPGGA *pack) -{ - char time_buff[NMEA_TIMEPARSE_BUF]; - - //NMEA_ASSERT(buff && pack); - - memset(pack, 0, sizeof(nmeaGPGGA)); - - nmea_trace_buff(buff, buff_sz); - - if(14 != nmea_scanf(buff, buff_sz, - "$GPGGA,%s,%f,%C,%f,%C,%d,%d,%f,%f,%C,%f,%C,%f,%d*", - &(time_buff[0]), - &(pack->lat), &(pack->ns), &(pack->lon), &(pack->ew), - &(pack->sig), &(pack->satinuse), &(pack->HDOP), &(pack->elv), &(pack->elv_units), - &(pack->diff), &(pack->diff_units), &(pack->dgps_age), &(pack->dgps_sid))) - { - nmea_error("GPGGA parse error!"); - return 0; - } - - if(0 != _nmea_parse_time(&time_buff[0], (int)strlen(&time_buff[0]), &(pack->utc))) - { - nmea_error("GPGGA time parse error!"); - return 0; - } - - return 1; -} - -/** - * \brief Parse GSA packet from buffer. - * @param buff a constant character pointer of packet buffer. - * @param buff_sz buffer size. - * @param pack a pointer of packet which will filled by function. - * @return 1 (true) - if parsed successfully or 0 (false) - if fail. - */ -int nmea_parse_GPGSA(const char *buff, int buff_sz, nmeaGPGSA *pack) -{ - //NMEA_ASSERT(buff && pack); - - memset(pack, 0, sizeof(nmeaGPGSA)); - - nmea_trace_buff(buff, buff_sz); - - if(17 != nmea_scanf(buff, buff_sz, - "$GPGSA,%C,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%f,%f,%f*", - &(pack->fix_mode), &(pack->fix_type), - &(pack->sat_prn[0]), &(pack->sat_prn[1]), &(pack->sat_prn[2]), &(pack->sat_prn[3]), &(pack->sat_prn[4]), &(pack->sat_prn[5]), - &(pack->sat_prn[6]), &(pack->sat_prn[7]), &(pack->sat_prn[8]), &(pack->sat_prn[9]), &(pack->sat_prn[10]), &(pack->sat_prn[11]), - &(pack->PDOP), &(pack->HDOP), &(pack->VDOP))) - { - nmea_error("GPGSA parse error!"); - return 0; - } - - return 1; -} - -/** - * \brief Parse GSV packet from buffer. - * @param buff a constant character pointer of packet buffer. - * @param buff_sz buffer size. - * @param pack a pointer of packet which will filled by function. - * @return 1 (true) - if parsed successfully or 0 (false) - if fail. - */ -int nmea_parse_GPGSV(const char *buff, int buff_sz, nmeaGPGSV *pack) -{ - int nsen, nsat; - - //NMEA_ASSERT(buff && pack); - - memset(pack, 0, sizeof(nmeaGPGSV)); - - nmea_trace_buff(buff, buff_sz); - - nsen = nmea_scanf(buff, buff_sz, - "$GPGSV,%d,%d,%d," - "%d,%d,%d,%d," - "%d,%d,%d,%d," - "%d,%d,%d,%d," - "%d,%d,%d,%d*", - &(pack->pack_count), &(pack->pack_index), &(pack->sat_count), - &(pack->sat_data[0].id), &(pack->sat_data[0].elv), &(pack->sat_data[0].azimuth), &(pack->sat_data[0].sig), - &(pack->sat_data[1].id), &(pack->sat_data[1].elv), &(pack->sat_data[1].azimuth), &(pack->sat_data[1].sig), - &(pack->sat_data[2].id), &(pack->sat_data[2].elv), &(pack->sat_data[2].azimuth), &(pack->sat_data[2].sig), - &(pack->sat_data[3].id), &(pack->sat_data[3].elv), &(pack->sat_data[3].azimuth), &(pack->sat_data[3].sig)); - - nsat = (pack->pack_index - 1) * NMEA_SATINPACK; - nsat = (nsat + NMEA_SATINPACK > pack->sat_count)?pack->sat_count - nsat:NMEA_SATINPACK; - nsat = nsat * 4 + 3 /* first three sentence`s */; - - if(nsen < nsat || nsen > (NMEA_SATINPACK * 4 + 3)) - { - nmea_error("GPGSV parse error!"); - return 0; - } - - return 1; -} - -/** - * \brief Parse RMC packet from buffer. - * @param buff a constant character pointer of packet buffer. - * @param buff_sz buffer size. - * @param pack a pointer of packet which will filled by function. - * @return 1 (true) - if parsed successfully or 0 (false) - if fail. - */ -int nmea_parse_GPRMC(const char *buff, int buff_sz, nmeaGPRMC *pack) -{ - int nsen; - char time_buff[NMEA_TIMEPARSE_BUF]; - - //NMEA_ASSERT(buff && pack); - - memset(pack, 0, sizeof(nmeaGPRMC)); - - nmea_trace_buff(buff, buff_sz); - - nsen = nmea_scanf(buff, buff_sz, - "$GPRMC,%s,%C,%f,%C,%f,%C,%f,%f,%2d%2d%2d,%f,%C,%C*", - &(time_buff[0]), - &(pack->status), &(pack->lat), &(pack->ns), &(pack->lon), &(pack->ew), - &(pack->speed), &(pack->direction), - &(pack->utc.day), &(pack->utc.mon), &(pack->utc.year), - &(pack->declination), &(pack->declin_ew), &(pack->mode)); - - if(nsen != 13 && nsen != 14) - { - nmea_error("GPRMC parse error!"); - return 0; - } - - if(0 != _nmea_parse_time(&time_buff[0], (int)strlen(&time_buff[0]), &(pack->utc))) - { - nmea_error("GPRMC time parse error!"); - return 0; - } - - if(pack->utc.year < 90) - pack->utc.year += 100; - pack->utc.mon -= 1; - - return 1; -} - -/** - * \brief Parse VTG packet from buffer. - * @param buff a constant character pointer of packet buffer. - * @param buff_sz buffer size. - * @param pack a pointer of packet which will filled by function. - * @return 1 (true) - if parsed successfully or 0 (false) - if fail. - */ -int nmea_parse_GPVTG(const char *buff, int buff_sz, nmeaGPVTG *pack) -{ - //NMEA_ASSERT(buff && pack); - - memset(pack, 0, sizeof(nmeaGPVTG)); - - nmea_trace_buff(buff, buff_sz); - - if(8 != nmea_scanf(buff, buff_sz, - "$GPVTG,%f,%C,%f,%C,%f,%C,%f,%C*", - &(pack->dir), &(pack->dir_t), - &(pack->dec), &(pack->dec_m), - &(pack->spn), &(pack->spn_n), - &(pack->spk), &(pack->spk_k))) - { - nmea_error("GPVTG parse error!"); - return 0; - } - - if( pack->dir_t != 'T' || - pack->dec_m != 'M' || - pack->spn_n != 'N' || - pack->spk_k != 'K') - { - nmea_error("GPVTG parse error (format error)!"); - return 0; - } - - return 1; -} - -/** - * \brief Fill nmeaINFO structure by GGA packet data. - * @param pack a pointer of packet structure. - * @param info a pointer of summary information structure. - */ -void nmea_GPGGA2info(nmeaGPGGA *pack, nmeaINFO *info) -{ - //NMEA_ASSERT(pack && info); - - info->utc.hour = pack->utc.hour; - info->utc.min = pack->utc.min; - info->utc.sec = pack->utc.sec; - info->utc.hsec = pack->utc.hsec; - info->sig = pack->sig; - info->HDOP = pack->HDOP; - info->elv = pack->elv; - info->lat = ((pack->ns == 'N')?pack->lat:-(pack->lat)); - info->lon = ((pack->ew == 'E')?pack->lon:-(pack->lon)); - info->smask |= GPGGA; -} - -/** - * \brief Fill nmeaINFO structure by GSA packet data. - * @param pack a pointer of packet structure. - * @param info a pointer of summary information structure. - */ -void nmea_GPGSA2info(nmeaGPGSA *pack, nmeaINFO *info) -{ - int i, j, nuse = 0; - - //NMEA_ASSERT(pack && info); - - info->fix = pack->fix_type; - info->PDOP = pack->PDOP; - info->HDOP = pack->HDOP; - info->VDOP = pack->VDOP; - - for(i = 0; i < NMEA_MAXSAT; ++i) - { - for(j = 0; j < info->satinfo.inview; ++j) - { - if(pack->sat_prn[i] && pack->sat_prn[i] == info->satinfo.sat[j].id) - { - info->satinfo.sat[j].in_use = 1; - nuse++; - } - } - } - - info->satinfo.inuse = nuse; - info->smask |= GPGSA; -} - -/** - * \brief Fill nmeaINFO structure by GSV packet data. - * @param pack a pointer of packet structure. - * @param info a pointer of summary information structure. - */ -void nmea_GPGSV2info(nmeaGPGSV *pack, nmeaINFO *info) -{ - int isat, isi, nsat; - - //NMEA_ASSERT(pack && info); - - if(pack->pack_index > pack->pack_count || - pack->pack_index * NMEA_SATINPACK > NMEA_MAXSAT) - return; - - if(pack->pack_index < 1) - pack->pack_index = 1; - - info->satinfo.inview = pack->sat_count; - - nsat = (pack->pack_index - 1) * NMEA_SATINPACK; - nsat = (nsat + NMEA_SATINPACK > pack->sat_count)?pack->sat_count - nsat:NMEA_SATINPACK; - - for(isat = 0; isat < nsat; ++isat) - { - isi = (pack->pack_index - 1) * NMEA_SATINPACK + isat; - info->satinfo.sat[isi].id = pack->sat_data[isat].id; - info->satinfo.sat[isi].elv = pack->sat_data[isat].elv; - info->satinfo.sat[isi].azimuth = pack->sat_data[isat].azimuth; - info->satinfo.sat[isi].sig = pack->sat_data[isat].sig; - } - - info->smask |= GPGSV; -} - -/** - * \brief Fill nmeaINFO structure by RMC packet data. - * @param pack a pointer of packet structure. - * @param info a pointer of summary information structure. - */ -void nmea_GPRMC2info(nmeaGPRMC *pack, nmeaINFO *info) -{ - //NMEA_ASSERT(pack && info); - - if('A' == pack->status) - { - if(NMEA_SIG_BAD == info->sig) - info->sig = NMEA_SIG_MID; - if(NMEA_FIX_BAD == info->fix) - info->fix = NMEA_FIX_2D; - } - else if('V' == pack->status) - { - info->sig = NMEA_SIG_BAD; - info->fix = NMEA_FIX_BAD; - } - - - info->utc = pack->utc; - info->lat = ((pack->ns == 'N')?pack->lat:-(pack->lat)); - info->lon = ((pack->ew == 'E')?pack->lon:-(pack->lon)); - info->speed = pack->speed * NMEA_TUD_KNOTS; - info->direction = pack->direction; - info->smask |= GPRMC; -} - -/** - * \brief Fill nmeaINFO structure by VTG packet data. - * @param pack a pointer of packet structure. - * @param info a pointer of summary information structure. - */ -void nmea_GPVTG2info(nmeaGPVTG *pack, nmeaINFO *info) -{ - //NMEA_ASSERT(pack && info); - - info->direction = pack->dir; - info->declination = pack->dec; - info->speed = pack->spk; - info->smask |= GPVTG; -} diff --git a/apps/gps/nmealib/parser.c b/apps/gps/nmealib/parser.c deleted file mode 100644 index f8b415866..000000000 --- a/apps/gps/nmealib/parser.c +++ /dev/null @@ -1,400 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: parser.c 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -/** - * \file parser.h - */ -#include "nmea/tok.h" -#include "nmea/parse.h" -#include "nmea/parser.h" -#include "nmea/context.h" - -#include -#include - -typedef struct _nmeaParserNODE -{ - int packType; - void *pack; - struct _nmeaParserNODE *next_node; - -} nmeaParserNODE; - -/* - * high level - */ - -/** - * \brief Initialization of parser object - * @return true (1) - success or false (0) - fail - */ -int nmea_parser_init(nmeaPARSER *parser) -{ - int resv = 0; - int buff_size = nmea_property()->parse_buff_size; - - //NMEA_ASSERT(parser); - - if(buff_size < NMEA_MIN_PARSEBUFF) - buff_size = NMEA_MIN_PARSEBUFF; - - memset(parser, 0, sizeof(nmeaPARSER)); - - if(0 == (parser->buffer = malloc(buff_size))) - nmea_error("Insufficient memory!"); - else - { - parser->buff_size = buff_size; - resv = 1; - } - - return resv; -} - -/** - * \brief Destroy parser object - */ -void nmea_parser_destroy(nmeaPARSER *parser) -{ - //NMEA_ASSERT(parser && parser->buffer); - free(parser->buffer); - nmea_parser_queue_clear(parser); - memset(parser, 0, sizeof(nmeaPARSER)); -} - -/** - * \brief Analysis of buffer and put results to information structure - * @return Number of packets wos parsed - */ -int nmea_parse( - nmeaPARSER *parser, - const char *buff, int buff_sz, - nmeaINFO *info - ) -{ - int ptype, nread = 0; - void *pack = 0; - - //NMEA_ASSERT(parser && parser->buffer); - - nmea_parser_push(parser, buff, buff_sz); - - while(GPNON != (ptype = nmea_parser_pop(parser, &pack))) - { - nread++; - - switch(ptype) - { - case GPGGA: - nmea_GPGGA2info((nmeaGPGGA *)pack, info); - break; - case GPGSA: - nmea_GPGSA2info((nmeaGPGSA *)pack, info); - break; - case GPGSV: - nmea_GPGSV2info((nmeaGPGSV *)pack, info); - break; - case GPRMC: - nmea_GPRMC2info((nmeaGPRMC *)pack, info); - break; - case GPVTG: - nmea_GPVTG2info((nmeaGPVTG *)pack, info); - break; - }; - - free(pack); - } - - return nread; -} - -/* - * low level - */ - -int nmea_parser_real_push(nmeaPARSER *parser, const char *buff, int buff_sz) -{ - int nparsed = 0, crc, sen_sz, ptype; - nmeaParserNODE *node = 0; - - //NMEA_ASSERT(parser && parser->buffer); - - /* clear unuse buffer (for debug) */ - /* - memset( - parser->buffer + parser->buff_use, 0, - parser->buff_size - parser->buff_use - ); - */ - - /* add */ - if(parser->buff_use + buff_sz >= parser->buff_size) - nmea_parser_buff_clear(parser); - - memcpy(parser->buffer + parser->buff_use, buff, buff_sz); - parser->buff_use += buff_sz; - - /* parse */ - for(;;node = 0) - { - sen_sz = nmea_find_tail( - (const char *)parser->buffer + nparsed, - (int)parser->buff_use - nparsed, &crc); - - if(!sen_sz) - { - if(nparsed) - memcpy( - parser->buffer, - parser->buffer + nparsed, - parser->buff_use -= nparsed); - break; - } - else if(crc >= 0) - { - ptype = nmea_pack_type( - (const char *)parser->buffer + nparsed + 1, - parser->buff_use - nparsed - 1); - - if(0 == (node = malloc(sizeof(nmeaParserNODE)))) - goto mem_fail; - - node->pack = 0; - - switch(ptype) - { - case GPGGA: - if(0 == (node->pack = malloc(sizeof(nmeaGPGGA)))) - goto mem_fail; - node->packType = GPGGA; - if(!nmea_parse_GPGGA( - (const char *)parser->buffer + nparsed, - sen_sz, (nmeaGPGGA *)node->pack)) - { - free(node); - node = 0; - } - break; - case GPGSA: - if(0 == (node->pack = malloc(sizeof(nmeaGPGSA)))) - goto mem_fail; - node->packType = GPGSA; - if(!nmea_parse_GPGSA( - (const char *)parser->buffer + nparsed, - sen_sz, (nmeaGPGSA *)node->pack)) - { - free(node); - node = 0; - } - break; - case GPGSV: - if(0 == (node->pack = malloc(sizeof(nmeaGPGSV)))) - goto mem_fail; - node->packType = GPGSV; - if(!nmea_parse_GPGSV( - (const char *)parser->buffer + nparsed, - sen_sz, (nmeaGPGSV *)node->pack)) - { - free(node); - node = 0; - } - break; - case GPRMC: - if(0 == (node->pack = malloc(sizeof(nmeaGPRMC)))) - goto mem_fail; - node->packType = GPRMC; - if(!nmea_parse_GPRMC( - (const char *)parser->buffer + nparsed, - sen_sz, (nmeaGPRMC *)node->pack)) - { - free(node); - node = 0; - } - break; - case GPVTG: - if(0 == (node->pack = malloc(sizeof(nmeaGPVTG)))) - goto mem_fail; - node->packType = GPVTG; - if(!nmea_parse_GPVTG( - (const char *)parser->buffer + nparsed, - sen_sz, (nmeaGPVTG *)node->pack)) - { - free(node); - node = 0; - } - break; - default: - free(node); - node = 0; - break; - }; - - if(node) - { - if(parser->end_node) - ((nmeaParserNODE *)parser->end_node)->next_node = node; - parser->end_node = node; - if(!parser->top_node) - parser->top_node = node; - node->next_node = 0; - } - } - - nparsed += sen_sz; - } - - return nparsed; - -mem_fail: - if(node) - free(node); - - nmea_error("Insufficient memory!"); - - return -1; -} - -/** - * \brief Analysis of buffer and keep results into parser - * @return Number of bytes wos parsed from buffer - */ -int nmea_parser_push(nmeaPARSER *parser, const char *buff, int buff_sz) -{ - int nparse, nparsed = 0; - - do - { - if(buff_sz > parser->buff_size) - nparse = parser->buff_size; - else - nparse = buff_sz; - - nparsed += nmea_parser_real_push( - parser, buff, nparse); - - buff_sz -= nparse; - - } while(buff_sz); - - return nparsed; -} - -/** - * \brief Get type of top packet keeped into parser - * @return Type of packet - * @see nmeaPACKTYPE - */ -int nmea_parser_top(nmeaPARSER *parser) -{ - int retval = GPNON; - nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node; - - //NMEA_ASSERT(parser && parser->buffer); - - if(node) - retval = node->packType; - - return retval; -} - -/** - * \brief Withdraw top packet from parser - * @return Received packet type - * @see nmeaPACKTYPE - */ -int nmea_parser_pop(nmeaPARSER *parser, void **pack_ptr) -{ - int retval = GPNON; - nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node; - - //NMEA_ASSERT(parser && parser->buffer); - - if(node) - { - *pack_ptr = node->pack; - retval = node->packType; - parser->top_node = node->next_node; - if(!parser->top_node) - parser->end_node = 0; - free(node); - } - - return retval; -} - -/** - * \brief Get top packet from parser without withdraw - * @return Received packet type - * @see nmeaPACKTYPE - */ -int nmea_parser_peek(nmeaPARSER *parser, void **pack_ptr) -{ - int retval = GPNON; - nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node; - - //NMEA_ASSERT(parser && parser->buffer); - - if(node) - { - *pack_ptr = node->pack; - retval = node->packType; - } - - return retval; -} - -/** - * \brief Delete top packet from parser - * @return Deleted packet type - * @see nmeaPACKTYPE - */ -int nmea_parser_drop(nmeaPARSER *parser) -{ - int retval = GPNON; - nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node; - - //NMEA_ASSERT(parser && parser->buffer); - - if(node) - { - if(node->pack) - free(node->pack); - retval = node->packType; - parser->top_node = node->next_node; - if(!parser->top_node) - parser->end_node = 0; - free(node); - } - - return retval; -} - -/** - * \brief Clear cache of parser - * @return true (1) - success - */ -int nmea_parser_buff_clear(nmeaPARSER *parser) -{ - //NMEA_ASSERT(parser && parser->buffer); - parser->buff_use = 0; - return 1; -} - -/** - * \brief Clear packets queue into parser - * @return true (1) - success - */ -int nmea_parser_queue_clear(nmeaPARSER *parser) -{ - //NMEA_ASSERT(parser); - while(parser->top_node) - nmea_parser_drop(parser); - return 1; -} diff --git a/apps/gps/nmealib/sentence.c b/apps/gps/nmealib/sentence.c deleted file mode 100644 index a66393a4d..000000000 --- a/apps/gps/nmealib/sentence.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: sentence.c 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -#include "nmea/sentence.h" - -#include - -void nmea_zero_GPGGA(nmeaGPGGA *pack) -{ - memset(pack, 0, sizeof(nmeaGPGGA)); - nmea_time_now(&pack->utc); - pack->ns = 'N'; - pack->ew = 'E'; - pack->elv_units = 'M'; - pack->diff_units = 'M'; -} - -void nmea_zero_GPGSA(nmeaGPGSA *pack) -{ - memset(pack, 0, sizeof(nmeaGPGSA)); - pack->fix_mode = 'A'; - pack->fix_type = NMEA_FIX_BAD; -} - -void nmea_zero_GPGSV(nmeaGPGSV *pack) -{ - memset(pack, 0, sizeof(nmeaGPGSV)); -} - -void nmea_zero_GPRMC(nmeaGPRMC *pack) -{ - memset(pack, 0, sizeof(nmeaGPRMC)); - nmea_time_now(&pack->utc); - pack->status = 'V'; - pack->ns = 'N'; - pack->ew = 'E'; - pack->declin_ew = 'E'; -} - -void nmea_zero_GPVTG(nmeaGPVTG *pack) -{ - memset(pack, 0, sizeof(nmeaGPVTG)); - pack->dir_t = 'T'; - pack->dec_m = 'M'; - pack->spn_n = 'N'; - pack->spk_k = 'K'; -} diff --git a/apps/gps/nmealib/time.c b/apps/gps/nmealib/time.c deleted file mode 100644 index a24319630..000000000 --- a/apps/gps/nmealib/time.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: time.c 4 2007-08-27 13:11:03Z xtimor $ - * - */ - -/*! \file time.h */ - -#include "nmea/time.h" - -#ifdef NMEA_WIN -# pragma warning(disable: 4201) -# pragma warning(disable: 4214) -# pragma warning(disable: 4115) -# include -# pragma warning(default: 4201) -# pragma warning(default: 4214) -# pragma warning(default: 4115) -#else -# include -#endif - -#ifdef NMEA_WIN - -void nmea_time_now(nmeaTIME *stm) -{ - SYSTEMTIME st; - - GetSystemTime(&st); - - stm->year = st.wYear - 1900; - stm->mon = st.wMonth - 1; - stm->day = st.wDay; - stm->hour = st.wHour; - stm->min = st.wMinute; - stm->sec = st.wSecond; - stm->hsec = st.wMilliseconds / 10; -} - -#else /* NMEA_WIN */ - -void nmea_time_now(nmeaTIME *stm) -{ - time_t lt; - struct tm *tt; - - time(<); - tt = gmtime(<); - - stm->year = tt->tm_year; - stm->mon = tt->tm_mon; - stm->day = tt->tm_mday; - stm->hour = tt->tm_hour; - stm->min = tt->tm_min; - stm->sec = tt->tm_sec; - stm->hsec = 0; -} - -#endif diff --git a/apps/gps/nmealib/tok.c b/apps/gps/nmealib/tok.c deleted file mode 100644 index c7cf2f4dc..000000000 --- a/apps/gps/nmealib/tok.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * - * NMEA library - * URL: http://nmea.sourceforge.net - * Author: Tim (xtimor@gmail.com) - * Licence: http://www.gnu.org/licenses/lgpl.html - * $Id: tok.c 17 2008-03-11 11:56:11Z xtimor $ - * - */ - -/*! \file tok.h */ - -#include "nmea/tok.h" - -#include -#include -#include -#include -#include -#include - -#define NMEA_TOKS_COMPARE (1) -#define NMEA_TOKS_PERCENT (2) -#define NMEA_TOKS_WIDTH (3) -#define NMEA_TOKS_TYPE (4) - -//memchr replacement -void * -memchr(s, c, n) - const void *s; - unsigned char c; - size_t n; -{ - if (n != 0) { - const unsigned char *p = s; - - do { - if (*p++ == c) - return ((void *)(p - 1)); - } while (--n != 0); - } - return (NULL); -} - - -/** - * \brief Calculate control sum of binary buffer - */ -int nmea_calc_crc(const char *buff, int buff_sz) -{ - int chsum = 0, - it; - - for(it = 0; it < buff_sz; ++it) - chsum ^= (int)buff[it]; - - return chsum; -} - -/** - * \brief Convert string to number - */ -int nmea_atoi(const char *str, int str_sz, int radix) -{ - char *tmp_ptr; - char buff[NMEA_CONVSTR_BUF]; - int res = 0; - - if(str_sz < NMEA_CONVSTR_BUF) - { - memcpy(&buff[0], str, str_sz); - buff[str_sz] = '\0'; - res = strtol(&buff[0], &tmp_ptr, radix); - } - return res; -} - -/** - * \brief Convert string to fraction number - */ -float nmea_atof(const char *str, int str_sz) -{ - char *tmp_ptr; - char buff[NMEA_CONVSTR_BUF]; - float res = 0; - - if(str_sz < NMEA_CONVSTR_BUF) - { - memcpy(&buff[0], str, str_sz); - buff[str_sz] = '\0'; - res = (float)strtod(&buff[0], &tmp_ptr); - } - return res; -} - -/** - * \brief Formating string (like standart printf) with CRC tail (*CRC) - */ -int nmea_printf(char *buff, int buff_sz, const char *format, ...) -{ - int retval, add = 0; - va_list arg_ptr; - - if(buff_sz <= 0) - return 0; - - va_start(arg_ptr, format); - - retval = NMEA_POSIX(vsnprintf)(buff, buff_sz, format, arg_ptr); - - if(retval > 0) - { - add = NMEA_POSIX(snprintf)( - buff + retval, buff_sz - retval, "*%02x\r\n", - nmea_calc_crc(buff + 1, retval - 1)); - } - - retval += add; - - if(retval < 0 || retval > buff_sz) - { - memset(buff, ' ', buff_sz); - retval = buff_sz; - } - - va_end(arg_ptr); - - return retval; -} - -/** - * \brief Analyse string (specificate for NMEA sentences) - */ -int nmea_scanf(const char *buff, int buff_sz, const char *format, ...) -{ - const char *beg_tok; - const char *end_buf = buff + buff_sz; - - va_list arg_ptr; - int tok_type = NMEA_TOKS_COMPARE; - int width = 0; - const char *beg_fmt = 0; - int snum = 0, unum = 0; - - int tok_count = 0; - void *parg_target; - - va_start(arg_ptr, format); - - for(; *format && buff < end_buf; ++format) - { - switch(tok_type) - { - case NMEA_TOKS_COMPARE: - if('%' == *format) - tok_type = NMEA_TOKS_PERCENT; - else if(*buff++ != *format) - goto fail; - break; - case NMEA_TOKS_PERCENT: - width = 0; - beg_fmt = format; - tok_type = NMEA_TOKS_WIDTH; - case NMEA_TOKS_WIDTH: - if(isdigit(*format)) - break; - { - tok_type = NMEA_TOKS_TYPE; - if(format > beg_fmt) - width = nmea_atoi(beg_fmt, (int)(format - beg_fmt), 10); - } - case NMEA_TOKS_TYPE: - beg_tok = buff; - - if(!width && ('c' == *format || 'C' == *format) && *buff != format[1]) - width = 1; - - if(width) - { - if(buff + width <= end_buf) - buff += width; - else - goto fail; - } - else - { - if(!format[1] || (0 == (buff = (char *)memchr(buff, format[1], end_buf - buff)))) - buff = end_buf; - } - - if(buff > end_buf) - goto fail; - - tok_type = NMEA_TOKS_COMPARE; - tok_count++; - - parg_target = 0; width = (int)(buff - beg_tok); - - switch(*format) - { - case 'c': - case 'C': - parg_target = (void *)va_arg(arg_ptr, char *); - if(width && 0 != (parg_target)) - *((char *)parg_target) = *beg_tok; - break; - case 's': - case 'S': - parg_target = (void *)va_arg(arg_ptr, char *); - if(width && 0 != (parg_target)) - { - memcpy(parg_target, beg_tok, width); - ((char *)parg_target)[width] = '\0'; - } - break; - case 'f': - case 'g': - case 'G': - case 'e': - case 'E': - parg_target = (void *)va_arg(arg_ptr, float *); - if(width && 0 != (parg_target)) - *((float *)parg_target) = nmea_atof(beg_tok, width); - break; - }; - - if(parg_target) - break; - if(0 == (parg_target = (void *)va_arg(arg_ptr, int *))) - break; - if(!width) - break; - - switch(*format) - { - case 'd': - case 'i': - snum = nmea_atoi(beg_tok, width, 10); - memcpy(parg_target, &snum, sizeof(int)); - break; - case 'u': - unum = nmea_atoi(beg_tok, width, 10); - memcpy(parg_target, &unum, sizeof(unsigned int)); - break; - case 'x': - case 'X': - unum = nmea_atoi(beg_tok, width, 16); - memcpy(parg_target, &unum, sizeof(unsigned int)); - break; - case 'o': - unum = nmea_atoi(beg_tok, width, 8); - memcpy(parg_target, &unum, sizeof(unsigned int)); - break; - default: - goto fail; - }; - - break; - }; - } - -fail: - - va_end(arg_ptr); - - return tok_count; -} diff --git a/apps/gps/ubx.c b/apps/gps/ubx.c deleted file mode 100644 index b9f8a28a0..000000000 --- a/apps/gps/ubx.c +++ /dev/null @@ -1,1022 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. - * Author: Thomas Gubler - * Julian Oes - * - * 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 PX4 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. - * - ****************************************************************************/ - -/* @file U-Blox protocol implementation */ - - -#include "ubx.h" -#include "gps.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define UBX_HEALTH_SUCCESS_COUNTER_LIMIT 2 -#define UBX_HEALTH_FAIL_COUNTER_LIMIT 3 -#define UBX_HEALTH_PROBE_COUNTER_LIMIT 4 - -#define UBX_BUFFER_SIZE 500 - -extern bool gps_mode_try_all; -extern bool gps_mode_success; -extern bool terminate_gps_thread; -extern bool gps_baud_try_all; -extern bool gps_verbose; -extern int current_gps_speed; - -pthread_mutex_t *ubx_mutex; -gps_bin_ubx_state_t *ubx_state; -enum UBX_CONFIG_STATE ubx_config_state; -static struct vehicle_gps_position_s *ubx_gps; - - - -void ubx_decode_init(void) -{ - ubx_state->ck_a = 0; - ubx_state->ck_b = 0; - ubx_state->rx_count = 0; - ubx_state->decode_state = UBX_DECODE_UNINIT; - ubx_state->message_class = CLASS_UNKNOWN; - ubx_state->message_id = ID_UNKNOWN; - ubx_state->payload_size = 0; - ubx_state->print_errors = false; -} - -void ubx_checksum(uint8_t b, uint8_t *ck_a, uint8_t *ck_b) -{ - *(ck_a) = *(ck_a) + b; - *(ck_b) = *(ck_b) + *(ck_a); -} - - - - - -int ubx_parse(uint8_t b, char *gps_rx_buffer) -{ - //printf("b=%x\n",b); - if (ubx_state->decode_state == UBX_DECODE_UNINIT) { - - if (b == UBX_SYNC_1) { - ubx_state->decode_state = UBX_DECODE_GOT_SYNC1; - } - - } else if (ubx_state->decode_state == UBX_DECODE_GOT_SYNC1) { - if (b == UBX_SYNC_2) { - ubx_state->decode_state = UBX_DECODE_GOT_SYNC2; - - } else { - // Second start symbol was wrong, reset state machine - ubx_decode_init(); - } - - } else if (ubx_state->decode_state == UBX_DECODE_GOT_SYNC2) { - // Add to checksum - ubx_checksum(b, &(ubx_state->ck_a), &(ubx_state->ck_b)); - - //check for known class - switch (b) { - case UBX_CLASS_ACK: - ubx_state->decode_state = UBX_DECODE_GOT_CLASS; - ubx_state->message_class = ACK; - break; - - case UBX_CLASS_NAV: - ubx_state->decode_state = UBX_DECODE_GOT_CLASS; - ubx_state->message_class = NAV; - break; - - case UBX_CLASS_RXM: - ubx_state->decode_state = UBX_DECODE_GOT_CLASS; - ubx_state->message_class = RXM; - break; - - case UBX_CLASS_CFG: - ubx_state->decode_state = UBX_DECODE_GOT_CLASS; - ubx_state->message_class = CFG; - break; - default: //unknown class: reset state machine - ubx_decode_init(); - break; - } - - } else if (ubx_state->decode_state == UBX_DECODE_GOT_CLASS) { - // Add to checksum - ubx_checksum(b, &(ubx_state->ck_a), &(ubx_state->ck_b)); - - //depending on class look for message id - switch (ubx_state->message_class) { - case NAV: - switch (b) { - case UBX_MESSAGE_NAV_POSLLH: //NAV-POSLLH: Geodetic Position Solution - ubx_state->decode_state = UBX_DECODE_GOT_MESSAGEID; - ubx_state->message_id = NAV_POSLLH; - break; - - case UBX_MESSAGE_NAV_SOL: - ubx_state->decode_state = UBX_DECODE_GOT_MESSAGEID; - ubx_state->message_id = NAV_SOL; - break; - - case UBX_MESSAGE_NAV_TIMEUTC: - ubx_state->decode_state = UBX_DECODE_GOT_MESSAGEID; - ubx_state->message_id = NAV_TIMEUTC; - break; - - case UBX_MESSAGE_NAV_DOP: - ubx_state->decode_state = UBX_DECODE_GOT_MESSAGEID; - ubx_state->message_id = NAV_DOP; - break; - - case UBX_MESSAGE_NAV_SVINFO: - ubx_state->decode_state = UBX_DECODE_GOT_MESSAGEID; - ubx_state->message_id = NAV_SVINFO; - break; - - case UBX_MESSAGE_NAV_VELNED: - ubx_state->decode_state = UBX_DECODE_GOT_MESSAGEID; - ubx_state->message_id = NAV_VELNED; - break; - - default: //unknown class: reset state machine, should not happen - ubx_decode_init(); - break; - } - - break; - - case RXM: - switch (b) { - case UBX_MESSAGE_RXM_SVSI: - ubx_state->decode_state = UBX_DECODE_GOT_MESSAGEID; - ubx_state->message_id = RXM_SVSI; - break; - - default: //unknown class: reset state machine, should not happen - ubx_decode_init(); - break; - } - break; - - case CFG: - switch (b) { - case UBX_MESSAGE_CFG_NAV5: - ubx_state->decode_state = UBX_DECODE_GOT_MESSAGEID; - ubx_state->message_id = CFG_NAV5; - break; - - default: //unknown class: reset state machine, should not happen - ubx_decode_init(); - break; - } - break; - - case ACK: - switch (b) { - case UBX_MESSAGE_ACK_ACK: - ubx_state->decode_state = UBX_DECODE_GOT_MESSAGEID; - ubx_state->message_id = ACK_ACK; - break; - case UBX_MESSAGE_ACK_NAK: - ubx_state->decode_state = UBX_DECODE_GOT_MESSAGEID; - ubx_state->message_id = ACK_NAK; - break; - default: //unknown class: reset state machine, should not happen - ubx_decode_init(); - break; - } - break; - default: //should not happen - ubx_decode_init(); - break; - } - - } else if (ubx_state->decode_state == UBX_DECODE_GOT_MESSAGEID) { - // Add to checksum - ubx_checksum(b, &(ubx_state->ck_a), &(ubx_state->ck_b)); - - ubx_state->payload_size = b; - ubx_state->decode_state = UBX_DECODE_GOT_LENGTH1; - - } else if (ubx_state->decode_state == UBX_DECODE_GOT_LENGTH1) { - // Add to checksum - ubx_checksum(b, &(ubx_state->ck_a), &(ubx_state->ck_b)); - - ubx_state->payload_size += b << 8; - ubx_state->decode_state = UBX_DECODE_GOT_LENGTH2; - - } else if (ubx_state->decode_state == UBX_DECODE_GOT_LENGTH2) { - uint8_t ret = 0; - - // Add to checksum if not yet at checksum byte - if (ubx_state->rx_count < ubx_state->payload_size) ubx_checksum(b, &(ubx_state->ck_a), &(ubx_state->ck_b)); - - // Fill packet buffer - gps_rx_buffer[ubx_state->rx_count] = b; - - //if whole payload + checksum is in buffer: - if (ubx_state->rx_count >= ubx_state->payload_size + 1) { - //convert to correct struct - switch (ubx_state->message_id) { //this enum is unique for all ids --> no need to check the class - case NAV_POSLLH: { -// printf("GOT NAV_POSLLH MESSAGE\n"); - gps_bin_nav_posllh_packet_t *packet = (gps_bin_nav_posllh_packet_t *) gps_rx_buffer; - - //Check if checksum is valid and the store the gps information - if (ubx_state->ck_a == packet->ck_a && ubx_state->ck_b == packet->ck_b) { - ubx_gps->lat = packet->lat; - ubx_gps->lon = packet->lon; - ubx_gps->alt = packet->height_msl; - - ubx_gps->counter_pos_valid++; - - ubx_gps->timestamp = hrt_absolute_time(); - ubx_gps->counter++; - - //pthread_mutex_lock(ubx_mutex); - ubx_state->last_message_timestamps[NAV_POSLLH - 1] = hrt_absolute_time(); - //pthread_mutex_unlock(ubx_mutex); - ret = 1; - - } else { - if (gps_verbose) printf("[gps] NAV_POSLLH: checksum invalid\n"); - - ret = 0; - } - - // Reset state machine to decode next packet - ubx_decode_init(); - return ret; - - break; - } - - case NAV_SOL: { -// printf("GOT NAV_SOL MESSAGE\n"); - gps_bin_nav_sol_packet_t *packet = (gps_bin_nav_sol_packet_t *) gps_rx_buffer; - - //Check if checksum is valid and the store the gps information - if (ubx_state->ck_a == packet->ck_a && ubx_state->ck_b == packet->ck_b) { - - ubx_gps->fix_type = packet->gpsFix; - - ubx_gps->timestamp = hrt_absolute_time(); - ubx_gps->counter++; - ubx_gps->s_variance = packet->sAcc; - ubx_gps->p_variance = packet->pAcc; - - //pthread_mutex_lock(ubx_mutex); - ubx_state->last_message_timestamps[NAV_SOL - 1] = hrt_absolute_time(); - //pthread_mutex_unlock(ubx_mutex); - ret = 1; - - } else { - if (gps_verbose) printf("[gps] NAV_SOL: checksum invalid\n"); - - ret = 0; - } - - // Reset state machine to decode next packet - ubx_decode_init(); - return ret; - - break; - } - - case NAV_DOP: { -// printf("GOT NAV_DOP MESSAGE\n"); - gps_bin_nav_dop_packet_t *packet = (gps_bin_nav_dop_packet_t *) gps_rx_buffer; - - //Check if checksum is valid and the store the gps information - if (ubx_state->ck_a == packet->ck_a && ubx_state->ck_b == packet->ck_b) { - - ubx_gps->eph = packet->hDOP; - ubx_gps->epv = packet->vDOP; - - ubx_gps->timestamp = hrt_absolute_time(); - ubx_gps->counter++; - - - //pthread_mutex_lock(ubx_mutex); - ubx_state->last_message_timestamps[NAV_DOP - 1] = hrt_absolute_time(); - //pthread_mutex_unlock(ubx_mutex); - ret = 1; - - } else { - if (gps_verbose) printf("[gps] NAV_DOP: checksum invalid\n"); - - ret = 0; - } - - // Reset state machine to decode next packet - ubx_decode_init(); - return ret; - - break; - } - - case NAV_TIMEUTC: { -// printf("GOT NAV_TIMEUTC MESSAGE\n"); - gps_bin_nav_timeutc_packet_t *packet = (gps_bin_nav_timeutc_packet_t *) gps_rx_buffer; - - //Check if checksum is valid and the store the gps information - if (ubx_state->ck_a == packet->ck_a && ubx_state->ck_b == packet->ck_b) { - //convert to unix timestamp - struct tm timeinfo; - timeinfo.tm_year = packet->year - 1900; - timeinfo.tm_mon = packet->month - 1; - timeinfo.tm_mday = packet->day; - timeinfo.tm_hour = packet->hour; - timeinfo.tm_min = packet->min; - timeinfo.tm_sec = packet->sec; - - time_t epoch = mktime(&timeinfo); - -// printf("%d.%d.%d %d:%d:%d:%d\n", timeinfo.tm_year, timeinfo.tm_mon, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, packet->time_nanoseconds); - - - - ubx_gps->time_gps_usec = (uint64_t)epoch * 1000000; //TODO: test this - ubx_gps->time_gps_usec += (uint64_t)(packet->time_nanoseconds * 1e-3f); - - ubx_gps->timestamp = hrt_absolute_time(); - ubx_gps->counter++; - - - //pthread_mutex_lock(ubx_mutex); - ubx_state->last_message_timestamps[NAV_TIMEUTC - 1] = hrt_absolute_time(); - //pthread_mutex_unlock(ubx_mutex); - ret = 1; - - } else { - if (gps_verbose) printf("\t[gps] NAV_TIMEUTC: checksum invalid\n"); - - ret = 0; - } - - // Reset state machine to decode next packet - ubx_decode_init(); - return ret; - - break; - } - - case NAV_SVINFO: { -// printf("GOT NAV_SVINFO MESSAGE\n"); - - //this is a more complicated message: the length depends on the number of satellites. This number is extracted from the first part of the message - const int length_part1 = 8; - char gps_rx_buffer_part1[length_part1]; - memcpy(gps_rx_buffer_part1, gps_rx_buffer, length_part1); - gps_bin_nav_svinfo_part1_packet_t *packet_part1 = (gps_bin_nav_svinfo_part1_packet_t *) gps_rx_buffer_part1; - - //read checksum - const int length_part3 = 2; - char gps_rx_buffer_part3[length_part3]; - memcpy(gps_rx_buffer_part3, &(gps_rx_buffer[ubx_state->rx_count - 1]), length_part3); - gps_bin_nav_svinfo_part3_packet_t *packet_part3 = (gps_bin_nav_svinfo_part3_packet_t *) gps_rx_buffer_part3; - - //Check if checksum is valid and then store the gps information - if (ubx_state->ck_a == packet_part3->ck_a && ubx_state->ck_b == packet_part3->ck_b) { - //definitions needed to read numCh elements from the buffer: - const int length_part2 = 12; - gps_bin_nav_svinfo_part2_packet_t *packet_part2; - char gps_rx_buffer_part2[length_part2]; //for temporal storage - - - int i; - - for (i = 0; i < packet_part1->numCh; i++) { //for each channel - - /* Get satellite information from the buffer */ - - memcpy(gps_rx_buffer_part2, &(gps_rx_buffer[length_part1 + i * length_part2]), length_part2); - packet_part2 = (gps_bin_nav_svinfo_part2_packet_t *) gps_rx_buffer_part2; - - - /* Write satellite information in the global storage */ - - ubx_gps->satellite_prn[i] = packet_part2->svid; - - //if satellite information is healthy store the data - uint8_t unhealthy = packet_part2->flags & 1 << 4; //flags is a bitfield - - if (!unhealthy) { - - if ((packet_part2->flags) & 1) { //flags is a bitfield - ubx_gps->satellite_used[i] = 1; - - } else { - ubx_gps->satellite_used[i] = 0; - } - - ubx_gps->satellite_snr[i] = packet_part2->cno; - ubx_gps->satellite_elevation[i] = (uint8_t)(packet_part2->elev); - ubx_gps->satellite_azimuth[i] = (uint8_t)((float)packet_part2->azim * 255.0f / 360.0f); - - } else { - ubx_gps->satellite_used[i] = 0; - ubx_gps->satellite_snr[i] = 0; - ubx_gps->satellite_elevation[i] = 0; - ubx_gps->satellite_azimuth[i] = 0; - } - - } - - for (i = packet_part1->numCh; i < 20; i++) { //these channels are unused - /* Unused channels have to be set to zero for e.g. MAVLink */ - ubx_gps->satellite_prn[i] = 0; - ubx_gps->satellite_used[i] = 0; - ubx_gps->satellite_snr[i] = 0; - ubx_gps->satellite_elevation[i] = 0; - ubx_gps->satellite_azimuth[i] = 0; - } - - /* set flag if any sat info is available */ - if (!packet_part1->numCh > 0) { - ubx_gps->satellite_info_available = 1; - - } else { - ubx_gps->satellite_info_available = 0; - } - - ubx_gps->timestamp = hrt_absolute_time(); - ubx_gps->counter++; - - - //pthread_mutex_lock(ubx_mutex); - ubx_state->last_message_timestamps[NAV_SVINFO - 1] = hrt_absolute_time(); - //pthread_mutex_unlock(ubx_mutex); - ret = 1; - - } else { - if (gps_verbose) printf("\t[gps] NAV_SVINFO: checksum invalid\n"); - - ret = 0; - } - - // Reset state machine to decode next packet - ubx_decode_init(); - return ret; - - break; - } - - case NAV_VELNED: { -// printf("GOT NAV_VELNED MESSAGE\n"); - gps_bin_nav_velned_packet_t *packet = (gps_bin_nav_velned_packet_t *) gps_rx_buffer; - - //Check if checksum is valid and the store the gps information - if (ubx_state->ck_a == packet->ck_a && ubx_state->ck_b == packet->ck_b) { - - ubx_gps->vel = (uint16_t)packet->speed; - ubx_gps->vel_n = packet->velN / 100.0f; - ubx_gps->vel_e = packet->velE / 100.0f; - ubx_gps->vel_d = packet->velD / 100.0f; - ubx_gps->vel_ned_valid = true; - ubx_gps->cog = (uint16_t)((float)(packet->heading) * 1e-3f); - - ubx_gps->timestamp = hrt_absolute_time(); - ubx_gps->counter++; - - - //pthread_mutex_lock(ubx_mutex); - ubx_state->last_message_timestamps[NAV_VELNED - 1] = hrt_absolute_time(); - //pthread_mutex_unlock(ubx_mutex); - ret = 1; - - } else { - if (gps_verbose) printf("[gps] NAV_VELNED: checksum invalid\n"); - - ret = 0; - } - - // Reset state machine to decode next packet - ubx_decode_init(); - return ret; - - break; - } - - case RXM_SVSI: { -// printf("GOT RXM_SVSI MESSAGE\n"); - const int length_part1 = 7; - char gps_rx_buffer_part1[length_part1]; - memcpy(gps_rx_buffer_part1, gps_rx_buffer, length_part1); - gps_bin_rxm_svsi_packet_t *packet = (gps_bin_rxm_svsi_packet_t *) gps_rx_buffer_part1; - - //Check if checksum is valid and the store the gps information - if (ubx_state->ck_a == gps_rx_buffer[ubx_state->rx_count - 1] && ubx_state->ck_b == gps_rx_buffer[ubx_state->rx_count]) { - - ubx_gps->satellites_visible = packet->numVis; - - ubx_gps->timestamp = hrt_absolute_time(); - ubx_gps->counter++; - - - //pthread_mutex_lock(ubx_mutex); - ubx_state->last_message_timestamps[RXM_SVSI - 1] = hrt_absolute_time(); - //pthread_mutex_unlock(ubx_mutex); - ret = 1; - - } else { - if (gps_verbose) printf("[gps] RXM_SVSI: checksum invalid\n"); - - ret = 0; - } - - // Reset state machine to decode next packet - ubx_decode_init(); - return ret; - - break; - } - - case ACK_ACK: { -// printf("GOT ACK_ACK\n"); - gps_bin_ack_ack_packet_t *packet = (gps_bin_ack_ack_packet_t *) gps_rx_buffer; - - //Check if checksum is valid - if (ubx_state->ck_a == packet->ck_a && ubx_state->ck_b == packet->ck_b) { - - switch (ubx_config_state) { - case UBX_CONFIG_STATE_PRT: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_PRT) - ubx_config_state++; - break; - case UBX_CONFIG_STATE_NAV5: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_NAV5) - ubx_config_state++; - break; - case UBX_CONFIG_STATE_MSG_NAV_POSLLH: - case UBX_CONFIG_STATE_MSG_NAV_TIMEUTC: - case UBX_CONFIG_STATE_MSG_NAV_DOP: - case UBX_CONFIG_STATE_MSG_NAV_SVINFO: - case UBX_CONFIG_STATE_MSG_NAV_SOL: - case UBX_CONFIG_STATE_MSG_NAV_VELNED: - case UBX_CONFIG_STATE_MSG_RXM_SVSI: - if (packet->clsID == UBX_CLASS_CFG && packet->msgID == UBX_MESSAGE_CFG_MSG) - ubx_config_state++; - break; - default: - break; - } - - - ret = 1; - - } else { - if (gps_verbose) printf("[gps] ACK_ACK: checksum invalid\n"); - - ret = 0; - } - - // Reset state machine to decode next packet - ubx_decode_init(); - return ret; - - break; - } - - case ACK_NAK: { -// printf("GOT ACK_NAK\n"); - gps_bin_ack_nak_packet_t *packet = (gps_bin_ack_nak_packet_t *) gps_rx_buffer; - - //Check if checksum is valid - if (ubx_state->ck_a == packet->ck_a && ubx_state->ck_b == packet->ck_b) { - - if (gps_verbose) printf("[gps] the ubx gps returned: not acknowledged\n"); - ret = 1; - - } else { - if (gps_verbose) printf("[gps] ACK_NAK: checksum invalid\n"); - - ret = 0; - } - - // Reset state machine to decode next packet - ubx_decode_init(); - return ret; - - break; - } - - default: //something went wrong - ubx_decode_init(); - - break; - } - } - - (ubx_state->rx_count)++; - - - - } - - - return 0; // no valid packet found - -} - -void calculate_ubx_checksum(uint8_t *message, uint8_t length) -{ - uint8_t ck_a = 0; - uint8_t ck_b = 0; - - int i; - - for (i = 2; i < length - 2; i++) { - ck_a = ck_a + message[i]; - ck_b = ck_b + ck_a; - } - - message[length - 2] = ck_a; - message[length - 1] = ck_b; -} - -int configure_gps_ubx(int *fd) -{ - // only needed once like this - const type_gps_bin_cfg_prt_packet_t cfg_prt_packet = { - .clsID = UBX_CLASS_CFG, - .msgID = UBX_MESSAGE_CFG_PRT, - .length = UBX_CFG_PRT_LENGTH, - .portID = UBX_CFG_PRT_PAYLOAD_PORTID, - .mode = UBX_CFG_PRT_PAYLOAD_MODE, - .baudRate = current_gps_speed, - .inProtoMask = UBX_CFG_PRT_PAYLOAD_INPROTOMASK, - .outProtoMask = UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK, - .ck_a = 0, - .ck_b = 0 - }; - - // only needed once like this - const type_gps_bin_cfg_nav5_packet_t cfg_nav5_packet = { - .clsID = UBX_CLASS_CFG, - .msgID = UBX_MESSAGE_CFG_NAV5, - .length = UBX_CFG_NAV5_LENGTH, - .mask = UBX_CFG_NAV5_PAYLOAD_MASK, - .dynModel = UBX_CFG_NAV5_PAYLOAD_DYNMODEL, - .fixMode = UBX_CFG_NAV5_PAYLOAD_FIXMODE, - .ck_a = 0, - .ck_b = 0 - }; - - // this message is reusable for different configuration commands, so not const - type_gps_bin_cfg_msg_packet cfg_msg_packet = { - .clsID = UBX_CLASS_CFG, - .msgID = UBX_MESSAGE_CFG_MSG, - .length = UBX_CFG_MSG_LENGTH, - .rate = UBX_CFG_MSG_PAYLOAD_RATE - }; - - uint64_t time_before_config = hrt_absolute_time(); - - while(hrt_absolute_time() < time_before_config + UBX_CONFIG_TIMEOUT) { - -// if (gps_verbose) printf("[gps] ubx config state: %d\n", ubx_config_state); - - switch (ubx_config_state) { - case UBX_CONFIG_STATE_PRT: -// if (gps_verbose) printf("[gps] Configuring ubx with baudrate: %d\n", cfg_prt_packet.baudRate); - - write_config_message_ubx((uint8_t*)(&cfg_prt_packet), sizeof(cfg_prt_packet), fd); - break; - case UBX_CONFIG_STATE_NAV5: - write_config_message_ubx((uint8_t*)(&cfg_nav5_packet), sizeof(cfg_nav5_packet), fd); - break; - case UBX_CONFIG_STATE_MSG_NAV_POSLLH: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_POSLLH; - write_config_message_ubx((uint8_t*)(&cfg_msg_packet), sizeof(cfg_msg_packet), fd); - break; - case UBX_CONFIG_STATE_MSG_NAV_TIMEUTC: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_TIMEUTC; - write_config_message_ubx((uint8_t*)(&cfg_msg_packet), sizeof(cfg_msg_packet), fd); - break; - case UBX_CONFIG_STATE_MSG_NAV_DOP: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_DOP; - write_config_message_ubx((uint8_t*)(&cfg_msg_packet), sizeof(cfg_msg_packet), fd); - break; - case UBX_CONFIG_STATE_MSG_NAV_SVINFO: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_SVINFO; - write_config_message_ubx((uint8_t*)(&cfg_msg_packet), sizeof(cfg_msg_packet), fd); - break; - case UBX_CONFIG_STATE_MSG_NAV_SOL: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_SOL; - write_config_message_ubx((uint8_t*)(&cfg_msg_packet), sizeof(cfg_msg_packet), fd); - break; - case UBX_CONFIG_STATE_MSG_NAV_VELNED: - cfg_msg_packet.msgClass_payload = UBX_CLASS_NAV; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_NAV_VELNED; - write_config_message_ubx((uint8_t*)(&cfg_msg_packet), sizeof(cfg_msg_packet), fd); - break; - case UBX_CONFIG_STATE_MSG_RXM_SVSI: - cfg_msg_packet.msgClass_payload = UBX_CLASS_RXM; - cfg_msg_packet.msgID_payload = UBX_MESSAGE_RXM_SVSI; - write_config_message_ubx((uint8_t*)(&cfg_msg_packet), sizeof(cfg_msg_packet), fd); - break; - case UBX_CONFIG_STATE_CONFIGURED: - if (gps_verbose) printf("[gps] ubx configuration finished\n"); - return OK; - break; - default: - break; - } - usleep(10000); - } - if (gps_verbose) printf("[gps] ubx configuration timeout\n"); - return ERROR; -} - - - -int read_gps_ubx(int *fd, char *gps_rx_buffer, int buffer_size) -{ - uint8_t ret = 0; - uint8_t c; - int rx_count = 0; - int gpsRxOverflow = 0; - - struct pollfd fds; - fds.fd = *fd; - fds.events = POLLIN; - - // UBX GPS mode - // This blocks the task until there is something on the buffer - while (1) { - //check if the thread should terminate - if (terminate_gps_thread == true) { - ret = 1; - break; - } - if (poll(&fds, 1, 1000) > 0) { - if (read(*fd, &c, 1) > 0) { - -// printf("Read %x\n",c); - if (rx_count >= buffer_size) { - // The buffer is already full and we haven't found a valid ubx sentence. - // Flush the buffer and note the overflow event. - gpsRxOverflow++; - rx_count = 0; - ubx_decode_init(); - - if (gps_verbose) printf("[gps] Buffer full\n"); - - } else { - //gps_rx_buffer[rx_count] = c; - rx_count++; - - } - - int msg_read = ubx_parse(c, gps_rx_buffer); - - if (msg_read > 0) { - //printf("Found sequence\n"); - break; - } - - } else { - break; - } - - } else { - break; - } - - } - - return ret; -} - -int write_config_message_ubx(const uint8_t *message, const size_t length, const int *fd) -{ - uint8_t ck_a = 0; - uint8_t ck_b = 0; - - unsigned int i; - - uint8_t buffer[2]; - ssize_t result_write = 0; - - //calculate and write checksum to the end - for (i = 0; i < length-2; i++) { - ck_a = ck_a + message[i]; - ck_b = ck_b + ck_a; - } - - // write sync bytes first - buffer[0] = UBX_SYNC_1; - buffer[1] = UBX_SYNC_2; - - // write config message without the checksum - result_write = write(*fd, buffer, sizeof(buffer)); - result_write += write(*fd, message, length-2); - - buffer[0] = ck_a; - buffer[1] = ck_b; - - // write the checksum - result_write += write(*fd, buffer, sizeof(buffer)); - - fsync(*fd); - if ((unsigned int)result_write != length + 2) - return ERROR; - - return OK; -} - -void *ubx_watchdog_loop(void *args) -{ - /* Set thread name */ - prctl(PR_SET_NAME, "gps ubx watchdog", getpid()); - - - /* Retrieve file descriptor and thread flag */ - struct arg_struct *arguments = (struct arg_struct *)args; - int *fd = arguments->fd_ptr; - bool *thread_should_exit = arguments->thread_should_exit_ptr; - - ubx_config_state = UBX_CONFIG_STATE_PRT; - /* first try to configure the GPS anyway */ - configure_gps_ubx(fd); - - /* GPS watchdog error message skip counter */ - - bool ubx_healthy = false; - - uint8_t ubx_fail_count = 0; - uint8_t ubx_success_count = 0; - bool once_ok = false; - - int mavlink_fd = open(MAVLINK_LOG_DEVICE, 0); - - //int err_skip_counter = 0; - - while (!(*thread_should_exit)) { - /* if some values are to old reconfigure gps */ - int i; - pthread_mutex_lock(ubx_mutex); - bool all_okay = true; - uint64_t timestamp_now = hrt_absolute_time(); - - for (i = 0; i < UBX_NO_OF_MESSAGES; i++) { -// printf("timestamp_now=%llu\n", timestamp_now); -// printf("last_message_timestamps=%llu\n", ubx_state->last_message_timestamps[i]); - if (timestamp_now - ubx_state->last_message_timestamps[i] > UBX_WATCHDOG_CRITICAL_TIME_MICROSECONDS) { - //printf("Warning: GPS ubx message %d not received for a long time\n", i); - all_okay = false; - } - } - - pthread_mutex_unlock(ubx_mutex); - - if (!all_okay) { - /* gps error */ - ubx_fail_count++; -// if (err_skip_counter == 0) -// { -// printf("GPS Watchdog detected gps not running or having problems\n"); -// err_skip_counter = 20; -// } -// err_skip_counter--; - //printf("gps_mode_try_all =%u, ubx_fail_count=%u, ubx_healthy=%u, once_ok=%u\n", gps_mode_try_all, ubx_fail_count, ubx_healthy, once_ok); - - - /* If we have too many failures and another mode or baud should be tried, exit... */ - if ((gps_mode_try_all == true || gps_baud_try_all == true) && (ubx_fail_count >= UBX_HEALTH_PROBE_COUNTER_LIMIT) && (ubx_healthy == false) && once_ok == false) { - if (gps_verbose) printf("[gps] Connection attempt failed, no UBX module found\n"); - - gps_mode_success = false; - break; - } - - if (ubx_healthy && ubx_fail_count == UBX_HEALTH_FAIL_COUNTER_LIMIT) { - printf("[gps] ERROR: UBX GPS module stopped responding\n"); - // global_data_send_subsystem_info(&ubx_present_enabled); - mavlink_log_critical(mavlink_fd, "[gps] UBX module stopped responding\n"); - ubx_healthy = false; - ubx_success_count = 0; - } - - /* trying to reconfigure the gps configuration */ - ubx_config_state = UBX_CONFIG_STATE_PRT; - configure_gps_ubx(fd); - fflush(stdout); - sleep(1); - - } else { - /* gps healthy */ - ubx_success_count++; - ubx_fail_count = 0; - once_ok = true; // XXX Should this be true on a single success, or on same criteria as ubx_healthy? - - if (!ubx_healthy && ubx_success_count == UBX_HEALTH_SUCCESS_COUNTER_LIMIT) { - //printf("[gps] ublox UBX module status ok (baud=%d)\r\n", current_gps_speed); - // global_data_send_subsystem_info(&ubx_present_enabled_healthy); - mavlink_log_info(mavlink_fd, "[gps] UBX module found, status ok\n"); - ubx_healthy = true; - } - } - usleep(UBX_WATCHDOG_WAIT_TIME_MICROSECONDS); - } - - if(gps_verbose) printf("[gps] ubx loop is going to terminate\n"); - close(mavlink_fd); - return NULL; -} - -void *ubx_loop(void *args) -{ - /* Set thread name */ - prctl(PR_SET_NAME, "gps ubx read", getpid()); - - /* Retrieve file descriptor and thread flag */ - struct arg_struct *arguments = (struct arg_struct *)args; - int *fd = arguments->fd_ptr; - bool *thread_should_exit = arguments->thread_should_exit_ptr; - - /* Initialize gps stuff */ - char gps_rx_buffer[UBX_BUFFER_SIZE]; - - - if (gps_verbose) printf("[gps] UBX protocol driver starting..\n"); - - //set parameters for ubx_state - - //ubx state - ubx_state = malloc(sizeof(gps_bin_ubx_state_t)); - //printf("gps: ubx_state created\n"); - ubx_decode_init(); - ubx_state->print_errors = false; - - - /* set parameters for ubx */ - - struct vehicle_gps_position_s ubx_gps_d = {.counter = 0}; - - ubx_gps = &ubx_gps_d; - - orb_advert_t gps_pub = orb_advertise(ORB_ID(vehicle_gps_position), &ubx_gps); - - while (!(*thread_should_exit)) { - /* Parse a message from the gps receiver */ - if (0 == read_gps_ubx(fd, gps_rx_buffer, UBX_BUFFER_SIZE)) { - /* publish new GPS position */ - orb_publish(ORB_ID(vehicle_gps_position), gps_pub, ubx_gps); - - } else { - /* de-advertise */ - close(gps_pub); - break; - } - } - - if(gps_verbose) printf("[gps] ubx read is going to terminate\n"); - close(gps_pub); - return NULL; - -} diff --git a/apps/gps/ubx.h b/apps/gps/ubx.h deleted file mode 100644 index f3313a3c6..000000000 --- a/apps/gps/ubx.h +++ /dev/null @@ -1,415 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2008-2012 PX4 Development Team. All rights reserved. - * Author: Thomas Gubler - * Julian Oes - * - * 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 PX4 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. - * - ****************************************************************************/ - -/* @file U-Blox protocol definitions */ - -#ifndef UBX_H_ -#define UBX_H_ - -#include -#include -#include -#include -#include -#include -#include -#include - - -//internal definitions (not depending on the ubx protocol -#define UBX_NO_OF_MESSAGES 7 /**< Read 7 UBX GPS messages */ -#define UBX_WATCHDOG_CRITICAL_TIME_MICROSECONDS 3000000 /**< Allow 3 seconds maximum inter-message time */ -#define UBX_WATCHDOG_WAIT_TIME_MICROSECONDS 2000000 /**< Check for current state every two seconds */ - -#define UBX_CONFIG_TIMEOUT 1000000 - -#define APPNAME "gps: ubx" - -#define UBX_SYNC_1 0xB5 -#define UBX_SYNC_2 0x62 - -//UBX Protocoll definitions (this is the subset of the messages that are parsed) -#define UBX_CLASS_NAV 0x01 -#define UBX_CLASS_RXM 0x02 -#define UBX_CLASS_ACK 0x05 -#define UBX_CLASS_CFG 0x06 -#define UBX_MESSAGE_NAV_POSLLH 0x02 -#define UBX_MESSAGE_NAV_SOL 0x06 -#define UBX_MESSAGE_NAV_TIMEUTC 0x21 -#define UBX_MESSAGE_NAV_DOP 0x04 -#define UBX_MESSAGE_NAV_SVINFO 0x30 -#define UBX_MESSAGE_NAV_VELNED 0x12 -#define UBX_MESSAGE_RXM_SVSI 0x20 -#define UBX_MESSAGE_ACK_ACK 0x01 -#define UBX_MESSAGE_ACK_NAK 0x00 -#define UBX_MESSAGE_CFG_PRT 0x00 -#define UBX_MESSAGE_CFG_NAV5 0x24 -#define UBX_MESSAGE_CFG_MSG 0x01 - -#define UBX_CFG_PRT_LENGTH 20 -#define UBX_CFG_PRT_PAYLOAD_PORTID 0x01 /**< port 1 */ -#define UBX_CFG_PRT_PAYLOAD_MODE 0x000008D0 /**< 0b0000100011010000: 8N1 */ -#define UBX_CFG_PRT_PAYLOAD_BAUDRATE 38400 /**< always choose 38400 as GPS baudrate */ -#define UBX_CFG_PRT_PAYLOAD_INPROTOMASK 0x01 /**< ubx in */ -#define UBX_CFG_PRT_PAYLOAD_OUTPROTOMASK 0x01 /**< ubx out */ - -#define UBX_CFG_NAV5_LENGTH 36 -#define UBX_CFG_NAV5_PAYLOAD_MASK 0x0001 /**< only update dynamic model and fix mode */ -#define UBX_CFG_NAV5_PAYLOAD_DYNMODEL 7 /**< 0: portable, 2: stationary, 3: pedestrian, 4: automotive, 5: sea, 6: airborne <1g, 7: airborne <2g, 8: airborne <4g */ -#define UBX_CFG_NAV5_PAYLOAD_FIXMODE 2 /**< 1: 2D only, 2: 3D only, 3: Auto 2D/3D */ - -#define UBX_CFG_MSG_LENGTH 8 -#define UBX_CFG_MSG_PAYLOAD_RATE {0x00, 0x01, 0x00, 0x00, 0x00, 0x00} /**< UART1 chosen */ - - -// ************ -/** the structures of the binary packets */ -#pragma pack(push, 1) -typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - int32_t lon; // Longitude * 1e-7, deg - int32_t lat; // Latitude * 1e-7, deg - int32_t height; // Height above Ellipsoid, mm - int32_t height_msl; // Height above mean sea level, mm - uint32_t hAcc; // Horizontal Accuracy Estimate, mm - uint32_t vAcc; // Vertical Accuracy Estimate, mm - - uint8_t ck_a; - uint8_t ck_b; -} type_gps_bin_nav_posllh_packet; - -typedef type_gps_bin_nav_posllh_packet gps_bin_nav_posllh_packet_t; - -typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - int32_t time_nanoseconds; // Fractional Nanoseconds remainder of rounded ms above, range -500000 .. 500000 - int16_t week; // GPS week (GPS time) - uint8_t gpsFix; //GPS Fix: 0 = No fix, 1 = Dead Reckoning only, 2 = 2D fix, 3 = 3d-fix, 4 = GPS + dead reckoning, 5 = time only fix - uint8_t flags; - int32_t ecefX; - int32_t ecefY; - int32_t ecefZ; - uint32_t pAcc; - int32_t ecefVX; - int32_t ecefVY; - int32_t ecefVZ; - uint32_t sAcc; - uint16_t pDOP; - uint8_t reserved1; - uint8_t numSV; - uint32_t reserved2; - - uint8_t ck_a; - uint8_t ck_b; -} type_gps_bin_nav_sol_packet; - -typedef type_gps_bin_nav_sol_packet gps_bin_nav_sol_packet_t; - -typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - uint32_t time_accuracy; //Time Accuracy Estimate, ns - int32_t time_nanoseconds; //Nanoseconds of second, range -1e9 .. 1e9 (UTC) - uint16_t year; //Year, range 1999..2099 (UTC) - uint8_t month; //Month, range 1..12 (UTC) - uint8_t day; //Day of Month, range 1..31 (UTC) - uint8_t hour; //Hour of Day, range 0..23 (UTC) - uint8_t min; //Minute of Hour, range 0..59 (UTC) - uint8_t sec; //Seconds of Minute, range 0..59 (UTC) - uint8_t valid_flag; //Validity Flags (see ubx documentation) - - - uint8_t ck_a; - uint8_t ck_b; -} type_gps_bin_nav_timeutc_packet; - -typedef type_gps_bin_nav_timeutc_packet gps_bin_nav_timeutc_packet_t; - -typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - uint16_t gDOP; //Geometric DOP (scaling 0.01) - uint16_t pDOP; //Position DOP (scaling 0.01) - uint16_t tDOP; //Time DOP (scaling 0.01) - uint16_t vDOP; //Vertical DOP (scaling 0.01) - uint16_t hDOP; //Horizontal DOP (scaling 0.01) - uint16_t nDOP; //Northing DOP (scaling 0.01) - uint16_t eDOP; //Easting DOP (scaling 0.01) - - - uint8_t ck_a; - uint8_t ck_b; -} type_gps_bin_nav_dop_packet; - -typedef type_gps_bin_nav_dop_packet gps_bin_nav_dop_packet_t; - -typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - uint8_t numCh; //Number of channels - uint8_t globalFlags; - uint16_t reserved2; - -} type_gps_bin_nav_svinfo_part1_packet; - -typedef type_gps_bin_nav_svinfo_part1_packet gps_bin_nav_svinfo_part1_packet_t; - -typedef struct { - uint8_t chn; //Channel number, 255 for SVs not assigned to a channel - uint8_t svid; //Satellite ID - uint8_t flags; - uint8_t quality; - uint8_t cno; //Carrier to Noise Ratio (Signal Strength), dbHz - int8_t elev; //Elevation in integer degrees - int16_t azim; //Azimuth in integer degrees - int32_t prRes; //Pseudo range residual in centimetres - -} type_gps_bin_nav_svinfo_part2_packet; - -typedef type_gps_bin_nav_svinfo_part2_packet gps_bin_nav_svinfo_part2_packet_t; - -typedef struct { - uint8_t ck_a; - uint8_t ck_b; - -} type_gps_bin_nav_svinfo_part3_packet; - -typedef type_gps_bin_nav_svinfo_part3_packet gps_bin_nav_svinfo_part3_packet_t; - - -typedef struct { - uint32_t time_milliseconds; // GPS Millisecond Time of Week - int32_t velN; //NED north velocity, cm/s - int32_t velE; //NED east velocity, cm/s - int32_t velD; //NED down velocity, cm/s - uint32_t speed; //Speed (3-D), cm/s - uint32_t gSpeed; //Ground Speed (2-D), cm/s - int32_t heading; //Heading of motion 2-D, deg, scaling: 1e-5 - uint32_t sAcc; //Speed Accuracy Estimate, cm/s - uint32_t cAcc; //Course / Heading Accuracy Estimate, scaling: 1e-5 - - uint8_t ck_a; - uint8_t ck_b; -} type_gps_bin_nav_velned_packet; - -typedef type_gps_bin_nav_velned_packet gps_bin_nav_velned_packet_t; - -typedef struct { - int32_t time_milliseconds; // Measurement integer millisecond GPS time of week - int16_t week; //Measurement GPS week number - uint8_t numVis; //Number of visible satellites - - //... rest of package is not used in this implementation - -} type_gps_bin_rxm_svsi_packet; - -typedef type_gps_bin_rxm_svsi_packet gps_bin_rxm_svsi_packet_t; - -typedef struct { - uint8_t clsID; - uint8_t msgID; - - uint8_t ck_a; - uint8_t ck_b; -} type_gps_bin_ack_ack_packet; - -typedef type_gps_bin_ack_ack_packet gps_bin_ack_ack_packet_t; - -typedef struct { - uint8_t clsID; - uint8_t msgID; - - uint8_t ck_a; - uint8_t ck_b; -} type_gps_bin_ack_nak_packet; - -typedef type_gps_bin_ack_nak_packet gps_bin_ack_nak_packet_t; - -typedef struct { - uint8_t clsID; - uint8_t msgID; - uint16_t length; - uint8_t portID; - uint8_t res0; - uint16_t res1; - uint32_t mode; - uint32_t baudRate; - uint16_t inProtoMask; - uint16_t outProtoMask; - uint16_t flags; - uint16_t pad; - - uint8_t ck_a; - uint8_t ck_b; -} type_gps_bin_cfg_prt_packet; - -typedef type_gps_bin_cfg_prt_packet type_gps_bin_cfg_prt_packet_t; - -typedef struct { - uint8_t clsID; - uint8_t msgID; - uint16_t length; - uint16_t mask; - uint8_t dynModel; - uint8_t fixMode; - int32_t fixedAlt; - uint32_t fixedAltVar; - int8_t minElev; - uint8_t drLimit; - uint16_t pDop; - uint16_t tDop; - uint16_t pAcc; - uint16_t tAcc; - uint8_t staticHoldThresh; - uint8_t dgpsTimeOut; - uint32_t reserved2; - uint32_t reserved3; - uint32_t reserved4; - - uint8_t ck_a; - uint8_t ck_b; -} type_gps_bin_cfg_nav5_packet; - -typedef type_gps_bin_cfg_nav5_packet type_gps_bin_cfg_nav5_packet_t; - -typedef struct { - uint8_t clsID; - uint8_t msgID; - uint16_t length; - uint8_t msgClass_payload; - uint8_t msgID_payload; - uint8_t rate[6]; - - uint8_t ck_a; - uint8_t ck_b; -} type_gps_bin_cfg_msg_packet; - -typedef type_gps_bin_cfg_msg_packet type_gps_bin_cfg_msg_packet_t; - - -// END the structures of the binary packets -// ************ - -enum UBX_CONFIG_STATE { - UBX_CONFIG_STATE_NONE = 0, - UBX_CONFIG_STATE_PRT = 1, - UBX_CONFIG_STATE_NAV5 = 2, - UBX_CONFIG_STATE_MSG_NAV_POSLLH = 3, - UBX_CONFIG_STATE_MSG_NAV_TIMEUTC = 4, - UBX_CONFIG_STATE_MSG_NAV_DOP = 5, - UBX_CONFIG_STATE_MSG_NAV_SVINFO = 6, - UBX_CONFIG_STATE_MSG_NAV_SOL = 7, - UBX_CONFIG_STATE_MSG_NAV_VELNED = 8, - UBX_CONFIG_STATE_MSG_RXM_SVSI = 9, - UBX_CONFIG_STATE_CONFIGURED = 10 -}; - -enum UBX_MESSAGE_CLASSES { - CLASS_UNKNOWN = 0, - NAV = 1, - RXM = 2, - ACK = 3, - CFG = 4 -}; - -enum UBX_MESSAGE_IDS { - //these numbers do NOT correspond to the message id numbers of the ubx protocol - ID_UNKNOWN = 0, - NAV_POSLLH = 1, - NAV_SOL = 2, - NAV_TIMEUTC = 3, - NAV_DOP = 4, - NAV_SVINFO = 5, - NAV_VELNED = 6, - RXM_SVSI = 7, - CFG_NAV5 = 8, - ACK_ACK = 9, - ACK_NAK = 10 -}; - -enum UBX_DECODE_STATES { - UBX_DECODE_UNINIT = 0, - UBX_DECODE_GOT_SYNC1 = 1, - UBX_DECODE_GOT_SYNC2 = 2, - UBX_DECODE_GOT_CLASS = 3, - UBX_DECODE_GOT_MESSAGEID = 4, - UBX_DECODE_GOT_LENGTH1 = 5, - UBX_DECODE_GOT_LENGTH2 = 6 -}; - -typedef struct { - union { - uint16_t ck; - struct { - uint8_t ck_a; - uint8_t ck_b; - }; - }; - enum UBX_DECODE_STATES decode_state; - bool print_errors; - int16_t rx_count; - uint16_t payload_size; - - enum UBX_MESSAGE_CLASSES message_class; - enum UBX_MESSAGE_IDS message_id; - uint64_t last_message_timestamps[UBX_NO_OF_MESSAGES]; - -} type_gps_bin_ubx_state; - -typedef type_gps_bin_ubx_state gps_bin_ubx_state_t; -#pragma pack(pop) - -extern pthread_mutex_t *ubx_mutex; -extern gps_bin_ubx_state_t *ubx_state; - -void ubx_decode_init(void); - -void ubx_checksum(uint8_t b, uint8_t *ck_a, uint8_t *ck_b); - - - -int ubx_parse(uint8_t b, char *gps_rx_buffer); - -int configure_gps_ubx(int *fd); - -int read_gps_ubx(int *fd, char *gps_rx_buffer, int buffer_size); - -int write_config_message_ubx(const uint8_t *message, const size_t length, const int *fd); - -void calculate_ubx_checksum(uint8_t *message, uint8_t length); - -void *ubx_watchdog_loop(void *args); - -void *ubx_loop(void *args); - - -#endif /* UBX_H_ */ -- cgit v1.2.3 From 3d3a68a7fb8315eb1d28b3f2906bb835f0e72994 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sun, 17 Feb 2013 18:11:33 +0100 Subject: Removed confusing non-error message, updated start scripts to match wiki and most recent SW revs --- ROMFS/scripts/rc.FMU_quad_x | 83 +++++++++++++++++++++++++++--------------- ROMFS/scripts/rc.PX4IO | 87 ++++++++++++++++++++++++--------------------- ROMFS/scripts/rc.PX4IOAR | 36 ++++++++++++++----- apps/commander/commander.c | 3 -- 4 files changed, 129 insertions(+), 80 deletions(-) diff --git a/ROMFS/scripts/rc.FMU_quad_x b/ROMFS/scripts/rc.FMU_quad_x index d9c9a8457..8787443ea 100644 --- a/ROMFS/scripts/rc.FMU_quad_x +++ b/ROMFS/scripts/rc.FMU_quad_x @@ -1,40 +1,67 @@ +#!nsh +# +# Flight startup script for PX4FMU with PWM outputs. +# + +# Disable the USB interface +set USB no + +# Disable autostarting other apps +set MODE custom + +echo "[init] doing PX4FMU Quad startup..." + +# +# Start the ORB # -# Startup for X-quad on FMU1.5/1.6 -# - -echo "[init] uORB" uorb start - -echo "[init] eeprom" -eeprom start -if [ -f /eeprom/parameters ] + +# +# Load microSD params +# +echo "[init] loading microSD params" +param select /fs/microsd/parameters +if [ -f /fs/microsd/parameters ] then - param load + param load /fs/microsd/parameters fi - -echo "[init] sensors" -#bma180 start -#l3gd20 start -mpu6000 start -hmc5883 start -ms5611 start - -sensors start - -echo "[init] mavlink" + +# +# Force some key parameters to sane values +# MAV_TYPE 1 = fixed wing, 2 = quadrotor, 13 = hexarotor +# see https://pixhawk.ethz.ch/mavlink/ +# +param set MAV_TYPE 2 + +# +# Start MAVLink +# mavlink start -d /dev/ttyS0 -b 57600 usleep 5000 - -echo "[init] commander" + +# +# Start the sensors and test them. +# +sh /etc/init.d/rc.sensors + +# +# Start the commander. +# commander start - -echo "[init] attitude control" + +# +# Start the attitude estimator +# attitude_estimator_ekf start -multirotor_att_control start - + echo "[init] starting PWM output" fmu mode_pwm mixer load /dev/pwm_output /etc/mixers/FMU_quad_x.mix - + +# +# Start attitude control +# +multirotor_att_control start + echo "[init] startup done, exiting" -exit +exit \ No newline at end of file diff --git a/ROMFS/scripts/rc.PX4IO b/ROMFS/scripts/rc.PX4IO index 84e181a5a..1e3963b9a 100644 --- a/ROMFS/scripts/rc.PX4IO +++ b/ROMFS/scripts/rc.PX4IO @@ -1,73 +1,80 @@ #!nsh - + +# Disable USB and autostart set USB no - +set MODE camflyer + # -# Start the object request broker +# Start the ORB # uorb start - + # -# Init the EEPROM +# Load microSD params # -echo "[init] eeprom" -eeprom start -if [ -f /eeprom/parameters ] +echo "[init] loading microSD params" +param select /fs/microsd/parameters +if [ -f /fs/microsd/parameters ] then - param load + param load /fs/microsd/parameters fi - -# -# Enable / connect to PX4IO -# -px4io start - + # -# Load an appropriate mixer. FMU_pass.mix is a passthru mixer -# which is good for testing. See ROMFS/mixers for a full list of mixers. +# Force some key parameters to sane values +# MAV_TYPE 1 = fixed wing, 2 = quadrotor, 13 = hexarotor +# see https://pixhawk.ethz.ch/mavlink/ # -mixer load /dev/pwm_output /etc/mixers/FMU_pass.mix - +param set MAV_TYPE 1 + # # Start the sensors. # sh /etc/init.d/rc.sensors - + # -# Start MAVLink on UART1 (dev/ttyS0) at 57600 baud (CLI is now unusable) +# Start MAVLink # -mavlink start -d /dev/ttyS0 -b 57600 +mavlink start -d /dev/ttyS1 -b 57600 usleep 5000 - + # # Start the commander. # commander start - + +# +# Start GPS interface +# +gps start + # # Start the attitude estimator # -attitude_estimator_ekf start - +kalman_demo start + # -# Start the attitude and position controller +# Start PX4IO interface # -fixedwing_att_control start -fixedwing_pos_control start - +px4io start + # -# Start GPS capture. Comment this out if you do not have a GPS. +# Load mixer and start controllers # -gps start - +mixer load /dev/pwm_output /etc/mixers/FMU_Q.mix +control_demo start + +# +# Start logging # -# Start logging to microSD if we can -# -sh /etc/init.d/rc.logging +sdlog start -s 10 # -# startup is done; we don't want the shell because we -# use the same UART for telemetry +# Start system state # -echo "[init] startup done" -exit +if blinkm start +then + echo "using BlinkM for state indication" + blinkm systemstate +else + echo "no BlinkM found, OK." +fi diff --git a/ROMFS/scripts/rc.PX4IOAR b/ROMFS/scripts/rc.PX4IOAR index 640cdf541..72df68e35 100644 --- a/ROMFS/scripts/rc.PX4IOAR +++ b/ROMFS/scripts/rc.PX4IOAR @@ -17,7 +17,7 @@ echo "[init] doing PX4IOAR startup..." uorb start # -# Load microSD params +# Init the parameter storage # echo "[init] loading microSD params" param select /fs/microsd/parameters @@ -27,16 +27,23 @@ then fi # -# Start MAVLink +# Force some key parameters to sane values +# MAV_TYPE 1 = fixed wing, 2 = quadrotor, 13 = hexarotor +# see https://pixhawk.ethz.ch/mavlink/ # -mavlink start -d /dev/ttyS0 -b 57600 -usleep 5000 +param set MAV_TYPE 2 # -# Start the sensors and test them. +# Start the sensors. # sh /etc/init.d/rc.sensors +# +# Start MAVLink +# +mavlink start -d /dev/ttyS0 -b 57600 +usleep 5000 + # # Start the commander. # @@ -62,15 +69,26 @@ multirotor_att_control start # ardrone_interface start -d /dev/ttyS1 +# +# Start GPS capture +# +gps start + # # Start logging # -#sdlog start - +sdlog start -s 10 + # -# Start GPS capture +# Start system state # -gps start +if blinkm start +then + echo "using BlinkM for state indication" + blinkm systemstate +else + echo "no BlinkM found, OK." +fi # # startup is done; we don't want the shell because we diff --git a/apps/commander/commander.c b/apps/commander/commander.c index 6b1bc0f9b..5dfb7a945 100644 --- a/apps/commander/commander.c +++ b/apps/commander/commander.c @@ -1459,9 +1459,6 @@ int commander_thread_main(int argc, char *argv[]) } else { current_status.flag_external_manual_override_ok = true; } - - } else { - warnx("ARMED, rejecting sys type change\n"); } } -- cgit v1.2.3