interrupt_controller_ll.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "soc/soc_caps.h"
  16. #include "soc/soc.h"
  17. #include "xtensa/xtensa_api.h"
  18. #include "xtensa/config/specreg.h"
  19. #include "xt_instr_macros.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /**
  24. * @brief enable interrupts specified by the mask
  25. *
  26. * @param mask bitmask of interrupts that needs to be enabled
  27. */
  28. static inline void intr_cntrl_ll_enable_interrupts(uint32_t mask)
  29. {
  30. xt_ints_on(mask);
  31. }
  32. /**
  33. * @brief disable interrupts specified by the mask
  34. *
  35. * @param mask bitmask of interrupts that needs to be disabled
  36. */
  37. static inline void intr_cntrl_ll_disable_interrupts(uint32_t mask)
  38. {
  39. xt_ints_off(mask);
  40. }
  41. /**
  42. * @brief Read the current interrupt mask of the CPU running this code.
  43. *
  44. * @return The current interrupt bitmask.
  45. */
  46. static inline uint32_t intr_cntrl_ll_read_interrupt_mask(void)
  47. {
  48. uint32_t int_mask;
  49. RSR(INTENABLE, int_mask);
  50. return int_mask;
  51. }
  52. /**
  53. * @brief checks if given interrupt number has a valid handler
  54. *
  55. * @param intr interrupt number ranged from 0 to 31
  56. * @param cpu cpu number ranged betweeen 0 to SOC_CPU_CORES_NUM - 1
  57. * @return true for valid handler, false otherwise
  58. */
  59. static inline bool intr_cntrl_ll_has_handler(uint8_t intr, uint8_t cpu)
  60. {
  61. return xt_int_has_handler(intr, cpu);
  62. }
  63. /**
  64. * @brief sets interrupt handler and optional argument of a given interrupt number
  65. *
  66. * @param intr interrupt number ranged from 0 to 31
  67. * @param handler handler invoked when an interrupt occurs
  68. * @param arg optional argument to pass to the handler
  69. */
  70. static inline void intr_cntrl_ll_set_int_handler(uint8_t intr, interrupt_handler_t handler, void *arg)
  71. {
  72. xt_set_interrupt_handler(intr, (xt_handler)handler, arg);
  73. }
  74. /**
  75. * @brief Gets argument passed to handler of a given interrupt number
  76. *
  77. * @param intr interrupt number ranged from 0 to 31
  78. *
  79. * @return argument used by handler of passed interrupt number
  80. */
  81. static inline void *intr_cntrl_ll_get_int_handler_arg(uint8_t intr)
  82. {
  83. return xt_get_interrupt_handler_arg(intr);
  84. }
  85. /**
  86. * @brief Acknowledge an edge-trigger interrupt by clearing its pending flag
  87. *
  88. * @param intr interrupt number ranged from 0 to 31
  89. */
  90. static inline void intr_cntrl_ll_edge_int_acknowledge (int intr)
  91. {
  92. xthal_set_intclear(1 << intr);
  93. }
  94. #ifdef __cplusplus
  95. }
  96. #endif