Skip to content

Commit f041653

Browse files
SangTranRVCquytranpzz
authored andcommitted
arch: rx: Add NMI vector table for Renesas RX MCU
Add support for non-maskable interrupt (NMI) vector table for Renesas RX architecture Signed-off-by: Sang Tran <sang.tran.jc@renesas.com>
1 parent 52ac5dd commit f041653

File tree

2 files changed

+107
-3
lines changed

2 files changed

+107
-3
lines changed

arch/rx/core/vects.c

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88
#include <zephyr/irq.h>
99
#include <kswap.h>
1010
#include <zephyr/tracing/tracing.h>
11+
#include <zephyr/arch/rx/sw_nmi_table.h>
1112

1213
typedef void (*fp)(void);
1314
extern void _start(void);
1415
extern void z_rx_irq_exit(void);
16+
extern void R_BSP_SoftwareReset(void);
17+
18+
#define NMI_NMIST_MASK 0x01
19+
#define NMI_OSTST_MASK 0x02
20+
#define NMI_IWDTST_MASK 0x08
21+
#define NMI_LVD1ST_MASK 0x10
22+
#define NMI_LVD2ST_MASK 0x20
1523

1624
/* this is mainly to give Visual Studio Code peace of mind */
1725
#ifndef CONFIG_GEN_IRQ_START_VECTOR
@@ -97,9 +105,9 @@ static void __ISR__ INT_Excep_FloatingPoint(void)
97105
static void __ISR__ INT_NonMaskableInterrupt(void)
98106
{
99107
REGISTER_SAVE();
100-
ISR_DIRECT_HEADER();
101-
z_fatal_error(K_ERR_CPU_EXCEPTION, NULL);
102-
ISR_DIRECT_FOOTER(1);
108+
int nmi_vector = get_nmi_request();
109+
110+
handle_nmi(nmi_vector);
103111
REGISTER_RESTORE_EXIT();
104112
}
105113

@@ -141,6 +149,64 @@ static void __ISR__ reserved_isr(void)
141149
/* wrapper for z_rx_context_switch_isr, defined in switch.S */
142150
extern void __ISR__ switch_isr_wrapper(void);
143151

152+
void nmi_enable(uint8_t nmi_vector, nmi_callback_t callback, void *arg)
153+
{
154+
if (nmi_vector >= NMI_TABLE_SIZE) {
155+
return;
156+
}
157+
158+
_nmi_vector_table[nmi_vector].callback = callback;
159+
_nmi_vector_table[nmi_vector].arg = arg;
160+
}
161+
162+
int get_nmi_request(void)
163+
{
164+
uint32_t nmi_status = ICU.NMISR.BYTE;
165+
166+
if (nmi_status & NMI_NMIST_MASK) {
167+
return 0;
168+
} else if (nmi_status & NMI_OSTST_MASK) {
169+
return 1;
170+
} else if (nmi_status & NMI_IWDTST_MASK) {
171+
return 2;
172+
} else if (nmi_status & NMI_LVD1ST_MASK) {
173+
return 3;
174+
} else if (nmi_status & NMI_LVD2ST_MASK) {
175+
return 4;
176+
}
177+
178+
return NMI_TABLE_SIZE;
179+
}
180+
181+
void handle_nmi(uint8_t nmi_vector)
182+
{
183+
if (nmi_vector >= NMI_TABLE_SIZE) {
184+
return;
185+
}
186+
187+
_nmi_vector_table[nmi_vector].callback(_nmi_vector_table[nmi_vector].arg);
188+
189+
switch (nmi_vector) {
190+
case 0:
191+
ICU.NMICLR.BIT.NMICLR = 0x01;
192+
break;
193+
case 1:
194+
ICU.NMICLR.BIT.OSTCLR = 0x01;
195+
break;
196+
case 2:
197+
ICU.NMICLR.BIT.IWDTCLR = 0x01;
198+
break;
199+
case 3:
200+
ICU.NMICLR.BIT.LVD1CLR = 0x01;
201+
break;
202+
case 4:
203+
ICU.NMICLR.BIT.LVD2CLR = 0x01;
204+
break;
205+
default:
206+
break;
207+
}
208+
}
209+
144210
/* this macro is used to define "demuxing" ISRs for all interrupts that are
145211
* handled through Zephyr's software isr table.
146212
*/
@@ -394,6 +460,15 @@ INT_DEMUX(253);
394460
INT_DEMUX(254);
395461
INT_DEMUX(255);
396462

463+
struct nmi_vector_entry _nmi_vector_table[NMI_TABLE_SIZE] = {
464+
{(nmi_callback_t)0xFFFFFFFFU, (void *)0xFFFFFFFFU}, /* NMI Pin Interrupt */
465+
{(nmi_callback_t)0xFFFFFFFFU,
466+
(void *)0xFFFFFFFFU}, /* Oscillation Stop Detection Interrupt */
467+
{(nmi_callback_t)0xFFFFFFFFU, (void *)0xFFFFFFFFU}, /* IWDT Underflow/Refresh Error */
468+
{(nmi_callback_t)0xFFFFFFFFU, (void *)0xFFFFFFFFU}, /* Voltage Monitoring 1 Interrupt */
469+
{(nmi_callback_t)0xFFFFFFFFU, (void *)0xFFFFFFFFU}, /* Voltage Monitoring 2 Interrupt */
470+
};
471+
397472
const void *FixedVectors[] FVECT_SECT = {
398473
/* 0x00-0x4c: Reserved, must be 0xff (according to e2 studio example) */
399474
/* Reserved for OFSM */

include/zephyr/arch/rx/sw_nmi_table.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_ARCH_RX_SW_NMI_TABLE_H
8+
#define ZEPHYR_INCLUDE_ARCH_RX_SW_NMI_TABLE_H
9+
10+
#include <stdint.h>
11+
#include <soc.h>
12+
#include "iodefine.h"
13+
14+
#define NMI_TABLE_SIZE (5)
15+
16+
typedef void (*nmi_callback_t)(void *arg);
17+
18+
struct nmi_vector_entry {
19+
nmi_callback_t callback;
20+
void *arg;
21+
};
22+
23+
extern struct nmi_vector_entry _nmi_vector_table[NMI_TABLE_SIZE];
24+
25+
void nmi_enable(uint8_t nmi_vector, nmi_callback_t callback, void *arg);
26+
int get_nmi_request(void);
27+
void handle_nmi(uint8_t nmi_vector);
28+
29+
#endif /* ZEPHYR_INCLUDE_ARCH_RX_SW_NMI_TABLE_H */

0 commit comments

Comments
 (0)