高分辨率定时器

概述

Although FreeRTOS provides software timers, these timers have a few limitations:
虽然FreeRTOS提供软件定时器,但这些定时器有一些限制:

  • Maximum resolution is equal to RTOS tick period
  • 最大分辨率等于RTOS滴答周期
  • Timer callbacks are dispatched from a low-priority task
  • 定时器回调的任务优先级低

Hardware timers are free from both of the limitations, but often they are less convenient to use. For example, application components may need timer events to fire at certain times in the future, but the hardware timer only contains one “compare” value used for interrupt generation. This means that some facility needs to be built on top of the hardware timer to manage the list of pending events can dispatch the callbacks for these events as corresponding hardware interrupts happen.
硬件定时器不受这两个限制,但通常使用起来不方便。例如,应用程序组件可能需要定时器事件才能在将来的特定时间触发,但硬件定时器只包含一个“比较”值用于产生中断。这意味着需要在硬件定时器的基础上构建一些设施来管理待处理事件列表,以便在相应的硬件中断发生时调度这些事件的回调。

esp_timer set of APIs provide such facility. Internally, esp_timer uses a 32-bit hardware timer (FRC1, “legacy” timer). esp_timer provides one-shot and periodic timers, microsecond time resolution, and 64-bit range.
esp_timerAPI提供这些。其内部,esp_timer使用32位硬件定时器(FRC1,“传统”定时器)。esp_timer提供一次性和周期性定时器,微秒级的分辨率和64位范围。

Timer callbacks are dispatched from a high-priority esp_timer task. Because all the callbacks are dispatched from the same task, it is recommended to only do the minimal possible amount of work from the callback itself, posting an event to a lower priority task using a queue instead.
定时器回调由高优先级的esp_timer任务分派。由于所有回调都是从同一个任务调度的,因此建议仅从回调做最少量的工作,//FIXME:而不是使用队列将事件发布到较低优先级的任务。

使用esp_timerAPI

Single timer is represented by esp_timer_handle_t type. Timer has a callback function associated with it. This callback function is called from the esp_timer task each time the timer elapses.
单个计时器由esp_timer_handle_t类型表示。Timer有一个与之相关的回调函数。这个回调函数在esp_timer任务中定时器超时的时候调用。

  • To create a timer, call esp_timer_create().
  • 创建计时器,请调用esp_timer_create()
  • To delete the timer when it is no longer needed, call esp_timer_delete().
  • 删除定时器,请调用esp_timer_delete()

The timer can be started in one-shot mode or in periodic mode.
定时器可以在单次模式或周期模式下启动。

  • To start the timer in one-shot mode, call esp_timer_start_once(), passing the time interval after which the callback should be called. When the callback gets called, the timer is considered to be stopped.
  • 要以单发模式启动计时器,请调用esp_timer_start_once(),并设定触发时间。当回调被调用时,定时器被认为是停止的。
  • To start the timer in periodic mode, call esp_timer_start_periodic(), passing the period with which the callback should be called. The timer keeps running until esp_timer_stop() is called.
  • 要以周期模式启动定时器,请调用esp_timer_start_periodic(),并设定触发周期。调用esp_timer_stop()停止定时器。

Note that the timer must not be running when esp_timer_start_once() or esp_timer_start_periodic()is called. To restart a running timer, call esp_timer_stop() first, then call one of the start functions.
请注意,定时器运行前需调用esp_timer_start_once()或者esp_timer_start_periodic()。要重启正在运行的定时器,先调用esp_timer_stop(),然后调用其中一个启动函数。

获取当前时间

esp_timer also provides a convenience function to obtain the time passed since start-up, with microsecond precision: esp_timer_get_time(). This function returns the number of microseconds since esp_timer was initialized, which usually happens shortly before app_main function is called.
esp_timer还提供了一个方便的功能来获得自启动以来的时间,精确到微秒:esp_timer_get_time()。该函数返回从esp_timer初始化完成到函数调用经过的微秒数,esp_timer初始化通常在app_main之前一些完成。

Unlike gettimeofday function, values returned by esp_timer_get_time():
与gettimeofday函数不同,esp_timer_get_time()函数的返回值:

  • Start from zero after the chip wakes up from deep sleep
  • 芯片从深度睡眠中醒来后,从零开始
  • Do not have timezone or DST adjustments applied
  • 没有应用时区或DST调整

API参考

头文件

  • esp32/include/esp_timer.h

本文翻译自:https://esp-idf.readthedocs.io/en/latest/api-reference/system/esp_timer.html

翻译水平有限,如有错误欢迎指正

官方文档翻译-ESP32-High Resolution Timer相关推荐

  1. About HTTP Live Streaming官方文档翻译 [iOS]

    新博客地址:About HTTP Live Streaming官方文档翻译 [iOS] 版权声明:本文为博主原创翻译,如需转载请注明出处. 苹果源文档地址 - 点击这里 About HTTP Live ...

  2. GoogleServices之GooglePlayService Accessing Google APIS(访问谷歌APIS)官方文档翻译

    GoogleServices之GooglePlayService  Accessing Google APIS(访问谷歌APIS)官方文档翻译 AccessingGoogle APIs(访问谷歌API ...

  3. 【iOS官方文档翻译】iOS蓝牙的基本概念

    之前写了[iOS官方文档翻译]iOS的蓝牙连接.数据接收及发送一文,介绍了怎样进行蓝牙通讯,但是很多基本概念没有进行解释,看起来可能有点吃力,所以现在再翻译一篇苹果对官方蓝牙4.0一些基本概念介绍的文 ...

  4. 欢迎参与 KubeVela 官方文档翻译活动

    来源 | 阿里巴巴云原生公众号 背景 KubeVela v1.0 启用了新的官网架构和文档维护方式,新增功能包括文档版本化控制.i18n 国际化以及自动化流程.但目前 KubeVela 官方文档只有英 ...

  5. UIControl事件---iOS-Apple苹果官方文档翻译

    本系列所有开发文档翻译链接地址: iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 UIControl事件1.UIControlEventTouchDown 单点触摸按 ...

  6. 【KubeVela 官方文档翻译】,欢迎大家踊跃参与

    简介:KubeVela v1.0 启用了新的官网架构和文档维护方式,新增功能包括文档版本化控制.i18n 国际化以及自动化流程.但目前 KubeVela 官方文档只有英文版,这提高了学习和使用 Kub ...

  7. UIPageControl---iOS-Apple苹果官方文档翻译

    本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/Ch ...

  8. Python3.2官方文档翻译--异常抛出和自定义异常

    Python3.2官方文档翻译--异常抛出和自定义异常 Python3.2官方文档翻译--异常抛出和自定义异常,有需要的朋友可以参考下. 6.4 抛出异常 Raise语句运行程序员强制抛出一个具体的异 ...

  9. Log4j2官方文档翻译--欢迎使用Log4j2!

    官网原文标题<Welcome to Log4j 2!> 官网原文地址http://logging.apache.org/log4j/2.x/manual/index.html 译者:本文介 ...

  10. fastapi官方文档翻译 -目录

    fastapi官方文档翻译 warmsirius 最新发布 最新评论 目录 fastapi教程翻译(前言):安装和运行 fastapi教程翻译(一):了解FastAPI结构 fastapi教程翻译(二 ...

最新文章

  1. 中date转为string_股票数据获取篇(持续更新中...)
  2. linux查看nginx并发连接情况
  3. python2中使用中文报错:SyntaxError: Non-ASCII character
  4. PaddleOCR——Visual Studio 2019 环境下C++推理部署 CMake 编译解决方案
  5. deepin15.7挂载/home到单独的分区:
  6. CSS样式:覆盖规则
  7. asp.net core源码飘香:Logging组件
  8. 1123. Is It a Complete AVL Tree (30)
  9. 【Elasticsearch】es查看有问题的索引或者分片
  10. Spring学习笔记之二----基于XML的Spring AOP配置
  11. Linux执行fastqc报错Exception in thread “main“ java.awt.HeadlessException: No X11 DISPLAY variable was s
  12. python select网络编程详细介绍
  13. js 实现文件上传 php,JS+php后台实现文件上传功能详解
  14. 风暴数码论坛教程-JAVA环境配置
  15. hdu5294(Tricks Device)题解
  16. VScode已经设置了默认浏览器依然不成功原因
  17. office365:PowerPoint新功能设计器,让排版更轻松
  18. npm run build报错Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of
  19. 狼已经一个sr闪狼已经夺人一个闪
  20. 计算机考研复试之软件工程三十问

热门文章

  1. 小红书增长负责人:精确化营销如何玩
  2. Maven的这三个用法你一定要会!
  3. 川大优秀毕业生在GitHub上建了一个项目《深度学习500问》,还未完结就获赞无数
  4. 消息中间件选型分析 —— 从 Kafka 与 RabbitMQ 的对比来看全局
  5. C++:=default一些说明
  6. 6.exit _exit _Exit
  7. 全面总结:进程与线程
  8. mysql - 要问 varchar 能存几个汉字? 能存几个 字母? 能存几个数字?请看下文讲解 (Java)
  9. php获取总共内存_php获取页面运行使用内存的两个函数
  10. PUE值测算标准实践问题探讨