Skip to content

Commit c3f0e8a

Browse files
committed
hal: renesas: rza: Add WDT support for RZ/A series
Add WDT FSP HAL driver to support Zephyr WDT driver for RZ/A3UL Signed-off-by: Nhut Nguyen <[email protected]> Signed-off-by: Quang Le <[email protected]>
1 parent 740a944 commit c3f0e8a

File tree

5 files changed

+776
-0
lines changed

5 files changed

+776
-0
lines changed

drivers/rz/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,8 @@ endif()
9494
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_MTU
9595
fsp/src/${SOC_SERIES_PREFIX}/r_mtu3/r_mtu3.c)
9696

97+
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_WDT
98+
fsp/src/${SOC_SERIES_PREFIX}/r_wdt/r_wdt.c)
99+
97100
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_CMTW
98101
fsp/src/${SOC_SERIES_PREFIX}/r_cmtw/r_cmtw.c)

drivers/rz/fsp/inc/api/r_wdt_api.h

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
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_MONITORING_INTERFACES
9+
* @defgroup WDT_API WDT Interface
10+
* @brief Interface for watch dog timer functions.
11+
*
12+
* @section WDT_API_Summary Summary
13+
* The WDT interface for the Watchdog Timer (WDT) peripheral provides watchdog functionality including resetting the
14+
* device or generating an interrupt.
15+
*
16+
*
17+
* @{
18+
**********************************************************************************************************************/
19+
20+
#ifndef R_WDT_API_H
21+
#define R_WDT_API_H
22+
23+
/***********************************************************************************************************************
24+
* Includes
25+
**********************************************************************************************************************/
26+
27+
/* Register definitions, common services and error codes. */
28+
#include "bsp_api.h"
29+
30+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
31+
FSP_HEADER
32+
33+
/**********************************************************************************************************************
34+
* Macro definitions
35+
**********************************************************************************************************************/
36+
37+
/**********************************************************************************************************************
38+
* Typedef definitions
39+
**********************************************************************************************************************/
40+
#ifndef BSP_OVERRIDE_WDT_TIMEOUT_T
41+
42+
/** WDT time-out periods. */
43+
typedef enum e_wdt_timeout
44+
{
45+
WDT_TIMEOUT_128 = 0, ///< 128 clock cycles
46+
WDT_TIMEOUT_512, ///< 512 clock cycles
47+
WDT_TIMEOUT_1024, ///< 1024 clock cycles
48+
WDT_TIMEOUT_2048, ///< 2048 clock cycles
49+
WDT_TIMEOUT_4096, ///< 4096 clock cycles
50+
WDT_TIMEOUT_8192, ///< 8192 clock cycles
51+
WDT_TIMEOUT_16384, ///< 16384 clock cycles
52+
} wdt_timeout_t;
53+
#endif
54+
55+
#ifndef BSP_OVERRIDE_WDT_CLOCK_DIVISION_T
56+
57+
/** WDT clock division ratio. */
58+
typedef enum e_wdt_clock_division
59+
{
60+
WDT_CLOCK_DIVISION_1 = 0, ///< CLK/1
61+
WDT_CLOCK_DIVISION_4 = 1, ///< CLK/4
62+
WDT_CLOCK_DIVISION_16 = 2, ///< CLK/16
63+
WDT_CLOCK_DIVISION_32 = 3, ///< CLK/32
64+
WDT_CLOCK_DIVISION_64 = 4, ///< CLK/64
65+
WDT_CLOCK_DIVISION_128 = 15, ///< CLK/128
66+
WDT_CLOCK_DIVISION_256 = 5, ///< CLK/256
67+
WDT_CLOCK_DIVISION_512 = 6, ///< CLK/512
68+
WDT_CLOCK_DIVISION_2048 = 7, ///< CLK/2048
69+
WDT_CLOCK_DIVISION_8192 = 8, ///< CLK/8192
70+
} wdt_clock_division_t;
71+
#endif
72+
73+
#ifndef BSP_OVERRIDE_WDT_WINDOW_START_END_T
74+
/** WDT refresh permitted period window start position. */
75+
typedef enum e_wdt_window_start
76+
{
77+
WDT_WINDOW_START_25 = 0, ///< Start position = 25%
78+
WDT_WINDOW_START_50 = 1, ///< Start position = 50%
79+
WDT_WINDOW_START_75 = 2, ///< Start position = 75%
80+
WDT_WINDOW_START_100 = 3, ///< Start position = 100%
81+
} wdt_window_start_t;
82+
83+
/** WDT refresh permitted period window end position. */
84+
typedef enum e_wdt_window_end
85+
{
86+
WDT_WINDOW_END_75 = 0, ///< End position = 75%
87+
WDT_WINDOW_END_50 = 1, ///< End position = 50%
88+
WDT_WINDOW_END_25 = 2, ///< End position = 25%
89+
WDT_WINDOW_END_0 = 3, ///< End position = 0%
90+
} wdt_window_end_t;
91+
#endif
92+
93+
/** WDT Counter underflow and refresh error control. */
94+
typedef enum e_wdt_reset_control
95+
{
96+
WDT_RESET_CONTROL_NMI = 0, ///< NMI/IRQ request when counter underflows.
97+
WDT_RESET_CONTROL_RESET = 1, ///< Reset request when counter underflows.
98+
} wdt_reset_control_t;
99+
100+
/** WDT Counter operation in sleep mode. */
101+
typedef enum e_wdt_stop_control
102+
{
103+
WDT_STOP_CONTROL_DISABLE = 0, ///< Count will not stop when device enters sleep mode.
104+
WDT_STOP_CONTROL_ENABLE = 1, ///< Count will automatically stop when device enters sleep mode.
105+
} wdt_stop_control_t;
106+
107+
/** WDT status */
108+
typedef enum e_wdt_status
109+
{
110+
WDT_STATUS_NO_ERROR = 0, ///< No status flags set.
111+
WDT_STATUS_UNDERFLOW = 1, ///< Underflow flag set.
112+
WDT_STATUS_REFRESH_ERROR = 2, ///< Refresh error flag set. Refresh outside of permitted window.
113+
WDT_STATUS_UNDERFLOW_AND_REFRESH_ERROR = 3, ///< Underflow and refresh error flags set.
114+
WDT_STATUS_OVERFLOW = 4, ///< Overflow flag set.
115+
} wdt_status_t;
116+
117+
/** Callback function parameter data */
118+
typedef struct st_wdt_callback_args
119+
{
120+
void const * p_context; ///< Placeholder for user data. Set in @ref wdt_api_t::open function in @ref wdt_cfg_t.
121+
} wdt_callback_args_t;
122+
123+
/** WDT timeout data. Used to return frequency of WDT clock and timeout period */
124+
typedef struct st_wdt_timeout_values
125+
{
126+
uint32_t clock_frequency_hz; ///< Frequency of watchdog clock after divider.
127+
uint32_t timeout_clocks; ///< Timeout period in units of watchdog clock ticks.
128+
} wdt_timeout_values_t;
129+
130+
/** WDT control block. Allocate an instance specific control block to pass into the WDT API calls.
131+
*/
132+
typedef void wdt_ctrl_t;
133+
134+
/** WDT configuration parameters. */
135+
typedef struct st_wdt_cfg
136+
{
137+
wdt_timeout_t timeout; ///< Timeout period.
138+
wdt_clock_division_t clock_division; ///< Clock divider.
139+
wdt_window_start_t window_start; ///< Refresh permitted window start position.
140+
wdt_window_end_t window_end; ///< Refresh permitted window end position.
141+
wdt_reset_control_t reset_control; ///< Select NMI/IRQ or reset generated on underflow.
142+
wdt_stop_control_t stop_control; ///< Select whether counter operates in sleep mode.
143+
void (* p_callback)(wdt_callback_args_t * p_args); ///< Callback provided when a WDT ISR occurs.
144+
145+
/** Placeholder for user data. Passed to the user callback in wdt_callback_args_t. */
146+
void const * p_context;
147+
void const * p_extend; ///< Placeholder for user extension.
148+
} wdt_cfg_t;
149+
150+
/** WDT functions implemented at the HAL layer will follow this API. */
151+
typedef struct st_wdt_api
152+
{
153+
/** Initialize the WDT in register start mode. In auto-start mode (Supported devices only) with NMI output it
154+
* registers the NMI callback.
155+
*
156+
* @param[in] p_ctrl Pointer to control structure.
157+
* @param[in] p_cfg Pointer to pin configuration structure.
158+
*/
159+
fsp_err_t (* open)(wdt_ctrl_t * const p_ctrl, wdt_cfg_t const * const p_cfg);
160+
161+
/** Refresh the watchdog timer.
162+
*
163+
* @param[in] p_ctrl Pointer to control structure.
164+
*/
165+
fsp_err_t (* refresh)(wdt_ctrl_t * const p_ctrl);
166+
167+
/** Read the status of the WDT.
168+
*
169+
* @param[in] p_ctrl Pointer to control structure.
170+
* @param[out] p_status Pointer to variable to return status information through.
171+
*/
172+
fsp_err_t (* statusGet)(wdt_ctrl_t * const p_ctrl, wdt_status_t * const p_status);
173+
174+
/** Clear the status flags of the WDT.
175+
*
176+
* @param[in] p_ctrl Pointer to control structure.
177+
* @param[in] status Status condition(s) to clear.
178+
*/
179+
fsp_err_t (* statusClear)(wdt_ctrl_t * const p_ctrl, const wdt_status_t status);
180+
181+
/** Read the current WDT counter value.
182+
*
183+
* @param[in] p_ctrl Pointer to control structure.
184+
* @param[out] p_count Pointer to variable to return current WDT counter value.
185+
*/
186+
fsp_err_t (* counterGet)(wdt_ctrl_t * const p_ctrl, uint32_t * const p_count);
187+
188+
/** Read the watchdog timeout values.
189+
*
190+
* @param[in] p_ctrl Pointer to control structure.
191+
* @param[out] p_timeout Pointer to structure to return timeout values.
192+
*/
193+
fsp_err_t (* timeoutGet)(wdt_ctrl_t * const p_ctrl, wdt_timeout_values_t * const p_timeout);
194+
195+
/** Specify callback function and optional context pointer and working memory pointer.
196+
*
197+
* @param[in] p_ctrl Pointer to the WDT control block.
198+
* @param[in] p_callback Callback function
199+
* @param[in] p_context Pointer to send to callback function
200+
* @param[in] p_callback_memory Pointer to volatile memory where callback structure can be allocated.
201+
* Callback arguments allocated here are only valid during the callback.
202+
*/
203+
fsp_err_t (* callbackSet)(wdt_ctrl_t * const p_ctrl, void (* p_callback)(wdt_callback_args_t *),
204+
void const * const p_context, wdt_callback_args_t * const p_callback_memory);
205+
} wdt_api_t;
206+
207+
/** This structure encompasses everything that is needed to use an instance of this interface. */
208+
typedef struct st_wdt_instance
209+
{
210+
wdt_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
211+
wdt_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
212+
wdt_api_t const * p_api; ///< Pointer to the API structure for this instance
213+
} wdt_instance_t;
214+
215+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
216+
FSP_FOOTER
217+
218+
#endif
219+
220+
/*******************************************************************************************************************//**
221+
* @} (end defgroup WDT_API)
222+
**********************************************************************************************************************/
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 WDT WDT
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_WDT_H
13+
#define R_WDT_H
14+
15+
#include "bsp_api.h"
16+
17+
#include "r_wdt_cfg.h"
18+
#include "r_wdt_api.h"
19+
20+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
21+
FSP_HEADER
22+
23+
/***********************************************************************************************************************
24+
* Macro definitions
25+
**********************************************************************************************************************/
26+
27+
/***********************************************************************************************************************
28+
* Typedef definitions
29+
**********************************************************************************************************************/
30+
31+
/** WDT private control block. DO NOT MODIFY. Initialization occurs when R_WDT_Open() is called. */
32+
typedef struct st_wdt_instance_ctrl
33+
{
34+
uint32_t wdt_open; // Indicates whether the open() API has been successfully
35+
// called.
36+
wdt_cfg_t const * p_cfg; // Pointer to the configuration block.
37+
void const * p_context; // Placeholder for user data. Passed to the user callback in
38+
// wdt_callback_args_t.
39+
void (* p_callback)(wdt_callback_args_t * p_args); // Callback provided when a WDT NMI ISR occurs.
40+
wdt_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+
} wdt_instance_ctrl_t;
42+
43+
/** WDT configuration extension. This extension is required. */
44+
typedef struct st_wdt_extended_cfg
45+
{
46+
uint16_t wdt_timeout; // Timeout value until the counter overflows.
47+
uint8_t overflow_ipl; // WDT Overflow interrupt priority.
48+
IRQn_Type overflow_irq; // WDT Overflow interrupt ID.
49+
} wdt_extended_cfg_t;
50+
51+
/**********************************************************************************************************************
52+
* Exported global variables
53+
**********************************************************************************************************************/
54+
55+
/** @cond INC_HEADER_DEFS_SEC */
56+
/** Filled in Interface API structure for this Instance. */
57+
extern const wdt_api_t g_wdt_on_wdt;
58+
59+
/** @endcond */
60+
61+
/**********************************************************************************************************************
62+
* Public Function Prototypes
63+
**********************************************************************************************************************/
64+
fsp_err_t R_WDT_Refresh(wdt_ctrl_t * const p_ctrl);
65+
66+
fsp_err_t R_WDT_Open(wdt_ctrl_t * const p_ctrl, wdt_cfg_t const * const p_cfg);
67+
68+
fsp_err_t R_WDT_StatusClear(wdt_ctrl_t * const p_ctrl, const wdt_status_t status);
69+
70+
fsp_err_t R_WDT_StatusGet(wdt_ctrl_t * const p_ctrl, wdt_status_t * const p_status);
71+
72+
fsp_err_t R_WDT_CounterGet(wdt_ctrl_t * const p_ctrl, uint32_t * const p_count);
73+
74+
fsp_err_t R_WDT_TimeoutGet(wdt_ctrl_t * const p_ctrl, wdt_timeout_values_t * const p_timeout);
75+
76+
fsp_err_t R_WDT_CallbackSet(wdt_ctrl_t * const p_ctrl,
77+
void ( * p_callback)(wdt_callback_args_t *),
78+
void const * const p_context,
79+
wdt_callback_args_t * const p_callback_memory);
80+
81+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
82+
FSP_FOOTER
83+
84+
#endif // R_WDT_H
85+
86+
/*******************************************************************************************************************//**
87+
* @} (end addtogroup WDT)
88+
**********************************************************************************************************************/

0 commit comments

Comments
 (0)