Azure Sphere MT3620 M4 API Reference Manual
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Function

M-HAL PWM API list information, including PWM controller allocating and releasing, PWM hardware initializing and de-initializing, setting PWM frequency and duty cycle, enabling and disabling PWM hardware output, getting PWM frequency and duty cycle, getting the current status of PWM, enabling and disabling clock. More...

Overview

M-HAL PWM API list information, including PWM controller allocating and releasing, PWM hardware initializing and de-initializing, setting PWM frequency and duty cycle, enabling and disabling PWM hardware output, getting PWM frequency and duty cycle, getting the current status of PWM, enabling and disabling clock.

Functions

int mtk_mhal_pwm_clock_select (struct mtk_pwm_controller *ctlr)
 This function is used to select PWM clock source of the PWM controller. More...
 
int mtk_mhal_pwm_enable_clk (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to enable PWM clock before operating hardware. More...
 
int mtk_mhal_pwm_disable_clk (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to disable PWM clock. More...
 
int mtk_mhal_pwm_init (struct mtk_pwm_controller *ctlr, u32 channel_bit_map)
 This function is used to initialize the PWM hardware. More...
 
int mtk_mhal_pwm_deinit (struct mtk_pwm_controller *ctlr, u32 channel_bit_map)
 This function is used to de-initialize PWM hardware. More...
 
int mtk_mhal_pwm_set_frequency (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to set PWM frequency. More...
 
int mtk_mhal_pwm_set_duty_cycle (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to set PWM duty cycle. More...
 
int mtk_mhal_pwm_start (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to start the PWM hardware. More...
 
int mtk_mhal_pwm_stop (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to stop the PWM hardware. More...
 
int mtk_mhal_pwm_get_frequency (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to get current frequency of the PWM with the unit of frequency being Hz. More...
 
int mtk_mhal_pwm_get_duty_cycle (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to get the current duty cycle of the PWM. More...
 
int mtk_mhal_pwm_get_running_status (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to get the current status of PWM. More...
 
int mtk_mhal_pwm_feature_enable (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to select PWM global kick, IO ctrl, polarity setting. More...
 
int mtk_mhal_pwm_config_s0_s1_freq_duty (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to set PWM frequency and duty cycle in 2-state mode. More...
 
int mtk_mhal_pwm_s0_s1_stay_cycle_config (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to set PWM stay cycles of S0 and S1 in 2-state mode. More...
 
int mtk_mhal_pwm_kick (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to kick PWM hardware output waveform in 2-state mode. More...
 
int mtk_mhal_pwm_global_kick (struct mtk_pwm_controller *ctlr)
 This function is used to reset PWM hardware by group. More...
 
int mtk_mhal_pwm_dpsel (struct mtk_pwm_controller *ctlr, pwm_channels channel_num)
 This function is used to set PWM channel's differential mode. More...
 

Function Documentation

int mtk_mhal_pwm_clock_select ( struct mtk_pwm_controller ctlr)

This function is used to select PWM clock source of the PWM controller.

Usage: It must be called before operating hardware; Otherwise, it will use dPWM_EFAULT clock source.

Parameters
[in]ctlr: Abstract a PWM controller.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctlr is NULL.
int mtk_mhal_pwm_enable_clk ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to enable PWM clock before operating hardware.

Usage: It must be called to enable clock before operating hardware; otherwise, the access to PWM register will fail, so this function should be called in the sequence: alloc_controller-> enable_clk-> pwm_init.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctlr is NULL.
int mtk_mhal_pwm_disable_clk ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to disable PWM clock.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctlr is NULL.
int mtk_mhal_pwm_init ( struct mtk_pwm_controller ctlr,
u32  channel_bit_map 
)

This function is used to initialize the PWM hardware.

Usage: OS-HAL calls this API to initialize PWM hardware, and the main sequence is as bellow:
1.This function should be called after allocating the PWM controller.
2.Before operating PWM hardware, this API should be called first.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_bit_map: PWM channel bit map(0x0~0xF).
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctlr is NULL.
If return value is -PWM_EPARAMETER , it means channel_num is invalid.
int mtk_mhal_pwm_deinit ( struct mtk_pwm_controller ctlr,
u32  channel_bit_map 
)

This function is used to de-initialize PWM hardware.

Usage: OS-HAL calls this API to de-initialize PWM hardware, and this function should be called before releasing the PWM controller.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_bit_map: PWM channel bit map(0x0~0xF).
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctlr is NULL.
If return value is -PWM_EPARAMETER , it means channel_num is invalid.
int mtk_mhal_pwm_set_frequency ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to set PWM frequency.

Usage: OS-HAL calls this API to set PWM hardware at the specified frequency, and this function should be called before starting PWM hardware.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctlr is NULL.
If return value is -PWM_EPARAMETER , it means parameter invalid.
int mtk_mhal_pwm_set_duty_cycle ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to set PWM duty cycle.

Usage: OS-HAL calls this API to set PWM hardware at the specified duty cycle, and this function should be called before PWM starting.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctlr is NULL.
If return value is -PWM_EPARAMETER , it means parameter invalid.
int mtk_mhal_pwm_start ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to start the PWM hardware.

Usage: OS-HAL calls this API to start PWM hardware output waveform at the specified frequency and duty cycle, and the main sequence is as bellow:
1.This function should be called after setting the frequency.
2.This function should be called after setting the duty cycle.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctlr is NULL.
If return value is -PWM_EPARAMETER , it means channel_num is invalid.
int mtk_mhal_pwm_stop ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to stop the PWM hardware.

Usage: The main sequence is as bellow:
1.This function should be called after setting the frequency.
2.This function should be called after setting the duty cycle.
3.This function should be called before de-initializing.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctlr is NULL.
If return value is -PWM_EPARAMETER , it means channel_num is invalid.
int mtk_mhal_pwm_get_frequency ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to get current frequency of the PWM with the unit of frequency being Hz.

Usage: The duty cycle is restored in ctlr->data.current_frequency.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means parameter is NULL.
If return value is -PWM_EPARAMETER , it means parameter is invalid.
int mtk_mhal_pwm_get_duty_cycle ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to get the current duty cycle of the PWM.

Usage: The duty cycle is restored in ctlr->data.current_duty_cycle.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means parameter is NULL.
If return value is -PWM_EPARAMETER , it means parameter is invalid.
int mtk_mhal_pwm_get_running_status ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to get the current status of PWM.

Usage: The running status is restored in ctlr->data.running_status.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means parameter is NULL.
If return value is -PWM_EPARAMETER , it means parameter is invalid.
int mtk_mhal_pwm_feature_enable ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to select PWM global kick, IO ctrl, polarity setting.

Usage: It must be called to set global kick, IO ctrl, polarity in 2-state mode and this function should be called before
kicking PWM hardware output waveform.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctrl is NULL.
If return value is -PWM_EPARAMETER , it means parameter is invalid.
int mtk_mhal_pwm_config_s0_s1_freq_duty ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to set PWM frequency and duty cycle in 2-state mode.

Usage: OS-HAL calls this API to set PWM hardware frequency and duty cycle and the main sequence is as bellow:
1.This function should be called before kicking PWM hardware output waveform.
2.This function can configure frequency and duty cycle of stage S0 and S1.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctrl is NULL.
If return value is -PWM_EPARAMETER , it means parameter is invalid.
int mtk_mhal_pwm_s0_s1_stay_cycle_config ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to set PWM stay cycles of S0 and S1 in 2-state mode.

Usage: OS-HAL calls this API to set PWM stay cycles of S0 and S1.
1.This function should be called before kicking PWM hardware output waveform.
2.This function can configure stay cycles of stage S0 and S1.
3.This function can configure enable replay mode or not.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctrl is NULL.
If return value is -PWM_EPARAMETER , it means parameter is invalid.
int mtk_mhal_pwm_kick ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to kick PWM hardware output waveform in 2-state mode.

Usage: OS-HAL calls this API to kick PWM hardware output waveform by channel.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctrl is NULL.
If return value is -PWM_EPARAMETER , it means channel_num is invalid.
int mtk_mhal_pwm_global_kick ( struct mtk_pwm_controller ctlr)

This function is used to reset PWM hardware by group.

Usage: OS-HAL calls this API to reset PWM hardware by group.

Parameters
[in]ctlr: Abstract a PWM controller.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctrl is NULL.
int mtk_mhal_pwm_dpsel ( struct mtk_pwm_controller ctlr,
pwm_channels  channel_num 
)

This function is used to set PWM channel's differential mode.

Usage: After setting PWM configuration, It should be called to set PWM channel's differential mode.

Parameters
[in]ctlr: Abstract a PWM controller.
[in]channel_num: PWM channel number(0~3).
For more details about the parameter, please refer to pwm_channels.
Returns
If return value is 0, it means success.
If return value is -PWM_EPTR , it means ctrl is NULL.
If return value is -PWM_EPARAMETER , it means parameter is invalid.