cpu_hal.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. /*
  8. Note: This is a compatibility header. Call the interfaces in esp_cpu.h instead
  9. [refactor-todo]: Mark all API in this header as deprecated
  10. */
  11. #include <stdint.h>
  12. #include <stddef.h>
  13. #include "soc/soc_caps.h"
  14. #include "hal/cpu_ll.h"
  15. #include "esp_cpu.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. typedef enum {
  20. WATCHPOINT_TRIGGER_ON_RO = ESP_CPU_WATCHPOINT_LOAD, // on read
  21. WATCHPOINT_TRIGGER_ON_WO = ESP_CPU_WATCHPOINT_STORE, // on write
  22. WATCHPOINT_TRIGGER_ON_RW = ESP_CPU_WATCHPOINT_ACCESS, // on either read or write
  23. } watchpoint_trigger_t;
  24. /**
  25. * Return the ID of the core currently executing this code.
  26. *
  27. * @return core id [0..SOC_CPU_CORES_NUM - 1]
  28. */
  29. #define cpu_hal_get_core_id() cpu_ll_get_core_id()
  30. /**
  31. * Get the current value of the stack pointer.
  32. *
  33. * @return the current stack pointer
  34. */
  35. #define cpu_hal_get_sp() cpu_ll_get_sp()
  36. /**
  37. * Get the current value of the internal counter that increments
  38. * every processor-clock cycle.
  39. *
  40. * @return cycle count; returns 0 if not supported
  41. */
  42. #define cpu_hal_get_cycle_count() cpu_ll_get_cycle_count()
  43. /**
  44. * Set the given value into the internal counter that increments
  45. * every processor-clock cycle.
  46. */
  47. #define cpu_hal_set_cycle_count(val) cpu_ll_set_cycle_count(val)
  48. /**
  49. * Check if some form of debugger is attached to CPU.
  50. *
  51. * @return true debugger is attached
  52. * @return false no debugger is attached/ no support for debuggers
  53. */
  54. #define cpu_hal_is_debugger_attached() cpu_ll_is_debugger_attached()
  55. /**
  56. * Init HW loop status.
  57. */
  58. #define cpu_hal_init_hwloop() cpu_ll_init_hwloop()
  59. /**
  60. * Trigger a call to debugger.
  61. */
  62. #define cpu_hal_break() cpu_ll_break()
  63. /**
  64. * Wait for interrupt.
  65. */
  66. #define cpu_hal_waiti() cpu_ll_waiti()
  67. #if SOC_CPU_BREAKPOINTS_NUM > 0
  68. /**
  69. * Set and enable breakpoint at an instruction address.
  70. *
  71. * @note Overwrites previously set breakpoint with same breakpoint ID.
  72. *
  73. * @param id breakpoint to set [0..SOC_CPU_BREAKPOINTS_NUM - 1]
  74. * @param addr address to set a breakpoint on
  75. */
  76. static inline void cpu_hal_set_breakpoint(int id, const void *addr)
  77. {
  78. esp_cpu_set_breakpoint(id, addr);
  79. }
  80. /**
  81. * Clear and disable breakpoint.
  82. *
  83. * @param id breakpoint to clear [0..SOC_CPU_BREAKPOINTS_NUM - 1]
  84. */
  85. static inline void cpu_hal_clear_breakpoint(int id)
  86. {
  87. esp_cpu_clear_breakpoint(id);
  88. }
  89. #endif // SOC_CPU_BREAKPOINTS_NUM > 0
  90. #if SOC_CPU_WATCHPOINTS_NUM > 0
  91. /**
  92. * Set and enable a watchpoint, specifying the memory range and trigger operation.
  93. *
  94. * @param id watchpoint to set [0..SOC_CPU_WATCHPOINTS_NUM - 1]
  95. * @param addr starting address
  96. * @param size number of bytes from starting address to watch
  97. * @param trigger operation on specified memory range that triggers the watchpoint (read, write, read/write)
  98. */
  99. static inline void cpu_hal_set_watchpoint(int id, const void *addr, size_t size, watchpoint_trigger_t trigger)
  100. {
  101. esp_cpu_set_watchpoint(id, addr, size, (esp_cpu_watchpoint_trigger_t)trigger);
  102. }
  103. /**
  104. * Clear and disable watchpoint.
  105. *
  106. * @param id watchpoint to clear [0..SOC_CPU_WATCHPOINTS_NUM - 1]
  107. */
  108. static inline void cpu_hal_clear_watchpoint(int id)
  109. {
  110. esp_cpu_clear_watchpoint(id);
  111. }
  112. #endif // SOC_CPU_WATCHPOINTS_NUM > 0
  113. /**
  114. * Set exception vector table base address.
  115. *
  116. * @param base address to move the exception vector table to
  117. */
  118. static inline __attribute__((always_inline)) void cpu_hal_set_vecbase(const void *base)
  119. {
  120. esp_cpu_intr_set_ivt_addr(base);
  121. }
  122. #ifdef __cplusplus
  123. }
  124. #endif