136 lines
3.2 KiB
C
136 lines
3.2 KiB
C
/* os shim includes */
|
|
#include "os_types.h"
|
|
#include "dbg_io.h"
|
|
#include "iot_io.h"
|
|
#include "gpio_mtx.h"
|
|
#include "pwm.h"
|
|
#include "clk.h"
|
|
#include "gpio_hw.h"
|
|
#include "iot_gpio_api.h"
|
|
/*
|
|
Only used for testing kl1,
|
|
kl2 see dtest/kl2_pwm_test,
|
|
kl3 see dtest/dtest3/unit_test_pwm
|
|
*/
|
|
extern void clk_core_freq_150m_set();
|
|
extern int pwm_dead_band_config(uint8_t ch, uint32_t rising_db, uint32_t falling_db,
|
|
uint32_t *rising_actual, uint32_t *falling_actual);
|
|
extern void pwm_fault_config(uint8_t ch, uint8_t gpio,
|
|
uint8_t h_state, uint8_t l_state,pwm_isr cb);
|
|
|
|
uint32_t pwm_falut_cb(void)
|
|
{
|
|
iot_printf("fault\r\n");
|
|
return 0;
|
|
}
|
|
|
|
void pwm_main(void)
|
|
{
|
|
volatile uint32_t delay = 0;
|
|
uint8_t duty = 20;
|
|
uint8_t ch = PWM_CHANNEL_0;
|
|
uint8_t test_for_single_mode = 0;
|
|
|
|
uint32_t clk_freq = 0;
|
|
uint32_t period = 100;
|
|
//clk_core_freq_150m_set();
|
|
dbg_uart_init();
|
|
|
|
if (test_for_single_mode) {
|
|
pwm_single_mode_init(ch);
|
|
pwm_set_duty(ch, duty * 100);
|
|
|
|
while (1) {
|
|
/* pwm output init */
|
|
pwm_set_period(ch, 1000);
|
|
pwm_set_duty(ch, 50 * 100);
|
|
pwm_ch_init(ch);
|
|
pwm_start_for_single(ch);
|
|
|
|
iot_printf("pwm single mode running...\n");
|
|
delay = 10000000;
|
|
while(delay--);
|
|
}
|
|
} else {
|
|
|
|
uint8_t clk_table[] = {IOT_PWM_CLK_SRC_2M5, IOT_PWM_CLK_SRC_25M, IOT_PWM_CLK_SRC_50M};
|
|
pwm_init(ch);
|
|
pwm_config(ch, clk_table[0], 10000, 34, 35);
|
|
|
|
|
|
clk_freq = pwm_get_ch_clk(ch);
|
|
iot_printf("clk_freq=%d\r\n", clk_freq);
|
|
|
|
|
|
pwm_set_period(ch, 2500);
|
|
|
|
pwm_set_duty(ch, 50 * 100);
|
|
|
|
pwm_fault_config(ch, 9, 0, 0, pwm_falut_cb);
|
|
|
|
uint32_t a,b;
|
|
if( pwm_dead_band_config(ch, 2020, 600, &a, &b) < 0)
|
|
{
|
|
iot_printf("dead_band_set err\r\n");
|
|
}
|
|
|
|
int gpio_o = 28;
|
|
//hw_gpio_api_table.gpio_init();
|
|
//hw_gpio_api_table.set_gpio_mode(gpio_o, GPIO_OUTPUT);
|
|
//gpio_pin_select(gpio_o, gpio_pin_func_get(gpio_o));
|
|
//gpio_mtx_sig_out_default(0xFF, gpio_o);
|
|
|
|
|
|
while(1) {
|
|
if (0) {
|
|
hw_gpio_api_table.set_value(gpio_o, 1);
|
|
pwm_start(ch);
|
|
delay = 1000000;
|
|
while (delay--);
|
|
|
|
hw_gpio_api_table.set_value(gpio_o, 0);
|
|
pwm_stop(ch);
|
|
delay = 1000000;
|
|
while (delay--);
|
|
}
|
|
}
|
|
while(1) {
|
|
|
|
|
|
iot_printf("clk_freq=%d\r\n", clk_freq);
|
|
pwm_set_period(ch, period);
|
|
|
|
period += 100;
|
|
if (period > 1000) {
|
|
period = 100;
|
|
}
|
|
|
|
|
|
for (duty = 0; duty <= 100; duty += 5) {
|
|
pwm_set_duty(ch, duty * 100);
|
|
iot_printf("PWM Duty: %d%%\r\n",duty);
|
|
delay = 1000000;
|
|
while (delay--);
|
|
}
|
|
|
|
for (duty = 100; duty > 0; duty -= 5) {
|
|
pwm_set_duty(ch, duty * 100);
|
|
iot_printf("PWM Duty: %d%%\r\n",duty);
|
|
delay = 1000000;
|
|
while (delay--);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#ifdef __GNUC__
|
|
|
|
int main(void)
|
|
{
|
|
pwm_main();
|
|
return 0;
|
|
}
|
|
|
|
#endif // __GCC__
|
|
|