From e82fa8182eef943a9a85d1f5d39a6917eda6d13a Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 6 Jul 2012 14:50:43 +0000 Subject: Add LPC43 GPIO configurtion logic git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4912 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/src/lpc43xx/Make.defs | 4 + nuttx/arch/arm/src/lpc43xx/lpc43_cgu.c | 6 +- nuttx/arch/arm/src/lpc43xx/lpc43_debug.c | 10 +- nuttx/arch/arm/src/lpc43xx/lpc43_gpio.c | 167 ++++++++++++++++++++++++--- nuttx/arch/arm/src/lpc43xx/lpc43_gpio.h | 160 ++++++++++++------------- nuttx/arch/arm/src/lpc43xx/lpc43_gpioint.c | 157 +++++++++++++++++++++++++ nuttx/arch/arm/src/lpc43xx/lpc43_gpioint.h | 139 ++++++++++++++++++++++ nuttx/arch/arm/src/lpc43xx/lpc43_irq.c | 10 +- nuttx/arch/arm/src/lpc43xx/lpc43_lowputc.c | 28 ++--- nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.c | 6 +- nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.h | 10 +- nuttx/arch/arm/src/lpc43xx/lpc43_spi.h | 2 +- 12 files changed, 560 insertions(+), 139 deletions(-) create mode 100644 nuttx/arch/arm/src/lpc43xx/lpc43_gpioint.c create mode 100644 nuttx/arch/arm/src/lpc43xx/lpc43_gpioint.h (limited to 'nuttx/arch/arm/src/lpc43xx') diff --git a/nuttx/arch/arm/src/lpc43xx/Make.defs b/nuttx/arch/arm/src/lpc43xx/Make.defs index 071a9dd9e..ee8b647c9 100644 --- a/nuttx/arch/arm/src/lpc43xx/Make.defs +++ b/nuttx/arch/arm/src/lpc43xx/Make.defs @@ -74,6 +74,10 @@ ifeq ($(CONFIG_LPC43_GPDMA),y) CHIP_CSRCS += lpc43_gpdma.c endif +ifeq ($(CONFIG_GPIO_IRQ),y) +CHIP_CSRCS += lpc43_gpioint.c +endif + ifeq ($(CONFIG_LPC43_SPI),y) CHIP_CSRCS += lpc43_spi.c endif diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_cgu.c b/nuttx/arch/arm/src/lpc43xx/lpc43_cgu.c index 05a214765..036da2697 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_cgu.c +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_cgu.c @@ -248,14 +248,14 @@ static inline void lpc43_pll1enable(void) } /**************************************************************************** - * Name: lpc32_m4clkselect + * Name: lpc43_m4clkselect * * Description: * Select PLL1 output as the Cortex-M4 source clock. * ****************************************************************************/ -static inline void lpc32_m4clkselect(void) +static inline void lpc43_m4clkselect(void) { uint32_t regval; @@ -295,5 +295,5 @@ void lpc43_clockconfig(void) /* Set up PLL1 output as the M4 clock */ - lpc32_m4clkselect(); + lpc43_m4clkselect(); } diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_debug.c b/nuttx/arch/arm/src/lpc43xx/lpc43_debug.c index 94237ab09..00e8ebc42 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_debug.c +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_debug.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/lpc43/lpc43_pinconfig.c + * arch/arm/src/lpc43/lpc43_pin_config.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -63,7 +63,7 @@ * Public Functions ****************************************************************************/ /**************************************************************************** - * Function: lpc43_dumppinconfig + * Function: lpc43_pin_dump * * Description: * Dump all pin configuration registers associated with the provided pin @@ -71,21 +71,21 @@ * ****************************************************************************/ -int lpc43_dumppinconfig(uint32_t pinconf, const char *msg) +int lpc43_pin_dump(uint32_t pinconf, const char *msg) { #warning "Missing logic" return -ENOSYS; } /******************************************************************************************** - * Function: lpc43_dumpgpio + * Function: lpc43_gpio_dump * * Description: * Dump all pin configuration registers associated with the provided base address * ********************************************************************************************/ -int lpc43_dumpgpio(uint16_t gpiocfg, const char *msg) +int lpc43_gpio_dump(uint16_t gpiocfg, const char *msg) { #warning "Missing logic" return -ENOSYS; diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.c b/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.c index 36983b8ec..d1f3ec859 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.c +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.c @@ -42,8 +42,10 @@ #include #include +#include -#include "lpc43_pinconfig.h" +#include "up_arch.h" +#include "lpc43_gpio.h" /**************************************************************************** * Pre-processor Definitions @@ -53,33 +55,159 @@ * Private Data ****************************************************************************/ +/**************************************************************************** + * Public Data + ****************************************************************************/ + /**************************************************************************** * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: lpc43_configinput + * + * Description: + * Configure a GPIO pin as an input (or pre-configured the pin for an + * interrupt). + * + * Returned Value: + * None + * + * Assumptions: + * Interrupts are disabled so that read-modify-write operations are safe. + * + ****************************************************************************/ + +static inline void lpc43_configinput(uint16_t gpiocfg, + unsigned int port, unsigned int pin) +{ + uintptr_t regaddr; + uint32_t regval; + + /* Make sure that the pin is *not* configured as an interrupt */ + +#ifdef CONFIG_GPIO_IRQ + (void)lpc43_gpioint_unconfig(gpiocfg) +#endif + + /* Then configure the pin as a normal input by clearing the corresponding + * bit in the GPIO DIR register for the port. + */ + + regaddr = LPC43_GPIO_DIR(port); + regval = getreg32(regaddr); + regval &= ~GPIO_DIR(pin); + putreg32(regval, regaddr); + + /* To be able to read the signal on the GPIO input, the input + * buffer must be enabled in the syscon block for the corresponding pin. + * This should have been done when the pin was configured as a GPIO. + */ +} + +/**************************************************************************** + * Name: lpc43_configoutput + * + * Description: + * Configure a GPIO pin as an output. + * + * Returned Value: + * None + * + * Assumptions: + * Interrupts are disabled so that read-modify-write operations are safe. + * + ****************************************************************************/ + +static inline void lpc43_configoutput(uint16_t gpiocfg, + unsigned int port, unsigned int pin) +{ + uintptr_t regaddr; + uint32_t regval; + + /* Make sure that the pin is *not* configured as an interrupt */ + +#ifdef CONFIG_GPIO_IRQ + (void)lpc43_gpioint_unconfig(gpiocfg) +#endif + + /* Then configure the pin as an output by setting the corresponding + * bit in the GPIO DIR register for the port. + */ + + regaddr = LPC43_GPIO_DIR(port); + regval = getreg32(regaddr); + regval |= GPIO_DIR(pin); + putreg32(regval, regaddr); + + /* Set the initial value of the output */ + + lpc43_gpio_write(gpiocfg, GPIO_IS_ONE(gpiocfg)); + + /* To be able to read the signal on the GPIO input, the input + * buffer must be enabled in the syscon block for the corresponding pin. + * This should have been done when the pin was configured as a GPIO. + */ +} + /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: lpc43_gpioconfig + * Name: lpc43_gpio_config * * Description: - * Configure a GPIO based on bit-encoded description of the pin. + * Configure a GPIO based on bit-encoded description of the pin. NOTE: + * The pin *must* have first been configured for GPIO usage with a + * corresponding call to lpc43_pin_config(). * * Returned Value: * OK on success; A negated errno value on failure. * ****************************************************************************/ -int lpc43_gpioconfig(uint16_t gpiocfg) +int lpc43_gpio_config(uint16_t gpiocfg) { -#warning "Missing logic" - return -ENOSYS; + unsigned int port = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); + unsigned int pin = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); + irqstate_t flags; + int ret = OK; + + DEBUGASSERT(port < NUM_GPIO_PORTS && pin < NUM_GPIO_PINS); + + /* Handle the GPIO configuration by the basic mode of the pin */ + + flags = irqsave(); + switch (gpiocfg & GPIO_PORT_MASK) + { + case GPIO_MODE_INPUT: + lpc43_configinput(gpiocfg, port, pin); + break; + + case GPIO_MODE_OUTPUT: + lpc43_configoutput(gpiocfg, port, pin); + break; + + case GPIO_MODE_INTERRUPT: + lpc43_configinput(gpiocfg, port, pin); +#ifdef CONFIG_GPIO_IRQ + ret = lpc43_gpiointconfig(gpiocfg, port, pin); +#endif + break; + + default : + sdbg("ERROR: Unrecognized pin mode: %04x\n", gpiocfg); + ret = -EINVAL; + break; + } + + irqrestore(flags); + return ret; } /**************************************************************************** - * Name: lpc43_gpiowrite + * Name: lpc43_gpio_write * * Description: * Write one or zero to the selected GPIO pin @@ -89,13 +217,20 @@ int lpc43_gpioconfig(uint16_t gpiocfg) * ****************************************************************************/ -void lpc43_gpiowrite(uint16_t gpiocfg, bool value) +void lpc43_gpio_write(uint16_t gpiocfg, bool value) { -#warning "Missing logic" + unsigned int port = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); + unsigned int pin = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); + + DEBUGASSERT(port < NUM_GPIO_PORTS && pin < NUM_GPIO_PINS); + + /* Write the value (0 or 1). To the pin byte register */ + + putreg8((uint8_t)value, LPC43_GPIO_B(port, pin)); } /**************************************************************************** - * Name: lpc43_gpioread + * Name: lpc43_gpio_read * * Description: * Read one or zero from the selected GPIO pin @@ -105,10 +240,16 @@ void lpc43_gpiowrite(uint16_t gpiocfg, bool value) * ****************************************************************************/ -bool lpc43_gpioread(uint16_t gpiocfg) +bool lpc43_gpio_read(uint16_t gpiocfg) { -#warning "Missing logic" - return false; + unsigned int port = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); + unsigned int pin = ((gpiocfg & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT); + + DEBUGASSERT(port < NUM_GPIO_PORTS && pin < NUM_GPIO_PINS); + + /* Get the value of the pin from the pin byte register */ + + return (getreg8(LPC43_GPIO_B(port, pin)) & GPIO_B) != 0; } diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.h b/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.h index d7615efa0..d3522197f 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.h +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_gpio.h @@ -51,6 +51,9 @@ /******************************************************************************************** * Pre-processor Definitions ********************************************************************************************/ + +/* Max number of GPIO ports and the maximum number of pins per port */ + #define NUM_GPIO_PORTS 8 #define NUM_GPIO_PINS 32 @@ -80,9 +83,9 @@ # define GPIO_MODE_OUTPUT (2 << GPIO_MODE_SHIFT) # define GPIO_MODE_INTERRUPT (3 << GPIO_MODE_SHIFT) -#define GPIO_IS_OUTPUT(p) ((p) & GPIO_MODE_MASK) == GPIO_MODE_INPUT) -#define GPIO_IS_INPUT(p) ((p) & GPIO_MODE_MASK) == GPIO_MODE_OUTPUT) -#define GPIO_IS_INTERRUPT(p) ((p) & GPIO_MODE_MASK) == GPIO_MODE_INTERRUPT) +#define GPIO_IS_OUTPUT(p) (((p) & GPIO_MODE_MASK) == GPIO_MODE_INPUT) +#define GPIO_IS_INPUT(p) (((p) & GPIO_MODE_MASK) == GPIO_MODE_OUTPUT) +#define GPIO_IS_INTERRUPT(p) (((p) & GPIO_MODE_MASK) == GPIO_MODE_INTERRUPT) /* Initial value (for GPIO outputs only) * @@ -95,6 +98,9 @@ #define GPIO_VALUE_ONE (1 << 12) /* Bit 12: 1=High */ #define GPIO_VALUE_ZERO (0) /* Bit 12: 0=Low */ +#define GPIO_IS_ONE(p) (((p) & GPIO_VALUE_ONE) != 0) +#define GPIO_IS_ZERO(p) (((p) & GPIO_VALUE_ONE) == 0) + /* Group Interrupt Selection (valid only for interrupt GPIO pins): * * 1111 1100 0000 0000 @@ -105,15 +111,15 @@ #define GPIO_GRPINT_SHIFT (11) /* Bits 11-12: Group interrupt selection */ #define GPIO_GRPINT_MASK (3 << GPIO_GRPINT_SHIFT) -# define GPIO_GRPINT_NONE (0 << GPIO_GRPINT_SHIFT) /* 00 Not a member of a group */ +# define GPIO_GRPINT_NOGROUP (0 << GPIO_GRPINT_SHIFT) /* 00 Not a member of a group */ # define GPIO_GRPINT_GROUP0 (2 << GPIO_GRPINT_SHIFT) /* 10 Member of group 0 */ # define GPIO_GRPINT_GROUP1 (3 << GPIO_GRPINT_SHIFT) /* 11 Member of group 1 */ #define _GPIO_GRPINT (1 << (GPIO_GRPINT_SHIFT+1)) /* Bit 12: 1=Member of a group */ #define _GPIO_GRPNO (1 << GPIO_GRPINT_SHIFT) /* Bit 11: Group number */ -#define GPIO_IS_GRPINT(p) ((p) & _GPIO_GRPINT) != 0) -#define GPIO_GRPPNO(p) ((p) & _GPIO_GRPNO) >> GPIO_GRPINT_SHIFT) +#define GPIO_IS_GRPINT(p) (((p) & _GPIO_GRPINT) != 0) +#define GPIO_GRPPNO(p) (((p) & _GPIO_GRPNO) >> GPIO_GRPINT_SHIFT) /* Group Interrupt Polarity (valid only for interrupt GPIO group interrupts ): * @@ -149,10 +155,10 @@ #define _GPIO_ACTIVE_HI (1 << GPIO_INT_SHIFT) #define _GPIO_EDGE (1 << (GPIO_INT_SHIFT+1)) -#define GPIO_IS_ACTIVE_HI(p) ((p) & _GPIO_ACTIVE_HI) != 0) -#define GPIO_IS_ACTIVE_LOW(p) ((p) & _GPIO_ACTIVE_HI) == 0) -#define GPIO_IS_EDGE(p) ((p) & _GPIO_EDGE) != 0) -#define GPIO_IS_LEVEL(p) ((p) & _GPIO_EDGE) == 0) +#define GPIO_IS_ACTIVE_HI(p) (((p) & _GPIO_ACTIVE_HI) != 0) +#define GPIO_IS_ACTIVE_LOW(p) (((p) & _GPIO_ACTIVE_HI) == 0) +#define GPIO_IS_EDGE(p) (((p) & _GPIO_EDGE) != 0) +#define GPIO_IS_LEVEL(p) (((p) & _GPIO_EDGE) == 0) /* GPIO Port Number: * @@ -162,16 +168,16 @@ * .... GPII .... .... */ -#define GPIO_PORT_SHIFT (4) /* Bits 4-6: Port number */ -#define GPIO_PORT_MASK (7 << GPIO_PORT_SHIFT) -# define GPIO_PORT0 (0 << GPIO_PORT_SHIFT) -# define GPIO_PORT1 (1 << GPIO_PORT_SHIFT) -# define GPIO_PORT2 (2 << GPIO_PORT_SHIFT) -# define GPIO_PORT3 (3 << GPIO_PORT_SHIFT) -# define GPIO_PORT4 (4 << GPIO_PORT_SHIFT) -# define GPIO_PORT5 (5 << GPIO_PORT_SHIFT) -# define GPIO_PORT6 (6 << GPIO_PORT_SHIFT) -# define GPIO_PORT7 (7 << GPIO_PORT_SHIFT) +#define GPIO_PORT_SHIFT (4) /* Bits 4-6: Port number */ +#define GPIO_PORT_MASK (7 << GPIO_PORT_SHIFT) +# define GPIO_PORT0 (0 << GPIO_PORT_SHIFT) +# define GPIO_PORT1 (1 << GPIO_PORT_SHIFT) +# define GPIO_PORT2 (2 << GPIO_PORT_SHIFT) +# define GPIO_PORT3 (3 << GPIO_PORT_SHIFT) +# define GPIO_PORT4 (4 << GPIO_PORT_SHIFT) +# define GPIO_PORT5 (5 << GPIO_PORT_SHIFT) +# define GPIO_PORT6 (6 << GPIO_PORT_SHIFT) +# define GPIO_PORT7 (7 << GPIO_PORT_SHIFT) /* GPIO Pin Number: * @@ -181,40 +187,40 @@ * .... .... ...B BBBB */ -#define GPIO_PIN_SHIFT (0) /* Bits 0-5: Pin number */ -#define GPIO_PIN_MASK (31 << GPIO_PIN_SHIFT) -# define GPIO_PIN0 (0 << GPIO_PIN_SHIFT) -# define GPIO_PIN1 (1 << GPIO_PIN_SHIFT) -# define GPIO_PIN2 (2 << GPIO_PIN_SHIFT) -# define GPIO_PIN3 (3 << GPIO_PIN_SHIFT) -# define GPIO_PIN4 (4 << GPIO_PIN_SHIFT) -# define GPIO_PIN5 (5 << GPIO_PIN_SHIFT) -# define GPIO_PIN6 (6 << GPIO_PIN_SHIFT) -# define GPIO_PIN7 (7 << GPIO_PIN_SHIFT) -# define GPIO_PIN8 (8 << GPIO_PIN_SHIFT) -# define GPIO_PIN9 (9 << GPIO_PIN_SHIFT) -# define GPIO_PIN10 (10 << GPIO_PIN_SHIFT) -# define GPIO_PIN11 (11 << GPIO_PIN_SHIFT) -# define GPIO_PIN12 (12 << GPIO_PIN_SHIFT) -# define GPIO_PIN13 (13 << GPIO_PIN_SHIFT) -# define GPIO_PIN14 (14 << GPIO_PIN_SHIFT) -# define GPIO_PIN15 (15 << GPIO_PIN_SHIFT) -# define GPIO_PIN16 (16 << GPIO_PIN_SHIFT) -# define GPIO_PIN17 (17 << GPIO_PIN_SHIFT) -# define GPIO_PIN18 (18 << GPIO_PIN_SHIFT) -# define GPIO_PIN19 (19 << GPIO_PIN_SHIFT) -# define GPIO_PIN20 (20 << GPIO_PIN_SHIFT) -# define GPIO_PIN21 (21 << GPIO_PIN_SHIFT) -# define GPIO_PIN22 (22 << GPIO_PIN_SHIFT) -# define GPIO_PIN23 (23 << GPIO_PIN_SHIFT) -# define GPIO_PIN24 (24 << GPIO_PIN_SHIFT) -# define GPIO_PIN25 (25 << GPIO_PIN_SHIFT) -# define GPIO_PIN26 (26 << GPIO_PIN_SHIFT) -# define GPIO_PIN27 (27 << GPIO_PIN_SHIFT) -# define GPIO_PIN28 (28 << GPIO_PIN_SHIFT) -# define GPIO_PIN29 (29 << GPIO_PIN_SHIFT) -# define GPIO_PIN30 (30 << GPIO_PIN_SHIFT) -# define GPIO_PIN31 (31 << GPIO_PIN_SHIFT) +#define GPIO_PIN_SHIFT (0) /* Bits 0-5: Pin number */ +#define GPIO_PIN_MASK (31 << GPIO_PIN_SHIFT) +# define GPIO_PIN0 (0 << GPIO_PIN_SHIFT) +# define GPIO_PIN1 (1 << GPIO_PIN_SHIFT) +# define GPIO_PIN2 (2 << GPIO_PIN_SHIFT) +# define GPIO_PIN3 (3 << GPIO_PIN_SHIFT) +# define GPIO_PIN4 (4 << GPIO_PIN_SHIFT) +# define GPIO_PIN5 (5 << GPIO_PIN_SHIFT) +# define GPIO_PIN6 (6 << GPIO_PIN_SHIFT) +# define GPIO_PIN7 (7 << GPIO_PIN_SHIFT) +# define GPIO_PIN8 (8 << GPIO_PIN_SHIFT) +# define GPIO_PIN9 (9 << GPIO_PIN_SHIFT) +# define GPIO_PIN10 (10 << GPIO_PIN_SHIFT) +# define GPIO_PIN11 (11 << GPIO_PIN_SHIFT) +# define GPIO_PIN12 (12 << GPIO_PIN_SHIFT) +# define GPIO_PIN13 (13 << GPIO_PIN_SHIFT) +# define GPIO_PIN14 (14 << GPIO_PIN_SHIFT) +# define GPIO_PIN15 (15 << GPIO_PIN_SHIFT) +# define GPIO_PIN16 (16 << GPIO_PIN_SHIFT) +# define GPIO_PIN17 (17 << GPIO_PIN_SHIFT) +# define GPIO_PIN18 (18 << GPIO_PIN_SHIFT) +# define GPIO_PIN19 (19 << GPIO_PIN_SHIFT) +# define GPIO_PIN20 (20 << GPIO_PIN_SHIFT) +# define GPIO_PIN21 (21 << GPIO_PIN_SHIFT) +# define GPIO_PIN22 (22 << GPIO_PIN_SHIFT) +# define GPIO_PIN23 (23 << GPIO_PIN_SHIFT) +# define GPIO_PIN24 (24 << GPIO_PIN_SHIFT) +# define GPIO_PIN25 (25 << GPIO_PIN_SHIFT) +# define GPIO_PIN26 (26 << GPIO_PIN_SHIFT) +# define GPIO_PIN27 (27 << GPIO_PIN_SHIFT) +# define GPIO_PIN28 (28 << GPIO_PIN_SHIFT) +# define GPIO_PIN29 (29 << GPIO_PIN_SHIFT) +# define GPIO_PIN30 (30 << GPIO_PIN_SHIFT) +# define GPIO_PIN31 (31 << GPIO_PIN_SHIFT) /******************************************************************************************** * Public Types @@ -232,29 +238,26 @@ extern "C" { #define EXTERN extern #endif -/* Base addresses for each GPIO block */ - -EXTERN const uint32_t g_gpiobase[NUM_GPIO_PORTS]; - /******************************************************************************************** * Public Functions ********************************************************************************************/ /******************************************************************************************** - * Name: lpc43_gpioconfig + * Name: lpc43_gpio_config * * Description: - * Configure a GPIO based on bit-encoded description of the pin. + * Configure a GPIO based on bit-encoded description of the pin. NOTE: The pin *must* + * have first been configured for GPIO usage with a corresponding call to lpc43_pin_config. * * Returned Value: * OK on success; A negated errno value on failure. * ********************************************************************************************/ -EXTERN int lpc43_gpioconfig(uint16_t gpiocfg); +EXTERN int lpc43_gpio_config(uint16_t gpiocfg); /******************************************************************************************** - * Name: lpc43_gpiowrite + * Name: lpc43_gpio_write * * Description: * Write one or zero to the selected GPIO pin @@ -264,10 +267,10 @@ EXTERN int lpc43_gpioconfig(uint16_t gpiocfg); * ********************************************************************************************/ -EXTERN void lpc43_gpiowrite(uint16_t gpiocfg, bool value); +EXTERN void lpc43_gpio_write(uint16_t gpiocfg, bool value); /******************************************************************************************** - * Name: lpc43_gpioread + * Name: lpc43_gpio_read * * Description: * Read one or zero from the selected GPIO pin @@ -277,31 +280,10 @@ EXTERN void lpc43_gpiowrite(uint16_t gpiocfg, bool value); * ********************************************************************************************/ -EXTERN bool lpc43_gpioread(uint16_t gpiocfg); - -/******************************************************************************************** - * Name: lpc43_gpioattach - * - * Description: - * Attach and enable a GPIO interrupts on the selected GPIO pin, receiving the - * interrupt with the selected interrupt handler. The GPIO interrupt may be - * disabled by providing a NULL value for the interrupt handler function pointer. - * - * Parameters: - * - gpiocfg: GPIO pin identification - * - func: Interrupt handler - * - * Returns: - * The previous value of the interrupt handler function pointer. This value may, - * for example, be used to restore the previous handler when multiple handlers are - * used. - * - ********************************************************************************************/ - -EXTERN xcpt_t lpc43_gpioattach(uint16_t gpiocfg, xcpt_t func); +EXTERN bool lpc43_gpio_read(uint16_t gpiocfg); /******************************************************************************************** - * Function: lpc43_dumpgpio + * Function: lpc43_gpio_dump * * Description: * Dump all pin configuration registers associated with the provided base address @@ -309,9 +291,9 @@ EXTERN xcpt_t lpc43_gpioattach(uint16_t gpiocfg, xcpt_t func); ********************************************************************************************/ #ifdef CONFIG_DEBUG -EXTERN int lpc43_dumpgpio(uint16_t gpiocfg, const char *msg); +EXTERN int lpc43_gpio_dump(uint16_t gpiocfg, const char *msg); #else -# define lpc43_dumpgpio(p,m) +# define lpc43_gpio_dump(p,m) #endif #undef EXTERN diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_gpioint.c b/nuttx/arch/arm/src/lpc43xx/lpc43_gpioint.c new file mode 100644 index 000000000..986151486 --- /dev/null +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_gpioint.c @@ -0,0 +1,157 @@ +/**************************************************************************** + * arch/arm/src/lpc43/lpc43_gpioint.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ +/* GPIO pin interrupts + * + * From all available GPIO pins, up to eight pins can be selected in the system + * control block to serve as external interrupt pins. The external interrupt pins + * are connected to eight individual interrupts in the NVIC and are created based + * on rising or falling edges or on the input level on the pin. + * + * GPIO group interrupt + * + * For each port/pin connected to one of the two the GPIO Grouped Interrupt blocks + * (GROUP0 and GROUP1), the GPIO grouped interrupt registers determine which pins are + * enabled to generate interrupts and what the active polarities of each of those + * inputs are. The GPIO grouped interrupt registers also select whether the interrupt + * output will be level or edge triggered and whether it will be based on the OR or + * the AND of all of the enabled inputs. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include + +#include "lpc43_gpioint.h" + +#ifdef CONFIG_GPIO_IRQ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lpc43_gpioint_initialize + * + * Description: + * Initialize logic to interrupting GPIO pins GPIO pins + * + ****************************************************************************/ + +void lpc43_gpioint_initialize(void) +{ +#warning "Missing logic" +} + +/**************************************************************************** + * Name: lpc43_gpioint_config + * + * Description: + * Configure a GPIO pin as an interrupt source (after it has been + * configured as an input). + * + * Returned Value: + * Zero on success; a negated errno value on failure. + * + ****************************************************************************/ + +int lpc43_gpioint_config(uint16_t gpiocfg) +{ +#warning "Missing logic" + return -ENOSYS; +} + +/**************************************************************************** + * Name: lpc43_gpiointconfig + * + * Description: + * Un-configure a GPIO pin as an interrupt source. + * + * Returned Value: + * Zero on success; a negated errno value on failure. + * + ****************************************************************************/ + +int lpc43_gpioint_unconfig(uint16_t gpiocfg) +{ +#warning "Missing logic" + return -ENOSYS; +} + +/**************************************************************************** + * Name: lpc43_gpioint_enable + * + * Description: + * Enable the interrupt for specified GPIO IRQ + * + ****************************************************************************/ + +void lpc43_gpioint_enable(int irq) +{ +#warning "Missing logic" +} + +/**************************************************************************** + * Name: lpc43_gpioint_disable + * + * Description: + * Disable the interrupt for specified GPIO IRQ + * + ****************************************************************************/ + +void lpc43_gpioint_disable(int irq) +{ +#warning "Missing logic" +} + +#endif /* CONFIG_GPIO_IRQ */ + diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_gpioint.h b/nuttx/arch/arm/src/lpc43xx/lpc43_gpioint.h new file mode 100644 index 000000000..1d9b2a826 --- /dev/null +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_gpioint.h @@ -0,0 +1,139 @@ +/************************************************************************************ + * arch/arm/src/lpc43xx/lpc43_gpioint.h + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ +/* GPIO pin interrupts + * + * From all available GPIO pins, up to eight pins can be selected in the system + * control block to serve as external interrupt pins. The external interrupt pins + * are connected to eight individual interrupts in the NVIC and are created based + * on rising or falling edges or on the input level on the pin. + * + * GPIO group interrupt + * + * For each port/pin connected to one of the two the GPIO Grouped Interrupt blocks + * (GROUP0 and GROUP1), the GPIO grouped interrupt registers determine which pins are + * enabled to generate interrupts and what the active polarities of each of those + * inputs are. The GPIO grouped interrupt registers also select whether the interrupt + * output will be level or edge triggered and whether it will be based on the OR or + * the AND of all of the enabled inputs. + */ + +#ifndef __ARCH_ARM_SRC_LPC43XX_LPC43_GPIOINT_H +#define __ARCH_ARM_SRC_LPC43XX_LPC43_GPIOINT_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include +#include "chip.h" +#include "chip/lpc43_gpio.h" + +#ifdef CONFIG_GPIO_IRQ + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/************************************************************************************ + * Public Types + ************************************************************************************/ + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: lpc43_gpioint_initialize + * + * Description: + * Initialize logic to interrupting GPIO pins GPIO pins + * + ************************************************************************************/ + +EXTERN void lpc43_gpioint_initialize(void); + +/**************************************************************************** + * Name: lpc43_gpioint_config + * + * Description: + * Configure a GPIO pin as an interrupt source (after it has been + * configured as an input). + * + * Returned Value: + * None + * + ****************************************************************************/ + +EXTERN int lpc43_gpioint_config(uint16_t gpiocfg); + +/**************************************************************************** + * Name: lpc43_gpiointconfig + * + * Description: + * Un-configure a GPIO pin as an interrupt source. + * + * Returned Value: + * Zero on success; a negated errno value on failure. + * + ****************************************************************************/ + +EXTERN int lpc43_gpioint_unconfig(uint16_t gpiocfg); + +/************************************************************************************ + * Name: lpc43_gpioint_enable + * + * Description: + * Zero on success; a negated errno value on failure. + * + ************************************************************************************/ + +EXTERN int lpc43_gpioint_enable(int irq); + +/************************************************************************************ + * Name: lpc43_gpioint_disable + * + * Description: + * Disable the interrupt for specified GPIO IRQ + * + ************************************************************************************/ + +EXTERN void lpc43_gpioint_disable(int irq); + +#endif /* CONFIG_GPIO_IRQ */ +#endif /* __ARCH_ARM_SRC_LPC43XX_LPC43_GPIOINT_H */ diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_irq.c b/nuttx/arch/arm/src/lpc43xx/lpc43_irq.c index 22471ce1e..c6c94af88 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_irq.c +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_irq.c @@ -357,12 +357,10 @@ void up_irqinitialize(void) lpc43_dumpnvic("initial", LPC43M4_IRQ_NIRQS); - /* Initialize logic to support a second level of interrupt decoding for - * GPIO pins. - */ + /* Initialize logic to interrupting GPIO pins GPIO pins */ #ifdef CONFIG_GPIO_IRQ - lpc43_gpioirqinitialize(); + lpc43_gpioint_initialize(); #endif /* And finally, enable interrupts */ @@ -400,7 +398,7 @@ void up_disable_irq(int irq) { /* Maybe it is a (derived) GPIO IRQ */ - lpc43_gpioirqdisable(irq); + lpc43_gpioint_disable(irq); } #endif lpc43_dumpnvic("disable", irq); @@ -433,7 +431,7 @@ void up_enable_irq(int irq) { /* Maybe it is a (derived) GPIO IRQ */ - lpc43_gpioirqenable(irq); + lpc43_gpioint_enable(irq); } #endif lpc43_dumpnvic("enable", irq); diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_lowputc.c b/nuttx/arch/arm/src/lpc43xx/lpc43_lowputc.c index 2e45f9855..e865be11d 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_lowputc.c +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_lowputc.c @@ -365,25 +365,25 @@ void lpc43_lowsetup(void) */ #if defined(CONFIG_USART0_SERIAL_CONSOLE) - lpc43_pinconfig(PINCONF_U0_TXD); - lpc43_pinconfig(PINCONF_U0_RXD); + lpc43_pin_config(PINCONF_U0_TXD); + lpc43_pin_config(PINCONF_U0_RXD); #elif defined(CONFIG_UART1_SERIAL_CONSOLE) - lpc43_pinconfig(PINCONF_U1_TXD); - lpc43_pinconfig(PINCONF_U1_RXD); + lpc43_pin_config(PINCONF_U1_TXD); + lpc43_pin_config(PINCONF_U1_RXD); #ifdef CONFIG_UART1_FLOWCONTROL - lpc43_pinconfig(PINCONF_U1_CTS); - lpc43_pinconfig(PINCONF_U1_DCD); - lpc43_pinconfig(PINCONF_U1_DSR); - lpc43_pinconfig(PINCONF_U1_DTR); - lpc43_pinconfig(PINCONF_U1_RI); - lpc43_pinconfig(PINCONF_U1_RTS); + lpc43_pin_config(PINCONF_U1_CTS); + lpc43_pin_config(PINCONF_U1_DCD); + lpc43_pin_config(PINCONF_U1_DSR); + lpc43_pin_config(PINCONF_U1_DTR); + lpc43_pin_config(PINCONF_U1_RI); + lpc43_pin_config(PINCONF_U1_RTS); #endif #elif defined(CONFIG_USART2_SERIAL_CONSOLE) - lpc43_pinconfig(PINCONF_U2_TXD); - lpc43_pinconfig(PINCONF_U2_RXD); + lpc43_pin_config(PINCONF_U2_TXD); + lpc43_pin_config(PINCONF_U2_RXD); #elif defined(CONFIG_USART3_SERIAL_CONSOLE) - lpc43_pinconfig(PINCONF_U3_TXD); - lpc43_pinconfig(PINCONF_U3_RXD); + lpc43_pin_config(PINCONF_U3_TXD); + lpc43_pin_config(PINCONF_U3_RXD); #endif /* Configure the console (only) */ diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.c b/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.c index d41d6f588..69456d12b 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.c +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/lpc43/lpc43_pinconfig.c + * arch/arm/src/lpc43/lpc43_pin_config.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: lpc43_pinconfig + * Name: lpc43_pin_config * * Description: * Configure a pin based on bit-encoded description of the pin. @@ -75,7 +75,7 @@ * ****************************************************************************/ -int lpc43_pinconfig(uint32_t pinconf) +int lpc43_pin_config(uint32_t pinconf) { #warning "Missing logic" return -ENOSYS; diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.h b/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.h index 27769f4b4..1de93a78d 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.h +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_pinconfig.h @@ -254,7 +254,7 @@ extern "C" { ********************************************************************************************/ /******************************************************************************************** - * Name: lpc43_pinconfig + * Name: lpc43_pin_config * * Description: * Configure a pin based on bit-encoded description of the pin. @@ -267,10 +267,10 @@ extern "C" { * ********************************************************************************************/ -EXTERN int lpc43_pinconfig(uint32_t pinconf); +EXTERN int lpc43_pin_config(uint32_t pinconf); /******************************************************************************************** - * Function: lpc43_dumppinconfig + * Function: lpc43_pin_dump * * Description: * Dump all pin configuration registers associated with the provided pin configuration @@ -278,9 +278,9 @@ EXTERN int lpc43_pinconfig(uint32_t pinconf); ********************************************************************************************/ #ifdef CONFIG_DEBUG -EXTERN int lpc43_dumppinconfig(uint32_t pinconf, const char *msg); +EXTERN int lpc43_pin_dump(uint32_t pinconf, const char *msg); #else -# define lpc43_dumppinconfig(p,m) +# define lpc43_pin_dump(p,m) #endif #undef EXTERN diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_spi.h b/nuttx/arch/arm/src/lpc43xx/lpc43_spi.h index 7af965947..28c833826 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_spi.h +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_spi.h @@ -42,7 +42,7 @@ #include #include -#include "chip/lpc32_spi.h" +#include "chip/lpc43_spi.h" #ifdef CONFIG_LPC43_SPI -- cgit v1.2.3