drivers: ieee802154: nrf5: load EUI64 from UICR

Add `IEEE802154_NRF5_UICR_EUI64_ENABLE` option to allow loading EUI64
from UICR registers.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
This commit is contained in:
Eduardo Montoya 2021-02-11 09:09:52 +01:00 committed by Jukka Rissanen
parent 32451230e2
commit 53fd3ae573
2 changed files with 45 additions and 3 deletions

View file

@ -43,4 +43,28 @@ config IEEE802154_NRF5_EXT_IRQ_MGMT
the system. One example of external radio IRQ provider could be
a radio arbiter used in dynamic multiprotocol applications.
config IEEE802154_NRF5_UICR_EUI64_ENABLE
bool "Enables using EUI64 value stored in UICR registers"
depends on !IEEE802154_VENDOR_OUI_ENABLE
depends on SOC_SERIES_NRF52X || SOC_SERIES_NRF53X
help
This option enables setting custom vendor EUI64 value
stored in User information configuration registers (UICR).
Notice that this disables the default setting of EUI64
value from Factory information configuration registers
(FICR).
if IEEE802154_NRF5_UICR_EUI64_ENABLE
config IEEE802154_NRF5_UICR_EUI64_REG
int "UICR base register for the EUI64 value"
range 0 30 if SOC_SERIES_NRF52X
range 0 190 if SOC_SERIES_NRF53X
default 0
help
Base of the two consecutive registers from the UICR customer
section in which custom EUI64 is stored.
endif # IEEE802154_NRF5_UICR_EUI64_ENABLE
endif

View file

@ -58,11 +58,27 @@ static struct nrf5_802154_data nrf5_data;
#define FRAME_PENDING_BIT (1 << 4)
#define TXTIME_OFFSET_US (5 * USEC_PER_MSEC)
#if defined(CONFIG_IEEE802154_NRF5_UICR_EUI64_ENABLE)
#if defined(CONFIG_SOC_NRF5340_CPUAPP)
#define EUI64_ADDR (NRF_UICR->OTP)
#else
#define EUI64_ADDR (NRF_UICR->CUSTOMER)
#endif /* CONFIG_SOC_NRF5340_CPUAPP */
#else
#if defined(CONFIG_SOC_NRF5340_CPUAPP) || defined(CONFIG_SOC_NRF5340_CPUNET)
#define EUI64_ADDR (NRF_FICR->INFO.DEVICEID)
#else
#define EUI64_ADDR (NRF_FICR->DEVICEID)
#endif
#endif /* CONFIG_SOC_NRF5340_CPUAPP || CONFIG_SOC_NRF5340_CPUNET */
#endif /* CONFIG_IEEE802154_NRF5_UICR_EUI64_ENABLE */
#if defined(CONFIG_IEEE802154_NRF5_UICR_EUI64_ENABLE)
#define EUI64_ADDR_HIGH CONFIG_IEEE802154_NRF5_UICR_EUI64_REG
#define EUI64_ADDR_LOW (CONFIG_IEEE802154_NRF5_UICR_EUI64_REG + 1)
#else
#define EUI64_ADDR_HIGH 0
#define EUI64_ADDR_LOW 1
#endif /* CONFIG_IEEE802154_NRF5_UICR_EUI64_ENABLE */
/* Convenience defines for RADIO */
#define NRF5_802154_DATA(dev) \
@ -82,18 +98,20 @@ static void nrf5_get_eui64(uint8_t *mac)
uint64_t factoryAddress;
uint32_t index = 0;
#if !defined(CONFIG_IEEE802154_NRF5_UICR_EUI64_ENABLE)
/* Set the MAC Address Block Larger (MA-L) formerly called OUI. */
mac[index++] = (IEEE802154_NRF5_VENDOR_OUI >> 16) & 0xff;
mac[index++] = (IEEE802154_NRF5_VENDOR_OUI >> 8) & 0xff;
mac[index++] = IEEE802154_NRF5_VENDOR_OUI & 0xff;
#endif
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && \
defined(CONFIG_TRUSTED_EXECUTION_NONSECURE)
#error Accessing EUI64 on the non-secure mode is not supported at the moment
#else
/* Use device identifier assigned during the production. */
factoryAddress = (uint64_t)EUI64_ADDR[0] << 32;
factoryAddress |= EUI64_ADDR[1];
factoryAddress = (uint64_t)EUI64_ADDR[EUI64_ADDR_HIGH] << 32;
factoryAddress |= EUI64_ADDR[EUI64_ADDR_LOW];
#endif
memcpy(mac + index, &factoryAddress, sizeof(factoryAddress) - index);
}