1 /*
2  * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 enum intr_type {
14     INTR_TYPE_LEVEL = 0,
15     INTR_TYPE_EDGE
16 };
17 /*************************** Software interrupt dispatcher ***************************/
18 
19 /** Callback type of the interrupt handler */
20 typedef void (*intr_handler_t)(void*);
21 
22 /** Set the interrupt handler function for the given CPU interrupt
23  * @param rv_int_num  CPU interrupt number
24  * @param fn  Handler function
25  * @param arg  Handler argument
26  */
27 void intr_handler_set(int rv_int_num, intr_handler_t fn, void* arg);
28 
29 /** Get the interrupt handler function for the given CPU interrupt
30  *
31  *@return interrupt handler registered for a particular interrupt number, or NULL otherwise
32  */
33 intr_handler_t intr_handler_get(int rv_int_num);
34 
35 /** Get the interrupt handler argument associated with the given CPU interrupt
36  *
37  *@return interrupt handler argument for a particular interrupt number, or NULL otherwise
38  */
39 void *intr_handler_get_arg(int rv_int_num);
40 
41 /*************************** Interrupt matrix ***************************/
42 
43 /**
44  * this function will be removed in later, please use `intr_matrix_set` instead
45  * Route the peripheral interrupt signal to the CPU
46  * @param periph_intr_source  Peripheral interrupt number, one of ETS_XXX_SOURCE
47  * @param rv_int_num  CPU interrupt number
48  */
49 void intr_matrix_route(int periph_intr_source, int rv_int_num);
50 
51 /*************************** ESP-RV Interrupt Controller ***************************/
52 
53 /**
54   * @brief Enable interrupts from interrupt controller.
55   *
56   * @param uint32_t unmask, unmask bits for interrupts, each bit for an interrupt
57   *
58   * return none
59   */
60 void esprv_intc_int_enable(uint32_t unmask);
61 
62 /**
63   * @brief Disable interrupts from interrupt controller.
64   *
65   * @param uint32_t mask, mask bits for interrupts, each bit for an interrupt
66   *
67   * return none
68   */
69 void esprv_intc_int_disable(uint32_t mask);
70 
71 /**
72  * @brief Set interrupt type
73  *
74  * Set the type of a particular interrupt (level or edge).
75  * - Level interrupts are cleared automatically once their interrupt source has
76  *   been cleared
77  * - Edge interrupts must be cleared by software when they are handled.
78  *
79  * @param intr_num Interrupt number
80  * @param type Interrupt type
81  */
82 void esprv_intc_int_set_type(int intr_num, enum intr_type type);
83 
84 /**
85  * @brief Get the current type of an interrupt
86  *
87  * Get the current type of a particular interrupt (level or edge). An interrupt's
88  * type can be set by calling esprv_intc_int_set_type().
89  *
90  * @param intr_num Interrupt number
91  * @return Interrupt type
92  */
93 enum intr_type esprv_intc_int_get_type(int intr_num);
94 
95 /**
96  * Set interrupt priority in the interrupt controller
97  * @param rv_int_num CPU interrupt number
98  * @param priority Interrupt priority level, 1 to 7
99  */
100 void esprv_intc_int_set_priority(int rv_int_num, int priority);
101 
102 /**
103  * @brief Get the current priority of an interrupt
104  *
105  * Get the current priority of an interrupt.
106  *
107  * @param rv_int_num CPU interrupt number
108  * @return Interrupt priority level, 1 to 7
109  */
110 int esprv_intc_int_get_priority(int rv_int_num);
111 
112 /**
113  * Set interrupt priority threshold.
114  * Interrupts with priority levels lower than the threshold are masked.
115  *
116  * @param priority_threshold  Interrupt priority threshold, 0 to 7
117  */
118 void esprv_intc_int_set_threshold(int priority_threshold);
119 
120 /**
121  * @brief Get interrupt unmask
122  * @param none
123  * @return uint32_t interrupt unmask
124  */
125 uint32_t esprv_intc_get_interrupt_unmask(void);
126 
127 #ifdef __cplusplus
128 }
129 #endif
130