65a866fbe2
- MMC and SD Card driver - ported from imxrt_usdhc.c Squashed commit of the following: commit 46cbe18ad6a6e41ec2727d839f86f5670577878a Author: Adam Feuer <adam@starcat.io> Date: Wed Jul 15 10:28:02 2020 -0700 nxstyle change - Public Function Prototypes - instead of Public Functions commit 486b7b62e83a78ae15b114e34846900d8fef8248 Author: Adam Feuer <adam@starcat.io> Date: Wed Jul 15 10:06:51 2020 -0700 nxstyle changes commit 28280d585a40aac99fd0e538295828ea013739b7 Author: Adam Feuer <adam@starcat.io> Date: Wed Jul 15 10:06:29 2020 -0700 removing unused enum value commit 7da6ba437e7e023d348e63c497732fea985a2d1b Author: Adam Feuer <adam@starcat.io> Date: Tue Jul 14 21:17:49 2020 -0700 CI build error fixes - unused vars - incorrect method calls commit 145a73449b9d1eaed8a6cbf47cb53fb5b7a551f6 Author: Adam Feuer <adam@starcat.io> Date: Tue Jul 14 17:29:56 2020 -0700 adding #defines to prevent unused var warning commit 47ed2c08235816caded26a019cf33899daed1621 Author: Adam Feuer <adam@starcat.io> Date: Tue Jul 14 16:29:07 2020 -0700 removing obsolete config values commit b43f129c03a8bb8dc57ae6984d124ce9e9306196 Author: Adam Feuer <adam@starcat.io> Date: Tue Jul 14 09:58:42 2020 -0700 removed obsolete config setting commit 23e3af846ac24cac928442c7af86c5d0ef183ad3 Merge: 8b47330fe56f6d61eec4
Author: Adam Feuer <adam@starcat.io> Date: Tue Jul 14 09:53:12 2020 -0700 Merge remote-tracking branch 'upstream/master' into feature/sama5d27-sdmmc-support commit 8b47330fe5bb49bbd1991f2f3e2c69bdfb833d2c Author: Adam Feuer <adam@starcat.io> Date: Tue Jul 14 09:51:56 2020 -0700 replaced license headers with Apache License 2.0 commit 865e69b9a84d077ab9e05c2056dc7a515222c6c7 Author: Adam Feuer <adam@starcat.io> Date: Thu Jul 9 18:38:01 2020 -0700 SAMA5D2x SDMMC peripheral support (SD Card driver) - reading and writing at 25 MHz and 50Mhz - UHS_SDR50, UHS_DDR50, and UHS_SDR104 are supported - ported from imxrt_usdhc.c - only tested on SAMA5D27 Squashed commit of the following: commit e3122baef2feaeb32bb00798ae56310b2cc5c448 Author: Adam Feuer <adam@starcat.io> Date: Thu Jul 9 18:30:03 2020 -0700 added sdmmcnsh defconfig and basic docs commit 12a290d7465a0a006473ba67893bf891a7bcea83 Author: Adam Feuer <adam@starcat.io> Date: Thu Jul 9 17:50:06 2020 -0700 nxstyle changes commit 33409c0f63c328dc200150ba883327cadf0300b2 Author: Adam Feuer <adam@starcat.io> Date: Thu Jul 9 16:15:00 2020 -0700 add short delay to in recvshortcrc - to allow SDMMC to respond commit 3be7a7fb6f79900042d1fdbef72810f364ac5f62 Author: Adam Feuer <adam@adamfeuer.com> Date: Thu Jul 9 10:54:59 2020 -0700 added SDR50 and SDR104 SDMMC bus modes commit 2888408866548ca53e582ea1525178a7733617b4 Author: Adam Feuer <adam@adamfeuer.com> Date: Thu Jul 9 10:54:25 2020 -0700 comment formatting cleanup commit 06cf2c39193971155eaa6f9c89a39a88b53964a8 Author: Adam Feuer <adam@adamfeuer.com> Date: Thu Jul 9 10:34:01 2020 -0700 removed unneeded comment commit ac89b69231bdf19563754865fda93d4bbbb4488d Author: Adam Feuer <adam@adamfeuer.com> Date: Thu Jul 9 10:30:23 2020 -0700 code cleanup - removing custinfo() logging - remove duplicate #defines - move var declarations to the beginning of methods commit bcd4abec7935ee9023ab72edfb02685dbeee243c Author: Adam Feuer <adam@adamfeuer.com> Date: Wed Jul 8 16:34:31 2020 -0700 handle SDMA Boundary Pause interrupt (DMAINT) - SDMMC_INT_DINT - add to waitints - add handler to sam_interrupt commit e9da026c1270e999df520ee2c60487195799f58c Author: Adam Feuer <adam@adamfeuer.com> Date: Tue Jul 7 16:07:34 2020 -0700 Kconfig setting for SDMMC bus speed - 25 and 50 MHz - 50 MHz is the default commit 9edc636b7f18f981d653f85970c3af0b80801778 Author: Adam Feuer <adam@adamfeuer.com> Date: Mon Jul 6 21:55:51 2020 -0700 added HSEN bit change for high speed mode - above 26 MHz commit b8e91c95b0f7b2f8220f02b1eb42b6134e0660d0 Author: Adam Feuer <adam@adamfeuer.com> Date: Mon Jul 6 21:28:03 2020 -0700 added calloc to fix bug - not sure why this works. commit 1ceaf2f8487fe39d4d6fb21adecd57e4c4992e07 Author: Adam Feuer <adam@adamfeuer.com> Date: Mon Jul 6 21:25:47 2020 -0700 removing spurious typo characters commit 14ba51743bcca35686b07a76f5af17bcce078a5f Author: Adam Feuer <adam@adamfeuer.com> Date: Sat Jul 4 18:10:46 2020 -0700 nxstyle changes commit d8af26df47b7840117de0d3a44ec548b3a72bc2b Author: Adam Feuer <adam@adamfeuer.com> Date: Sat Jul 4 17:01:11 2020 -0700 nxstyle changes commit 0ae532bd62d02c5ac36aa2192f31fa1f7f1cde99 Author: Adam Feuer <adam@adamfeuer.com> Date: Sat Jul 4 16:37:17 2020 -0700 remove long lines in comments - nxstyle commit 3d025a84f8e9ddb7f7a4570504118d782dd5574c Author: Adam Feuer <adam@adamfeuer.com> Date: Sat Jul 4 16:36:52 2020 -0700 removed custinfo logging commit 366b5d9d241a42d693583679cb49aa7bf25615aa Author: Adam Feuer <adam@adamfeuer.com> Date: Sat Jul 4 16:35:08 2020 -0700 removed custinfo logging commit c74396e4a4943873c7de5b6ffee193787c39baef Author: Adam Feuer <adam@adamfeuer.com> Date: Sat Jul 4 16:34:36 2020 -0700 fixed typo commit 7f51e99d7f4c1e5e0bf71a84fd0b2467157fea59 Merge: c40f8c10392481b1bfd5
Author: Adam Feuer <adam@adamfeuer.com> Date: Sat Jul 4 15:33:06 2020 -0700 Merge remote-tracking branch 'upstream/master' into feature/sama5d27-sdmmc-support commit c40f8c10390ecefeb3a113046edd6740b07ab31b Author: Adam Feuer <adam@adamfeuer.com> Date: Thu Jul 2 22:08:20 2020 -0700 SDMMC support for SAMA5D27
526 lines
14 KiB
C
526 lines
14 KiB
C
/****************************************************************************
|
|
* arch/arm/src/sama5/sam_pioirq.c
|
|
*
|
|
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
*
|
|
* 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 <assert.h>
|
|
#include <errno.h>
|
|
#include <debug.h>
|
|
|
|
#include <nuttx/init.h>
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <arch/irq.h>
|
|
#include <arch/board/board.h>
|
|
|
|
#include "arm_arch.h"
|
|
#include "arm_internal.h"
|
|
|
|
#include "hardware/sam_pio.h"
|
|
#include "hardware/sam_pmc.h"
|
|
|
|
#include "sam_pio.h"
|
|
#include "sam_periphclks.h"
|
|
|
|
#ifdef CONFIG_SAMA5_PIO_IRQ
|
|
|
|
/****************************************************************************
|
|
* Pre-processor Definitions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Private Data
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Public Data
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Private Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: sam_piobase
|
|
*
|
|
* Description:
|
|
* Return the base address of the PIO register set
|
|
*
|
|
****************************************************************************/
|
|
|
|
static inline uint32_t sam_piobase(pio_pinset_t pinset)
|
|
{
|
|
int port = (pinset & PIO_PORT_MASK) >> PIO_PORT_SHIFT;
|
|
return sam_pion_vbase(port >> PIO_PORT_SHIFT);
|
|
}
|
|
|
|
/****************************************************************************
|
|
* Name: sam_piopin
|
|
*
|
|
* Description:
|
|
* Return the base address of the PIO register set
|
|
*
|
|
****************************************************************************/
|
|
|
|
static inline int sam_piopin(pio_pinset_t pinset)
|
|
{
|
|
return 1 << ((pinset & PIO_PIN_MASK) >> PIO_PIN_SHIFT);
|
|
}
|
|
|
|
/****************************************************************************
|
|
* Name: sam_irqbase
|
|
*
|
|
* Description:
|
|
* Return PIO information associated with this IRQ
|
|
*
|
|
****************************************************************************/
|
|
|
|
static int sam_irqbase(int irq, uint32_t *base, int *pin)
|
|
{
|
|
if (irq >= SAM_IRQ_NINT)
|
|
{
|
|
#ifdef CONFIG_SAMA5_PIOA_IRQ
|
|
if (irq <= SAM_IRQ_PA31)
|
|
{
|
|
*base = SAM_PIOA_VBASE;
|
|
*pin = irq - SAM_IRQ_PA0;
|
|
return OK;
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAMA5_PIOB_IRQ
|
|
if (irq <= SAM_IRQ_PB31)
|
|
{
|
|
*base = SAM_PIOB_VBASE;
|
|
*pin = irq - SAM_IRQ_PB0;
|
|
return OK;
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAMA5_PIOC_IRQ
|
|
if (irq <= SAM_IRQ_PC31)
|
|
{
|
|
*base = SAM_PIOC_VBASE;
|
|
*pin = irq - SAM_IRQ_PC0;
|
|
return OK;
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAMA5_PIOD_IRQ
|
|
if (irq <= SAM_IRQ_PD31)
|
|
{
|
|
*base = SAM_PIOD_VBASE;
|
|
*pin = irq - SAM_IRQ_PD0;
|
|
return OK;
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAMA5_PIOE_IRQ
|
|
if (irq <= SAM_IRQ_PE31)
|
|
{
|
|
*base = SAM_PIOE_VBASE;
|
|
*pin = irq - SAM_IRQ_PE0;
|
|
return OK;
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAMA5_PIOF_IRQ
|
|
if (irq <= SAM_IRQ_PF31)
|
|
{
|
|
*base = SAM_PIOF_VBASE;
|
|
*pin = irq - SAM_IRQ_PF0;
|
|
return OK;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
return -EINVAL;
|
|
}
|
|
|
|
/****************************************************************************
|
|
* Name: sam_pioa/b/c/d/e/finterrupt
|
|
*
|
|
* Description:
|
|
* Receive PIOA/B/C/D/E/F interrupts
|
|
*
|
|
****************************************************************************/
|
|
|
|
static int sam_piointerrupt(uint32_t base, int irq0, void *context)
|
|
{
|
|
uint32_t pending;
|
|
uint32_t bit;
|
|
int irq;
|
|
|
|
pending = getreg32(base + SAM_PIO_ISR_OFFSET) & getreg32(base +
|
|
SAM_PIO_IMR_OFFSET);
|
|
for (bit = 1, irq = irq0; pending != 0; bit <<= 1, irq++)
|
|
{
|
|
if ((pending & bit) != 0)
|
|
{
|
|
/* Re-deliver the IRQ (recurses! We got here from irq_dispatch!) */
|
|
|
|
irq_dispatch(irq, context);
|
|
|
|
/* Remove this from the set of pending interrupts */
|
|
|
|
pending &= ~bit;
|
|
}
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
#ifdef CONFIG_SAMA5_PIOA_IRQ
|
|
static int sam_pioainterrupt(int irq, void *context, FAR void *arg)
|
|
{
|
|
return sam_piointerrupt(SAM_PIOA_VBASE, SAM_IRQ_PA0, context);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAMA5_PIOB_IRQ
|
|
static int sam_piobinterrupt(int irq, void *context, FAR void *arg)
|
|
{
|
|
return sam_piointerrupt(SAM_PIOB_VBASE, SAM_IRQ_PB0, context);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAMA5_PIOC_IRQ
|
|
static int sam_piocinterrupt(int irq, void *context, FAR void *arg)
|
|
{
|
|
return sam_piointerrupt(SAM_PIOC_VBASE, SAM_IRQ_PC0, context);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAMA5_PIOD_IRQ
|
|
static int sam_piodinterrupt(int irq, void *context, FAR void *arg)
|
|
{
|
|
return sam_piointerrupt(SAM_PIOD_VBASE, SAM_IRQ_PD0, context);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAMA5_PIOE_IRQ
|
|
static int sam_pioeinterrupt(int irq, void *context, FAR void *arg)
|
|
{
|
|
return sam_piointerrupt(SAM_PIOE_VBASE, SAM_IRQ_PE0, context);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAMA5_PIOF_IRQ
|
|
static int sam_piofinterrupt(int irq, void *context, FAR void *arg)
|
|
{
|
|
return sam_piointerrupt(SAM_PIOF_VBASE, SAM_IRQ_PF0, context);
|
|
}
|
|
#endif
|
|
|
|
/****************************************************************************
|
|
* Public Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: sam_pioirqinitialize
|
|
*
|
|
* Description:
|
|
* Initialize logic to support a second level of interrupt decoding for
|
|
* PIO pins.
|
|
*
|
|
****************************************************************************/
|
|
|
|
void sam_pioirqinitialize(void)
|
|
{
|
|
/* Configure PIOA interrupts */
|
|
|
|
#ifdef CONFIG_SAMA5_PIOA_IRQ
|
|
/* Enable PIOA clocking */
|
|
|
|
sam_pioa_enableclk();
|
|
|
|
/* Clear and disable all PIOA interrupts */
|
|
|
|
getreg32(SAM_PIOA_ISR);
|
|
putreg32(0xffffffff, SAM_PIOA_IDR);
|
|
|
|
/* Attach and enable the PIOA IRQ */
|
|
|
|
irq_attach(SAM_IRQ_PIOA, sam_pioainterrupt, NULL);
|
|
up_enable_irq(SAM_IRQ_PIOA);
|
|
#endif
|
|
|
|
/* Configure PIOB interrupts */
|
|
|
|
#ifdef CONFIG_SAMA5_PIOB_IRQ
|
|
/* Enable PIOB clocking */
|
|
|
|
sam_piob_enableclk();
|
|
|
|
/* Clear and disable all PIOB interrupts */
|
|
|
|
getreg32(SAM_PIOB_ISR);
|
|
putreg32(0xffffffff, SAM_PIOB_IDR);
|
|
|
|
/* Attach and enable the PIOB IRQ */
|
|
|
|
irq_attach(SAM_IRQ_PIOB, sam_piobinterrupt, NULL);
|
|
up_enable_irq(SAM_IRQ_PIOB);
|
|
#endif
|
|
|
|
/* Configure PIOC interrupts */
|
|
|
|
#ifdef CONFIG_SAMA5_PIOC_IRQ
|
|
/* Enable PIOC clocking */
|
|
|
|
sam_pioc_enableclk();
|
|
|
|
/* Clear and disable all PIOC interrupts */
|
|
|
|
getreg32(SAM_PIOC_ISR);
|
|
putreg32(0xffffffff, SAM_PIOC_IDR);
|
|
|
|
/* Attach and enable the PIOC IRQ */
|
|
|
|
irq_attach(SAM_IRQ_PIOC, sam_piocinterrupt, NULL);
|
|
up_enable_irq(SAM_IRQ_PIOC);
|
|
#endif
|
|
|
|
/* Configure PIOD interrupts */
|
|
|
|
#ifdef CONFIG_SAMA5_PIOD_IRQ
|
|
/* Enable PIOD clocking */
|
|
|
|
sam_piod_enableclk();
|
|
|
|
/* Clear and disable all PIOD interrupts */
|
|
|
|
getreg32(SAM_PIOD_ISR);
|
|
putreg32(0xffffffff, SAM_PIOD_IDR);
|
|
|
|
/* Attach and enable the PIOC IRQ */
|
|
|
|
irq_attach(SAM_IRQ_PIOD, sam_piodinterrupt, NULL);
|
|
up_enable_irq(SAM_IRQ_PIOD);
|
|
#endif
|
|
|
|
/* Configure PIOE interrupts */
|
|
|
|
#ifdef CONFIG_SAMA5_PIOE_IRQ
|
|
/* Enable PIOE clocking */
|
|
|
|
sam_pioe_enableclk();
|
|
|
|
/* Clear and disable all PIOE interrupts */
|
|
|
|
getreg32(SAM_PIOE_ISR);
|
|
putreg32(0xffffffff, SAM_PIOE_IDR);
|
|
|
|
/* Attach and enable the PIOE IRQ */
|
|
|
|
irq_attach(SAM_IRQ_PIOE, sam_pioeinterrupt, NULL);
|
|
up_enable_irq(SAM_IRQ_PIOE);
|
|
#endif
|
|
|
|
/* Configure PIOF interrupts */
|
|
|
|
#ifdef CONFIG_SAMA5_PIOF_IRQ
|
|
/* Enable PIOF clocking */
|
|
|
|
sam_piof_enableclk();
|
|
|
|
/* Clear and disable all PIOF interrupts */
|
|
|
|
getreg32(SAM_PIOF_ISR);
|
|
putreg32(0xffffffff, SAM_PIOF_IDR);
|
|
|
|
/* Attach and enable the PIOF IRQ */
|
|
|
|
irq_attach(SAM_IRQ_PIOF, sam_piofinterrupt, NULL);
|
|
up_enable_irq(SAM_IRQ_PIOF);
|
|
#endif
|
|
}
|
|
|
|
/****************************************************************************
|
|
* Name: sam_pioirq
|
|
*
|
|
* Description:
|
|
* Configure an interrupt for the specified PIO pin.
|
|
*
|
|
****************************************************************************/
|
|
|
|
void sam_pioirq(pio_pinset_t pinset)
|
|
{
|
|
#if defined(SAM_PIO_ISLR_OFFSET)
|
|
uint32_t regval;
|
|
#endif
|
|
#if defined(SAM_PIO_ISLR_OFFSET) || defined(_PIO_INT_AIM)
|
|
uint32_t base = sam_piobase(pinset);
|
|
int pin = sam_piopin(pinset);
|
|
#endif
|
|
|
|
#if defined(SAM_PIO_ISLR_OFFSET)
|
|
/* Enable writing to PIO registers. The following registers are protected:
|
|
*
|
|
* - PIO Enable/Disable Registers (PER/PDR)
|
|
* - PIO Output Enable/Disable Registers (OER/ODR)
|
|
* - PIO Interrupt Security Level Register (ISLR)
|
|
* - PIO Input Filter Enable/Disable Registers (IFER/IFDR)
|
|
* - PIO Multi-driver Enable/Disable Registers (MDER/MDDR)
|
|
* - PIO Pull-Up Enable/Disable Registers (PUER/PUDR)
|
|
* - PIO Peripheral ABCD Select Register 1/2 (ABCDSR1/2)
|
|
* - PIO Output Write Enable/Disable Registers
|
|
* - PIO Pad Pull-Down Enable/Disable Registers (PPER/PPDR)
|
|
*
|
|
* I suspect that the default state is the WPMR is unprotected, so these
|
|
* operations could probably all be avoided.
|
|
*/
|
|
|
|
putreg32(PIO_WPMR_WPKEY, base + SAM_PIO_WPMR_OFFSET);
|
|
|
|
/* Is the interrupt secure? */
|
|
|
|
regval = getreg32(base + SAM_PIO_ISLR_OFFSET);
|
|
if ((pinset & PIO_INT_SECURE) != 0)
|
|
{
|
|
/* Yes.. make sure that the corresponding bit in ISLR is cleared */
|
|
|
|
regval &= ~pin;
|
|
}
|
|
else
|
|
{
|
|
/* Yes.. make sure that the corresponding bit in ISLR is set */
|
|
|
|
regval |= pin;
|
|
}
|
|
|
|
putreg32(regval, base + SAM_PIO_ISLR_OFFSET);
|
|
#endif
|
|
|
|
/* Are any additional interrupt modes selected? */
|
|
|
|
#ifdef _PIO_INT_AIM
|
|
if ((pinset & _PIO_INT_AIM) != 0)
|
|
{
|
|
/* Yes.. Enable additional interrupt mode */
|
|
|
|
putreg32(pin, base + SAM_PIO_AIMER_OFFSET);
|
|
|
|
/* Level or edge detected interrupt? */
|
|
|
|
if ((pinset & _PIO_INT_LEVEL) != 0)
|
|
{
|
|
putreg32(pin, base + SAM_PIO_LSR_OFFSET); /* Level */
|
|
}
|
|
else
|
|
{
|
|
putreg32(pin, base + SAM_PIO_ESR_OFFSET); /* Edge */
|
|
}
|
|
|
|
/* High level/rising edge or low level /falling edge? */
|
|
|
|
if ((pinset & _PIO_INT_RH) != 0)
|
|
{
|
|
/* High level/Rising edge */
|
|
|
|
putreg32(pin, base + SAM_PIO_REHLSR_OFFSET);
|
|
}
|
|
else
|
|
{
|
|
/* Low level/Falling edge */
|
|
|
|
putreg32(pin, base + SAM_PIO_FELLSR_OFFSET);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* No.. Disable additional interrupt mode */
|
|
|
|
putreg32(pin, base + SAM_PIO_AIMDR_OFFSET);
|
|
}
|
|
#endif
|
|
|
|
#if defined(SAM_PIO_ISLR_OFFSET)
|
|
/* Disable writing to PIO registers */
|
|
|
|
putreg32(PIO_WPMR_WPEN | PIO_WPMR_WPKEY, base + SAM_PIO_WPMR_OFFSET);
|
|
#endif
|
|
}
|
|
|
|
/****************************************************************************
|
|
* Name: sam_pioirqenable
|
|
*
|
|
* Description:
|
|
* Enable the interrupt for specified PIO IRQ
|
|
*
|
|
****************************************************************************/
|
|
|
|
void sam_pioirqenable(int irq)
|
|
{
|
|
uint32_t base;
|
|
int pin;
|
|
|
|
if (sam_irqbase(irq, &base, &pin) == OK)
|
|
{
|
|
/* Clear (all) pending interrupts and enable this pin interrupt */
|
|
|
|
(void)getreg32(base + SAM_PIO_ISR_OFFSET);
|
|
putreg32((1 << pin), base + SAM_PIO_IER_OFFSET);
|
|
}
|
|
}
|
|
|
|
/****************************************************************************
|
|
* Name: sam_pioirqdisable
|
|
*
|
|
* Description:
|
|
* Disable the interrupt for specified PIO IRQ
|
|
*
|
|
****************************************************************************/
|
|
|
|
void sam_pioirqdisable(int irq)
|
|
{
|
|
uint32_t base;
|
|
int pin;
|
|
|
|
if (sam_irqbase(irq, &base, &pin) == OK)
|
|
{
|
|
/* Disable this pin interrupt */
|
|
|
|
putreg32((1 << pin), base + SAM_PIO_IDR_OFFSET);
|
|
}
|
|
}
|
|
|
|
#endif /* CONFIG_SAMA5_PIO_IRQ */
|