systimer_hal.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2020 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. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "soc/soc_caps.h"
  18. #include "soc/systimer_struct.h"
  19. #include "hal/systimer_types.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. typedef struct {
  24. systimer_dev_t *dev;
  25. } systimer_hal_context_t;
  26. /**
  27. * @brief initialize systimer in HAL layer
  28. */
  29. void systimer_hal_init(systimer_hal_context_t *hal);
  30. /**
  31. * @brief enable systimer counter
  32. */
  33. void systimer_hal_enable_counter(systimer_hal_context_t *hal, uint32_t counter_id);
  34. /**
  35. * @brief get current counter value
  36. */
  37. uint64_t systimer_hal_get_counter_value(systimer_hal_context_t *hal, uint32_t counter_id);
  38. /**
  39. * @brief get current time (in microseconds)
  40. */
  41. uint64_t systimer_hal_get_time(systimer_hal_context_t *hal, uint32_t counter_id);
  42. /*
  43. * @brief set alarm target value (used in one-shot mode)
  44. */
  45. void systimer_hal_set_alarm_target(systimer_hal_context_t *hal, uint32_t alarm_id, uint64_t target);
  46. /**
  47. * @brief set alarm period value (used in period mode)
  48. */
  49. void systimer_hal_set_alarm_period(systimer_hal_context_t *hal, uint32_t alarm_id, uint32_t period);
  50. /**
  51. * @brief get alarm time
  52. */
  53. uint64_t systimer_hal_get_alarm_value(systimer_hal_context_t *hal, uint32_t alarm_id);
  54. /**
  55. * @brief enable alarm interrupt
  56. */
  57. void systimer_hal_enable_alarm_int(systimer_hal_context_t *hal, uint32_t alarm_id);
  58. /**
  59. * @brief select alarm mode
  60. */
  61. void systimer_hal_select_alarm_mode(systimer_hal_context_t *hal, uint32_t alarm_id, systimer_alarm_mode_t mode);
  62. /**
  63. * @brief update systimer step when apb clock gets changed
  64. */
  65. void systimer_hal_on_apb_freq_update(systimer_hal_context_t *hal, uint32_t apb_ticks_per_us);
  66. /**
  67. * @brief move systimer counter value forward or backward
  68. */
  69. void systimer_hal_counter_value_advance(systimer_hal_context_t *hal, uint32_t counter_id, int64_t time_us);
  70. /**
  71. * @brief connect alarm unit to selected counter
  72. */
  73. void systimer_hal_connect_alarm_counter(systimer_hal_context_t *hal, uint32_t alarm_id, uint32_t counter_id);
  74. /**
  75. * @brief set if a counter should be stalled when CPU is halted by the debugger
  76. */
  77. void systimer_hal_counter_can_stall_by_cpu(systimer_hal_context_t *hal, uint32_t counter_id, uint32_t cpu_id, bool can);
  78. #if !SOC_SYSTIMER_FIXED_TICKS_US
  79. /**
  80. * @brief set increase steps for systimer counter on different clock source
  81. */
  82. void systimer_hal_set_steps_per_tick(systimer_hal_context_t *hal, int clock_source, uint32_t steps);
  83. #endif
  84. #ifdef __cplusplus
  85. }
  86. #endif