1 /*
2  * Copyright (C) 2017-2020 Alibaba Group Holding Limited
3  */
4 
5 /******************************************************************************
6  * @file     drv/intc.h
7  * @brief    Header File for INTC Driver
8  * @version  V1.0
9  * @date     02. June 2020
10  * @model    intc
11  ******************************************************************************/
12 
13 #ifndef _DRV_INTC_H_
14 #define _DRV_INTC_H_
15 
16 #include <stdint.h>
17 #include <drv/common.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 typedef enum int_trigger_mode_t {
23     INT_MODE_LOW_LEVEL,
24     INT_MODE_HIGH_LEVEL,
25     INT_MODE_RISING_EDGE,
26     INT_MODE_FALLING_EDGE,
27     INT_MODE_DOUBLE_EDGE,
28 } int_trigger_mode_t;
29 
30 /**
31   \brief    Initialize the INTC interrupt controller
32  */
33 void csi_intc_init(void);
34 
35 /**
36   \brief        Enable External Interrupt
37   \details      Enables a device-specific interrupt in the INTC interrupt controller.
38   \param[in]    IRQn  External interrupt number. Value cannot be negative.
39  */
40 void csi_intc_enable_irq(int32_t IRQn);
41 
42 /**
43   \brief        Disable External Interrupt
44   \details      Disables a device-specific interrupt in the INTC interrupt controller.
45   \param[in]    IRQn  External interrupt number. Value cannot be negative.
46  */
47 void csi_intc_disable_irq(int32_t IRQn);
48 
49 /**
50   \brief        Get Pending Interrupt
51   \details      Reads the pending register in the INTC and returns the pending bit for the specified interrupt.
52   \param[in]    IRQn  Interrupt number.
53   \return       0  Interrupt status is not pending.
54   \return       1  Interrupt status is pending.
55  */
56 uint32_t csi_intc_get_pending_irq(int32_t IRQn);
57 
58 /**
59   \brief        Set Pending Interrupt
60   \details      Sets the pending bit of an external interrupt.
61   \param[in]    IRQn  Interrupt number. Value cannot be negative.
62  */
63 void csi_intc_set_pending_irq(int32_t IRQn);
64 
65 /**
66   \brief        Clear Pending Interrupt
67   \details      Clears the pending bit of an external interrupt.
68   \param[in]    IRQn  External interrupt number. Value cannot be negative.
69  */
70 void csi_intc_clear_pending_irq(int32_t IRQn);
71 
72 /**
73   \brief        Get Wake up Interrupt
74   \details      Reads the wake up register in the INTC and returns the pending bit for the specified interrupt.
75   \param[in]    IRQn  Interrupt number.
76   \return       0  Interrupt is not set as wake up interrupt.
77   \return       1  Interrupt is set as wake up interrupt.
78  */
79 uint32_t csi_intc_get_wakeup_irq(int32_t IRQn);
80 
81 /**
82   \brief        Set Wake up Interrupt
83   \details      Sets the wake up bit of an external interrupt.
84   \param[in]    IRQn  Interrupt number. Value cannot be negative.
85  */
86 void csi_intc_set_wakeup_irq(int32_t IRQn);
87 
88 /**
89   \brief        Clear Wake up Interrupt
90   \details      Clears the wake up bit of an external interrupt.
91   \param[in]    IRQn  External interrupt number. Value cannot be negative.
92  */
93 void csi_intc_clear_wakeup_irq(int32_t IRQn);
94 
95 /**
96   \brief        Get Active Interrupt
97   \details      Reads the active register in the INTC and returns the active bit for the device specific interrupt.
98   \param[in]    IRQn  Device specific interrupt number.
99   \return       0  Interrupt status is not active.
100   \return       1  Interrupt status is active.
101   \note    IRQn must not be negative.
102  */
103 uint32_t csi_intc_get_active(int32_t IRQn);
104 
105 /**
106   \brief        Set Threshold register
107   \details      set the threshold register in the INTC.
108   \param[in]    VectThreshold  specific vecter threshold.
109   \param[in]    PrioThreshold  specific priority threshold.
110  */
111 void csi_intc_set_threshold(uint32_t VectThreshold, uint32_t PrioThreshold);
112 
113 /**
114   \brief        Set Interrupt Priority
115   \details      Sets the priority of an interrupt.
116   \note         The priority cannot be set for every core interrupt.
117   \param[in]    IRQn  Interrupt number.
118   \param[in]    priority  Priority to set.
119  */
120 void csi_intc_set_prio(int32_t IRQn, uint32_t priority);
121 
122 /**
123   \brief        Get Interrupt Priority
124   \details      Reads the priority of an interrupt.
125                 The interrupt number can be positive to specify an external (device specific) interrupt,
126                 or negative to specify an internal (core) interrupt.
127   \param[in]    IRQn  Interrupt number.
128   \return       Interrupt Priority.
129                 Value is aligned automatically to the implemented priority bits of the microcontroller.
130  */
131 uint32_t csi_intc_get_prio(int32_t IRQn);
132 
133 /**
134   \brief        funciton is acknowledge the IRQ. this interface is internally used by irq system
135   \param[in]    irq  irq number to operate
136   \return       0 on success; -1 on failure
137  */
138 int csi_intc_ack_irq(int32_t IRQn);
139 
140 /**
141   \brief        This function is set the attributes of an IRQ.
142   \param[in]    irq    irq number to operate
143   \param[in]    priority    interrupt priority
144   \param[in]    trigger_mode    interrupt trigger_mode
145   \return       0 on success; -1 on failure
146 */
147 int csi_intc_set_attribute(int32_t IRQn, uint32_t priority, int_trigger_mode_t trigger_mode);
148 
149 /**
150   \brief        Set interrupt handler
151   \details      Set the interrupt handler according to the interrupt num, the handler will be filled in g_irqvector[].
152   \param[in]    IRQn  Interrupt number.
153   \param[in]    handler  Interrupt handler.
154  */
155 void csi_intc_set_vector(int32_t IRQn, uint32_t handler);
156 
157 /**
158   \brief        Get interrupt handler
159   \details      Get the address of interrupt handler function.
160   \param[in]    IRQn  Interrupt number.
161  */
162 uint32_t csi_intc_get_vector(int32_t IRQn);
163 
164 #endif /* _DRV_INTC_H_ */
165