|
| 1 | +/* |
| 2 | + * Copyright (c) 2018-2025 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#include <nrf_error.h> |
| 8 | +#include <nrf_soc.h> |
| 9 | +#include <stdlib.h> |
| 10 | + |
| 11 | +#include <bm/bluetooth/ble_radio_notification.h> |
| 12 | +#include <zephyr/logging/log.h> |
| 13 | + |
| 14 | +#if CONFIG_UNITY |
| 15 | +#include <cmsis.h> |
| 16 | +#endif |
| 17 | + |
| 18 | +LOG_MODULE_REGISTER(ble_radio_ntf, CONFIG_BLE_RADIO_NOTIFICATION_LOG_LEVEL); |
| 19 | + |
| 20 | +/* Radio notification type. */ |
| 21 | +#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE) |
| 22 | +#define NOTIFICATION_TYPE NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE |
| 23 | +#elif defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_INACTIVE) |
| 24 | +#define NOTIFICATION_TYPE NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE |
| 25 | +#else |
| 26 | +#define NOTIFICATION_TYPE NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH |
| 27 | +#endif |
| 28 | + |
| 29 | +/* Application event handler for handling Radio Notification events. */ |
| 30 | +static ble_radio_notification_evt_handler_t evt_handler; |
| 31 | + |
| 32 | +void radio_notification_isr(const void *arg) |
| 33 | +{ |
| 34 | + static bool radio_active = IS_ENABLED(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE); |
| 35 | + |
| 36 | + ARG_UNUSED(arg); |
| 37 | + |
| 38 | +#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH) |
| 39 | + radio_active = !radio_active; |
| 40 | +#endif |
| 41 | + |
| 42 | + if (evt_handler) { |
| 43 | + evt_handler(radio_active); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +uint32_t ble_radio_notification_init(uint32_t distance, |
| 48 | + ble_radio_notification_evt_handler_t notif_evt_handler) |
| 49 | +{ |
| 50 | + if (!notif_evt_handler) { |
| 51 | + return NRF_ERROR_NULL; |
| 52 | + } |
| 53 | + |
| 54 | + evt_handler = notif_evt_handler; |
| 55 | + |
| 56 | + /* Initialize Radio Notification software interrupt */ |
| 57 | + IRQ_DIRECT_CONNECT(RADIO_NOTIFICATION_IRQn, CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO, |
| 58 | + radio_notification_isr, 0); |
| 59 | + |
| 60 | + NVIC_ClearPendingIRQ(RADIO_NOTIFICATION_IRQn); |
| 61 | + NVIC_EnableIRQ(RADIO_NOTIFICATION_IRQn); |
| 62 | + |
| 63 | + return sd_radio_notification_cfg_set(NOTIFICATION_TYPE, distance); |
| 64 | +} |
0 commit comments