1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2018-08-07 Tanek first implementation 9 */ 10 11 #include <board.h> 12 #include <rtthread.h> 13 #include <rtdevice.h> 14 15 #ifndef RT_USING_TIMER_SOFT 16 #error "Please enable soft timer feature!" 17 #endif 18 19 #define TIMER_APP_DEFAULT_TICK (RT_TICK_PER_SECOND * 2) 20 21 #ifdef RT_USING_PM 22 23 static rt_timer_t timer1; 24 25 static void _timeout_entry(void *parameter) 26 { 27 rt_kprintf("current tick: %ld\n", rt_tick_get()); 28 } 29 30 static int timer_app_init(void) 31 { 32 timer1 = rt_timer_create("timer_app", 33 _timeout_entry, 34 RT_NULL, 35 TIMER_APP_DEFAULT_TICK, 36 RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER); 37 if (timer1 != RT_NULL) 38 { 39 rt_timer_start(timer1); 40 41 /* keep in timer mode */ 42 rt_pm_request(PM_SLEEP_MODE_TIMER); 43 44 return 0; 45 } 46 else 47 { 48 return -1; 49 } 50 } 51 INIT_APP_EXPORT(timer_app_init); 52 53 #endif /* RT_USING_PM */ 54 55