forked from meshtastic/firmware
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ad314f
commit bb9f595
Showing
11 changed files
with
137 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "OSTimer.h" | ||
#include "configuration.h" | ||
|
||
#ifdef NO_ESP32 | ||
|
||
/** | ||
* Schedule a callback to run. The callback must _not_ block, though it is called from regular thread level (not ISR) | ||
* | ||
* NOTE! xTimerPend... seems to ignore the time passed in on ESP32 - I haven't checked on NRF52 | ||
* | ||
* @return true if successful, false if the timer fifo is too full. | ||
*/ | ||
bool scheduleOSCallback(PendableFunction callback, void *param1, uint32_t param2, uint32_t delayMsec) | ||
{ | ||
return xTimerPendFunctionCall(callback, param1, param2, pdMS_TO_TICKS(delayMsec)); | ||
} | ||
|
||
#else | ||
|
||
// Super skanky quick hack to use hardware timers of the ESP32 | ||
static hw_timer_t *timer; | ||
static PendableFunction tCallback; | ||
static void *tParam1; | ||
static uint32_t tParam2; | ||
|
||
static void IRAM_ATTR onTimer() | ||
{ | ||
(*tCallback)(tParam1, tParam2); | ||
} | ||
|
||
bool scheduleHWCallback(PendableFunction callback, void *param1, uint32_t param2, uint32_t delayMsec) | ||
{ | ||
if (!timer) { | ||
timer = timerBegin(0, 80, true); // one usec per tick (main clock is 80MhZ on ESP32) | ||
assert(timer); | ||
timerAttachInterrupt(timer, &onTimer, true); | ||
} | ||
|
||
tCallback = callback; | ||
tParam1 = param1; | ||
tParam2 = param2; | ||
|
||
timerAlarmWrite(timer, delayMsec * 1000L, false); // Do not reload, we want it to be a single shot timer | ||
timerRestart(timer); | ||
timerAlarmEnable(timer); | ||
return true; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters