cpu.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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 "xtensa/corebits.h"
  16. /* C macros for xtensa special register read/write/exchange */
  17. #define RSR(reg, curval) asm volatile ("rsr %0, " #reg : "=r" (curval));
  18. #define WSR(reg, newval) asm volatile ("wsr %0, " #reg : : "r" (newval));
  19. #define XSR(reg, swapval) asm volatile ("xsr %0, " #reg : "+r" (swapval));
  20. /* Return true if the CPU is in an interrupt context
  21. (PS.UM == 0)
  22. */
  23. static inline bool cpu_in_interrupt_context(void)
  24. {
  25. uint32_t ps;
  26. RSR(PS, ps);
  27. return (ps & PS_UM) == 0;
  28. }
  29. #endif