1 // Copyright (C) 2022 Beken Corporation 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 // 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 15 #pragma once 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 #include <common/bk_err.h> 21 #include <driver/int_types.h> 22 23 /* @brief Overview about this API header 24 * 25 */ 26 27 /** 28 * @brief ICU API 29 * @defgroup bk_api_icu ICU API group 30 * @{ 31 */ 32 33 /** 34 * @brief Init the ICU driver 35 * 36 * This API init the icu modules : 37 * - Init ICU driver control memory, enable fiq and irq 38 * 39 * This API should be called before any other ICU APIs. 40 * 41 * @return 42 * - BK_OK: succeed 43 * - others: other errors. 44 */ 45 bk_err_t bk_icu_driver_init(void); 46 47 /** 48 * @brief deinit the ICU driver 49 * 50 * This API deinit the icu module 51 * 52 * This API disable all devices' intterrupts 53 * 54 * @return 55 * - BK_OK: succeed 56 * - others: other errors. 57 */ 58 bk_err_t bk_icu_driver_deinit(void); 59 60 #ifdef CONFIG_ISR_REG_DISABLE 61 #define bk_int_isr_register(dev, isr, arg) 62 #define bk_int_isr_unregister(src) 63 #else 64 65 /** 66 * @brief register interrupt service handler 67 * 68 * @attention 1. If this is called, the default interrupt handler is replaced by the 69 * new handler, the caller is fully responsible for handling the interrupt, 70 * such as, read the interrupt status, clear the interrupt status and 71 * processing the interrupt etc. 72 * 73 * @param dev interrupt source device 74 * @param isr int service function 75 * 76 * @return 77 * - BK_OK: succeed 78 * - BK_ERR_NO_MEM: no memoery 79 * - BK_ERR_INT_DEVICE_NONE: no int device 80 * - others: other errors. 81 */ 82 bk_err_t bk_int_isr_register(icu_int_src_t dev, int_group_isr_t isr, void*arg); 83 84 /** 85 * @brief unregister interrupt service handler 86 * 87 * @param dev interrupt source device 88 * 89 * @return 90 * - BK_OK: succeed 91 * - BK_ERR_INT_DEVICE_NONE:no int device 92 * - others: other errors. 93 */ 94 bk_err_t bk_int_isr_unregister(icu_int_src_t src); 95 #endif 96 97 /** 98 * @brief set/change interrupt priority 99 * 100 * Every interrupt source has a two-level priority, the group priority and the 101 * priority. The interrupt source has higher group priority will be schedule 102 * first. The interrupt sources has higher priority will be schedule first if 103 * they has the same group priority. 104 * 105 * This API is used to configure the pririty. 106 * 107 * @param dev interrupt source device 108 * @param isr int service function 109 * 110 * @return 111 * - BK_OK: succeed 112 * - BK_ERR_NOT_SUPPORT :not support 113 * - others: other errors. 114 */ 115 bk_err_t bk_int_set_priority(icu_int_src_t src, uint32_t int_priority); 116 117 118 /** 119 * @brief set the interrupt group priority 120 * 121 * Every interrupt source has a two-level priority, the group priority and the 122 * priority. The interrupt source has higher group priority will be schedule 123 * first. The interrupt sources has higher priority will be schedule first if 124 * they has the same group priority. 125 * 126 * This API is used to configure the group priority of the interrupt source. 127 * 128 * @attention 1. For ARM9, it has two group priorities which are mapped to 129 * ARM9 FIQ and IRQ. Currently all interrupt source are statically 130 * mapped to the group priority and can't change by this API. 131 * We may support it in future. 132 * 133 * @return 134 * - BK_OK: succeed 135 * - BK_ERR_NOT_SUPPORT :not support 136 * - others: other errors. 137 */ 138 bk_err_t bk_int_set_group(void); 139 140 /** 141 * @brief Register callback for mac ps 142 * 143 * @param mac_ps_cb mac ps callback 144 * 145 * @return 146 * - BK_OK: succeed 147 * - others: other errors. 148 */ 149 bk_err_t bk_int_register_mac_ps_callback(int_mac_ps_callback_t mac_ps_cb); 150 151 #ifdef __cplusplus 152 153 } 154 #endif 155