hw_timer.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef _HW_TIMER_H
  2. #define _HW_TIMER_H
  3. #if APB_CLK_FREQ == 80 * 1000000
  4. // 80 MHz divided by 16 is 5 MHz count rate.
  5. #define US_TO_RTC_TIMER_TICKS(t) ((t) * 5)
  6. #else
  7. #define US_TO_RTC_TIMER_TICKS(t) \
  8. ((t) ? \
  9. (((t) > 0x35A) ? \
  10. (((t)>>2) * ((APB_CLK_FREQ>>4)/250000) + ((t)&0x3) * ((APB_CLK_FREQ>>4)/1000000)) : \
  11. (((t) *(APB_CLK_FREQ>>4)) / 1000000)) : \
  12. 0)
  13. #endif
  14. typedef enum {
  15. FRC1_SOURCE = 0,
  16. NMI_SOURCE = 1,
  17. } FRC1_TIMER_SOURCE_TYPE;
  18. bool ICACHE_RAM_ATTR platform_hw_timer_arm_ticks(os_param_t owner, uint32_t ticks);
  19. bool ICACHE_RAM_ATTR platform_hw_timer_arm_us(os_param_t owner, uint32_t microseconds);
  20. bool platform_hw_timer_set_func(os_param_t owner, void (* user_hw_timer_cb_set)(os_param_t), os_param_t arg);
  21. bool platform_hw_timer_init(os_param_t owner, FRC1_TIMER_SOURCE_TYPE source_type, bool autoload);
  22. bool ICACHE_RAM_ATTR platform_hw_timer_close(os_param_t owner);
  23. uint32_t ICACHE_RAM_ATTR platform_hw_timer_get_delay_ticks(os_param_t owner);
  24. #endif