2021-05-18 23:28:19 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021 NXP
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DT_DRV_COMPAT nxp_lpc_uid
|
|
|
|
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/hwinfo.h>
|
2021-05-18 23:28:19 +08:00
|
|
|
#include <string.h>
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/sys/byteorder.h>
|
2021-05-18 23:28:19 +08:00
|
|
|
|
2022-07-29 14:11:28 +08:00
|
|
|
#define UID_WORD_COUNT (DT_INST_REG_SIZE(0) / sizeof(uint32_t))
|
|
|
|
|
|
|
|
struct uid {
|
|
|
|
uint32_t id[UID_WORD_COUNT];
|
|
|
|
};
|
|
|
|
|
2021-05-18 23:28:19 +08:00
|
|
|
ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
|
|
|
|
{
|
2022-07-29 14:11:28 +08:00
|
|
|
volatile const uint32_t * const uid_addr = (uint32_t *) DT_INST_REG_ADDR(0);
|
|
|
|
struct uid dev_id;
|
2021-05-18 23:28:19 +08:00
|
|
|
|
|
|
|
if (buffer == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-29 14:11:28 +08:00
|
|
|
for (size_t i = 0 ; i < UID_WORD_COUNT ; i++) {
|
|
|
|
dev_id.id[i] = sys_cpu_to_be32(uid_addr[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length > sizeof(dev_id.id)) {
|
|
|
|
length = sizeof(dev_id.id);
|
2021-05-18 23:28:19 +08:00
|
|
|
}
|
|
|
|
|
2022-07-29 14:11:28 +08:00
|
|
|
memcpy(buffer, dev_id.id, length);
|
2021-05-18 23:28:19 +08:00
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|