timer_app.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include <board.h>
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #ifndef RT_USING_TIMER_SOFT
  14. #error "Please enable soft timer feature!"
  15. #endif
  16. #define TIMER_APP_DEFAULT_TICK (RT_TICK_PER_SECOND * 2)
  17. #ifdef RT_USING_PM
  18. static rt_timer_t timer1;
  19. static void _timeout_entry(void *parameter)
  20. {
  21. rt_kprintf("current tick: %ld\n", rt_tick_get());
  22. }
  23. static int timer_app_init(void)
  24. {
  25. timer1 = rt_timer_create("timer_app",
  26. _timeout_entry,
  27. RT_NULL,
  28. TIMER_APP_DEFAULT_TICK,
  29. RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER);
  30. if (timer1 != RT_NULL)
  31. {
  32. rt_timer_start(timer1);
  33. /* keep in timer mode */
  34. rt_pm_request(PM_SLEEP_MODE_TIMER);
  35. return 0;
  36. }
  37. else
  38. {
  39. return -1;
  40. }
  41. }
  42. INIT_APP_EXPORT(timer_app_init);
  43. #endif /* RT_USING_PM */