Skip to content

Commit 0e3b57e

Browse files
hw/bsp/nordic: Implement new hal_bsp API for provisioned data
1 parent e9d6b2f commit 0e3b57e

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

hw/bsp/nordic_pca10056/src/hal_bsp.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "hal/hal_flash.h"
2828
#include "hal/hal_system.h"
2929
#include "mcu/nrf52_hal.h"
30+
#include "mcu/nrf52_hw_id.h"
3031
#include "mcu/nrf52_periph.h"
3132
#include "bsp/bsp.h"
3233

@@ -95,6 +96,63 @@ hal_bsp_get_nvic_priority(int irq_num, uint32_t pri)
9596
return cfg_pri;
9697
}
9798

99+
static int
100+
prov_data_hw_id(void *data, uint16_t *length)
101+
{
102+
uint16_t len = nrf52_hw_id_len();
103+
104+
if (*length < len) {
105+
*length = len;
106+
return SYS_ENOMEM;
107+
}
108+
109+
*length = nrf52_hw_id(data, *length);
110+
111+
return 0;
112+
}
113+
114+
static int
115+
prov_data_ble_public_addr(void *data, uint16_t *length)
116+
{
117+
if ((NRF_FICR->DEVICEADDRTYPE & 1) != 0) {
118+
return SYS_ENOENT;
119+
}
120+
121+
memcpy(data, (void *)&NRF_FICR->DEVICEADDR[0], 6);
122+
123+
return 0;
124+
}
125+
126+
static int
127+
prov_data_ble_static_addr(void *data, uint16_t *length)
128+
{
129+
uint8_t *addr = data;
130+
131+
if ((NRF_FICR->DEVICEADDRTYPE & 1) == 0) {
132+
return SYS_ENOENT;
133+
}
134+
135+
memcpy(data, (void *)&NRF_FICR->DEVICEADDR[0], 6);
136+
addr[5] |= 0xc0;
137+
138+
return 0;
139+
}
140+
141+
int
142+
hal_bsp_prov_data_get_int(uint16_t id, void *data, uint16_t *length)
143+
{
144+
switch (id) {
145+
case HAL_BSP_PROV_HW_ID:
146+
return prov_data_hw_id(data, length);
147+
case HAL_BSP_PROV_BLE_PUBLIC_ADDR:
148+
return prov_data_ble_public_addr(data, length);
149+
case HAL_BSP_PROV_BLE_STATIC_ADDR:
150+
return prov_data_ble_static_addr(data, length);
151+
}
152+
153+
return SYS_ENOTSUP;
154+
}
155+
98156
void
99157
hal_bsp_init(void)
100158
{

0 commit comments

Comments
 (0)