Contiki-NG
Loading...
Searching...
No Matches
nrf_802154_platform_irq.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026, RISE Research Institutes of Sweden AB.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30/*---------------------------------------------------------------------------*/
31/**
32 * \file
33 * IRQ abstraction layer for nrf_802154 on the nRF5340 network core.
34 *
35 * The 802.15.4 driver uses two interrupts: RADIO and an EGU (SWI).
36 * On the network core these are RADIO_IRQn and EGU0_IRQn (the library
37 * default NRF_802154_EGU_INSTANCE_NO is 0). The registered ISRs are
38 * dispatched from the NVIC handlers defined here. With the direct
39 * (non-SWI) notification/request implementation selected in the
40 * project config, the EGU ISR is normally never registered, but the
41 * handler is provided for completeness.
42 *
43 * The legacy nrf-ieee-driver-arch.c (which also defines
44 * RADIO_IRQHandler) must be filtered out of the net-core build.
45 */
46/*---------------------------------------------------------------------------*/
47#include "platform/nrf_802154_irq.h"
48#include "nrf_802154_config.h"
49#include "nrf.h"
50
51#include <stddef.h>
52#include <stdbool.h>
53#include <stdint.h>
54
55static nrf_802154_isr_t radio_isr;
56static nrf_802154_isr_t egu_isr;
57/*---------------------------------------------------------------------------*/
58void
59nrf_802154_irq_init(uint32_t irqn, int32_t prio, nrf_802154_isr_t isr)
60{
61 if(prio < 0) {
62 /* Negative priorities denote zero-latency IRQs, which a bare-metal
63 * Contiki-NG build does not expose; clamp to the highest programmable
64 * priority. */
65 prio = 0;
66 }
67
68 if(irqn == RADIO_IRQn) {
69 radio_isr = isr;
70 } else if(irqn == EGU0_IRQn) {
71 egu_isr = isr;
72 }
73
74 NVIC_SetPriority((IRQn_Type)irqn, (uint32_t)prio);
75 NVIC_ClearPendingIRQ((IRQn_Type)irqn);
76}
77/*---------------------------------------------------------------------------*/
78void
79nrf_802154_irq_enable(uint32_t irqn)
80{
81 NVIC_EnableIRQ((IRQn_Type)irqn);
82}
83/*---------------------------------------------------------------------------*/
84void
85nrf_802154_irq_disable(uint32_t irqn)
86{
87 NVIC_DisableIRQ((IRQn_Type)irqn);
88}
89/*---------------------------------------------------------------------------*/
90void
91nrf_802154_irq_set_pending(uint32_t irqn)
92{
93 NVIC_SetPendingIRQ((IRQn_Type)irqn);
94}
95/*---------------------------------------------------------------------------*/
96void
97nrf_802154_irq_clear_pending(uint32_t irqn)
98{
99 NVIC_ClearPendingIRQ((IRQn_Type)irqn);
100}
101/*---------------------------------------------------------------------------*/
102bool
103nrf_802154_irq_is_enabled(uint32_t irqn)
104{
105 return NVIC_GetEnableIRQ((IRQn_Type)irqn) != 0;
106}
107/*---------------------------------------------------------------------------*/
108uint32_t
109nrf_802154_irq_priority_get(uint32_t irqn)
110{
111 return NVIC_GetPriority((IRQn_Type)irqn);
112}
113/*---------------------------------------------------------------------------*/
114#if !NRF_802154_INTERNAL_RADIO_IRQ_HANDLING
115/* When internal RADIO IRQ handling is enabled, nrf_802154_trx.c provides
116 * RADIO_IRQHandler itself, so only define it here in the external case. */
117void
118RADIO_IRQHandler(void)
119{
120 if(radio_isr != NULL) {
121 radio_isr();
122 }
123}
124#endif
125/*---------------------------------------------------------------------------*/
126#if !NRF_802154_INTERNAL_SWI_IRQ_HANDLING
127void
128EGU0_IRQHandler(void)
129{
130 if(egu_isr != NULL) {
131 egu_isr();
132 }
133}
134#endif
135/*---------------------------------------------------------------------------*/