Skip to content

Commit 33408ed

Browse files
thenguyenyfKhiemNguyenT
authored andcommitted
hal: renesas: ra: enable support for NMI group register
First commit to enable support for NMI group register Signed-off-by: The Nguyen <[email protected]>
1 parent d86b251 commit 33408ed

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ set(srcs
1515
fsp/src/bsp/mcu/all/bsp_delay.c
1616
fsp/src/bsp/mcu/all/bsp_register_protection.c
1717
fsp/src/bsp/mcu/all/bsp_irq.c
18+
fsp/src/bsp/mcu/all/bsp_group_irq.c
1819
)
1920

2021
zephyr_include_directories(${include_dirs})
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/***********************************************************************************************************************
8+
* Includes <System Includes> , "Project Includes"
9+
**********************************************************************************************************************/
10+
#include "bsp_api.h"
11+
12+
/***********************************************************************************************************************
13+
* Macro definitions
14+
**********************************************************************************************************************/
15+
#define BSP_GRP_IRQ_TOTAL_ITEMS (16U)
16+
17+
/***********************************************************************************************************************
18+
* Typedef definitions
19+
**********************************************************************************************************************/
20+
21+
/***********************************************************************************************************************
22+
* Exported global variables (to be accessed by other files)
23+
**********************************************************************************************************************/
24+
25+
/***********************************************************************************************************************
26+
* Private global variables and functions
27+
**********************************************************************************************************************/
28+
29+
/** This array holds callback functions. */
30+
bsp_grp_irq_cb_t g_bsp_group_irq_sources[BSP_GRP_IRQ_TOTAL_ITEMS] BSP_SECTION_EARLY_INIT;
31+
32+
void NMI_Handler(void);
33+
static void bsp_group_irq_call(bsp_grp_irq_t irq);
34+
35+
/*******************************************************************************************************************//**
36+
* Calls the callback function for an interrupt if a callback has been registered.
37+
*
38+
* @param[in] irq Which interrupt to check and possibly call.
39+
*
40+
* @retval FSP_SUCCESS Callback was called.
41+
* @retval FSP_ERR_INVALID_ARGUMENT No valid callback has been registered for this interrupt source.
42+
*
43+
* @warning This function is called from within an interrupt
44+
**********************************************************************************************************************/
45+
BSP_SECTION_FLASH_GAP static void bsp_group_irq_call (bsp_grp_irq_t irq)
46+
{
47+
/** Check for valid callback */
48+
if (NULL != g_bsp_group_irq_sources[irq])
49+
{
50+
/** Callback has been found. Call it. */
51+
g_bsp_group_irq_sources[irq](irq);
52+
}
53+
}
54+
55+
/*******************************************************************************************************************//**
56+
* @addtogroup BSP_MCU
57+
*
58+
* @{
59+
**********************************************************************************************************************/
60+
61+
/*******************************************************************************************************************//**
62+
* Register a callback function for supported interrupts. If NULL is passed for the callback argument then any
63+
* previously registered callbacks are unregistered.
64+
*
65+
* @param[in] irq Interrupt for which to register a callback.
66+
* @param[in] p_callback Pointer to function to call when interrupt occurs.
67+
*
68+
* @retval FSP_SUCCESS Callback registered
69+
* @retval FSP_ERR_ASSERTION Callback pointer is NULL
70+
**********************************************************************************************************************/
71+
BSP_SECTION_FLASH_GAP fsp_err_t R_BSP_GroupIrqWrite (bsp_grp_irq_t irq, void (* p_callback)(bsp_grp_irq_t irq))
72+
{
73+
#if BSP_CFG_PARAM_CHECKING_ENABLE
74+
75+
/* Check pointer for NULL value. */
76+
FSP_ASSERT(p_callback);
77+
#endif
78+
79+
/* Register callback. */
80+
g_bsp_group_irq_sources[irq] = p_callback;
81+
82+
return FSP_SUCCESS;
83+
}
84+
85+
/*******************************************************************************************************************//**
86+
* Non-maskable interrupt handler. This exception is defined by the BSP, unlike other system exceptions, because
87+
* there are many sources that map to the NMI exception.
88+
**********************************************************************************************************************/
89+
BSP_SECTION_FLASH_GAP void NMI_Handler (void)
90+
{
91+
/* NMISR is masked by NMIER to prevent iterating over NMI status flags that are not enabled. */
92+
uint16_t nmier = R_ICU->NMIER;
93+
uint16_t nmisr = R_ICU->NMISR & nmier;
94+
95+
/* Loop over all NMI status flags */
96+
for (bsp_grp_irq_t irq = BSP_GRP_IRQ_IWDT_ERROR; irq <= (bsp_grp_irq_t) (BSP_GRP_IRQ_TOTAL_ITEMS - 1); irq++)
97+
{
98+
/* If the current irq status register is set call the irq callback. */
99+
if (0U != (nmisr & (1U << irq)))
100+
{
101+
(void) bsp_group_irq_call(irq);
102+
}
103+
}
104+
105+
/* Clear status flags that have been handled. */
106+
R_ICU->NMICLR = nmisr;
107+
108+
#if BSP_CFG_MCU_PART_SERIES == 8
109+
110+
/* Wait for NMISR to be cleared before exiting the ISR to prevent the IRQ from being regenerated.
111+
* See section "13.2.12 NMICLR : Non-Maskable Interrupt Status Clear Register" in the RA8M1 manual
112+
* R01UH0994EJ0100 */
113+
FSP_HARDWARE_REGISTER_WAIT((R_ICU->NMISR & nmisr), 0);
114+
#endif
115+
}
116+
117+
/** @} (end addtogroup BSP_MCU) */

0 commit comments

Comments
 (0)