1 /*
2  * Copyright (C) 2017-2020 Alibaba Group Holding Limited
3  */
4 
5 /******************************************************************************
6  * @file     drv/irq.h
7  * @brief    header File for IRQ Driver
8  * @version  V1.0
9  * @date     16. Mar 2020
10  * @model    irq
11  ******************************************************************************/
12 
13 #ifndef _DRV_IRQ_H_
14 #define _DRV_IRQ_H_
15 
16 #include <stdint.h>
17 #include <drv/common.h>
18 #include <soc.h>
19 #include <csi_core.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26   \brief       Enable irq.
27   \param[in]   irq_num Number of IRQ.
28   \return      None.
29 */
csi_irq_enable(uint32_t irq_num)30 __ALWAYS_STATIC_INLINE void csi_irq_enable(uint32_t irq_num)
31 {
32     extern void soc_irq_enable(uint32_t irq_num);
33     soc_irq_enable(irq_num);
34 }
35 
36 /**
37   \brief       Disable irq.
38   \param[in]   irq_num Number of IRQ.
39   \return      None.
40 */
csi_irq_disable(uint32_t irq_num)41 __ALWAYS_STATIC_INLINE void csi_irq_disable(uint32_t irq_num)
42 {
43     extern void soc_irq_disable(uint32_t irq_num);
44     soc_irq_disable(irq_num);
45 }
46 
47 /**
48   \brief       Attach irq handler.
49   \param[in]   irq_num     Number of IRQ.
50   \param[in]   irq_handler IRQ Handler.
51   \param[in]   dev         The dev to operate
52   \return      None.
53 */
54 void csi_irq_attach(uint32_t irq_num, void *irq_handler, csi_dev_t *dev);
55 
56 /**
57   \brief       detach irq handler.
58   \param[in]   irq_num Number of IRQ.
59   \param[in]   irq_handler IRQ Handler.
60   \return      None.
61 */
62 void csi_irq_detach(uint32_t irq_num);
63 
64 /**
65   \brief       Set irq priority
66   \param[in]   irq_num Number of IRQ.
67   \param[in]   priority IRQ Priority.
68   \return      None.
69 */
csi_irq_priority(uint32_t irq_num,uint32_t priority)70 __ALWAYS_STATIC_INLINE void csi_irq_priority(uint32_t irq_num, uint32_t priority)
71 {
72     extern void soc_irq_priority(uint32_t irq_num, uint32_t priority);
73     soc_irq_priority(irq_num, priority);
74 }
75 
76 /**
77   \brief       Gets whether the interrupt is enabled
78   \param[in]   irq_num Number of IRQ.
79   \return      true or false.
80 */
csi_irq_is_enabled(uint32_t irq_num)81 static inline bool csi_irq_is_enabled(uint32_t irq_num)
82 {
83     extern bool soc_irq_is_enabled(uint32_t irq_num);
84     return soc_irq_is_enabled(irq_num);
85 }
86 
87 /**
88   \brief       Enable the interrupt wakeup attribution
89   \param[in]   irq_num Number of IRQ.
90   \return      None.
91 */
csi_irq_enable_wakeup(uint32_t irq_num)92 __ALWAYS_STATIC_INLINE void csi_irq_enable_wakeup(uint32_t irq_num)
93 {
94     extern void soc_irq_enable_wakeup(uint32_t irq_num);
95     soc_irq_enable_wakeup(irq_num);
96 }
97 
98 /**
99   \brief       Disable the interrupt wakeup attribution
100   \param[in]   irq_num Number of IRQ.
101   \return      None.
102 */
csi_irq_disable_wakeup(uint32_t irq_num)103 __ALWAYS_STATIC_INLINE void csi_irq_disable_wakeup(uint32_t irq_num)
104 {
105     extern void soc_irq_disable_wakeup(uint32_t irq_num);
106     soc_irq_disable_wakeup(irq_num);
107 }
108 
109 /**
110   \brief       Gets whether in irq context
111   \return      true or false.
112 */
113 bool csi_irq_context(void);
114 
115 /**
116   \brief       Dispatching irq handlers
117   \return      None.
118 */
119 void do_irq(void);
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #endif /* _DRV_IRQ_H_ */
126