/* * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */#pragmaonce#include<stdint.h>#include"sdkconfig.h"#include"freertos/FreeRTOS.h"#include"esp_err.h"#include"esp_intr_alloc.h"#include"esp_heap_caps.h"#include"esp_pm.h"#include"soc/soc_caps.h"#include"hal/mcpwm_hal.h"#include"hal/mcpwm_types.h"#include"driver/mcpwm_types.h"#include"esp_private/sleep_retention.h"12 includes#ifdef__cplusplusextern"C"{#endif#ifCONFIG_MCPWM_ISR_IRAM_SAFE||CONFIG_MCPWM_CTRL_FUNC_IN_IRAM#defineMCPWM_MEM_ALLOC_CAPS(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)#else#defineMCPWM_MEM_ALLOC_CAPSMALLOC_CAP_DEFAULT#endif#ifCONFIG_MCPWM_ISR_IRAM_SAFE#defineMCPWM_INTR_ALLOC_FLAG(ESP_INTR_FLAG_SHARED|ESP_INTR_FLAG_INTRDISABLED|ESP_INTR_FLAG_IRAM)#else#defineMCPWM_INTR_ALLOC_FLAG(ESP_INTR_FLAG_SHARED|ESP_INTR_FLAG_INTRDISABLED)#endif// Use retention link only when the target supports sleep retention is enabled#defineMCPWM_USE_RETENTION_LINK(SOC_MCPWM_SUPPORT_SLEEP_RETENTION&&CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP)#defineMCPWM_ALLOW_INTR_PRIORITY_MASKESP_INTR_FLAG_LOWMED#defineMCPWM_GROUP_CLOCK_DEFAULT_PRESCALE2#defineMCPWM_PM_LOCK_NAME_LEN_MAX16typedefstructmcpwm_group_tmcpwm_group_t;typedefstructmcpwm_timer_tmcpwm_timer_t;typedefstructmcpwm_cap_timer_tmcpwm_cap_timer_t;typedefstructmcpwm_oper_tmcpwm_oper_t;typedefstructmcpwm_cmpr_tmcpwm_cmpr_t;typedefstructmcpwm_oper_cmpr_tmcpwm_oper_cmpr_t;typedefstructmcpwm_evt_cmpr_tmcpwm_evt_cmpr_t;typedefstructmcpwm_gen_tmcpwm_gen_t;typedefstructmcpwm_fault_tmcpwm_fault_t;typedefstructmcpwm_gpio_fault_tmcpwm_gpio_fault_t;typedefstructmcpwm_soft_fault_tmcpwm_soft_fault_t;typedefstructmcpwm_sync_tmcpwm_sync_t;typedefstructmcpwm_gpio_sync_src_tmcpwm_gpio_sync_src_t;typedefstructmcpwm_timer_sync_src_tmcpwm_timer_sync_src_t;typedefstructmcpwm_soft_sync_src_tmcpwm_soft_sync_src_t;typedefstructmcpwm_cap_channel_tmcpwm_cap_channel_t;structmcpwm_group_t{intgroup_id;// group ID, index from 0intintr_priority;// MCPWM interrupt prioritymcpwm_hal_context_thal;// HAL instance is at group levelportMUX_TYPEspinlock;// group level spinlockuint32_tprescale;// group prescaleuint32_tresolution_hz;// MCPWM group clock resolution: clock_src_hz / clock_prescale = resolution_hzesp_pm_lock_handle_tpm_lock;// power management locksoc_module_clk_tclk_src;// peripheral source clockmcpwm_cap_timer_t*cap_timer;// mcpwm capture timersmcpwm_timer_t*timers[SOC_MCPWM_TIMERS_PER_GROUP];// mcpwm timer arraymcpwm_oper_t*operators[SOC_MCPWM_OPERATORS_PER_GROUP];// mcpwm operator arraymcpwm_gpio_fault_t*gpio_faults[SOC_MCPWM_GPIO_FAULTS_PER_GROUP];// mcpwm fault detectors arraymcpwm_gpio_sync_src_t*gpio_sync_srcs[SOC_MCPWM_GPIO_SYNCHROS_PER_GROUP];// mcpwm gpio sync array#ifCONFIG_PM_ENABLEcharpm_lock_name[MCPWM_PM_LOCK_NAME_LEN_MAX];// pm lock name#endif}{ ... };typedefenum{MCPWM_TIMER_FSM_INIT,MCPWM_TIMER_FSM_ENABLE,}{ ... }mcpwm_timer_fsm_t;structmcpwm_timer_t{inttimer_id;// timer ID, index from 0mcpwm_group_t*group;// which group the timer belongs tomcpwm_timer_fsm_tfsm;// driver FSMportMUX_TYPEspinlock;// spin lockintr_handle_tintr;// interrupt handleuint32_tresolution_hz;// resolution of the timeruint32_tpeak_ticks;// peak ticks that the timer could reach tomcpwm_timer_sync_src_t*sync_src;// timer sync_srcmcpwm_timer_count_mode_tcount_mode;// count modemcpwm_timer_event_cb_ton_full;// callback function when MCPWM timer counts to peak valuemcpwm_timer_event_cb_ton_empty;// callback function when MCPWM timer counts to zeromcpwm_timer_event_cb_ton_stop;// callback function when MCPWM timer stopsvoid*user_data;// user data which would be passed to the timer callbacks}{ ... };typedefenum{MCPWM_TRIGGER_NO_ASSIGN,//default trigger sourceMCPWM_TRIGGER_GPIO_FAULT,//trigger assigned to gpio faultMCPWM_TRIGGER_SYNC_EVENT,//trigger assigned to sync event}{ ... }mcpwm_trigger_source_t;structmcpwm_oper_t{intoper_id;// operator ID, index from 0mcpwm_group_t*group;// which group the timer belongs tomcpwm_timer_t*timer;// which timer is connected to this operatorportMUX_TYPEspinlock;// spin lockintr_handle_tintr;// interrupt handlemcpwm_gen_t*generators[SOC_MCPWM_GENERATORS_PER_OPERATOR];// mcpwm generator arraymcpwm_oper_cmpr_t*comparators[SOC_MCPWM_COMPARATORS_PER_OPERATOR];// mcpwm operator comparator array#ifSOC_MCPWM_SUPPORT_EVENT_COMPARATORmcpwm_evt_cmpr_t*event_comparators[SOC_MCPWM_EVENT_COMPARATORS_PER_OPERATOR];// mcpwm event comparator array#endifmcpwm_trigger_source_ttriggers[SOC_MCPWM_TRIGGERS_PER_OPERATOR];// mcpwm trigger array, can be either a fault or a syncmcpwm_soft_fault_t*soft_fault;// mcpwm software faultmcpwm_operator_brake_mode_tbrake_mode_on_soft_fault;// brake mode on software triggered faultmcpwm_operator_brake_mode_tbrake_mode_on_gpio_fault[SOC_MCPWM_GPIO_FAULTS_PER_GROUP];// brake mode on GPIO triggered faultsuint32_tdeadtime_resolution_hz;// resolution of deadtime submodulemcpwm_gen_t*posedge_delay_owner;// which generator owns the positive edge delaymcpwm_gen_t*negedge_delay_owner;// which generator owns the negative edge delaymcpwm_brake_event_cb_ton_brake_cbc;// callback function which would be invoked when mcpwm operator goes into trip zonemcpwm_brake_event_cb_ton_brake_ost;// callback function which would be invoked when mcpwm operator goes into trip zonevoid*user_data;// user data which would be passed to the trip zone callback}{ ... };typedefenum{MCPWM_OPERATOR_COMPARATOR,// operator comparator, can affect generator's behaviour#ifSOC_MCPWM_SUPPORT_EVENT_COMPARATORMCPWM_EVENT_COMPARATOR,// event comparator, can only generate ETM event#endif}{ ... }mcpwm_comparator_type_t;structmcpwm_cmpr_t{intcmpr_id;// comparator ID, index from 0mcpwm_oper_t*oper;// which operator that the comparator resides inportMUX_TYPEspinlock;// spin lockuint32_tcompare_ticks;// compare value of this comparatormcpwm_comparator_type_ttype;// comparator type}{ ... };structmcpwm_oper_cmpr_t{mcpwm_cmpr_tbase;// base classintr_handle_tintr;// interrupt handlemcpwm_compare_event_cb_ton_reach;// ISR callback function which would be invoked on timer counter reaches compare valuevoid*user_data;// user data which would be passed to the comparator callbacks}{ ... };structmcpwm_evt_cmpr_t{mcpwm_cmpr_tbase;// base class}{ ... };structmcpwm_gen_t{intgen_id;// generator ID, index from 0mcpwm_oper_t*oper;// which operator that the generator resides inintgen_gpio_num;// GPIO number used by the generatorportMUX_TYPEspinlock;// spin lock}{ ... };typedefenum{MCPWM_FAULT_TYPE_GPIO,// external GPIO faultMCPWM_FAULT_TYPE_SOFT,// software fault}{ ... }mcpwm_fault_type_t;structmcpwm_fault_t{mcpwm_group_t*group;// which group the fault belongs tomcpwm_fault_type_ttype;// fault typeesp_err_t(*del)(mcpwm_fault_t*fault);}{ ... };structmcpwm_gpio_fault_t{mcpwm_fault_tbase;// base classintfault_id;// fault detector ID, index from 0intgpio_num;// GPIO number of fault detectorintr_handle_tintr;// interrupt handlemcpwm_fault_event_cb_ton_fault_enter;// ISR callback function that would be invoked when fault signal got triggeredmcpwm_fault_event_cb_ton_fault_exit;// ISR callback function that would be invoked when fault signal got clearvoid*user_data;// user data which would be passed to the isr_cb}{ ... };structmcpwm_soft_fault_t{mcpwm_fault_tbase;// base classmcpwm_oper_t*oper;// the operator where the soft fault allocated from}{ ... };typedefenum{MCPWM_SYNC_TYPE_TIMER,// sync event generated by MCPWM timer count eventMCPWM_SYNC_TYPE_GPIO,// sync event generated by GPIOMCPWM_SYNC_TYPE_SOFT,// sync event generated by software}{ ... }mcpwm_sync_src_type_t;structmcpwm_sync_t{mcpwm_group_t*group;// which group the sync_src belongs tomcpwm_sync_src_type_ttype;// sync_src typeesp_err_t(*del)(mcpwm_sync_t*sync_src);}{ ... };structmcpwm_gpio_sync_src_t{mcpwm_sync_tbase;// base classintsync_id;// sync signal IDintgpio_num;// GPIO number}{ ... };structmcpwm_timer_sync_src_t{mcpwm_sync_tbase;// base classmcpwm_timer_t*timer;// timer handle, where this sync_src allocated from}{ ... };typedefenum{MCPWM_SOFT_SYNC_FROM_NONE,// the software sync event generator has not been assignedMCPWM_SOFT_SYNC_FROM_TIMER,// the software sync event is generated by MCPWM timerMCPWM_SOFT_SYNC_FROM_CAP,// the software sync event is generated by MCPWM capture timer}{ ... }mcpwm_soft_sync_source_t;structmcpwm_soft_sync_src_t{mcpwm_sync_tbase;// base classmcpwm_soft_sync_source_tsoft_sync_from;// where the software sync event is generated byunion{mcpwm_timer_t*timer;// soft sync is generated by which MCPWM timermcpwm_cap_timer_t*cap_timer;// soft sync is generated by which MCPWM capture timer}{ ... };}{ ... };typedefenum{MCPWM_CAP_TIMER_FSM_INIT,MCPWM_CAP_TIMER_FSM_ENABLE,}{ ... }mcpwm_cap_timer_fsm_t;typedefenum{MCPWM_CAP_CHAN_FSM_INIT,MCPWM_CAP_CHAN_FSM_ENABLE,}{ ... }mcpwm_cap_channel_fsm_t;structmcpwm_cap_timer_t{mcpwm_group_t*group;// which group the capture timer belongs toportMUX_TYPEspinlock;// spin lock, to prevent concurrently accessing capture timer level resources, including registersuint32_tresolution_hz;// resolution of capture timermcpwm_cap_timer_fsm_tfsm;// driver FSMesp_pm_lock_handle_tpm_lock;// power management lockmcpwm_cap_channel_t*cap_channels[SOC_MCPWM_CAPTURE_CHANNELS_PER_TIMER];// capture channel array}{ ... };structmcpwm_cap_channel_t{intcap_chan_id;// capture channel ID, index from 0mcpwm_cap_timer_t*cap_timer;// which capture timer that the channel resides inuint32_tprescale;// prescale of capture signalintgpio_num;// GPIO number used by the channelmcpwm_cap_channel_fsm_tfsm;// driver FSMintr_handle_tintr;// Interrupt handlemcpwm_capture_event_cb_ton_cap;// Callback function which would be invoked in capture interrupt routinevoid*user_data;// user data which would be passed to the capture callback}{ ... };mcpwm_group_t*mcpwm_acquire_group_handle(intgroup_id);voidmcpwm_release_group_handle(mcpwm_group_t*group);esp_err_tmcpwm_check_intr_priority(mcpwm_group_t*group,intintr_priority);intmcpwm_get_intr_priority_flag(mcpwm_group_t*group);esp_err_tmcpwm_select_periph_clock(mcpwm_group_t*group,soc_module_clk_tclk_src);esp_err_tmcpwm_set_prescale(mcpwm_group_t*group,uint32_texpect_module_resolution_hz,uint32_tmodule_prescale_max,uint32_t*ret_module_prescale);#ifMCPWM_USE_RETENTION_LINKvoidmcpwm_create_retention_module(mcpwm_group_t*group);#endif#ifdef__cplusplus}{...}#endif
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.