2016-10-12 21:11:05 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/xtensa/include/irq.h
|
|
|
|
*
|
2021-03-28 17:44:37 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2016-10-12 21:11:05 +02:00
|
|
|
*
|
2021-03-28 17:44:37 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-10-12 21:11:05 +02:00
|
|
|
*
|
2021-03-28 17:44:37 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-10-12 21:11:05 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
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
|
|
|
|
2021-08-04 12:29:01 +02:00
|
|
|
/* Include chip-specific IRQ definitions (including IRQ numbers) */
|
|
|
|
|
|
|
|
#include <arch/chip/irq.h>
|
|
|
|
|
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>
|
|
|
|
|
2021-05-20 22:07:54 +02:00
|
|
|
#elif CONFIG_ARCH_FAMILY_LX7
|
|
|
|
# include <arch/lx7/irq.h>
|
|
|
|
|
2016-10-12 22:50:28 +02:00
|
|
|
#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)
|
|
|
|
|
2021-05-21 23:32:28 +02:00
|
|
|
#if XCHAL_HAVE_LOOPS != 0
|
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
|
|
|
|
|
2020-12-01 17:53:26 +01:00
|
|
|
#define XCPTCONTEXT_SIZE ((4 * XCPTCONTEXT_REGS) + 0x20)
|
2016-10-14 21:17:48 +02:00
|
|
|
|
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__
|
|
|
|
(
|
2021-06-17 06:30:27 +02:00
|
|
|
"wsr %0, PS \n"
|
|
|
|
"rsync \n"
|
|
|
|
:
|
|
|
|
: "r"(ps)
|
|
|
|
: "memory"
|
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__
|
|
|
|
(
|
2021-06-17 06:30:27 +02:00
|
|
|
"wsr %0, PS \n"
|
|
|
|
"rsync \n"
|
|
|
|
:
|
|
|
|
: "r"(ps)
|
|
|
|
: "memory"
|
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__
|
|
|
|
(
|
2021-08-04 10:04:49 +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:
|
2020-10-06 18:59:57 +02:00
|
|
|
* Disables a set of interrupts. Does not simply clear INTENABLE directly,
|
2016-10-15 20:23:36 +02:00
|
|
|
* 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 */
|