cpu_hal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "hal/cpu_types.h"
  18. #include "hal/cpu_ll.h"
  19. #include "soc/cpu_caps.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. * Check if some form of debugger is attached to CPU.
  44. *
  45. * @return true debugger is attached
  46. * @return false no debugger is attached/ no support for debuggers
  47. */
  48. #define cpu_hal_is_debugger_attached() cpu_ll_is_debugger_attached()
  49. /**
  50. * Init HW loop status.
  51. */
  52. #define cpu_hal_init_hwloop() cpu_ll_init_hwloop()
  53. /**
  54. * Trigger a call to debugger.
  55. */
  56. #define cpu_hal_break() cpu_ll_break()
  57. #if SOC_CPU_BREAKPOINTS_NUM > 0
  58. /**
  59. * Set and enable breakpoint at an instruction address.
  60. *
  61. * @note Overwrites previously set breakpoint with same breakpoint ID.
  62. *
  63. * @param id breakpoint to set [0..SOC_CPU_BREAKPOINTS_NUM - 1]
  64. * @param addr address to set a breakpoint on
  65. */
  66. void cpu_hal_set_breakpoint(int id, const void* addr);
  67. /**
  68. * Clear and disable breakpoint.
  69. *
  70. * @param id breakpoint to clear [0..SOC_CPU_BREAKPOINTS_NUM - 1]
  71. */
  72. void cpu_hal_clear_breakpoint(int id);
  73. #endif // SOC_CPU_BREAKPOINTS_NUM > 0
  74. #if SOC_CPU_WATCHPOINTS_NUM > 0
  75. /**
  76. * Set and enable a watchpoint, specifying the memory range and trigger operation.
  77. *
  78. * @param id watchpoint to set [0..SOC_CPU_WATCHPOINTS_NUM - 1]
  79. * @param addr starting address
  80. * @param size number of bytes from starting address to watch
  81. * @param trigger operation on specified memory range that triggers the watchpoint (read, write, read/write)
  82. */
  83. void cpu_hal_set_watchpoint(int id, const void* addr, size_t size, watchpoint_trigger_t trigger);
  84. /**
  85. * Clear and disable watchpoint.
  86. *
  87. * @param id watchpoint to clear [0..SOC_CPU_WATCHPOINTS_NUM - 1]
  88. */
  89. void cpu_hal_clear_watchpoint(int id);
  90. #endif // SOC_CPU_WATCHPOINTS_NUM > 0
  91. /**
  92. * Set exception vector table base address.
  93. *
  94. * @param base address to move the exception vector table to
  95. */
  96. void cpu_hal_set_vecbase(const void* base);
  97. #ifdef __cplusplus
  98. }
  99. #endif