初始提交
This commit is contained in:
179
dtest/led_ctrl_test/led_ctrl_test.c
Normal file
179
dtest/led_ctrl_test/led_ctrl_test.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/****************************************************************************
|
||||
|
||||
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
||||
|
||||
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
||||
be copied by any method or incorporated into another program without
|
||||
the express written consent of Aerospace C.Power. This Information or any portion
|
||||
thereof remains the property of Aerospace C.Power. The Information contained herein
|
||||
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
||||
liability for its use in any way and conveys no license or title under
|
||||
any patent or copyright and makes no representation or warranty that this
|
||||
Information is free from patent or copyright infringement.
|
||||
|
||||
****************************************************************************/
|
||||
#include "os_utils.h"
|
||||
#include "chip_reg_base.h"
|
||||
#include "hw_reg_api.h"
|
||||
#include "ahb.h"
|
||||
#include "gpio_mtx.h"
|
||||
#include "iot_led.h"
|
||||
#include "ledc.h"
|
||||
#include "sec_glb.h"
|
||||
#include "iot_io.h"
|
||||
#include "dbg_io.h"
|
||||
|
||||
#define REG32(a) (*((volatile uint32_t *)(a)))
|
||||
|
||||
void gpio_sel()
|
||||
{
|
||||
gpio_mtx_enable();
|
||||
gpio_sig_info_t sfc = {
|
||||
2,
|
||||
{
|
||||
{IO_TYPE_OUT, 0, 0, 0xff, 49},
|
||||
{IO_TYPE_OUT, 0, 1, 0xff, 50},
|
||||
}
|
||||
};
|
||||
gpio_module_pin_select(&sfc);
|
||||
gpio_module_sig_select(&sfc, GPIO_MTX_MODE_MATRIX);
|
||||
|
||||
// gpio output inv
|
||||
gpio_pin_oinv(1, 1);
|
||||
gpio_pin_oinv(0, 1);
|
||||
}
|
||||
|
||||
void led_ctrl_test()
|
||||
{
|
||||
ledc_ena_rst();
|
||||
|
||||
//set l2h value
|
||||
ledc_set_l2h_val(0, 0x00);
|
||||
|
||||
// config target
|
||||
ledc_target_cfg(0, 1, 0, 1, 1, 0);
|
||||
ledc_target_value(0, 0x100);
|
||||
|
||||
// set timer
|
||||
ledc_timer_cfg(0, 0, 0, 0, 0x20000, 11);
|
||||
|
||||
// conf ledc
|
||||
ledc_cfg(0, 0, 1, 0);
|
||||
}
|
||||
|
||||
void led_ctrl_test2()
|
||||
{
|
||||
iot_led_init();
|
||||
volatile int i = 0;
|
||||
iot_led_blink(0, 1);
|
||||
int count = 0;
|
||||
iot_led_blink(0, 1);
|
||||
while(1) {
|
||||
for(i = 0; i< 1000000; i++);
|
||||
count++;
|
||||
if (count > 10) {
|
||||
iot_led_off(1);
|
||||
} else if (count > 5) {
|
||||
iot_printf("turn off\n");
|
||||
iot_led_off(0);
|
||||
} else if (count > 3) {
|
||||
iot_printf("count %d\n", count);
|
||||
iot_led_blink(1, 1);
|
||||
REG32(0x44007048) = 0x80;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void led_ctrl_test3()
|
||||
{
|
||||
volatile int i = 0;
|
||||
|
||||
int count = 0;
|
||||
iot_led_off(1);
|
||||
while(1) {
|
||||
for(i = 0; i< 10000000; i++);
|
||||
count++;
|
||||
if (count > 20) {
|
||||
count = 0;
|
||||
} else if (count > 10) {
|
||||
iot_led_on(0);
|
||||
} else if (count > 5) {
|
||||
iot_printf("turn off\n");
|
||||
iot_led_off(0);
|
||||
} else if (count > 3) {
|
||||
REG32(0x44007048) = 0x80;
|
||||
}
|
||||
iot_led_blink(1, 1);
|
||||
iot_printf("count %d\n", count);
|
||||
}
|
||||
}
|
||||
|
||||
void led_ctrl_test4()
|
||||
{
|
||||
iot_led_blink(0, 1);
|
||||
}
|
||||
|
||||
void led_ctrl_test5()
|
||||
{
|
||||
|
||||
//iot_led_light(0, 1000);
|
||||
}
|
||||
|
||||
void led_ctrl_test_kl2()
|
||||
{
|
||||
ledc_ena_rst();
|
||||
|
||||
// config timer, timer0 for led0, timer1 for led1, timer2 for reference led
|
||||
ledc_timer_cfg(0, 0, 0, 0, 0x10000, 5);
|
||||
ledc_timer_cfg(1, 0, 0, 0, 0x10000, 5);
|
||||
ledc_timer_cfg(2, 0, 0, 0, 0x10001, 5);
|
||||
|
||||
#if 1 // enable reference led clock
|
||||
ledc_set_l2h_val(8, 0);
|
||||
ledc_target_value(8, 0xa0);
|
||||
ledc_target_cfg(8, LED_TARGET_SHADOW_ENA, LED_TARGET_DEC, 8, 1, 2);
|
||||
// led config
|
||||
ledc_cfg(8, 1, 1, 2);
|
||||
#endif
|
||||
|
||||
#if 1 // enable test led0
|
||||
ledc_set_l2h_val(0, 0);
|
||||
ledc_target_value(0, 0xa0);
|
||||
ledc_target_cfg(0, LED_TARGET_SHADOW_ENA, LED_TARGET_DEC, 0, 1, 1);
|
||||
ledc_cfg(0, 0, 1, 0);
|
||||
|
||||
// use reference led
|
||||
ledc_out_ref(0, 1);
|
||||
#endif
|
||||
|
||||
#if 1 // enable test led1
|
||||
ledc_set_l2h_val(1, 0);
|
||||
ledc_target_value(1, 0xa0);
|
||||
ledc_target_cfg(1, LED_TARGET_SHADOW_ENA, LED_TARGET_DEC, 0, 1, 1);
|
||||
ledc_cfg(1, 0, 1, 1);
|
||||
|
||||
// use reference led
|
||||
ledc_out_ref(1, 1);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
dbg_uart_init();
|
||||
gpio_sel();
|
||||
iot_printf("test led\n");
|
||||
#if 0 // kunlun1
|
||||
iot_led_init();
|
||||
//led_ctrl_test();
|
||||
//led_ctrl_test2();
|
||||
//led_ctrl_test3();
|
||||
//led_ctrl_test4();
|
||||
//led_ctrl_test5();
|
||||
#else // kunlun2
|
||||
led_ctrl_test_kl2();
|
||||
#endif
|
||||
iot_printf("end.......\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user