1 /*
2  * Copyright (c) 2020, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  *    list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
18  *    contributors may be used to endorse or promote products derived from this
19  *    software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 
35 /**
36  * @brief This module defines the Interrupt Abstraction Layer for the 802.15.4 driver.
37  *
38  * Interrupt Abstraction Layer can be used by other modules to configure, enable and disable
39  * interrupts controlled by the 802.15.4 driver.
40  */
41 
42 #ifndef NRF_802154_IRQ_H__
43 #define NRF_802154_IRQ_H__
44 
45 #include <stdbool.h>
46 #include <stdint.h>
47 
48 /**
49  * @brief Function pointer used for IRQ handling.
50  *
51  * This type intentionally does not specify any parameters of the function.
52  * In contrast to C++, where unspecified function's parameter would be equivalent
53  * to void parameter, in C such syntax indicates that the function in question
54  * accepts parameters of any type. Therefore, it's convenient for compatibility reasons,
55  * as the following functions:
56  *
57  * @code
58  * void foo(void);
59  * void bar(void * p_parameter);
60  * @endcode
61  *
62  * are both of type nrf_802154_isr_t and can both be passed to functions expecting a parameter
63  * of this type.
64  */
65 typedef void (* nrf_802154_isr_t)();
66 
67 /**
68  * @brief Initializes a provided interrupt line.
69  *
70  * @note This function does not enable the interrupt. In order to enable it,  additional call
71  *       to @ref nrf_802154_irq_enable is necessary.
72  *
73  * @param[in] irqn  IRQ line number.
74  * @param[in] prio  Priority of the IRQ.
75  * @param[in] isr   Pointer to ISR.
76  *
77  * @note Interpretation of the value represented by @p prio is platform-dependent and defined by
78  *       the implementation.
79  */
80 void nrf_802154_irq_init(uint32_t irqn, int32_t prio, nrf_802154_isr_t isr);
81 
82 /**
83  * @brief Enables an interrupt.
84  *
85  * @param[in] irqn  IRQ line number.
86  */
87 void nrf_802154_irq_enable(uint32_t irqn);
88 
89 /**
90  * @brief Disables an interrupt.
91  *
92  * @param[in] irqn  IRQ line number.
93  */
94 void nrf_802154_irq_disable(uint32_t irqn);
95 
96 /**
97  * @brief Sets an interrupt pending.
98  *
99  * @param[in] irqn  IRQ line number.
100  */
101 void nrf_802154_irq_set_pending(uint32_t irqn);
102 
103 /**
104  * @brief Clears a pending interrupt.
105  *
106  * @param[in] irqn  IRQ line number.
107  */
108 void nrf_802154_irq_clear_pending(uint32_t irqn);
109 
110 /**
111  * @brief Checks if an interrupt is enabled.
112  *
113  * @param[in] irqn  IRQ line number.
114  *
115  * @retval true   IRQ is enabled.
116  * @retval false  Otherwise.
117  */
118 bool nrf_802154_irq_is_enabled(uint32_t irqn);
119 
120 /**
121  * @brief Gets priority of an interrupt.
122  *
123  * This function returns the actual value of the IRQ priority present in the IRQ configuration
124  * register. It might not be equal to the IRQ priority specified in @ref nrf_802154_irq_init.
125  * In order to reliably compare IRQ priorities, do not rely on the values of IRQ priorities
126  * passed to @ref nrf_802154_irq_init, but rather always use this function instead.
127  *
128  * @param[in] irqn  IRQ line number.
129  *
130  * @return Priority of the provided interrupt.
131  */
132 uint32_t nrf_802154_irq_priority_get(uint32_t irqn);
133 
134 #endif // NRF_802154_IRQ_H__
135