DA14580 --- 如何创建一个任务

1.目的

     分析代码程序是如何执行开启广播的

2.分析


3.平台:

协议栈版本:DA1458x_SDK5.0.2

编译软件:keil 4.72

硬件平台:开发板

例子:DA1458x_SDK5.0.3\DA1458x_SDK5.0.3\DA1458x_SDK\5.0.3\projects\target_apps\ble_examples\prox_reporter\Keil_4

4.步骤

  1.在include"app_task.c"中

  

/* Default State handlers definition. */
const struct ke_msg_handler app_default_state[] =
{   
    {KE_MSG_DEFAULT_HANDLER,                (ke_msg_func_t)app_entry_point_handler},
    {APP_TIMER_API_MES1,                    (ke_msg_func_t)app_second_timer_handler}, //创建一个 定时器任务
};

在APP_TIMER_API_MES1 的定义  在app.h中  可以修改

/*
 * TYPE DEFINITIONS
 ****************************************************************************************
 */

/// APP Task messages
enum APP_MSG
{
    APP_MODULE_INIT_CMP_EVT = KE_FIRST_MSG(TASK_APP),
    
#if BLE_PROX_REPORTER
    APP_PXP_TIMER,
#endif //BLE_PROX_REPORTER

#if BLE_BAS_SERVER
    APP_BATT_TIMER,
    APP_BATT_ALERT_TIMER,
#endif //BLE_BAS_SERVER

#if HAS_MULTI_BOND
    APP_ALT_PAIR_TIMER,
#endif //HAS_MULTI_BOND

    APP_CREATE_NEW_TIMER,
    APP_CANCEL_TIMER,
    //Do not alter the order of the next messages 
    //they are considered a range
	  
    APP_TIMER_API_MES0,
    APP_TIMER_API_MES1=APP_TIMER_API_MES0+1,
    APP_TIMER_API_MES2=APP_TIMER_API_MES0+2,
    APP_TIMER_API_MES3=APP_TIMER_API_MES0+3,   APP_TIMER_API_MES4=APP_TIMER_API_MES0+4,
    APP_TIMER_API_MES5=APP_TIMER_API_MES0+5,
    APP_TIMER_API_MES6=APP_TIMER_API_MES0+6,
    APP_TIMER_API_MES7=APP_TIMER_API_MES0+7,
    APP_TIMER_API_MES8=APP_TIMER_API_MES0+8,
    APP_TIMER_API_MES9=APP_TIMER_API_MES0+9,
    APP_TIMER_API_LAST_MES=APP_TIMER_API_MES9,
    
    APP_MSG_UTIL_API_MES0,
    APP_MSG_UTIL_API_MES1=APP_MSG_UTIL_API_MES0+1,
    APP_MSG_UTIL_API_MES2=APP_MSG_UTIL_API_MES0+2,
    APP_MSG_UTIL_API_MES3=APP_MSG_UTIL_API_MES0+3,
    APP_MSG_UTIL_API_MES4=APP_MSG_UTIL_API_MES0+4,
    APP_MSG_UTIL_API_LAST_MES=APP_MSG_UTIL_API_MES4

};

2.创建一个文件夹,如下所示:

 DA14580 --- 如何创建一个任务_第1张图片

custom_task.c内容如下

#include "app.h"

#define GPIO_LED1_PORT  GPIO_PORT_1
#define GPIO_LED1_PIN   GPIO_PIN_0

void  Led_init(void)
{
		GPIO_ConfigurePin(GPIO_LED1_PORT,GPIO_LED1_PIN,OUTPUT,PID_GPIO,false);
}


int app_second_timer_handler(ke_msg_id_t const msgid,
                                   void const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id){
	static bool  flag = 0 ;
	if(flag == 0)
	{
	 flag = 1 ;
   GPIO_SetActive  (GPIO_LED1_PORT,GPIO_LED1_PIN);
	}
	else
	{
	 flag = 0 ;
   GPIO_SetInactive(GPIO_LED1_PORT,GPIO_LED1_PIN);
	}
	// while(1);
	app_timer_set(APP_TIMER_API_MES1,TASK_APP,100);	
}	

#include"custom_task.h"内容如下

#ifndef __led__h
#define __led__h



#include "app_easy_timer.h"


void  Led_timer_init(void);
void  Led_init(void);

int app_second_timer_handler(ke_msg_id_t const msgid,
                                   void const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id);







#endif

3.在usar_periph_setup.c里面

#include "rwip_config.h"             // SW configuration
#include "user_periph_setup.h"            // periphera configuration
#include "global_io.h"
#include "gpio.h"
#include "uart.h"                    // UART initialization

#include "user_proxr.h"

#include "custom_task.h" //加入头文件
在外设初始化函数中

void GPIO_reservations(void)
{

/*
* Application specific GPIOs reservation
*/    
#if BLE_PROX_REPORTER
    #if USE_PUSH_BUTTON
    RESERVE_GPIO( PUSH_BUTTON, GPIO_BUTTON_PORT, GPIO_BUTTON_PIN, PID_GPIO);   
    #endif // USE_PUSH_BUTTON
    RESERVE_GPIO( GREEN_LED, GPIO_ALERT_LED_PORT, GPIO_ALERT_LED_PIN, PID_GPIO);
#endif
#if BLE_BAS_SERVER && USE_BAT_LEVEL_ALERT
	//Setup LED GPIO for battery alert
    RESERVE_GPIO( RED_LED, GPIO_BAT_LED_PORT, GPIO_BAT_LED_PIN, PID_GPIO);
#endif    
#if (BLE_SPOTA_RECEIVER)

    #if !defined(__DA14583__)
    RESERVE_GPIO(SPI_EN,  SPI_EN_GPIO_PORT,  SPI_EN_GPIO_PIN,  PID_SPI_EN);
    RESERVE_GPIO(SPI_CLK, SPI_CLK_GPIO_PORT, SPI_CLK_GPIO_PIN, PID_SPI_CLK);
    RESERVE_GPIO(SPI_DO,  SPI_DO_GPIO_PORT,  SPI_DO_GPIO_PIN,  PID_SPI_DO);
    RESERVE_GPIO(SPI_DI,  SPI_DI_GPIO_PORT,  SPI_DI_GPIO_PIN,  PID_SPI_DI);
    #else
        // The DA14583 GPIOs that are dedicated to its internal SPI flash
        // are automaticaly reserved by the GPIO driver.
    #endif   
    // Example GPIO reservations for an I2C EEPROM.
    //RESERVE_GPIO( I2C_SCL, GPIO_PORT_0, GPIO_PIN_2, PID_I2C_SCL);
    //RESERVE_GPIO( I2C_SDA, GPIO_PORT_0, GPIO_PIN_3, PID_I2C_SDA);
#endif
    Led_init();   //添加led灯初始化函数
}
#endif

4.在#include "app_default_handlers.h"中找到广播开始函数 开启定时的led的事件

/**
 ****************************************************************************************
 * @brief The advertise operation used by the rest of default handlers.
 * @return None.
 ****************************************************************************************
 */
void default_advertise_operation(void)
{
        if (user_default_hnd_conf.adv_scenario==DEF_ADV_FOREVER)
            app_easy_gap_undirected_advertise_start();
        else if (user_default_hnd_conf.adv_scenario==DEF_ADV_WITH_TIMEOUT)
            app_easy_gap_undirected_advertise_with_timeout_start(user_default_hnd_conf.advertise_period,NULL);
				app_timer_set(APP_TIMER_API_MES1,TASK_APP,100); //开启led时间函数
}

这样 过来100*10ms就会跳到app_second_timer_handler函数了。

函数里面开始了led等闪烁。







你可能感兴趣的:(DA14580)