|
27 | 27 | #include "hal/hal_flash.h" |
28 | 28 | #include "hal/hal_system.h" |
29 | 29 | #include "mcu/nrf52_hal.h" |
| 30 | +#include "mcu/nrf52_hw_id.h" |
30 | 31 | #include "mcu/nrf52_periph.h" |
31 | 32 | #include "bsp/bsp.h" |
32 | 33 |
|
@@ -95,6 +96,63 @@ hal_bsp_get_nvic_priority(int irq_num, uint32_t pri) |
95 | 96 | return cfg_pri; |
96 | 97 | } |
97 | 98 |
|
| 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 | + |
98 | 156 | void |
99 | 157 | hal_bsp_init(void) |
100 | 158 | { |
|
0 commit comments