summaryrefslogtreecommitdiff
path: root/ports/esp32s2/common-hal/microcontroller/Processor.c
diff options
context:
space:
mode:
authordherrada <33632497+dherrada@users.noreply.github.com>2020-07-17 14:55:30 -0400
committerGitHub <noreply@github.com>2020-07-17 14:55:30 -0400
commit612c6bb86b8762aa9388566eb69db9bbe4e8bbe4 (patch)
treee6fed04531c6772ea4724a75e3a88b8521e60703 /ports/esp32s2/common-hal/microcontroller/Processor.c
parentd64b4e305929ccb68e0cf1ef977f42e213023f3b (diff)
parent88d89563783771daba2973eb8dc3faa237ba4b62 (diff)
Merge branch 'main' into type_hints
Diffstat (limited to 'ports/esp32s2/common-hal/microcontroller/Processor.c')
-rw-r--r--ports/esp32s2/common-hal/microcontroller/Processor.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/ports/esp32s2/common-hal/microcontroller/Processor.c b/ports/esp32s2/common-hal/microcontroller/Processor.c
index 8eaf1a33d..39b85a18b 100644
--- a/ports/esp32s2/common-hal/microcontroller/Processor.c
+++ b/ports/esp32s2/common-hal/microcontroller/Processor.c
@@ -26,10 +26,14 @@
*/
#include <math.h>
+#include <string.h>
+
#include "common-hal/microcontroller/Processor.h"
#include "py/runtime.h"
#include "supervisor/shared/translate.h"
+#include "soc/efuse_reg.h"
+
float common_hal_mcu_processor_get_temperature(void) {
return NAN;
}
@@ -42,5 +46,23 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
return 0;
}
+STATIC uint8_t swap_nibbles(uint8_t v) {
+ return ((v << 4) | (v >> 4)) & 0xff;
+}
+
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
+ memset(raw_id, 0, COMMON_HAL_MCU_PROCESSOR_UID_LENGTH);
+
+ uint8_t *ptr = &raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH-1];
+ // MAC address contains 48 bits (6 bytes), 32 in the low order word
+ uint32_t mac_address_part = REG_READ(EFUSE_RD_MAC_SPI_SYS_0_REG);
+ *ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8;
+ *ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8;
+ *ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8;
+ *ptr-- = swap_nibbles(mac_address_part & 0xff);
+
+ // and 16 in the high order word
+ mac_address_part = REG_READ(EFUSE_RD_MAC_SPI_SYS_1_REG);
+ *ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8;
+ *ptr-- = swap_nibbles(mac_address_part & 0xff);
}