esp_timer_impl.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2017 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. /**
  16. * @file esp_timer_impl.h
  17. *
  18. * @brief Interface between common and platform-specific parts of esp_timer.
  19. *
  20. * The functions in this header file are implemented for each supported SoC.
  21. * High level functions defined in esp_timer.c call the functions here to
  22. * interact with the hardware.
  23. */
  24. #include <stdint.h>
  25. #include "esp_err.h"
  26. #include "esp_intr_alloc.h"
  27. /**
  28. * @brief Initialize platform specific layer of esp_timer
  29. * @param alarm_handler function to call on timer interrupt
  30. * @return ESP_OK, ESP_ERR_NO_MEM, or one of the errors from interrupt allocator
  31. */
  32. esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler);
  33. /**
  34. * @brief Deinitialize platform specific layer of esp_timer
  35. */
  36. void esp_timer_impl_deinit();
  37. /**
  38. * @brief Set up the timer interrupt to fire at a particular time
  39. *
  40. * If the alarm time is too close in the future, implementation should set the
  41. * alarm to the earliest time possible.
  42. *
  43. * @param timestamp time in microseconds when interrupt should fire (relative to
  44. * boot time, i.e. as returned by esp_timer_impl_get_time)
  45. */
  46. void esp_timer_impl_set_alarm(uint64_t timestamp);
  47. /**
  48. * @brief Get time, in microseconds, since esp_timer_impl_init was called
  49. * @return timestamp in microseconds
  50. */
  51. uint64_t esp_timer_impl_get_time();
  52. /**
  53. * @brief Get minimal timer period, in microseconds
  54. * Periods shorter than the one returned may not be possible to achieve due to
  55. * interrupt latency and context switch time. Short period of periodic timer may
  56. * cause the system to spend all the time servicing the interrupt and timer
  57. * callback, preventing other tasks from running.
  58. * @return minimal period of periodic timer, in microseconds
  59. */
  60. uint64_t esp_timer_impl_get_min_period_us();