Skip to content

Commit c8a4589

Browse files
committed
wip
1 parent 79beda7 commit c8a4589

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

cores/esp8266/Schedule.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct recurrent_fn_t
4747

4848
static recurrent_fn_t* rFirst = nullptr;
4949
static recurrent_fn_t* rLast = nullptr;
50+
static uint32_t rScheduleTarget = 0;
5051

5152
// Returns a pointer to an unused sched_fn_t,
5253
// or if none are available allocates a new one,
@@ -117,6 +118,10 @@ bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
117118

118119
item->mFunc = fn;
119120
item->alarm = alarm;
121+
// if (!rScheduleTarget || rScheduleTarget > item.callNow.remaining())
122+
// {
123+
// rScheduleTarget = item.callNow.remaining();
124+
// }
120125

121126
esp8266::InterruptLock lockAllInterruptsInThisScope;
122127

@@ -133,6 +138,11 @@ bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
133138
return true;
134139
}
135140

141+
uint32_t compute_scheduled_recurrent_grain()
142+
{
143+
return 0;
144+
}
145+
136146
void run_scheduled_functions()
137147
{
138148
// prevent scheduling of new functions during this run

cores/esp8266/Schedule.h

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
// scheduled function happen more often: every yield() (vs every loop()),
4040
// and time resolution is microsecond (vs millisecond). Details are below.
4141

42+
// compute_scheduled_recurrent_grain() is used by delay() to give a chance to
43+
// all recurrent functions to run per their timing requirement.
44+
45+
uint32_t compute_scheduled_recurrent_grain ();
46+
4247
// scheduled functions called once:
4348
//
4449
// * internal queue is FIFO.

cores/esp8266/core_esp8266_main.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,16 @@ bool esp_try_delay(const uint32_t start_ms, const uint32_t timeout_ms, const uin
171171
if (expired >= timeout_ms) {
172172
return true; // expired
173173
}
174-
esp_delay(std::min((timeout_ms - expired), intvl_ms));
175-
return false;
174+
175+
// compute greatest delay interval with respect to scheduled recurrent functions
176+
uint32_t grain_ms = std::min(intvl_ms, compute_scheduled_recurrent_grain());
177+
178+
// recurrent scheduled functions will be called from esp_delay()->esp_suspend()
179+
esp_delay(grain_ms > 0 ?
180+
std::min((timeout_ms - expired), grain_ms) :
181+
(timeout_ms - expired));
182+
183+
return false; // expiration must be checked again
176184
}
177185

178186
extern "C" void __yield() {

0 commit comments

Comments
 (0)