Skip to content

Commit 325167b

Browse files
nhutnguyenkcKhiemNguyenT
authored andcommitted
hal: renesas: rzg: Initial support for Interrupt Control
Initial HAL support for Interrupt Control Signed-off-by: Hoang Nguyen <[email protected]> Signed-off-by: Nhut Nguyen <[email protected]>
1 parent 64fce2e commit 325167b

File tree

8 files changed

+1080
-0
lines changed

8 files changed

+1080
-0
lines changed

drivers/rz/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_RIIC_MASTER
3434

3535
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_GTM
3636
fsp/src/${SOC_SERIES_PREFIX}/r_gtm/r_gtm.c)
37+
38+
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_EXT_IRQ
39+
fsp/src/${SOC_SERIES_PREFIX}/r_intc_irq/r_intc_irq.c
40+
fsp/src/${SOC_SERIES_PREFIX}/r_intc_nmi/r_intc_nmi.c)
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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+
* @ingroup RENESAS_INTERFACES
9+
* @defgroup EXTERNAL_IRQ_API External IRQ Interface
10+
* @brief Interface for detecting external interrupts.
11+
*
12+
* @section EXTERNAL_IRQ_API_Summary Summary
13+
* The External IRQ Interface is for configuring interrupts to fire when a trigger condition is detected on an
14+
* external IRQ pin.
15+
*
16+
* The External IRQ Interface can be implemented by:
17+
* - @ref INTC_NMI
18+
* - @ref INTC_IRQ
19+
*
20+
* @{
21+
**********************************************************************************************************************/
22+
23+
#ifndef R_EXTERNAL_IRQ_API_H
24+
#define R_EXTERNAL_IRQ_API_H
25+
26+
/***********************************************************************************************************************
27+
* Includes
28+
**********************************************************************************************************************/
29+
30+
/* Includes board and MCU related header files. */
31+
#include "bsp_api.h"
32+
33+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
34+
FSP_HEADER
35+
36+
/**********************************************************************************************************************
37+
* Macro definitions
38+
*********************************************************************************************************************/
39+
40+
/*********************************************************************************************************************
41+
* Typedef definitions
42+
*********************************************************************************************************************/
43+
44+
/** Callback function parameter data */
45+
typedef struct st_external_irq_callback_args
46+
{
47+
/** Placeholder for user data. Set in @ref external_irq_api_t::open function in @ref external_irq_cfg_t. */
48+
void const * p_context;
49+
uint32_t channel; ///< The physical hardware channel that caused the interrupt.
50+
} external_irq_callback_args_t;
51+
52+
/** Condition that will trigger an interrupt when detected. */
53+
typedef enum e_external_irq_trigger
54+
{
55+
EXTERNAL_IRQ_TRIG_FALLING = 0, ///< Falling edge trigger
56+
EXTERNAL_IRQ_TRIG_RISING = 1, ///< Rising edge trigger
57+
EXTERNAL_IRQ_TRIG_BOTH_EDGE = 2, ///< Both edges trigger
58+
EXTERNAL_IRQ_TRIG_LEVEL_LOW = 3, ///< Low level trigger
59+
} external_irq_trigger_t;
60+
61+
/** External IRQ input pin digital filtering sample clock divisor settings. The digital filter rejects trigger
62+
* conditions that are shorter than 3 periods of the filter clock.
63+
*/
64+
typedef enum e_external_irq_pclk_div
65+
{
66+
EXTERNAL_IRQ_PCLK_DIV_BY_1 = 0, ///< Filter using PCLK divided by 1
67+
EXTERNAL_IRQ_PCLK_DIV_BY_8 = 1, ///< Filter using PCLK divided by 8
68+
EXTERNAL_IRQ_PCLK_DIV_BY_32 = 2, ///< Filter using PCLK divided by 32
69+
EXTERNAL_IRQ_PCLK_DIV_BY_64 = 3, ///< Filter using PCLK divided by 64
70+
} external_irq_pclk_div_t;
71+
72+
/** User configuration structure, used in open function */
73+
typedef struct st_external_irq_cfg
74+
{
75+
uint8_t channel; ///< Hardware channel used.
76+
uint8_t ipl; ///< Interrupt priority
77+
IRQn_Type irq; ///< NVIC interrupt number assigned to this instance
78+
external_irq_trigger_t trigger; ///< Trigger setting.
79+
external_irq_pclk_div_t pclk_div; ///< Digital filter clock divisor setting.
80+
bool filter_enable; ///< Digital filter enable/disable setting.
81+
82+
/** Callback provided external input trigger occurs. */
83+
void (* p_callback)(external_irq_callback_args_t * p_args);
84+
85+
/** Placeholder for user data. Passed to the user callback in @ref external_irq_callback_args_t. */
86+
void const * p_context;
87+
void const * p_extend; ///< External IRQ hardware dependent configuration.
88+
} external_irq_cfg_t;
89+
90+
/** External IRQ control block. Allocate an instance specific control block to pass into the external IRQ API calls.
91+
* @par Implemented as
92+
* - intc_nmi_instance_ctrl_t
93+
* - intc_irq_instance_ctrl_t
94+
*/
95+
typedef void external_irq_ctrl_t;
96+
97+
/** External interrupt driver structure. External interrupt functions implemented at the HAL layer will follow this API. */
98+
typedef struct st_external_irq_api
99+
{
100+
/** Initial configuration.
101+
* @par Implemented as
102+
* - @ref R_INTC_NMI_ExternalIrqOpen()
103+
* - @ref R_INTC_IRQ_ExternalIrqOpen()
104+
*
105+
* @param[out] p_ctrl Pointer to control block. Must be declared by user. Value set here.
106+
* @param[in] p_cfg Pointer to configuration structure. All elements of the structure must be set by user.
107+
*/
108+
fsp_err_t (* open)(external_irq_ctrl_t * const p_ctrl, external_irq_cfg_t const * const p_cfg);
109+
110+
/** Enable callback when an external trigger condition occurs.
111+
* @par Implemented as
112+
* - @ref R_INTC_NMI_ExternalIrqEnable()
113+
* - @ref R_INTC_IRQ_ExternalIrqEnable()
114+
*
115+
* @param[in] p_ctrl Control block set in Open call for this external interrupt.
116+
*/
117+
fsp_err_t (* enable)(external_irq_ctrl_t * const p_ctrl);
118+
119+
/** Disable callback when external trigger condition occurs.
120+
* @par Implemented as
121+
* - @ref R_INTC_NMI_ExternalIrqDisable()
122+
* - @ref R_INTC_IRQ_ExternalIrqDisable()
123+
*
124+
* @param[in] p_ctrl Control block set in Open call for this external interrupt.
125+
*/
126+
fsp_err_t (* disable)(external_irq_ctrl_t * const p_ctrl);
127+
128+
/**
129+
* Specify callback function and optional context pointer and working memory pointer.
130+
* @par Implemented as
131+
* - R_INTC_NMI_ExternalIrqCallbackSet()
132+
* - R_INTC_IRQ_ExternalIrqCallbackSet()
133+
*
134+
* @param[in] p_ctrl Pointer to the Extneral IRQ control block.
135+
* @param[in] p_callback Callback function
136+
* @param[in] p_context Pointer to send to callback function
137+
* @param[in] p_working_memory Pointer to volatile memory where callback structure can be allocated.
138+
* Callback arguments allocated here are only valid during the callback.
139+
*/
140+
fsp_err_t (* callbackSet)(external_irq_ctrl_t * const p_api_ctrl,
141+
void ( * p_callback)(external_irq_callback_args_t *),
142+
void const * const p_context,
143+
external_irq_callback_args_t * const p_callback_memory);
144+
145+
/** Allow driver to be reconfigured. May reduce power consumption.
146+
* @par Implemented as
147+
* - @ref R_INTC_NMI_ExternalIrqClose()
148+
* - @ref R_INTC_IRQ_ExternalIrqClose()
149+
*
150+
* @param[in] p_ctrl Control block set in Open call for this external interrupt.
151+
*/
152+
fsp_err_t (* close)(external_irq_ctrl_t * const p_ctrl);
153+
} external_irq_api_t;
154+
155+
/** This structure encompasses everything that is needed to use an instance of this interface. */
156+
typedef struct st_external_irq_instance
157+
{
158+
external_irq_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
159+
external_irq_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
160+
external_irq_api_t const * p_api; ///< Pointer to the API structure for this instance
161+
} external_irq_instance_t;
162+
163+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
164+
FSP_FOOTER
165+
166+
/*******************************************************************************************************************//**
167+
* @} (end defgroup EXTERNAL_IRQ_API)
168+
**********************************************************************************************************************/
169+
170+
#endif
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
* @addtogroup INTC_IRQ
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_INTC_IRQ_H
13+
#define R_INTC_IRQ_H
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
#include "bsp_api.h"
19+
#include "r_external_irq_api.h"
20+
21+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
22+
FSP_HEADER
23+
24+
/***********************************************************************************************************************
25+
* Macro definitions
26+
**********************************************************************************************************************/
27+
28+
/*********************************************************************************************************************
29+
* Typedef definitions
30+
*********************************************************************************************************************/
31+
32+
/** INTC_IRQ private control block. DO NOT MODIFY. Initialization occurs when R_INTC_IRQ_ExternalIrqOpen is called. */
33+
typedef struct st_intc_irq_instance_ctrl
34+
{
35+
uint32_t open; ///< Used to determine if channel control block is in use
36+
IRQn_Type irq; ///< NVIC interrupt number
37+
uint8_t channel; ///< Channel
38+
39+
#if BSP_TZ_SECURE_BUILD
40+
external_irq_callback_args_t * p_callback_memory; // Pointer to non-secure memory that can be used to pass arguments to a callback in non-secure memory.
41+
#endif
42+
void (* p_callback)(external_irq_callback_args_t * p_args); // Pointer to callback that is called when an edge is detected on the external irq pin.
43+
44+
/** Placeholder for user data. Passed to the user callback in ::external_irq_callback_args_t. */
45+
void const * p_context;
46+
} intc_irq_instance_ctrl_t;
47+
48+
/**********************************************************************************************************************
49+
* Exported global variables
50+
**********************************************************************************************************************/
51+
52+
/** @cond INC_HEADER_DEFS_SEC */
53+
/** Filled in Interface API structure for this Instance. */
54+
extern const external_irq_api_t g_external_irq_on_intc_irq;
55+
56+
/** @endcond */
57+
58+
/***********************************************************************************************************************
59+
* Public APIs
60+
**********************************************************************************************************************/
61+
fsp_err_t R_INTC_IRQ_ExternalIrqOpen(external_irq_ctrl_t * const p_api_ctrl, external_irq_cfg_t const * const p_cfg);
62+
63+
fsp_err_t R_INTC_IRQ_ExternalIrqEnable(external_irq_ctrl_t * const p_api_ctrl);
64+
65+
fsp_err_t R_INTC_IRQ_ExternalIrqDisable(external_irq_ctrl_t * const p_api_ctrl);
66+
67+
fsp_err_t R_INTC_IRQ_ExternalIrqCallbackSet(external_irq_ctrl_t * const p_api_ctrl,
68+
void ( * p_callback)(
69+
external_irq_callback_args_t *),
70+
void const * const p_context,
71+
external_irq_callback_args_t * const p_callback_memory);
72+
73+
fsp_err_t R_INTC_IRQ_ExternalIrqClose(external_irq_ctrl_t * const p_api_ctrl);
74+
75+
/*******************************************************************************************************************//**
76+
* @} (end defgroup INTC_IRQ)
77+
**********************************************************************************************************************/
78+
79+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
80+
FSP_FOOTER
81+
82+
#endif // R_INTC_IRQ_H
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
* @addtogroup INTC_NMI
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_INTC_NMI_H
13+
#define R_INTC_NMI_H
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
#include "bsp_api.h"
19+
#include "r_external_irq_api.h"
20+
21+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
22+
FSP_HEADER
23+
24+
/***********************************************************************************************************************
25+
* Macro definitions
26+
**********************************************************************************************************************/
27+
28+
/*********************************************************************************************************************
29+
* Typedef definitions
30+
*********************************************************************************************************************/
31+
32+
/** INTC_NMI private control block. DO NOT MODIFY. Initialization occurs when R_INTC_NMI_ExternalIrqOpen is called. */
33+
typedef struct st_intc_nmi_instance_ctrl
34+
{
35+
uint32_t open; ///< Used to determine if channel control block is in use
36+
IRQn_Type irq; ///< NVIC Interrupt number
37+
uint8_t channel; ///< Channel
38+
39+
#if BSP_TZ_SECURE_BUILD
40+
external_irq_callback_args_t * p_callback_memory; // Pointer to non-secure memory that can be used to pass arguments to a callback in non-secure memory.
41+
#endif
42+
void (* p_callback)(external_irq_callback_args_t * p_args); // Pointer to callback that is called when an edge is detected on the external irq pin.
43+
44+
/** Placeholder for user data. Passed to the user callback in ::external_irq_callback_args_t. */
45+
void const * p_context;
46+
} intc_nmi_instance_ctrl_t;
47+
48+
/**********************************************************************************************************************
49+
* Exported global variables
50+
**********************************************************************************************************************/
51+
52+
/** @cond INC_HEADER_DEFS_SEC */
53+
/** Filled in Interface API structure for this Instance. */
54+
extern const external_irq_api_t g_external_irq_on_intc_nmi;
55+
56+
/** @endcond */
57+
58+
/***********************************************************************************************************************
59+
* Public APIs
60+
**********************************************************************************************************************/
61+
fsp_err_t R_INTC_NMI_ExternalIrqOpen(external_irq_ctrl_t * const p_api_ctrl, external_irq_cfg_t const * const p_cfg);
62+
63+
fsp_err_t R_INTC_NMI_ExternalIrqEnable(external_irq_ctrl_t * const p_api_ctrl);
64+
65+
fsp_err_t R_INTC_NMI_ExternalIrqDisable(external_irq_ctrl_t * const p_api_ctrl);
66+
67+
fsp_err_t R_INTC_NMI_ExternalIrqCallbackSet(external_irq_ctrl_t * const p_api_ctrl,
68+
void ( * p_callback)(
69+
external_irq_callback_args_t *),
70+
void const * const p_context,
71+
external_irq_callback_args_t * const p_callback_memory);
72+
73+
fsp_err_t R_INTC_NMI_ExternalIrqClose(external_irq_ctrl_t * const p_api_ctrl);
74+
75+
/*******************************************************************************************************************//**
76+
* @} (end defgroup INTC_NMI)
77+
**********************************************************************************************************************/
78+
79+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
80+
FSP_FOOTER
81+
82+
#endif // R_INTC_NMI_H

0 commit comments

Comments
 (0)