diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-05-05 23:17:25 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-05-05 23:17:25 +0000 |
commit | 36f080fa7d94e0d321fbc01a040677d3f625dc73 (patch) | |
tree | 3d90f49b12de4032eef21df067f4d2dff75a3221 | |
parent | 03d9d974b5e930fc9ad158460f1764dbd5d903df (diff) | |
download | px4-firmware-36f080fa7d94e0d321fbc01a040677d3f625dc73.tar.gz px4-firmware-36f080fa7d94e0d321fbc01a040677d3f625dc73.tar.bz2 px4-firmware-36f080fa7d94e0d321fbc01a040677d3f625dc73.zip |
Add GPIO support to STMPE11 driver; NFS update
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4701 7fd9a85b-ad96-42d3-883c-3090e2eb8679
-rw-r--r-- | apps/nshlib/nsh_fscmds.c | 43 | ||||
-rw-r--r-- | nuttx/drivers/input/Make.defs | 3 | ||||
-rw-r--r-- | nuttx/drivers/input/stmpe11.h | 72 | ||||
-rw-r--r-- | nuttx/drivers/input/stmpe11_base.c | 131 | ||||
-rw-r--r-- | nuttx/drivers/input/stmpe11_gpio.c | 437 | ||||
-rw-r--r-- | nuttx/fs/nfs/nfs_mount.h | 2 | ||||
-rw-r--r-- | nuttx/fs/nfs/nfs_socket.c | 21 | ||||
-rw-r--r-- | nuttx/fs/nfs/nfs_vfsops.c | 198 | ||||
-rw-r--r-- | nuttx/fs/nfs/rpc_clnt.c | 52 | ||||
-rw-r--r-- | nuttx/include/nuttx/fs/nfs.h | 4 | ||||
-rw-r--r-- | nuttx/include/nuttx/input/stmpe11.h | 65 |
11 files changed, 817 insertions, 211 deletions
diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c index 28a779292..eefa5e2a4 100644 --- a/apps/nshlib/nsh_fscmds.c +++ b/apps/nshlib/nsh_fscmds.c @@ -1225,7 +1225,6 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) FAR char *address; FAR char *target; FAR char *protocol; - struct sockaddr_in *sin; bool badarg = false; #ifdef CONFIG_NET_IPv6 struct in6_addr inaddr; @@ -1337,35 +1336,25 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return ERROR; } - /* Create an instance of the sockaddr_in state structure */ - - sin = (struct sockaddr_in *)zalloc(sizeof(struct sockaddr_in)); - if (!sin) - { - nsh_output(vtbl, g_fmtcmdoutofmemory, argv[0]); - return -ENOMEM; - } - /* Place all of the NFS arguements into the nfs_args structure */ memset(&data, 0, sizeof(data)); - data.version = NFS_ARGSVERSION; - data.proto = (tcp) ? IPPROTO_TCP : IPPROTO_UDP; - data.sotype = (tcp) ? SOCK_STREAM : SOCK_DGRAM; - sin->sin_family = AF_INET; - sin->sin_port = htons(NFS_PORT); - sin->sin_addr = inaddr; - data.addr = (struct sockaddr *)sin; - data.addrlen = sizeof(struct sockaddr); - data.flags = NFSMNT_NFSV3; - data.retrans = 3; - data.acregmin = 3; - data.acregmax = 60; - data.acdirmin = 30; - data.acdirmax = 60; - data.rsize = 0; - data.wsize = 0; - data.timeo = (tcp) ? 70 : 7; + data.version = NFS_ARGSVERSION; + data.proto = (tcp) ? IPPROTO_TCP : IPPROTO_UDP; + data.sotype = (tcp) ? SOCK_STREAM : SOCK_DGRAM; + data.addr.sin_family = AF_INET; + data.addr.sin_port = htons(NFS_PORT); + data.addr.sin_addr = inaddr; + data.addrlen = sizeof(struct sockaddr); + data.flags = NFSMNT_NFSV3; + data.retrans = 3; + data.acregmin = 3; + data.acregmax = 60; + data.acdirmin = 30; + data.acdirmax = 60; + data.rsize = 0; + data.wsize = 0; + data.timeo = (tcp) ? 70 : 7; /* Perform the mount */ diff --git a/nuttx/drivers/input/Make.defs b/nuttx/drivers/input/Make.defs index ff01217cb..5d8d121db 100644 --- a/nuttx/drivers/input/Make.defs +++ b/nuttx/drivers/input/Make.defs @@ -49,6 +49,9 @@ endif ifeq ($(CONFIG_INPUT_STMPE11),y) CSRCS += stmpe11_base.c +ifneq ($(CONFIG_INPUT_STMPE11_GPIO_DISABLE),y) + CSRCS += stmpe11_gpio.c +endif endif # Include input device driver build support diff --git a/nuttx/drivers/input/stmpe11.h b/nuttx/drivers/input/stmpe11.h index 1ab347191..4bc4ac1d0 100644 --- a/nuttx/drivers/input/stmpe11.h +++ b/nuttx/drivers/input/stmpe11.h @@ -107,28 +107,36 @@ struct stmpe11_dev_s #ifdef CONFIG_STMPE11_MULTIPLE FAR struct stmpe11_dev_s *flink; /* Supports a singly linked list of drivers */ #endif -#ifdef CONFIG_STMPE11_REFCNT - uint8_t crefs; /* Number of times the device has been opened */ -#endif - uint8_t nwaiters; /* Number of threads waiting for STMPE11 data */ - uint8_t inuse; /* SMTPE11 pins in use */ - uint8_t id; /* Current touch point ID (TSC only) */ - uint8_t minor; /* Touchscreen minor device number (TSC only) */ - volatile bool penchange; /* An unreported event is buffered (TSC only) */ - sem_t devsem; /* Manages exclusive access to this structure */ - sem_t waitsem; /* Used to wait for the availability of data */ - uint32_t threshx; /* Thresholded X value (TSC only) */ - uint32_t threshy; /* Thresholded Y value (TSC only) */ + /* Common fields */ + + FAR struct stmpe11_config_s *config; /* Board configuration data */ + sem_t exclsem; /* Manages exclusive access to this structure */ #ifdef CONFIG_STMPE11_SPI FAR struct spi_dev_s *spi; /* Saved SPI driver instance */ #else FAR struct i2c_dev_s *i2c; /* Saved I2C driver instance */ #endif - FAR struct stmpe11_config_s *config; /* Board configuration data (TSC only) */ + uint8_t inuse; /* SMTPE11 pins in use */ + + /* Fields that may be disabled to save size if touchscreen support is not used. */ + +#ifndef CONFIG_STMPE11_TSC_DISABLE +#ifdef CONFIG_STMPE11_REFCNT + uint8_t crefs; /* Number of times the device has been opened */ +#endif + uint8_t nwaiters; /* Number of threads waiting for STMPE11 data */ + uint8_t id; /* Current touch point ID */ + uint8_t minor; /* Touchscreen minor device number */ + volatile bool penchange; /* An unreported event is buffered */ + + uint32_t threshx; /* Thresholded X value */ + uint32_t threshy; /* Thresholded Y value */ + sem_t waitsem; /* Used to wait for the availability of data */ + struct work_s work; /* Supports the interrupt handling "bottom half" */ - struct stmpe11_sample_s sample; /* Last sampled touch point data (TSC only) */ + struct stmpe11_sample_s sample; /* Last sampled touch point data */ /* The following is a list if poll structures of threads waiting for * driver events. The 'struct pollfd' reference for each open is also @@ -138,6 +146,14 @@ struct stmpe11_dev_s #ifndef CONFIG_DISABLE_POLL struct pollfd *fds[CONFIG_STMPE11_NPOLLWAITERS]; #endif +#endif + + /* Fields that may be disabled to save size of GPIO support is not used */ + +#if !defined(CONFIG_STMPE11_GPIO_DISABLE) && !defined(CONFIG_STMPE11_GPIOINT_DISABLE) + bool initialized; /* True if GPIO interrupt subsystem has been initialized */ + stmpe11_handler_t handlers[8]; /* GPIO "interrupt handlers" */ +#endif }; /******************************************************************************************** @@ -152,7 +168,7 @@ struct stmpe11_dev_s * ********************************************************************************************/ -static uint8_t stmpe11_getreg8(FAR struct stmpe11_dev_s *priv, uint8_t regaddr); +uint8_t stmpe11_getreg8(FAR struct stmpe11_dev_s *priv, uint8_t regaddr); /******************************************************************************************** * Name: stmpe11_putreg8 @@ -174,5 +190,31 @@ void stmpe11_putreg8(FAR struct stmpe11_dev_s *priv, uint8_t regaddr, uint8_t re uint16_t stmpe11_getreg16(FAR struct stmpe11_dev_s *priv, uint8_t regaddr); +/******************************************************************************************** + * Name: stmpe11_tscint + * + * Description: + * Handle touchscreen interrupt events (this function actually executes in the context of + * the worker thread). + * + ********************************************************************************************/ + +#ifndef CONFIG_STMPE11_TSC_DISABLE +void stmpe11_tscint(FAR struct stmpe11_dev_s *priv) weak_function; +#endif + +/******************************************************************************************** + * Name: stmpe11_gpioint + * + * Description: + * Handle GPIO interrupt events (this function actually executes in the context of the + * worker thread). + * + ********************************************************************************************/ + +#if !defined(CONFIG_STMPE11_GPIO_DISABLE) && !defined(CONFIG_STMPE11_GPIOINT_DISABLE) +void stmpe11_gpioint(FAR struct stmpe11_dev_s *priv) weak_function; +#endif + #endif /* CONFIG_INPUT && CONFIG_INPUT_STMPE11 */ #endif /* __DRIVERS_INPUT_STMPE11_H */ diff --git a/nuttx/drivers/input/stmpe11_base.c b/nuttx/drivers/input/stmpe11_base.c index 25f6a1e81..bfa1a45b8 100644 --- a/nuttx/drivers/input/stmpe11_base.c +++ b/nuttx/drivers/input/stmpe11_base.c @@ -79,6 +79,122 @@ static struct stmpe11_dev_s *g_stmpe11list; ****************************************************************************/ /**************************************************************************** + * Name: stmpe11_worker + * + * Description: + * This is the "bottom half" of the STMPE11 interrupt handler + * + ****************************************************************************/ + +static void stmpe11_worker(FAR void *arg) +{ + FAR struct stmpe11_dev_s *priv = (FAR struct stmpe11_dev_s *)arg; + uint8_t regval; + + /* Get the globl interrupt status */ + + regval = stmpe11_getreg8(priv, STMPE11_INT_STA); + + /* Check for a touchscreen interrupt */ + +#ifndef CONFIG_STMPE11_TSC_DISABLE + if ((regval & (INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW)) != 0) + { + /* Dispatch the touchscreen interrupt if it was brought into the link */ + + if (stmpe11_tscint) + { + stmpe11_tscint(priv); + } + + stmpe11_putreg8(priv, STMPE11_INT_STA, (INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW)); + regval &= ~(INT_TOUCH_DET|INT_FIFO_TH|INT_FIFO_OFLOW); + } +#endif + +#if !defined(CONFIG_STMPE11_GPIO_DISABLE) && !defined(CONFIG_STMPE11_GPIOINT_DISABLE) + if ((regval & INT_GPIO) != 0) + { + /* Dispatch the GPIO interrupt if it was brought into the link */ + + if (stmpe11_gpioint) + { + stmpe11_gpioint(priv); + } + + stmpe11_putreg8(priv, STMPE11_INT_STA, INT_GPIO); + regval &= ~INT_GPIO; + } +#endif + + /* Clear any other residual, unhandled pending interrupt */ + + if (regval != 0) + { + stmpe11_putreg8(priv, STMPE11_INT_STA, regval); + } + + /* Clear the STMPE11 global interrupt */ + + priv->config->clear(priv->config); +} + +/**************************************************************************** + * Name: stmpe11_interrupt + * + * Description: + * The STMPE11 interrupt handler + * + ****************************************************************************/ + +static int stmpe11_interrupt(int irq, FAR void *context) +{ + FAR struct stmpe11_dev_s *priv; + FAR struct stmpe11_config_s *config; + int ret; + + /* Which STMPE11 device caused the interrupt? */ + +#ifndef CONFIG_STMPE11_MULTIPLE + priv = &g_stmpe11; +#else + for (priv = g_stmpe11list; + priv && priv->configs->irq != irq; + priv = priv->flink); + + ASSERT(priv != NULL); +#endif + + /* Get a pointer the callbacks for convenience (and so the code is not so + * ugly). + */ + + config = priv->config; + DEBUGASSERT(config != NULL); + + /* Disable further interrupts */ + + config->enable(config, false); + + /* Transfer processing to the worker thread. Since STMPE11 interrupts are + * disabled while the work is pending, no special action should be required + * to protected the work queue. + */ + + DEBUGASSERT(priv->work.worker == NULL); + ret = work_queue(&priv->work, stmpe11_worker, priv, 0); + if (ret != 0) + { + illdbg("Failed to queue work: %d\n", ret); + } + + /* Clear any pending interrupts and return success */ + + config->clear(config); + return OK; +} + +/**************************************************************************** * Name: stmpe11_checkid * * Description: @@ -191,6 +307,7 @@ STMPE11_HANDLE stmpe11_instantiate(FAR struct i2c_dev_s *dev, /* Initialize the device state structure */ + sem_init(&priv->exclsem, 0, 1); #ifdef CONFIG_STMPE11_SPI priv->spi = dev; #else @@ -211,6 +328,20 @@ STMPE11_HANDLE stmpe11_instantiate(FAR struct i2c_dev_s *dev, /* Generate STMPE11 Software reset */ stmpe11_reset(priv); + + /* Attach the STMPE11 interrupt handler * yet). + */ + + config->attach(config, stmpe11_interrupt); + + /* Clear any pending interrupts */ + + stmpe11_putreg8(priv, STMPE11_INT_STA, INT_ALL); + config->clear(config); + config->enable(config, true); + + /* Return our private data structure as an opaque handle */ + return (STMPE11_HANDLE)priv; } diff --git a/nuttx/drivers/input/stmpe11_gpio.c b/nuttx/drivers/input/stmpe11_gpio.c new file mode 100644 index 000000000..719c0af7c --- /dev/null +++ b/nuttx/drivers/input/stmpe11_gpio.c @@ -0,0 +1,437 @@ +/**************************************************************************** + * drivers/input/stmpe11_gpio.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * References: + * "STMPE811 S-Touch® advanced resistive touchscreen controller with 8-bit + * GPIO expander," Doc ID 14489 Rev 6, CD00186725, STMicroelectronics" + * + * 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 <errno.h> +#include <debug.h> + +#include <nuttx/input/stmpe11.h> + +#include "stmpe11.h" + +#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_STMPE11) && !defined(CONFIG_STMPE11_GPIO_DISABLE) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stmpe11_gpioinit + * + * Description: + * Initialize the GPIO interrupt subsystem + * + * Input Parameters: + * handle - The handle previously returned by stmpe11_instantiate + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +#ifndef CONFIG_STMPE11_GPIOINT_DISABLE +static inline void stmpe11_gpioinit(FAR struct stmpe11_dev_s *priv) +{ + uint8_t regval; + + if (!priv->initialized) + { + /* Disable all GPIO interrupts */ + + stmpe11_putreg8(priv, STMPE11_GPIO_EN, 0); + + /* Enable global GPIO interrupts */ + + regval = stmpe11_getreg8(priv, STMPE11_INT_EN); + regval |= INT_GPIO; + stmpe11_putreg8(priv, STMPE11_INT_EN, regval); + + priv->initialized = true; + } +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stmpe11_gpioconfig + * + * Description: + * Configure an STMPE11 GPIO pin + * + * Input Parameters: + * handle - The handle previously returned by stmpe11_instantiate + * pinconfig - Bit-encoded pin configuration + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int stmpe11_gpioconfig(STMPE11_HANDLE handle, uint8_t pinconfig) +{ + FAR struct stmpe11_dev_s *priv = (FAR struct stmpe11_dev_s *)handle; + int pin = (pinconfig & STMPE11_GPIO_PIN_MASK) >> STMPE11_GPIO_PIN_SHIFT; + uint8_t pinmask = (1 << pin); + uint8_t regval; + int ret; + + DEBUGASSERT(handle && (unsigned)pin < 8); + + /* Get exclusive access to the device structure */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + int errval = errno; + idbg("sem_wait failed: %d\n", errval); + return -errval; + } + + /* Make sure that the pin is not already in use */ + + if ((priv->inuse & pinmask) != 0) + { + idbg("PIN%d is already in-use\n", pin); + sem_post(&priv->exclsem); + return -EBUSY; + } + + /* Is the pin an input or an output? */ + + if ((pinconfig & STMPE11_GPIO_DIR) == STMPE11_GPIO_OUTPUT) + { + /* The pin is an output */ + + regval = stmpe11_getreg8(priv, STMPE11_GPIO_DIR); + regval &= ~pinmask; + stmpe11_putreg8(priv, STMPE11_GPIO_DIR, regval); + + /* Set its initial output value */ + + stmpe11_gpiowrite(handle, pinconfig, + (pinconfig & STMPE11_GPIO_VALUE) != STMPE11_GPIO_ZERO); + } + else + { + /* It is an input */ + + regval = stmpe11_getreg8(priv, STMPE11_GPIO_DIR); + regval |= pinmask; + stmpe11_putreg8(priv, STMPE11_GPIO_DIR, regval); + + /* Set up the falling edge detection */ + + regval = stmpe11_getreg8(priv, STMPE11_GPIO_FE); + if ((pinconfig & STMPE11_GPIO_FALLING) != 0) + { + regval |= pinmask; + } + else + { + regval &= pinmask; + } + stmpe11_putreg8(priv, STMPE11_GPIO_FE, regval); + + /* Set up the rising edge detection */ + + regval = stmpe11_getreg8(priv, STMPE11_GPIO_RE); + if ((pinconfig & STMPE11_GPIO_FALLING) != 0) + { + regval |= pinmask; + } + else + { + regval &= pinmask; + } + stmpe11_putreg8(priv, STMPE11_GPIO_RE, regval); + + /* Disable interrupts for now */ + + regval = stmpe11_getreg8(priv, STMPE11_GPIO_EN); + regval &= ~pinmask; + stmpe11_putreg8(priv, STMPE11_GPIO_EN, regval); + } + + /* Mark the pin as 'in use' */ + + priv->inuse |= pinmask; + sem_post(&priv->exclsem); + return OK; +} + +/**************************************************************************** + * Name: stmpe11_gpiowrite + * + * Description: + * Set or clear the GPIO output + * + * Input Parameters: + * handle - The handle previously returned by stmpe11_instantiate + * pinconfig - Bit-encoded pin configuration + * value = true: write logic '1'; false: write logic '0; + * + * Returned Value: + * None + * + ****************************************************************************/ + +void stmpe11_gpiowrite(STMPE11_HANDLE handle, uint8_t pinconfig, bool value) +{ + FAR struct stmpe11_dev_s *priv = (FAR struct stmpe11_dev_s *)handle; + int pin = (pinconfig & STMPE11_GPIO_PIN_MASK) >> STMPE11_GPIO_PIN_SHIFT; + int ret; + + DEBUGASSERT(handle && (unsigned)pin < 8); + + /* Get exclusive access to the device structure */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + idbg("sem_wait failed: %d\n", errno); + return; + } + + /* Are we setting or clearing outputs? */ + + if (value) + { + /* Set the output valu(s)e by writing to the SET register */ + + stmpe11_putreg8(priv, STMPE11_GPIO_SETPIN, (1 << pin)); + } + else + { + /* Clear the output value(s) by writing to the CLR register */ + + stmpe11_putreg8(priv, STMPE11_GPIO_CLRPIN, (1 << pin)); + } + + sem_post(&priv->exclsem); +} + +/**************************************************************************** + * Name: stmpe11_gpioread + * + * Description: + * Set or clear the GPIO output + * + * Input Parameters: + * handle - The handle previously returned by stmpe11_instantiate + * pinconfig - Bit-encoded pin configuration + * value - The location to return the state of the GPIO pin + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int stmpe11_gpioread(STMPE11_HANDLE handle, uint8_t pinconfig, bool *value) +{ + FAR struct stmpe11_dev_s *priv = (FAR struct stmpe11_dev_s *)handle; + int pin = (pinconfig & STMPE11_GPIO_PIN_MASK) >> STMPE11_GPIO_PIN_SHIFT; + uint8_t regval; + int ret; + + DEBUGASSERT(handle && (unsigned)pin < 8); + + /* Get exclusive access to the device structure */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + int errval = errno; + idbg("sem_wait failed: %d\n", errval); + return -errval; + } + + regval = stmpe11_getreg8(priv, STMPE11_GPIO_MPSTA); + *value = ((regval & GPIO_PIN(pin)) != 0); + sem_post(&priv->exclsem); + return OK; +} + +/*********************************************************************************** + * Name: stmpe11_gpioattach + * + * Description: + * Attach to a GPIO interrupt input pin and enable interrupts on the pin. Using + * the value NULL for the handler address will disable interrupts from the pin and + * detach the handler. + * + * NOTE: Callbacks do not occur from an interrupt handler but rather from the + * context of the worker thread. + * + * Input Parameters: + * handle - The handle previously returned by stmpe11_instantiate + * pinconfig - Bit-encoded pin configuration + * handler - The handler that will be called when the interrupt occurs. + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. + * + ************************************************************************************/ + +#ifndef CONFIG_STMPE11_GPIOINT_DISABLE +int stmpe11_gpioattach(STMPE11_HANDLE handle, uint8_t pinconfig, + stmpe11_handler_t handler) +{ + FAR struct stmpe11_dev_s *priv = (FAR struct stmpe11_dev_s *)handle; + int pin = (pinconfig & STMPE11_GPIO_PIN_MASK) >> STMPE11_GPIO_PIN_SHIFT; + uint8_t regval; + int ret; + + DEBUGASSERT(handle && (unsigned)pin < 8); + + /* Get exclusive access to the device structure */ + + ret = sem_wait(&priv->exclsem); + if (ret < 0) + { + int errval = errno; + idbg("sem_wait failed: %d\n", errval); + return -errval; + } + + /* Make sure that the GPIO interrupt system has been initialized */ + + stmpe11_gpioinit(priv); + + /* Set/clear the handler */ + + priv->handlers[pin] = handler; + + /* If an handler has provided, then we are enabling interrupts */ + + regval = stmpe11_getreg8(priv, STMPE11_GPIO_EN); + if (handler) + { + /* Enable interrupts for this GPIO */ + + regval &= ~GPIO_PIN(pin); + } + else + { + /* Disable interrupts for this GPIO */ + + regval &= ~GPIO_PIN(pin); + } + stmpe11_putreg8(priv, STMPE11_GPIO_EN, regval); + + sem_post(&priv->exclsem); + return OK; +} +#endif + +/**************************************************************************** + * Name: stmpe11_gpioint + * + * Description: + * Handle GPIO interrupt events (this function actually executes in the + * context of the worker thread). + * + ****************************************************************************/ + +#ifndef CONFIG_STMPE11_GPIOINT_DISABLE +void stmpe11_gpioint(FAR struct stmpe11_dev_s *priv) +{ + uint8_t regval; + uint8_t pinmask; + int pin; + + /* Get the set of pending GPIO interrupts */ + + regval = stmpe11_getreg8(priv, STMPE11_GPIO_INTSTA); + + /* Look at each pin */ + + for (pin = 0; pin < 8; pin++) + { + pinmask = GPIO_INT(pin); + if ((regval & pinmask) != 0) + { + /* Check if we have a handler for this interrupt (there should + * be one) + */ + + if (priv->handlers[pin]) + { + /* Interrupt is pending... dispatch the interrupt to the + * callback + */ + + priv->handlers[pin](pin); + } + else + { + illdbg("No handler for PIN%d, GPIO_INTSTA: %02x\n", pin, regval); + } + + /* Clear the pending GPIO interrupt by writing a '1' to the + * pin position in the status register. + */ + + stmpe11_putreg8(priv, STMPE11_GPIO_INTSTA, pinmask); + } + } +} +#endif + +#endif /* CONFIG_INPUT && CONFIG_INPUT_STMPE11 */ + diff --git a/nuttx/fs/nfs/nfs_mount.h b/nuttx/fs/nfs/nfs_mount.h index bfd5035bd..26b3eb2f9 100644 --- a/nuttx/fs/nfs/nfs_mount.h +++ b/nuttx/fs/nfs/nfs_mount.h @@ -81,7 +81,7 @@ struct nfsmount uint8_t nm_sotype; /* Type of socket */ uint8_t nm_soproto; /* and protocol */ uint8_t nm_soflags; /* pr_flags for socket protocol */ - struct sockaddr *nm_nam; /* Addr of server */ + struct sockaddr nm_nam; /* Addr of server */ int nm_timeo; /* Init timer for NFSMNT_DUMBTIMR */ int nm_retry; /* Max retries */ int nm_srtt[4]; /* Timers for rpcs */ diff --git a/nuttx/fs/nfs/nfs_socket.c b/nuttx/fs/nfs/nfs_socket.c index 0dc8860a0..93e84c0e6 100644 --- a/nuttx/fs/nfs/nfs_socket.c +++ b/nuttx/fs/nfs/nfs_socket.c @@ -145,7 +145,7 @@ int nfs_connect(struct nfsmount *nmp) rpc->rc_authtype = RPCAUTH_NULL; /* for now */ //rpc->rc_servername = nmp->nm_mountp->mnt_stat.f_mntfromname; - rpc->rc_name = nmp->nm_nam; + rpc->rc_name = &nmp->nm_nam; rpc->rc_sotype = nmp->nm_sotype; rpc->rc_soproto = nmp->nm_soproto; @@ -184,30 +184,21 @@ int nfs_request(struct nfsmount *nmp, int procnum, void *datain, void *dataout) { int error; struct rpcclnt *clnt= nmp->nm_rpcclnt; - struct rpc_reply *reply; + struct rpc_reply reply; int trylater_delay; - /* Create an instance of the reply state structure */ - - reply = (struct rpc_reply *)kzalloc(sizeof(struct rpc_reply)); - if (!reply) - { - fdbg("Failed to allocate reply structure\n"); - return -ENOMEM; - } - tryagain: - if ((error = rpcclnt_request(clnt, procnum, reply, datain)) != 0) + if ((error = rpcclnt_request(clnt, procnum, &reply, datain)) != 0) { goto out; } - dataout = &reply->stat.where; + bcopy (dataout, &reply.stat.where, sizeof(reply.stat.where)); - if (reply->rpc_verfi.authtype != 0) + if (reply.rpc_verfi.authtype != 0) { - error = fxdr_unsigned(int, reply->rpc_verfi.authtype); + error = fxdr_unsigned(int, reply.rpc_verfi.authtype); if ((nmp->nm_flag & NFSMNT_NFSV3) && error == NFSERR_TRYLATER) { diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c index ae5ef8585..e0e20839c 100644 --- a/nuttx/fs/nfs/nfs_vfsops.c +++ b/nuttx/fs/nfs/nfs_vfsops.c @@ -185,7 +185,7 @@ nfs_open(FAR struct file *filep, FAR const char *relpath, struct nfsmount *nmp; struct nfsnode *np; struct CREATE3args create; - struct CREATE3resok *resok; + struct CREATE3resok resok; void *datareply; int error = 0; @@ -219,6 +219,8 @@ nfs_open(FAR struct file *filep, FAR const char *relpath, DEBUGASSERT(filep->f_priv == NULL); again: nfsstats.rpccnt[NFSPROC_CREATE]++; + memset(&sp, 0, sizeof(struct nfsv3_sattr)); + memset(&vap, 0, sizeof(struct nfs_fattr)); vap = nmp->nm_head->n_fattr; sp.sa_modetrue = true; sp.sa_mode = txdr_unsigned(vap.fa_mode); @@ -230,6 +232,7 @@ again: sp.sa_atime = vap.fa3_atime; sp.sa_mtime = vap.fa3_mtime; + memset(&create, 0, sizeof(struct CREATE3args)); create.how = sp; create.where.dir = nmp->nm_fh; create.where.name = relpath; @@ -253,14 +256,14 @@ again: * non-zero elements) */ - resok = (struct CREATE3resok *) datareply; + bcopy (datareply, &resok, sizeof(struct CREATE3resok)); np->n_open = true; np->nfsv3_type = NFREG; - np->n_fhp = resok->handle; - np->n_size = fxdr_hyper(&resok->attributes.fa3_size); - np->n_fattr = resok->attributes; - fxdr_nfsv3time(&resok->attributes.fa3_mtime, &np->n_mtime) - np->n_ctime = fxdr_hyper(&resok->attributes.fa3_ctime); + np->n_fhp = resok.handle; + np->n_size = fxdr_hyper(&resok.attributes.fa3_size); + np->n_fattr = resok.attributes; + fxdr_nfsv3time(&resok.attributes.fa3_mtime, &np->n_mtime) + np->n_ctime = fxdr_hyper(&resok.attributes.fa3_ctime); /* Attach the private date to the struct file instance */ @@ -361,7 +364,7 @@ static ssize_t nfs_read(FAR struct file *filep, char *buffer, size_t buflen) uint64_t offset; void *datareply; struct READ3args read; - struct READ3resok *resok; + struct READ3resok resok; uint8_t *userbuffer = (uint8_t*)buffer; int error = 0; int len; @@ -427,6 +430,7 @@ static ssize_t nfs_read(FAR struct file *filep, char *buffer, size_t buflen) nfsstats.rpccnt[NFSPROC_READ]++; again: + memset(&read, 0, sizeof(struct READ3args)); read.file = np->nfsv3_type; read.count = buflen; read.offset = offset; @@ -437,13 +441,13 @@ again: goto errout_with_semaphore; } - resok = (struct READ3resok *) datareply; - eof = resok->eof; + bcopy (datareply, &resok, sizeof(struct READ3resok)); + eof = resok.eof; if (eof == true) { - readsize = resok->count; - np->n_fattr = resok->file_attributes; - memcpy(userbuffer, resok->data, readsize); + readsize = resok.count; + np->n_fattr = resok.file_attributes; + memcpy(userbuffer, resok.data, readsize); } else { @@ -471,7 +475,7 @@ nfs_write(FAR struct file *filep, const char *buffer, size_t buflen) unsigned int writesize; void *datareply; struct WRITE3args write; - struct WRITE3resok *resok; + struct WRITE3resok resok; uint8_t *userbuffer = (uint8_t*)buffer; int error = 0; uint64_t offset; @@ -518,6 +522,7 @@ nfs_write(FAR struct file *filep, const char *buffer, size_t buflen) writesize = 0; nfsstats.rpccnt[NFSPROC_WRITE]++; + memset(&write, 0, sizeof(struct WRITE3args)); write.file = np->nfsv3_type; write.offset = offset; write.count = buflen; @@ -530,16 +535,16 @@ nfs_write(FAR struct file *filep, const char *buffer, size_t buflen) goto errout_with_semaphore; } - resok = (struct WRITE3resok *)datareply; - writesize = resok->count; + bcopy (datareply, &resok, sizeof(struct WRITE3resok)); + writesize = resok.count; if (writesize == 0) { error = NFSERR_IO; goto errout_with_semaphore; } - commit = resok->committed; - np->n_fattr = resok->file_wcc.after; + commit = resok.committed; + np->n_fattr = resok.file_wcc.after; /* Return the lowest committment level obtained by any of the RPCs. */ @@ -555,12 +560,12 @@ nfs_write(FAR struct file *filep, const char *buffer, size_t buflen) if ((nmp->nm_flag & NFSMNT_HASWRITEVERF) == 0) { - bcopy((void*) resok->verf, (void*) nmp->nm_verf, NFSX_V3WRITEVERF); + bcopy((void*) resok.verf, (void*) nmp->nm_verf, NFSX_V3WRITEVERF); nmp->nm_flag |= NFSMNT_HASWRITEVERF; } - else if (strncmp((char*) resok->verf, (char*) nmp->nm_verf, NFSX_V3WRITEVERF)) + else if (strncmp((char*) resok.verf, (char*) nmp->nm_verf, NFSX_V3WRITEVERF)) { - bcopy((void*) resok->verf, (void*) nmp->nm_verf, NFSX_V3WRITEVERF); + bcopy((void*) resok.verf, (void*) nmp->nm_verf, NFSX_V3WRITEVERF); } fxdr_nfsv3time(&np->n_fattr.fa3_mtime, &np->n_mtime) @@ -585,7 +590,7 @@ int nfs_readdirrpc(struct nfsmount *nmp, struct nfsnode *np, int error = 0; void *datareply = NULL; struct READDIR3args readir; - struct READDIR3resok *resok; + struct READDIR3resok resok; /* Loop around doing readdir rpc's of size nm_readdirsize * truncated to a multiple of NFS_READDIRBLKSIZ. @@ -595,6 +600,7 @@ int nfs_readdirrpc(struct nfsmount *nmp, struct nfsnode *np, while (end_of_directory == false) { nfsstats.rpccnt[NFSPROC_READDIR]++; + memset(&readir, 0, sizeof(struct READDIR3args)); readir.dir = np->n_fhp; readir.count = nmp->nm_readdirsize; if (nfsstats.rpccnt[NFSPROC_READDIR] == 1) @@ -619,17 +625,17 @@ int nfs_readdirrpc(struct nfsmount *nmp, struct nfsnode *np, goto nfsmout; } - resok = (struct READDIR3resok*) datareply; - np->n_fattr = resok->dir_attributes; - np->n_cookieverf.nfsuquad[0] = resok->cookieverf.nfsuquad[0]; - np->n_cookieverf.nfsuquad[1] = resok->cookieverf.nfsuquad[1]; - dir->fd_dir.d_type = resok->reply.entries->fileid; - memcpy(&dir->fd_dir.d_name[NAME_MAX], &resok->reply.entries->name, NAME_MAX); + bcopy (datareply, &resok, sizeof(struct READDIR3resok)); + np->n_fattr = resok.dir_attributes; + np->n_cookieverf.nfsuquad[0] = resok.cookieverf.nfsuquad[0]; + np->n_cookieverf.nfsuquad[1] = resok.cookieverf.nfsuquad[1]; + dir->fd_dir.d_type = resok.reply.entries->fileid; + memcpy(&dir->fd_dir.d_name[NAME_MAX], &resok.reply.entries->name, NAME_MAX); //dir->fd_dir.d_name = resok->reply.entries->name;// - dir->u.nfs.cookie[0] = resok->reply.entries->cookie.nfsuquad[0]; - dir->u.nfs.cookie[1] = resok->reply.entries->cookie.nfsuquad[1]; + dir->u.nfs.cookie[0] = resok.reply.entries->cookie.nfsuquad[0]; + dir->u.nfs.cookie[1] = resok.reply.entries->cookie.nfsuquad[1]; - if(resok->reply.eof == true) + if (resok.reply.eof == true) { end_of_directory = true; } @@ -661,7 +667,7 @@ int nfs_readdirrpc(struct nfsmount *nmp, struct nfsnode *np, /* We are now either at the end of the directory */ - if (resok->reply.entries == NULL) + if (resok.reply.entries == NULL) { np->n_direofoffset = fxdr_hyper(&dir->u.nfs.cookie[0]); @@ -1050,6 +1056,8 @@ int mountnfs(struct nfs_args *argp, void **handle) bad: nfs_disconnect(nmp); sem_destroy(&nmp->nm_sem); + kfree(nmp->nm_so); + kfree(nmp->nm_rpcclnt); kfree(nmp); return error; } @@ -1152,6 +1160,8 @@ int nfs_unbind(void *handle, struct inode **blkdriver) nfs_disconnect(nmp); sem_destroy(&nmp->nm_sem); + kfree(nmp->nm_so); + kfree(nmp->nm_rpcclnt); kfree(nmp); return 0; @@ -1170,13 +1180,12 @@ int nfs_unbind(void *handle, struct inode **blkdriver) static int nfs_statfs(struct inode *mountpt, struct statfs *sbp) { - struct nfs_statfs *sfp; + struct nfs_statfs sfp; struct nfsmount *nmp; int error = 0; uint64_t tquad; void *datareply; struct FSSTAT3args fsstat; - int info_v3; /* Sanity checks */ @@ -1185,7 +1194,6 @@ static int nfs_statfs(struct inode *mountpt, struct statfs *sbp) /* Get the mountpoint private data from the inode structure */ nmp = (struct nfsmount*)mountpt->i_private; - info_v3 = (nmp->nm_flag & NFSMNT_NFSV3); /* Check if the mount is still healthy */ @@ -1202,12 +1210,13 @@ static int nfs_statfs(struct inode *mountpt, struct statfs *sbp) memset(sbp, 0, sizeof(struct statfs)); sbp->f_type = NFS_SUPER_MAGIC; - if (info_v3 && (nmp->nm_flag & NFSMNT_GOTFSINFO) == 0) + if ((nmp->nm_flag & NFSMNT_GOTFSINFO) == 0) { (void)nfs_fsinfo(mountpt, NULL, NULL); } nfsstats.rpccnt[NFSPROC_FSSTAT]++; + memset(&fsstat, 0, sizeof(struct FSSTAT3args)); fsstat.fsroot = nmp->nm_fh; error = nfs_request(nmp, NFSPROC_FSSTAT, &fsstat, datareply); if (error) @@ -1215,33 +1224,20 @@ static int nfs_statfs(struct inode *mountpt, struct statfs *sbp) goto errout_with_semaphore; } - sfp = (struct nfs_statfs *)datareply; - nmp->nm_head->n_fattr = sfp->obj_attributes; - if (info_v3) - { - sbp->f_bsize = NFS_FABLKSIZE; - tquad = fxdr_hyper(&sfp->sf_tbytes); - sbp->f_blocks = tquad / (uint64_t) NFS_FABLKSIZE; - tquad = fxdr_hyper(&sfp->sf_fbytes); - sbp->f_bfree = tquad / (uint64_t) NFS_FABLKSIZE; - tquad = fxdr_hyper(&sfp->sf_abytes); - sbp->f_bavail = tquad / (uint64_t) NFS_FABLKSIZE; - - tquad = fxdr_hyper(&sfp->sf_tfiles); - sbp->f_files = tquad; - tquad = fxdr_hyper(&sfp->sf_ffiles); - sbp->f_ffree = tquad; - sbp->f_namelen = NAME_MAX; - } - else - { - sbp->f_bsize = fxdr_unsigned(int32_t, sfp->sf_bsize); - sbp->f_blocks = fxdr_unsigned(int32_t, sfp->sf_blocks); - sbp->f_bfree = fxdr_unsigned(int32_t, sfp->sf_bfree); - sbp->f_bavail = fxdr_unsigned(int32_t, sfp->sf_bavail); - sbp->f_files = 0; - sbp->f_ffree = 0; - } + bcopy (datareply, &sfp, sizeof(struct nfs_statfs)); + nmp->nm_head->n_fattr = sfp.obj_attributes; + sbp->f_bsize = NFS_FABLKSIZE; + tquad = fxdr_hyper(&sfp.sf_tbytes); + sbp->f_blocks = tquad / (uint64_t) NFS_FABLKSIZE; + tquad = fxdr_hyper(&sfp.sf_fbytes); + sbp->f_bfree = tquad / (uint64_t) NFS_FABLKSIZE; + tquad = fxdr_hyper(&sfp.sf_abytes); + sbp->f_bavail = tquad / (uint64_t) NFS_FABLKSIZE; + tquad = fxdr_hyper(&sfp.sf_tfiles); + sbp->f_files = tquad; + tquad = fxdr_hyper(&sfp.sf_ffiles); + sbp->f_ffree = tquad; + sbp->f_namelen = NAME_MAX; errout_with_semaphore: nfs_semgive(nmp); @@ -1261,7 +1257,7 @@ static int nfs_remove(struct inode *mountpt, const char *relpath) struct nfsnode *np; void *datareply; struct REMOVE3args remove; - struct REMOVE3resok *resok; + struct REMOVE3resok resok; int error = 0; /* Sanity checks */ @@ -1295,6 +1291,7 @@ static int nfs_remove(struct inode *mountpt, const char *relpath) /* Do the rpc */ nfsstats.rpccnt[NFSPROC_REMOVE]++; + memset(&remove, 0, sizeof(struct REMOVE3args)); remove.object.dir = np->n_fhp; remove.object.name = relpath; @@ -1316,8 +1313,8 @@ static int nfs_remove(struct inode *mountpt, const char *relpath) goto errout_with_semaphore; } - resok = (struct REMOVE3resok *)datareply; - np->n_fattr = resok->dir_wcc.after; + bcopy (datareply, &resok, sizeof(struct REMOVE3resok)); + np->n_fattr = resok.dir_wcc.after; np->n_flag |= NMODIFIED; } NFS_INVALIDATE_ATTRCACHE(np); @@ -1336,12 +1333,12 @@ errout_with_semaphore: static int nfs_mkdir(struct inode *mountpt, const char *relpath, mode_t mode) { - struct nfs_fattr *vap; +//struct nfs_fattr *vap; struct nfsv3_sattr sp; struct nfsmount *nmp; struct nfsnode *np; struct MKDIR3args mkir; - struct MKDIR3resok *resok; + struct MKDIR3resok resok; void *datareply; int error = 0; @@ -1365,18 +1362,6 @@ static int nfs_mkdir(struct inode *mountpt, const char *relpath, mode_t mode) goto errout_with_semaphore; } - /* Create an instance of the private data to describe the opened - * file. - */ - - vap = (struct nfs_fattr*)kzalloc(sizeof(struct nfs_fattr)); - if (!vap) - { - fdbg("Failed to allocate private data\n", error); - error = -ENOMEM; - goto errout_with_semaphore; - } - /* Check if the mount is still healthy */ nfs_semtake(nmp); @@ -1387,19 +1372,20 @@ static int nfs_mkdir(struct inode *mountpt, const char *relpath, mode_t mode) } nfsstats.rpccnt[NFSPROC_MKDIR]++; + memset(&mkir, 0, sizeof(struct MKDIR3args)); mkir.where.dir = nmp->nm_fh; mkir.where.name = relpath; sp.sa_modetrue = nfs_true; - sp.sa_mode = txdr_unsigned(vap->fa_mode); + sp.sa_mode = txdr_unsigned(mode); sp.sa_uidfalse = nfs_xdrneg1; sp.sa_gidfalse = nfs_xdrneg1; sp.sa_sizefalse = nfs_xdrneg1; sp.sa_atimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); sp.sa_mtimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); -//fxdr_nfsv3time2(vap->fa3_atime, &sp.sa_atime); -//fxdr_nfsv3time2(vap->fa3_mtime, &sp.sa_mtime); + memset(&sp.sa_atime, 0, sizeof(nfstime3)); + memset(&sp.sa_mtime, 0, sizeof(nfstime3)); mkir.attributes = sp; @@ -1409,10 +1395,10 @@ static int nfs_mkdir(struct inode *mountpt, const char *relpath, mode_t mode) goto errout_with_semaphore; } - resok = (struct MKDIR3resok *) datareply; + bcopy (datareply, &resok, sizeof(struct MKDIR3resok)); np->nfsv3_type = NFDIR; - np->n_fhp = resok->handle; - np->n_fattr = resok->obj_attributes; + np->n_fhp = resok.handle; + np->n_fattr = resok.obj_attributes; np->n_flag |= NMODIFIED; nmp->nm_head = np; @@ -1436,7 +1422,7 @@ static int nfs_rmdir(struct inode *mountpt, const char *relpath) struct nfsmount *nmp; struct nfsnode *np; struct RMDIR3args rmdir; - struct RMDIR3resok *resok; + struct RMDIR3resok resok; void *datareply; int error = 0; @@ -1466,6 +1452,7 @@ static int nfs_rmdir(struct inode *mountpt, const char *relpath) /* Do the rpc */ nfsstats.rpccnt[NFSPROC_RMDIR]++; + memset(&rmdir, 0, sizeof(struct RMDIR3args)); rmdir.object.dir = np->n_fhp; rmdir.object.name = relpath; error = nfs_request(nmp, NFSPROC_RMDIR, &rmdir, datareply); @@ -1480,8 +1467,8 @@ static int nfs_rmdir(struct inode *mountpt, const char *relpath) goto errout_with_semaphore; } - resok = (struct RMDIR3resok *)datareply; - np->n_fattr = resok->dir_wcc.after; + bcopy (datareply, &resok, sizeof(struct RMDIR3resok)); + np->n_fattr = resok.dir_wcc.after; np->n_flag |= NMODIFIED; } @@ -1506,7 +1493,7 @@ static int nfs_rename(struct inode *mountpt, const char *oldrelpath, struct nfsnode *np; void *datareply; struct RENAME3args rename; - struct RENAME3resok *resok; + struct RENAME3resok resok; int error = 0; /* Sanity checks */ @@ -1535,6 +1522,7 @@ static int nfs_rename(struct inode *mountpt, const char *oldrelpath, } nfsstats.rpccnt[NFSPROC_RENAME]++; + memset(&rename, 0, sizeof(struct RENAME3args)); rename.from.dir = np->n_fhp; rename.from.name = oldrelpath; rename.to.dir = np->n_fhp; @@ -1554,8 +1542,8 @@ static int nfs_rename(struct inode *mountpt, const char *oldrelpath, goto errout_with_semaphore; } - resok = (struct RENAME3resok *) datareply; - np->n_fattr = resok->todir_wcc.after; + bcopy (datareply, &resok, sizeof(struct RENAME3resok)); + np->n_fattr = resok.todir_wcc.after; np->n_flag |= NMODIFIED; NFS_INVALIDATE_ATTRCACHE(np); @@ -1573,7 +1561,7 @@ errout_with_semaphore: static int nfs_fsinfo(struct inode *mountpt, const char *relpath, struct stat *buf) { - struct nfsv3_fsinfo *fsp; + struct nfsv3_fsinfo fsp; struct FSINFOargs fsinfo; struct nfsmount *nmp; uint32_t pref, max; @@ -1606,15 +1594,15 @@ static int nfs_fsinfo(struct inode *mountpt, const char *relpath, struct stat *b goto errout_with_semaphore; } - fsp = (struct nfsv3_fsinfo *)datareply; - nmp->nm_head->n_fattr = fsp->obj_attributes; - pref = fxdr_unsigned(uint32_t, fsp->fs_wtpref); + bcopy (datareply, &fsp, sizeof(struct nfsv3_fsinfo)); + nmp->nm_head->n_fattr = fsp.obj_attributes; + pref = fxdr_unsigned(uint32_t, fsp.fs_wtpref); if (pref < nmp->nm_wsize) { nmp->nm_wsize = (pref + NFS_FABLKSIZE - 1) & ~(NFS_FABLKSIZE - 1); } - max = fxdr_unsigned(uint32_t, fsp->fs_wtmax); + max = fxdr_unsigned(uint32_t, fsp.fs_wtmax); if (max < nmp->nm_wsize) { nmp->nm_wsize = max & ~(NFS_FABLKSIZE - 1); @@ -1622,13 +1610,13 @@ static int nfs_fsinfo(struct inode *mountpt, const char *relpath, struct stat *b nmp->nm_wsize = max; } - pref = fxdr_unsigned(uint32_t, fsp->fs_rtpref); + pref = fxdr_unsigned(uint32_t, fsp.fs_rtpref); if (pref < nmp->nm_rsize) { nmp->nm_rsize = (pref + NFS_FABLKSIZE - 1) & ~(NFS_FABLKSIZE - 1); } - max = fxdr_unsigned(uint32_t, fsp->fs_rtmax); + max = fxdr_unsigned(uint32_t, fsp.fs_rtmax); if (max < nmp->nm_rsize) { nmp->nm_rsize = max & ~(NFS_FABLKSIZE - 1); @@ -1638,7 +1626,7 @@ static int nfs_fsinfo(struct inode *mountpt, const char *relpath, struct stat *b } } - pref = fxdr_unsigned(uint32_t, fsp->fs_dtpref); + pref = fxdr_unsigned(uint32_t, fsp.fs_dtpref); if (pref < nmp->nm_readdirsize) { nmp->nm_readdirsize = (pref + NFS_DIRBLKSIZ - 1) & ~(NFS_DIRBLKSIZ - 1); @@ -1653,13 +1641,13 @@ static int nfs_fsinfo(struct inode *mountpt, const char *relpath, struct stat *b } } - buf->st_mode = fxdr_hyper(&fsp->obj_attributes.fa_mode); - buf->st_size = fxdr_hyper(&fsp->obj_attributes.fa3_size); + buf->st_mode = fxdr_hyper(&fsp.obj_attributes.fa_mode); + buf->st_size = fxdr_hyper(&fsp.obj_attributes.fa3_size); buf->st_blksize = 0; buf->st_blocks = 0; - buf->st_mtime = fxdr_hyper(&fsp->obj_attributes.fa3_mtime); - buf->st_atime = fxdr_hyper(&fsp->obj_attributes.fa3_atime); - buf->st_ctime = fxdr_hyper(&fsp->obj_attributes.fa3_ctime); + buf->st_mtime = fxdr_hyper(&fsp.obj_attributes.fa3_mtime); + buf->st_atime = fxdr_hyper(&fsp.obj_attributes.fa3_atime); + buf->st_ctime = fxdr_hyper(&fsp.obj_attributes.fa3_ctime); nmp->nm_flag |= NFSMNT_GOTFSINFO; errout_with_semaphore: diff --git a/nuttx/fs/nfs/rpc_clnt.c b/nuttx/fs/nfs/rpc_clnt.c index a7e7f5a1c..af14d69a9 100644 --- a/nuttx/fs/nfs/rpc_clnt.c +++ b/nuttx/fs/nfs/rpc_clnt.c @@ -194,8 +194,8 @@ static uint32_t rpcclnt_xid = 0; static uint32_t rpcclnt_xid_touched = 0; int rpcclnt_ticks; struct rpcstats rpcstats; -struct rpc_call *callmgs; -struct rpc_reply *replymsg; +//struct rpc_call *callmgs; +//struct rpc_reply *replymsg; /* Queue head for rpctask's */ @@ -223,7 +223,7 @@ static int rpcclnt_sigintr(struct rpcclnt *, struct rpctask *, cthread_t *); static void rpcclnt_softterm(struct rpctask *task); static uint32_t rpcclnt_proct(struct rpcclnt *, uint32_t); -static int rpcclnt_buildheader(struct rpcclnt *, int, int, void *, struct rpc_call *); +static int rpcclnt_buildheader(struct rpcclnt *, int, void *, struct rpc_call *); /**************************************************************************** * Private Functions @@ -293,9 +293,7 @@ rpcclnt_send(struct socket *so, struct sockaddr *nam, struct rpc_call *call, flags = 0; } - error = - psock_sendto(so, call, sizeof(*call), flags, sendnam, sizeof(*sendnam)); - + error = psock_sendto(so, call, sizeof(*call), flags, sendnam, sizeof(*sendnam)); if (error != 0) { if (rep != NULL) @@ -567,7 +565,7 @@ static int rpcclnt_receive(struct rpctask *rep, struct sockaddr *aname, */ static int -rpcclnt_reply(struct rpctask *myrep, struct rpc_call *call, +rpcclnt_reply(struct rpctask *myrep, struct rpc_call *call, //Here we need to make changes for debugging struct rpc_reply *reply) { struct rpctask *rep; @@ -624,7 +622,6 @@ rpcclnt_reply(struct rpctask *myrep, struct rpc_call *call, rxid = reply->rp_xid; - /* if (reply->rp_direction != rpc_reply) { rpcstats.rpcinvalid++; @@ -635,7 +632,6 @@ rpcclnt_reply(struct rpctask *myrep, struct rpc_call *call, continue; } - */ /* Loop through the request list to match up the reply Iff no * match, just drop the datagram @@ -956,7 +952,8 @@ int rpcclnt_connect(struct rpcclnt *rpc) /* Create the socket */ saddr = rpc->rc_name; - + memset(&sin, 0, sizeof(sin)); + /* Create an instance of the socket state structure */ so = (struct socket *)kzalloc(sizeof(struct socket)); @@ -965,7 +962,7 @@ int rpcclnt_connect(struct rpcclnt *rpc) fdbg("Failed to allocate socket structure\n"); return -ENOMEM; } - + error = psock_socket(saddr->sa_family, rpc->rc_sotype, rpc->rc_soproto, so); @@ -1103,7 +1100,6 @@ void rpcclnt_disconnect(struct rpcclnt *rpc) if (rpc->rc_so != NULL) { so = rpc->rc_so; - rpc->rc_so = NULL; (void)psock_close(so); } } @@ -1126,10 +1122,7 @@ void rpcclnt_safedisconnect(struct rpcclnt *rpc) /* Code from nfs_request - goes something like this - fill in task struct - * links task into list - calls nfs_send() for first transmit - calls * nfs_receive() to get reply - fills in reply (which should be initialized - * prior to calling), which is valid when 0 is returned and is NEVER freed in - * this function - * - * always frees the request header, but NEVER frees 'mrest' + * prior to calling), which is valid when 0. * * note that reply->result_* are invalid unless reply->type == * RPC_MSGACCEPTED and reply->status == RPC_SUCCESS and that reply->verf_* @@ -1152,7 +1145,7 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, struct rpc_reply *reply, v fdbg("Failed to allocate call msg structure\n"); return -ENOMEM; } - + /* Create an instance of the reply state structure */ replysvr = (struct rpc_reply *)kzalloc(sizeof(struct rpc_reply)); @@ -1161,7 +1154,7 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, struct rpc_reply *reply, v fdbg("Failed to allocate reply msg structure\n"); return -ENOMEM; } - + /* Create an instance of the task state structure */ task = (struct rpctask *)kzalloc(sizeof(struct rpctask)); @@ -1170,16 +1163,16 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, struct rpc_reply *reply, v fdbg("Failed to allocate reply msg structure\n"); return -ENOMEM; } - - error = rpcclnt_buildheader(rpc, procnum, xid, datain, callhost); + + error = rpcclnt_buildheader(rpc, procnum, datain, callhost); if (error) { ndbg("building call header error"); goto rpcmout; } - task->r_rpcclnt = rpc; - task->r_xid = fxdr_unsigned(uint32_t,xid); + task->r_rpcclnt = rpc; + task->r_xid = callhost->rp_xid; task->r_procnum = procnum; if (rpc->rc_flag & RPCCLNT_SOFT) @@ -1210,7 +1203,7 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, struct rpc_reply *reply, v * LAST so timer finds oldest requests first. */ - dq_addlast((struct dq_entry_t *)task, &rpctask_q); + dq_addlast(&task->r_chain, &rpctask_q); /* If backing off another request or avoiding congestion, don't send * this one now but let timer do it. If not timing a request, do it @@ -1260,7 +1253,7 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, struct rpc_reply *reply, v /* RPC done, unlink the request. */ - dq_rem((struct dq_entry_t *)task, &rpctask_q); + dq_rem(&task->r_chain, &rpctask_q); /* Decrement the outstanding request count. */ @@ -1277,6 +1270,7 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, struct rpc_reply *reply, v /* Break down the rpc header and check if ok */ + memset(reply, 0, sizeof(rpc_reply)); reply->stat.type = fxdr_unsigned(uint32_t, replysvr->stat.type); if (reply->stat.type == RPC_MSGDENIED) { @@ -1320,7 +1314,7 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, struct rpc_reply *reply, v if (reply->stat.status == RPC_SUCCESS) { nvdbg("RPC_SUCCESS"); - + reply->stat.where = replysvr->stat.where; } else if (reply->stat.status == RPC_PROGMISMATCH) @@ -1340,6 +1334,9 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, struct rpc_reply *reply, v } rpcmout: + kfree(callhost); + kfree(replysvr); + kfree(task); RPC_RETURN(error); } @@ -1482,12 +1479,13 @@ void rpcclnt_timer(void *arg, struct rpc_call *call) /* Build the RPC header and fill in the authorization info. */ int rpcclnt_buildheader(struct rpcclnt *rpc, int procid, - int xidp, void *datain, struct rpc_call *call) + void *datain, struct rpc_call *call) { #ifdef CONFIG_NFS_UNIX_AUTH struct timeval tv; #endif srand(time(NULL)); + int xidp = 0; /* The RPC header.*/ @@ -1509,7 +1507,7 @@ int rpcclnt_buildheader(struct rpcclnt *rpc, int procid, rpcclnt_xid += xidp; } - call->rp_xid = xidp = txdr_unsigned(rpcclnt_xid); + call->rp_xid = txdr_unsigned(rpcclnt_xid); call->rp_direction = rpc_call; call->rp_rpcvers = rpc_vers; call->rp_prog = txdr_unsigned(rpc->rc_prog->prog_id); diff --git a/nuttx/include/nuttx/fs/nfs.h b/nuttx/include/nuttx/fs/nfs.h index 977736390..423c212e6 100644 --- a/nuttx/include/nuttx/fs/nfs.h +++ b/nuttx/include/nuttx/fs/nfs.h @@ -47,6 +47,8 @@ * Included Files ****************************************************************************/ +#include <sys/socket.h> + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -109,7 +111,7 @@ typedef union nfsfh nfsfh_t; struct nfs_args { uint8_t version; /* args structure version number */ - struct sockaddr *addr; /* file server address */ + struct sockaddr addr; /* file server address */ uint8_t addrlen; /* length of address */ uint8_t sotype; /* Socket type */ uint8_t proto; /* and Protocol */ diff --git a/nuttx/include/nuttx/input/stmpe11.h b/nuttx/include/nuttx/input/stmpe11.h index e833b3ebd..5bf79e8cd 100644 --- a/nuttx/include/nuttx/input/stmpe11.h +++ b/nuttx/include/nuttx/input/stmpe11.h @@ -221,7 +221,7 @@ #define INT_TEMP_SENS (1 << 5) /* Bit 5: Temperature threshold triggering */ #define INT_ADC (1 << 6) /* Bit 6: Any enabled ADC interrupts */ #define INT_GPIO (1 << 7) /* Bit 7: Any enabled GPIO interrupts */ - +#define INT_ALL 0xff /* GPIO interrupt enable/status register */ @@ -349,31 +349,33 @@ * * 7654 3210 * ---- ---- - * MIRF VPPP + * DIRF VPPP * * Input Pins: 1IRF .PPP * - * Output Pins: 0.RF VPPP + * Output Pins: 0... VPPP * * Bits 7 is the pin direction. */ +#define STMPE11_GPIO_DIR (1 << 7) /* Bit7: Direction bit */ #define STMPE11_GPIO_INPUT (1 << 7) /* Input pin (possibly interrupting) */ -#define STMPE11_GPIO_INPUT (0) /* Configure as in input pin (possibly interrupting) */ +#define STMPE11_GPIO_OUTPUT (0) /* Configure as in output */ /* Bit 6 indicates that the pin will generate an interrupt (inputs only) */ -#define STMPE11_GPIO_IN (1 << 6) /* Input interrupting pin */ +#define STMPE11_GPIO_IN (1 << 6) /* Bit 6: Input interrupting pin */ /* The bits 4-5 select the rising and/or the falling edge detection. */ -#define STMPE11_GPIO_RISING (1 << 5) /* Input interrupting pin */ -#define STMPE11_GPIO_FALLING (1 << 4) /* Input interrupting pin */ +#define STMPE11_GPIO_RISING (1 << 5) /* Bit 5: Input interrupting pin */ +#define STMPE11_GPIO_FALLING (1 << 4) /* Bit 4: Input interrupting pin */ /* Bit 3 is the initial value for output pins */ -#define STMPE11_GPIO_ONE (1 << 3) /* The initial value is logic 1 */ -#define STMPE11_GPIO_ZERO (0) /* The initial value is logic 0 */ +#define STMPE11_GPIO_VALUE (1 << 3) /* Bit 3: The initial value of an output pin */ +# define STMPE11_GPIO_ONE (1 << 3) /* Bit 3: The initial value is logic 1 */ +# define STMPE11_GPIO_ZERO (0) /* Bit 3: The initial value is logic 0 */ /* Bits 0-2 is the pin number */ @@ -391,6 +393,13 @@ /******************************************************************************************** * Public Types ********************************************************************************************/ + +/* Form of the GPIO "interrupt handler" callback. Callbacks do not occur from an interrupt + * handler but rather from the context of the worker thread with interrupts enabled. + */ + +typedef void (*stmpe11_handler_t)(int pin); + /* A reference to a structure of this type must be passed to the STMPE11 driver when the * driver is instantiaed. This structure provides information about the configuration of the * STMPE11 and provides some board-specific hooks. @@ -432,12 +441,14 @@ struct stmpe11_config_s int (*attach)(FAR struct stmpe11_config_s *state, xcpt_t isr); void (*enable)(FAR struct stmpe11_config_s *state, bool enable); void (*clear)(FAR struct stmpe11_config_s *state); +#ifndef CONFIG_STMPE11_TSC_DISABLE bool (*pendown)(FAR struct stmpe11_config_s *state); +#endif }; /* Since the STMPE11 is a multi-function device, no functionality is assumed when the device * is first created. Rather, a multi-step initialization is required. When - * stmpe11_register is called, it returns a handle of the following type. That handle may + * stmpe11_instantiate is called, it returns a handle of the following type. That handle may * then be used to enable a configure the STMPE11 functionality. */ @@ -487,7 +498,7 @@ EXTERN STMPE11_HANDLE stmpe11_instantiate(FAR struct i2c_dev_s *dev, * touchsceen driver as /dev/inputN where N is the minor device number * * Input Parameters: - * handle - The handle previously returned by stmpe11_register + * handle - The handle previously returned by stmpe11_instantiate * minor - The input device minor number * * Returned Value: @@ -496,7 +507,9 @@ EXTERN STMPE11_HANDLE stmpe11_instantiate(FAR struct i2c_dev_s *dev, * ********************************************************************************************/ +#ifndef CONFIG_STMPE11_TSC_DISABLE EXTERN int stmpe11_register(STMPE11_HANDLE handle, int minor); +#endif /******************************************************************************************** * Name: stmpe11_gpioconfig @@ -505,7 +518,7 @@ EXTERN int stmpe11_register(STMPE11_HANDLE handle, int minor); * Configure an STMPE11 GPIO pin * * Input Parameters: - * handle - The handle previously returned by stmpe11_register + * handle - The handle previously returned by stmpe11_instantiate * pinconfig - Bit-encoded pin configuration * * Returned Value: @@ -514,7 +527,9 @@ EXTERN int stmpe11_register(STMPE11_HANDLE handle, int minor); * ********************************************************************************************/ +#ifndef CONFIG_STMPE11_GPIO_DISABLE EXTERN int stmpe11_gpioconfig(STMPE11_HANDLE handle, uint8_t pinconfig); +#endif /******************************************************************************************** * Name: stmpe11_gpiowrite @@ -523,17 +538,18 @@ EXTERN int stmpe11_gpioconfig(STMPE11_HANDLE handle, uint8_t pinconfig); * Set or clear the GPIO output * * Input Parameters: - * handle - The handle previously returned by stmpe11_register + * handle - The handle previously returned by stmpe11_instantiate * pinconfig - Bit-encoded pin configuration * value = true: write logic '1'; false: write logic '0; * * Returned Value: - * Zero is returned on success. Otherwise, a negated errno value is returned to indicate - * the nature of the failure. + * None * ********************************************************************************************/ -EXTERN int stmpe11_gpiowrite(STMPE11_HANDLE handle, uint8_t pinconfig, bool value); +#ifndef CONFIG_STMPE11_GPIO_DISABLE +EXTERN void stmpe11_gpiowrite(STMPE11_HANDLE handle, uint8_t pinconfig, bool value); +#endif /******************************************************************************************** * Name: stmpe11_gpioread @@ -542,7 +558,7 @@ EXTERN int stmpe11_gpiowrite(STMPE11_HANDLE handle, uint8_t pinconfig, bool valu * Set or clear the GPIO output * * Input Parameters: - * handle - The handle previously returned by stmpe11_register + * handle - The handle previously returned by stmpe11_instantiate * pinconfig - Bit-encoded pin configuration * value - The location to return the state of the GPIO pin * @@ -552,16 +568,22 @@ EXTERN int stmpe11_gpiowrite(STMPE11_HANDLE handle, uint8_t pinconfig, bool valu * ********************************************************************************************/ +#ifndef CONFIG_STMPE11_GPIO_DISABLE EXTERN int stmpe11_gpioread(STMPE11_HANDLE handle, uint8_t pinconfig, bool *value); +#endif /******************************************************************************************** * Name: stmpe11_gpioattach * * Description: - * Attach to a GPIO interrupt input pin and enable interrrupts on the pin + * Attach to a GPIO interrupt input pin and enable interrupts on the pin. Using the value + * NULL for the handler address will disable interrupts from the pin and detach the handler. + * + * NOTE: Callbacks do not occur from an interrupt handler but rather from the context + * of the worker thread with interrupts enabled. * * Input Parameters: - * handle - The handle previously returned by stmpe11_register + * handle - The handle previously returned by stmpe11_instantiate * pinconfig - Bit-encoded pin configuration * handler - The handler that will be called when the interrupt occurs. * @@ -571,7 +593,10 @@ EXTERN int stmpe11_gpioread(STMPE11_HANDLE handle, uint8_t pinconfig, bool *valu * ********************************************************************************************/ -EXTERN int stmpe11_gpioread(STMPE11_HANDLE handle, uint8_t pinconfig, bool *value); +#if !defined(CONFIG_STMPE11_GPIO_DISABLE) && !defined(CONFIG_STMPE11_GPIOINT_DISABLE) +EXTERN int stmpe11_gpioattach(STMPE11_HANDLE handle, uint8_t pinconfig, + stmpe11_handler_t handler); +#endif #undef EXTERN #ifdef __cplusplus |