From bfb77d05444e68462caaa38fb6f72b223799870a Mon Sep 17 00:00:00 2001 From: MicroDev <70126934+MicroDev1@users.noreply.github.com> Date: Thu, 26 Jan 2023 13:01:14 +0530 Subject: [PATCH] move `ULPArch` to `Architecture` --- .../espulp/{ULPArch.c => Architecture.c} | 24 ++++++++--------- .../espulp/{ULPArch.h => Architecture.h} | 12 ++++----- ports/espressif/bindings/espulp/ULP.c | 26 +++++++++---------- ports/espressif/bindings/espulp/ULP.h | 2 +- ports/espressif/bindings/espulp/ULPAlarm.c | 7 +++-- ports/espressif/bindings/espulp/ULPAlarm.h | 2 +- ports/espressif/bindings/espulp/__init__.c | 4 +-- ports/espressif/common-hal/espulp/ULP.c | 2 +- ports/espressif/common-hal/espulp/ULP.h | 4 +-- ports/espressif/common-hal/espulp/ULPAlarm.c | 4 +++ 10 files changed, 47 insertions(+), 40 deletions(-) rename ports/espressif/bindings/espulp/{ULPArch.c => Architecture.c} (70%) rename ports/espressif/bindings/espulp/{ULPArch.h => Architecture.h} (81%) diff --git a/ports/espressif/bindings/espulp/ULPArch.c b/ports/espressif/bindings/espulp/Architecture.c similarity index 70% rename from ports/espressif/bindings/espulp/ULPArch.c rename to ports/espressif/bindings/espulp/Architecture.c index 01f61458c1..d87691716c 100644 --- a/ports/espressif/bindings/espulp/ULPArch.c +++ b/ports/espressif/bindings/espulp/Architecture.c @@ -26,26 +26,26 @@ #include "py/enum.h" -#include "bindings/espulp/ULPArch.h" +#include "bindings/espulp/Architecture.h" -MAKE_ENUM_VALUE(espulp_ulparch_type, ulparch, FSM, FSM); -MAKE_ENUM_VALUE(espulp_ulparch_type, ulparch, RISCV, RISCV); +MAKE_ENUM_VALUE(espulp_architecture_type, architecture, FSM, FSM); +MAKE_ENUM_VALUE(espulp_architecture_type, architecture, RISCV, RISCV); -//| class ULPArch: +//| class Architecture: //| """The ULP architectures available.""" //| -//| FSM: ULPArch +//| FSM: Architecture //| """The ULP Finite State Machine.""" //| -//| RISCV: ULPArch +//| RISCV: Architecture //| """The ULP RISC-V Coprocessor.""" //| -MAKE_ENUM_MAP(espulp_ulparch) { - MAKE_ENUM_MAP_ENTRY(ulparch, FSM), - MAKE_ENUM_MAP_ENTRY(ulparch, RISCV), +MAKE_ENUM_MAP(espulp_architecture) { + MAKE_ENUM_MAP_ENTRY(architecture, FSM), + MAKE_ENUM_MAP_ENTRY(architecture, RISCV), }; -STATIC MP_DEFINE_CONST_DICT(espulp_ulparch_locals_dict, espulp_ulparch_locals_table); +STATIC MP_DEFINE_CONST_DICT(espulp_architecture_locals_dict, espulp_architecture_locals_table); -MAKE_PRINTER(espulp, espulp_ulparch); +MAKE_PRINTER(espulp, espulp_architecture); -MAKE_ENUM_TYPE(espulp, ULPArch, espulp_ulparch); +MAKE_ENUM_TYPE(espulp, Architecture, espulp_architecture); diff --git a/ports/espressif/bindings/espulp/ULPArch.h b/ports/espressif/bindings/espulp/Architecture.h similarity index 81% rename from ports/espressif/bindings/espulp/ULPArch.h rename to ports/espressif/bindings/espulp/Architecture.h index 1b1e8a1331..54c0677f05 100644 --- a/ports/espressif/bindings/espulp/ULPArch.h +++ b/ports/espressif/bindings/espulp/Architecture.h @@ -24,17 +24,17 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_BINDINGS_ESPULP_ULPARCH_H -#define MICROPY_INCLUDED_BINDINGS_ESPULP_ULPARCH_H +#ifndef MICROPY_INCLUDED_BINDINGS_ESPULP_ARCHITECTURE_H +#define MICROPY_INCLUDED_BINDINGS_ESPULP_ARCHITECTURE_H #include "py/enum.h" typedef enum { FSM, RISCV -} espulp_ulparch_t; +} espulp_architecture_t; -extern const mp_obj_type_t espulp_ulparch_type; -extern const cp_enum_obj_t ulparch_FSM_obj; +extern const mp_obj_type_t espulp_architecture_type; +extern const cp_enum_obj_t architecture_FSM_obj; -#endif // MICROPY_INCLUDED_BINDINGS_ESPULP_ULPARCH_H +#endif // MICROPY_INCLUDED_BINDINGS_ESPULP_ARCHITECTURE_H diff --git a/ports/espressif/bindings/espulp/ULP.c b/ports/espressif/bindings/espulp/ULP.c index 3506a3067b..c9666fb143 100644 --- a/ports/espressif/bindings/espulp/ULP.c +++ b/ports/espressif/bindings/espulp/ULP.c @@ -33,24 +33,24 @@ #include "py/objproperty.h" //| class ULP: -//| def __init__(self, arch: ULPArch = ULPArch.FSM): +//| def __init__(self, arch: Architecture = Architecture.FSM): //| """The ultra-low-power processor. //| //| Raises an exception if another ULP has been instantiated. This //| ensures that is is only used by one piece of code at a time. //| -//| :param ULPArch arch: The ulp arch""" +//| :param Architecture arch: The ulp arch""" //| ... STATIC mp_obj_t espulp_ulp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_arch }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_arch, MP_ARG_OBJ, {.u_obj = (void *)&ulparch_FSM_obj} }, + { MP_QSTR_arch, MP_ARG_OBJ, {.u_obj = (void *)&architecture_FSM_obj} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const espulp_ulparch_t arch = cp_enum_value(&espulp_ulparch_type, args[ARG_arch].u_obj, MP_QSTR_arch); + const espulp_architecture_t arch = cp_enum_value(&espulp_architecture_type, args[ARG_arch].u_obj, MP_QSTR_arch); espulp_ulp_obj_t *self = m_new_obj(espulp_ulp_obj_t); self->base.type = &espulp_ulp_type; @@ -149,14 +149,14 @@ STATIC mp_obj_t espulp_ulp_halt(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(espulp_ulp_halt_obj, espulp_ulp_halt); -//| arch: ULPArch -//| """The ulp arch. (read-only)""" +//| arch: Architecture +//| """The ulp architecture. (read-only)""" //| STATIC mp_obj_t espulp_ulp_get_arch(mp_obj_t self_in) { espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); - return cp_enum_find(&espulp_ulparch_type, self->arch); + return cp_enum_find(&espulp_architecture_type, self->arch); } MP_DEFINE_CONST_FUN_OBJ_1(espulp_ulp_get_arch_obj, espulp_ulp_get_arch); @@ -164,12 +164,12 @@ MP_PROPERTY_GETTER(espulp_ulp_arch_obj, (mp_obj_t)&espulp_ulp_get_arch_obj); STATIC const mp_rom_map_elem_t espulp_ulp_locals_table[] = { - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&espulp_ulp_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&espulp_ulp___exit___obj) }, - { MP_ROM_QSTR(MP_QSTR_run), MP_ROM_PTR(&espulp_ulp_run_obj) }, - { MP_ROM_QSTR(MP_QSTR_halt), MP_ROM_PTR(&espulp_ulp_halt_obj) }, - { MP_ROM_QSTR(MP_QSTR_arch), MP_ROM_PTR(&espulp_ulp_arch_obj) }, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&espulp_ulp_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&espulp_ulp___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_run), MP_ROM_PTR(&espulp_ulp_run_obj) }, + { MP_ROM_QSTR(MP_QSTR_halt), MP_ROM_PTR(&espulp_ulp_halt_obj) }, + { MP_ROM_QSTR(MP_QSTR_arch), MP_ROM_PTR(&espulp_ulp_arch_obj) }, }; STATIC MP_DEFINE_CONST_DICT(espulp_ulp_locals_dict, espulp_ulp_locals_table); diff --git a/ports/espressif/bindings/espulp/ULP.h b/ports/espressif/bindings/espulp/ULP.h index f06f783902..490cbef1ca 100644 --- a/ports/espressif/bindings/espulp/ULP.h +++ b/ports/espressif/bindings/espulp/ULP.h @@ -31,7 +31,7 @@ extern const mp_obj_type_t espulp_ulp_type; -void common_hal_espulp_ulp_construct(espulp_ulp_obj_t *self, espulp_ulparch_t arch); +void common_hal_espulp_ulp_construct(espulp_ulp_obj_t *self, espulp_architecture_t arch); bool common_hal_espulp_ulp_deinited(espulp_ulp_obj_t *self); void common_hal_espulp_ulp_deinit(espulp_ulp_obj_t *self); diff --git a/ports/espressif/bindings/espulp/ULPAlarm.c b/ports/espressif/bindings/espulp/ULPAlarm.c index 921c23d4f5..6efd1c98ef 100644 --- a/ports/espressif/bindings/espulp/ULPAlarm.c +++ b/ports/espressif/bindings/espulp/ULPAlarm.c @@ -25,9 +25,9 @@ */ #include "bindings/espulp/ULPAlarm.h" -#include "bindings/espulp/ULPArch.h" #include "py/runtime.h" +#include "py/objproperty.h" //| class ULPAlarm: //| """Trigger an alarm when the ULP requests wake-up.""" @@ -52,7 +52,10 @@ STATIC mp_obj_t espulp_ulpalarm_make_new(const mp_obj_type_t *type, size_t n_arg espulp_ulpalarm_obj_t *self = m_new_obj(espulp_ulpalarm_obj_t); self->base.type = &espulp_ulpalarm_type; - self->ulp = mp_arg_validate_type(args[ARG_ulp].u_obj, &espulp_ulp_type, MP_QSTR_ulp); + + espulp_ulp_obj_t *ulp = mp_arg_validate_type(args[ARG_ulp].u_obj, &espulp_ulp_type, MP_QSTR_ulp); + + common_hal_espulp_ulpalarm_construct(self, ulp); return MP_OBJ_FROM_PTR(self); } diff --git a/ports/espressif/bindings/espulp/ULPAlarm.h b/ports/espressif/bindings/espulp/ULPAlarm.h index 75e96c0a45..f2b2e69bba 100644 --- a/ports/espressif/bindings/espulp/ULPAlarm.h +++ b/ports/espressif/bindings/espulp/ULPAlarm.h @@ -30,4 +30,4 @@ extern const mp_obj_type_t espulp_ulpalarm_type; -void common_hal_espulp_ulpalarm_construct(espulp_ulpalarm_obj_t *self); +void common_hal_espulp_ulpalarm_construct(espulp_ulpalarm_obj_t *self, espulp_ulp_obj_t *ulp); diff --git a/ports/espressif/bindings/espulp/__init__.c b/ports/espressif/bindings/espulp/__init__.c index ff6d727ec5..f2b688dda4 100644 --- a/ports/espressif/bindings/espulp/__init__.c +++ b/ports/espressif/bindings/espulp/__init__.c @@ -29,7 +29,7 @@ #include "bindings/espulp/__init__.h" #include "bindings/espulp/ULP.h" #include "bindings/espulp/ULPAlarm.h" -#include "bindings/espulp/ULPArch.h" +#include "bindings/espulp/Architecture.h" #include "py/runtime.h" @@ -82,7 +82,7 @@ STATIC const mp_rom_map_elem_t espulp_module_globals_table[] = { // module classes { MP_ROM_QSTR(MP_QSTR_ULP), MP_OBJ_FROM_PTR(&espulp_ulp_type) }, { MP_ROM_QSTR(MP_QSTR_ULPAlarm), MP_OBJ_FROM_PTR(&espulp_ulpalarm_type) }, - { MP_ROM_QSTR(MP_QSTR_ULPArch), MP_ROM_PTR(&espulp_ulparch_type) }, + { MP_ROM_QSTR(MP_QSTR_Architecture), MP_ROM_PTR(&espulp_architecture_type) }, }; STATIC MP_DEFINE_CONST_DICT(espulp_module_globals, espulp_module_globals_table); diff --git a/ports/espressif/common-hal/espulp/ULP.c b/ports/espressif/common-hal/espulp/ULP.c index c2dfdb038b..3350f6d45c 100644 --- a/ports/espressif/common-hal/espulp/ULP.c +++ b/ports/espressif/common-hal/espulp/ULP.c @@ -133,7 +133,7 @@ void common_hal_espulp_ulp_halt(espulp_ulp_obj_t *self) { } } -void common_hal_espulp_ulp_construct(espulp_ulp_obj_t *self, espulp_ulparch_t arch) { +void common_hal_espulp_ulp_construct(espulp_ulp_obj_t *self, espulp_architecture_t arch) { // Use a static variable to track ULP in use so that subsequent code runs can // use a running ULP. This is only to prevent multiple portions of user code // from using the ULP concurrently. diff --git a/ports/espressif/common-hal/espulp/ULP.h b/ports/espressif/common-hal/espulp/ULP.h index 42081411f0..360dd0c9fd 100644 --- a/ports/espressif/common-hal/espulp/ULP.h +++ b/ports/espressif/common-hal/espulp/ULP.h @@ -27,10 +27,10 @@ #pragma once #include "py/obj.h" -#include "bindings/espulp/ULPArch.h" +#include "bindings/espulp/Architecture.h" typedef struct { mp_obj_base_t base; - espulp_ulparch_t arch; + espulp_architecture_t arch; bool inited; } espulp_ulp_obj_t; diff --git a/ports/espressif/common-hal/espulp/ULPAlarm.c b/ports/espressif/common-hal/espulp/ULPAlarm.c index e209325d68..3717d2ab71 100644 --- a/ports/espressif/common-hal/espulp/ULPAlarm.c +++ b/ports/espressif/common-hal/espulp/ULPAlarm.c @@ -37,6 +37,10 @@ static volatile bool woke_up = false; static bool alarm_set = false; +void common_hal_espulp_ulpalarm_construct(espulp_ulpalarm_obj_t *self, espulp_ulp_obj_t *ulp) { + self->ulp = ulp; +} + mp_obj_t espulp_ulpalarm_find_triggered_alarm(const size_t n_alarms, const mp_obj_t *alarms) { for (size_t i = 0; i < n_alarms; i++) { if (mp_obj_is_type(alarms[i], &espulp_ulpalarm_type)) {