esp_cpu.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2010-2016 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. #ifndef _ESP_CPU_H
  14. #define _ESP_CPU_H
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include <stddef.h>
  18. #include "hal/cpu_hal.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define ESP_WATCHPOINT_LOAD 0x40000000
  23. #define ESP_WATCHPOINT_STORE 0x80000000
  24. #define ESP_WATCHPOINT_ACCESS 0xC0000000
  25. typedef uint32_t esp_cpu_ccount_t;
  26. /** @brief Read current stack pointer address
  27. *
  28. */
  29. static inline void *esp_cpu_get_sp(void)
  30. {
  31. return cpu_hal_get_sp();
  32. }
  33. /**
  34. * @brief Stall CPU using RTC controller
  35. * @param cpu_id ID of the CPU to stall (0 = PRO, 1 = APP)
  36. */
  37. void esp_cpu_stall(int cpu_id);
  38. /**
  39. * @brief Un-stall CPU using RTC controller
  40. * @param cpu_id ID of the CPU to un-stall (0 = PRO, 1 = APP)
  41. */
  42. void esp_cpu_unstall(int cpu_id);
  43. /**
  44. * @brief Reset CPU using RTC controller
  45. * @param cpu_id ID of the CPU to reset (0 = PRO, 1 = APP)
  46. */
  47. void esp_cpu_reset(int cpu_id);
  48. /**
  49. * @brief Returns true if a JTAG debugger is attached to CPU
  50. * OCD (on chip debug) port.
  51. *
  52. * @note If "Make exception and panic handlers JTAG/OCD aware"
  53. * is disabled, this function always returns false.
  54. */
  55. bool esp_cpu_in_ocd_debug_mode(void);
  56. static inline esp_cpu_ccount_t esp_cpu_get_ccount(void)
  57. {
  58. return cpu_hal_get_cycle_count();
  59. }
  60. static inline void esp_cpu_set_ccount(esp_cpu_ccount_t val)
  61. {
  62. cpu_hal_set_cycle_count(val);
  63. }
  64. /**
  65. * @brief Set a watchpoint to break/panic when a certain memory range is accessed.
  66. *
  67. * @param no Watchpoint number. On the ESP32, this can be 0 or 1.
  68. * @param adr Base address to watch
  69. * @param size Size of the region, starting at the base address, to watch. Must
  70. * be one of 2^n, with n in [0..6].
  71. * @param flags One of ESP_WATCHPOINT_* flags
  72. *
  73. * @return ESP_ERR_INVALID_ARG on invalid arg, ESP_OK otherwise
  74. *
  75. * @warning The ESP32 watchpoint hardware watches a region of bytes by effectively
  76. * masking away the lower n bits for a region with size 2^n. If adr does
  77. * not have zero for these lower n bits, you may not be watching the
  78. * region you intended.
  79. */
  80. esp_err_t esp_cpu_set_watchpoint(int no, void *adr, int size, int flags);
  81. /**
  82. * @brief Clear a watchpoint
  83. *
  84. * @param no Watchpoint to clear
  85. *
  86. */
  87. void esp_cpu_clear_watchpoint(int no);
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif // _ESP_CPU_H