2023-04-28 17:05:02 +02:00
|
|
|
/****************************************************************************
|
2009-12-11 16:29:11 +01:00
|
|
|
* arch/hc/include/hcs12/irq.h
|
|
|
|
*
|
2021-03-28 15:52:32 +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
|
2009-12-11 16:29:11 +01:00
|
|
|
*
|
2021-03-28 15:52:32 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-12-11 16:29:11 +01:00
|
|
|
*
|
2021-03-28 15:52:32 +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.
|
2009-12-11 16:29:11 +01:00
|
|
|
*
|
2023-04-28 17:05:02 +02:00
|
|
|
****************************************************************************/
|
2009-12-11 16:29:11 +01:00
|
|
|
|
2020-04-05 23:00:04 +02:00
|
|
|
/* This file should never be included directly but, rather,
|
2009-12-11 16:29:11 +01:00
|
|
|
* only indirectly through nuttx/irq.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ARCH_HC_INCLUDE_HCS12_IRQ_H
|
|
|
|
#define __ARCH_HC_INCLUDE_HCS12_IRQ_H
|
|
|
|
|
2023-04-28 17:05:02 +02:00
|
|
|
/****************************************************************************
|
2009-12-11 16:29:11 +01:00
|
|
|
* Included Files
|
2023-04-28 17:05:02 +02:00
|
|
|
****************************************************************************/
|
2009-12-11 16:29:11 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
|
2023-04-28 17:05:02 +02:00
|
|
|
/****************************************************************************
|
2015-04-08 16:04:12 +02:00
|
|
|
* Pre-processor Definitions
|
2023-04-28 17:05:02 +02:00
|
|
|
****************************************************************************/
|
2020-07-08 20:39:29 +02:00
|
|
|
|
2011-02-20 20:47:40 +01:00
|
|
|
/* CCR bit definitions */
|
|
|
|
|
|
|
|
#define HCS12_CCR_C (1 << 0) /* Bit 0: Carry/Borrow status bit */
|
2022-09-27 14:14:07 +02:00
|
|
|
#define HCS12_CCR_V (1 << 1) /* Bit 1: Two's complement overflow status bit */
|
2011-02-20 20:47:40 +01:00
|
|
|
#define HCS12_CCR_Z (1 << 2) /* Bit 2: Zero status bit */
|
|
|
|
#define HCS12_CCR_N (1 << 3) /* Bit 3: Negative status bit */
|
|
|
|
#define HCS12_CCR_I (1 << 4) /* Bit 4: Maskable interrupt control bit */
|
|
|
|
#define HCS12_CCR_H (1 << 5) /* Bit 5: Half-carry status bit */
|
|
|
|
#define HCS12_CCR_X (1 << 6) /* Bit 6: Non-maskable interrupt control bit */
|
|
|
|
#define HCS12_CCR_S (1 << 7) /* Bit 7: STOP instruction control bit */
|
|
|
|
|
2023-04-28 17:05:02 +02:00
|
|
|
/****************************************************************************
|
2020-07-08 20:39:29 +02:00
|
|
|
* Register state save strucure
|
2011-02-16 02:45:35 +01:00
|
|
|
* Low Address <-- SP after state save
|
|
|
|
* [PPAGE]
|
|
|
|
* [soft regisers]
|
|
|
|
* XYH
|
|
|
|
* XYL
|
|
|
|
* ZH
|
|
|
|
* ZL
|
|
|
|
* TMPH
|
|
|
|
* TMPL
|
|
|
|
* FRAMEH
|
2011-02-17 03:12:14 +01:00
|
|
|
* FRAMEL
|
|
|
|
* SP <-- SP after interrupt
|
2011-02-16 02:45:35 +01:00
|
|
|
* CCR
|
|
|
|
* B
|
|
|
|
* A
|
|
|
|
* XH
|
|
|
|
* XL
|
|
|
|
* YH
|
|
|
|
* YL
|
|
|
|
* PCH
|
|
|
|
* High Address PCL <-- SP before interrupt
|
|
|
|
*
|
2023-04-28 17:05:02 +02:00
|
|
|
****************************************************************************/
|
2011-02-16 02:45:35 +01:00
|
|
|
|
|
|
|
/* Byte offsets */
|
2020-07-08 20:39:29 +02:00
|
|
|
|
2011-02-17 03:12:14 +01:00
|
|
|
/* PPAGE register (only in banked mode) */
|
2011-02-16 02:45:35 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_HCS12_NONBANKED
|
|
|
|
# define REG_PPAGE 0
|
|
|
|
# define REG_FIRST_SOFTREG 1
|
|
|
|
#else
|
|
|
|
# define REG_FIRST_SOFTREG 0
|
|
|
|
#endif
|
|
|
|
|
2011-02-17 03:12:14 +01:00
|
|
|
/* Soft registers (as configured) */
|
|
|
|
|
2011-02-16 02:45:35 +01:00
|
|
|
#if CONFIG_HCS12_MSOFTREGS > 2
|
|
|
|
# error "Need to save more registers"
|
|
|
|
#elif CONFIG_HCS12_MSOFTREGS == 2
|
|
|
|
# define REG_SOFTREG1 REG_FIRST_SOFTREG
|
|
|
|
# define REG_SOFTREG2 (REG_FIRST_SOFTREG+2)
|
|
|
|
# define REG_FIRST_HARDREG (REG_FIRST_SOFTREG+4)
|
|
|
|
#elif CONFIG_HCS12_MSOFTREGS == 1
|
|
|
|
# define REG_SOFTREG1 REG_FIRST_SOFTREG
|
|
|
|
# define REG_FIRST_HARDREG (REG_FIRST_SOFTREG+2)
|
|
|
|
#else
|
|
|
|
# define REG_FIRST_HARDREG REG_FIRST_SOFTREG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define REG_XY REG_FIRST_HARDREG
|
|
|
|
#define REG_Z (REG_FIRST_HARDREG+2)
|
|
|
|
# define REG_ZH (REG_FIRST_HARDREG+2)
|
|
|
|
# define REG_ZL (REG_FIRST_HARDREG+3)
|
|
|
|
#define REG_TMP (REG_FIRST_HARDREG+4)
|
|
|
|
# define REG_TMPH (REG_FIRST_HARDREG+4)
|
|
|
|
# define REG_TMPL (REG_FIRST_HARDREG+5)
|
|
|
|
#define REG_FRAME (REG_FIRST_HARDREG+6)
|
|
|
|
# define REG_FRAMEH (REG_FIRST_HARDREG+6)
|
|
|
|
# define REG_FRAMEL (REG_FIRST_HARDREG+7)
|
|
|
|
|
2011-02-17 03:12:14 +01:00
|
|
|
/* Stack pointer before the interrupt */
|
|
|
|
|
|
|
|
#define REG_SP (REG_FIRST_HARDREG+8)
|
|
|
|
# define REG_SPH (REG_FIRST_HARDREG+8)
|
|
|
|
# define REG_SPL (REG_FIRST_HARDREG+9)
|
|
|
|
|
2023-04-28 17:05:02 +02:00
|
|
|
/* On entry into an I- or X-interrupt, into an SWI, or into an undefined
|
|
|
|
* instruction interrupt, the stack frame created by hardware looks like:
|
2011-02-17 03:12:14 +01:00
|
|
|
*
|
|
|
|
* Low Address <-- SP after interrupt
|
|
|
|
* CCR
|
|
|
|
* B
|
|
|
|
* A
|
|
|
|
* XH
|
|
|
|
* XL
|
|
|
|
* YH
|
|
|
|
* YL
|
|
|
|
* PCH
|
|
|
|
* High Address PCL <-- SP before interrupt
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define REG_CCR (REG_FIRST_HARDREG+10)
|
|
|
|
#define REG_BA (REG_FIRST_HARDREG+11)
|
|
|
|
# define REG_B (REG_FIRST_HARDREG+11)
|
|
|
|
# define REG_A (REG_FIRST_HARDREG+12)
|
|
|
|
#define REG_X (REG_FIRST_HARDREG+13)
|
|
|
|
# define REG_XH (REG_FIRST_HARDREG+13)
|
|
|
|
# define REG_XL (REG_FIRST_HARDREG+14)
|
|
|
|
#define REG_Y (REG_FIRST_HARDREG+15)
|
|
|
|
# define REG_YH (REG_FIRST_HARDREG+15)
|
|
|
|
# define REG_YL (REG_FIRST_HARDREG+16)
|
|
|
|
#define REG_PC (REG_FIRST_HARDREG+17)
|
|
|
|
# define REG_PCH (REG_FIRST_HARDREG+17)
|
|
|
|
# define REG_PCL (REG_FIRST_HARDREG+18)
|
2011-02-16 02:45:35 +01:00
|
|
|
|
2011-02-18 02:28:35 +01:00
|
|
|
#define TOTALFRAME_SIZE (REG_FIRST_HARDREG+17)
|
2011-02-17 03:12:14 +01:00
|
|
|
#define INTFRAME_SIZE 9
|
2011-02-18 02:28:35 +01:00
|
|
|
#define XCPTCONTEXT_REGS TOTALFRAME_SIZE
|
2009-12-11 16:29:11 +01:00
|
|
|
|
2023-04-28 17:05:02 +02:00
|
|
|
/****************************************************************************
|
2009-12-11 16:29:11 +01:00
|
|
|
* Public Types
|
2023-04-28 17:05:02 +02:00
|
|
|
****************************************************************************/
|
2009-12-11 16:29:11 +01:00
|
|
|
|
|
|
|
/* This structure defines the way the registers are stored. */
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
struct xcptcontext
|
|
|
|
{
|
2011-02-16 02:45:35 +01:00
|
|
|
uint8_t regs[XCPTCONTEXT_REGS];
|
2009-12-11 16:29:11 +01:00
|
|
|
};
|
|
|
|
|
2023-04-28 17:05:02 +02:00
|
|
|
/****************************************************************************
|
2009-12-11 16:29:11 +01:00
|
|
|
* Inline functions
|
2023-04-28 17:05:02 +02:00
|
|
|
****************************************************************************/
|
2009-12-11 16:29:11 +01:00
|
|
|
|
2016-02-14 23:11:25 +01:00
|
|
|
/* Name: up_irq_save, up_irq_restore, and friends.
|
|
|
|
*
|
|
|
|
* NOTE: This function should never be called from application code and,
|
|
|
|
* as a general rule unless you really know what you are doing, this
|
|
|
|
* function should not be called directly from operation system code either:
|
|
|
|
* Typically, the wrapper functions, enter_critical_section() and
|
|
|
|
* leave_critical section(), are probably what you really want.
|
|
|
|
*/
|
|
|
|
|
2011-02-20 20:47:40 +01:00
|
|
|
/* Enable/Disable interrupts */
|
|
|
|
|
|
|
|
#define ienable() __asm("cli");
|
|
|
|
#define idisable() __asm("orcc #0x10")
|
|
|
|
#define xenable() __asm("andcc #0xbf")
|
|
|
|
#define xdisable() __asm("orcc #0x40")
|
|
|
|
|
|
|
|
/* Get the current value of the CCR */
|
|
|
|
|
|
|
|
static inline irqstate_t up_getccr(void)
|
|
|
|
{
|
|
|
|
irqstate_t ccr;
|
|
|
|
__asm__
|
|
|
|
(
|
|
|
|
"\ttpa\n"
|
|
|
|
"\tstaa %0\n"
|
2016-02-14 23:11:25 +01:00
|
|
|
: "=m"(ccr) :
|
2011-02-20 20:47:40 +01:00
|
|
|
);
|
|
|
|
return ccr;
|
|
|
|
}
|
|
|
|
|
2009-12-11 16:29:11 +01:00
|
|
|
/* Save the current interrupt enable state & disable IRQs */
|
|
|
|
|
2016-02-14 23:11:25 +01:00
|
|
|
static inline irqstate_t up_irq_save(void)
|
2009-12-11 16:29:11 +01:00
|
|
|
{
|
2011-02-20 20:47:40 +01:00
|
|
|
irqstate_t ccr;
|
|
|
|
__asm__
|
|
|
|
(
|
|
|
|
"\ttpa\n"
|
|
|
|
"\tstaa %0\n"
|
|
|
|
"\torcc #0x50\n"
|
2016-02-14 23:11:25 +01:00
|
|
|
: "=m"(ccr) :
|
2011-02-20 20:47:40 +01:00
|
|
|
);
|
|
|
|
return ccr;
|
2009-12-11 16:29:11 +01:00
|
|
|
}
|
|
|
|
|
2011-02-20 20:47:40 +01:00
|
|
|
/* Restore saved interrupt state */
|
2009-12-11 16:29:11 +01:00
|
|
|
|
2016-02-14 23:11:25 +01:00
|
|
|
static inline void up_irq_restore(irqstate_t flags)
|
2009-12-11 16:29:11 +01:00
|
|
|
{
|
2011-02-20 20:47:40 +01:00
|
|
|
/* Should interrupts be enabled? */
|
2009-12-11 16:29:11 +01:00
|
|
|
|
2011-02-20 20:47:40 +01:00
|
|
|
if ((flags & HCS12_CCR_I) == 0)
|
|
|
|
{
|
|
|
|
/* Yes.. unmask I- and Z-interrupts */
|
|
|
|
|
|
|
|
__asm("andcc #0xaf");
|
|
|
|
}
|
2009-12-11 16:29:11 +01:00
|
|
|
}
|
|
|
|
|
2011-02-20 20:47:40 +01:00
|
|
|
/* System call */
|
|
|
|
|
2011-03-29 02:07:02 +02:00
|
|
|
static inline void system_call3(unsigned int nbr, uintptr_t parm1,
|
2016-02-14 23:11:25 +01:00
|
|
|
uintptr_t parm2, uintptr_t parm3)
|
2011-03-29 02:07:02 +02:00
|
|
|
{
|
|
|
|
/* To be provided */
|
2020-07-08 20:39:29 +02:00
|
|
|
|
2011-03-29 02:07:02 +02:00
|
|
|
/* __asm("swi") */
|
|
|
|
}
|
2011-02-20 20:47:40 +01:00
|
|
|
|
2023-04-28 17:05:02 +02:00
|
|
|
/****************************************************************************
|
2009-12-11 16:29:11 +01:00
|
|
|
* Public Data
|
2023-04-28 17:05:02 +02:00
|
|
|
****************************************************************************/
|
2009-12-11 16:29:11 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
2015-06-13 03:26:01 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2009-12-11 16:29:11 +01:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2023-04-28 17:05:02 +02:00
|
|
|
/****************************************************************************
|
2020-07-08 20:39:29 +02:00
|
|
|
* Public Functions Prototypes
|
2023-04-28 17:05:02 +02:00
|
|
|
****************************************************************************/
|
2009-12-11 16:29:11 +01:00
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* __ARCH_HC_INCLUDE_HCS12_IRQ_H */
|