interrupt_controller_hal.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include "hal/interrupt_controller_hal.h"
  14. #include "soc/soc_caps.h"
  15. #if __riscv
  16. #include "riscv/instruction_decode.h"
  17. static bool is_interrupt_number_reserved(int interrupt_number)
  18. {
  19. //TODO. Workaround to reserve interrupt number 0 for Wi-Fi.
  20. if (interrupt_number == 1) {
  21. return true;
  22. }
  23. extern int _vector_table;
  24. extern int _interrupt_handler;
  25. const intptr_t pc = (intptr_t)(&_vector_table + interrupt_number);
  26. /* JAL instructions are relative to the PC there are executed from. */
  27. const intptr_t destination = pc + riscv_decode_offset_from_jal_instruction(pc);
  28. return destination != (intptr_t)&_interrupt_handler;
  29. }
  30. #endif
  31. int_type_t interrupt_controller_hal_desc_type(int interrupt_number)
  32. {
  33. #ifndef SOC_CPU_HAS_FLEXIBLE_INTC
  34. const int_desc_t *int_desc = interrupt_controller_hal_desc_table();
  35. return (int_desc[interrupt_number].type);
  36. #else
  37. return (INTTP_NA);
  38. #endif
  39. }
  40. int interrupt_controller_hal_desc_level(int interrupt_number)
  41. {
  42. #ifndef SOC_CPU_HAS_FLEXIBLE_INTC
  43. const int_desc_t *int_desc = interrupt_controller_hal_desc_table();
  44. return (int_desc[interrupt_number].level);
  45. #else
  46. return 1;
  47. #endif
  48. }
  49. int_desc_flag_t interrupt_controller_hal_desc_flags(int interrupt_number, int cpu_number)
  50. {
  51. #ifndef SOC_CPU_HAS_FLEXIBLE_INTC
  52. const int_desc_t *int_desc = interrupt_controller_hal_desc_table();
  53. return (int_desc[interrupt_number].cpuflags[cpu_number]);
  54. #else
  55. #if __riscv
  56. return is_interrupt_number_reserved(interrupt_number) ? INTDESC_RESVD : INTDESC_NORMAL;
  57. #else
  58. return INTDESC_NORMAL;
  59. #endif
  60. #endif
  61. }