summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2021-09-12 17:57:01 +0200
committerDamien George <damien@micropython.org>2021-10-25 23:53:48 +1100
commit6754213a9d54f7c57005794824dd6aabd71855c8 (patch)
tree81dd3b03234b8b9b35b1c66a5b3daa6dc960a3c7
parenta12e318948cc422950751f61563b46784eb6b665 (diff)
mimxrt/modmachine: Implement soft_reset() and unique_id() functions.
-rw-r--r--ports/mimxrt/modmachine.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/ports/mimxrt/modmachine.c b/ports/mimxrt/modmachine.c
index d4078d566..a05c81a40 100644
--- a/ports/mimxrt/modmachine.c
+++ b/ports/mimxrt/modmachine.c
@@ -32,10 +32,12 @@
#include "extmod/machine_pulse.h"
#include "extmod/machine_signal.h"
#include "extmod/machine_spi.h"
+#include "shared/runtime/pyexec.h"
#include "led.h"
#include "pin.h"
#include "modmachine.h"
#include "fsl_clock.h"
+#include "fsl_ocotp.h"
#include "fsl_wdog.h"
#include CPU_HEADER_H
@@ -48,6 +50,21 @@ typedef enum {
MP_SOFT_RESET
} reset_reason_t;
+STATIC mp_obj_t machine_unique_id(void) {
+ unsigned char id[8];
+ OCOTP_Init(OCOTP, CLOCK_GetFreq(kCLOCK_IpgClk));
+ *(uint32_t *)&id[0] = OCOTP->CFG0;
+ *(uint32_t *)&id[4] = OCOTP->CFG1;
+ return mp_obj_new_bytes(id, sizeof(id));
+}
+MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
+
+STATIC mp_obj_t machine_soft_reset(void) {
+ pyexec_system_exit = PYEXEC_FORCED_EXIT;
+ mp_raise_type(&mp_type_SystemExit);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset);
+
STATIC mp_obj_t machine_reset(void) {
WDOG_TriggerSystemSoftwareReset(WDOG1);
return mp_const_none;
@@ -94,6 +111,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq);
STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) },
+ { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) },
+ { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) },