diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-08-14 14:42:50 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-08-14 14:42:50 +0000 |
commit | aa09e054326770824994f0ee7bb07d3155484337 (patch) | |
tree | b7f43cc028560883de0ec4c9bf58b345dbadb02e | |
parent | a72ff3b651c8b4a13c4791fb1829c94ed0ce88ed (diff) | |
download | px4-firmware-aa09e054326770824994f0ee7bb07d3155484337.tar.gz px4-firmware-aa09e054326770824994f0ee7bb07d3155484337.tar.bz2 px4-firmware-aa09e054326770824994f0ee7bb07d3155484337.zip |
Revise recent changes to serial driver error handling: Errors other than EINTR may be returned when the driver is used very early in initialization. STM32 SPI driver will now survive repeated initializations
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5026 7fd9a85b-ad96-42d3-883c-3090e2eb8679
-rw-r--r-- | nuttx/arch/arm/src/stm32/stm32_spi.c | 51 | ||||
-rw-r--r-- | nuttx/lib/stdio/lib_rawinstream.c | 3 | ||||
-rw-r--r-- | nuttx/lib/stdio/lib_rawoutstream.c | 9 | ||||
-rw-r--r-- | nuttx/lib/stdio/lib_stdoutstream.c | 11 | ||||
-rw-r--r-- | nuttx/lib/stdio/lib_syslogstream.c | 5 |
5 files changed, 48 insertions, 31 deletions
diff --git a/nuttx/arch/arm/src/stm32/stm32_spi.c b/nuttx/arch/arm/src/stm32/stm32_spi.c index 06a994524..40b1a29a0 100644 --- a/nuttx/arch/arm/src/stm32/stm32_spi.c +++ b/nuttx/arch/arm/src/stm32/stm32_spi.c @@ -1368,15 +1368,20 @@ FAR struct spi_dev_s *up_spiinitialize(int port) priv = &g_spi1dev; - /* Configure SPI1 pins: SCK, MISO, and MOSI */ + /* Only configure if the port is not already configured */ - stm32_configgpio(GPIO_SPI1_SCK); - stm32_configgpio(GPIO_SPI1_MISO); - stm32_configgpio(GPIO_SPI1_MOSI); + if ((spi_getreg(priv, STM32_SPI_CR1_OFFSET) & SPI_CR1_SPE) == 0) + { + /* Configure SPI1 pins: SCK, MISO, and MOSI */ + + stm32_configgpio(GPIO_SPI1_SCK); + stm32_configgpio(GPIO_SPI1_MISO); + stm32_configgpio(GPIO_SPI1_MOSI); - /* Set up default configuration: Master, 8-bit, etc. */ + /* Set up default configuration: Master, 8-bit, etc. */ - spi_portinitialize(priv); + spi_portinitialize(priv); + } } else #endif @@ -1387,15 +1392,20 @@ FAR struct spi_dev_s *up_spiinitialize(int port) priv = &g_spi2dev; - /* Configure SPI2 pins: SCK, MISO, and MOSI */ + /* Only configure if the port is not already configured */ + + if ((spi_getreg(priv, STM32_SPI_CR1_OFFSET) & SPI_CR1_SPE) == 0) + { + /* Configure SPI2 pins: SCK, MISO, and MOSI */ - stm32_configgpio(GPIO_SPI2_SCK); - stm32_configgpio(GPIO_SPI2_MISO); - stm32_configgpio(GPIO_SPI2_MOSI); + stm32_configgpio(GPIO_SPI2_SCK); + stm32_configgpio(GPIO_SPI2_MISO); + stm32_configgpio(GPIO_SPI2_MOSI); - /* Set up default configuration: Master, 8-bit, etc. */ + /* Set up default configuration: Master, 8-bit, etc. */ - spi_portinitialize(priv); + spi_portinitialize(priv); + } } else #endif @@ -1406,15 +1416,20 @@ FAR struct spi_dev_s *up_spiinitialize(int port) priv = &g_spi3dev; - /* Configure SPI3 pins: SCK, MISO, and MOSI */ + /* Only configure if the port is not already configured */ + + if ((spi_getreg(priv, STM32_SPI_CR1_OFFSET) & SPI_CR1_SPE) == 0) + { + /* Configure SPI3 pins: SCK, MISO, and MOSI */ - stm32_configgpio(GPIO_SPI3_SCK); - stm32_configgpio(GPIO_SPI3_MISO); - stm32_configgpio(GPIO_SPI3_MOSI); + stm32_configgpio(GPIO_SPI3_SCK); + stm32_configgpio(GPIO_SPI3_MISO); + stm32_configgpio(GPIO_SPI3_MOSI); - /* Set up default configuration: Master, 8-bit, etc. */ + /* Set up default configuration: Master, 8-bit, etc. */ - spi_portinitialize(priv); + spi_portinitialize(priv); + } } #endif diff --git a/nuttx/lib/stdio/lib_rawinstream.c b/nuttx/lib/stdio/lib_rawinstream.c index aacc8f867..9671a2716 100644 --- a/nuttx/lib/stdio/lib_rawinstream.c +++ b/nuttx/lib/stdio/lib_rawinstream.c @@ -69,12 +69,11 @@ static int rawinstream_getc(FAR struct lib_instream_s *this) } /* Return EOF on any failure to read from the incoming byte stream. The - * only expected error is EINTER meaning that the read was interrupted + * only expected error is EINTR meaning that the read was interrupted * by a signal. A Zero return value would indicated an end-of-file * confition. */ - DEBUGASSERT(nwritten == 0 || get_errno() == EINTR); return EOF; } diff --git a/nuttx/lib/stdio/lib_rawoutstream.c b/nuttx/lib/stdio/lib_rawoutstream.c index 6adf9b53d..ed813f87a 100644 --- a/nuttx/lib/stdio/lib_rawoutstream.c +++ b/nuttx/lib/stdio/lib_rawoutstream.c @@ -59,9 +59,11 @@ static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch) DEBUGASSERT(this && rthis->fd >= 0); - /* Loop until the character is successfully transferred */ + /* Loop until the character is successfully transferred or until an + * irrecoverable error occurs. + */ - for (;;) + do { nwritten = write(rthis->fd, &buffer, 1); if (nwritten == 1) @@ -75,8 +77,9 @@ static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch) * from write(). */ - DEBUGASSERT(nwritten < 0 && get_errno() == EINTR); + DEBUGASSERT(nwritten < 0); } + while (get_errno() == EINTR); } /**************************************************************************** diff --git a/nuttx/lib/stdio/lib_stdoutstream.c b/nuttx/lib/stdio/lib_stdoutstream.c index b8dd0bf63..20da5b702 100644 --- a/nuttx/lib/stdio/lib_stdoutstream.c +++ b/nuttx/lib/stdio/lib_stdoutstream.c @@ -58,9 +58,11 @@ static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch) DEBUGASSERT(this && sthis->stream); - /* Loop until the character is successfully transferred */ + /* Loop until the character is successfully transferred or an irrecoverable + * error occurs. + */ - for (;;) + do { result = fputc(ch, sthis->stream); if (result != EOF) @@ -70,11 +72,10 @@ static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch) } /* EINTR (meaning that fputc was interrupted by a signal) is the only - * expected error. + * recoverable error. */ - - DEBUGASSERT(get_errno() == EINTR); } + while (get_errno() == EINTR); } /**************************************************************************** diff --git a/nuttx/lib/stdio/lib_syslogstream.c b/nuttx/lib/stdio/lib_syslogstream.c index 1a47f6abb..7e47d794a 100644 --- a/nuttx/lib/stdio/lib_syslogstream.c +++ b/nuttx/lib/stdio/lib_syslogstream.c @@ -69,7 +69,7 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch) * error occurs. */ - for (;;) + do { /* Write the character to the supported logging device */ @@ -85,9 +85,8 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch) * syslog_putc() was awakened by a signal. This is not a real error and * must be ignored in this context. */ - - DEBUGASSERT(ret == -EINTR); } + while (ret == -EINTR); } /**************************************************************************** |