nuttx/arch/arm/src/stm32f0l0g0/stm32_irq.c

342 lines
10 KiB
C
Raw Normal View History

2017-04-14 08:06:01 -06:00
/****************************************************************************
* arch/arm/src/stm32f0l0g0/stm32_irq.c
2017-04-14 08:06:01 -06:00
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Alan Carvalho de Assis <acassis@gmail.com>
2017-04-14 08:06:01 -06: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 <debug.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <arch/irq.h>
#include "nvic.h"
#include "arm_arch.h"
#include "arm_internal.h"
2017-04-14 08:06:01 -06:00
//#include "stm32_irq.h"
2017-04-14 08:06:01 -06:00
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Get a 32-bit version of the default priority */
#define DEFPRIORITY32 \
(NVIC_SYSH_PRIORITY_DEFAULT << 24 | NVIC_SYSH_PRIORITY_DEFAULT << 16 | \
NVIC_SYSH_PRIORITY_DEFAULT << 8 | NVIC_SYSH_PRIORITY_DEFAULT)
/****************************************************************************
* Public Data
****************************************************************************/
/* g_current_regs[] holds a references to the current interrupt level
* register storage structure. If is non-NULL only during interrupt
* processing. Access to g_current_regs[] must be through the macro
* CURRENT_REGS for portability.
*/
volatile uint32_t *g_current_regs[1];
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_dumpnvic
2017-04-14 08:06:01 -06:00
*
* Description:
* Dump some interesting NVIC registers
*
****************************************************************************/
#if defined(CONFIG_DEBUG_IRQ_INFO)
static void stm32_dumpnvic(const char *msg, int irq)
2017-04-14 08:06:01 -06:00
{
irqstate_t flags;
flags = enter_critical_section();
irqinfo("NVIC (%s, irq=%d):\n", msg, irq);
irqinfo(" ISER: %08x ICER: %08x\n",
getreg32(ARMV6M_NVIC_ISER), getreg32(ARMV6M_NVIC_ICER));
irqinfo(" ISPR: %08x ICPR: %08x\n",
getreg32(ARMV6M_NVIC_ISPR), getreg32(ARMV6M_NVIC_ICPR));
irqinfo(" IRQ PRIO: %08x %08x %08x %08x\n",
getreg32(ARMV6M_NVIC_IPR0), getreg32(ARMV6M_NVIC_IPR1),
getreg32(ARMV6M_NVIC_IPR2), getreg32(ARMV6M_NVIC_IPR3));
irqinfo(" %08x %08x %08x %08x\n",
getreg32(ARMV6M_NVIC_IPR4), getreg32(ARMV6M_NVIC_IPR5),
getreg32(ARMV6M_NVIC_IPR6), getreg32(ARMV6M_NVIC_IPR7));
irqinfo("SYSCON:\n");
irqinfo(" CPUID: %08x\n",
getreg32(ARMV6M_SYSCON_CPUID));
irqinfo(" ICSR: %08x AIRCR: %08x\n",
getreg32(ARMV6M_SYSCON_ICSR), getreg32(ARMV6M_SYSCON_AIRCR));
irqinfo(" SCR: %08x CCR: %08x\n",
getreg32(ARMV6M_SYSCON_SCR), getreg32(ARMV6M_SYSCON_CCR));
irqinfo(" SHPR2: %08x SHPR3: %08x\n",
getreg32(ARMV6M_SYSCON_SHPR2), getreg32(ARMV6M_SYSCON_SHPR3));
leave_critical_section(flags);
}
#else
# define stm32_dumpnvic(msg, irq)
2017-04-14 08:06:01 -06:00
#endif
/****************************************************************************
* Name: stm32_nmi, stm32_busfault, stm32_usagefault, stm32_pendsv,
* stm32_dbgmonitor, stm32_pendsv, stm32_reserved
2017-04-14 08:06:01 -06:00
*
* Description:
* Handlers for various exceptions. None are handled and all are fatal
2017-04-14 08:06:01 -06:00
* error conditions. The only advantage these provided over the default
* unexpected interrupt handler is that they provide a diagnostic output.
*
****************************************************************************/
#ifdef CONFIG_DEBUG_FEATURES
static int stm32_nmi(int irq, FAR void *context, FAR void *arg)
2017-04-14 08:06:01 -06:00
{
up_irq_save();
2017-04-14 08:06:01 -06:00
_err("PANIC!!! NMI received\n");
PANIC();
return 0;
}
static int stm32_pendsv(int irq, FAR void *context, FAR void *arg)
2017-04-14 08:06:01 -06:00
{
up_irq_save();
2017-04-14 08:06:01 -06:00
_err("PANIC!!! PendSV received\n");
PANIC();
return 0;
}
static int stm32_reserved(int irq, FAR void *context, FAR void *arg)
2017-04-14 08:06:01 -06:00
{
up_irq_save();
2017-04-14 08:06:01 -06:00
_err("PANIC!!! Reserved interrupt\n");
PANIC();
return 0;
}
#endif
/****************************************************************************
* Name: stm32_clrpend
2017-04-14 08:06:01 -06:00
*
* Description:
* Clear a pending interrupt at the NVIC.
*
****************************************************************************/
static inline void stm32_clrpend(int irq)
2017-04-14 08:06:01 -06:00
{
/* This will be called on each interrupt exit whether the interrupt can be
* enambled or not. So this assertion is necessarily lame.
*/
DEBUGASSERT((unsigned)irq < NR_IRQS);
/* Check for an external interrupt */
if (irq >= STM32_IRQ_EXTINT && irq < (STM32_IRQ_EXTINT + 32))
2017-04-14 08:06:01 -06:00
{
/* Set the appropriate bit in the ISER register to enable the
* interrupt
*/
putreg32((1 << (irq - STM32_IRQ_EXTINT)), ARMV6M_NVIC_ICPR);
2017-04-14 08:06:01 -06:00
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_irqinitialize
****************************************************************************/
void up_irqinitialize(void)
{
uint32_t regaddr;
int i;
/* Disable all interrupts */
putreg32(0xffffffff, ARMV6M_NVIC_ICER);
/* Set all interrupts (and exceptions) to the default priority */
putreg32(DEFPRIORITY32, ARMV6M_SYSCON_SHPR2);
putreg32(DEFPRIORITY32, ARMV6M_SYSCON_SHPR3);
/* Now set all of the interrupt lines to the default priority */
for (i = 0; i < 8; i++)
{
regaddr = ARMV6M_NVIC_IPR(i);
putreg32(DEFPRIORITY32, regaddr);
}
/* currents_regs is non-NULL only while processing an interrupt */
CURRENT_REGS = NULL;
/* Attach the SVCall and Hard Fault exception handlers. The SVCall
* exception is used for performing context switches; The Hard Fault
* must also be caught because a SVCall may show up as a Hard Fault
* under certain conditions.
*/
irq_attach(STM32_IRQ_SVCALL, arm_svcall, NULL);
irq_attach(STM32_IRQ_HARDFAULT, arm_hardfault, NULL);
2017-04-14 08:06:01 -06:00
/* Attach all other processor exceptions (except reset and sys tick) */
#ifdef CONFIG_DEBUG_FEATURES
irq_attach(STM32_IRQ_NMI, stm32_nmi, NULL);
irq_attach(STM32_IRQ_PENDSV, stm32_pendsv, NULL);
irq_attach(STM32_IRQ_RESERVED, stm32_reserved, NULL);
2017-04-14 08:06:01 -06:00
#endif
stm32_dumpnvic("initial", NR_IRQS);
2017-04-14 08:06:01 -06:00
/* Initialize logic to support a second level of interrupt decoding for
* configured pin interrupts.
*/
#ifdef CONFIG_STM32F0L0G0_GPIOIRQ
stm32_gpioirqinitialize();
2017-04-14 08:06:01 -06:00
#endif
#ifndef CONFIG_SUPPRESS_INTERRUPTS
/* And finally, enable interrupts */
up_irq_enable();
#endif
}
/****************************************************************************
* Name: up_disable_irq
*
* Description:
* Disable the IRQ specified by 'irq'
*
****************************************************************************/
void up_disable_irq(int irq)
{
DEBUGASSERT((unsigned)irq < NR_IRQS);
/* Check for an external interrupt */
if (irq >= STM32_IRQ_EXTINT && irq < (STM32_IRQ_EXTINT + 32))
2017-04-14 08:06:01 -06:00
{
/* Set the appropriate bit in the ICER register to disable the
* interrupt
*/
putreg32((1 << (irq - STM32_IRQ_EXTINT)), ARMV6M_NVIC_ICER);
2017-04-14 08:06:01 -06:00
}
/* Handle processor exceptions. Only SysTick can be disabled */
else if (irq == STM32_IRQ_SYSTICK)
2017-04-14 08:06:01 -06:00
{
modifyreg32(ARMV6M_SYSTICK_CSR, SYSTICK_CSR_ENABLE, 0);
}
stm32_dumpnvic("disable", irq);
2017-04-14 08:06:01 -06:00
}
/****************************************************************************
* Name: up_enable_irq
*
* Description:
* Enable the IRQ specified by 'irq'
*
****************************************************************************/
void up_enable_irq(int irq)
{
/* This will be called on each interrupt exit whether the interrupt can be
* enabled or not. So this assertion is necessarily lame.
*/
DEBUGASSERT((unsigned)irq < NR_IRQS);
/* Check for external interrupt */
if (irq >= STM32_IRQ_EXTINT && irq < (STM32_IRQ_EXTINT + 32))
2017-04-14 08:06:01 -06:00
{
/* Set the appropriate bit in the ISER register to enable the
* interrupt
*/
putreg32((1 << (irq - STM32_IRQ_EXTINT)), ARMV6M_NVIC_ISER);
2017-04-14 08:06:01 -06:00
}
/* Handle processor exceptions. Only SysTick can be disabled */
else if (irq == STM32_IRQ_SYSTICK)
2017-04-14 08:06:01 -06:00
{
modifyreg32(ARMV6M_SYSTICK_CSR, 0, SYSTICK_CSR_ENABLE);
}
stm32_dumpnvic("enable", irq);
2017-04-14 08:06:01 -06:00
}
/****************************************************************************
* Name: arm_ack_irq
2017-04-14 08:06:01 -06:00
*
* Description:
* Acknowledge the IRQ
*
****************************************************************************/
void arm_ack_irq(int irq)
2017-04-14 08:06:01 -06:00
{
stm32_clrpend(irq);
2017-04-14 08:06:01 -06:00
}