1 /* shared_irq - Shared interrupt driver */
2
3 /*
4 * Copyright (c) 2015 Intel corporation
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #ifndef ZEPHYR_INCLUDE_SHARED_IRQ_H_
10 #define ZEPHYR_INCLUDE_SHARED_IRQ_H_
11
12 #include <autoconf.h>
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 typedef int (*isr_t)(const struct device *dev);
19
20 /* driver API definition */
21 typedef int (*shared_irq_register_t)(const struct device *dev,
22 isr_t isr_func,
23 const struct device *isr_dev);
24 typedef int (*shared_irq_enable_t)(const struct device *dev,
25 const struct device *isr_dev);
26 typedef int (*shared_irq_disable_t)(const struct device *dev,
27 const struct device *isr_dev);
28
29 struct shared_irq_driver_api {
30 shared_irq_register_t isr_register;
31 shared_irq_enable_t enable;
32 shared_irq_disable_t disable;
33 };
34
35 /**
36 * @brief Register a device ISR
37 * @param dev Pointer to device structure for SHARED_IRQ driver instance.
38 * @param isr_func Pointer to the ISR function for the device.
39 * @param isr_dev Pointer to the device that will service the interrupt.
40 */
shared_irq_isr_register(const struct device * dev,isr_t isr_func,const struct device * isr_dev)41 static inline int shared_irq_isr_register(const struct device *dev,
42 isr_t isr_func,
43 const struct device *isr_dev)
44 {
45 const struct shared_irq_driver_api *api =
46 (const struct shared_irq_driver_api *)dev->api;
47
48 return api->isr_register(dev, isr_func, isr_dev);
49 }
50
51 /**
52 * @brief Enable ISR for device
53 * @param dev Pointer to device structure for SHARED_IRQ driver instance.
54 * @param isr_dev Pointer to the device that will service the interrupt.
55 */
shared_irq_enable(const struct device * dev,const struct device * isr_dev)56 static inline int shared_irq_enable(const struct device *dev,
57 const struct device *isr_dev)
58 {
59 const struct shared_irq_driver_api *api =
60 (const struct shared_irq_driver_api *)dev->api;
61
62 return api->enable(dev, isr_dev);
63 }
64
65 /**
66 * @brief Disable ISR for device
67 * @param dev Pointer to device structure for SHARED_IRQ driver instance.
68 * @param isr_dev Pointer to the device that will service the interrupt.
69 */
shared_irq_disable(const struct device * dev,const struct device * isr_dev)70 static inline int shared_irq_disable(const struct device *dev,
71 const struct device *isr_dev)
72 {
73 const struct shared_irq_driver_api *api =
74 (const struct shared_irq_driver_api *)dev->api;
75
76 return api->disable(dev, isr_dev);
77 }
78
79 #ifdef __cplusplus
80 }
81 #endif
82
83 #endif /* ZEPHYR_INCLUDE_SHARED_IRQ_H_ */
84