HPM APP
HPMicro Application solution
mp_pwm.c File Reference
#include "board.h"
#include "hpm_pwm_drv.h"
#include "hpm_trgm_drv.h"
#include "hpm_synt_drv.h"
#include "hpm_clock_drv.h"
#include "mp_api.h"
#include "mp_pwm.h"

Macros

#define MP_PWM_SHADOW_CMP   (15)
 
#define MP_PWM_FAULT_CMP   (14)
 
#define MP_PWM_PAIR_MAP_CTX   pwm_pair_map_t
 
#define MP_PWM_PAIR_MAP_COUNT   pwm_pair_map_count
 
#define PWM_PAIR_INDEX   pwm_pair_t->pwm_pair_index
 
#define PWM_PAIR_MAP_INDEX   pwm_pair_t->pwm_map_index
 
#define PWM_PAIR_BASE   MP_PWM_PAIR_MAP_CTX[PWM_PAIR_MAP_INDEX].pwm_x
 
#define PWM_PAIR_CMP   MP_PWM_PAIR_MAP_CTX[PWM_PAIR_MAP_INDEX].cmp
 
#define PWM_PAIR_PIN   MP_PWM_PAIR_MAP_CTX[PWM_PAIR_MAP_INDEX].pin
 
#define PWM_PAIR_TRIG_CMP   MP_PWM_PAIR_MAP_CTX[PWM_PAIR_MAP_INDEX].pwm_trigger_map[MP_PWM_TRIGGER_ADC_BIT].trgm_cmp
 
#define PWM_PAIR_TRIG_PIN   MP_PWM_PAIR_MAP_CTX[PWM_PAIR_MAP_INDEX].pwm_trigger_map[MP_PWM_TRIGGER_ADC_BIT].trgm_pin
 
#define MP_PWM_MAP_CTX   pwm_map_t
 
#define MP_PWM_MAP_COUNT   pwm_map_count
 
#define PWM_INDEX   pwm_t->pwm_index
 
#define PWM_MAP_INDEX   pwm_t->pwm_map_index
 
#define PWM_BASE   MP_PWM_MAP_CTX[PWM_MAP_INDEX].pwm_x
 
#define PWM_CMP   MP_PWM_MAP_CTX[PWM_MAP_INDEX].cmp
 
#define PWM_PIN   MP_PWM_MAP_CTX[PWM_MAP_INDEX].pin
 
#define PWM_TRIG_CMP   MP_PWM_MAP_CTX[PWM_MAP_INDEX].pwm_trigger_map[MP_PWM_TRIGGER_ADC_BIT].trgm_cmp
 
#define PWM_TRIG_PIN   MP_PWM_MAP_CTX[PWM_MAP_INDEX].pwm_trigger_map[MP_PWM_TRIGGER_ADC_BIT].trgm_pin
 

Functions

static void isr_pwm0 (void)
 
static void isr_pwm1 (void)
 
uint8_t mp_pwm_pair_get_mapindex (uint8_t pair_index)
 Get the PWM MAP index number of a pair of PWM ;获取PWM对 MAP数组序号 More...
 
uint8_t mp_pwm_get_mapindex (uint8_t index)
 Get the PWM MAP index number of the PWM ;获取PWM MAP数组序号 More...
 
uint32_t mp_pwm_pair_get_busfreq (uint8_t pair_index)
 Get the bus frequency of a pair of PWM ;获取PWM对总线频率 More...
 
uint32_t mp_pwm_get_busfreq (uint8_t index)
 Get the bus frequency of the PWM ;获取PWM总线频率 More...
 
uint32_t mp_pwm_pair_get_reload (uint8_t pair_index, uint32_t freq)
 Get the reload_count of a pair of PWM ;获取PWM对重载值reload_count. More...
 
uint32_t mp_pwm_get_reload (uint8_t index, uint32_t freq)
 Get the reload_count of the PWM ;获取PWM重载值reload_count. More...
 
int mp_pwm_pair_config (hpm_pwm_pair_t *pwm_pair_t)
 A pair of PWM init config
;PWM对初始配置 More...
 
int mp_pwm_config (hpm_pwm_t *pwm_t)
 PWM init config ;PWM初始配置 More...
 
int mp_pwm_pair_output_enable (hpm_pwm_pair_t *pwm_pair_t, bool enable)
 Enable a pair of PWM waveform outputs ;PWM对波形输出使能 More...
 
int mp_pwm_output_enable (hpm_pwm_t *pwm_t, bool enable)
 Enable the PWM waveform outputs ;PWM波形输出使能 More...
 
int mp_pwm_enable_counter (hpm_pwm_t *pwm_t, bool enable)
 The PWM counter enables counting ;PWM计数器使能计数 More...
 
int hpm_mp_api_pwmpair_force_config (hpm_pwm_pair_t *pwm_pair_t, uint8_t index, uint8_t level)
 Setting forced output for a pair of PWM (setting a pair of PWM signals to high or low level) Note: This interface is for configuration only and does not enable the active state. Enable or disable the following interfaces separately Enable (force output to be high or low level) hpm_mp_api_pwmpair_force_enable_output Disable (Restore PWM waveform) hpm_mp_api_pwmpair_force_disable_output ;PWM对强制输出设置(将PWM对强制设置为高电平或低电平) 注意: 此接口只是配置,并不会使能生效状态,使能或禁止需单独调用以下接口 使能生效(强制输出为高或低) hpm_mp_api_pwmpair_force_enable_output 禁止生效(恢复PWM波形) hpm_mp_api_pwmpair_force_disable_output. More...
 
int hpm_mp_api_pwm_force_config (hpm_pwm_t *pwm_t, uint8_t level)
 Setting forced output for the PWM (setting the PWM signal to high or low level) Note: This interface is for configuration only and does not enable the active state. Enable or disable the following interfaces separately Enable (force output to be high or low level) hpm_mp_api_pwm_force_enable_output Disable (Restore PWM waveform) hpm_mp_api_pwm_force_disable_output ;PWM强制输出设置(将PWM强制设置为高电平或低电平) 注意: 此接口只是配置,并不会使能生效状态,使能或禁止需单独调用以下接口 使能生效(强制输出为高或低) hpm_mp_api_pwm_force_enable_output 禁止生效(恢复PWM波形) hpm_mp_api_pwm_force_disable_output. More...
 
void hpm_mp_api_pwmpair_force_enable_output (hpm_pwm_pair_t *pwm_pair_t, uint8_t index)
 Enable a pair of PWM signals forced outputs (force output to be high or low level) ;PWM对强制输出使能生效(强制输出为高或低) More...
 
void hpm_mp_api_pwm_force_enable_output (hpm_pwm_t *pwm_t)
 Enable the PWM signal forced outputs (force output to be high or low level) ;PWM强制输出使能生效(强制输出为高或低) More...
 
void hpm_mp_api_pwmpair_force_disable_output (hpm_pwm_pair_t *pwm_pair_t, uint8_t index)
 Disable a pair of PWM signals forced outputs(Restore PWM waveform) ;PWM对强制输出禁止生效(恢复PWM波形) More...
 
void hpm_mp_api_pwm_force_disable_output (hpm_pwm_t *pwm_t)
 Disable the PWM signal forced outputs(Restore PWM waveform)
;PWM强制输出禁止生效(恢复PWM波形) More...
 
int mp_pwm_fault_mux_config (uint8_t type, void *handle)
 PWM TRGM for fault protection ;PWM故障保护互联配置 More...
 
void hpm_mp_api_pwmpair_fault_software_clear (hpm_pwm_pair_t *pwm_pair_t)
 A pair of PWM fault states are cleared by software Note: When the fault recovery is set to software recovery, use this interface to clear the fault status after confirming fault clearance. ;PWM对故障状态软件清除 注意: 当故障恢复设置为软件恢复后,在确认故障清除后,使用此接口清除故障状态 More...
 
void hpm_mp_api_pwm_fault_software_clear (hpm_pwm_t *pwm_t)
 The PWM fault states are cleared by software Note: When the fault recovery is set to software recovery, use this interface to clear the fault status after confirming fault clearance. ;PWM故障状态软件清除 注意: 当故障恢复设置为软件恢复后,在确认故障清除后,使用此接口清除故障状态 More...
 
int mp_pwm_trigger_mux_config (uint8_t type, void *handle)
 PWM TRGM (trigger ADC sampling at a specific moment during PWM, etc) ;PWM互联触发配置(PWM某一时刻触发ADC采样等) More...
 
const mp_pwm_trigger_map_tmp_pwm_get_trigger_map (uint8_t type, uint8_t index)
 Get the PWM TRGM for MAP table ;获取PWM互联触发MAP表 More...
 
int mp_pwm_sync_config (hpm_mp_t *mp_t)
 PWM synchronous configuration Note: PWM synchronization only supports different PWM controllers ;PWM同步配置 注意: PWM同步只支持不同的PWM控制器 More...
 
static hpm_stat_t pwm_update_raw_cmp_central_aligned_t (PWM_Type *pwm_x, uint8_t cmp1_index, uint8_t cmp2_index, uint32_t target_cmp1, uint32_t target_cmp2)
 
static int mp_pwm_pair_duty_convert (hpm_pwm_pair_t *pwm_pair_t, uint32_t o_duty_array[4])
 
uint32_t hpm_mp_api_pwmpair_get_reload_of_freq (hpm_pwm_pair_t *pwm_pair_t, uint32_t freq)
 A pair of PWM gets the overloaded value 'reload_count' based on frequency ;PWM对根据频率获取重载值reload_count. More...
 
int hpm_mp_api_pwmpair_set_reload_and_duty (hpm_pwm_pair_t *pwm_pair_t, uint32_t reload_count, uint32_t duty_count)
 A pair of PWM, configured frequency and duty cycle Note: Get reload_count by frequency first,by using hpm_mp_api_pwmpair_get_reload_of_freq ;PWM对同时设置频率和占空比; 注意: 先通过频率获取reload_count,调用 hpm_mp_api_pwmpair_get_reload_of_freq 接口获取 More...
 
int hpm_mp_api_pwmpair_freq (hpm_pwm_pair_t *pwm_pair_t, uint32_t freq)
 A pair of PWM frequency Settings; Note: After setting the frequency, the duty cycle automatically converts to the original percentage. For example, with a 20% duty cycle, after setting the frequency, the duty cycle remains at 20% ;PWM对频率设置; 注意: 设置频率后,占空比自动转换为原始百分比。如:20占空比,设置频率后,占空比仍然为20%. More...
 
int hpm_mp_api_pwmpair_freq_of_half_duty (hpm_pwm_pair_t *pwm_pair_t, uint32_t freq)
 Setting the frequency for a pair of PWM and configuring a 50% duty cycle Note: After setting the frequency, the duty cycle is simultaneously set to 50% ;PWM对频率设置且固定半占空比 注意: 设置频率后,占空比同时设置为50%. More...
 
int hpm_mp_api_pwm_freq (hpm_pwm_t *pwm_t, uint32_t freq)
 PWM frequency Settings; Note: After setting the frequency, the duty cycle automatically converts to the original percentage. For example, with a 20% duty cycle, after setting the frequency, the duty cycle remains at 20% ;PWM频率设置; 注意: 设置频率后,占空比自动转换为原始百分比。如:20占空比,设置频率后,占空比仍然为20%. More...
 
int hpm_mp_api_pwm_freq_of_half_duty (hpm_pwm_t *pwm_t, uint32_t freq)
 Setting the frequency for the PWM and configuring a 50% duty cycle Note: After setting the frequency, the duty cycle is simultaneously set to 50% ;PWM频率设置且固定半占空比 注意: 设置频率后,占空比同时设置为50%. More...
 
int hpm_mp_api_pwmpair_duty (hpm_pwm_pair_t *pwm_pair_t, uint32_t duty)
 A pair of PWM duty cycle Settings Note: The duty cycle ranges from 0 to reload_count(reload_count is a member of pwm_pair_t) ;PWM对占空比设置 注意: 占空比范围为0~reload_count(reload_count为pwm_pair_t成员) More...
 
int hpm_mp_api_pwm_duty (hpm_pwm_t *pwm_t, uint32_t duty)
 The PWM duty cycle Settings Note: The duty cycle ranges from 0 to reload_count(reload_count is a member of pwm_pair_t) ;PWM占空比设置 注意: 占空比范围为0~reload_count(reload_count为pwm_t成员) More...
 
int hpm_mp_api_pwm_pair_trig_set_duty (hpm_pwm_pair_t *pwm_pair_t, uint32_t duty)
 Setting the duty cycle for a pair of PWM signals that trigger ADC sampling moments Note: Duty cycle ranges from 0 to reload_count(pwm_t) ;PWM对触发ADC采样时刻占空比设置 注意: 占空比范围为0~reload_count(pwm_pair_t) More...
 
int hpm_mp_api_pwm_trig_set_duty (hpm_pwm_t *pwm_t, uint32_t duty)
 Setting the duty cycle for the PWM signal that trigger ADC sampling moments Note: Duty cycle ranges from 0 to reload_count(pwm_t) ;PWM 触发ADC采样时刻占空比设置 注意: 占空比范围为0~reload_count(pwm_t) More...
 
int hpm_mp_api_pwm_pair_set_deadzone (hpm_pwm_pair_t *pwm_pair_t, uint32_t start_halfcycle, uint32_t end_halfcycle)
 A pair of PWM dead zone Settings ;PWM对前后死区设置 More...
 
int hpm_mp_api_dma_request_enable (bool enable, uint8_t type, void *handle)
 PWM DMA enable ;PWM DMA请求使能 More...
 
void hpm_mp_api_pair_pwm_io_init (uint8_t pair_index)
 A pair of PWM IO init ;PWM 对 IO初始化 More...
 
void hpm_mp_api_pwm_io_init (uint8_t index)
 PWM IO init ;PWM IO初始化 More...
 
int hpm_mp_api_pwm_pair_set_map (const mp_pwm_pair_map_t *map_t, int count)
 Settings for a pair of PWM MAP ;PWM对 MAP设置 More...
 
int hpm_mp_api_pwm_set_map (const mp_pwm_map_t *map_t, int count)
 Settings for the PWM MAP ;PWM MAP设置 More...
 

Variables

static const mp_pwm_pair_map_tpwm_pair_map_t = NULL
 
static uint32_t pwm_pair_map_count = 0
 
static volatile uint8_t mp_sync_done = 0
 
static uint32_t sync_time_max = 0
 
static const mp_pwm_map_tpwm_map_t = NULL
 
static uint32_t pwm_map_count = 0
 

Macro Definition Documentation

◆ MP_PWM_FAULT_CMP

#define MP_PWM_FAULT_CMP   (14)

◆ MP_PWM_MAP_COUNT

#define MP_PWM_MAP_COUNT   pwm_map_count

◆ MP_PWM_MAP_CTX

#define MP_PWM_MAP_CTX   pwm_map_t

◆ MP_PWM_PAIR_MAP_COUNT

#define MP_PWM_PAIR_MAP_COUNT   pwm_pair_map_count

◆ MP_PWM_PAIR_MAP_CTX

#define MP_PWM_PAIR_MAP_CTX   pwm_pair_map_t

◆ MP_PWM_SHADOW_CMP

#define MP_PWM_SHADOW_CMP   (15)

◆ PWM_BASE

#define PWM_BASE   MP_PWM_MAP_CTX[PWM_MAP_INDEX].pwm_x

◆ PWM_CMP

#define PWM_CMP   MP_PWM_MAP_CTX[PWM_MAP_INDEX].cmp

◆ PWM_INDEX

#define PWM_INDEX   pwm_t->pwm_index

◆ PWM_MAP_INDEX

#define PWM_MAP_INDEX   pwm_t->pwm_map_index

◆ PWM_PAIR_BASE

#define PWM_PAIR_BASE   MP_PWM_PAIR_MAP_CTX[PWM_PAIR_MAP_INDEX].pwm_x

◆ PWM_PAIR_CMP

#define PWM_PAIR_CMP   MP_PWM_PAIR_MAP_CTX[PWM_PAIR_MAP_INDEX].cmp

◆ PWM_PAIR_INDEX

#define PWM_PAIR_INDEX   pwm_pair_t->pwm_pair_index

◆ PWM_PAIR_MAP_INDEX

#define PWM_PAIR_MAP_INDEX   pwm_pair_t->pwm_map_index

◆ PWM_PAIR_PIN

#define PWM_PAIR_PIN   MP_PWM_PAIR_MAP_CTX[PWM_PAIR_MAP_INDEX].pin

◆ PWM_PAIR_TRIG_CMP

#define PWM_PAIR_TRIG_CMP   MP_PWM_PAIR_MAP_CTX[PWM_PAIR_MAP_INDEX].pwm_trigger_map[MP_PWM_TRIGGER_ADC_BIT].trgm_cmp

◆ PWM_PAIR_TRIG_PIN

#define PWM_PAIR_TRIG_PIN   MP_PWM_PAIR_MAP_CTX[PWM_PAIR_MAP_INDEX].pwm_trigger_map[MP_PWM_TRIGGER_ADC_BIT].trgm_pin

◆ PWM_PIN

#define PWM_PIN   MP_PWM_MAP_CTX[PWM_MAP_INDEX].pin

◆ PWM_TRIG_CMP

#define PWM_TRIG_CMP   MP_PWM_MAP_CTX[PWM_MAP_INDEX].pwm_trigger_map[MP_PWM_TRIGGER_ADC_BIT].trgm_cmp

◆ PWM_TRIG_PIN

#define PWM_TRIG_PIN   MP_PWM_MAP_CTX[PWM_MAP_INDEX].pwm_trigger_map[MP_PWM_TRIGGER_ADC_BIT].trgm_pin

Function Documentation

◆ isr_pwm0()

static void isr_pwm0 ( void  )
static

◆ isr_pwm1()

static void isr_pwm1 ( void  )
static

◆ mp_pwm_pair_duty_convert()

static int mp_pwm_pair_duty_convert ( hpm_pwm_pair_t pwm_pair_t,
uint32_t  o_duty_array[4] 
)
static

◆ pwm_update_raw_cmp_central_aligned_t()

static hpm_stat_t pwm_update_raw_cmp_central_aligned_t ( PWM_Type *  pwm_x,
uint8_t  cmp1_index,
uint8_t  cmp2_index,
uint32_t  target_cmp1,
uint32_t  target_cmp2 
)
static

Variable Documentation

◆ mp_sync_done

volatile uint8_t mp_sync_done = 0
static

◆ pwm_map_count

uint32_t pwm_map_count = 0
static

◆ pwm_map_t

const mp_pwm_map_t* pwm_map_t = NULL
static

◆ pwm_pair_map_count

uint32_t pwm_pair_map_count = 0
static

◆ pwm_pair_map_t

const mp_pwm_pair_map_t* pwm_pair_map_t = NULL
static

◆ sync_time_max

uint32_t sync_time_max = 0
static