【BLE】TLSR8258開發記錄之6--添加自定義定時任務

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的頻率閃爍

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章