Skip to content

Commit

Permalink
esp8266: Clean up Pin intr handler by moving all code to machine_pin.c.
Browse files Browse the repository at this point in the history
The macro MP_FASTCODE is used to explicitly place required functions in
iRAM, instead of needing a separate .c file.
  • Loading branch information
dpgeorge committed May 8, 2020
1 parent f792e6c commit e12de1f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 43 deletions.
1 change: 0 additions & 1 deletion ports/esp8266/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ SRC_C = \
esppwm.c \
espneopixel.c \
espapa102.c \
intr.c \
modpyb.c \
modmachine.c \
machine_pin.c \
Expand Down
37 changes: 0 additions & 37 deletions ports/esp8266/intr.c

This file was deleted.

15 changes: 12 additions & 3 deletions ports/esp8266/machine_pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ typedef struct _pin_irq_obj_t {
uint16_t phys_port;
} pin_irq_obj_t;

STATIC void pin_intr_handler_part1(void *arg);
STATIC void pin_intr_handler_part2(uint32_t status);

const pyb_pin_obj_t pyb_pin_obj[16 + 1] = {
{{&pyb_pin_type}, 0, FUNC_GPIO0, PERIPHS_IO_MUX_GPIO0_U},
{{&pyb_pin_type}, 1, FUNC_GPIO1, PERIPHS_IO_MUX_U0TXD_U},
Expand Down Expand Up @@ -88,7 +91,7 @@ STATIC const pin_irq_obj_t pin_irq_obj[16];

void pin_init0(void) {
ETS_GPIO_INTR_DISABLE();
ETS_GPIO_INTR_ATTACH(pin_intr_handler_iram, NULL);
ETS_GPIO_INTR_ATTACH(pin_intr_handler_part1, NULL);
// disable all interrupts
memset(&MP_STATE_PORT(pin_irq_handler)[0], 0, 16 * sizeof(mp_obj_t));
for (int p = 0; p < 16; ++p) {
Expand All @@ -98,7 +101,13 @@ void pin_init0(void) {
ETS_GPIO_INTR_ENABLE();
}

void MP_FASTCODE(pin_intr_handler)(uint32_t status) {
void MP_FASTCODE(pin_intr_handler_part1)(void *arg) {
uint32_t status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, status);
pin_intr_handler_part2(status);
}

void MP_FASTCODE(pin_intr_handler_part2)(uint32_t status) {
status &= 0xffff;
for (int p = 0; status; ++p, status >>= 1) {
if (status & 1) {
Expand Down Expand Up @@ -478,7 +487,7 @@ STATIC const pin_irq_obj_t pin_irq_obj[16] = {
STATIC mp_obj_t pin_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
pin_irq_obj_t *self = self_in;
mp_arg_check_num(n_args, n_kw, 0, 0, false);
pin_intr_handler(1 << self->phys_port);
pin_intr_handler_part2(1 << self->phys_port);
return mp_const_none;
}

Expand Down
2 changes: 0 additions & 2 deletions ports/esp8266/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ typedef struct _pyb_pin_obj_t {
const pyb_pin_obj_t pyb_pin_obj[16 + 1];

void pin_init0(void);
void pin_intr_handler_iram(void *arg);
void pin_intr_handler(uint32_t);

uint mp_obj_get_pin(mp_obj_t pin_in);
pyb_pin_obj_t *mp_obj_get_pin_obj(mp_obj_t pin_in);
Expand Down

0 comments on commit e12de1f

Please sign in to comment.