]> granicus.if.org Git - esp-idf/commitdiff
esp_timer: add documentation, expose profiling option in Kconfig
authorIvan Grokhotkov <ivan@espressif.com>
Fri, 24 Nov 2017 10:51:37 +0000 (18:51 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Wed, 29 Nov 2017 03:44:46 +0000 (11:44 +0800)
components/esp32/Kconfig
components/esp32/include/esp_timer.h
components/esp32/test/test_esp_timer.c
docs/Doxyfile
docs/api-reference/system/esp_timer.rst [new file with mode: 0644]
docs/api-reference/system/index.rst
tools/unit-test-app/sdkconfig.defaults

index 73e4fe4c64455bbeaa6152dcafdbb6cd3e62f53e..f4fe83f0cdc260c01494f1c5be7187f1f62ba055 100644 (file)
@@ -762,7 +762,6 @@ config NO_BLOBS
 
 config ESP_TIMER_PROFILING
        bool "Enable esp_timer profiling features"
-       depends on MAKING_ESP_TIMER_A_PUBLIC_API
        default n
        help
                If enabled, esp_timer_dump will dump information such as number of times
index e3e8b481286d3b60068dffa7ce43fc32f000945b..07e2372140533f4f5ca188311415c9ec0d5fb55e 100644 (file)
  * use RTOS notification mechanisms (queues, semaphores, event groups, etc.) to
  * pass information to other tasks.
  *
- * <to be implemented> It should be possible to request the callback to be called
+ * To be implemented: it should be possible to request the callback to be called
  * directly from the ISR. This reduces the latency, but has potential impact on
  * all other callbacks which need to be dispatched. This option should only be
  * used for simple callback functions, which do not take longer than a few
- * microseconds to run. </to be implemented>
+ * microseconds to run.
  *
  * Implementation note: on the ESP32, esp_timer APIs use the "legacy" FRC2
  * timer. Timer callbacks are called from a task running on the PRO CPU.
index d77ddeb5e8f90211af76eee053270a720d1313c8..4007528bd1ddc6f12a6787f761e10d7e7588755a 100644 (file)
 #include "freertos/semphr.h"
 #include "test_utils.h"
 
+#ifdef CONFIG_ESP_TIMER_PROFILING
+#define WITH_PROFILING 1
+#endif
+
 
 TEST_CASE("esp_timer orders timers correctly", "[esp_timer]")
 {
index e2dc5eab8ee513d97b7b271c62745ce5f22fee8e..950f914214b6b15d41de672b2c3e623852d4a029 100644 (file)
@@ -151,7 +151,9 @@ INPUT = \
     ../components/app_trace/include/esp_app_trace.h \
     ### Power management
     ../components/esp32/include/esp_pm.h \
-    ../components/esp32/include/esp32/pm.h
+    ../components/esp32/include/esp32/pm.h \
+    ### esp_timer, High Resolution Timer
+    ../components/esp32/include/esp_timer.h
 
 
 ## Get warnings for functions that have no documentation for their parameters or return value
diff --git a/docs/api-reference/system/esp_timer.rst b/docs/api-reference/system/esp_timer.rst
new file mode 100644 (file)
index 0000000..3e0b8c8
--- /dev/null
@@ -0,0 +1,52 @@
+High Resolution Timer
+=====================
+
+Overview
+--------
+
+Although FreeRTOS provides software timers, these timers have a few limitations:
+
+- Mmaximum resolution is equal to RTOS tick period
+- 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.
+
+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.
+
+.. note: Provisions are made to dispatch some simple callbacks directly from the interrupt handler, if needed. However this option is not implemented at the moment.
+
+Using ``esp_timer`` APIs
+------------------------
+
+Single timer is represented by :cpp:type:`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.
+
+- To create a timer, call :cpp:func:`esp_timer_create`.
+- To delete the timer when it is no longer needed, call :cpp:func:`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 :cpp:func:`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.
+
+- To start the timer in periodic mode, call :cpp:func:`esp_timer_start_periodic`, passing the period with which the callback should be called. The timer keeps running until :cpp:func:`esp_timer_stop` is called.
+
+Note that the timer must not be running when :cpp:func:`esp_timer_start_once` or :cpp:func:`esp_timer_start_periodic` is called. To restart a running timer, call :cpp:func:`esp_timer_stop` first, then call one of the start functions.
+
+Obtaining Current Time
+----------------------
+
+``esp_timer`` also provides a convenience function to obtain the time passed since start-up, with microsecond precision: :cpp:func:`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.
+
+Unlike `gettimeofday` function, values returned by :cpp:func:`esp_timer_get_time`:
+
+- Start from zero after the chip wakes up from deep sleep
+- Do not have timezone or DST adjustments applied
+
+
+API Reference
+-------------
+
+.. include:: /_build/inc/esp_timer.inc
+
+
index b4e92050d2ae47338af30df5e1d3336f7615b17b..c895ebd8b549707d4ac2ddd20c2071eb07c6502a 100644 (file)
@@ -10,6 +10,7 @@ System API
    Watchdogs <wdts>
    Hooks <hooks>
    Inter-Processor Call <ipc>
+   High Resolution Timer <esp_timer>
    Over The Air Updates (OTA) <ota>
    Sleep Modes <sleep_modes>
    Power Management <power_management>
index 534eca74ed7a1dfddad9fc5014469424fabae65d..9e9dfa691696850fd0289f8c35ebb4daf62a9f55 100644 (file)
@@ -24,3 +24,4 @@ CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=7
 CONFIG_STACK_CHECK_STRONG=y
 CONFIG_STACK_CHECK=y
 CONFIG_SUPPORT_STATIC_ALLOCATION=y
+CONFIG_ESP_TIMER_PROFILING=y