move ULPArch to Architecture

This commit is contained in:
MicroDev 2023-01-26 13:01:14 +05:30
parent 2bb12293f8
commit bfb77d0544
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
10 changed files with 47 additions and 40 deletions

View File

@ -26,26 +26,26 @@
#include "py/enum.h" #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_architecture_type, architecture, FSM, FSM);
MAKE_ENUM_VALUE(espulp_ulparch_type, ulparch, RISCV, RISCV); MAKE_ENUM_VALUE(espulp_architecture_type, architecture, RISCV, RISCV);
//| class ULPArch: //| class Architecture:
//| """The ULP architectures available.""" //| """The ULP architectures available."""
//| //|
//| FSM: ULPArch //| FSM: Architecture
//| """The ULP Finite State Machine.""" //| """The ULP Finite State Machine."""
//| //|
//| RISCV: ULPArch //| RISCV: Architecture
//| """The ULP RISC-V Coprocessor.""" //| """The ULP RISC-V Coprocessor."""
//| //|
MAKE_ENUM_MAP(espulp_ulparch) { MAKE_ENUM_MAP(espulp_architecture) {
MAKE_ENUM_MAP_ENTRY(ulparch, FSM), MAKE_ENUM_MAP_ENTRY(architecture, FSM),
MAKE_ENUM_MAP_ENTRY(ulparch, RISCV), 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);

View File

@ -24,17 +24,17 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef MICROPY_INCLUDED_BINDINGS_ESPULP_ULPARCH_H #ifndef MICROPY_INCLUDED_BINDINGS_ESPULP_ARCHITECTURE_H
#define MICROPY_INCLUDED_BINDINGS_ESPULP_ULPARCH_H #define MICROPY_INCLUDED_BINDINGS_ESPULP_ARCHITECTURE_H
#include "py/enum.h" #include "py/enum.h"
typedef enum { typedef enum {
FSM, FSM,
RISCV RISCV
} espulp_ulparch_t; } espulp_architecture_t;
extern const mp_obj_type_t espulp_ulparch_type; extern const mp_obj_type_t espulp_architecture_type;
extern const cp_enum_obj_t ulparch_FSM_obj; extern const cp_enum_obj_t architecture_FSM_obj;
#endif // MICROPY_INCLUDED_BINDINGS_ESPULP_ULPARCH_H #endif // MICROPY_INCLUDED_BINDINGS_ESPULP_ARCHITECTURE_H

View File

@ -33,24 +33,24 @@
#include "py/objproperty.h" #include "py/objproperty.h"
//| class ULP: //| class ULP:
//| def __init__(self, arch: ULPArch = ULPArch.FSM): //| def __init__(self, arch: Architecture = Architecture.FSM):
//| """The ultra-low-power processor. //| """The ultra-low-power processor.
//| //|
//| Raises an exception if another ULP has been instantiated. This //| Raises an exception if another ULP has been instantiated. This
//| ensures that is is only used by one piece of code at a time. //| 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) { 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 }; enum { ARG_arch };
static const mp_arg_t allowed_args[] = { 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_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); 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); espulp_ulp_obj_t *self = m_new_obj(espulp_ulp_obj_t);
self->base.type = &espulp_ulp_type; 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); STATIC MP_DEFINE_CONST_FUN_OBJ_1(espulp_ulp_halt_obj, espulp_ulp_halt);
//| arch: ULPArch //| arch: Architecture
//| """The ulp arch. (read-only)""" //| """The ulp architecture. (read-only)"""
//| //|
STATIC mp_obj_t espulp_ulp_get_arch(mp_obj_t self_in) { STATIC mp_obj_t espulp_ulp_get_arch(mp_obj_t self_in) {
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in); espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self); 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); 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); (mp_obj_t)&espulp_ulp_get_arch_obj);
STATIC const mp_rom_map_elem_t espulp_ulp_locals_table[] = { 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_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___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___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_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_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_arch), MP_ROM_PTR(&espulp_ulp_arch_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(espulp_ulp_locals_dict, espulp_ulp_locals_table); STATIC MP_DEFINE_CONST_DICT(espulp_ulp_locals_dict, espulp_ulp_locals_table);

View File

@ -31,7 +31,7 @@
extern const mp_obj_type_t espulp_ulp_type; 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); bool common_hal_espulp_ulp_deinited(espulp_ulp_obj_t *self);
void common_hal_espulp_ulp_deinit(espulp_ulp_obj_t *self); void common_hal_espulp_ulp_deinit(espulp_ulp_obj_t *self);

View File

@ -25,9 +25,9 @@
*/ */
#include "bindings/espulp/ULPAlarm.h" #include "bindings/espulp/ULPAlarm.h"
#include "bindings/espulp/ULPArch.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/objproperty.h"
//| class ULPAlarm: //| class ULPAlarm:
//| """Trigger an alarm when the ULP requests wake-up.""" //| """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); espulp_ulpalarm_obj_t *self = m_new_obj(espulp_ulpalarm_obj_t);
self->base.type = &espulp_ulpalarm_type; 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); return MP_OBJ_FROM_PTR(self);
} }

View File

@ -30,4 +30,4 @@
extern const mp_obj_type_t espulp_ulpalarm_type; 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);

View File

@ -29,7 +29,7 @@
#include "bindings/espulp/__init__.h" #include "bindings/espulp/__init__.h"
#include "bindings/espulp/ULP.h" #include "bindings/espulp/ULP.h"
#include "bindings/espulp/ULPAlarm.h" #include "bindings/espulp/ULPAlarm.h"
#include "bindings/espulp/ULPArch.h" #include "bindings/espulp/Architecture.h"
#include "py/runtime.h" #include "py/runtime.h"
@ -82,7 +82,7 @@ STATIC const mp_rom_map_elem_t espulp_module_globals_table[] = {
// module classes // module classes
{ MP_ROM_QSTR(MP_QSTR_ULP), MP_OBJ_FROM_PTR(&espulp_ulp_type) }, { 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_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); STATIC MP_DEFINE_CONST_DICT(espulp_module_globals, espulp_module_globals_table);

View File

@ -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 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 // use a running ULP. This is only to prevent multiple portions of user code
// from using the ULP concurrently. // from using the ULP concurrently.

View File

@ -27,10 +27,10 @@
#pragma once #pragma once
#include "py/obj.h" #include "py/obj.h"
#include "bindings/espulp/ULPArch.h" #include "bindings/espulp/Architecture.h"
typedef struct { typedef struct {
mp_obj_base_t base; mp_obj_base_t base;
espulp_ulparch_t arch; espulp_architecture_t arch;
bool inited; bool inited;
} espulp_ulp_obj_t; } espulp_ulp_obj_t;

View File

@ -37,6 +37,10 @@
static volatile bool woke_up = false; static volatile bool woke_up = false;
static bool alarm_set = 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) { 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++) { for (size_t i = 0; i < n_alarms; i++) {
if (mp_obj_is_type(alarms[i], &espulp_ulpalarm_type)) { if (mp_obj_is_type(alarms[i], &espulp_ulpalarm_type)) {