blob: 984b7fe7e145837823e110acee0a67758157914c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include <stdio.h>
#include <zephyr/devicetree.h>
#include "uid64.h"
#define UID64_NODE DT_NODELABEL(uid64)
uint64_t uid64_get(void) {
#if DT_NODE_EXISTS(UID64_NODE)
return *(volatile uint64_t *) DT_REG_ADDR(UID64_NODE);
#else
return 0;
#endif
}
void uid64_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 uid64_available(void) {
#if DT_NODE_EXISTS(UID64_NODE)
return true;
#else
return false;
#endif
}
|