Skip to content

Commit fcee5ef

Browse files
Hieu Nguyennhutnguyenkc
authored andcommitted
hal: renesas: rza: Initial PWM support for RZ/A series
Add MTU FSP HAL driver to support PWM driver for RZ/A series Signed-off-by: Hieu Nguyen <[email protected]> Signed-off-by: Nhut Nguyen <[email protected]>
1 parent 985d39b commit fcee5ef

File tree

8 files changed

+4745
-69
lines changed

8 files changed

+4745
-69
lines changed

drivers/rz/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,6 @@ else()
7979
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_SCI_UART
8080
fsp/src/${SOC_SERIES_PREFIX}/r_sci_uart/r_sci_uart.c)
8181
endif()
82+
83+
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_MTU
84+
fsp/src/${SOC_SERIES_PREFIX}/r_mtu3/r_mtu3.c)

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

Lines changed: 47 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/*******************************************************************************************************************//**
1111
* @defgroup TIMER_API Timer Interface
12-
* @ingroup RENESAS_INTERFACES
12+
* @ingroup RENESAS_TIMERS_INTERFACES
1313
* @brief Interface for timer functions.
1414
*
1515
* @section TIMER_API_SUMMARY Summary
@@ -19,10 +19,6 @@
1919
* If an instance supports output compare mode, it is provided in the extension configuration
2020
* timer_on_<instance>_cfg_t defined in r_<instance>.h.
2121
*
22-
* Implemented by:
23-
* - @ref GPT
24-
* - @ref GTM
25-
* - @ref MTU3
2622
*
2723
* @{
2824
**********************************************************************************************************************/
@@ -45,6 +41,8 @@ FSP_HEADER
4541
* Typedef definitions
4642
**********************************************************************************************************************/
4743

44+
#ifndef BSP_OVERRIDE_TIMER_EVENT_T
45+
4846
/** Events that can trigger a callback function */
4947
typedef enum e_timer_event
5048
{
@@ -53,21 +51,36 @@ typedef enum e_timer_event
5351
TIMER_EVENT_CAPTURE_A, ///< A capture has occurred on signal A
5452
TIMER_EVENT_CAPTURE_B, ///< A capture has occurred on signal B
5553
TIMER_EVENT_TROUGH, ///< Timer trough event (counter is 0, triangle-wave PWM only
56-
TIMER_EVENT_OUTPUT_COMPARE_0, ///< An output has occurred on signal 0
57-
TIMER_EVENT_OUTPUT_COMPARE_1, ///< An output has occurred on signal 1
58-
TIMER_EVENT_DEAD_TIME, ///< Dead time event
59-
TIMER_EVENT_CAPTURE_U, ///< A capture has occurred on signal U
60-
TIMER_EVENT_CAPTURE_V, ///< A capture has occurred on signal V
61-
TIMER_EVENT_CAPTURE_W, ///< A capture has occurred on signal W
54+
TIMER_EVENT_COMPARE_A, ///< A compare has occurred on signal A
55+
TIMER_EVENT_COMPARE_B, ///< A compare has occurred on signal B
56+
TIMER_EVENT_COMPARE_C, ///< A compare has occurred on signal C
57+
TIMER_EVENT_COMPARE_D, ///< A compare has occurred on signal D
58+
TIMER_EVENT_COMPARE_E, ///< A compare has occurred on signal E
59+
TIMER_EVENT_COMPARE_F, ///< A compare has occurred on signal F
60+
TIMER_EVENT_DEAD_TIME ///< Dead time event
6261
} timer_event_t;
62+
#endif
6363

6464
/** Timer variant types. */
6565
typedef enum e_timer_variant
6666
{
67-
TIMER_VARIANT_32_BIT, ///< 32-bit timer
68-
TIMER_VARIANT_16_BIT ///< 16-bit timer
67+
TIMER_VARIANT_32_BIT, ///< 32-bit timer
68+
TIMER_VARIANT_16_BIT ///< 16-bit timer
6969
} timer_variant_t;
7070

71+
/** Options for storing compare match value */
72+
typedef enum e_timer_compare_match
73+
{
74+
TIMER_COMPARE_MATCH_A = 0U, ///< Compare match A value
75+
TIMER_COMPARE_MATCH_B = 1U, ///< Compare match B value
76+
TIMER_COMPARE_MATCH_C = 2U, ///< Compare match C value
77+
TIMER_COMPARE_MATCH_D = 3U, ///< Compare match D value
78+
TIMER_COMPARE_MATCH_E = 4U, ///< Compare match E value
79+
TIMER_COMPARE_MATCH_F = 5U, ///< Compare match F value
80+
TIMER_COMPARE_MATCH_G = 6U, ///< Compare match G value
81+
TIMER_COMPARE_MATCH_H = 7U, ///< Compare match H value
82+
} timer_compare_match_t;
83+
7184
/** Callback function parameter data */
7285
typedef struct st_timer_callback_args
7386
{
@@ -80,19 +93,16 @@ typedef struct st_timer_callback_args
8093
} timer_callback_args_t;
8194

8295
/** Timer control block. Allocate an instance specific control block to pass into the timer API calls.
83-
* @par Implemented as
84-
* - gpt_instance_ctrl_t
85-
* - gtm_instance_ctrl_t
86-
* - mtu3_instance_ctrl_t
8796
*/
8897
typedef void timer_ctrl_t;
8998

9099
/** Possible status values returned by @ref timer_api_t::statusGet. */
91100
typedef enum e_timer_state
92101
{
93102
TIMER_STATE_STOPPED = 0, ///< Timer is stopped
94-
TIMER_STATE_COUNTING = 1, ///< Timer is running
103+
TIMER_STATE_COUNTING = 1 ///< Timer is running
95104
} timer_state_t;
105+
#ifndef BSP_OVERRIDE_TIMER_MODE_T
96106

97107
/** Timer operational modes */
98108
typedef enum e_timer_mode
@@ -109,16 +119,20 @@ typedef enum e_timer_mode
109119
* not need to be updated at each tough/crest interrupt. Instead, the trough and crest duty cycle values can be
110120
* set once and only need to be updated when the application needs to change the duty cycle.
111121
*/
112-
TIMER_MODE_TRIANGLE_WAVE_ASYMMETRIC_PWM_MODE3 = 6U,
122+
TIMER_MODE_TRIANGLE_WAVE_ASYMMETRIC_PWM_MODE3 = 6U
113123
} timer_mode_t;
114124

125+
#endif
126+
115127
/** Direction of timer count */
116128
typedef enum e_timer_direction
117129
{
118130
TIMER_DIRECTION_DOWN = 0, ///< Timer count goes up
119131
TIMER_DIRECTION_UP = 1 ///< Timer count goes down
120132
} timer_direction_t;
121133

134+
#ifndef BSP_OVERRIDE_TIMER_SOURCE_DIV_T
135+
122136
/** Clock source divisors */
123137
typedef enum e_timer_source_div
124138
{
@@ -133,7 +147,9 @@ typedef enum e_timer_source_div
133147
TIMER_SOURCE_DIV_256 = 8, ///< Timer clock source divided by 256
134148
TIMER_SOURCE_DIV_512 = 9, ///< Timer clock source divided by 512
135149
TIMER_SOURCE_DIV_1024 = 10, ///< Timer clock source divided by 1024
150+
TIMER_SOURCE_DIV_8192 = 13, ///< Timer clock source divided by 8192
136151
} timer_source_div_t;
152+
#endif
137153

138154
/** Timer information structure to store various information for a timer resource */
139155
typedef struct st_timer_info
@@ -183,136 +199,98 @@ typedef struct st_timer_cfg
183199
typedef struct st_timer_api
184200
{
185201
/** Initial configuration.
186-
* @par Implemented as
187-
* - @ref R_GPT_Open()
188-
* - @ref R_GTM_Open()
189-
* - @ref R_MTU3_Open()
190202
*
191203
* @param[in] p_ctrl Pointer to control block. Must be declared by user. Elements set here.
192204
* @param[in] p_cfg Pointer to configuration structure. All elements of this structure must be set by user.
193205
*/
194206
fsp_err_t (* open)(timer_ctrl_t * const p_ctrl, timer_cfg_t const * const p_cfg);
195207

196208
/** Start the counter.
197-
* @par Implemented as
198-
* - @ref R_GPT_Start()
199-
* - @ref R_GTM_Start()
200-
* - @ref R_MTU3_Start()
201209
*
202210
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
203211
*/
204212
fsp_err_t (* start)(timer_ctrl_t * const p_ctrl);
205213

206214
/** Stop the counter.
207-
* @par Implemented as
208-
* - @ref R_GPT_Stop()
209-
* - @ref R_GTM_Stop()
210-
* - @ref R_MTU3_Stop()
211215
*
212216
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
213217
*/
214218
fsp_err_t (* stop)(timer_ctrl_t * const p_ctrl);
215219

216220
/** Reset the counter to the initial value.
217-
* @par Implemented as
218-
* - @ref R_GPT_Reset()
219-
* - @ref R_GTM_Reset()
220-
* - @ref R_MTU3_Reset()
221221
*
222222
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
223223
*/
224224
fsp_err_t (* reset)(timer_ctrl_t * const p_ctrl);
225225

226226
/** Enables input capture.
227-
* @par Implemented as
228-
* - @ref R_GPT_Enable()
229-
* - @ref R_GTM_Enable()
230-
* - @ref R_MTU3_Enable()
231227
*
232228
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
233229
*/
234230
fsp_err_t (* enable)(timer_ctrl_t * const p_ctrl);
235231

236232
/** Disables input capture.
237-
* @par Implemented as
238-
* - @ref R_GPT_Disable()
239-
* - @ref R_GTM_Disable()
240-
* - @ref R_MTU3_Disable()
241233
*
242234
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
243235
*/
244236
fsp_err_t (* disable)(timer_ctrl_t * const p_ctrl);
245237

246238
/** Set the time until the timer expires. See implementation for details of period update timing.
247239
*
248-
* @par Implemented as
249-
* - @ref R_GPT_PeriodSet()
250-
* - @ref R_GTM_PeriodSet()
251-
* - @ref R_MTU3_PeriodSet()
252240
*
253241
* @note Timer expiration may or may not generate a CPU interrupt based on how the timer is configured in
254242
* @ref timer_api_t::open.
255243
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
256-
* @param[in] p_period Time until timer should expire.
244+
* @param[in] period Time until timer should expire.
257245
*/
258246
fsp_err_t (* periodSet)(timer_ctrl_t * const p_ctrl, uint32_t const period);
259247

260248
/** Sets the number of counts for the pin level to be high. If the timer is counting, the updated duty cycle is
261249
* reflected after the next timer expiration.
262250
*
263-
* @par Implemented as
264-
* - @ref R_GPT_DutyCycleSet()
265-
* - @ref R_GTM_DutyCycleSet()
266-
* - @ref R_MTU3_DutyCycleSet()
267251
*
268252
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
269253
* @param[in] duty_cycle_counts Time until duty cycle should expire.
270254
* @param[in] pin Which output pin to update. See implementation for details.
271255
*/
272256
fsp_err_t (* dutyCycleSet)(timer_ctrl_t * const p_ctrl, uint32_t const duty_cycle_counts, uint32_t const pin);
273257

258+
/** Set a compare match value in raw counts.
259+
*
260+
*
261+
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
262+
* @param[in] compare_match_value Timer value to trigger a compare match event.
263+
* @param[in] match_channel Which channel to update.
264+
*/
265+
fsp_err_t (* compareMatchSet)(timer_ctrl_t * const p_ctrl, uint32_t const compare_match_value,
266+
timer_compare_match_t const match_channel);
267+
274268
/** Stores timer information in p_info.
275-
* @par Implemented as
276-
* - @ref R_GPT_InfoGet()
277-
* - @ref R_GTM_InfoGet()
278-
* - @ref R_MTU3_InfoGet()
279269
*
280270
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
281271
* @param[out] p_info Collection of information for this timer.
282272
*/
283273
fsp_err_t (* infoGet)(timer_ctrl_t * const p_ctrl, timer_info_t * const p_info);
284274

285275
/** Get the current counter value and timer state and store it in p_status.
286-
* @par Implemented as
287-
* - @ref R_GPT_StatusGet()
288-
* - @ref R_GTM_StatusGet()
289-
* - @ref R_MTU3_StatusGet()
290276
*
291277
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
292278
* @param[out] p_status Current status of this timer.
293279
*/
294280
fsp_err_t (* statusGet)(timer_ctrl_t * const p_ctrl, timer_status_t * const p_status);
295281

296282
/** Specify callback function and optional context pointer and working memory pointer.
297-
* @par Implemented as
298-
* - @ref R_GPT_CallbackSet()
299-
* - @ref R_GTM_CallbackSet()
300-
* - @ref R_MTU3_CallbackSet()
301283
*
302284
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
303285
* @param[in] p_callback Callback function to register
304286
* @param[in] p_context Pointer to send to callback function
305287
* @param[in] p_working_memory Pointer to volatile memory where callback structure can be allocated.
306288
* Callback arguments allocated here are only valid during the callback.
307289
*/
308-
fsp_err_t (* callbackSet)(timer_ctrl_t * const p_api_ctrl, void (* p_callback)(timer_callback_args_t *),
290+
fsp_err_t (* callbackSet)(timer_ctrl_t * const p_ctrl, void (* p_callback)(timer_callback_args_t *),
309291
void const * const p_context, timer_callback_args_t * const p_callback_memory);
310292

311293
/** Allows driver to be reconfigured and may reduce power consumption.
312-
* @par Implemented as
313-
* - @ref R_GPT_Close()
314-
* - @ref R_GTM_Close()
315-
* - @ref R_MTU3_Close()
316294
*
317295
* @param[in] p_ctrl Control block set in @ref timer_api_t::open call for this timer.
318296
*/

0 commit comments

Comments
 (0)