1 /*
2 * Copyright (c) 2017 Intel corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /**
8 * @file
9 * @brief Public interface for configuring interrupts
10 */
11 #ifndef ZEPHYR_INCLUDE_IRQ_NEXTLEVEL_H_
12 #define ZEPHYR_INCLUDE_IRQ_NEXTLEVEL_H_
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /**
19 * @cond INTERNAL_HIDDEN
20 *
21 * These are for internal use only, so skip these in
22 * public documentation.
23 */
24 typedef void (*irq_next_level_func_t)(const struct device *dev,
25 unsigned int irq);
26 typedef unsigned int (*irq_next_level_get_state_t)(const struct device *dev);
27 typedef void (*irq_next_level_priority_t)(const struct device *dev,
28 unsigned int irq, unsigned int prio,
29 uint32_t flags);
30 typedef int (*irq_next_level_get_line_state_t)(const struct device *dev,
31 unsigned int irq);
32
33 struct irq_next_level_api {
34 irq_next_level_func_t intr_enable;
35 irq_next_level_func_t intr_disable;
36 irq_next_level_get_state_t intr_get_state;
37 irq_next_level_priority_t intr_set_priority;
38 irq_next_level_get_line_state_t intr_get_line_state;
39 };
40 /**
41 * @endcond
42 */
43
44 /**
45 * @brief Enable an IRQ in the next level.
46 *
47 * This routine enables interrupts present in the interrupt controller.
48 *
49 * @param dev Pointer to the device structure for the driver instance.
50 * @param irq IRQ to be enabled.
51 */
irq_enable_next_level(const struct device * dev,uint32_t irq)52 static inline void irq_enable_next_level(const struct device *dev,
53 uint32_t irq)
54 {
55 const struct irq_next_level_api *api =
56 (const struct irq_next_level_api *)dev->api;
57
58 api->intr_enable(dev, irq);
59 }
60
61 /**
62 * @brief Disable an IRQ in the next level.
63 *
64 * This routine disables interrupts present in the interrupt controller.
65 *
66 * @param dev Pointer to the device structure for the driver instance.
67 * @param irq IRQ to be disabled.
68 */
irq_disable_next_level(const struct device * dev,uint32_t irq)69 static inline void irq_disable_next_level(const struct device *dev,
70 uint32_t irq)
71 {
72 const struct irq_next_level_api *api =
73 (const struct irq_next_level_api *)dev->api;
74
75 api->intr_disable(dev, irq);
76 }
77
78 /**
79 * @brief Get IRQ enable state.
80 *
81 * This routine indicates if any interrupts are enabled in the interrupt
82 * controller.
83 *
84 * @param dev Pointer to the device structure for the driver instance.
85 *
86 * @return interrupt enable state, true or false
87 */
irq_is_enabled_next_level(const struct device * dev)88 static inline unsigned int irq_is_enabled_next_level(const struct device *dev)
89 {
90 const struct irq_next_level_api *api =
91 (const struct irq_next_level_api *)dev->api;
92
93 return api->intr_get_state(dev);
94 }
95
96 /**
97 * @brief Set IRQ priority.
98 *
99 * This routine indicates if any interrupts are enabled in the interrupt
100 * controller.
101 *
102 * @param dev Pointer to the device structure for the driver instance.
103 * @param irq IRQ to be disabled.
104 * @param prio priority for irq in the interrupt controller.
105 * @param flags controller specific flags.
106 */
irq_set_priority_next_level(const struct device * dev,uint32_t irq,uint32_t prio,uint32_t flags)107 static inline void irq_set_priority_next_level(const struct device *dev,
108 uint32_t irq,
109 uint32_t prio, uint32_t flags)
110 {
111 const struct irq_next_level_api *api =
112 (const struct irq_next_level_api *)dev->api;
113
114 if (api->intr_set_priority)
115 api->intr_set_priority(dev, irq, prio, flags);
116 }
117
118 /**
119 * @brief Get IRQ line enable state.
120 *
121 * Query if a particular IRQ line is enabled.
122 *
123 * @param dev Pointer to the device structure for the driver instance.
124 * @param irq IRQ line to be queried.
125 *
126 * @return interrupt enable state, true or false
127 */
irq_line_is_enabled_next_level(const struct device * dev,unsigned int irq)128 static inline unsigned int irq_line_is_enabled_next_level(const struct device *dev,
129 unsigned int irq)
130 {
131 const struct irq_next_level_api *api =
132 (const struct irq_next_level_api *)dev->api;
133
134 return api->intr_get_line_state(dev, irq);
135 }
136
137 #ifdef __cplusplus
138 }
139 #endif
140
141 #endif /* ZEPHYR_INCLUDE_IRQ_NEXTLEVEL_H_ */
142