feat(mcpwm): ETM support mcpwm timer TEZ/TEP events

This commit is contained in:
Chen Chen
2026-02-05 18:08:51 +08:00
parent a483acbf8f
commit 346a021d3d
13 changed files with 417 additions and 23 deletions
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include "soc/soc_caps.h"
#include "soc/mcpwm_struct.h"
#include "soc/mcpwm_reg.h"
#include "soc/clk_tree_defs.h"
#include "soc/pcr_struct.h"
#include "hal/mcpwm_types.h"
@@ -69,9 +70,16 @@ extern "C" {
#define MCPWM_LL_GEN_ACTION_TO_REG_CAL(action) ((uint8_t[]) {0, 1, 2, 3}[(action)])
#define MCPWM_LL_BRAKE_MODE_TO_REG_VAL(mode) ((uint8_t[]) {0, 1}[(mode)])
// MCPWM ETM timer event table
#define MCPWM_LL_TIMER_ETM_EVENT_TABLE(group, timer_id, event) \
(uint32_t[1][MCPWM_TIMER_ETM_EVENT_MAX]){{ \
[MCPWM_TIMER_ETM_EVENT_TEZ] = MCPWM0_EVT_TIMER0_TEZ + timer_id, \
[MCPWM_TIMER_ETM_EVENT_TEP] = MCPWM0_EVT_TIMER0_TEP + timer_id, \
}}[group][event]
// MCPWM ETM comparator event table
#define MCPWM_LL_ETM_COMPARATOR_EVENT_TABLE(group, oper_id, cmpr_id, event) \
(uint32_t[2][MCPWM_CMPR_ETM_EVENT_MAX]){ \
(uint32_t[1][MCPWM_CMPR_ETM_EVENT_MAX]){ \
{ \
[MCPWM_CMPR_ETM_EVENT_EQUAL] = MCPWM0_EVT_OP0_TEA + oper_id + 3 * cmpr_id, \
}, \
@@ -79,7 +87,7 @@ extern "C" {
// MCPWM ETM event comparator event table
#define MCPWM_LL_ETM_EVENT_COMPARATOR_EVENT_TABLE(group, oper_id, cmpr_id, event) \
(uint32_t[2][MCPWM_CMPR_ETM_EVENT_MAX]){ \
(uint32_t[1][MCPWM_CMPR_ETM_EVENT_MAX]){ \
{ \
[MCPWM_CMPR_ETM_EVENT_EQUAL] = MCPWM0_EVT_OP0_TEE1 + oper_id + 3 * cmpr_id, \
}, \
@@ -1699,6 +1707,29 @@ static inline void mcpwm_ll_etm_enable_evt_comparator_event(mcpwm_dev_t *mcpwm,
}
}
/**
* @brief Enable timer ETM event
*
* @param mcpwm Peripheral instance address
* @param timer_id Timer ID, index from 0 to 2
* @param event_type Timer ETM event type (TEZ or TEP)
* @param en True: enable ETM module, False: disable ETM module
*/
static inline void mcpwm_ll_etm_enable_timer_event(mcpwm_dev_t *mcpwm, int timer_id, mcpwm_timer_etm_event_type_t event_type, bool en)
{
uint32_t bit_offset;
if (event_type == MCPWM_TIMER_ETM_EVENT_TEZ) {
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEZ_EN_S;
} else { // MCPWM_TIMER_ETM_EVENT_TEP
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEP_EN_S;
}
if (en) {
mcpwm->evt_en.val |= 1 << bit_offset;
} else {
mcpwm->evt_en.val &= ~(1 << bit_offset);
}
}
#ifdef __cplusplus
}
#endif
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -11,6 +11,7 @@
#include <stdbool.h>
#include "soc/soc_caps.h"
#include "soc/mcpwm_struct.h"
#include "soc/mcpwm_reg.h"
#include "soc/clk_tree_defs.h"
#include "soc/pcr_struct.h"
#include "hal/mcpwm_types.h"
@@ -69,6 +70,13 @@ extern "C" {
#define MCPWM_LL_GEN_ACTION_TO_REG_CAL(action) ((uint8_t[]) {0, 1, 2, 3}[(action)])
#define MCPWM_LL_BRAKE_MODE_TO_REG_VAL(mode) ((uint8_t[]) {0, 1}[(mode)])
// MCPWM ETM timer event table
#define MCPWM_LL_TIMER_ETM_EVENT_TABLE(group, timer_id, event) \
(uint32_t[1][MCPWM_TIMER_ETM_EVENT_MAX]){{ \
[MCPWM_TIMER_ETM_EVENT_TEZ] = MCPWM_EVT_TIMER0_TEZ + timer_id, \
[MCPWM_TIMER_ETM_EVENT_TEP] = MCPWM_EVT_TIMER0_TEP + timer_id, \
}}[group][event]
// MCPWM ETM comparator event table
#define MCPWM_LL_ETM_COMPARATOR_EVENT_TABLE(group, oper_id, cmpr_id, event) \
(uint32_t [1][MCPWM_CMPR_ETM_EVENT_MAX]){{ \
@@ -1653,6 +1661,29 @@ static inline void mcpwm_ll_etm_enable_comparator_event(mcpwm_dev_t *mcpwm, int
}
}
/**
* @brief Enable timer ETM event
*
* @param mcpwm Peripheral instance address
* @param timer_id Timer ID, index from 0 to 2
* @param event_type Timer ETM event type (TEZ or TEP)
* @param en True: enable ETM module, False: disable ETM module
*/
static inline void mcpwm_ll_etm_enable_timer_event(mcpwm_dev_t *mcpwm, int timer_id, mcpwm_timer_etm_event_type_t event_type, bool en)
{
uint32_t bit_offset;
if (event_type == MCPWM_TIMER_ETM_EVENT_TEZ) {
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEZ_EN_S;
} else { // MCPWM_TIMER_ETM_EVENT_TEP
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEP_EN_S;
}
if (en) {
mcpwm->evt_en.val |= 1 << bit_offset;
} else {
mcpwm->evt_en.val &= ~(1 << bit_offset);
}
}
#ifdef __cplusplus
}
#endif
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -9,6 +9,7 @@
#include <stdbool.h>
#include "soc/soc_caps.h"
#include "soc/mcpwm_struct.h"
#include "soc/mcpwm_reg.h"
#include "soc/clk_tree_defs.h"
#include "soc/pcr_struct.h"
#include "hal/mcpwm_types.h"
@@ -67,6 +68,13 @@ extern "C" {
#define MCPWM_LL_GEN_ACTION_TO_REG_CAL(action) ((uint8_t[]) {0, 1, 2, 3}[(action)])
#define MCPWM_LL_BRAKE_MODE_TO_REG_VAL(mode) ((uint8_t[]) {0, 1}[(mode)])
// MCPWM ETM timer event table
#define MCPWM_LL_TIMER_ETM_EVENT_TABLE(group, timer_id, event) \
(uint32_t[1][MCPWM_TIMER_ETM_EVENT_MAX]){{ \
[MCPWM_TIMER_ETM_EVENT_TEZ] = MCPWM_EVT_TIMER0_TEZ + timer_id, \
[MCPWM_TIMER_ETM_EVENT_TEP] = MCPWM_EVT_TIMER0_TEP + timer_id, \
}}[group][event]
// MCPWM ETM comparator event table
#define MCPWM_LL_ETM_COMPARATOR_EVENT_TABLE(group, oper_id, cmpr_id, event) \
(uint32_t [1][MCPWM_CMPR_ETM_EVENT_MAX]){{ \
@@ -1651,6 +1659,29 @@ static inline void mcpwm_ll_etm_enable_comparator_event(mcpwm_dev_t *mcpwm, int
}
}
/**
* @brief Enable timer ETM event
*
* @param mcpwm Peripheral instance address
* @param timer_id Timer ID, index from 0 to 2
* @param event_type Timer ETM event type (TEZ or TEP)
* @param en True: enable ETM module, False: disable ETM module
*/
static inline void mcpwm_ll_etm_enable_timer_event(mcpwm_dev_t *mcpwm, int timer_id, mcpwm_timer_etm_event_type_t event_type, bool en)
{
uint32_t bit_offset;
if (event_type == MCPWM_TIMER_ETM_EVENT_TEZ) {
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEZ_EN_S;
} else { // MCPWM_TIMER_ETM_EVENT_TEP
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEP_EN_S;
}
if (en) {
mcpwm->evt_en.val |= 1 << bit_offset;
} else {
mcpwm->evt_en.val &= ~(1 << bit_offset);
}
}
#ifdef __cplusplus
}
#endif
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -9,6 +9,7 @@
#include <stdbool.h>
#include "soc/soc_caps.h"
#include "soc/mcpwm_struct.h"
#include "soc/mcpwm_reg.h"
#include "soc/clk_tree_defs.h"
#include "soc/pcr_struct.h"
#include "hal/mcpwm_types.h"
@@ -67,6 +68,13 @@ extern "C" {
#define MCPWM_LL_GEN_ACTION_TO_REG_CAL(action) ((uint8_t[]) {0, 1, 2, 3}[(action)])
#define MCPWM_LL_BRAKE_MODE_TO_REG_VAL(mode) ((uint8_t[]) {0, 1}[(mode)])
// MCPWM ETM timer event table
#define MCPWM_LL_TIMER_ETM_EVENT_TABLE(group, timer_id, event) \
(uint32_t[1][MCPWM_TIMER_ETM_EVENT_MAX]){{ \
[MCPWM_TIMER_ETM_EVENT_TEZ] = MCPWM_EVT_TIMER0_TEZ + timer_id, \
[MCPWM_TIMER_ETM_EVENT_TEP] = MCPWM_EVT_TIMER0_TEP + timer_id, \
}}[group][event]
// MCPWM ETM comparator event table
#define MCPWM_LL_ETM_COMPARATOR_EVENT_TABLE(group, oper_id, cmpr_id, event) \
(uint32_t [1][MCPWM_CMPR_ETM_EVENT_MAX]){{ \
@@ -1651,6 +1659,29 @@ static inline void mcpwm_ll_etm_enable_comparator_event(mcpwm_dev_t *mcpwm, int
}
}
/**
* @brief Enable timer ETM event
*
* @param mcpwm Peripheral instance address
* @param timer_id Timer ID, index from 0 to 2
* @param event_type Timer ETM event type (TEZ or TEP)
* @param en True: enable ETM module, False: disable ETM module
*/
static inline void mcpwm_ll_etm_enable_timer_event(mcpwm_dev_t *mcpwm, int timer_id, mcpwm_timer_etm_event_type_t event_type, bool en)
{
uint32_t bit_offset;
if (event_type == MCPWM_TIMER_ETM_EVENT_TEZ) {
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEZ_EN_S;
} else { // MCPWM_TIMER_ETM_EVENT_TEP
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEP_EN_S;
}
if (en) {
mcpwm->evt_en.val |= 1 << bit_offset;
} else {
mcpwm->evt_en.val &= ~(1 << bit_offset);
}
}
#ifdef __cplusplus
}
#endif
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include "soc/soc_caps.h"
#include "soc/mcpwm_struct.h"
#include "soc/mcpwm_reg.h"
#include "soc/clk_tree_defs.h"
#include "soc/pcr_struct.h"
#include "hal/mcpwm_types.h"
@@ -69,12 +70,28 @@ extern "C" {
#define MCPWM_LL_GEN_ACTION_TO_REG_CAL(action) ((uint8_t[]) {0, 1, 2, 3}[(action)])
#define MCPWM_LL_BRAKE_MODE_TO_REG_VAL(mode) ((uint8_t[]) {0, 1}[(mode)])
// MCPWM ETM timer event table
#define MCPWM_LL_TIMER_ETM_EVENT_TABLE(group, timer_id, event) \
(uint32_t[2][MCPWM_TIMER_ETM_EVENT_MAX]){ \
{ \
[MCPWM_TIMER_ETM_EVENT_TEZ] = MCPWM0_EVT_TIMER0_TEZ + timer_id, \
[MCPWM_TIMER_ETM_EVENT_TEP] = MCPWM0_EVT_TIMER0_TEP + timer_id, \
}, \
{ \
[MCPWM_TIMER_ETM_EVENT_TEZ] = MCPWM1_EVT_TIMER0_TEZ + timer_id, \
[MCPWM_TIMER_ETM_EVENT_TEP] = MCPWM1_EVT_TIMER0_TEP + timer_id, \
}, \
}[group][event]
// MCPWM ETM comparator event table
#define MCPWM_LL_ETM_COMPARATOR_EVENT_TABLE(group, oper_id, cmpr_id, event) \
(uint32_t[2][MCPWM_CMPR_ETM_EVENT_MAX]){ \
{ \
[MCPWM_CMPR_ETM_EVENT_EQUAL] = MCPWM0_EVT_OP0_TEA + oper_id + 3 * cmpr_id, \
}, \
{ \
[MCPWM_CMPR_ETM_EVENT_EQUAL] = MCPWM1_EVT_OP0_TEA + oper_id + 3 * cmpr_id, \
}, \
}[group][event]
// MCPWM ETM event comparator event table
@@ -82,7 +99,10 @@ extern "C" {
(uint32_t[2][MCPWM_CMPR_ETM_EVENT_MAX]){ \
{ \
[MCPWM_CMPR_ETM_EVENT_EQUAL] = MCPWM0_EVT_OP0_TEE1 + oper_id + 3 * cmpr_id, \
}, \
}, \
{ \
[MCPWM_CMPR_ETM_EVENT_EQUAL] = MCPWM1_EVT_OP0_TEE1 + oper_id + 3 * cmpr_id, \
}, \
}[group][event]
/**
@@ -1717,6 +1737,29 @@ static inline void mcpwm_ll_etm_enable_evt_comparator_event(mcpwm_dev_t *mcpwm,
}
}
/**
* @brief Enable timer ETM event
*
* @param mcpwm Peripheral instance address
* @param timer_id Timer ID, index from 0 to 2
* @param event_type Timer ETM event type (TEZ or TEP)
* @param en True: enable ETM module, False: disable ETM module
*/
static inline void mcpwm_ll_etm_enable_timer_event(mcpwm_dev_t *mcpwm, int timer_id, mcpwm_timer_etm_event_type_t event_type, bool en)
{
uint32_t bit_offset;
if (event_type == MCPWM_TIMER_ETM_EVENT_TEZ) {
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEZ_EN_S;
} else { // MCPWM_TIMER_ETM_EVENT_TEP
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEP_EN_S;
}
if (en) {
mcpwm->evt_en.val |= 1 << bit_offset;
} else {
mcpwm->evt_en.val &= ~(1 << bit_offset);
}
}
#ifdef __cplusplus
}
#endif
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -12,6 +12,7 @@
#include <stdio.h>
#include "soc/soc_caps.h"
#include "soc/mcpwm_struct.h"
#include "soc/mcpwm_reg.h"
#include "soc/clk_tree_defs.h"
#include "soc/hp_sys_clkrst_struct.h"
#include "hal/mcpwm_types.h"
@@ -71,6 +72,18 @@ extern "C" {
#define MCPWM_LL_GEN_ACTION_TO_REG_CAL(action) ((uint8_t[]) {0, 1, 2, 3}[(action)])
#define MCPWM_LL_BRAKE_MODE_TO_REG_VAL(mode) ((uint8_t[]) {0, 1}[(mode)])
#define MCPWM_LL_TIMER_ETM_EVENT_TABLE(group, timer_id, event) \
(uint32_t[2][MCPWM_TIMER_ETM_EVENT_MAX]){ \
{ \
[MCPWM_TIMER_ETM_EVENT_TEZ] = MCPWM0_EVT_TIMER0_TEZ + timer_id, \
[MCPWM_TIMER_ETM_EVENT_TEP] = MCPWM0_EVT_TIMER0_TEP + timer_id, \
}, \
{ \
[MCPWM_TIMER_ETM_EVENT_TEZ] = MCPWM1_EVT_TIMER0_TEZ + timer_id, \
[MCPWM_TIMER_ETM_EVENT_TEP] = MCPWM1_EVT_TIMER0_TEP + timer_id, \
}, \
}[group][event]
// MCPWM ETM comparator event table
#define MCPWM_LL_ETM_COMPARATOR_EVENT_TABLE(group, oper_id, cmpr_id, event) \
(uint32_t[2][MCPWM_CMPR_ETM_EVENT_MAX]){ \
@@ -1758,6 +1771,29 @@ static inline void mcpwm_ll_etm_enable_evt_comparator_event(mcpwm_dev_t *mcpwm,
}
}
/**
* @brief Enable timer ETM event
*
* @param mcpwm Peripheral instance address
* @param timer_id Timer ID, index from 0 to 2
* @param event_type Timer ETM event type (TEZ or TEP)
* @param en True: enable ETM module, False: disable ETM module
*/
static inline void mcpwm_ll_etm_enable_timer_event(mcpwm_dev_t *mcpwm, int timer_id, mcpwm_timer_etm_event_type_t event_type, bool en)
{
uint32_t bit_offset;
if (event_type == MCPWM_TIMER_ETM_EVENT_TEZ) {
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEZ_EN_S; // TEZ events start at bit 3
} else { // MCPWM_TIMER_ETM_EVENT_TEP
bit_offset = timer_id + MCPWM_EVT_TIMER0_TEP_EN_S; // TEP events start at bit 6
}
if (en) {
mcpwm->evt_en.val |= 1 << bit_offset;
} else {
mcpwm->evt_en.val &= ~(1 << bit_offset);
}
}
#ifdef __cplusplus
}
#endif
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -105,6 +105,15 @@ typedef enum {
MCPWM_CAP_EDGE_NEG, /*!< Capture on the negative edge */
} mcpwm_capture_edge_t;
/**
* @brief MCPWM timer specific events that supported by the ETM module
*/
typedef enum {
MCPWM_TIMER_ETM_EVENT_TEZ, /*!< The timer reaches zero */
MCPWM_TIMER_ETM_EVENT_TEP, /*!< The timer reaches peak */
MCPWM_TIMER_ETM_EVENT_MAX, /*!< Maximum number of timer events */
} mcpwm_timer_etm_event_type_t;
/**
* @brief MCPWM comparator specific events that supported by the ETM module
*/