diff options
| author | xengineering <me@xengineering.eu> | 2024-05-30 22:06:31 +0200 | 
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2024-05-30 22:12:34 +0200 | 
| commit | b8147bcba2e8dfef419ba14053285bc9750dc319 (patch) | |
| tree | 62a7129f0805ec2eea65ab79e63305c848762083 /firmware/src/eui64.c | |
| parent | 17008662c08e8e99aefc1814dd80d366872d7ded (diff) | |
| download | iot-core-b8147bcba2e8dfef419ba14053285bc9750dc319.tar iot-core-b8147bcba2e8dfef419ba14053285bc9750dc319.tar.zst iot-core-b8147bcba2e8dfef419ba14053285bc9750dc319.zip | |
firmware: Rename from uid64 to eui64
The term EUI-64 is more commonly known (see Wikipedia about MAC
addresses [1]). The term UID-64 was introduced because of ST
documentation.
[1]: https://en.wikipedia.org/wiki/MAC_address
Diffstat (limited to 'firmware/src/eui64.c')
| -rw-r--r-- | firmware/src/eui64.c | 42 | 
1 files changed, 42 insertions, 0 deletions
| diff --git a/firmware/src/eui64.c b/firmware/src/eui64.c new file mode 100644 index 0000000..516ff84 --- /dev/null +++ b/firmware/src/eui64.c @@ -0,0 +1,42 @@ +#include <stdio.h> +#include <stdbool.h> + +#include <zephyr/devicetree.h> + +#include "eui64.h" + +#define UID64_NODE DT_NODELABEL(eui64) + +uint64_t eui64_get(void) { +#if DT_NODE_EXISTS(UID64_NODE) +		return *(volatile uint64_t *) DT_REG_ADDR(UID64_NODE); +#else +		return 0; +#endif +} + +void eui64_to_string(uint64_t uid, char *str) { +	uint8_t *source = (uint8_t *)&uid + 7; +	char *sink = str; + +	for (unsigned int i = 0; i < 8; i++) { +		/* delimiter */ +		if (i > 0) { +			*sink = ':'; +			sink++; +		} + +		/* byte values */ +		snprintf(sink, 3, "%02x", *source); +		source--; +		sink += 2; +	} +} + +bool eui64_available(void) { +#if DT_NODE_EXISTS(UID64_NODE) +	return true; +#else +	return false; +#endif +} | 
