Skip to content

Commit f01650d

Browse files
thenguyenyfKhiemNguyenT
authored andcommitted
hal: renesas: ra: initial support for r_wdt
First commit to add support for Renesas RA r_wdt Signed-off-by: The Nguyen <[email protected]>
1 parent 33408ed commit f01650d

File tree

5 files changed

+1018
-0
lines changed

5 files changed

+1018
-0
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_DAC
6969
fsp/src/r_dac/r_dac.c)
7070
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_USB_HOST
7171
fsp/src/r_usb_host/r_usb_host.c)
72+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_WDT
73+
fsp/src/r_wdt/r_wdt.c)
7274

7375
if(CONFIG_USE_RA_FSP_SCE)
7476
zephyr_include_directories(

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

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
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+
/** WDT refresh permitted period window start position. */
74+
typedef enum e_wdt_window_start
75+
{
76+
WDT_WINDOW_START_25 = 0, ///< Start position = 25%
77+
WDT_WINDOW_START_50 = 1, ///< Start position = 50%
78+
WDT_WINDOW_START_75 = 2, ///< Start position = 75%
79+
WDT_WINDOW_START_100 = 3, ///< Start position = 100%
80+
} wdt_window_start_t;
81+
82+
/** WDT refresh permitted period window end position. */
83+
typedef enum e_wdt_window_end
84+
{
85+
WDT_WINDOW_END_75 = 0, ///< End position = 75%
86+
WDT_WINDOW_END_50 = 1, ///< End position = 50%
87+
WDT_WINDOW_END_25 = 2, ///< End position = 25%
88+
WDT_WINDOW_END_0 = 3, ///< End position = 0%
89+
} wdt_window_end_t;
90+
91+
/** WDT Counter underflow and refresh error control. */
92+
typedef enum e_wdt_reset_control
93+
{
94+
WDT_RESET_CONTROL_NMI = 0, ///< NMI/IRQ request when counter underflows.
95+
WDT_RESET_CONTROL_RESET = 1, ///< Reset request when counter underflows.
96+
} wdt_reset_control_t;
97+
98+
/** WDT Counter operation in sleep mode. */
99+
typedef enum e_wdt_stop_control
100+
{
101+
WDT_STOP_CONTROL_DISABLE = 0, ///< Count will not stop when device enters sleep mode.
102+
WDT_STOP_CONTROL_ENABLE = 1, ///< Count will automatically stop when device enters sleep mode.
103+
} wdt_stop_control_t;
104+
105+
/** WDT status */
106+
typedef enum e_wdt_status
107+
{
108+
WDT_STATUS_NO_ERROR = 0, ///< No status flags set.
109+
WDT_STATUS_UNDERFLOW = 1, ///< Underflow flag set.
110+
WDT_STATUS_REFRESH_ERROR = 2, ///< Refresh error flag set. Refresh outside of permitted window.
111+
WDT_STATUS_UNDERFLOW_AND_REFRESH_ERROR = 3, ///< Underflow and refresh error flags set.
112+
WDT_STATUS_OVERFLOW = 4, ///< Overflow flag set.
113+
} wdt_status_t;
114+
115+
/** Callback function parameter data */
116+
typedef struct st_wdt_callback_args
117+
{
118+
void const * p_context; ///< Placeholder for user data. Set in @ref wdt_api_t::open function in @ref wdt_cfg_t.
119+
} wdt_callback_args_t;
120+
121+
/** WDT timeout data. Used to return frequency of WDT clock and timeout period */
122+
typedef struct st_wdt_timeout_values
123+
{
124+
uint32_t clock_frequency_hz; ///< Frequency of watchdog clock after divider.
125+
uint32_t timeout_clocks; ///< Timeout period in units of watchdog clock ticks.
126+
} wdt_timeout_values_t;
127+
128+
/** WDT control block. Allocate an instance specific control block to pass into the WDT API calls.
129+
*/
130+
typedef void wdt_ctrl_t;
131+
132+
/** WDT configuration parameters. */
133+
typedef struct st_wdt_cfg
134+
{
135+
wdt_timeout_t timeout; ///< Timeout period.
136+
wdt_clock_division_t clock_division; ///< Clock divider.
137+
wdt_window_start_t window_start; ///< Refresh permitted window start position.
138+
wdt_window_end_t window_end; ///< Refresh permitted window end position.
139+
wdt_reset_control_t reset_control; ///< Select NMI/IRQ or reset generated on underflow.
140+
wdt_stop_control_t stop_control; ///< Select whether counter operates in sleep mode.
141+
void (* p_callback)(wdt_callback_args_t * p_args); ///< Callback provided when a WDT ISR occurs.
142+
143+
/** Placeholder for user data. Passed to the user callback in wdt_callback_args_t. */
144+
void const * p_context;
145+
void const * p_extend; ///< Placeholder for user extension.
146+
} wdt_cfg_t;
147+
148+
/** WDT functions implemented at the HAL layer will follow this API. */
149+
typedef struct st_wdt_api
150+
{
151+
/** Initialize the WDT in register start mode. In auto-start mode (Supported devices only) with NMI output it
152+
* registers the NMI callback.
153+
*
154+
* @param[in] p_ctrl Pointer to control structure.
155+
* @param[in] p_cfg Pointer to pin configuration structure.
156+
*/
157+
fsp_err_t (* open)(wdt_ctrl_t * const p_ctrl, wdt_cfg_t const * const p_cfg);
158+
159+
/** Refresh the watchdog timer.
160+
*
161+
* @param[in] p_ctrl Pointer to control structure.
162+
*/
163+
fsp_err_t (* refresh)(wdt_ctrl_t * const p_ctrl);
164+
165+
/** Read the status of the WDT.
166+
*
167+
* @param[in] p_ctrl Pointer to control structure.
168+
* @param[out] p_status Pointer to variable to return status information through.
169+
*/
170+
fsp_err_t (* statusGet)(wdt_ctrl_t * const p_ctrl, wdt_status_t * const p_status);
171+
172+
/** Clear the status flags of the WDT.
173+
*
174+
* @param[in] p_ctrl Pointer to control structure.
175+
* @param[in] status Status condition(s) to clear.
176+
*/
177+
fsp_err_t (* statusClear)(wdt_ctrl_t * const p_ctrl, const wdt_status_t status);
178+
179+
/** Read the current WDT counter value.
180+
*
181+
* @param[in] p_ctrl Pointer to control structure.
182+
* @param[out] p_count Pointer to variable to return current WDT counter value.
183+
*/
184+
fsp_err_t (* counterGet)(wdt_ctrl_t * const p_ctrl, uint32_t * const p_count);
185+
186+
/** Read the watchdog timeout values.
187+
*
188+
* @param[in] p_ctrl Pointer to control structure.
189+
* @param[out] p_timeout Pointer to structure to return timeout values.
190+
*/
191+
fsp_err_t (* timeoutGet)(wdt_ctrl_t * const p_ctrl, wdt_timeout_values_t * const p_timeout);
192+
193+
/** Specify callback function and optional context pointer and working memory pointer.
194+
*
195+
* @param[in] p_ctrl Pointer to the WDT control block.
196+
* @param[in] p_callback Callback function
197+
* @param[in] p_context Pointer to send to callback function
198+
* @param[in] p_callback_memory Pointer to volatile memory where callback structure can be allocated.
199+
* Callback arguments allocated here are only valid during the callback.
200+
*/
201+
fsp_err_t (* callbackSet)(wdt_ctrl_t * const p_ctrl, void (* p_callback)(wdt_callback_args_t *),
202+
void const * const p_context, wdt_callback_args_t * const p_callback_memory);
203+
} wdt_api_t;
204+
205+
/** This structure encompasses everything that is needed to use an instance of this interface. */
206+
typedef struct st_wdt_instance
207+
{
208+
wdt_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
209+
wdt_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
210+
wdt_api_t const * p_api; ///< Pointer to the API structure for this instance
211+
} wdt_instance_t;
212+
213+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
214+
FSP_FOOTER
215+
216+
#endif
217+
218+
/*******************************************************************************************************************//**
219+
* @} (end defgroup WDT_API)
220+
**********************************************************************************************************************/

drivers/ra/fsp/inc/instances/r_wdt.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
void const * p_context; // Placeholder for user data. Passed to the user callback in
37+
// wdt_callback_args_t.
38+
void (* p_callback)(wdt_callback_args_t * p_args); // Callback provided when a WDT NMI ISR occurs.
39+
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.
40+
} wdt_instance_ctrl_t;
41+
42+
/**********************************************************************************************************************
43+
* Exported global variables
44+
**********************************************************************************************************************/
45+
46+
/** @cond INC_HEADER_DEFS_SEC */
47+
/** Filled in Interface API structure for this Instance. */
48+
extern const wdt_api_t g_wdt_on_wdt;
49+
50+
/** @endcond */
51+
52+
/**********************************************************************************************************************
53+
* Public Function Prototypes
54+
**********************************************************************************************************************/
55+
fsp_err_t R_WDT_Refresh(wdt_ctrl_t * const p_ctrl);
56+
57+
fsp_err_t R_WDT_Open(wdt_ctrl_t * const p_ctrl, wdt_cfg_t const * const p_cfg);
58+
59+
fsp_err_t R_WDT_StatusClear(wdt_ctrl_t * const p_ctrl, const wdt_status_t status);
60+
61+
fsp_err_t R_WDT_StatusGet(wdt_ctrl_t * const p_ctrl, wdt_status_t * const p_status);
62+
63+
fsp_err_t R_WDT_CounterGet(wdt_ctrl_t * const p_ctrl, uint32_t * const p_count);
64+
65+
fsp_err_t R_WDT_TimeoutGet(wdt_ctrl_t * const p_ctrl, wdt_timeout_values_t * const p_timeout);
66+
67+
fsp_err_t R_WDT_CallbackSet(wdt_ctrl_t * const p_ctrl,
68+
void ( * p_callback)(wdt_callback_args_t *),
69+
void const * const p_context,
70+
wdt_callback_args_t * const p_callback_memory);
71+
72+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
73+
FSP_FOOTER
74+
75+
#endif // R_WDT_H
76+
77+
/*******************************************************************************************************************//**
78+
* @} (end addtogroup WDT)
79+
**********************************************************************************************************************/

0 commit comments

Comments
 (0)