You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.7 KiB

  1. #include "timer_u.h"
  2. void timer_set_pause_and_counter_zero(int group, int timer)
  3. {
  4. timer_pause(group, timer);
  5. timer_set_counter_value(group, timer, 0);
  6. }
  7. void port_timer_delay_ms(uint64_t delay)
  8. {
  9. uint64_t timer_count = 0;
  10. timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
  11. timer_start(TIMER_GROUP_0, TIMER_0);
  12. while (timer_count < (delay * 1000))
  13. {
  14. timer_get_counter_value(TIMER_GROUP_0, TIMER_0, &timer_count);
  15. }
  16. timer_pause(TIMER_GROUP_0, TIMER_0);
  17. }
  18. void timer_group_init(int group, int timer, bool auto_reload, int timer_interval, uint32_t timer_unit_time)
  19. {
  20. /* Select and initialize basic parameters of the timer */
  21. timer_config_t config = {
  22. .divider = 80,
  23. .counter_dir = TIMER_COUNT_UP,
  24. .counter_en = TIMER_PAUSE,
  25. .alarm_en = TIMER_ALARM_EN,
  26. .auto_reload = auto_reload,
  27. }; // default clock source is APB
  28. timer_init(group, timer, &config);
  29. /* Timer's counter will initially start from value below.
  30. Also, if auto_reload is set, this value will be automatically reload on alarm */
  31. timer_set_counter_value(group, timer, 0); //指定定时器首个计数值为0
  32. //检查定时器的当前值,调用函数 timer_get_counter_value() 或 timer_get_counter_time_sec()。
  33. //可通过调用函数 timer_pause() 随时暂停定时器。要再次启动它,调用函数 timer_start()。
  34. /* Configure the alarm value and the interrupt on alarm. */
  35. timer_set_alarm_value(group, timer, timer_interval * ((80 * timer_unit_time) / 80));
  36. timer_enable_intr(group, timer);
  37. // timer_isr_callback_add(group, timer, timer_group_isr_callback, NULL, 0);
  38. // timer_start(group, timer);
  39. timer_pause(group, timer);
  40. }