mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
refactor(mcpwm): move interrupt conflict checks to allocator
This commit is contained in:
@@ -275,10 +275,6 @@ esp_err_t mcpwm_new_capture_channel(mcpwm_cap_timer_handle_t cap_timer, const mc
|
||||
mcpwm_hal_context_t *hal = &group->hal;
|
||||
int cap_chan_id = cap_chan->cap_chan_id;
|
||||
|
||||
// if interrupt priority specified before, it cannot be changed until the group is released
|
||||
// check if the new priority specified consistents with the old one
|
||||
ESP_GOTO_ON_ERROR(mcpwm_check_intr_priority(group, config->intr_priority), err, TAG, "set group interrupt priority failed");
|
||||
|
||||
mcpwm_ll_capture_enable_negedge(hal->dev, cap_chan_id, config->flags.neg_edge);
|
||||
mcpwm_ll_capture_enable_posedge(hal->dev, cap_chan_id, config->flags.pos_edge);
|
||||
mcpwm_ll_invert_input(hal->dev, cap_chan_id, config->flags.invert_cap_signal);
|
||||
@@ -293,6 +289,7 @@ esp_err_t mcpwm_new_capture_channel(mcpwm_cap_timer_handle_t cap_timer, const mc
|
||||
|
||||
cap_chan->gpio_num = config->gpio_num;
|
||||
cap_chan->fsm = MCPWM_CAP_CHAN_FSM_INIT;
|
||||
cap_chan->intr_priority = config->intr_priority;
|
||||
|
||||
*ret_cap_channel = cap_chan;
|
||||
ESP_LOGD(TAG, "new capture channel (%d,%d) at %p", group->group_id, cap_chan_id, cap_chan);
|
||||
@@ -384,11 +381,18 @@ esp_err_t mcpwm_capture_channel_register_event_callbacks(mcpwm_cap_channel_handl
|
||||
// lazy install interrupt service
|
||||
if (!cap_channel->intr) {
|
||||
ESP_RETURN_ON_FALSE(cap_channel->fsm == MCPWM_CAP_CHAN_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "channel not in init state");
|
||||
int isr_flags = MCPWM_INTR_ALLOC_FLAG;
|
||||
isr_flags |= mcpwm_get_intr_priority_flag(group);
|
||||
ESP_RETURN_ON_ERROR(esp_intr_alloc_intrstatus(soc_mcpwm_signals[group_id].irq_id, isr_flags,
|
||||
(uint32_t)mcpwm_ll_intr_get_status_reg(hal->dev), MCPWM_LL_EVENT_CAPTURE(cap_chan_id),
|
||||
mcpwm_capture_default_isr, cap_channel, &cap_channel->intr), TAG, "install interrupt service for cap channel failed");
|
||||
int isr_flags = MCPWM_INTR_ALLOC_FLAG |
|
||||
(cap_channel->intr_priority ? (1 << cap_channel->intr_priority) : MCPWM_ALLOW_INTR_PRIORITY_MASK);
|
||||
esp_intr_alloc_info_t intr_info = {
|
||||
.source = soc_mcpwm_signals[group_id].irq_id,
|
||||
.flags = isr_flags,
|
||||
.intrstatusreg = (uint32_t)mcpwm_ll_intr_get_status_reg(hal->dev),
|
||||
.intrstatusmask = MCPWM_LL_EVENT_CAPTURE(cap_chan_id),
|
||||
.handler = mcpwm_capture_default_isr,
|
||||
.arg = cap_channel,
|
||||
.bind_by.name = soc_mcpwm_signals[group_id].module_name,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_intr_alloc_info(&intr_info, &cap_channel->intr), TAG, "install interrupt service for cap channel failed");
|
||||
}
|
||||
|
||||
portENTER_CRITICAL(&group->spinlock);
|
||||
|
||||
@@ -112,16 +112,13 @@ esp_err_t mcpwm_new_comparator(mcpwm_oper_handle_t oper, const mcpwm_comparator_
|
||||
int oper_id = oper->oper_id;
|
||||
int cmpr_id = cmpr->base.cmpr_id;
|
||||
|
||||
// if interrupt priority specified before, it cannot be changed until the group is released
|
||||
// check if the new priority specified consistent with the old one
|
||||
ESP_GOTO_ON_ERROR(mcpwm_check_intr_priority(group, config->intr_priority), err, TAG, "set group interrupt priority failed");
|
||||
|
||||
mcpwm_ll_operator_enable_update_compare_on_tez(hal->dev, oper_id, cmpr_id, config->flags.update_cmp_on_tez);
|
||||
mcpwm_ll_operator_enable_update_compare_on_tep(hal->dev, oper_id, cmpr_id, config->flags.update_cmp_on_tep);
|
||||
mcpwm_ll_operator_enable_update_compare_on_sync(hal->dev, oper_id, cmpr_id, config->flags.update_cmp_on_sync);
|
||||
|
||||
// fill in other comparator members
|
||||
cmpr->base.spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED;
|
||||
cmpr->intr_priority = config->intr_priority;
|
||||
*ret_cmpr = &cmpr->base;
|
||||
ESP_LOGD(TAG, "new operator comparator (%d,%d,%d) at %p", group->group_id, oper_id, cmpr_id, cmpr);
|
||||
return ESP_OK;
|
||||
@@ -233,11 +230,18 @@ esp_err_t mcpwm_comparator_register_event_callbacks(mcpwm_cmpr_handle_t cmpr, co
|
||||
// lazy install interrupt service
|
||||
if (!oper_cmpr->intr) {
|
||||
// we want the interrupt service to be enabled after allocation successfully
|
||||
int isr_flags = MCPWM_INTR_ALLOC_FLAG & ~ ESP_INTR_FLAG_INTRDISABLED;
|
||||
isr_flags |= mcpwm_get_intr_priority_flag(group);
|
||||
ESP_RETURN_ON_ERROR(esp_intr_alloc_intrstatus(soc_mcpwm_signals[group_id].irq_id, isr_flags,
|
||||
(uint32_t)mcpwm_ll_intr_get_status_reg(hal->dev), MCPWM_LL_EVENT_CMP_EQUAL(oper_id, cmpr_id),
|
||||
mcpwm_comparator_default_isr, oper_cmpr, &oper_cmpr->intr), TAG, "install interrupt service for comparator failed");
|
||||
int isr_flags = (MCPWM_INTR_ALLOC_FLAG & ~ESP_INTR_FLAG_INTRDISABLED) |
|
||||
(oper_cmpr->intr_priority ? (1 << oper_cmpr->intr_priority) : MCPWM_ALLOW_INTR_PRIORITY_MASK);
|
||||
esp_intr_alloc_info_t intr_info = {
|
||||
.source = soc_mcpwm_signals[group_id].irq_id,
|
||||
.flags = isr_flags,
|
||||
.intrstatusreg = (uint32_t)mcpwm_ll_intr_get_status_reg(hal->dev),
|
||||
.intrstatusmask = MCPWM_LL_EVENT_CMP_EQUAL(oper_id, cmpr_id),
|
||||
.handler = mcpwm_comparator_default_isr,
|
||||
.arg = oper_cmpr,
|
||||
.bind_by.name = soc_mcpwm_signals[group_id].module_name,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_intr_alloc_info(&intr_info, &oper_cmpr->intr), TAG, "install interrupt service for comparator failed");
|
||||
}
|
||||
|
||||
portENTER_CRITICAL(&group->spinlock);
|
||||
|
||||
@@ -35,7 +35,6 @@ mcpwm_group_t *mcpwm_acquire_group_handle(int group_id)
|
||||
new_group = true;
|
||||
s_platform.groups[group_id] = group;
|
||||
group->group_id = group_id;
|
||||
group->intr_priority = -1;
|
||||
group->spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED;
|
||||
#if MCPWM_USE_RETENTION_LINK
|
||||
sleep_retention_module_t module = mcpwm_reg_retention_info[group_id].retention_module;
|
||||
@@ -131,32 +130,6 @@ void mcpwm_release_group_handle(mcpwm_group_t *group)
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t mcpwm_check_intr_priority(mcpwm_group_t *group, int intr_priority)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
bool intr_priority_conflict = false;
|
||||
portENTER_CRITICAL(&group->spinlock);
|
||||
if (group->intr_priority == -1) {
|
||||
group->intr_priority = intr_priority;
|
||||
} else if (intr_priority != 0) {
|
||||
intr_priority_conflict = (group->intr_priority != intr_priority);
|
||||
}
|
||||
portEXIT_CRITICAL(&group->spinlock);
|
||||
ESP_RETURN_ON_FALSE(!intr_priority_conflict, ESP_ERR_INVALID_STATE, TAG, "intr_priority conflict, already is %d but attempt to %d", group->intr_priority, intr_priority);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mcpwm_get_intr_priority_flag(mcpwm_group_t *group)
|
||||
{
|
||||
int isr_flags = 0;
|
||||
if (group->intr_priority) {
|
||||
isr_flags |= 1 << (group->intr_priority);
|
||||
} else {
|
||||
isr_flags |= MCPWM_ALLOW_INTR_PRIORITY_MASK;
|
||||
}
|
||||
return isr_flags;
|
||||
}
|
||||
|
||||
esp_err_t mcpwm_select_periph_clock(mcpwm_group_t *group, soc_module_clk_t clk_src)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
@@ -86,10 +86,6 @@ esp_err_t mcpwm_new_gpio_fault(const mcpwm_gpio_fault_config_t *config, mcpwm_fa
|
||||
mcpwm_hal_context_t *hal = &group->hal;
|
||||
int fault_id = fault->fault_id;
|
||||
|
||||
// if interrupt priority specified before, it cannot be changed until the group is released
|
||||
// check if the new priority specified consistents with the old one
|
||||
ESP_GOTO_ON_ERROR(mcpwm_check_intr_priority(group, config->intr_priority), err, TAG, "set group interrupt priority failed");
|
||||
|
||||
// GPIO configuration
|
||||
gpio_func_sel(config->gpio_num, PIN_FUNC_GPIO);
|
||||
gpio_input_enable(config->gpio_num);
|
||||
@@ -107,6 +103,7 @@ esp_err_t mcpwm_new_gpio_fault(const mcpwm_gpio_fault_config_t *config, mcpwm_fa
|
||||
// fill in other operator members
|
||||
fault->base.type = MCPWM_FAULT_TYPE_GPIO;
|
||||
fault->gpio_num = config->gpio_num;
|
||||
fault->intr_priority = config->intr_priority;
|
||||
fault->base.del = mcpwm_del_gpio_fault;
|
||||
*ret_fault = &fault->base;
|
||||
ESP_LOGD(TAG, "new gpio fault (%d,%d) at %p, GPIO: %d", group_id, fault_id, fault, config->gpio_num);
|
||||
@@ -229,11 +226,18 @@ esp_err_t mcpwm_fault_register_event_callbacks(mcpwm_fault_handle_t fault, const
|
||||
// lazy install interrupt service
|
||||
if (!gpio_fault->intr) {
|
||||
// we want the interrupt service to be enabled after allocation successfully
|
||||
int isr_flags = MCPWM_INTR_ALLOC_FLAG & ~ESP_INTR_FLAG_INTRDISABLED;
|
||||
isr_flags |= mcpwm_get_intr_priority_flag(group);
|
||||
ESP_RETURN_ON_ERROR(esp_intr_alloc_intrstatus(soc_mcpwm_signals[group_id].irq_id, isr_flags,
|
||||
(uint32_t)mcpwm_ll_intr_get_status_reg(hal->dev), MCPWM_LL_EVENT_FAULT_MASK(fault_id),
|
||||
mcpwm_gpio_fault_default_isr, gpio_fault, &gpio_fault->intr), TAG, "install interrupt service for gpio fault failed");
|
||||
int isr_flags = (MCPWM_INTR_ALLOC_FLAG & ~ESP_INTR_FLAG_INTRDISABLED) |
|
||||
(gpio_fault->intr_priority ? (1 << gpio_fault->intr_priority) : MCPWM_ALLOW_INTR_PRIORITY_MASK);
|
||||
esp_intr_alloc_info_t intr_info = {
|
||||
.source = soc_mcpwm_signals[group_id].irq_id,
|
||||
.flags = isr_flags,
|
||||
.intrstatusreg = (uint32_t)mcpwm_ll_intr_get_status_reg(hal->dev),
|
||||
.intrstatusmask = MCPWM_LL_EVENT_FAULT_MASK(fault_id),
|
||||
.handler = mcpwm_gpio_fault_default_isr,
|
||||
.arg = gpio_fault,
|
||||
.bind_by.name = soc_mcpwm_signals[group_id].module_name,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_intr_alloc_info(&intr_info, &gpio_fault->intr), TAG, "install interrupt service for gpio fault failed");
|
||||
}
|
||||
|
||||
// different mcpwm events share the same interrupt control register
|
||||
|
||||
@@ -82,10 +82,6 @@ esp_err_t mcpwm_new_operator(const mcpwm_operator_config_t *config, mcpwm_oper_h
|
||||
mcpwm_hal_context_t *hal = &group->hal;
|
||||
int oper_id = oper->oper_id;
|
||||
|
||||
// if interrupt priority specified before, it cannot be changed until the group is released
|
||||
// check if the new priority specified consistents with the old one
|
||||
ESP_GOTO_ON_ERROR(mcpwm_check_intr_priority(group, config->intr_priority), err, TAG, "set group interrupt priority failed");
|
||||
|
||||
// reset MCPWM operator
|
||||
mcpwm_hal_operator_reset(hal, oper_id);
|
||||
|
||||
@@ -103,6 +99,7 @@ esp_err_t mcpwm_new_operator(const mcpwm_operator_config_t *config, mcpwm_oper_h
|
||||
|
||||
// fill in other operator members
|
||||
oper->spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED;
|
||||
oper->intr_priority = config->intr_priority;
|
||||
*ret_oper = oper;
|
||||
ESP_LOGD(TAG, "new operator (%d,%d) at %p", group_id, oper_id, oper);
|
||||
return ESP_OK;
|
||||
@@ -233,11 +230,18 @@ esp_err_t mcpwm_operator_register_event_callbacks(mcpwm_oper_handle_t oper, cons
|
||||
// lazy install interrupt service
|
||||
if (!oper->intr) {
|
||||
// we want the interrupt service to be enabled after allocation successfully
|
||||
int isr_flags = MCPWM_INTR_ALLOC_FLAG & ~ ESP_INTR_FLAG_INTRDISABLED;
|
||||
isr_flags |= mcpwm_get_intr_priority_flag(group);
|
||||
ESP_RETURN_ON_ERROR(esp_intr_alloc_intrstatus(soc_mcpwm_signals[group_id].irq_id, isr_flags,
|
||||
(uint32_t)mcpwm_ll_intr_get_status_reg(hal->dev), MCPWM_LL_EVENT_OPER_MASK(oper_id),
|
||||
mcpwm_operator_default_isr, oper, &oper->intr), TAG, "install interrupt service for operator failed");
|
||||
int isr_flags = (MCPWM_INTR_ALLOC_FLAG & ~ESP_INTR_FLAG_INTRDISABLED) |
|
||||
(oper->intr_priority ? (1 << oper->intr_priority) : MCPWM_ALLOW_INTR_PRIORITY_MASK);
|
||||
esp_intr_alloc_info_t intr_info = {
|
||||
.source = soc_mcpwm_signals[group_id].irq_id,
|
||||
.flags = isr_flags,
|
||||
.intrstatusreg = (uint32_t)mcpwm_ll_intr_get_status_reg(hal->dev),
|
||||
.intrstatusmask = MCPWM_LL_EVENT_OPER_MASK(oper_id),
|
||||
.handler = mcpwm_operator_default_isr,
|
||||
.arg = oper,
|
||||
.bind_by.name = soc_mcpwm_signals[group_id].module_name,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_intr_alloc_info(&intr_info, &oper->intr), TAG, "install interrupt service for operator failed");
|
||||
}
|
||||
|
||||
// enable/disable interrupt events
|
||||
|
||||
@@ -42,9 +42,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#if CONFIG_MCPWM_ISR_CACHE_SAFE
|
||||
#define MCPWM_INTR_ALLOC_FLAG (ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM)
|
||||
#define MCPWM_INTR_ALLOC_FLAG (ESP_INTR_FLAG_SHARED_PRIVATE | ESP_INTR_FLAG_INTRDISABLED | ESP_INTR_FLAG_IRAM)
|
||||
#else
|
||||
#define MCPWM_INTR_ALLOC_FLAG (ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_INTRDISABLED)
|
||||
#define MCPWM_INTR_ALLOC_FLAG (ESP_INTR_FLAG_SHARED_PRIVATE | ESP_INTR_FLAG_INTRDISABLED)
|
||||
#endif
|
||||
|
||||
// Use retention link only when the target supports sleep retention is enabled
|
||||
@@ -76,7 +76,6 @@ typedef struct mcpwm_cap_channel_t mcpwm_cap_channel_t;
|
||||
|
||||
struct mcpwm_group_t {
|
||||
int group_id; // group ID, index from 0
|
||||
int intr_priority; // MCPWM interrupt priority
|
||||
mcpwm_hal_context_t hal; // HAL instance is at group level
|
||||
portMUX_TYPE spinlock; // group level spinlock
|
||||
uint32_t prescale; // group prescale
|
||||
@@ -103,6 +102,7 @@ struct mcpwm_timer_t {
|
||||
mcpwm_timer_fsm_t fsm; // driver FSM
|
||||
portMUX_TYPE spinlock; // spin lock
|
||||
intr_handle_t intr; // interrupt handle
|
||||
int intr_priority; // interrupt priority used by this timer
|
||||
uint32_t resolution_hz; // resolution of the timer
|
||||
uint32_t peak_ticks; // peak ticks that the timer could reach to
|
||||
mcpwm_timer_sync_src_t *sync_src; // timer sync_src
|
||||
@@ -125,6 +125,7 @@ struct mcpwm_oper_t {
|
||||
mcpwm_timer_t *timer; // which timer is connected to this operator
|
||||
portMUX_TYPE spinlock; // spin lock
|
||||
intr_handle_t intr; // interrupt handle
|
||||
int intr_priority; // interrupt priority used by this operator
|
||||
mcpwm_gen_t *generators[MCPWM_LL_GET(GENERATORS_PER_OPERATOR)]; // mcpwm generator array
|
||||
mcpwm_oper_cmpr_t *comparators[MCPWM_LL_GET(COMPARATORS_PER_OPERATOR)]; // mcpwm operator comparator array
|
||||
#if SOC_MCPWM_SUPPORT_EVENT_COMPARATOR
|
||||
@@ -160,6 +161,7 @@ struct mcpwm_cmpr_t {
|
||||
struct mcpwm_oper_cmpr_t {
|
||||
mcpwm_cmpr_t base; // base class
|
||||
intr_handle_t intr; // interrupt handle
|
||||
int intr_priority; // interrupt priority used by this comparator
|
||||
mcpwm_compare_event_cb_t on_reach; // ISR callback function which would be invoked on timer counter reaches compare value
|
||||
void *user_data; // user data which would be passed to the comparator callbacks
|
||||
};
|
||||
@@ -191,6 +193,7 @@ struct mcpwm_gpio_fault_t {
|
||||
int fault_id; // fault detector ID, index from 0
|
||||
int gpio_num; // GPIO number of fault detector
|
||||
intr_handle_t intr; // interrupt handle
|
||||
int intr_priority; // interrupt priority used by this fault detector
|
||||
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
|
||||
void *user_data; // user data which would be passed to the isr_cb
|
||||
@@ -267,14 +270,13 @@ struct mcpwm_cap_channel_t {
|
||||
int gpio_num; // GPIO number used by the channel
|
||||
mcpwm_cap_channel_fsm_t fsm; // driver FSM
|
||||
intr_handle_t intr; // Interrupt handle
|
||||
int intr_priority; // interrupt priority used by this capture channel
|
||||
mcpwm_capture_event_cb_t on_cap; // Callback function which would be invoked in capture interrupt routine
|
||||
void *user_data; // user data which would be passed to the capture callback
|
||||
};
|
||||
|
||||
mcpwm_group_t *mcpwm_acquire_group_handle(int group_id);
|
||||
void mcpwm_release_group_handle(mcpwm_group_t *group);
|
||||
esp_err_t mcpwm_check_intr_priority(mcpwm_group_t *group, int intr_priority);
|
||||
int mcpwm_get_intr_priority_flag(mcpwm_group_t *group);
|
||||
esp_err_t mcpwm_select_periph_clock(mcpwm_group_t *group, soc_module_clk_t clk_src);
|
||||
esp_err_t mcpwm_set_prescale(mcpwm_group_t *group, uint32_t expect_module_resolution_hz, uint32_t module_prescale_max, uint32_t *ret_module_prescale);
|
||||
|
||||
|
||||
@@ -94,10 +94,6 @@ esp_err_t mcpwm_new_timer(const mcpwm_timer_config_t *config, mcpwm_timer_handle
|
||||
mcpwm_hal_context_t *hal = &group->hal;
|
||||
int timer_id = timer->timer_id;
|
||||
|
||||
// if interrupt priority specified before, it cannot be changed until the group is released
|
||||
// check if the new priority specified consistents with the old one
|
||||
ESP_GOTO_ON_ERROR(mcpwm_check_intr_priority(group, config->intr_priority), err, TAG, "set group interrupt priority failed");
|
||||
|
||||
// select the clock source
|
||||
mcpwm_timer_clock_source_t clk_src = config->clk_src ? config->clk_src : MCPWM_TIMER_CLK_SRC_DEFAULT;
|
||||
ESP_GOTO_ON_ERROR(mcpwm_select_periph_clock(group, (soc_module_clk_t)clk_src), err, TAG, "set group clock failed");
|
||||
@@ -125,6 +121,7 @@ esp_err_t mcpwm_new_timer(const mcpwm_timer_config_t *config, mcpwm_timer_handle
|
||||
// fill in other timer specific members
|
||||
timer->spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED;
|
||||
timer->fsm = MCPWM_TIMER_FSM_INIT;
|
||||
timer->intr_priority = config->intr_priority;
|
||||
*ret_timer = timer;
|
||||
|
||||
#if MCPWM_USE_RETENTION_LINK
|
||||
@@ -208,11 +205,18 @@ esp_err_t mcpwm_timer_register_event_callbacks(mcpwm_timer_handle_t timer, const
|
||||
// lazy install interrupt service
|
||||
if (!timer->intr) {
|
||||
ESP_RETURN_ON_FALSE(timer->fsm == MCPWM_TIMER_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "timer not in init state");
|
||||
int isr_flags = MCPWM_INTR_ALLOC_FLAG;
|
||||
isr_flags |= mcpwm_get_intr_priority_flag(group);
|
||||
ESP_RETURN_ON_ERROR(esp_intr_alloc_intrstatus(soc_mcpwm_signals[group_id].irq_id, isr_flags,
|
||||
(uint32_t)mcpwm_ll_intr_get_status_reg(hal->dev), MCPWM_LL_EVENT_TIMER_MASK(timer_id),
|
||||
mcpwm_timer_default_isr, timer, &timer->intr), TAG, "install interrupt service for timer failed");
|
||||
int isr_flags = MCPWM_INTR_ALLOC_FLAG |
|
||||
(timer->intr_priority ? (1 << timer->intr_priority) : MCPWM_ALLOW_INTR_PRIORITY_MASK);
|
||||
esp_intr_alloc_info_t intr_info = {
|
||||
.source = soc_mcpwm_signals[group_id].irq_id,
|
||||
.flags = isr_flags,
|
||||
.intrstatusreg = (uint32_t)mcpwm_ll_intr_get_status_reg(hal->dev),
|
||||
.intrstatusmask = MCPWM_LL_EVENT_TIMER_MASK(timer_id),
|
||||
.handler = mcpwm_timer_default_isr,
|
||||
.arg = timer,
|
||||
.bind_by.name = soc_mcpwm_signals[group_id].module_name,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_intr_alloc_info(&intr_info, &timer->intr), TAG, "install interrupt service for timer failed");
|
||||
}
|
||||
|
||||
// enable/disable interrupt events
|
||||
|
||||
@@ -9,6 +9,36 @@
|
||||
#include "driver/mcpwm_prelude.h"
|
||||
#include "test_mcpwm_utils.h"
|
||||
|
||||
TEST_MCPWM_CALLBACK_ATTR
|
||||
static bool test_mcpwm_timer_on_full_cb(mcpwm_timer_handle_t timer, const mcpwm_timer_event_data_t *edata, void *user_data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST_MCPWM_CALLBACK_ATTR
|
||||
static bool test_mcpwm_oper_on_brake_cbc_cb(mcpwm_oper_handle_t oper, const mcpwm_brake_event_data_t *edata, void *user_data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST_MCPWM_CALLBACK_ATTR
|
||||
static bool test_mcpwm_cmpr_on_reach_cb(mcpwm_cmpr_handle_t comparator, const mcpwm_compare_event_data_t *edata, void *user_data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST_MCPWM_CALLBACK_ATTR
|
||||
static bool test_mcpwm_fault_on_enter_cb(mcpwm_fault_handle_t fault, const mcpwm_fault_event_data_t *edata, void *user_data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST_MCPWM_CALLBACK_ATTR
|
||||
static bool test_mcpwm_cap_on_cap_cb(mcpwm_cap_channel_handle_t cap_channel, const mcpwm_capture_event_data_t *edata, void *user_data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST_CASE("mcpwm_set_interrupt_priority", "[mcpwm]")
|
||||
{
|
||||
printf("install timer\r\n");
|
||||
@@ -25,13 +55,13 @@ TEST_CASE("mcpwm_set_interrupt_priority", "[mcpwm]")
|
||||
printf("register event callbacks\r\n");
|
||||
mcpwm_timer_event_callbacks_t timer_cbs = {
|
||||
.on_stop = NULL,
|
||||
.on_full = NULL,
|
||||
.on_full = test_mcpwm_timer_on_full_cb,
|
||||
.on_empty = NULL,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_timer_register_event_callbacks(timer, &timer_cbs, NULL));
|
||||
timer_config.intr_priority = 1;
|
||||
mcpwm_timer_handle_t timer2 = NULL;
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, mcpwm_new_timer(&timer_config, &timer2));
|
||||
TEST_ESP_OK(mcpwm_new_timer(&timer_config, &timer2));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, mcpwm_timer_register_event_callbacks(timer2, &timer_cbs, NULL));
|
||||
|
||||
printf("install operator\r\n");
|
||||
@@ -43,13 +73,13 @@ TEST_CASE("mcpwm_set_interrupt_priority", "[mcpwm]")
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper));
|
||||
printf("register event callbacks\r\n");
|
||||
mcpwm_operator_event_callbacks_t oper_cbs = {
|
||||
.on_brake_cbc = NULL,
|
||||
.on_brake_cbc = test_mcpwm_oper_on_brake_cbc_cb,
|
||||
.on_brake_ost = NULL,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_operator_register_event_callbacks(oper, &oper_cbs, NULL));
|
||||
operator_config.intr_priority = 1;
|
||||
mcpwm_oper_handle_t oper2 = NULL;
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, mcpwm_new_operator(&operator_config, &oper2));
|
||||
TEST_ESP_OK(mcpwm_new_operator(&operator_config, &oper2));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, mcpwm_operator_register_event_callbacks(oper2, &oper_cbs, NULL));
|
||||
|
||||
printf("install comparator\r\n");
|
||||
@@ -61,12 +91,12 @@ TEST_CASE("mcpwm_set_interrupt_priority", "[mcpwm]")
|
||||
TEST_ESP_OK(mcpwm_operator_connect_timer(oper, timer));
|
||||
printf("register event callback\r\n");
|
||||
mcpwm_comparator_event_callbacks_t comparator_cbs = {
|
||||
.on_reach = NULL,
|
||||
.on_reach = test_mcpwm_cmpr_on_reach_cb,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_comparator_register_event_callbacks(comparator, &comparator_cbs, NULL));
|
||||
comparator_config.intr_priority = 1;
|
||||
mcpwm_cmpr_handle_t comparator2 = NULL;
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, mcpwm_new_comparator(oper, &comparator_config, &comparator2));
|
||||
TEST_ESP_OK(mcpwm_new_comparator(oper, &comparator_config, &comparator2));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, mcpwm_comparator_register_event_callbacks(comparator2, &comparator_cbs, NULL));
|
||||
|
||||
printf("install gpio fault\r\n");
|
||||
@@ -81,13 +111,13 @@ TEST_CASE("mcpwm_set_interrupt_priority", "[mcpwm]")
|
||||
|
||||
printf("register event callback\r\n");
|
||||
mcpwm_fault_event_callbacks_t fault_cbs = {
|
||||
.on_fault_enter = NULL,
|
||||
.on_fault_enter = test_mcpwm_fault_on_enter_cb,
|
||||
.on_fault_exit = NULL,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_fault_register_event_callbacks(fault, &fault_cbs, NULL));
|
||||
gpio_fault_config.intr_priority = 1;
|
||||
mcpwm_fault_handle_t fault2 = NULL;
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, mcpwm_new_gpio_fault(&gpio_fault_config, &fault2));
|
||||
TEST_ESP_OK(mcpwm_new_gpio_fault(&gpio_fault_config, &fault2));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, mcpwm_fault_register_event_callbacks(fault2, &fault_cbs, NULL));
|
||||
|
||||
printf("install capture timer\r\n");
|
||||
@@ -108,21 +138,26 @@ TEST_CASE("mcpwm_set_interrupt_priority", "[mcpwm]")
|
||||
|
||||
printf("register event callback\r\n");
|
||||
mcpwm_capture_event_callbacks_t cap_cbs = {
|
||||
.on_cap = NULL,
|
||||
.on_cap = test_mcpwm_cap_on_cap_cb,
|
||||
};
|
||||
TEST_ESP_OK(mcpwm_capture_channel_register_event_callbacks(cap_channel, &cap_cbs, NULL));
|
||||
cap_chan_config.intr_priority = 1;
|
||||
mcpwm_cap_channel_handle_t cap_channel2 = NULL;
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, mcpwm_new_capture_channel(cap_timer, &cap_chan_config, &cap_channel2));
|
||||
TEST_ESP_OK(mcpwm_new_capture_channel(cap_timer, &cap_chan_config, &cap_channel2));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, mcpwm_capture_channel_register_event_callbacks(cap_channel2, &cap_cbs, NULL));
|
||||
|
||||
printf("delete all mcpwm objects\r\n");
|
||||
TEST_ESP_OK(mcpwm_del_comparator(comparator));
|
||||
TEST_ESP_OK(mcpwm_del_comparator(comparator2));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper));
|
||||
TEST_ESP_OK(mcpwm_del_operator(oper2));
|
||||
TEST_ESP_OK(mcpwm_del_capture_channel(cap_channel));
|
||||
TEST_ESP_OK(mcpwm_del_capture_channel(cap_channel2));
|
||||
TEST_ESP_OK(mcpwm_del_capture_timer(cap_timer));
|
||||
TEST_ESP_OK(mcpwm_del_timer(timer));
|
||||
TEST_ESP_OK(mcpwm_del_timer(timer2));
|
||||
TEST_ESP_OK(mcpwm_del_fault(fault));
|
||||
TEST_ESP_OK(mcpwm_del_fault(fault2));
|
||||
}
|
||||
|
||||
TEST_CASE("mcpwm_group_set_prescale_dynamically", "[mcpwm]")
|
||||
|
||||
Reference in New Issue
Block a user