Skip to content

Commit 74f5f27

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 2a5aba2 commit 74f5f27

File tree

2 files changed

+104
-3
lines changed

2 files changed

+104
-3
lines changed

arch/rx/core/vects.c

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@
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
1826
#define CONFIG_GEN_IRQ_START_VECTOR 0
1927
#endif
28+
#define NMI_TABLE_SIZE (5)
2029

2130
#define EXVECT_SECT __attribute__((section(".exvectors")))
2231
#define RVECT_SECT __attribute__((section(".rvectors")))
@@ -97,9 +106,9 @@ static void __ISR__ INT_Excep_FloatingPoint(void)
97106
static void __ISR__ INT_NonMaskableInterrupt(void)
98107
{
99108
REGISTER_SAVE();
100-
ISR_DIRECT_HEADER();
101-
z_fatal_error(K_ERR_CPU_EXCEPTION, NULL);
102-
ISR_DIRECT_FOOTER(1);
109+
int nmi_vector = get_nmi_request();
110+
111+
handle_nmi(nmi_vector);
103112
REGISTER_RESTORE_EXIT();
104113
}
105114

@@ -141,6 +150,63 @@ static void __ISR__ reserved_isr(void)
141150
/* wrapper for z_rx_context_switch_isr, defined in switch.S */
142151
extern void __ISR__ switch_isr_wrapper(void);
143152

153+
void nmi_enable(uint8_t nmi_vector, nmi_callback_t callback, void *arg)
154+
{
155+
if (nmi_vector >= NMI_TABLE_SIZE) {
156+
return;
157+
}
158+
159+
_nmi_vector_table[nmi_vector].callback = callback;
160+
_nmi_vector_table[nmi_vector].arg = arg;
161+
}
162+
163+
int get_nmi_request(void)
164+
{
165+
uint32_t nmi_status = ICU.NMISR.BYTE;
166+
167+
if (nmi_status & NMI_NMIST_MASK) {
168+
return 0;
169+
} else if (nmi_status & NMI_OSTST_MASK) {
170+
return 1;
171+
} else if (nmi_status & NMI_IWDTST_MASK) {
172+
return 2;
173+
} else if (nmi_status & NMI_LVD1ST_MASK) {
174+
return 3;
175+
} else if (nmi_status & NMI_LVD2ST_MASK) {
176+
return 4;
177+
}
178+
179+
return NMI_TABLE_SIZE;
180+
}
181+
182+
void handle_nmi(uint8_t nmi_vector)
183+
{
184+
if (nmi_vector >= NMI_TABLE_SIZE) {
185+
return;
186+
}
187+
188+
_nmi_vector_table[nmi_vector].callback(_nmi_vector_table[nmi_vector].arg);
189+
190+
switch (nmi_vector) {
191+
case 0:
192+
ICU.NMICLR.BIT.NMICLR = 0x01;
193+
break;
194+
case 1:
195+
ICU.NMICLR.BIT.OSTCLR = 0x01;
196+
break;
197+
case 2:
198+
ICU.NMICLR.BIT.IWDTCLR = 0x01;
199+
R_BSP_SoftwareReset();
200+
break;
201+
case 3:
202+
ICU.NMICLR.BIT.LVD1CLR = 0x01;
203+
break;
204+
case 4:
205+
ICU.NMICLR.BIT.LVD2CLR = 0x01;
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,14 @@ 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)0xFFFFFFFF, (void *)0xFFFFFFFF}, /* NMI Pin Interrupt */
465+
{(nmi_callback_t)0xFFFFFFFF, (void *)0xFFFFFFFF}, /* Oscillation Stop Detection Interrupt */
466+
{(nmi_callback_t)0xFFFFFFFF, (void *)0xFFFFFFFF}, /* IWDT Underflow/Refresh Error */
467+
{(nmi_callback_t)0xFFFFFFFF, (void *)0xFFFFFFFF}, /* Voltage Monitoring 1 Interrupt */
468+
{(nmi_callback_t)0xFFFFFFFF, (void *)0xFFFFFFFF}, /* Voltage Monitoring 2 Interrupt */
469+
};
470+
397471
const void *FixedVectors[] FVECT_SECT = {
398472
/* 0x00-0x4c: Reserved, must be 0xff (according to e2 studio example) */
399473
/* Reserved for OFSM */

include/zephyr/arch/rx/sw_nmi_table.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
typedef void (*nmi_callback_t)(void *arg);
15+
16+
struct nmi_vector_entry {
17+
nmi_callback_t callback;
18+
void *arg;
19+
};
20+
21+
extern struct nmi_vector_entry _nmi_vector_table[];
22+
23+
void nmi_enable(uint8_t nmi_vector, nmi_callback_t callback, void *arg);
24+
int get_nmi_request(void);
25+
void handle_nmi(uint8_t nmi_vector);
26+
27+
#endif /* ZEPHYR_INCLUDE_ARCH_RX_SW_NMI_TABLE_H */

0 commit comments

Comments
 (0)