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