2016-10-12 21:11:05 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/xtensa/include/irq.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-05 23:00:04 +02:00
|
|
|
/* This file should never be included directly but, rather, only indirectly
|
2016-10-12 21:11:05 +02:00
|
|
|
* through nuttx/irq.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ARCH_XTENSA_INCLUDE_IRQ_H
|
|
|
|
#define __ARCH_XTENSA_INCLUDE_IRQ_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Include NuttX-specific IRQ definitions */
|
|
|
|
|
2016-10-23 16:00:17 +02:00
|
|
|
#include <nuttx/config.h>
|
2016-10-12 21:11:05 +02:00
|
|
|
#include <nuttx/irq.h>
|
2016-10-29 18:27:46 +02:00
|
|
|
|
2016-10-15 20:23:36 +02:00
|
|
|
#include <arch/types.h>
|
2016-10-29 18:27:46 +02:00
|
|
|
#include <arch/chip/tie.h>
|
2016-10-20 19:44:14 +02:00
|
|
|
#include <arch/chip/core-isa.h>
|
2016-10-29 18:27:46 +02:00
|
|
|
|
2016-10-23 16:04:57 +02:00
|
|
|
#include <arch/xtensa/xtensa_specregs.h>
|
|
|
|
#include <arch/xtensa/xtensa_corebits.h>
|
2016-10-28 18:33:20 +02:00
|
|
|
#include <arch/xtensa/xtensa_coproc.h>
|
2016-10-12 21:11:05 +02:00
|
|
|
|
2016-10-12 22:50:28 +02:00
|
|
|
/* Include architecture-specific IRQ definitions */
|
2016-10-12 21:11:05 +02:00
|
|
|
|
2016-10-13 22:48:29 +02:00
|
|
|
#ifdef CONFIG_ARCH_FAMILY_LX6
|
2016-10-12 22:50:28 +02:00
|
|
|
# include <arch/lx6/irq.h>
|
|
|
|
|
|
|
|
/* Include implementation-specific IRQ definitions (including IRQ numbers) */
|
|
|
|
|
|
|
|
# ifdef CONFIG_ARCH_CHIP_ESP32
|
|
|
|
# include <arch/esp32/irq.h>
|
|
|
|
# else
|
|
|
|
# error Unknown LX6 implementation
|
|
|
|
# endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
# error Unknown XTENSA architecture
|
|
|
|
#endif
|
2016-10-12 21:11:05 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-10-14 21:17:48 +02:00
|
|
|
/* IRQ Stack Frame Format. Each value is a uint32_t register index */
|
|
|
|
|
2016-10-20 19:44:14 +02:00
|
|
|
#define REG_PC (0) /* Return PC */
|
|
|
|
#define REG_PS (1) /* Return PS */
|
|
|
|
#define REG_A0 (2)
|
|
|
|
#define REG_A1 (3) /* Stack pointer before interrupt */
|
|
|
|
#define REG_A2 (4)
|
|
|
|
#define REG_A3 (5)
|
|
|
|
#define REG_A4 (6)
|
|
|
|
#define REG_A5 (7)
|
|
|
|
#define REG_A6 (8)
|
|
|
|
#define REG_A7 (9)
|
|
|
|
#define REG_A8 (10)
|
|
|
|
#define REG_A9 (11)
|
|
|
|
#define REG_A10 (12)
|
|
|
|
#define REG_A11 (13)
|
|
|
|
#define REG_A12 (14)
|
|
|
|
#define REG_A13 (15)
|
|
|
|
#define REG_A14 (16)
|
|
|
|
#define REG_A15 (17)
|
|
|
|
#define REG_SAR (18)
|
|
|
|
#define REG_EXCCAUSE (19)
|
|
|
|
#define REG_EXCVADDR (20)
|
|
|
|
|
|
|
|
#define _REG_LOOPS_START (21)
|
|
|
|
|
2016-10-22 17:03:43 +02:00
|
|
|
#ifdef XCHAL_HAVE_LOOPS
|
2016-10-14 21:17:48 +02:00
|
|
|
# define REG_LBEG (_REG_LOOPS_START + 0)
|
|
|
|
# define REG_LEND (_REG_LOOPS_START + 1)
|
|
|
|
# define REG_LCOUNT (_REG_LOOPS_START + 2)
|
2016-12-16 16:20:36 +01:00
|
|
|
# define _REG_WINDOW_TMPS (_REG_LOOPS_START + 3)
|
2016-10-14 21:17:48 +02:00
|
|
|
#else
|
2016-12-16 16:20:36 +01:00
|
|
|
# define _REG_WINDOW_TMPS _REG_LOOPS_START
|
2016-10-14 21:17:48 +02:00
|
|
|
#endif
|
|
|
|
|
2016-10-30 14:37:51 +01:00
|
|
|
#ifndef __XTENSA_CALL0_ABI__
|
2016-12-16 16:20:36 +01:00
|
|
|
/* Temporary space for saving stuff during window spill.
|
|
|
|
* REVISIT: I don't think that we need so many temporaries.
|
|
|
|
*/
|
2016-10-14 21:17:48 +02:00
|
|
|
|
2016-12-16 16:20:36 +01:00
|
|
|
# define REG_TMP0 (_REG_WINDOW_TMPS + 0)
|
|
|
|
# define REG_TMP1 (_REG_WINDOW_TMPS + 1)
|
|
|
|
# define _REG_OVLY_START (_REG_WINDOW_TMPS + 2)
|
2016-10-14 21:17:48 +02:00
|
|
|
#else
|
2016-12-16 16:20:36 +01:00
|
|
|
# define _REG_OVLY_START _REG_WINDOW_TMPS
|
2016-10-14 21:17:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_XTENSA_USE_OVLY
|
|
|
|
/* Storage for overlay state */
|
|
|
|
|
2016-10-23 14:24:35 +02:00
|
|
|
# error Overlays not supported
|
2016-10-23 18:06:30 +02:00
|
|
|
# define XCPTCONTEXT_REGS _REG_OVLY_START
|
2016-10-14 21:17:48 +02:00
|
|
|
#else
|
2016-10-23 18:06:30 +02:00
|
|
|
# define XCPTCONTEXT_REGS _REG_OVLY_START
|
2016-10-14 21:17:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define XCPTCONTEXT_SIZE (4 * XCPTCONTEXT_REGS)
|
|
|
|
|
2016-10-12 21:11:05 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
2016-10-14 21:17:48 +02:00
|
|
|
/* This struct defines the way the registers are stored. */
|
|
|
|
|
|
|
|
struct xcptcontext
|
|
|
|
{
|
|
|
|
/* The following function pointer is non-zero if there are pending signals
|
|
|
|
* to be processed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void *sigdeliver; /* Actual type is sig_deliver_t */
|
|
|
|
|
2019-02-04 15:35:03 +01:00
|
|
|
/* These are saved copies of registers used during signal processing.
|
|
|
|
*
|
|
|
|
* REVISIT: Because there is only one copy of these save areas,
|
|
|
|
* only a single signal handler can be active. This precludes
|
|
|
|
* queuing of signal actions. As a result, signals received while
|
|
|
|
* another signal handler is executing will be ignored!
|
|
|
|
*/
|
2016-10-14 21:17:48 +02:00
|
|
|
|
|
|
|
uint32_t saved_pc;
|
2016-10-23 17:02:50 +02:00
|
|
|
uint32_t saved_ps;
|
2016-10-14 21:17:48 +02:00
|
|
|
|
2016-10-16 15:57:16 +02:00
|
|
|
/* Register save area */
|
2016-10-14 21:17:48 +02:00
|
|
|
|
2016-10-16 15:57:16 +02:00
|
|
|
uint32_t regs[XCPTCONTEXT_REGS];
|
2016-10-14 21:17:48 +02:00
|
|
|
|
2016-10-28 18:33:20 +02:00
|
|
|
#if XCHAL_CP_NUM > 0
|
|
|
|
/* Co-processor save area */
|
|
|
|
|
2016-10-29 17:36:33 +02:00
|
|
|
struct xtensa_cpstate_s cpstate;
|
2016-10-28 18:33:20 +02:00
|
|
|
#endif
|
|
|
|
|
2016-10-14 21:17:48 +02:00
|
|
|
#ifdef CONFIG_LIB_SYSCALL
|
|
|
|
/* The following array holds the return address and the exc_return value
|
|
|
|
* needed to return from each nested system call.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t nsyscalls;
|
|
|
|
struct xcpt_syscall_s syscall[CONFIG_SYS_NNEST];
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2016-10-12 21:11:05 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Inline functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-10-23 16:00:17 +02:00
|
|
|
/* Return the current value of the PS register */
|
|
|
|
|
|
|
|
static inline uint32_t xtensa_getps(void)
|
|
|
|
{
|
|
|
|
uint32_t ps;
|
|
|
|
|
|
|
|
__asm__ __volatile__
|
|
|
|
(
|
|
|
|
"rsr %0, PS" : "=r"(ps)
|
|
|
|
);
|
|
|
|
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the value of the PS register */
|
|
|
|
|
|
|
|
static inline void xtensa_setps(uint32_t ps)
|
|
|
|
{
|
|
|
|
__asm__ __volatile__
|
|
|
|
(
|
2016-10-23 16:04:57 +02:00
|
|
|
"wsr %0, PS" : : "r"(ps)
|
2016-10-23 16:00:17 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the value of the PS register */
|
|
|
|
|
|
|
|
static inline void up_irq_restore(uint32_t ps)
|
|
|
|
{
|
|
|
|
__asm__ __volatile__
|
|
|
|
(
|
2016-10-23 16:04:57 +02:00
|
|
|
"wsr %0, PS" : : "r"(ps)
|
2016-10-23 16:00:17 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable interrupts and return the previous value of the PS register */
|
|
|
|
|
|
|
|
static inline uint32_t up_irq_save(void)
|
|
|
|
{
|
2016-10-23 21:37:40 +02:00
|
|
|
uint32_t ps;
|
2016-10-23 16:00:17 +02:00
|
|
|
|
|
|
|
/* Disable all low- and medium-priority interrupts. High priority
|
|
|
|
* interrupts should not interfere with ongoing RTOS operations and
|
|
|
|
* are not disabled.
|
|
|
|
*/
|
|
|
|
|
2016-10-23 21:37:40 +02:00
|
|
|
__asm__ __volatile__
|
|
|
|
(
|
2016-10-23 21:33:48 +02:00
|
|
|
"rsil %0, %1" : "=r"(ps) : "I"(XCHAL_EXCM_LEVEL)
|
2016-10-23 21:37:40 +02:00
|
|
|
);
|
2016-10-23 16:00:17 +02:00
|
|
|
|
|
|
|
/* Return the previous PS value so that it can be restored with
|
|
|
|
* up_irq_restore().
|
|
|
|
*/
|
|
|
|
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
2016-10-23 16:04:57 +02:00
|
|
|
/* Enable interrupts at all levels */
|
|
|
|
|
|
|
|
static inline void up_irq_enable(void)
|
|
|
|
{
|
2016-10-30 14:37:51 +01:00
|
|
|
#ifdef __XTENSA_CALL0_ABI__
|
2016-10-23 16:04:57 +02:00
|
|
|
xtensa_setps(PS_INTLEVEL(0) | PS_UM);
|
|
|
|
#else
|
|
|
|
xtensa_setps(PS_INTLEVEL(0) | PS_UM | PS_WOE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable low- and medium- priority interrupts */
|
|
|
|
|
|
|
|
static inline void up_irq_disable(void)
|
|
|
|
{
|
2016-10-30 14:37:51 +01:00
|
|
|
#ifdef __XTENSA_CALL0_ABI__
|
2016-10-23 16:04:57 +02:00
|
|
|
xtensa_setps(PS_INTLEVEL(XCHAL_EXCM_LEVEL) | PS_UM);
|
|
|
|
#else
|
|
|
|
xtensa_setps(PS_INTLEVEL(XCHAL_EXCM_LEVEL) | PS_UM | PS_WOE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-10-12 21:11:05 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2016-10-15 20:23:36 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: xtensa_enable_interrupts
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enables a set of interrupts. Does not simply set INTENABLE directly,
|
|
|
|
* but computes it as a function of the current virtual priority.
|
|
|
|
* Can be called from interrupt handlers.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
irqstate_t xtensa_enable_interrupts(irqstate_t mask);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: xtensa_disable_interrupts
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disables a set of interrupts. Does not simply set INTENABLE directly,
|
|
|
|
* but computes it as a function of the current virtual priority.
|
|
|
|
* Can be called from interrupt handlers.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
irqstate_t xtensa_disable_interrupts(irqstate_t mask);
|
|
|
|
|
2016-10-12 21:11:05 +02:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* __ARCH_XTENSA_INCLUDE_IRQ_H */
|