1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 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 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * Description: Interrupt DRIVER 15 * 16 * Create: 2021-06-30 17 */ 18 #ifndef INTERRUPT_H 19 #define INTERRUPT_H 20 21 #include "arch_port.h" 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif /* __cplusplus */ 26 #endif /* __cplusplus */ 27 28 /** 29 * @brief interupt callback function declaration. 30 */ 31 typedef void (*isr_function)(void); 32 33 /** 34 * @brief Set interupt callback function 35 * @param irq_id External interrupt number. 36 * @param func Interupt callback function 37 * @return Success or fail. 38 */ 39 uint32_t int_set_irq_func(int32_t irq_id, isr_function func); 40 41 /** 42 * @brief Set priority grouping. 43 * @param priority_group Priority grouping field. 44 */ 45 void int_set_priority_grouping(uint32_t priority_group); 46 47 /** 48 * @brief Get priority grouping. 49 * @return Priority grouping field. 50 */ 51 uint32_t int_get_priority_grouping(void); 52 53 /** 54 * @brief Enable external interrupt. 55 * @param irq_id External interrupt number. 56 */ 57 void int_enable_irq(int32_t irq_id); 58 59 /** 60 * @brief Disable external interrupt. 61 * @param irq_id External interrupt number. 62 */ 63 void int_disable_irq(int32_t irq_id); 64 65 /** 66 * @brief Get interrupt enable status 67 * @param irq_id External interrupt number. 68 * @return Returns a device specific interrupt enable status from the interrupt controller. 69 */ 70 uint32_t int_get_enable_irq(int32_t irq_id); 71 72 /** 73 * @brief Get pending interrupt. 74 * @param irq_id External interrupt number. 75 * @return The pending bit for the specified interrupt. 76 */ 77 uint32_t int_get_pending_irq(int32_t irq_id); 78 79 /** 80 * @brief Clear pending interrupt 81 * @param irq_id External interrupt number. 82 */ 83 void int_clear_pending_irq(int32_t irq_id); 84 85 /** 86 * @brief Set pending interrupt. 87 * @param irq_id External interrupt number. 88 */ 89 void int_set_pendind_irq(int32_t irq_id); 90 91 /** 92 * @brief Get active interrupt. 93 * @param irq_id External interrupt number. 94 * @return Returns a device specific interrupt status from the interrupt controller. 95 */ 96 uint32_t int_get_active(int32_t irq_id); 97 98 /** 99 * @brief Set interrupt priority 100 * @param irq_id External interrupt number. 101 * @param priority Priority to set. 102 */ 103 void int_set_priority(int32_t irq_id, uint32_t priority); 104 105 /** 106 * @brief Get interrupt priority. 107 * @param irq_id External interrupt number. 108 * @return Interrupt priority. 109 */ 110 uint32_t int_get_priority(int32_t irq_id); 111 112 /** 113 * @brief The function initiates a system reset request to reset the CPU. 114 */ 115 void int_system_reset(void); 116 117 /** 118 * @brief Setup the interrupt for current core. 119 */ 120 void int_setup(void); 121 122 /** 123 * @brief Checks if we are currently in interrupt context. 124 * @return If we are in interrupt context this will return true, false otherwise. 125 */ 126 bool int_is_interrupt_context(void); 127 128 /** 129 * @brief Gets the current IRQ that we are in. 130 * @return The irq number. 131 */ 132 int32_t int_get_current_irqn(void); 133 134 /** 135 * @brief Gets the current interrupt priority level. 136 * @return The current interrupt priority level. 137 */ 138 int32_t int_get_current_priority(void); 139 140 #ifdef __cplusplus 141 #if __cplusplus 142 } 143 #endif /* __cplusplus */ 144 #endif /* __cplusplus */ 145 146 #endif 147