其实说移植,更确切说是完善DEMO Code,因为官方已经有一个ble_app_template_freertos的demo code了,为了方便测试功耗已经功能的运行.
1.打开工程
工程的目录结构还算简洁
2.为了简化测试,先将程序瘦身,其中?print_test_task只留了一个延时,vStartTasks只创建print_task任务
static void print_test_task(void *p_arg)
{
while (1)
{
// app_rtc_get_time(&g_calendar_time);
// APP_LOG_INFO("TickCount: %d, Time: %02d/%02d %02d:%02d:%02d.%03d\r\n",
// xTaskGetTickCount(),
// g_calendar_time.mon, g_calendar_time.date,
// g_calendar_time.hour, g_calendar_time.min, g_calendar_time.sec, g_calendar_time.ms);
// app_log_flush();
vTaskDelay(2000);
}
}
/**
*****************************************************************************************
* @brief To create two task, the one is ble-schedule, another is watcher task
*****************************************************************************************
*/
static void vStartTasks(void *arg)
{
// system_pmu_calibration_start();
// app_calendar_init();
xTaskCreate(print_test_task, "print_task", APP_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
// xTaskCreate(dfu_schedule_task, "dfu_schedule_task", DFU_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, NULL);
#if APP_LOG_STORE_ENABLE
xTaskCreate(log_store_dump_task, "log_store_dump_task", LOG_STORE_DUMP_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 3, NULL);
#endif
vTaskDelete(NULL);
}
需要注意修改以下宏定义
// <o> Eanble APP log module
// <0=> DISABLE
// <1=> ENABLE
#ifndef APP_LOG_ENABLE
#define APP_LOG_ENABLE 0//1
#endif
// <o> Enable BLE DFU support
// <0=> DISABLE
// <1=> ENABLE
#ifndef DFU_ENABLE
#define DFU_ENABLE 0//1
#endif
3.调整代码
1)调整app_periph_init函数
/*
* GLOBAL FUNCTION DEFINITIONS
*****************************************************************************************
*/
void app_periph_init(void)
{
SYS_SET_BD_ADDR(s_bd_addr);
// bsp_log_init();
#if APP_LOG_STORE_ENABLE
log_store_init();
#endif
// dfu_port_init(NULL, NULL);
pwr_mgmt_mode_set(PMR_MGMT_SLEEP_MODE);
}
2)添加gus透传profile,此处为了与原有的gus区分开,将文件名也更新为gus_test
?
3)在下列参数中修改广播周期为2000mS
#define DEVICE_NAME "RTOS_test" /**< Device Name which will be set in GAP. */
#define APP_ADV_FAST_MIN_INTERVAL 32 /**< The fast advertising min interval (in units of 0.625 ms. This value corresponds to 160 ms). */
#define APP_ADV_FAST_MAX_INTERVAL 48 /**< The fast advertising max interval (in units of 0.625 ms. This value corresponds to 1000 ms). */
#define APP_ADV_SLOW_MIN_INTERVAL 1600 * 2 /**< The slow advertising min interval (in units of 0.625 ms). */
#define APP_ADV_SLOW_MAX_INTERVAL 1600 * 2 /**< The slow advertising max interval (in units of 0.625 ms). */
#define APP_ADV_TIMEOUT_IN_SECONDS 0 /**< The advertising timeout in units of seconds. */
#define MIN_CONN_INTERVAL 320 /**< Minimum acceptable connection interval (0.4 seconds). */
#define MAX_CONN_INTERVAL 520 /**< Maximum acceptable connection interval (0.65 second). */
#define SLAVE_LATENCY 0 /**< Slave latency. */
#define CONN_SUP_TIMEOUT 400 /**< Connection supervisory timeout (4 seconds). */
4)注意修改services_init函数
static void services_init(void)
{
sdk_err_t error_code;
gus_init_t gus_init;
#if DFU_ENABLE
dfu_service_init(NULL);
#endif
gus_init.evt_handler = gus_service_process_event;
error_code = gus_service_init(&gus_init);
APP_ERROR_CHECK(error_code);
#if APP_LOG_STORE_ENABLE
app_log_dump_service_init();
#endif
}
4.烧写到评估版,使用电流分析仪连接测试
可以看到2秒的定时任务,还要2秒的广播周期,平均电流约9.5uA
?
|