1  /*
2  * Copyright (C) 2017-2024 Alibaba Group Holding Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /******************************************************************************
20  * @file     drv/irq.h
21  * @brief    header File for IRQ Driver
22  * @version  V1.0
23  * @date     16. Mar 2020
24  * @model    irq
25  ******************************************************************************/
26 
27 #ifndef _DRV_IRQ_H_
28 #define _DRV_IRQ_H_
29 
30 #include <stdint.h>
31 #include <drv/common.h>
32 #include <soc.h>
33 #include <csi_core.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /**
40   \brief       Enable irq.
41   \param[in]   irq_num Number of IRQ.
42   \return      None.
43 */
csi_irq_enable(uint32_t irq_num)44 __ALWAYS_STATIC_INLINE void csi_irq_enable(uint32_t irq_num)
45 {
46     extern void soc_irq_enable(uint32_t irq_num);
47     soc_irq_enable(irq_num);
48 }
49 
50 /**
51   \brief       Disable irq.
52   \param[in]   irq_num Number of IRQ.
53   \return      None.
54 */
csi_irq_disable(uint32_t irq_num)55 __ALWAYS_STATIC_INLINE void csi_irq_disable(uint32_t irq_num)
56 {
57     extern void soc_irq_disable(uint32_t irq_num);
58     soc_irq_disable(irq_num);
59 }
60 
61 /**
62   \brief       Attach irq handler.
63   \param[in]   irq_num     Number of IRQ.
64   \param[in]   irq_handler IRQ Handler.
65   \param[in]   dev         The dev to operate
66   \return      None.
67 */
68 void csi_irq_attach(uint32_t irq_num, void *irq_handler, csi_dev_t *dev);
69 
70 /**
71   \brief       Attach irq handler2 for compatible.
72   \param[in]   irq_num      Number of IRQ.
73   \param[in]   irq_handler2 IRQ Handler.
74   \param[in]   dev          The dev to operate
75   \param[in]   arg          user data of irq_handler2
76   \return      None.
77 */
78 void csi_irq_attach2(uint32_t irq_num, void *irq_handler2, csi_dev_t *dev, void *arg);
79 
80 /**
81   \brief       detach irq handler.
82   \param[in]   irq_num Number of IRQ.
83   \param[in]   irq_handler IRQ Handler.
84   \return      None.
85 */
86 void csi_irq_detach(uint32_t irq_num);
87 
88 /**
89   \brief       Set irq priority
90   \param[in]   irq_num Number of IRQ.
91   \param[in]   priority IRQ Priority.
92   \return      None.
93 */
csi_irq_priority(uint32_t irq_num,uint32_t priority)94 __ALWAYS_STATIC_INLINE void csi_irq_priority(uint32_t irq_num, uint32_t priority)
95 {
96     extern void soc_irq_priority(uint32_t irq_num, uint32_t priority);
97     soc_irq_priority(irq_num, priority);
98 }
99 
100 /**
101   \brief       Gets whether the interrupt is enabled
102   \param[in]   irq_num Number of IRQ.
103   \return      true or false.
104 */
csi_irq_is_enabled(uint32_t irq_num)105 static inline bool csi_irq_is_enabled(uint32_t irq_num)
106 {
107     extern bool soc_irq_is_enabled(uint32_t irq_num);
108     return soc_irq_is_enabled(irq_num);
109 }
110 
111 /**
112   \brief       Enable the interrupt wakeup attribution
113   \param[in]   irq_num Number of IRQ.
114   \return      None.
115 */
csi_irq_enable_wakeup(uint32_t irq_num)116 __ALWAYS_STATIC_INLINE void csi_irq_enable_wakeup(uint32_t irq_num)
117 {
118     extern void soc_irq_enable_wakeup(uint32_t irq_num);
119     soc_irq_enable_wakeup(irq_num);
120 }
121 
122 /**
123   \brief       Disable the interrupt wakeup attribution
124   \param[in]   irq_num Number of IRQ.
125   \return      None.
126 */
csi_irq_disable_wakeup(uint32_t irq_num)127 __ALWAYS_STATIC_INLINE void csi_irq_disable_wakeup(uint32_t irq_num)
128 {
129     extern void soc_irq_disable_wakeup(uint32_t irq_num);
130     soc_irq_disable_wakeup(irq_num);
131 }
132 
133 /**
134   \brief       Gets whether in irq context
135   \return      true or false.
136 */
137 bool csi_irq_context(void);
138 
139 /**
140   \brief       Dispatching irq handlers
141   \return      None.
142 */
143 void do_irq(void);
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif /* _DRV_IRQ_H_ */
150