Skip to content

Commit f544815

Browse files
committed
Add hooks for sketches/libraries to perform work on each yield() and each completed loop.
1 parent 7d78247 commit f544815

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

cores/esp32/Arduino.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ void init(void);
130130
void initVariant(void);
131131
void initArduino(void);
132132

133+
void yield_completed(void);
134+
void loop_completed(void);
135+
133136
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
134137
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
135138

cores/esp32/esp32-hal-misc.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ float temperatureRead()
4444
return (temprature_sens_read() - 32) / 1.8;
4545
}
4646

47-
void yield()
48-
{
49-
vPortYield();
50-
}
51-
5247
#if CONFIG_AUTOSTART_ARDUINO
5348

5449
extern TaskHandle_t loopTaskHandle;
@@ -139,9 +134,34 @@ unsigned long IRAM_ATTR millis()
139134
return (unsigned long) (esp_timer_get_time() / 1000ULL);
140135
}
141136

137+
void initVariant() __attribute__((weak));
138+
void initVariant() {}
139+
140+
void init() __attribute__((weak));
141+
void init() {}
142+
143+
void yield_completed() __attribute__((weak));
144+
void yield_completed() {}
145+
146+
bool verifyOta() __attribute__((weak));
147+
bool verifyOta() { return true; }
148+
149+
#ifdef CONFIG_BT_ENABLED
150+
//overwritten in esp32-hal-bt.c
151+
bool btInUse() __attribute__((weak));
152+
bool btInUse() { return false; }
153+
#endif
154+
155+
void yield()
156+
{
157+
vPortYield();
158+
yield_completed();
159+
}
160+
142161
void delay(uint32_t ms)
143162
{
144-
vTaskDelay(ms / portTICK_PERIOD_MS);
163+
vTaskDelay(ms / portTICK_PERIOD_MS);
164+
yield_completed();
145165
}
146166

147167
void IRAM_ATTR delayMicroseconds(uint32_t us)
@@ -160,21 +180,6 @@ void IRAM_ATTR delayMicroseconds(uint32_t us)
160180
}
161181
}
162182

163-
void initVariant() __attribute__((weak));
164-
void initVariant() {}
165-
166-
void init() __attribute__((weak));
167-
void init() {}
168-
169-
bool verifyOta() __attribute__((weak));
170-
bool verifyOta() { return true; }
171-
172-
#ifdef CONFIG_BT_ENABLED
173-
//overwritten in esp32-hal-bt.c
174-
bool btInUse() __attribute__((weak));
175-
bool btInUse(){ return false; }
176-
#endif
177-
178183
void initArduino()
179184
{
180185
#ifdef CONFIG_APP_ROLLBACK_ENABLE

cores/esp32/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void loopTask(void *pvParameters)
1717
esp_task_wdt_reset();
1818
}
1919
loop();
20+
loop_completed();
2021
}
2122
}
2223

@@ -27,4 +28,7 @@ extern "C" void app_main()
2728
xTaskCreateUniversal(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, CONFIG_ARDUINO_RUNNING_CORE);
2829
}
2930

31+
extern "C" void loop_completed() __attribute__((weak));
32+
extern "C" void loop_completed() {}
33+
3034
#endif

0 commit comments

Comments
 (0)