mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-22 13:01:16 +03:00
Merge branch 'refactor/mcpwm_tiny_refactor' into 'master'
refactor(mcpwm): update MCPWM soft sync source enum and related logic See merge request espressif/esp-idf!51492
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
if(${target} STREQUAL "linux")
|
||||
return() # This component is not supported by the POSIX/Linux simulator
|
||||
endif()
|
||||
|
||||
set(srcs)
|
||||
set(public_include "include")
|
||||
@@ -12,25 +15,20 @@ if(CONFIG_SOC_MCPWM_SUPPORTED)
|
||||
"src/mcpwm_sync.c"
|
||||
"src/mcpwm_timer.c")
|
||||
if(CONFIG_SOC_PAU_SUPPORTED AND CONFIG_SOC_MCPWM_SUPPORT_SLEEP_RETENTION)
|
||||
list(APPEND srcs "${target}/mcpwm_retention.c")
|
||||
list(APPEND srcs "src/${target}/mcpwm_retention.c")
|
||||
endif()
|
||||
if(CONFIG_SOC_MCPWM_SUPPORT_ETM)
|
||||
list(APPEND srcs "src/mcpwm_etm.c")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(${target} STREQUAL "linux")
|
||||
set(requires "")
|
||||
set(priv_requires "")
|
||||
else()
|
||||
set(requires esp_hal_mcpwm)
|
||||
set(priv_requires esp_pm esp_driver_gpio)
|
||||
endif()
|
||||
set(requires esp_hal_mcpwm)
|
||||
set(priv_requires esp_pm esp_driver_gpio)
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS ${public_include}
|
||||
PRIV_INCLUDE_DIRS "src"
|
||||
REQUIRES "${requires}"
|
||||
PRIV_REQUIRES "${priv_requires}"
|
||||
REQUIRES ${requires}
|
||||
PRIV_REQUIRES ${priv_requires}
|
||||
LDFRAGMENTS "linker.lf"
|
||||
)
|
||||
|
||||
@@ -460,7 +460,7 @@ esp_err_t mcpwm_capture_timer_set_phase_on_sync(mcpwm_cap_timer_handle_t cap_tim
|
||||
}
|
||||
case MCPWM_SYNC_TYPE_SOFT: {
|
||||
mcpwm_soft_sync_src_t *soft_sync = __containerof(sync_source, mcpwm_soft_sync_src_t, base);
|
||||
soft_sync->soft_sync_from = MCPWM_SOFT_SYNC_FROM_CAP;
|
||||
soft_sync->soft_sync_bound_to = MCPWM_SOFT_SYNC_BOUND_TO_CAP;
|
||||
soft_sync->cap_timer = cap_timer;
|
||||
soft_sync->base.group = group;
|
||||
break;
|
||||
|
||||
@@ -238,14 +238,14 @@ struct mcpwm_timer_sync_src_t {
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
MCPWM_SOFT_SYNC_FROM_NONE, // the software sync event generator has not been assigned
|
||||
MCPWM_SOFT_SYNC_FROM_TIMER, // the software sync event is generated by MCPWM timer
|
||||
MCPWM_SOFT_SYNC_FROM_CAP, // the software sync event is generated by MCPWM capture timer
|
||||
} mcpwm_soft_sync_source_t;
|
||||
MCPWM_SOFT_SYNC_BOUND_TO_NONE, // the software sync event generator has not been assigned
|
||||
MCPWM_SOFT_SYNC_BOUND_TO_TIMER, // the software sync event generator is bound to a PWM timer
|
||||
MCPWM_SOFT_SYNC_BOUND_TO_CAP, // the software sync event generator is bound to a capture timer
|
||||
} mcpwm_soft_sync_bound_target_t;
|
||||
|
||||
struct mcpwm_soft_sync_src_t {
|
||||
mcpwm_sync_t base; // base class
|
||||
mcpwm_soft_sync_source_t soft_sync_from; // where the software sync event is generated by
|
||||
mcpwm_soft_sync_bound_target_t soft_sync_bound_to; // which type of timer the soft sync is bound to
|
||||
union {
|
||||
mcpwm_timer_t *timer; // soft sync is generated by which MCPWM timer
|
||||
mcpwm_cap_timer_t *cap_timer; // soft sync is generated by which MCPWM capture timer
|
||||
|
||||
@@ -221,7 +221,7 @@ esp_err_t mcpwm_new_soft_sync_src(const mcpwm_soft_sync_config_t *config, mcpwm_
|
||||
ESP_GOTO_ON_FALSE(soft_sync, ESP_ERR_NO_MEM, err, TAG, "no mem for soft sync");
|
||||
|
||||
// fill in other sync member
|
||||
soft_sync->soft_sync_from = MCPWM_SOFT_SYNC_FROM_NONE;
|
||||
soft_sync->soft_sync_bound_to = MCPWM_SOFT_SYNC_BOUND_TO_NONE;
|
||||
soft_sync->base.type = MCPWM_SYNC_TYPE_SOFT;
|
||||
soft_sync->base.del = mcpwm_del_soft_sync_src;
|
||||
*ret_sync = &soft_sync->base;
|
||||
@@ -255,13 +255,13 @@ esp_err_t mcpwm_soft_sync_activate(mcpwm_sync_handle_t sync_src)
|
||||
mcpwm_group_t *group = sync_src->group;
|
||||
mcpwm_soft_sync_src_t *soft_sync = __containerof(sync_src, mcpwm_soft_sync_src_t, base);
|
||||
|
||||
switch (soft_sync->soft_sync_from) {
|
||||
case MCPWM_SOFT_SYNC_FROM_TIMER: {
|
||||
switch (soft_sync->soft_sync_bound_to) {
|
||||
case MCPWM_SOFT_SYNC_BOUND_TO_TIMER: {
|
||||
mcpwm_timer_t *timer = soft_sync->timer;
|
||||
mcpwm_ll_timer_trigger_soft_sync(group->hal.dev, timer->timer_id);
|
||||
break;
|
||||
}
|
||||
case MCPWM_SOFT_SYNC_FROM_CAP: {
|
||||
case MCPWM_SOFT_SYNC_BOUND_TO_CAP: {
|
||||
mcpwm_ll_capture_trigger_sw_sync(group->hal.dev);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -340,10 +340,10 @@ esp_err_t mcpwm_timer_set_phase_on_sync(mcpwm_timer_handle_t timer, const mcpwm_
|
||||
}
|
||||
case MCPWM_SYNC_TYPE_SOFT: {
|
||||
mcpwm_soft_sync_src_t *soft_sync = __containerof(sync_source, mcpwm_soft_sync_src_t, base);
|
||||
if (soft_sync->soft_sync_from == MCPWM_SOFT_SYNC_FROM_TIMER && soft_sync->timer != timer) {
|
||||
if (soft_sync->soft_sync_bound_to == MCPWM_SOFT_SYNC_BOUND_TO_TIMER && soft_sync->timer != timer) {
|
||||
ESP_RETURN_ON_FALSE(false, ESP_ERR_INVALID_STATE, TAG, "soft sync already used by another timer");
|
||||
}
|
||||
soft_sync->soft_sync_from = MCPWM_SOFT_SYNC_FROM_TIMER;
|
||||
soft_sync->soft_sync_bound_to = MCPWM_SOFT_SYNC_BOUND_TO_TIMER;
|
||||
soft_sync->timer = timer;
|
||||
soft_sync->base.group = group;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user