extmod/modmachine: Factor ports' machine module dict to common code.

This is a code factoring to have the dict for the machine module in one
location, and all the ports use that same dict.  The machine.soft_reset()
function implementation is also factored because it's the same for all
ports that did already implement it.  Eventually more functions/bindings
can be factored.

All ports remain functionally the same, except:
- cc3200 port: gains soft_reset, mem8, mem16, mem32, Signal; loses POWER_ON
  (which was a legacy constant, replaced long ago by PWRON_RESET)
- nrf port: gains Signal
- qemu-arm port: gains soft_reset
- unix port: gains soft_reset
- zephyr port: gains soft_reset, mem8, mem16, mem32

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2023-11-22 13:00:02 +11:00
parent 14432b5da0
commit 7d39db2503
44 changed files with 550 additions and 922 deletions

View File

@@ -200,7 +200,6 @@ SRC_C += \
unix_mphal.c \
mpthreadport.c \
input.c \
modmachine.c \
alloc.c \
fatfs_port.c \
mpbthciport.c \

View File

@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2013-2023 Damien P. George
* Copyright (c) 2015 Paul Sokolovsky
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -25,13 +25,8 @@
* THE SOFTWARE.
*/
#include <stdio.h>
#include <stdint.h>
#include "py/runtime.h"
#include "py/obj.h"
#include "extmod/modmachine.h"
// This file is never compiled standalone, it's included directly from
// extmod/modmachine.c via MICROPY_PY_MACHINE_INCLUDEFILE.
#if MICROPY_PLAT_DEV_MEM
#include <errno.h>
@@ -41,7 +36,18 @@
#define MICROPY_PAGE_MASK (MICROPY_PAGE_SIZE - 1)
#endif
#if MICROPY_PY_MACHINE
#ifdef MICROPY_UNIX_MACHINE_IDLE
#define MICROPY_PY_MACHINE_IDLE_ENTRY { MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },
#else
#define MICROPY_PY_MACHINE_IDLE_ENTRY
#endif
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
MICROPY_PY_MACHINE_IDLE_ENTRY \
{ MP_ROM_QSTR(MP_QSTR_PinBase), MP_ROM_PTR(&machine_pinbase_type) }, \
// This variable is needed for machine.soft_reset(), but the variable is otherwise unused.
int pyexec_system_exit = 0;
uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) {
uintptr_t addr = mp_obj_get_int_truncated(addr_o);
@@ -81,32 +87,3 @@ STATIC mp_obj_t machine_idle(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);
#endif
STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) },
{ MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) },
{ MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) },
{ MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) },
#ifdef MICROPY_UNIX_MACHINE_IDLE
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },
#endif
{ MP_ROM_QSTR(MP_QSTR_PinBase), MP_ROM_PTR(&machine_pinbase_type) },
{ MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) },
#if MICROPY_PY_MACHINE_PULSE
{ MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) },
#endif
};
STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table);
const mp_obj_module_t mp_module_machine = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&machine_module_globals,
};
MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine);
#endif // MICROPY_PY_MACHINE

View File

@@ -134,6 +134,9 @@ typedef long mp_off_t;
#define MICROPY_STACKLESS_STRICT (0)
#endif
// Implementation of the machine module.
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/unix/modmachine.c"
// Unix-specific configuration of machine.mem*.
#define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr
#define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr