drivers: hwinfo: add driver support for Nordic NRF device ID
Add driver support for Nordic NRF ID device. This device has an ID of 8 bytes. Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
This commit is contained in:
parent
8f3e6ab5d2
commit
841f72f81e
3 changed files with 37 additions and 0 deletions
|
@ -2,3 +2,4 @@ zephyr_sources_ifdef(CONFIG_USERSPACE hwinfo_handlers.c)
|
|||
zephyr_sources_ifdef(CONFIG_HWINFO hwinfo_weak_impl.c)
|
||||
|
||||
zephyr_sources_ifdef(CONFIG_HWINFO_STM32 hwinfo_stm32.c)
|
||||
zephyr_sources_ifdef(CONFIG_HWINFO_NRF hwinfo_nrf.c)
|
||||
|
|
|
@ -21,4 +21,11 @@ config HWINFO_STM32
|
|||
help
|
||||
Enable STM32 hwinfo driver.
|
||||
|
||||
config HWINFO_NRF
|
||||
bool "NRF device ID"
|
||||
default y
|
||||
depends on (SOC_SERIES_NRF52X || SOC_SERIES_NRF51X)
|
||||
help
|
||||
Enable Nordic NRF hwinfo driver.
|
||||
|
||||
endif
|
||||
|
|
29
drivers/hwinfo/hwinfo_nrf.c
Normal file
29
drivers/hwinfo/hwinfo_nrf.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Alexander Wachter
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <soc.h>
|
||||
#include <hwinfo.h>
|
||||
#include <string.h>
|
||||
|
||||
struct nrf_uid {
|
||||
u32_t id[2];
|
||||
};
|
||||
|
||||
ssize_t _impl_hwinfo_get_device_id(u8_t *buffer, size_t length)
|
||||
{
|
||||
struct nrf_uid dev_id;
|
||||
|
||||
dev_id.id[0] = NRF_FICR->DEVICEID[0];
|
||||
dev_id.id[1] = NRF_FICR->DEVICEID[1];
|
||||
|
||||
if (length > sizeof(dev_id.id)) {
|
||||
length = sizeof(dev_id.id);
|
||||
}
|
||||
|
||||
memcpy(buffer, dev_id.id, length);
|
||||
|
||||
return length;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue