1、说明
基于 SDKV3.4 添加自定义定时任务
2、操作
A.首先开启软件定时器宏定义,在blt_soft_timer.h中,将BLT_SOFTWARE_TIMER_ENABLE定义为1
并且添加头文件timer.h
#include "../../drivers/8258/timer.h"
//user define
#ifndef BLT_SOFTWARE_TIMER_ENABLE
#define BLT_SOFTWARE_TIMER_ENABLE 1 //enable or disable
#endif
在tl_commom.h中添加头文件
#include "vendor/common/blt_soft_timer.h"
B.在app.c文件中添加定时任务(此处为LED定时亮灭)
//MG add
int test0()
{
gpio_toggle(GPIO_PD2);
return 0;
}
int test1()
{
gpio_toggle(GPIO_PD3);
return 0;
}
int test2()
{
gpio_toggle(GPIO_PD4);
return 0;
}
在user_init_noamal函数中添加定时器初始化
blt_soft_timer_init();
blt_soft_timer_add(&test0,200000);
blt_soft_timer_add(&test1,100000);
blt_soft_timer_add(&test2,500000);
C.在main.c文件中添加GPIO初始化`
//MG add
void MG_GPIO_Init(void)
{
gpio_set_func(GPIO_PD2,AS_GPIO);
gpio_set_output_en(GPIO_PD2,1);
gpio_write(GPIO_PD2,0);
gpio_set_func(GPIO_PD3,AS_GPIO);
gpio_set_output_en(GPIO_PD3,1);
gpio_write(GPIO_PD3,0);
gpio_set_func(GPIO_PD4,AS_GPIO);
gpio_set_output_en(GPIO_PD4,1);
gpio_write(GPIO_PD4,0);
}
在main函数中添加GPIO初始化
MG_GPIO_Init();
D.在app.c文件中添加计数变量
u32 tick_loop = 0;
在main_loop函数中添加
tick_loop++;
blt_soft_timer_process(CALLBACK_ENTRY);
3、现象
程序烧录后,可见D1以200ms的频率闪烁、D2以100ms的频率闪烁、D3以500ms的频率闪烁