cpu_hal.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include "esp_err.h"
  17. #include "soc/soc_caps.h"
  18. #include "hal/cpu_types.h"
  19. #include "hal/cpu_ll.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  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. void cpu_hal_set_breakpoint(int id, const void* addr);
  76. /**
  77. * Clear and disable breakpoint.
  78. *
  79. * @param id breakpoint to clear [0..SOC_CPU_BREAKPOINTS_NUM - 1]
  80. */
  81. void cpu_hal_clear_breakpoint(int id);
  82. #endif // SOC_CPU_BREAKPOINTS_NUM > 0
  83. #if SOC_CPU_WATCHPOINTS_NUM > 0
  84. /**
  85. * Set and enable a watchpoint, specifying the memory range and trigger operation.
  86. *
  87. * @param id watchpoint to set [0..SOC_CPU_WATCHPOINTS_NUM - 1]
  88. * @param addr starting address
  89. * @param size number of bytes from starting address to watch
  90. * @param trigger operation on specified memory range that triggers the watchpoint (read, write, read/write)
  91. */
  92. void cpu_hal_set_watchpoint(int id, const void* addr, size_t size, watchpoint_trigger_t trigger);
  93. /**
  94. * Clear and disable watchpoint.
  95. *
  96. * @param id watchpoint to clear [0..SOC_CPU_WATCHPOINTS_NUM - 1]
  97. */
  98. void cpu_hal_clear_watchpoint(int id);
  99. #endif // SOC_CPU_WATCHPOINTS_NUM > 0
  100. /**
  101. * Set exception vector table base address.
  102. *
  103. * @param base address to move the exception vector table to
  104. */
  105. void cpu_hal_set_vecbase(const void* base);
  106. #ifdef __cplusplus
  107. }
  108. #endif