stm32/irq: Clean up irq.h so it does not depend on core uPy defines.
The irq.h file now just provides low-level IRQ definitions and priorities. All Python binding definitions are moved to modmachine.h, with some renaming of pyb -> machine, and also the machine_idle definition (was pyb_wfi) is moved to modmachine.c. The cc3200 and teensy ports are updated to build with these changes. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
ac15be9365
commit
5f3c2f1fa8
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
#include "irq.h"
|
|
||||||
#include "inc/hw_types.h"
|
#include "inc/hw_types.h"
|
||||||
#include "inc/hw_gpio.h"
|
#include "inc/hw_gpio.h"
|
||||||
#include "inc/hw_ints.h"
|
#include "inc/hw_ints.h"
|
||||||
@ -69,6 +68,9 @@ extern OsiTaskHandle xSimpleLinkSpawnTaskHndl;
|
|||||||
/// \module machine - functions related to the SoC
|
/// \module machine - functions related to the SoC
|
||||||
///
|
///
|
||||||
|
|
||||||
|
MP_DECLARE_CONST_FUN_OBJ_0(machine_disable_irq_obj);
|
||||||
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_enable_irq_obj);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
// MicroPython bindings;
|
// MicroPython bindings;
|
||||||
|
|
||||||
@ -176,8 +178,8 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_wake_reason), MP_ROM_PTR(&machine_wake_reason_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_wake_reason), MP_ROM_PTR(&machine_wake_reason_obj) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&pyb_disable_irq_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&pyb_enable_irq_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&pyb_rtc_type) },
|
{ MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&pyb_rtc_type) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) },
|
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) },
|
||||||
|
@ -27,44 +27,28 @@
|
|||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
|
#include "modmachine.h"
|
||||||
/// \moduleref pyb
|
|
||||||
|
|
||||||
#if IRQ_ENABLE_STATS
|
#if IRQ_ENABLE_STATS
|
||||||
uint32_t irq_stats[IRQ_STATS_MAX] = {0};
|
uint32_t irq_stats[IRQ_STATS_MAX] = {0};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// \function wfi()
|
// disable_irq()
|
||||||
/// Wait for an interrupt.
|
// Disable interrupt requests.
|
||||||
/// This executies a `wfi` instruction which reduces power consumption
|
// Returns the previous IRQ state which can be passed to enable_irq.
|
||||||
/// of the MCU until an interrupt occurs, at which point execution continues.
|
STATIC mp_obj_t machine_disable_irq(void) {
|
||||||
STATIC mp_obj_t pyb_wfi(void) {
|
|
||||||
__WFI();
|
|
||||||
return mp_const_none;
|
|
||||||
}
|
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(pyb_wfi_obj, pyb_wfi);
|
|
||||||
|
|
||||||
/// \function disable_irq()
|
|
||||||
/// Disable interrupt requests.
|
|
||||||
/// Returns the previous IRQ state: `False`/`True` for disabled/enabled IRQs
|
|
||||||
/// respectively. This return value can be passed to enable_irq to restore
|
|
||||||
/// the IRQ to its original state.
|
|
||||||
STATIC mp_obj_t pyb_disable_irq(void) {
|
|
||||||
return mp_obj_new_bool(disable_irq() == IRQ_STATE_ENABLED);
|
return mp_obj_new_bool(disable_irq() == IRQ_STATE_ENABLED);
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(pyb_disable_irq_obj, pyb_disable_irq);
|
MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq);
|
||||||
|
|
||||||
/// \function enable_irq(state=True)
|
// enable_irq(state=True)
|
||||||
/// Enable interrupt requests.
|
// Enable interrupt requests, based on the argument, which is usually the
|
||||||
/// If `state` is `True` (the default value) then IRQs are enabled.
|
// value returned by a previous call to disable_irq.
|
||||||
/// If `state` is `False` then IRQs are disabled. The most common use of
|
STATIC mp_obj_t machine_enable_irq(uint n_args, const mp_obj_t *arg) {
|
||||||
/// this function is to pass it the value returned by `disable_irq` to
|
|
||||||
/// exit a critical section.
|
|
||||||
STATIC mp_obj_t pyb_enable_irq(uint n_args, const mp_obj_t *arg) {
|
|
||||||
enable_irq((n_args == 0 || mp_obj_is_true(arg[0])) ? IRQ_STATE_ENABLED : IRQ_STATE_DISABLED);
|
enable_irq((n_args == 0 || mp_obj_is_true(arg[0])) ? IRQ_STATE_ENABLED : IRQ_STATE_DISABLED);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_enable_irq_obj, 0, 1, pyb_enable_irq);
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_enable_irq_obj, 0, 1, machine_enable_irq);
|
||||||
|
|
||||||
#if IRQ_ENABLE_STATS
|
#if IRQ_ENABLE_STATS
|
||||||
// return a memoryview of the irq statistics array
|
// return a memoryview of the irq statistics array
|
||||||
|
@ -52,7 +52,7 @@ extern uint32_t irq_stats[IRQ_STATS_MAX];
|
|||||||
#define IRQ_EXIT(irq)
|
#define IRQ_EXIT(irq)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline mp_uint_t query_irq(void) {
|
static inline uint32_t query_irq(void) {
|
||||||
return __get_PRIMASK();
|
return __get_PRIMASK();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,11 +92,6 @@ static inline void restore_irq_pri(uint32_t state) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MP_DECLARE_CONST_FUN_OBJ_0(pyb_wfi_obj);
|
|
||||||
MP_DECLARE_CONST_FUN_OBJ_0(pyb_disable_irq_obj);
|
|
||||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_enable_irq_obj);
|
|
||||||
MP_DECLARE_CONST_FUN_OBJ_0(pyb_irq_stats_obj);
|
|
||||||
|
|
||||||
// IRQ priority definitions.
|
// IRQ priority definitions.
|
||||||
//
|
//
|
||||||
// Lower number implies higher interrupt priority.
|
// Lower number implies higher interrupt priority.
|
||||||
|
@ -346,6 +346,15 @@ STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
|
|||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 4, machine_freq);
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 4, machine_freq);
|
||||||
|
|
||||||
|
// idle()
|
||||||
|
// This executies a wfi machine instruction which reduces power consumption
|
||||||
|
// of the MCU until an interrupt occurs, at which point execution continues.
|
||||||
|
STATIC mp_obj_t machine_idle(void) {
|
||||||
|
__WFI();
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);
|
||||||
|
|
||||||
STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||||
if (n_args != 0) {
|
if (n_args != 0) {
|
||||||
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
|
||||||
@ -382,7 +391,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
|||||||
#if MICROPY_HW_ENABLE_RNG
|
#if MICROPY_HW_ENABLE_RNG
|
||||||
{ MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&pyb_rng_get_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&pyb_rng_get_obj) },
|
||||||
#endif
|
#endif
|
||||||
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&pyb_wfi_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) },
|
||||||
@ -391,8 +400,8 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_wake_reason), MP_ROM_PTR(&machine_wake_reason_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_wake_reason), MP_ROM_PTR(&machine_wake_reason_obj) },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&pyb_disable_irq_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&pyb_enable_irq_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) },
|
||||||
|
|
||||||
|
@ -39,7 +39,14 @@ MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj);
|
|||||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj);
|
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj);
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj);
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj);
|
||||||
|
|
||||||
|
MP_DECLARE_CONST_FUN_OBJ_0(machine_idle_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj);
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj);
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj);
|
||||||
|
|
||||||
|
MP_DECLARE_CONST_FUN_OBJ_0(machine_disable_irq_obj);
|
||||||
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_enable_irq_obj);
|
||||||
|
|
||||||
|
MP_DECLARE_CONST_FUN_OBJ_0(pyb_irq_stats_obj);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_STM32_MODMACHINE_H
|
#endif // MICROPY_INCLUDED_STM32_MODMACHINE_H
|
||||||
|
@ -146,9 +146,9 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_repl_info), MP_ROM_PTR(&pyb_set_repl_info_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_repl_info), MP_ROM_PTR(&pyb_set_repl_info_obj) },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_wfi), MP_ROM_PTR(&pyb_wfi_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_wfi), MP_ROM_PTR(&machine_idle_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&pyb_disable_irq_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&pyb_enable_irq_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
|
||||||
#if IRQ_ENABLE_STATS
|
#if IRQ_ENABLE_STATS
|
||||||
{ MP_ROM_QSTR(MP_QSTR_irq_stats), MP_ROM_PTR(&pyb_irq_stats_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_irq_stats), MP_ROM_PTR(&pyb_irq_stats_obj) },
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include "lib/utils/pyexec.h"
|
#include "lib/utils/pyexec.h"
|
||||||
|
|
||||||
#include "gccollect.h"
|
#include "gccollect.h"
|
||||||
#include "irq.h"
|
|
||||||
#include "systick.h"
|
#include "systick.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "pin.h"
|
#include "pin.h"
|
||||||
@ -53,6 +52,7 @@
|
|||||||
#include "dac.h"
|
#include "dac.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
#include "portmodules.h"
|
#include "portmodules.h"
|
||||||
|
#include "modmachine.h"
|
||||||
|
|
||||||
/// \module pyb - functions related to the pyboard
|
/// \module pyb - functions related to the pyboard
|
||||||
///
|
///
|
||||||
@ -230,6 +230,12 @@ STATIC mp_obj_t pyb_udelay(mp_obj_t usec_in) {
|
|||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_udelay_obj, pyb_udelay);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_udelay_obj, pyb_udelay);
|
||||||
|
|
||||||
|
STATIC mp_obj_t pyb_wfi(void) {
|
||||||
|
__WFI();
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_0(pyb_wfi_obj, pyb_wfi);
|
||||||
|
|
||||||
STATIC mp_obj_t pyb_stop(void) {
|
STATIC mp_obj_t pyb_stop(void) {
|
||||||
printf("stop not currently implemented\n");
|
printf("stop not currently implemented\n");
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
@ -285,8 +291,8 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_wfi), MP_ROM_PTR(&pyb_wfi_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_wfi), MP_ROM_PTR(&pyb_wfi_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&pyb_disable_irq_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&pyb_enable_irq_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&pyb_stop_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&pyb_stop_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_standby), MP_ROM_PTR(&pyb_standby_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_standby), MP_ROM_PTR(&pyb_standby_obj) },
|
||||||
|
Loading…
Reference in New Issue
Block a user