diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-08-02 00:42:46 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-08-02 00:42:46 +0000 |
commit | 6913926a9621d7aa92c89a44d7946290d299dcde (patch) | |
tree | f5f5fb874369d5379c1bdd728e0789c499e7ce81 /nuttx/drivers | |
parent | 20324504d5997b2ddad85ec3bfa91544c09edd2a (diff) | |
download | px4-firmware-6913926a9621d7aa92c89a44d7946290d299dcde.tar.gz px4-firmware-6913926a9621d7aa92c89a44d7946290d299dcde.tar.bz2 px4-firmware-6913926a9621d7aa92c89a44d7946290d299dcde.zip |
Move RAMLOG driver to drivers/syslog; Add ability to output debug information to any character device or file
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4996 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/drivers')
-rw-r--r-- | nuttx/drivers/Kconfig | 68 | ||||
-rw-r--r-- | nuttx/drivers/Makefile | 5 | ||||
-rw-r--r-- | nuttx/drivers/mtd/Make.defs | 3 | ||||
-rw-r--r-- | nuttx/drivers/syslog/Make.defs | 67 | ||||
-rw-r--r-- | nuttx/drivers/syslog/README.txt | 46 | ||||
-rw-r--r-- | nuttx/drivers/syslog/ramlog.c (renamed from nuttx/drivers/ramlog.c) | 16 | ||||
-rw-r--r-- | nuttx/drivers/syslog/syslog.c | 177 | ||||
-rw-r--r-- | nuttx/drivers/usbhost/Kconfig | 6 |
8 files changed, 308 insertions, 80 deletions
diff --git a/nuttx/drivers/Kconfig b/nuttx/drivers/Kconfig index 17f471bee..6d4c5fc6a 100644 --- a/nuttx/drivers/Kconfig +++ b/nuttx/drivers/Kconfig @@ -29,70 +29,6 @@ config RAMDISK a block driver that can be mounted as a files system. See include/nuttx/ramdisk.h. -config RAMLOG - bool "RAM log message support" - default n - ---help--- - This is a driver that was intended to support debugging output, - aka syslogging, when the normal serial output is not available. - For example, if you are using a telnet or USB serial console, - the debug output will get lost. - - This driver is similar to a pipe in that it saves the debugging - output in a FIFO in RAM. It differs from a pipe in numerous - details as needed to support logging. - -if RAMLOG -config RAMLOG_SYSLOG - bool "Use RAMLOG for SYSLOG" - default n - depends on SYSLOG - ---help--- - Use the RAM logging device for the syslogging interface. If this feature - is enabled (along with SYSLOG), then all debug output (only) will be re-directed - to the circular buffer in RAM. This RAM log can be view from NSH using the - 'dmesg'command. - -config RAMLOG_CONSOLE - bool "Use RAMLOG for /dev/console" - default n - depends on DEV_CONSOLE - ---help--- - Use the RAM logging device as a system console. If this feature is enabled (along - with DEV_CONSOLE), then all console output will be re-directed to a circular - buffer in RAM. This is useful, for example, if the only console is a Telnet - console. Then in that case, console output from non-Telnet threads will go to - the circular buffer and can be viewed using the NSH 'dmesg' command. - -config RAMLOG_CONSOLE_BUFSIZE - int "RAMLOG buffer size" - default 1024 - depends on RAMLOG_SYSLOG || RAMLOG_CONSOLE - ---help--- - Size of the console RAM log. Default: 1024 - -config RAMLOG_CRLF - bool "RAMLOG CR/LF" - default n - ---help--- - Pre-pend a carriage return before every linefeed that goes into the RAM log. - -config RAMLOG_NONBLOCKING - bool "RAMLOG non-block reads" - default y - ---help--- - Reading from the RAMLOG will never block if the RAMLOG is empty. If the RAMLOG - is empty, then zero is returned (usually interpreted as end-of-file). - -config RAMLOG_NPOLLWAITERS - int "RAMLOG number of poll waiters" - default 4 - depends on !DISABLE_POLL - ---help--- - The maximum number of threads that may be waiting on the poll method. - -endif - config CAN bool "CAN support" default n @@ -387,3 +323,7 @@ menuconfig WIRELESS if WIRELESS source drivers/wireless/Kconfig endif + +source drivers/syslog/Kconfig + + diff --git a/nuttx/drivers/Makefile b/nuttx/drivers/Makefile index e32075624..26a2ea992 100644 --- a/nuttx/drivers/Makefile +++ b/nuttx/drivers/Makefile @@ -60,6 +60,7 @@ include power/Make.defs include sensors/Make.defs include sercomm/Make.defs include serial/Make.defs +include syslog/Make.defs include usbdev/Make.defs include usbhost/Make.defs include wireless/Make.defs @@ -71,10 +72,6 @@ ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) CSRCS += ramdisk.c rwbuffer.c endif -ifeq ($(CONFIG_RAMLOG),y) - CSRCS += ramlog.c -endif - ifeq ($(CONFIG_CAN),y) CSRCS += can.c endif diff --git a/nuttx/drivers/mtd/Make.defs b/nuttx/drivers/mtd/Make.defs index 8e2e840f0..866d7c713 100644 --- a/nuttx/drivers/mtd/Make.defs +++ b/nuttx/drivers/mtd/Make.defs @@ -1,6 +1,7 @@ ############################################################################ # drivers/mtd/Make.defs -# This driver supports a block of RAM as a NuttX MTD device +# These driver supports various Memory Technology Devices (MTD) using the +# NuttX MTD interface. # # Copyright (C) 2009-2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt <gnutt@nuttx.org> diff --git a/nuttx/drivers/syslog/Make.defs b/nuttx/drivers/syslog/Make.defs new file mode 100644 index 000000000..9826beb01 --- /dev/null +++ b/nuttx/drivers/syslog/Make.defs @@ -0,0 +1,67 @@ +############################################################################ +# drivers/syslog/Make.defs +# These drivers support system logging devices +# +# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Include SYSLOG drivers (only one should be enabled) + +ifeq ($(CONFIG_SYSLOG),y) + +ifeq ($(CONFIG_SYSLOG_CHAR),y) + CSRCS += syslog.c +endif + +ifeq ($(CONFIG_RAMLOG),y) + CSRCS += ramlog.c +endif + +# Include SYSLOG build support + +DEPPATH += --dep-path syslog +VPATH += :syslog + +else + +# The RAMLOG can be used even if system logging is not enabled. + +ifeq ($(CONFIG_RAMLOG),y) + +# Include RAMLOG build support + +CSRCS += ramlog.c +DEPPATH += --dep-path syslog +VPATH += :syslog + +endif +endif diff --git a/nuttx/drivers/syslog/README.txt b/nuttx/drivers/syslog/README.txt new file mode 100644 index 000000000..c034b49b6 --- /dev/null +++ b/nuttx/drivers/syslog/README.txt @@ -0,0 +1,46 @@ +drivers/syslog README File +========================== + +This README file discusses the SYLOG drivers that can be found in the +drivers/syslog directory. In NuttX, syslog output is equivalent to +debug output and, therefore, the syslogging interfaces are defined in the +header file include/debug.h. + +By default, all system log output goes to console (/dev/console). But that +behavior can be changed by the drivers in this directory. + +ramlog.c +-------- + The RAM logging driver is a driver that was intended to support debugging + output (syslogging) when the normal serial output is not available. For + example, if you are using a telnet or USB serial console, the debug + output will get lost. + + The RAM logging driver is similar to a pipe in that it saves the + debugging output in a FIFO in RAM. It differs from a pipe in numerous + details as needed to support logging. + + This driver is built when CONFIG_RAMLOG is defined in the Nuttx + configuration. + + Configuration options: + + CONFIG_RAMLOG - Enables the RAM logging feature + CONFIG_RAMLOG_CONSOLE - Use the RAM logging device as a system console. + If this feature is enabled (along with CONFIG_DEV_CONSOLE), then all + console output will be re-directed to a circular buffer in RAM. This + is useful, for example, if the only console is a Telnet console. Then + in that case, console output from non-Telnet threads will go to the + circular buffer and can be viewed using the NSH 'dmesg' command. + CONFIG_RAMLOG_SYSLOG - Use the RAM logging device for the syslogging + interface. If this feature is enabled (along with CONFIG_SYSLOG), + then all debug output (only) will be re-directed to the circular + buffer in RAM. This RAM log can be view from NSH using the 'dmesg' + command. + CONFIG_RAMLOG_NPOLLWAITERS - The number of threads than can be waiting + for this driver on poll(). Default: 4 + + If CONFIG_RAMLOG_CONSOLE or CONFIG_RAMLOG_SYSLOG is selected, then the + following may also be provided: + + CONFIG_RAMLOG_CONSOLE_BUFSIZE - Size of the console RAM log. Default: 1024 diff --git a/nuttx/drivers/ramlog.c b/nuttx/drivers/syslog/ramlog.c index 775d03ec8..b3a2ad0f5 100644 --- a/nuttx/drivers/ramlog.c +++ b/nuttx/drivers/syslog/ramlog.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/ramlog.c + * drivers/syslog/ramlog.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> @@ -139,8 +139,8 @@ static const struct file_operations g_ramlogfops = static char g_sysbuffer[CONFIG_RAMLOG_CONSOLE_BUFSIZE]; /* This is the device structure for the console or syslogging function. It - * must be statically initialized because the ramlog_putc function could be - * called before the driver initialization logic executes. + * must be statically initialized because the RAMLOG syslog_putc function + * could be called before the driver initialization logic executes. */ static struct ramlog_dev_s g_sysdev = @@ -705,7 +705,7 @@ int ramlog_consoleinit(void) * * Description: * Create the RAM logging device and register it at the specified path. - * Mostly likely this path will be /dev/syslog + * Mostly likely this path will be CONFIG_RAMLOG_SYSLOG * * If CONFIG_RAMLOG_CONSOLE is also defined, then this functionality is * performed when ramlog_consoleinit() is called. @@ -717,12 +717,12 @@ int ramlog_sysloginit(void) { /* Register the syslog character driver */ - return register_driver("/dev/syslog", &g_ramlogfops, 0666, &g_sysdev); + return register_driver(CONFIG_SYSLOG_DEVPATH, &g_ramlogfops, 0666, &g_sysdev); } #endif /**************************************************************************** - * Name: ramlog + * Name: syslog_putc * * Description: * This is the low-level system logging interface. The debugging/syslogging @@ -730,12 +730,12 @@ int ramlog_sysloginit(void) * the lib_rawprintf() writes to fd=1 (stdout) and lib_lowprintf() uses * a lower level interface that works from interrupt handlers. This * function is a a low-level interface used to implement lib_lowprintf() - * when CONFIG_RAMLOG_SYSLOG=y and CONFIG_SYSLOG=ramlog + * when CONFIG_RAMLOG_SYSLOG=y and CONFIG_SYSLOG=y * ****************************************************************************/ #if defined(CONFIG_RAMLOG_CONSOLE) || defined(CONFIG_RAMLOG_SYSLOG) -int ramlog_putc(int ch) +int syslog_putc(int ch) { FAR struct ramlog_dev_s *priv = &g_sysdev; int ret; diff --git a/nuttx/drivers/syslog/syslog.c b/nuttx/drivers/syslog/syslog.c new file mode 100644 index 000000000..60e9cffcb --- /dev/null +++ b/nuttx/drivers/syslog/syslog.c @@ -0,0 +1,177 @@ +/**************************************************************************** + * drivers/syslog/syslog.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> + +#include <stdint.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> + +#include <nuttx/syslog.h> + +#if defined(CONFIG_SYSLOG) && defined(CONFIG_SYSLOG_CHAR) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct syslog_dev_s +{ + int fd; /* File descriptor of the opened SYSLOG character device */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This is the device structure for the console or syslogging function. It + * must be statically initialized because the RAMLOG syslog_putc function + * could be called before the driver initialization logic executes. + */ + +static struct syslog_dev_s g_sysdev = { -1 }; +static const uint8_t g_syscrlf[2] = { '\r', '\n' }; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: syslog_initialize + * + * Description: + * Initialize to use the character device at CONFIG_SYSLOG_DEVPATH as the + * SYSLOG. + * + ****************************************************************************/ + +int syslog_initialize(void) +{ + /* Has the device been opened yet */ + + if (g_sysdev.fd < 0) + { + /* No, try to open the device now: write-only, try to create it if + * it doesn't exist (it might be a file), if it is a file that already + * exists, then append new log data to the file. + */ + + g_sysdev.fd = open(CONFIG_SYSLOG_DEVPATH, O_WRONLY | O_CREAT | O_APPEND, 0644); + if (g_sysdev.fd < 0) + { + return -get_errno(); + } + } + + /* The SYSLOG device is open and ready for writing. */ + + return OK; +} + +/**************************************************************************** + * Name: syslog_putc + * + * 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 + * a lower level interface that works from interrupt handlers. This + * function is a a low-level interface used to implement lib_lowprintf(). + * + ****************************************************************************/ + +int syslog_putc(int ch) +{ + ssize_t nbytes; + int ret; + + /* Try to initialize the device. We do this repeatedly because the log + * device might be something that was not ready the first time that + * syslog_intialize() was called (such as a USB serial device or a file + * in an NFS mounted file system. + */ + + ret = syslog_initialize(); + if (ret < 0) + { + return ret; + } + + /* Ignore carriage returns */ + + if (ch == '\r') + { + return ch; + } + + /* Pre-pend a newline with a carriage return */ + + if (ch == '\n') + { + nbytes = write(g_sysdev.fd, g_syscrlf, 2); + } + else + { + nbytes = write(g_sysdev.fd, &ch, 1); + } + + if (nbytes < 0) + { + return nbytes; + } + + return ch; +} + +#endif /* CONFIG_SYSLOG && CONFIG_SYSLOG_CHAR */ diff --git a/nuttx/drivers/usbhost/Kconfig b/nuttx/drivers/usbhost/Kconfig index 4d37641f8..35695d750 100644 --- a/nuttx/drivers/usbhost/Kconfig +++ b/nuttx/drivers/usbhost/Kconfig @@ -86,7 +86,7 @@ config HIDKBD_NODEBOUNCE ---help--- If set to y normal debouncing is disabled. Default: Debounce enabled (No repeat keys). - USB host mass storage class driver. Requires CONFIG_USBHOST=y, - config USBHOST_BULK_DISABLE=n, CONFIG_NFILE_DESCRIPTORS > 0, - and CONFIG_SCHED_WORKQUEUE=y + USB host mass storage class driver. Requires USBHOST=y, + config USBHOST_BULK_DISABLE=n, NFILE_DESCRIPTORS > 0, + and SCHED_WORKQUEUE=y endif |