cpu_hal.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. */
  10. #include <stdint.h>
  11. #include <stddef.h>
  12. #include "soc/soc_caps.h"
  13. #include "hal/cpu_ll.h"
  14. #include "esp_cpu.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. typedef enum {
  19. WATCHPOINT_TRIGGER_ON_RO = ESP_CPU_WATCHPOINT_LOAD, // on read
  20. WATCHPOINT_TRIGGER_ON_WO = ESP_CPU_WATCHPOINT_STORE, // on write
  21. WATCHPOINT_TRIGGER_ON_RW = ESP_CPU_WATCHPOINT_ACCESS, // on either read or write
  22. } watchpoint_trigger_t;
  23. /**
  24. * Return the ID of the core currently executing this code.
  25. *
  26. * @return core id [0..SOC_CPU_CORES_NUM - 1]
  27. */
  28. #define cpu_hal_get_core_id() cpu_ll_get_core_id()
  29. /**
  30. * Get the current value of the stack pointer.
  31. *
  32. * @return the current stack pointer
  33. */
  34. #define cpu_hal_get_sp() cpu_ll_get_sp()
  35. /**
  36. * Get the current value of the internal counter that increments
  37. * every processor-clock cycle.
  38. *
  39. * @return cycle count; returns 0 if not supported
  40. */
  41. #define cpu_hal_get_cycle_count() cpu_ll_get_cycle_count()
  42. /**
  43. * Set the given value into the internal counter that increments
  44. * every processor-clock cycle.
  45. */
  46. #define cpu_hal_set_cycle_count(val) cpu_ll_set_cycle_count(val)
  47. /**
  48. * Check if some form of debugger is attached to CPU.
  49. *
  50. * @return true debugger is attached
  51. * @return false no debugger is attached/ no support for debuggers
  52. */
  53. #define cpu_hal_is_debugger_attached() cpu_ll_is_debugger_attached()
  54. /**
  55. * Init HW loop status.
  56. */
  57. #define cpu_hal_init_hwloop() cpu_ll_init_hwloop()
  58. /**
  59. * Trigger a call to debugger.
  60. */
  61. #define cpu_hal_break() cpu_ll_break()
  62. /**
  63. * Wait for interrupt.
  64. */
  65. #define cpu_hal_waiti() cpu_ll_waiti()
  66. #if SOC_CPU_BREAKPOINTS_NUM > 0
  67. /**
  68. * Set and enable breakpoint at an instruction address.
  69. *
  70. * @note Overwrites previously set breakpoint with same breakpoint ID.
  71. *
  72. * @param id breakpoint to set [0..SOC_CPU_BREAKPOINTS_NUM - 1]
  73. * @param addr address to set a breakpoint on
  74. */
  75. static inline __attribute__((deprecated)) void cpu_hal_set_breakpoint(int id, const void *addr)
  76. {
  77. esp_cpu_set_breakpoint(id, addr);
  78. }
  79. /**
  80. * Clear and disable breakpoint.
  81. *
  82. * @param id breakpoint to clear [0..SOC_CPU_BREAKPOINTS_NUM - 1]
  83. */
  84. static inline __attribute__((deprecated)) void cpu_hal_clear_breakpoint(int id)
  85. {
  86. esp_cpu_clear_breakpoint(id);
  87. }
  88. #endif // SOC_CPU_BREAKPOINTS_NUM > 0
  89. #if SOC_CPU_WATCHPOINTS_NUM > 0
  90. /**
  91. * Set and enable a watchpoint, specifying the memory range and trigger operation.
  92. *
  93. * @param id watchpoint to set [0..SOC_CPU_WATCHPOINTS_NUM - 1]
  94. * @param addr starting address
  95. * @param size number of bytes from starting address to watch
  96. * @param trigger operation on specified memory range that triggers the watchpoint (read, write, read/write)
  97. */
  98. static inline __attribute__((deprecated))
  99. 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 __attribute__((deprecated)) 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__((deprecated)) __attribute__((always_inline))
  119. void cpu_hal_set_vecbase(const void *base)
  120. {
  121. esp_cpu_intr_set_ivt_addr(base);
  122. }
  123. #ifdef __cplusplus
  124. }
  125. #endif