Skip to content

Commit 1758a18

Browse files
committed
Remove special support for FunctionalInterrupt from core interrupt handling:
- VIP treatment in general attach/detach/handling looks untidy: extern symbols without matching header include but copy&paste special under-the-hood c++ delete support, where everyone else has to do their own resource tracking as usual. - FunctionalInterrupt is not used by anything inside core ESP8266 Arduino for 2 years now, it can be a library, which reduces precious core size for everyone else. Expose attachInterruptArg via Arduino.h.
1 parent 31c24a6 commit 1758a18

File tree

4 files changed

+40
-182
lines changed

4 files changed

+40
-182
lines changed

cores/esp8266/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
182182
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
183183

184184
void attachInterrupt(uint8_t pin, void (*)(void), int mode);
185+
void attachInterruptArg(uint8_t pin, void (*)(void*), void * arg, int mode);
185186
void detachInterrupt(uint8_t pin);
186187
void attachInterruptArg(uint8_t pin, void (*)(void*), void* arg, int mode);
187188

cores/esp8266/FunctionalInterrupt.cpp

Lines changed: 0 additions & 65 deletions
This file was deleted.

cores/esp8266/FunctionalInterrupt.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

cores/esp8266/core_esp8266_wiring_digital.cpp

Lines changed: 39 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "ets_sys.h"
2727
#include "user_interface.h"
2828
#include "core_esp8266_waveform.h"
29-
#include "interrupts.h"
3029

3130
extern "C" {
3231

@@ -54,17 +53,17 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
5453
GPEC = (1 << pin); //Disable
5554
GPC(pin) = (GPC(pin) & (0xF << GPCI)) | (1 << GPCD); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED)
5655
if(mode == INPUT_PULLUP) {
57-
GPF(pin) |= (1 << GPFPU); // Enable Pullup
56+
GPF(pin) |= (1 << GPFPU); // Enable Pullup
5857
}
5958
} else if(mode == WAKEUP_PULLUP || mode == WAKEUP_PULLDOWN){
6059
GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO
6160
GPEC = (1 << pin); //Disable
6261
if(mode == WAKEUP_PULLUP) {
63-
GPF(pin) |= (1 << GPFPU); // Enable Pullup
64-
GPC(pin) = (1 << GPCD) | (4 << GPCI) | (1 << GPCWE); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(LOW) | WAKEUP_ENABLE(ENABLED)
62+
GPF(pin) |= (1 << GPFPU); // Enable Pullup
63+
GPC(pin) = (1 << GPCD) | (4 << GPCI) | (1 << GPCWE); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(LOW) | WAKEUP_ENABLE(ENABLED)
6564
} else {
66-
GPF(pin) |= (1 << GPFPD); // Enable Pulldown
67-
GPC(pin) = (1 << GPCD) | (5 << GPCI) | (1 << GPCWE); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(HIGH) | WAKEUP_ENABLE(ENABLED)
65+
GPF(pin) |= (1 << GPFPD); // Enable Pulldown
66+
GPC(pin) = (1 << GPCD) | (5 << GPCI) | (1 << GPCWE); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(HIGH) | WAKEUP_ENABLE(ENABLED)
6867
}
6968
}
7069
} else if(pin == 16){
@@ -111,23 +110,10 @@ typedef void (*voidFuncPtrArg)(void*);
111110
typedef struct {
112111
uint8_t mode;
113112
voidFuncPtr fn;
114-
void * arg;
115-
bool functional;
113+
void* arg;
116114
} interrupt_handler_t;
117115

118-
//duplicate from functionalInterrupt.h keep in sync
119-
typedef struct InterruptInfo {
120-
uint8_t pin;
121-
uint8_t value;
122-
uint32_t micro;
123-
} InterruptInfo;
124-
125-
typedef struct {
126-
InterruptInfo* interruptInfo;
127-
void* functionInfo;
128-
} ArgStructure;
129-
130-
static interrupt_handler_t interrupt_handlers[16] = { {0, 0, 0, 0}, };
116+
static interrupt_handler_t interrupt_handlers[16] = { {0, 0, 0}, };
131117
static uint32_t interrupt_reg = 0;
132118

133119
void ICACHE_RAM_ATTR interrupt_handler(void *arg, void *frame)
@@ -144,53 +130,27 @@ void ICACHE_RAM_ATTR interrupt_handler(void *arg, void *frame)
144130
while(changedbits){
145131
while(!(changedbits & (1 << i))) i++;
146132
changedbits &= ~(1 << i);
147-
interrupt_handler_t *handler = &interrupt_handlers[i];
133+
interrupt_handler_t* handler = &interrupt_handlers[i];
148134
if (handler->fn &&
149-
(handler->mode == CHANGE ||
150-
(handler->mode & 1) == !!(levels & (1 << i)))) {
135+
(handler->mode == CHANGE ||
136+
(handler->mode & 1) == !!(levels & (1 << i)))) {
151137
// to make ISR compatible to Arduino AVR model where interrupts are disabled
152138
// we disable them before we call the client ISR
153139
esp8266::InterruptLock irqLock; // stop other interrupts
154-
if (handler->functional)
155-
{
156-
ArgStructure* localArg = (ArgStructure*)handler->arg;
157-
if (localArg && localArg->interruptInfo)
158-
{
159-
localArg->interruptInfo->pin = i;
160-
localArg->interruptInfo->value = __digitalRead(i);
161-
localArg->interruptInfo->micro = micros();
162-
}
163-
}
164-
if (handler->arg)
165-
{
166-
((voidFuncPtrArg)handler->fn)(handler->arg);
167-
}
168-
else
169-
{
170-
handler->fn();
171-
}
140+
if (handler->arg)
141+
{
142+
((voidFuncPtrArg)handler->fn)(handler->arg);
172143
}
144+
else
145+
{
146+
handler->fn();
147+
}
148+
}
173149
}
174150
ETS_GPIO_INTR_ENABLE();
175151
}
176152

177-
extern void cleanupFunctional(void* arg);
178-
179-
static void ICACHE_RAM_ATTR set_interrupt_handlers(uint8_t pin, voidFuncPtr userFunc, void* arg, uint8_t mode, bool functional)
180-
{
181-
interrupt_handler_t* handler = &interrupt_handlers[pin];
182-
handler->mode = mode;
183-
handler->fn = userFunc;
184-
if (handler->functional && handler->arg) // Clean when new attach without detach
185-
{
186-
cleanupFunctional(handler->arg);
187-
}
188-
handler->arg = arg;
189-
handler->functional = functional;
190-
}
191-
192-
extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc, void* arg, int mode, bool functional)
193-
{
153+
extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void* arg, int mode) {
194154
// #5780
195155
// https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map
196156
if ((uint32_t)userFunc >= 0x40200000)
@@ -202,7 +162,10 @@ extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc,
202162

203163
if(pin < 16) {
204164
ETS_GPIO_INTR_DISABLE();
205-
set_interrupt_handlers(pin, (voidFuncPtr)userFunc, arg, mode, functional);
165+
interrupt_handler_t* handler = &interrupt_handlers[pin];
166+
handler->mode = mode;
167+
handler->fn = (voidFuncPtr)userFunc;
168+
handler->arg = arg;
206169
interrupt_reg |= (1 << pin);
207170
GPC(pin) &= ~(0xF << GPCI);//INT mode disabled
208171
GPIEC = (1 << pin); //Clear Interrupt for this pin
@@ -212,29 +175,23 @@ extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc,
212175
}
213176
}
214177

215-
extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void* arg, int mode)
216-
{
217-
__attachInterruptFunctionalArg(pin, userFunc, arg, mode, false);
218-
}
219-
220-
extern void ICACHE_RAM_ATTR __detachInterrupt(uint8_t pin) {
221-
if (pin < 16)
222-
{
223-
ETS_GPIO_INTR_DISABLE();
224-
GPC(pin) &= ~(0xF << GPCI);//INT mode disabled
225-
GPIEC = (1 << pin); //Clear Interrupt for this pin
226-
interrupt_reg &= ~(1 << pin);
227-
set_interrupt_handlers(pin, nullptr, nullptr, 0, false);
228-
if (interrupt_reg)
229-
{
230-
ETS_GPIO_INTR_ENABLE();
231-
}
232-
}
178+
extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int mode ) {
179+
__attachInterruptArg(pin, (voidFuncPtrArg)userFunc, 0, mode);
233180
}
234181

235-
extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int mode)
236-
{
237-
__attachInterruptFunctionalArg(pin, (voidFuncPtrArg)userFunc, 0, mode, false);
182+
extern void __detachInterrupt(uint8_t pin) {
183+
if(pin < 16) {
184+
ETS_GPIO_INTR_DISABLE();
185+
GPC(pin) &= ~(0xF << GPCI);//INT mode disabled
186+
GPIEC = (1 << pin); //Clear Interrupt for this pin
187+
interrupt_reg &= ~(1 << pin);
188+
interrupt_handler_t* handler = &interrupt_handlers[pin];
189+
handler->mode = 0;
190+
handler->fn = 0;
191+
handler->arg = 0;
192+
if (interrupt_reg)
193+
ETS_GPIO_INTR_ENABLE();
194+
}
238195
}
239196

240197
extern void __resetPins() {
@@ -258,7 +215,7 @@ extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pi
258215
extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias("__digitalWrite")));
259216
extern int digitalRead(uint8_t pin) __attribute__ ((weak, alias("__digitalRead"), nothrow));
260217
extern void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) __attribute__ ((weak, alias("__attachInterrupt")));
261-
extern void attachInterruptArg(uint8_t pin, voidFuncPtrArg handler, void* arg, int mode) __attribute__((weak, alias("__attachInterruptArg")));
218+
extern void attachInterruptArg(uint8_t pin, voidFuncPtrArg handler, void* arg, int mode) __attribute__ ((weak, alias("__attachInterruptArg")));
262219
extern void detachInterrupt(uint8_t pin) __attribute__ ((weak, alias("__detachInterrupt")));
263220

264221
};

0 commit comments

Comments
 (0)