2010-06-06 19:11:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/arm/src/lpc17xx/lpc17_gpioint.c
|
|
|
|
*
|
2013-04-03 21:35:21 +02:00
|
|
|
* Copyright (C) 2010-2011, 2013 Gregory Nutt. All rights reserved.
|
2012-01-01 00:09:33 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2010-06-06 19:11:15 +02:00
|
|
|
*
|
|
|
|
* 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 <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <arch/irq.h>
|
2011-03-24 03:26:25 +01:00
|
|
|
#include <nuttx/arch.h>
|
2010-06-06 19:11:15 +02:00
|
|
|
|
|
|
|
#include "up_arch.h"
|
|
|
|
#include "chip.h"
|
|
|
|
#include "lpc17_gpio.h"
|
2013-01-18 20:16:44 +01:00
|
|
|
|
2010-06-06 19:11:15 +02:00
|
|
|
#ifdef CONFIG_GPIO_IRQ
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: lpc17_getintedge
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the stored interrupt edge configuration.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static unsigned int lpc17_getintedge(unsigned int port, unsigned int pin)
|
|
|
|
{
|
2011-03-24 03:26:25 +01:00
|
|
|
uint64_t *intedge;
|
2010-06-06 19:11:15 +02:00
|
|
|
|
|
|
|
/* Which word to we use? */
|
|
|
|
|
|
|
|
if (port == 0)
|
|
|
|
{
|
2011-03-24 03:26:25 +01:00
|
|
|
intedge = &g_intedge0;
|
2010-06-06 19:11:15 +02:00
|
|
|
}
|
|
|
|
else if (port == 2)
|
|
|
|
{
|
2013-04-03 21:35:21 +02:00
|
|
|
intedge = &g_intedge2;
|
2010-06-06 19:11:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the value for the PINSEL */
|
|
|
|
|
2011-03-23 13:16:38 +01:00
|
|
|
return (unsigned int)(((*intedge) >> (pin << 1)) & 3);
|
2010-06-06 19:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: lpc17_setintedge
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the edge interrupt enabled bits for this pin.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
static void lpc17_setintedge(uint32_t intbase, unsigned int pin,
|
|
|
|
unsigned int edges)
|
2010-06-06 19:11:15 +02:00
|
|
|
{
|
2013-04-07 21:46:05 +02:00
|
|
|
irqstate_t flags;
|
2010-06-06 19:11:15 +02:00
|
|
|
int regval;
|
|
|
|
|
2013-04-07 21:46:05 +02:00
|
|
|
/* These must be atomic */
|
|
|
|
|
|
|
|
flags = irqsave();
|
|
|
|
|
2010-06-06 19:11:15 +02:00
|
|
|
/* Set/clear the rising edge enable bit */
|
|
|
|
|
|
|
|
regval = getreg32(intbase + LPC17_GPIOINT_INTENR_OFFSET);
|
|
|
|
if ((edges & 2) != 0)
|
|
|
|
{
|
|
|
|
regval |= GPIOINT(pin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
regval &= ~GPIOINT(pin);
|
|
|
|
}
|
2013-04-03 21:35:21 +02:00
|
|
|
|
2010-06-06 19:11:15 +02:00
|
|
|
putreg32(regval, intbase + LPC17_GPIOINT_INTENR_OFFSET);
|
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set/clear the falling edge enable bit */
|
2010-06-06 19:11:15 +02:00
|
|
|
|
|
|
|
regval = getreg32(intbase + LPC17_GPIOINT_INTENF_OFFSET);
|
|
|
|
if ((edges & 1) != 0)
|
|
|
|
{
|
|
|
|
regval |= GPIOINT(pin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
regval &= ~GPIOINT(pin);
|
|
|
|
}
|
2013-04-03 21:35:21 +02:00
|
|
|
|
2010-06-06 19:11:15 +02:00
|
|
|
putreg32(regval, intbase + LPC17_GPIOINT_INTENF_OFFSET);
|
2013-04-07 21:46:05 +02:00
|
|
|
irqrestore(flags);
|
2010-06-06 19:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: lpc17_irq2port
|
|
|
|
*
|
|
|
|
* Description:
|
2010-06-06 19:22:05 +02:00
|
|
|
* Given an IRQ number, return the GPIO port number (0 or 2) of the interrupt.
|
2010-06-06 19:11:15 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int lpc17_irq2port(int irq)
|
|
|
|
{
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set 1:
|
|
|
|
* LPC176x: 12 interrupts p0.0-p0.11
|
|
|
|
* LPC178x: 16 interrupts p0.0-p0.15
|
|
|
|
*/
|
2010-06-06 19:22:05 +02:00
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
if (irq >= LPC17_VALID_FIRST0L &&
|
|
|
|
irq < (LPC17_VALID_FIRST0L + LPC17_VALID_NIRQS0L))
|
2010-06-06 19:22:05 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set 2:
|
|
|
|
* LPC176x: 16 interrupts p0.15-p0.30
|
|
|
|
* LPC178x: 16 interrupts p0.16-p0.31
|
|
|
|
*/
|
2010-06-06 19:22:05 +02:00
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
else if (irq >= LPC17_VALID_FIRST0H &&
|
|
|
|
irq < (LPC17_VALID_FIRST0H + LPC17_VALID_NIRQS0H))
|
2010-06-06 19:22:05 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-18 00:40:53 +01:00
|
|
|
#if defined (LPC176x)
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set 3:
|
|
|
|
* LPC17x: 14 interrupts p2.0-p2.13
|
|
|
|
*/
|
2010-06-06 19:22:05 +02:00
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
else if (irq >= LPC17_VALID_FIRST2 &&
|
|
|
|
irq < (LPC17_VALID_FIRST2 + LPC17_VALID_NIRQS2))
|
2010-06-06 19:22:05 +02:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
2013-03-18 00:40:53 +01:00
|
|
|
|
|
|
|
#elif defined (LPC178x)
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set 3:
|
|
|
|
* LPC18x: 16 interrupts p2.0-p2.15
|
|
|
|
*/
|
2013-03-18 00:40:53 +01:00
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
else if (irq >= LPC17_VALID_FIRST2L &&
|
|
|
|
irq < (LPC17_VALID_FIRST2L + LPC17_VALID_NIRQS2L))
|
2013-03-18 00:40:53 +01:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set 4:
|
|
|
|
* LPC178x: 16 interrupts p2.16-p2.31
|
|
|
|
*/
|
2013-03-18 00:40:53 +01:00
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
else if (irq >= LPC17_VALID_FIRST2H &&
|
|
|
|
irq < (LPC17_VALID_FIRST2H + LPC17_VALID_NIRQS2H))
|
2013-03-18 00:40:53 +01:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-06-06 19:22:05 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: lpc17_irq2pin
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Given an IRQ number, return the GPIO pin number (0..31) of the interrupt.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-03-24 03:26:25 +01:00
|
|
|
static int lpc17_irq2pin(int irq)
|
2010-06-06 19:22:05 +02:00
|
|
|
{
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set 1:
|
|
|
|
* LPC17x: 12 interrupts p0.0-p0.11
|
|
|
|
* LPC18x: 16 interrupts p0.0-p0.15
|
2013-03-18 00:40:53 +01:00
|
|
|
*
|
2011-04-11 21:14:11 +02:00
|
|
|
* See arch/arm/include/lpc17xx/irq.h:
|
2013-04-03 21:35:21 +02:00
|
|
|
* LPC17_VALID_SHIFT0L 0 - Bit 0 is thre first bit in the group of
|
|
|
|
* 12/16 interrupts
|
|
|
|
* LPC17_VALID_FIRST0L irq - IRQ number associated with p0.0
|
|
|
|
* LPC17_VALID_NIRQS0L 12/16 - Number of interrupt bits in the group
|
2011-04-11 21:14:11 +02:00
|
|
|
*/
|
2010-06-06 19:22:05 +02:00
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
if (irq >= LPC17_VALID_FIRST0L &&
|
|
|
|
irq < (LPC17_VALID_FIRST0L + LPC17_VALID_NIRQS0L))
|
2010-06-06 19:22:05 +02:00
|
|
|
{
|
|
|
|
return irq - LPC17_VALID_FIRST0L + LPC17_VALID_SHIFT0L;
|
|
|
|
}
|
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set 2:
|
|
|
|
* LPC176x: 16 interrupts p0.15-p0.30
|
|
|
|
* LPC178x: 16 interrupts p0.16-p0.31
|
2013-03-18 00:40:53 +01:00
|
|
|
*
|
2013-04-03 21:35:21 +02:00
|
|
|
* LPC17_VALID_SHIFT0H 15/16 - Bit number of the first bit in a group
|
|
|
|
* of 16 interrupts
|
|
|
|
* LPC17_VALID_FIRST0L irq - IRQ number associated with p0.15/16
|
2011-04-11 21:14:11 +02:00
|
|
|
* LPC17_VALID_NIRQS0L 16 - 16 interrupt bits in the group
|
|
|
|
*/
|
2010-06-06 19:22:05 +02:00
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
else if (irq >= LPC17_VALID_FIRST0H &&
|
|
|
|
irq < (LPC17_VALID_FIRST0H + LPC17_VALID_NIRQS0H))
|
2010-06-06 19:22:05 +02:00
|
|
|
{
|
|
|
|
return irq - LPC17_VALID_FIRST0H + LPC17_VALID_SHIFT0H;
|
|
|
|
}
|
|
|
|
|
2013-03-18 00:40:53 +01:00
|
|
|
#if defined(LPC176x)
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set 3:
|
|
|
|
* LPC17x: 14 interrupts p2.0-p2.13
|
2013-03-18 00:40:53 +01:00
|
|
|
*
|
2013-04-03 21:35:21 +02:00
|
|
|
* LPC17_VALID_SHIFT2 0 - Bit 0 is the first bit in a group of 14
|
|
|
|
* interrupts
|
2011-04-11 21:14:11 +02:00
|
|
|
* LPC17_VALID_FIRST2 irq - IRQ number associated with p2.0
|
|
|
|
* LPC17_VALID_NIRQS2 14 - 14 interrupt bits in the group
|
|
|
|
*/
|
2010-06-06 19:22:05 +02:00
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
else if (irq >= LPC17_VALID_FIRST2 &&
|
|
|
|
irq < (LPC17_VALID_FIRST2 + LPC17_VALID_NIRQS2))
|
2010-06-06 19:22:05 +02:00
|
|
|
{
|
2011-04-11 21:14:11 +02:00
|
|
|
return irq - LPC17_VALID_FIRST2 + LPC17_VALID_SHIFT2;
|
2010-06-06 19:22:05 +02:00
|
|
|
}
|
2013-03-18 00:40:53 +01:00
|
|
|
|
|
|
|
#elif defined(LPC178x)
|
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set 3:
|
|
|
|
* LPC18x: 16 interrupts p2.0-p2.15
|
2013-03-18 00:40:53 +01:00
|
|
|
*
|
2013-04-03 21:35:21 +02:00
|
|
|
* LPC17_VALID_SHIFT2L 0 - Bit 0 is the first bit in a group of 16
|
|
|
|
* interrupts
|
2013-03-18 00:40:53 +01:00
|
|
|
* LPC17_VALID_FIRST2L irq - IRQ number associated with p2.0
|
2013-04-03 21:35:21 +02:00
|
|
|
* LPC17_VALID_NIRQS2L 16 - 16 interrupt bits in the group
|
2013-03-18 00:40:53 +01:00
|
|
|
*/
|
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
else if (irq >= LPC17_VALID_FIRST2L &&
|
|
|
|
irq < (LPC17_VALID_FIRST2L + LPC17_VALID_NIRQS2L))
|
2013-03-18 00:40:53 +01:00
|
|
|
{
|
|
|
|
return irq - LPC17_VALID_FIRST2L + LPC17_VALID_SHIFT2L;
|
|
|
|
}
|
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
/* Set 3:
|
|
|
|
* LPC18x: 16 interrupts p2.16-p2.31
|
2013-03-18 00:40:53 +01:00
|
|
|
*
|
2013-04-03 21:35:21 +02:00
|
|
|
* LPC17_VALID_SHIFT2L 16 - Bit 16 is the first bit in a group of 16
|
|
|
|
* interrupts
|
2013-03-19 14:33:00 +01:00
|
|
|
* LPC17_VALID_FIRST2L irq - IRQ number associated with p2.0
|
2013-04-03 21:35:21 +02:00
|
|
|
* LPC17_VALID_NIRQS2L 16 - 16 interrupt bits in the group
|
2013-03-18 00:40:53 +01:00
|
|
|
*/
|
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
else if (irq >= LPC17_VALID_FIRST2H &&
|
|
|
|
irq < (LPC17_VALID_FIRST2H + LPC17_VALID_NIRQS2H))
|
2013-03-18 00:40:53 +01:00
|
|
|
{
|
|
|
|
return irq - LPC17_VALID_FIRST2H + LPC17_VALID_SHIFT2H;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-06-06 19:22:05 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-03-18 00:40:53 +01:00
|
|
|
|
2011-03-24 03:26:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: lpc17_gpiodemux
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Demux all interrupts on one GPIO interrupt status register.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void lpc17_gpiodemux(uint32_t intbase, uint32_t intmask,
|
|
|
|
int irqbase, void *context)
|
|
|
|
{
|
|
|
|
uint32_t intstatr;
|
|
|
|
uint32_t intstatf;
|
|
|
|
uint32_t intstatus;
|
|
|
|
uint32_t bit;
|
|
|
|
int irq;
|
|
|
|
|
|
|
|
/* Get the interrupt rising and falling edge status and mask out only the
|
|
|
|
* interrupts that are enabled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
intstatr = getreg32(intbase + LPC17_GPIOINT_INTSTATR_OFFSET);
|
|
|
|
intstatr &= getreg32(intbase + LPC17_GPIOINT_INTENR_OFFSET);
|
|
|
|
|
|
|
|
intstatf = getreg32(intbase + LPC17_GPIOINT_INTSTATF_OFFSET);
|
|
|
|
intstatf &= getreg32(intbase + LPC17_GPIOINT_INTENF_OFFSET);
|
|
|
|
|
|
|
|
/* And get the OR of the enabled interrupt sources. We do not make any
|
|
|
|
* distinction between rising and falling edges (but the hardware does support
|
2013-04-03 21:35:21 +02:00
|
|
|
* the ability to handle them differently if needed).
|
2011-03-24 03:26:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
intstatus = intstatr | intstatf;
|
|
|
|
|
|
|
|
/* Now march through the (valid) bits and dispatch each interrupt */
|
|
|
|
|
|
|
|
irq = irqbase;
|
|
|
|
bit = 1;
|
|
|
|
while (intstatus != 0)
|
|
|
|
{
|
|
|
|
/* Does this pin support an interrupt? If no, skip over it WITHOUT
|
|
|
|
* incrementing irq.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((intmask & bit) != 0)
|
|
|
|
{
|
|
|
|
/* This pin can support an interrupt. Is there an interrupt pending
|
|
|
|
* and enabled?
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((intstatus & bit) != 0)
|
|
|
|
{
|
|
|
|
/* Clear the interrupt status */
|
|
|
|
|
|
|
|
putreg32(bit, intbase + LPC17_GPIOINT_INTCLR_OFFSET);
|
|
|
|
|
|
|
|
/* And dispatch the interrupt */
|
|
|
|
|
|
|
|
irq_dispatch(irq, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment the IRQ number on each interrupt pin */
|
|
|
|
|
|
|
|
irq++;
|
|
|
|
}
|
2013-03-18 00:40:53 +01:00
|
|
|
|
2011-03-24 03:26:25 +01:00
|
|
|
/* Next bit */
|
|
|
|
|
|
|
|
intstatus &= ~bit;
|
|
|
|
bit <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: lpc17_gpiointerrupt
|
|
|
|
*
|
|
|
|
* Description:
|
2013-04-07 21:46:05 +02:00
|
|
|
* Handle the GPIO interrupt. For the LPC176x family, that interrupt could
|
|
|
|
* also that also indicates that an EINT3 interrupt has occurred. NOTE:
|
|
|
|
* This logic would have to be extended if EINT3 is actually used for
|
|
|
|
* External Interrupt 3 on an LPC176x platform.
|
2011-03-24 03:26:25 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int lpc17_gpiointerrupt(int irq, void *context)
|
|
|
|
{
|
|
|
|
/* Get the GPIO interrupt status */
|
|
|
|
|
|
|
|
uint32_t intstatus = getreg32(LPC17_GPIOINT_IOINTSTATUS);
|
|
|
|
|
|
|
|
/* Check for an interrupt on GPIO0 */
|
|
|
|
|
|
|
|
if ((intstatus & GPIOINT_IOINTSTATUS_P0INT) != 0)
|
|
|
|
{
|
|
|
|
lpc17_gpiodemux(LPC17_GPIOINT0_BASE, LPC17_VALID_GPIOINT0,
|
|
|
|
LPC17_VALID_FIRST0L, context);
|
|
|
|
}
|
|
|
|
|
2013-03-18 00:40:53 +01:00
|
|
|
#if defined(LPC176x)
|
2011-03-24 03:26:25 +01:00
|
|
|
/* Check for an interrupt on GPIO2 */
|
|
|
|
|
|
|
|
if ((intstatus & GPIOINT_IOINTSTATUS_P2INT) != 0)
|
|
|
|
{
|
|
|
|
lpc17_gpiodemux(LPC17_GPIOINT2_BASE, LPC17_VALID_GPIOINT2,
|
|
|
|
LPC17_VALID_FIRST2, context);
|
|
|
|
}
|
|
|
|
|
2013-03-18 00:40:53 +01:00
|
|
|
#elif defined(LPC178x)
|
|
|
|
/* Check for an interrupt on GPIO2 */
|
|
|
|
|
|
|
|
if ((intstatus & GPIOINT_IOINTSTATUS_P2INT) != 0)
|
|
|
|
{
|
|
|
|
lpc17_gpiodemux(LPC17_GPIOINT2_BASE, LPC17_VALID_GPIOINT2,
|
|
|
|
LPC17_VALID_FIRST2L, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-03-24 03:26:25 +01:00
|
|
|
return OK;
|
|
|
|
}
|
2010-06-06 19:11:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Global Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-03-24 03:26:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: lpc17_gpioirqinitialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize logic to support a second level of interrupt decoding for
|
|
|
|
* GPIO pins.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void lpc17_gpioirqinitialize(void)
|
|
|
|
{
|
|
|
|
/* Disable all GPIO interrupts */
|
|
|
|
|
|
|
|
putreg32(0, LPC17_GPIOINT0_INTENR);
|
|
|
|
putreg32(0, LPC17_GPIOINT0_INTENF);
|
|
|
|
putreg32(0, LPC17_GPIOINT2_INTENR);
|
|
|
|
putreg32(0, LPC17_GPIOINT2_INTENF);
|
|
|
|
|
2013-03-19 14:33:00 +01:00
|
|
|
/* Attach and enable the GPIO IRQ. */
|
|
|
|
|
|
|
|
#if defined(LPC176x)
|
|
|
|
/* For the LPC176x family, GPIO0 and GPIO2 interrupts share the same
|
|
|
|
* position in the NVIC with External Interrupt 3
|
2011-03-24 03:26:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
(void)irq_attach(LPC17_IRQ_EINT3, lpc17_gpiointerrupt);
|
|
|
|
up_enable_irq(LPC17_IRQ_EINT3);
|
2013-03-19 14:33:00 +01:00
|
|
|
|
|
|
|
#elif defined(LPC178x)
|
2013-04-03 21:35:21 +02:00
|
|
|
/* the LPC178x family has a single, dedicated interrupt for GPIO0 and
|
|
|
|
* GPIO2.
|
|
|
|
*/
|
2013-03-19 14:33:00 +01:00
|
|
|
|
|
|
|
(void)irq_attach(LPC17_IRQ_GPIO, lpc17_gpiointerrupt);
|
|
|
|
up_enable_irq(LPC17_IRQ_GPIO);
|
|
|
|
|
|
|
|
#endif
|
2011-03-24 03:26:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2010-06-06 19:11:15 +02:00
|
|
|
* Name: lpc17_gpioirqenable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enable the interrupt for specified GPIO IRQ
|
|
|
|
*
|
2011-03-24 03:26:25 +01:00
|
|
|
****************************************************************************/
|
2010-06-06 19:11:15 +02:00
|
|
|
|
|
|
|
void lpc17_gpioirqenable(int irq)
|
|
|
|
{
|
|
|
|
/* Map the IRQ number to a port number */
|
|
|
|
|
|
|
|
int port = lpc17_irq2port(irq);
|
|
|
|
if (port >= 0)
|
|
|
|
{
|
|
|
|
/* The IRQ number does correspond to an interrupt port. Now get the base
|
|
|
|
* address of the GPIOINT registers for the port.
|
|
|
|
*/
|
|
|
|
|
2011-03-24 03:26:25 +01:00
|
|
|
uint32_t intbase = g_intbase[port];
|
|
|
|
if (intbase != 0)
|
2010-06-06 19:11:15 +02:00
|
|
|
{
|
|
|
|
/* And get the pin number associated with the port */
|
|
|
|
|
2011-03-24 03:26:25 +01:00
|
|
|
unsigned int pin = lpc17_irq2pin(irq);
|
2010-06-06 19:11:15 +02:00
|
|
|
unsigned int edges = lpc17_getintedge(port, pin);
|
|
|
|
lpc17_setintedge(intbase, pin, edges);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-24 03:26:25 +01:00
|
|
|
/****************************************************************************
|
2010-06-06 19:11:15 +02:00
|
|
|
* Name: lpc17_gpioirqdisable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disable the interrupt for specified GPIO IRQ
|
|
|
|
*
|
2011-03-24 03:26:25 +01:00
|
|
|
****************************************************************************/
|
2010-06-06 19:11:15 +02:00
|
|
|
|
|
|
|
void lpc17_gpioirqdisable(int irq)
|
|
|
|
{
|
|
|
|
/* Map the IRQ number to a port number */
|
|
|
|
|
|
|
|
int port = lpc17_irq2port(irq);
|
|
|
|
if (port >= 0)
|
|
|
|
{
|
|
|
|
/* The IRQ number does correspond to an interrupt port. Now get the base
|
|
|
|
* address of the GPIOINT registers for the port.
|
|
|
|
*/
|
|
|
|
|
2011-03-24 03:26:25 +01:00
|
|
|
uint32_t intbase = g_intbase[port];
|
|
|
|
if (intbase != 0)
|
2010-06-06 19:11:15 +02:00
|
|
|
{
|
|
|
|
/* And get the pin number associated with the port */
|
|
|
|
|
2013-04-03 21:35:21 +02:00
|
|
|
unsigned int pin = lpc17_irq2pin(irq);
|
2010-06-06 19:11:15 +02:00
|
|
|
lpc17_setintedge(intbase, pin, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_GPIO_IRQ */
|
|
|
|
|