cpu.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 _SOC_CPU_H
  14. #define _SOC_CPU_H
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include <stddef.h>
  18. #include "esp_cpu.h"
  19. #if __XTENSA__
  20. #include "xt_instr_macros.h"
  21. // [refactor-todo] not actually needed in this header now,
  22. // but kept for compatibility
  23. #include "xtensa/corebits.h"
  24. #include "xtensa/config/core.h"
  25. #include "xtensa/config/specreg.h"
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /** @brief Read current stack pointer address.
  31. * Superseded by esp_cpu_get_sp in esp_cpu.h.
  32. */
  33. static inline __attribute__((deprecated)) void *get_sp(void)
  34. {
  35. return esp_cpu_get_sp();
  36. }
  37. static inline uint32_t esp_cpu_process_stack_pc(uint32_t pc)
  38. {
  39. if (pc & 0x80000000) {
  40. //Top two bits of a0 (return address) specify window increment. Overwrite to map to address space.
  41. pc = (pc & 0x3fffffff) | 0x40000000;
  42. }
  43. //Minus 3 to get PC of previous instruction (i.e. instruction executed before return address)
  44. return pc - 3;
  45. }
  46. /**
  47. * @brief Configure CPU to disable access to invalid memory regions
  48. *
  49. */
  50. void esp_cpu_configure_region_protection(void);
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #endif