interrupt_controller_hal.c 2.0 KB

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