1 、timers_init();
static void timers_init(void)
{
uint32_t err_code;
// Initialize timer module
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
// Create timers
err_code = app_timer_create(&m_battery_timer_id,
APP_TIMER_MODE_REPEATED,
battery_level_meas_timeout_handler);
APP_ERROR_CHECK(err_code);
err_code = app_timer_start(m_battery_timer_id, BATTERY_LEVEL_MEAS_INTERVAL, NULL);
APP_ERROR_CHECK(err_code);
APP_ERROR_CHECK(err_code);
}
battery_level_meas_timeout_handler 为定时器处理函数
BATTERY_LEVEL_MEAS_INTERVAL 为定时时间间隔 (宏定义)
static void battery_level_meas_timeout_handler(void * p_context)
{
(void)p_context;
//用户代码
}
原文:http://www.cnblogs.com/vhuichen/p/4859824.html