13 #if RUUVI_NRF5_SDK15_RADIO_ENABLED
22 #include "nordic_common.h"
25 #include "nrf_sdh_ble.h"
27 #include "ble_advdata.h"
28 #include "ble_radio_notification.h"
29 #include "sdk_errors.h"
37 # define PHY_RAM_START 0x20000000
48 static void on_radio_evt (
bool active)
55 if (NULL != on_radio_activity_callback) { on_radio_activity_callback (evt); }
61 ret_code_t err_code = NRF_SUCCESS;
73 err_code = nrf_sdh_enable_request();
77 uint32_t ram_start = 0;
87 err_code |= nrf_sdh_ble_enable (&ram_start);
89 static ble_opt_t opt = {0};
90 opt.common_opt.conn_evt_ext.enable =
true;
91 err_code |= sd_ble_opt_set (BLE_COMMON_OPT_CONN_EVT_EXT, &opt);
95 NRF_RADIO_NOTIFICATION_DISTANCE_800US,
98 m_modulation = modulation;
107 nrf_sdh_disable_request();
109 sd_softdevice_disable();
110 on_radio_activity_callback = NULL;
126 uint32_t status = NRF_SUCCESS;
133 mac |= (uint64_t) ( (NRF_FICR->DEVICEADDR[0] >> 0) & 0xFF) << 0;
134 mac |= (uint64_t) ( (NRF_FICR->DEVICEADDR[0] >> 8) & 0xFF) << 8;
135 mac |= (uint64_t) ( (NRF_FICR->DEVICEADDR[0] >> 16) & 0xFF) << 16;
136 mac |= (uint64_t) ( (NRF_FICR->DEVICEADDR[0] >> 24) & 0xFF) << 24;
137 mac |= (uint64_t) ( (NRF_FICR->DEVICEADDR[1] >> 0) & 0xFF) << 32;
138 mac |= (uint64_t) ( (NRF_FICR->DEVICEADDR[1] >> 8 | 0xC0) & 0xFF) << 40;
143 addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
144 status |= sd_ble_gap_addr_get (&addr);
145 mac |= (uint64_t) (addr.addr[0]) << 0;
146 mac |= (uint64_t) (addr.addr[1]) << 8;
147 mac |= (uint64_t) (addr.addr[2]) << 16;
148 mac |= (uint64_t) (addr.addr[3]) << 24;
149 mac |= (uint64_t) (addr.addr[4]) << 32;
150 mac |= (uint64_t) (addr.addr[5]) << 40;
160 addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
161 addr.addr[0] = address >> 0;
162 addr.addr[1] = address >> 8;
163 addr.addr[2] = address >> 16;
164 addr.addr[3] = address >> 24;
165 addr.addr[4] = address >> 32;
166 addr.addr[5] = address >> 40;
174 if (NULL != handler && NULL != on_radio_activity_callback)
180 on_radio_activity_callback = handler;
186 return nrf_sdh_is_enabled();
193 if (NULL == p_modulation)
203 *p_modulation = m_modulation;
210 uint8_t ruuvi_nrf5_sdk15_radio_phy_get (
void)
212 uint8_t nrf_modulation = BLE_GAP_PHY_NOT_SET;
221 nrf_modulation = BLE_GAP_PHY_CODED;
225 nrf_modulation = BLE_GAP_PHY_1MBPS;
229 nrf_modulation = BLE_GAP_PHY_2MBPS;
233 nrf_modulation = BLE_GAP_PHY_NOT_SET;
238 return nrf_modulation;
241 void ruuvi_nrf5_sdk15_radio_channels_set (uint8_t *
const nrf_channels,
244 memset (nrf_channels, 0,
sizeof (ble_gap_ch_mask_t));
245 nrf_channels[4] |= (!channels.
channel_37) << 5;
246 nrf_channels[4] |= (!channels.
channel_38) << 6;
247 nrf_channels[4] |= (!channels.
channel_39) << 7;
252 bool supported =
false;
#define RD_ERROR_INVALID_PARAM
Invalid Parameter.
#define RD_ERROR_NULL
Null Pointer.
#define RD_ERROR_FATAL
Program should always reset after this.
uint32_t rd_status_t
bitfield for representing errors
rd_status_t ruuvi_nrf5_sdk15_to_ruuvi_error(const ret_code_t error)
convert nrf5 sdk15 error code into Ruuvi error code.
#define RD_ERROR_CHECK(error, mask)
Shorthand macro for calling the rd_error_check with current file & line.
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
void ri_radio_activity_callback_set(const ri_radio_activity_interrupt_fp_t handler)
Setup radio activity interrupt.
rd_status_t ri_radio_get_modulation(ri_radio_modulation_t *const p_modulation)
Get the modulation used by application.
bool ri_radio_is_init()
Check if radio is initialized.
ri_radio_activity_evt_t
radio activity event type.
rd_status_t ri_radio_init(const ri_radio_modulation_t modulation)
Enable radio stack for an user. This function also starts radio activity callbacks internally.
rd_status_t ri_radio_uninit()
Release radio stack.
rd_status_t ri_radio_address_get(uint64_t *const address)
bool ri_radio_supports(ri_radio_modulation_t modulation)
Check if radio supports given modulation.
void(* ri_radio_activity_interrupt_fp_t)(const ri_radio_activity_evt_t evt)
Type of radio activity interrupt. This is common to all radio modules, i,e, the callback gets called ...
ri_radio_modulation_t
type of radio modulation to be used.
rd_status_t ri_radio_address_set(uint64_t const address)
@ RI_RADIO_AFTER
Event is after radio activity, i.e. radio was turned off.
@ RI_RADIO_BEFORE
Event is before radio goes active, i.e. radio turns on soon.
@ RI_RADIO_BLE_1MBPS
"Normal" BLE 4 modulation
@ RI_RADIO_BLE_2MBPS
"Fast BLE". Advertising uses 1MBPS primary advertisement followed by 2 MBit/s extended advertisement.
@ RI_RADIO_BLE_125KBPS
Also known as BLE Long Range S=8.
#define RUUVI_NRF5_SDK15_RADIO_IRQ_PRIORITY
priorities 0,1, 4,5 are reserved by SD
#define RUUVI_NRF5_SDK15_BLE4_STACK_CONN_TAG
< Check if NRF_NFC is required
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Bitfield to describe related sensor data.
uint8_t channel_37
BLE channel 37, 2402 MHz.
uint8_t channel_39
BLE channel 39, 2480 MHz.
uint8_t channel_38
BLE channel 38, 2426 MHz.