|
3 | 3 | *
|
4 | 4 | * The MIT License (MIT)
|
5 | 5 | *
|
6 |
| - * Copyright (c) 2013, 2014 Damien P. George |
| 6 | + * Copyright (c) 2013-2023 Damien P. George |
7 | 7 | * Copyright (c) 2015 Daniel Campora
|
8 | 8 | *
|
9 | 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
25 | 25 | * THE SOFTWARE.
|
26 | 26 | */
|
27 | 27 |
|
28 |
| -#include <stdint.h> |
| 28 | +// This file is never compiled standalone, it's included directly from |
| 29 | +// extmod/modmachine.c via MICROPY_PY_MACHINE_INCLUDEFILE. |
| 30 | + |
29 | 31 | #include <stdio.h>
|
30 | 32 |
|
31 |
| -#include "py/runtime.h" |
32 |
| -#include "py/mphal.h" |
33 |
| -#include "extmod/modmachine.h" |
34 | 33 | #include "inc/hw_types.h"
|
35 | 34 | #include "inc/hw_gpio.h"
|
36 | 35 | #include "inc/hw_ints.h"
|
37 | 36 | #include "inc/hw_memmap.h"
|
38 | 37 | #include "inc/hw_uart.h"
|
39 | 38 | #include "rom_map.h"
|
40 |
| -#include "prcm.h" |
41 | 39 | #include "pybuart.h"
|
42 | 40 | #include "pybpin.h"
|
43 | 41 | #include "pybrtc.h"
|
44 | 42 | #include "simplelink.h"
|
45 |
| -#include "modnetwork.h" |
46 | 43 | #include "modwlan.h"
|
47 |
| -#include "modos.h" |
48 |
| -#include "FreeRTOS.h" |
49 |
| -#include "portable.h" |
50 |
| -#include "task.h" |
51 | 44 | #include "random.h"
|
52 | 45 | #include "pybadc.h"
|
53 | 46 | #include "pybi2c.h"
|
54 | 47 | #include "pybsd.h"
|
55 | 48 | #include "pybsleep.h"
|
56 | 49 | #include "pybspi.h"
|
57 | 50 | #include "pybtimer.h"
|
58 |
| -#include "utils.h" |
59 |
| -#include "gccollect.h" |
60 | 51 |
|
| 52 | +#ifdef DEBUG |
| 53 | +#define MICROPY_PY_MACHINE_INFO_ENTRY { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, |
| 54 | +#else |
| 55 | +#define MICROPY_PY_MACHINE_INFO_ENTRY |
| 56 | +#endif |
| 57 | + |
| 58 | +#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \ |
| 59 | + { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \ |
| 60 | + MICROPY_PY_MACHINE_INFO_ENTRY \ |
| 61 | + { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, \ |
| 62 | + { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \ |
| 63 | + { MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&machine_main_obj) }, \ |
| 64 | + { MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&machine_rng_get_obj) }, \ |
| 65 | + { MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) }, \ |
| 66 | + { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \ |
| 67 | + { MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \ |
| 68 | + { MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) }, \ |
| 69 | + { MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \ |
| 70 | + { MP_ROM_QSTR(MP_QSTR_wake_reason), MP_ROM_PTR(&machine_wake_reason_obj) }, \ |
| 71 | + \ |
| 72 | + { MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \ |
| 73 | + { MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \ |
| 74 | + \ |
| 75 | + { MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&pyb_rtc_type) }, \ |
| 76 | + { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) }, \ |
| 77 | + { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&pyb_adc_type) }, \ |
| 78 | + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&pyb_i2c_type) }, \ |
| 79 | + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&pyb_spi_type) }, \ |
| 80 | + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&pyb_uart_type) }, \ |
| 81 | + { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&pyb_timer_type) }, \ |
| 82 | + { MP_ROM_QSTR(MP_QSTR_SD), MP_ROM_PTR(&pyb_sd_type) }, \ |
| 83 | + \ |
| 84 | + /* class constants */ \ |
| 85 | + { MP_ROM_QSTR(MP_QSTR_IDLE), MP_ROM_INT(PYB_PWR_MODE_ACTIVE) }, \ |
| 86 | + { MP_ROM_QSTR(MP_QSTR_SLEEP), MP_ROM_INT(PYB_PWR_MODE_LPDS) }, \ |
| 87 | + { MP_ROM_QSTR(MP_QSTR_DEEPSLEEP), MP_ROM_INT(PYB_PWR_MODE_HIBERNATE) }, \ |
| 88 | + { MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(PYB_SLP_PWRON_RESET) }, \ |
| 89 | + { MP_ROM_QSTR(MP_QSTR_HARD_RESET), MP_ROM_INT(PYB_SLP_HARD_RESET) }, \ |
| 90 | + { MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(PYB_SLP_WDT_RESET) }, \ |
| 91 | + { MP_ROM_QSTR(MP_QSTR_DEEPSLEEP_RESET), MP_ROM_INT(PYB_SLP_HIB_RESET) }, \ |
| 92 | + { MP_ROM_QSTR(MP_QSTR_SOFT_RESET), MP_ROM_INT(PYB_SLP_SOFT_RESET) }, \ |
| 93 | + { MP_ROM_QSTR(MP_QSTR_WLAN_WAKE), MP_ROM_INT(PYB_SLP_WAKED_BY_WLAN) }, \ |
| 94 | + { MP_ROM_QSTR(MP_QSTR_PIN_WAKE), MP_ROM_INT(PYB_SLP_WAKED_BY_GPIO) }, \ |
| 95 | + { MP_ROM_QSTR(MP_QSTR_RTC_WAKE), MP_ROM_INT(PYB_SLP_WAKED_BY_RTC) }, \ |
61 | 96 |
|
62 | 97 | #ifdef DEBUG
|
63 | 98 | extern OsiTaskHandle mpTaskHandle;
|
@@ -161,58 +196,4 @@ STATIC mp_obj_t machine_wake_reason (void) {
|
161 | 196 | }
|
162 | 197 | STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason);
|
163 | 198 |
|
164 |
| -STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { |
165 |
| - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, |
166 |
| - |
167 |
| - { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, |
168 |
| -#ifdef DEBUG |
169 |
| - { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, |
170 |
| -#endif |
171 |
| - { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, |
172 |
| - { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, |
173 |
| - { MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&machine_main_obj) }, |
174 |
| - { MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&machine_rng_get_obj) }, |
175 |
| - { MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) }, |
176 |
| - { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) }, |
177 |
| - { MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, |
178 |
| - { MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) }, |
179 |
| - { MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, |
180 |
| - { MP_ROM_QSTR(MP_QSTR_wake_reason), MP_ROM_PTR(&machine_wake_reason_obj) }, |
181 |
| - |
182 |
| - { MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, |
183 |
| - { MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, |
184 |
| - |
185 |
| - { MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&pyb_rtc_type) }, |
186 |
| - { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) }, |
187 |
| - { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&pyb_adc_type) }, |
188 |
| - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&pyb_i2c_type) }, |
189 |
| - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&pyb_spi_type) }, |
190 |
| - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&pyb_uart_type) }, |
191 |
| - { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&pyb_timer_type) }, |
192 |
| - { MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) }, |
193 |
| - { MP_ROM_QSTR(MP_QSTR_SD), MP_ROM_PTR(&pyb_sd_type) }, |
194 |
| - |
195 |
| - // class constants |
196 |
| - { MP_ROM_QSTR(MP_QSTR_IDLE), MP_ROM_INT(PYB_PWR_MODE_ACTIVE) }, |
197 |
| - { MP_ROM_QSTR(MP_QSTR_SLEEP), MP_ROM_INT(PYB_PWR_MODE_LPDS) }, |
198 |
| - { MP_ROM_QSTR(MP_QSTR_DEEPSLEEP), MP_ROM_INT(PYB_PWR_MODE_HIBERNATE) }, |
199 |
| - { MP_ROM_QSTR(MP_QSTR_POWER_ON), MP_ROM_INT(PYB_SLP_PWRON_RESET) }, // legacy constant |
200 |
| - { MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(PYB_SLP_PWRON_RESET) }, |
201 |
| - { MP_ROM_QSTR(MP_QSTR_HARD_RESET), MP_ROM_INT(PYB_SLP_HARD_RESET) }, |
202 |
| - { MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(PYB_SLP_WDT_RESET) }, |
203 |
| - { MP_ROM_QSTR(MP_QSTR_DEEPSLEEP_RESET), MP_ROM_INT(PYB_SLP_HIB_RESET) }, |
204 |
| - { MP_ROM_QSTR(MP_QSTR_SOFT_RESET), MP_ROM_INT(PYB_SLP_SOFT_RESET) }, |
205 |
| - { MP_ROM_QSTR(MP_QSTR_WLAN_WAKE), MP_ROM_INT(PYB_SLP_WAKED_BY_WLAN) }, |
206 |
| - { MP_ROM_QSTR(MP_QSTR_PIN_WAKE), MP_ROM_INT(PYB_SLP_WAKED_BY_GPIO) }, |
207 |
| - { MP_ROM_QSTR(MP_QSTR_RTC_WAKE), MP_ROM_INT(PYB_SLP_WAKED_BY_RTC) }, |
208 |
| -}; |
209 |
| - |
210 |
| -STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table); |
211 |
| - |
212 |
| -const mp_obj_module_t mp_module_machine = { |
213 |
| - .base = { &mp_type_module }, |
214 |
| - .globals = (mp_obj_dict_t*)&machine_module_globals, |
215 |
| -}; |
216 |
| - |
217 |
| -MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); |
218 | 199 | MP_REGISTER_ROOT_POINTER(mp_obj_t machine_config_main);
|
0 commit comments