mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
mcpwm: don't use keyword operator
Closes https://github.com/espressif/esp-idf/issues/9510
This commit is contained in:
parent
104b9c3fb1
commit
2c5a866ea3
@ -82,14 +82,14 @@ typedef struct {
|
||||
/**
|
||||
* @brief Set brake method for MCPWM operator
|
||||
*
|
||||
* @param[in] operator MCPWM operator, allocated by `mcpwm_new_operator()`
|
||||
* @param[in] oper MCPWM operator, allocated by `mcpwm_new_operator()`
|
||||
* @param[in] config MCPWM brake configuration
|
||||
* @return
|
||||
* - ESP_OK: Set trip for operator successfully
|
||||
* - ESP_ERR_INVALID_ARG: Set trip for operator failed because of invalid argument
|
||||
* - ESP_FAIL: Set trip for operator failed because of other error
|
||||
*/
|
||||
esp_err_t mcpwm_operator_set_brake_on_fault(mcpwm_oper_handle_t operator, const mcpwm_brake_config_t *config);
|
||||
esp_err_t mcpwm_operator_set_brake_on_fault(mcpwm_oper_handle_t oper, const mcpwm_brake_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Try to make the operator recover from fault
|
||||
@ -97,7 +97,7 @@ esp_err_t mcpwm_operator_set_brake_on_fault(mcpwm_oper_handle_t operator, const
|
||||
* @note To recover from fault or escape from trip, you make sure the fault signal has dissappeared already.
|
||||
* Otherwise the recovery can't succeed.
|
||||
*
|
||||
* @param[in] operator MCPWM operator, allocated by `mcpwm_new_operator()`
|
||||
* @param[in] oper MCPWM operator, allocated by `mcpwm_new_operator()`
|
||||
* @param[in] fault MCPWM fault handle
|
||||
* @return
|
||||
* - ESP_OK: Recover from fault successfully
|
||||
@ -105,7 +105,7 @@ esp_err_t mcpwm_operator_set_brake_on_fault(mcpwm_oper_handle_t operator, const
|
||||
* - ESP_ERR_INVALID_STATE: Recover from fault failed because the fault source is still active
|
||||
* - ESP_FAIL: Recover from fault failed because of other error
|
||||
*/
|
||||
esp_err_t mcpwm_operator_recover_from_fault(mcpwm_oper_handle_t operator, mcpwm_fault_handle_t fault);
|
||||
esp_err_t mcpwm_operator_recover_from_fault(mcpwm_oper_handle_t oper, mcpwm_fault_handle_t fault);
|
||||
|
||||
/**
|
||||
* @brief Group of supported MCPWM operator event callbacks
|
||||
|
@ -81,12 +81,12 @@ typedef struct {
|
||||
/**
|
||||
* @brief MCPWM operator brake event callback function
|
||||
*
|
||||
* @param[in] operator MCPWM operator handle
|
||||
* @param[in] oper MCPWM operator handle
|
||||
* @param[in] edata MCPWM brake event data, fed by driver
|
||||
* @param[in] user_ctx User data, set in `mcpwm_operator_register_event_callbacks()`
|
||||
* @return Whether a high priority task has been waken up by this function
|
||||
*/
|
||||
typedef bool (*mcpwm_brake_event_cb_t)(mcpwm_oper_handle_t operator, const mcpwm_brake_event_data_t *edata, void *user_ctx);
|
||||
typedef bool (*mcpwm_brake_event_cb_t)(mcpwm_oper_handle_t oper, const mcpwm_brake_event_data_t *edata, void *user_ctx);
|
||||
|
||||
/**
|
||||
* @brief MCPWM fault event data
|
||||
|
@ -44,13 +44,13 @@ static esp_err_t mcpwm_comparator_register_to_operator(mcpwm_cmpr_t *cmpr, mcpwm
|
||||
ESP_RETURN_ON_FALSE(cmpr_id >= 0, ESP_ERR_NOT_FOUND, TAG, "no free comparator in operator (%d,%d)", oper->group->group_id, oper->oper_id);
|
||||
|
||||
cmpr->cmpr_id = cmpr_id;
|
||||
cmpr->operator = oper;
|
||||
cmpr->oper = oper;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void mcpwm_comparator_unregister_from_operator(mcpwm_cmpr_t *cmpr)
|
||||
{
|
||||
mcpwm_oper_t *oper = cmpr->operator;
|
||||
mcpwm_oper_t *oper = cmpr->oper;
|
||||
int cmpr_id = cmpr->cmpr_id;
|
||||
|
||||
portENTER_CRITICAL(&oper->spinlock);
|
||||
@ -63,7 +63,7 @@ static esp_err_t mcpwm_comparator_destory(mcpwm_cmpr_t *cmpr)
|
||||
if (cmpr->intr) {
|
||||
ESP_RETURN_ON_ERROR(esp_intr_free(cmpr->intr), TAG, "uninstall interrupt service failed");
|
||||
}
|
||||
if (cmpr->operator) {
|
||||
if (cmpr->oper) {
|
||||
mcpwm_comparator_unregister_from_operator(cmpr);
|
||||
}
|
||||
free(cmpr);
|
||||
@ -105,10 +105,10 @@ err:
|
||||
esp_err_t mcpwm_del_comparator(mcpwm_cmpr_handle_t cmpr)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(cmpr, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_oper_t *operator= cmpr->operator;
|
||||
mcpwm_group_t *group = operator->group;
|
||||
mcpwm_oper_t *oper = cmpr->oper;
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_hal_context_t *hal = &group->hal;
|
||||
int oper_id = operator->oper_id;
|
||||
int oper_id = oper->oper_id;
|
||||
int cmpr_id = cmpr->cmpr_id;
|
||||
|
||||
portENTER_CRITICAL(&group->spinlock);
|
||||
@ -125,7 +125,7 @@ esp_err_t mcpwm_del_comparator(mcpwm_cmpr_handle_t cmpr)
|
||||
esp_err_t mcpwm_comparator_set_compare_value(mcpwm_cmpr_handle_t cmpr, uint32_t cmp_ticks)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(cmpr, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_oper_t *oper = cmpr->operator;
|
||||
mcpwm_oper_t *oper = cmpr->oper;
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_timer_t *timer = oper->timer;
|
||||
ESP_RETURN_ON_FALSE(timer, ESP_ERR_INVALID_STATE, TAG, "timer and operator are not connected");
|
||||
@ -142,7 +142,7 @@ esp_err_t mcpwm_comparator_set_compare_value(mcpwm_cmpr_handle_t cmpr, uint32_t
|
||||
esp_err_t mcpwm_comparator_register_event_callbacks(mcpwm_cmpr_handle_t cmpr, const mcpwm_comparator_event_callbacks_t *cbs, void *user_data)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(cmpr && cbs, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_oper_t *oper = cmpr->operator;
|
||||
mcpwm_oper_t *oper = cmpr->oper;
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_hal_context_t *hal = &group->hal;
|
||||
int group_id = group->group_id;
|
||||
@ -180,7 +180,7 @@ esp_err_t mcpwm_comparator_register_event_callbacks(mcpwm_cmpr_handle_t cmpr, co
|
||||
static void IRAM_ATTR mcpwm_comparator_default_isr(void *args)
|
||||
{
|
||||
mcpwm_cmpr_t *cmpr = (mcpwm_cmpr_t *)args;
|
||||
mcpwm_oper_t *oper = cmpr->operator;
|
||||
mcpwm_oper_t *oper = cmpr->oper;
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_hal_context_t *hal = &group->hal;
|
||||
int oper_id = oper->oper_id;
|
||||
|
@ -196,18 +196,18 @@ esp_err_t mcpwm_soft_fault_activate(mcpwm_fault_handle_t fault)
|
||||
ESP_RETURN_ON_FALSE(fault->type == MCPWM_FAULT_TYPE_SOFT, ESP_ERR_INVALID_ARG, TAG, "not a valid soft fault");
|
||||
mcpwm_group_t *group = fault->group;
|
||||
mcpwm_soft_fault_t *soft_fault = __containerof(fault, mcpwm_soft_fault_t, base);
|
||||
mcpwm_oper_t *operator = soft_fault->operator;
|
||||
ESP_RETURN_ON_FALSE(operator, ESP_ERR_INVALID_STATE, TAG, "no operator is assigned to the fault");
|
||||
mcpwm_oper_t *oper = soft_fault->oper;
|
||||
ESP_RETURN_ON_FALSE(oper, ESP_ERR_INVALID_STATE, TAG, "no operator is assigned to the fault");
|
||||
|
||||
switch (operator->brake_mode_on_soft_fault) {
|
||||
switch (oper->brake_mode_on_soft_fault) {
|
||||
case MCPWM_OPER_BRAKE_MODE_CBC:
|
||||
mcpwm_ll_brake_trigger_soft_cbc(group->hal.dev, operator->oper_id);
|
||||
mcpwm_ll_brake_trigger_soft_cbc(group->hal.dev, oper->oper_id);
|
||||
break;
|
||||
case MCPWM_OPER_BRAKE_MODE_OST:
|
||||
mcpwm_ll_brake_trigger_soft_ost(group->hal.dev, operator->oper_id);
|
||||
mcpwm_ll_brake_trigger_soft_ost(group->hal.dev, oper->oper_id);
|
||||
break;
|
||||
default:
|
||||
ESP_RETURN_ON_FALSE(false, ESP_ERR_INVALID_STATE, TAG, "unknown brake mode:%d", operator->brake_mode_on_soft_fault);
|
||||
ESP_RETURN_ON_FALSE(false, ESP_ERR_INVALID_STATE, TAG, "unknown brake mode:%d", oper->brake_mode_on_soft_fault);
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
|
@ -42,13 +42,13 @@ static esp_err_t mcpwm_generator_register_to_operator(mcpwm_gen_t *gen, mcpwm_op
|
||||
ESP_RETURN_ON_FALSE(gen_id >= 0, ESP_ERR_NOT_FOUND, TAG, "no free generator in operator (%d,%d)", oper->group->group_id, oper->oper_id);
|
||||
|
||||
gen->gen_id = gen_id;
|
||||
gen->operator = oper;
|
||||
gen->oper = oper;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void mcpwm_generator_unregister_from_operator(mcpwm_gen_t *gen)
|
||||
{
|
||||
mcpwm_oper_t *oper = gen->operator;
|
||||
mcpwm_oper_t *oper = gen->oper;
|
||||
int gen_id = gen->gen_id;
|
||||
|
||||
portENTER_CRITICAL(&oper->spinlock);
|
||||
@ -58,7 +58,7 @@ static void mcpwm_generator_unregister_from_operator(mcpwm_gen_t *gen)
|
||||
|
||||
static esp_err_t mcpwm_generator_destory(mcpwm_gen_t *gen)
|
||||
{
|
||||
if (gen->operator) {
|
||||
if (gen->oper) {
|
||||
mcpwm_generator_unregister_from_operator(gen);
|
||||
}
|
||||
free(gen);
|
||||
@ -113,7 +113,7 @@ err:
|
||||
esp_err_t mcpwm_del_generator(mcpwm_gen_handle_t gen)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(gen, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_oper_t *oper = gen->operator;
|
||||
mcpwm_oper_t *oper = gen->oper;
|
||||
mcpwm_group_t *group = oper->group;
|
||||
|
||||
ESP_LOGD(TAG, "del generator (%d,%d,%d)", group->group_id, oper->oper_id, gen->gen_id);
|
||||
@ -125,7 +125,7 @@ esp_err_t mcpwm_del_generator(mcpwm_gen_handle_t gen)
|
||||
esp_err_t mcpwm_generator_set_force_level(mcpwm_gen_handle_t gen, int level, bool hold_on)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(gen && level <= 1, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_oper_t *oper = gen->operator;
|
||||
mcpwm_oper_t *oper = gen->oper;
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_hal_context_t *hal = &group->hal;
|
||||
int oper_id = oper->oper_id;
|
||||
@ -151,9 +151,9 @@ esp_err_t mcpwm_generator_set_force_level(mcpwm_gen_handle_t gen, int level, boo
|
||||
esp_err_t mcpwm_generator_set_actions_on_timer_event(mcpwm_gen_handle_t gen, mcpwm_gen_timer_event_action_t ev_act, ...)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(gen, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_oper_t *operator= gen->operator;
|
||||
mcpwm_group_t *group = operator->group;
|
||||
mcpwm_timer_t *timer = operator->timer;
|
||||
mcpwm_oper_t *oper = gen->oper;
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_timer_t *timer = oper->timer;
|
||||
ESP_RETURN_ON_FALSE(timer, ESP_ERR_INVALID_STATE, TAG, "no timer is connected to the operator");
|
||||
mcpwm_gen_timer_event_action_t ev_act_itor = ev_act;
|
||||
bool invalid_utep = false;
|
||||
@ -171,7 +171,7 @@ esp_err_t mcpwm_generator_set_actions_on_timer_event(mcpwm_gen_handle_t gen, mcp
|
||||
va_end(it);
|
||||
ESP_RETURN_ON_FALSE(false, ESP_ERR_INVALID_ARG, TAG, "UTEP and DTEZ can't be reached under MCPWM_TIMER_COUNT_MODE_UP_DOWN mode");
|
||||
}
|
||||
mcpwm_ll_generator_set_action_on_timer_event(group->hal.dev, operator->oper_id, gen->gen_id,
|
||||
mcpwm_ll_generator_set_action_on_timer_event(group->hal.dev, oper->oper_id, gen->gen_id,
|
||||
ev_act_itor.direction, ev_act_itor.event, ev_act_itor.action);
|
||||
ev_act_itor = va_arg(it, mcpwm_gen_timer_event_action_t);
|
||||
}
|
||||
@ -182,13 +182,13 @@ esp_err_t mcpwm_generator_set_actions_on_timer_event(mcpwm_gen_handle_t gen, mcp
|
||||
esp_err_t mcpwm_generator_set_actions_on_compare_event(mcpwm_gen_handle_t gen, mcpwm_gen_compare_event_action_t ev_act, ...)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(gen, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_oper_t *operator= gen->operator;
|
||||
mcpwm_group_t *group = operator->group;
|
||||
mcpwm_oper_t *oper = gen->oper;
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_gen_compare_event_action_t ev_act_itor = ev_act;
|
||||
va_list it;
|
||||
va_start(it, ev_act);
|
||||
while (ev_act_itor.comparator) {
|
||||
mcpwm_ll_generator_set_action_on_compare_event(group->hal.dev, operator->oper_id, gen->gen_id,
|
||||
mcpwm_ll_generator_set_action_on_compare_event(group->hal.dev, oper->oper_id, gen->gen_id,
|
||||
ev_act_itor.direction, ev_act_itor.comparator->cmpr_id, ev_act_itor.action);
|
||||
ev_act_itor = va_arg(it, mcpwm_gen_compare_event_action_t);
|
||||
}
|
||||
@ -199,13 +199,13 @@ esp_err_t mcpwm_generator_set_actions_on_compare_event(mcpwm_gen_handle_t gen, m
|
||||
esp_err_t mcpwm_generator_set_actions_on_brake_event(mcpwm_gen_handle_t gen, mcpwm_gen_brake_event_action_t ev_act, ...)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(gen, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_oper_t *operator= gen->operator;
|
||||
mcpwm_group_t *group = operator->group;
|
||||
mcpwm_oper_t *oper = gen->oper;
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_gen_brake_event_action_t ev_act_itor = ev_act;
|
||||
va_list it;
|
||||
va_start(it, ev_act);
|
||||
while (ev_act_itor.brake_mode != MCPWM_OPER_BRAKE_MODE_INVALID) {
|
||||
mcpwm_ll_generator_set_action_on_brake_event(group->hal.dev, operator->oper_id, gen->gen_id,
|
||||
mcpwm_ll_generator_set_action_on_brake_event(group->hal.dev, oper->oper_id, gen->gen_id,
|
||||
ev_act_itor.direction, ev_act_itor.brake_mode, ev_act_itor.action);
|
||||
ev_act_itor = va_arg(it, mcpwm_gen_brake_event_action_t);
|
||||
}
|
||||
@ -216,13 +216,13 @@ esp_err_t mcpwm_generator_set_actions_on_brake_event(mcpwm_gen_handle_t gen, mcp
|
||||
esp_err_t mcpwm_generator_set_dead_time(mcpwm_gen_handle_t in_generator, mcpwm_gen_handle_t out_generator, const mcpwm_dead_time_config_t *config)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(in_generator && out_generator && config, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
ESP_RETURN_ON_FALSE(in_generator->operator == out_generator->operator, ESP_ERR_INVALID_ARG, TAG, "in/out generator are not derived from the same operator");
|
||||
ESP_RETURN_ON_FALSE(in_generator->oper == out_generator->oper, ESP_ERR_INVALID_ARG, TAG, "in/out generator are not derived from the same operator");
|
||||
ESP_RETURN_ON_FALSE(config->negedge_delay_ticks < MCPWM_LL_MAX_DEAD_DELAY && config->posedge_delay_ticks < MCPWM_LL_MAX_DEAD_DELAY,
|
||||
ESP_ERR_INVALID_ARG, TAG, "delay time out of range");
|
||||
mcpwm_oper_t *operator= in_generator->operator;
|
||||
mcpwm_group_t *group = operator->group;
|
||||
mcpwm_oper_t *oper = in_generator->oper;
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_hal_context_t *hal = &group->hal;
|
||||
int oper_id = operator->oper_id;
|
||||
int oper_id = oper->oper_id;
|
||||
|
||||
// Note: to better understand the following code, you should read the deadtime module topology diagram in the TRM
|
||||
// check if we want to bypass the deadtime module
|
||||
|
@ -86,19 +86,19 @@ esp_err_t mcpwm_new_operator(const mcpwm_operator_config_t *config, mcpwm_oper_h
|
||||
esp_log_level_set(TAG, ESP_LOG_DEBUG);
|
||||
#endif
|
||||
esp_err_t ret = ESP_OK;
|
||||
mcpwm_oper_t *operator= NULL;
|
||||
mcpwm_oper_t *oper = NULL;
|
||||
ESP_GOTO_ON_FALSE(config && ret_oper, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
|
||||
ESP_GOTO_ON_FALSE(config->group_id < SOC_MCPWM_GROUPS && config->group_id >= 0, ESP_ERR_INVALID_ARG,
|
||||
err, TAG, "invalid group ID:%d", config->group_id);
|
||||
|
||||
operator= heap_caps_calloc(1, sizeof(mcpwm_oper_t), MCPWM_MEM_ALLOC_CAPS);
|
||||
ESP_GOTO_ON_FALSE(operator, ESP_ERR_NO_MEM, err, TAG, "no mem for operator");
|
||||
oper = heap_caps_calloc(1, sizeof(mcpwm_oper_t), MCPWM_MEM_ALLOC_CAPS);
|
||||
ESP_GOTO_ON_FALSE(oper, ESP_ERR_NO_MEM, err, TAG, "no mem for operator");
|
||||
|
||||
ESP_GOTO_ON_ERROR(mcpwm_operator_register_to_group(operator, config->group_id), err, TAG, "register operator failed");
|
||||
mcpwm_group_t *group = operator->group;
|
||||
ESP_GOTO_ON_ERROR(mcpwm_operator_register_to_group(oper, config->group_id), err, TAG, "register operator failed");
|
||||
mcpwm_group_t *group = oper->group;
|
||||
int group_id = group->group_id;
|
||||
mcpwm_hal_context_t *hal = &group->hal;
|
||||
int oper_id = operator->oper_id;
|
||||
int oper_id = oper->oper_id;
|
||||
|
||||
// reset MCPWM operator
|
||||
mcpwm_hal_operator_reset(hal, oper_id);
|
||||
@ -113,17 +113,17 @@ esp_err_t mcpwm_new_operator(const mcpwm_operator_config_t *config, mcpwm_oper_h
|
||||
mcpwm_ll_deadtime_enable_update_delay_on_sync(hal->dev, oper_id, config->flags.update_dead_time_on_sync);
|
||||
// set the clock source for dead time submodule, the resolution is the same to the MCPWM group
|
||||
mcpwm_ll_operator_set_deadtime_clock_src(hal->dev, oper_id, MCPWM_LL_DEADTIME_CLK_SRC_GROUP);
|
||||
operator->deadtime_resolution_hz = group->resolution_hz;
|
||||
oper->deadtime_resolution_hz = group->resolution_hz;
|
||||
|
||||
// fill in other operator members
|
||||
operator->spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED;
|
||||
*ret_oper = operator;
|
||||
ESP_LOGD(TAG, "new operator (%d,%d) at %p", group_id, oper_id, operator);
|
||||
oper->spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED;
|
||||
*ret_oper = oper;
|
||||
ESP_LOGD(TAG, "new operator (%d,%d) at %p", group_id, oper_id, oper);
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (operator) {
|
||||
mcpwm_operator_destory(operator);
|
||||
if (oper) {
|
||||
mcpwm_operator_destory(oper);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -253,13 +253,13 @@ esp_err_t mcpwm_operator_register_event_callbacks(mcpwm_oper_handle_t oper, cons
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t mcpwm_operator_set_brake_on_fault(mcpwm_oper_handle_t operator, const mcpwm_brake_config_t *config)
|
||||
esp_err_t mcpwm_operator_set_brake_on_fault(mcpwm_oper_handle_t oper, const mcpwm_brake_config_t *config)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(operator && config, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_group_t *group = operator->group;
|
||||
ESP_RETURN_ON_FALSE(oper && config, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_fault_t *fault = config->fault;
|
||||
|
||||
int oper_id = operator->oper_id;
|
||||
int oper_id = oper->oper_id;
|
||||
mcpwm_ll_brake_enable_cbc_refresh_on_tez(group->hal.dev, oper_id, config->flags.cbc_recover_on_tez);
|
||||
mcpwm_ll_fault_enable_cbc_refresh_on_tep(group->hal.dev, oper_id, config->flags.cbc_recover_on_tep);
|
||||
|
||||
@ -269,17 +269,17 @@ esp_err_t mcpwm_operator_set_brake_on_fault(mcpwm_oper_handle_t operator, const
|
||||
mcpwm_gpio_fault_t *gpio_fault = __containerof(fault, mcpwm_gpio_fault_t, base);
|
||||
mcpwm_ll_brake_enable_cbc_mode(group->hal.dev, oper_id, gpio_fault->fault_id, config->brake_mode == MCPWM_OPER_BRAKE_MODE_CBC);
|
||||
mcpwm_ll_brake_enable_oneshot_mode(group->hal.dev, oper_id, gpio_fault->fault_id, config->brake_mode == MCPWM_OPER_BRAKE_MODE_OST);
|
||||
operator->brake_mode_on_gpio_fault[gpio_fault->fault_id] = config->brake_mode;
|
||||
oper->brake_mode_on_gpio_fault[gpio_fault->fault_id] = config->brake_mode;
|
||||
break;
|
||||
}
|
||||
case MCPWM_FAULT_TYPE_SOFT: {
|
||||
mcpwm_soft_fault_t *soft_fault = __containerof(fault, mcpwm_soft_fault_t, base);
|
||||
ESP_RETURN_ON_FALSE(!soft_fault->operator || soft_fault->operator == operator, ESP_ERR_INVALID_STATE, TAG, "soft fault already used by another operator");
|
||||
soft_fault->operator = operator;
|
||||
soft_fault->base.group = operator->group;
|
||||
ESP_RETURN_ON_FALSE(!soft_fault->oper || soft_fault->oper == oper, ESP_ERR_INVALID_STATE, TAG, "soft fault already used by another operator");
|
||||
soft_fault->oper = oper;
|
||||
soft_fault->base.group = oper->group;
|
||||
mcpwm_ll_brake_enable_soft_cbc(group->hal.dev, oper_id, config->brake_mode == MCPWM_OPER_BRAKE_MODE_CBC);
|
||||
mcpwm_ll_brake_enable_soft_ost(group->hal.dev, oper_id, config->brake_mode == MCPWM_OPER_BRAKE_MODE_OST);
|
||||
operator->brake_mode_on_soft_fault = config->brake_mode;
|
||||
oper->brake_mode_on_soft_fault = config->brake_mode;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -289,21 +289,21 @@ esp_err_t mcpwm_operator_set_brake_on_fault(mcpwm_oper_handle_t operator, const
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t mcpwm_operator_recover_from_fault(mcpwm_oper_handle_t operator, mcpwm_fault_handle_t fault)
|
||||
esp_err_t mcpwm_operator_recover_from_fault(mcpwm_oper_handle_t oper, mcpwm_fault_handle_t fault)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(operator && fault, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_group_t *group = operator->group;
|
||||
ESP_RETURN_ON_FALSE(oper && fault, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
mcpwm_group_t *group = oper->group;
|
||||
mcpwm_operator_brake_mode_t brake_mode;
|
||||
|
||||
// check the brake mode on the fault event
|
||||
switch (fault->type) {
|
||||
case MCPWM_FAULT_TYPE_GPIO: {
|
||||
mcpwm_gpio_fault_t *gpio_fault = __containerof(fault, mcpwm_gpio_fault_t, base);
|
||||
brake_mode = operator->brake_mode_on_gpio_fault[gpio_fault->fault_id];
|
||||
brake_mode = oper->brake_mode_on_gpio_fault[gpio_fault->fault_id];
|
||||
break;
|
||||
}
|
||||
case MCPWM_FAULT_TYPE_SOFT:
|
||||
brake_mode = operator->brake_mode_on_soft_fault;
|
||||
brake_mode = oper->brake_mode_on_soft_fault;
|
||||
break;
|
||||
default:
|
||||
ESP_RETURN_ON_FALSE(false, ESP_ERR_INVALID_ARG, TAG, "unknown fault type:%d", fault->type);
|
||||
@ -312,13 +312,13 @@ esp_err_t mcpwm_operator_recover_from_fault(mcpwm_oper_handle_t operator, mcpwm_
|
||||
|
||||
bool fault_signal_is_active = false;
|
||||
if (brake_mode == MCPWM_OPER_BRAKE_MODE_OST) {
|
||||
fault_signal_is_active = mcpwm_ll_ost_brake_active(group->hal.dev, operator->oper_id);
|
||||
fault_signal_is_active = mcpwm_ll_ost_brake_active(group->hal.dev, oper->oper_id);
|
||||
// OST brake can't recover automatically, need to manually recovery the operator
|
||||
if (!fault_signal_is_active) {
|
||||
mcpwm_ll_brake_clear_ost(group->hal.dev, operator->oper_id);
|
||||
mcpwm_ll_brake_clear_ost(group->hal.dev, oper->oper_id);
|
||||
}
|
||||
} else {
|
||||
fault_signal_is_active = mcpwm_ll_cbc_brake_active(group->hal.dev, operator->oper_id);
|
||||
fault_signal_is_active = mcpwm_ll_cbc_brake_active(group->hal.dev, oper->oper_id);
|
||||
// CBC brake can recover automatically after deactivating the fault signal
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ struct mcpwm_oper_t {
|
||||
|
||||
struct mcpwm_cmpr_t {
|
||||
int cmpr_id; // comparator ID, index from 0
|
||||
mcpwm_oper_t *operator; // which operator that the comparator resides in
|
||||
mcpwm_oper_t *oper; // which operator that the comparator resides in
|
||||
intr_handle_t intr; // interrupt handle
|
||||
portMUX_TYPE spinlock; // spin lock
|
||||
uint32_t compare_ticks; // compare value of this comparator
|
||||
@ -119,7 +119,7 @@ struct mcpwm_cmpr_t {
|
||||
|
||||
struct mcpwm_gen_t {
|
||||
int gen_id; // generator ID, index from 0
|
||||
mcpwm_oper_t *operator; // which operator that the generator resides in
|
||||
mcpwm_oper_t *oper; // which operator that the generator resides in
|
||||
int gen_gpio_num; // GPIO number used by the generator
|
||||
portMUX_TYPE spinlock; // spin lock
|
||||
};
|
||||
@ -138,7 +138,7 @@ struct mcpwm_fault_t {
|
||||
struct mcpwm_gpio_fault_t {
|
||||
mcpwm_fault_t base; // base class
|
||||
int fault_id; // fault detector ID, index from 0
|
||||
int gpio_num; // GPIO number of fault detector
|
||||
int gpio_num; // GPIO number of fault detector
|
||||
intr_handle_t intr; // interrupt handle
|
||||
mcpwm_fault_event_cb_t on_fault_enter; // ISR callback function that would be invoked when fault signal got triggered
|
||||
mcpwm_fault_event_cb_t on_fault_exit; // ISR callback function that would be invoked when fault signal got clear
|
||||
@ -147,7 +147,7 @@ struct mcpwm_gpio_fault_t {
|
||||
|
||||
struct mcpwm_soft_fault_t {
|
||||
mcpwm_fault_t base; // base class
|
||||
mcpwm_oper_t *operator; // the operator where the soft fault allocated from
|
||||
mcpwm_oper_t *oper; // the operator where the soft fault allocated from
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
@ -15,7 +15,7 @@
|
||||
TEST_CASE("mcpwm_comparator_install_uninstall", "[mcpwm]")
|
||||
{
|
||||
mcpwm_timer_handle_t timer;
|
||||
mcpwm_oper_handle_t operator;
|
||||
mcpwm_oper_handle_t oper;
|
||||
mcpwm_cmpr_handle_t comparators[SOC_MCPWM_COMPARATORS_PER_OPERATOR];
|
||||
|
||||
mcpwm_timer_config_t timer_config = {
|
||||
@ -30,25 +30,25 @@ TEST_CASE("mcpwm_comparator_install_uninstall", "[mcpwm]")
|
||||
};
|
||||
printf("install timer and operator");
|
||||
TEST_ESP_OK(mcpwm_new_timer(&timer_config, &timer));
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &operator));
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper));
|
||||
|
||||
printf("install comparator\r\n");
|
||||
mcpwm_comparator_config_t comparator_config = {};
|
||||
for (int i = 0; i < SOC_MCPWM_COMPARATORS_PER_OPERATOR; i++) {
|
||||
TEST_ESP_OK(mcpwm_new_comparator(operator, &comparator_config, &comparators[i]));
|
||||
TEST_ESP_OK(mcpwm_new_comparator(oper, &comparator_config, &comparators[i]));
|
||||
}
|
||||
TEST_ESP_ERR(ESP_ERR_NOT_FOUND, mcpwm_new_comparator(operator, &comparator_config, &comparators[0]));
|
||||
TEST_ESP_ERR(ESP_ERR_NOT_FOUND, mcpwm_new_comparator(oper, &comparator_config, &comparators[0]));
|
||||
|
||||
printf("connect MCPWM timer and operators\r\n");
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(operator, timer));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(oper, timer));
|
||||
|
||||
printf("uninstall timer, operator and comparators\r\n");
|
||||
// can't delete operator if the comparators are still in working
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, mcpwm_del_operator(operator));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, mcpwm_del_operator(oper));
|
||||
for (int i = 0; i < SOC_MCPWM_COMPARATORS_PER_OPERATOR; i++) {
|
||||
TEST_ESP_OK(mcpwm_del_comparator(comparators[i]));
|
||||
}
|
||||
TEST_ESP_OK(mcpwm_del_operator(operator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper));
|
||||
TEST_ESP_OK(mcpwm_del_timer(timer));
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ static bool test_compare_on_reach(mcpwm_cmpr_handle_t cmpr, const mcpwm_compare_
|
||||
TEST_CASE("mcpwm_comparator_event_callback", "[mcpwm]")
|
||||
{
|
||||
mcpwm_timer_handle_t timer;
|
||||
mcpwm_oper_handle_t operator;
|
||||
mcpwm_oper_handle_t oper;
|
||||
mcpwm_cmpr_handle_t comparator;
|
||||
|
||||
mcpwm_timer_config_t timer_config = {
|
||||
@ -78,13 +78,13 @@ TEST_CASE("mcpwm_comparator_event_callback", "[mcpwm]")
|
||||
mcpwm_comparator_config_t comparator_config = {};
|
||||
printf("install timer, operator and comparator\r\n");
|
||||
TEST_ESP_OK(mcpwm_new_timer(&timer_config, &timer));
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &operator));
|
||||
TEST_ESP_OK(mcpwm_new_comparator(operator, &comparator_config, &comparator));
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper));
|
||||
TEST_ESP_OK(mcpwm_new_comparator(oper, &comparator_config, &comparator));
|
||||
|
||||
// set compare value before connecting timer and operator will fail
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, mcpwm_comparator_set_compare_value(comparator, 5000));
|
||||
printf("connect MCPWM timer and operators\r\n");
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(operator, timer));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(oper, timer));
|
||||
// compare ticks can't exceed the timer's period ticks
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, mcpwm_comparator_set_compare_value(comparator, 20 * 1000));
|
||||
TEST_ESP_OK(mcpwm_comparator_set_compare_value(comparator, 5 * 1000));
|
||||
@ -109,6 +109,6 @@ TEST_CASE("mcpwm_comparator_event_callback", "[mcpwm]")
|
||||
printf("uninstall timer, operator and comparator\r\n");
|
||||
TEST_ESP_OK(mcpwm_timer_disable(timer));
|
||||
TEST_ESP_OK(mcpwm_del_comparator(comparator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(operator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper));
|
||||
TEST_ESP_OK(mcpwm_del_timer(timer));
|
||||
}
|
||||
|
@ -45,11 +45,11 @@ TEST_CASE("mcpwm_generator_force_level_hold_on", "[mcpwm]")
|
||||
{
|
||||
// The operator can even work without the timer
|
||||
printf("create operator and generator\r\n");
|
||||
mcpwm_oper_handle_t operator = NULL;
|
||||
mcpwm_oper_handle_t oper = NULL;
|
||||
mcpwm_operator_config_t operator_config = {
|
||||
.group_id = 0,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &operator));
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper));
|
||||
|
||||
mcpwm_gen_handle_t generator = NULL;
|
||||
const int gen_gpio = 0;
|
||||
@ -57,7 +57,7 @@ TEST_CASE("mcpwm_generator_force_level_hold_on", "[mcpwm]")
|
||||
.gen_gpio_num = gen_gpio,
|
||||
.flags.io_loop_back = true, // loop back for test
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &generator));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &generator));
|
||||
|
||||
printf("add force level to the generator, hold on");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
@ -74,7 +74,7 @@ TEST_CASE("mcpwm_generator_force_level_hold_on", "[mcpwm]")
|
||||
|
||||
printf("delete generator and operator\r\n");
|
||||
TEST_ESP_OK(mcpwm_del_generator(generator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(operator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper));
|
||||
}
|
||||
|
||||
TEST_CASE("mcpwm_generator_force_level_recovery", "[mcpwm]")
|
||||
@ -92,13 +92,13 @@ TEST_CASE("mcpwm_generator_force_level_recovery", "[mcpwm]")
|
||||
TEST_ESP_OK(mcpwm_timer_enable(timer));
|
||||
|
||||
printf("create operator\r\n");
|
||||
mcpwm_oper_handle_t operator = NULL;
|
||||
mcpwm_oper_handle_t oper = NULL;
|
||||
mcpwm_operator_config_t operator_config = {
|
||||
.group_id = 0,
|
||||
.flags.update_gen_action_on_tez = true,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &operator));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(operator, timer));
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(oper, timer));
|
||||
|
||||
printf("create generator\r\n");
|
||||
mcpwm_gen_handle_t generator = NULL;
|
||||
@ -107,7 +107,7 @@ TEST_CASE("mcpwm_generator_force_level_recovery", "[mcpwm]")
|
||||
.gen_gpio_num = gen_gpio,
|
||||
.flags.io_loop_back = true, // loop back for test
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &generator));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &generator));
|
||||
|
||||
printf("add force level to the generator, and recovery by events");
|
||||
TEST_ESP_OK(mcpwm_generator_set_force_level(generator, 0, false));
|
||||
@ -142,7 +142,7 @@ TEST_CASE("mcpwm_generator_force_level_recovery", "[mcpwm]")
|
||||
printf("delete generator, operator and timer\r\n");
|
||||
TEST_ESP_OK(mcpwm_timer_disable(timer));
|
||||
TEST_ESP_OK(mcpwm_del_generator(generator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(operator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper));
|
||||
TEST_ESP_OK(mcpwm_del_timer(timer));
|
||||
}
|
||||
|
||||
@ -227,9 +227,9 @@ static void mcpwm_gen_action_test_template(uint32_t timer_resolution, uint32_t p
|
||||
mcpwm_operator_config_t operator_config = {
|
||||
.group_id = 0,
|
||||
};
|
||||
mcpwm_oper_handle_t operator = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &operator));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(operator, timer));
|
||||
mcpwm_oper_handle_t oper = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(oper, timer));
|
||||
|
||||
TEST_ESP_OK(mcpwm_timer_enable(timer));
|
||||
|
||||
@ -238,8 +238,8 @@ static void mcpwm_gen_action_test_template(uint32_t timer_resolution, uint32_t p
|
||||
mcpwm_comparator_config_t comparator_config = {
|
||||
.flags.update_cmp_on_tez = true,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_new_comparator(operator, &comparator_config, &comparator_a));
|
||||
TEST_ESP_OK(mcpwm_new_comparator(operator, &comparator_config, &comparator_b));
|
||||
TEST_ESP_OK(mcpwm_new_comparator(oper, &comparator_config, &comparator_a));
|
||||
TEST_ESP_OK(mcpwm_new_comparator(oper, &comparator_config, &comparator_b));
|
||||
TEST_ESP_OK(mcpwm_comparator_set_compare_value(comparator_a, cmpa));
|
||||
TEST_ESP_OK(mcpwm_comparator_set_compare_value(comparator_b, cmpb));
|
||||
|
||||
@ -248,9 +248,9 @@ static void mcpwm_gen_action_test_template(uint32_t timer_resolution, uint32_t p
|
||||
mcpwm_generator_config_t generator_config = {
|
||||
.gen_gpio_num = gpioa,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &generator_a));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &generator_a));
|
||||
generator_config.gen_gpio_num = gpiob;
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &generator_b));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &generator_b));
|
||||
|
||||
set_generator_actions(generator_a, generator_b, comparator_a, comparator_b);
|
||||
|
||||
@ -264,7 +264,7 @@ static void mcpwm_gen_action_test_template(uint32_t timer_resolution, uint32_t p
|
||||
TEST_ESP_OK(mcpwm_del_generator(generator_b));
|
||||
TEST_ESP_OK(mcpwm_del_comparator(comparator_a));
|
||||
TEST_ESP_OK(mcpwm_del_comparator(comparator_b));
|
||||
TEST_ESP_OK(mcpwm_del_operator(operator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper));
|
||||
TEST_ESP_OK(mcpwm_del_timer(timer));
|
||||
}
|
||||
|
||||
@ -398,9 +398,9 @@ static void mcpwm_deadtime_test_template(uint32_t timer_resolution, uint32_t per
|
||||
mcpwm_operator_config_t operator_config = {
|
||||
.group_id = 0,
|
||||
};
|
||||
mcpwm_oper_handle_t operator = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &operator));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(operator, timer));
|
||||
mcpwm_oper_handle_t oper = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(oper, timer));
|
||||
|
||||
TEST_ESP_OK(mcpwm_timer_enable(timer));
|
||||
|
||||
@ -409,8 +409,8 @@ static void mcpwm_deadtime_test_template(uint32_t timer_resolution, uint32_t per
|
||||
mcpwm_comparator_config_t comparator_config = {
|
||||
.flags.update_cmp_on_tez = true,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_new_comparator(operator, &comparator_config, &comparator_a));
|
||||
TEST_ESP_OK(mcpwm_new_comparator(operator, &comparator_config, &comparator_b));
|
||||
TEST_ESP_OK(mcpwm_new_comparator(oper, &comparator_config, &comparator_a));
|
||||
TEST_ESP_OK(mcpwm_new_comparator(oper, &comparator_config, &comparator_b));
|
||||
TEST_ESP_OK(mcpwm_comparator_set_compare_value(comparator_a, cmpa));
|
||||
TEST_ESP_OK(mcpwm_comparator_set_compare_value(comparator_b, cmpb));
|
||||
|
||||
@ -419,9 +419,9 @@ static void mcpwm_deadtime_test_template(uint32_t timer_resolution, uint32_t per
|
||||
mcpwm_generator_config_t generator_config = {
|
||||
.gen_gpio_num = gpioa,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &generator_a));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &generator_a));
|
||||
generator_config.gen_gpio_num = gpiob;
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &generator_b));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &generator_b));
|
||||
|
||||
set_generator_actions(generator_a, generator_b, comparator_a, comparator_b);
|
||||
set_dead_time(generator_a, generator_b);
|
||||
@ -436,7 +436,7 @@ static void mcpwm_deadtime_test_template(uint32_t timer_resolution, uint32_t per
|
||||
TEST_ESP_OK(mcpwm_del_generator(generator_b));
|
||||
TEST_ESP_OK(mcpwm_del_comparator(comparator_a));
|
||||
TEST_ESP_OK(mcpwm_del_comparator(comparator_b));
|
||||
TEST_ESP_OK(mcpwm_del_operator(operator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper));
|
||||
TEST_ESP_OK(mcpwm_del_timer(timer));
|
||||
}
|
||||
|
||||
|
@ -73,15 +73,15 @@ TEST_CASE("mcpwm_operator_carrier", "[mcpwm]")
|
||||
mcpwm_operator_config_t operator_config = {
|
||||
.group_id = 0,
|
||||
};
|
||||
mcpwm_oper_handle_t operator = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &operator));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(operator, timer));
|
||||
mcpwm_oper_handle_t oper = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(oper, timer));
|
||||
|
||||
mcpwm_generator_config_t generator_config = {
|
||||
.gen_gpio_num = 0,
|
||||
};
|
||||
mcpwm_gen_handle_t generator = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &generator));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &generator));
|
||||
|
||||
TEST_ESP_OK(mcpwm_generator_set_actions_on_timer_event(generator,
|
||||
MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_TOGGLE),
|
||||
@ -93,7 +93,7 @@ TEST_CASE("mcpwm_operator_carrier", "[mcpwm]")
|
||||
.duty_cycle = 0.5,
|
||||
.first_pulse_duration_us = 10,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_operator_apply_carrier(operator, &carrier_config));
|
||||
TEST_ESP_OK(mcpwm_operator_apply_carrier(oper, &carrier_config));
|
||||
|
||||
TEST_ESP_OK(mcpwm_timer_enable(timer));
|
||||
|
||||
@ -104,7 +104,7 @@ TEST_CASE("mcpwm_operator_carrier", "[mcpwm]")
|
||||
|
||||
printf("remove carrier from PWM wave\r\n");
|
||||
carrier_config.frequency_hz = 0;
|
||||
TEST_ESP_OK(mcpwm_operator_apply_carrier(operator, &carrier_config));
|
||||
TEST_ESP_OK(mcpwm_operator_apply_carrier(oper, &carrier_config));
|
||||
TEST_ESP_OK(mcpwm_timer_start_stop(timer, MCPWM_TIMER_START_NO_STOP));
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
TEST_ESP_OK(mcpwm_timer_start_stop(timer, MCPWM_TIMER_STOP_EMPTY));
|
||||
@ -112,17 +112,17 @@ TEST_CASE("mcpwm_operator_carrier", "[mcpwm]")
|
||||
|
||||
TEST_ESP_OK(mcpwm_timer_disable(timer));
|
||||
TEST_ESP_OK(mcpwm_del_generator(generator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(operator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper));
|
||||
TEST_ESP_OK(mcpwm_del_timer(timer));
|
||||
}
|
||||
|
||||
static bool test_cbc_brake_on_gpio_fault_callback(mcpwm_oper_handle_t operator, const mcpwm_brake_event_data_t *edata, void *user_data)
|
||||
static bool test_cbc_brake_on_gpio_fault_callback(mcpwm_oper_handle_t oper, const mcpwm_brake_event_data_t *edata, void *user_data)
|
||||
{
|
||||
esp_rom_printf("cbc brake\r\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool test_ost_brake_on_gpio_fault_callback(mcpwm_oper_handle_t operator, const mcpwm_brake_event_data_t *edata, void *user_data)
|
||||
static bool test_ost_brake_on_gpio_fault_callback(mcpwm_oper_handle_t oper, const mcpwm_brake_event_data_t *edata, void *user_data)
|
||||
{
|
||||
esp_rom_printf("ost brake\r\n");
|
||||
return false;
|
||||
@ -145,16 +145,16 @@ TEST_CASE("mcpwm_operator_brake_on_gpio_fault", "[mcpwm]")
|
||||
mcpwm_operator_config_t operator_config = {
|
||||
.group_id = 0,
|
||||
};
|
||||
mcpwm_oper_handle_t operator = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &operator));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(operator, timer));
|
||||
mcpwm_oper_handle_t oper = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(oper, timer));
|
||||
|
||||
printf("set brake event callbacks for operator\r\n");
|
||||
mcpwm_operator_event_callbacks_t cbs = {
|
||||
.on_brake_cbc = test_cbc_brake_on_gpio_fault_callback,
|
||||
.on_brake_ost = test_ost_brake_on_gpio_fault_callback,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_operator_register_event_callbacks(operator, &cbs, NULL));
|
||||
TEST_ESP_OK(mcpwm_operator_register_event_callbacks(oper, &cbs, NULL));
|
||||
|
||||
printf("install gpio fault\r\n");
|
||||
mcpwm_gpio_fault_config_t gpio_fault_config = {
|
||||
@ -183,10 +183,10 @@ TEST_CASE("mcpwm_operator_brake_on_gpio_fault", "[mcpwm]")
|
||||
.brake_mode = MCPWM_OPER_BRAKE_MODE_CBC,
|
||||
.flags.cbc_recover_on_tez = true,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_operator_set_brake_on_fault(operator, &brake_config));
|
||||
TEST_ESP_OK(mcpwm_operator_set_brake_on_fault(oper, &brake_config));
|
||||
brake_config.fault = gpio_ost_fault;
|
||||
brake_config.brake_mode = MCPWM_OPER_BRAKE_MODE_OST;
|
||||
TEST_ESP_OK(mcpwm_operator_set_brake_on_fault(operator, &brake_config));
|
||||
TEST_ESP_OK(mcpwm_operator_set_brake_on_fault(oper, &brake_config));
|
||||
|
||||
printf("create generators\r\n");
|
||||
const int gen_a_gpio = 0;
|
||||
@ -197,9 +197,9 @@ TEST_CASE("mcpwm_operator_brake_on_gpio_fault", "[mcpwm]")
|
||||
.flags.io_loop_back = true,
|
||||
};
|
||||
generator_config.gen_gpio_num = gen_a_gpio;
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &gen_a));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &gen_a));
|
||||
generator_config.gen_gpio_num = gen_b_gpio;
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &gen_b));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &gen_b));
|
||||
|
||||
printf("set generator actions on timer event\r\n");
|
||||
TEST_ESP_OK(mcpwm_generator_set_actions_on_timer_event(gen_a,
|
||||
@ -229,7 +229,7 @@ TEST_CASE("mcpwm_operator_brake_on_gpio_fault", "[mcpwm]")
|
||||
// remove the fault signal
|
||||
gpio_set_level(cbc_fault_gpio, 0);
|
||||
// recovery
|
||||
TEST_ESP_OK(mcpwm_operator_recover_from_fault(operator, gpio_cbc_fault));
|
||||
TEST_ESP_OK(mcpwm_operator_recover_from_fault(oper, gpio_cbc_fault));
|
||||
vTaskDelay(pdMS_TO_TICKS(40));
|
||||
// should recovery automatically
|
||||
TEST_ASSERT_EQUAL(0, gpio_get_level(gen_a_gpio));
|
||||
@ -241,14 +241,14 @@ TEST_CASE("mcpwm_operator_brake_on_gpio_fault", "[mcpwm]")
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
TEST_ASSERT_EQUAL(1, gpio_get_level(gen_b_gpio));
|
||||
// can't recover because fault signal is still active
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, mcpwm_operator_recover_from_fault(operator, gpio_ost_fault));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, mcpwm_operator_recover_from_fault(oper, gpio_ost_fault));
|
||||
// remove the fault signal
|
||||
gpio_set_level(ost_fault_gpio, 0);
|
||||
vTaskDelay(pdMS_TO_TICKS(40));
|
||||
// for ost brake, the generator can't recover before we manually recover it
|
||||
TEST_ASSERT_EQUAL(1, gpio_get_level(gen_b_gpio));
|
||||
// now it's safe to recover the operator
|
||||
TEST_ESP_OK(mcpwm_operator_recover_from_fault(operator, gpio_ost_fault));
|
||||
TEST_ESP_OK(mcpwm_operator_recover_from_fault(oper, gpio_ost_fault));
|
||||
vTaskDelay(pdMS_TO_TICKS(40));
|
||||
// should recovery now
|
||||
TEST_ASSERT_EQUAL(0, gpio_get_level(gen_b_gpio));
|
||||
@ -260,7 +260,7 @@ TEST_CASE("mcpwm_operator_brake_on_gpio_fault", "[mcpwm]")
|
||||
TEST_ESP_OK(mcpwm_del_fault(gpio_ost_fault));
|
||||
TEST_ESP_OK(mcpwm_del_generator(gen_a));
|
||||
TEST_ESP_OK(mcpwm_del_generator(gen_b));
|
||||
TEST_ESP_OK(mcpwm_del_operator(operator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper));
|
||||
TEST_ESP_OK(mcpwm_del_timer(timer));
|
||||
}
|
||||
|
||||
@ -281,9 +281,9 @@ TEST_CASE("mcpwm_operator_brake_on_soft_fault", "[mcpwm]")
|
||||
mcpwm_operator_config_t operator_config = {
|
||||
.group_id = 0,
|
||||
};
|
||||
mcpwm_oper_handle_t operator = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &operator));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(operator, timer));
|
||||
mcpwm_oper_handle_t oper = NULL;
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper));
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(oper, timer));
|
||||
|
||||
printf("install soft fault\r\n");
|
||||
mcpwm_soft_fault_config_t soft_fault_config = {};
|
||||
@ -296,7 +296,7 @@ TEST_CASE("mcpwm_operator_brake_on_soft_fault", "[mcpwm]")
|
||||
.brake_mode = MCPWM_OPER_BRAKE_MODE_CBC,
|
||||
.flags.cbc_recover_on_tez = true,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_operator_set_brake_on_fault(operator, &brake_config));
|
||||
TEST_ESP_OK(mcpwm_operator_set_brake_on_fault(oper, &brake_config));
|
||||
|
||||
printf("create generators\r\n");
|
||||
const int gen_a_gpio = 0;
|
||||
@ -307,9 +307,9 @@ TEST_CASE("mcpwm_operator_brake_on_soft_fault", "[mcpwm]")
|
||||
.flags.io_loop_back = true,
|
||||
};
|
||||
generator_config.gen_gpio_num = gen_a_gpio;
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &gen_a));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &gen_a));
|
||||
generator_config.gen_gpio_num = gen_b_gpio;
|
||||
TEST_ESP_OK(mcpwm_new_generator(operator, &generator_config, &gen_b));
|
||||
TEST_ESP_OK(mcpwm_new_generator(oper, &generator_config, &gen_b));
|
||||
|
||||
printf("set generator actions on timer event\r\n");
|
||||
TEST_ESP_OK(mcpwm_generator_set_actions_on_timer_event(gen_a,
|
||||
@ -344,7 +344,7 @@ TEST_CASE("mcpwm_operator_brake_on_soft_fault", "[mcpwm]")
|
||||
// start the timer, so that operator can recover at a specific event (e.g. tez)
|
||||
TEST_ESP_OK(mcpwm_timer_start_stop(timer, MCPWM_TIMER_START_NO_STOP));
|
||||
// recover on tez
|
||||
TEST_ESP_OK(mcpwm_operator_recover_from_fault(operator, soft_fault));
|
||||
TEST_ESP_OK(mcpwm_operator_recover_from_fault(oper, soft_fault));
|
||||
vTaskDelay(pdMS_TO_TICKS(40));
|
||||
// the generator output should be recoverd automatically
|
||||
TEST_ASSERT_EQUAL(0, gpio_get_level(gen_a_gpio));
|
||||
@ -352,7 +352,7 @@ TEST_CASE("mcpwm_operator_brake_on_soft_fault", "[mcpwm]")
|
||||
|
||||
printf("change the brake mode to ost\r\n");
|
||||
brake_config.brake_mode = MCPWM_OPER_BRAKE_MODE_OST;
|
||||
TEST_ESP_OK(mcpwm_operator_set_brake_on_fault(operator, &brake_config));
|
||||
TEST_ESP_OK(mcpwm_operator_set_brake_on_fault(oper, &brake_config));
|
||||
|
||||
printf("trigger soft fault signal, brake in OST mode\r\n");
|
||||
TEST_ESP_OK(mcpwm_timer_start_stop(timer, MCPWM_TIMER_START_NO_STOP));
|
||||
@ -364,7 +364,7 @@ TEST_CASE("mcpwm_operator_brake_on_soft_fault", "[mcpwm]")
|
||||
vTaskDelay(pdMS_TO_TICKS(40));
|
||||
// don't recover without a manual recover
|
||||
TEST_ASSERT_EQUAL(1, gpio_get_level(gen_b_gpio));
|
||||
TEST_ESP_OK(mcpwm_operator_recover_from_fault(operator, soft_fault));
|
||||
TEST_ESP_OK(mcpwm_operator_recover_from_fault(oper, soft_fault));
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
// should recovery now
|
||||
TEST_ASSERT_EQUAL(0, gpio_get_level(gen_b_gpio));
|
||||
@ -375,6 +375,6 @@ TEST_CASE("mcpwm_operator_brake_on_soft_fault", "[mcpwm]")
|
||||
TEST_ESP_OK(mcpwm_del_fault(soft_fault));
|
||||
TEST_ESP_OK(mcpwm_del_generator(gen_a));
|
||||
TEST_ESP_OK(mcpwm_del_generator(gen_b));
|
||||
TEST_ESP_OK(mcpwm_del_operator(operator));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper));
|
||||
TEST_ESP_OK(mcpwm_del_timer(timer));
|
||||
}
|
||||
|
@ -39,27 +39,27 @@ void app_main(void)
|
||||
};
|
||||
ESP_ERROR_CHECK(mcpwm_new_timer(&timer_config, &timer));
|
||||
|
||||
mcpwm_oper_handle_t operator = NULL;
|
||||
mcpwm_oper_handle_t oper = NULL;
|
||||
mcpwm_operator_config_t operator_config = {
|
||||
.group_id = 0, // operator must be in the same group to the timer
|
||||
};
|
||||
ESP_ERROR_CHECK(mcpwm_new_operator(&operator_config, &operator));
|
||||
ESP_ERROR_CHECK(mcpwm_new_operator(&operator_config, &oper));
|
||||
|
||||
ESP_LOGI(TAG, "Connect timer and operator");
|
||||
ESP_ERROR_CHECK(mcpwm_operator_connect_timer(operator, timer));
|
||||
ESP_ERROR_CHECK(mcpwm_operator_connect_timer(oper, timer));
|
||||
|
||||
ESP_LOGI(TAG, "Create comparator and generator from the operator");
|
||||
mcpwm_cmpr_handle_t comparator = NULL;
|
||||
mcpwm_comparator_config_t comparator_config = {
|
||||
.flags.update_cmp_on_tez = true,
|
||||
};
|
||||
ESP_ERROR_CHECK(mcpwm_new_comparator(operator, &comparator_config, &comparator));
|
||||
ESP_ERROR_CHECK(mcpwm_new_comparator(oper, &comparator_config, &comparator));
|
||||
|
||||
mcpwm_gen_handle_t generator = NULL;
|
||||
mcpwm_generator_config_t generator_config = {
|
||||
.gen_gpio_num = SERVO_PULSE_GPIO,
|
||||
};
|
||||
ESP_ERROR_CHECK(mcpwm_new_generator(operator, &generator_config, &generator));
|
||||
ESP_ERROR_CHECK(mcpwm_new_generator(oper, &generator_config, &generator));
|
||||
|
||||
// set the initial compare value, so that the servo will spin to the center position
|
||||
ESP_ERROR_CHECK(mcpwm_comparator_set_compare_value(comparator, example_angle_to_compare(0)));
|
||||
|
@ -1,4 +1,5 @@
|
||||
idf_component_register(SRCS cxx_build_test_main.cpp
|
||||
test_soc_reg_macros.cpp
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES driver
|
||||
REQUIRES soc)
|
||||
|
@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "driver/mcpwm_prelude.h"
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user