Implement tmr.wdclr()
This commit is contained in:
parent
a2ba49e36b
commit
5c59c57a16
|
@ -233,6 +233,15 @@ static int tmr_create( lua_State *L ) {
|
|||
}
|
||||
|
||||
|
||||
// Lua: tmr.wdclr()
|
||||
static int tmr_wdclr( lua_State *L )
|
||||
{
|
||||
// Suspend ourselves momentarily to let the IDLE task do its thing
|
||||
vTaskDelay(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Module function map
|
||||
|
||||
LROT_BEGIN(tmr_dyn, NULL, LROT_MASK_GC_INDEX)
|
||||
|
@ -249,6 +258,7 @@ LROT_END(tmr_dyn, NULL, LROT_MASK_GC_INDEX)
|
|||
|
||||
LROT_BEGIN(tmr, NULL, 0)
|
||||
LROT_FUNCENTRY( create, tmr_create )
|
||||
LROT_FUNCENTRY( wdclr, tmr_wdclr )
|
||||
LROT_NUMENTRY ( ALARM_SINGLE, TIMER_MODE_SINGLE )
|
||||
LROT_NUMENTRY ( ALARM_SEMI, TIMER_MODE_SEMI )
|
||||
LROT_NUMENTRY ( ALARM_AUTO, TIMER_MODE_AUTO )
|
||||
|
|
|
@ -212,3 +212,37 @@ none
|
|||
|
||||
#### See also
|
||||
[`tmr.obj:register()`](#tmrobjregister)
|
||||
|
||||
|
||||
## tmr.wdclr()
|
||||
|
||||
Resets the watchdog timer to prevent a reboot due to a perceived hung task.
|
||||
|
||||
Use with caution, as this could prevent a reboot to recover from a
|
||||
genuinely hung task.
|
||||
|
||||
On the ESP32, the `tmr.wdclr()` function is implemented as a task yield
|
||||
to let the system "IDLE" task do the necessary watchdog maintenance.
|
||||
Overuse of this function is likely to result in degraded performance.
|
||||
|
||||
#### Syntax
|
||||
`tmr.wdclr()`
|
||||
|
||||
#### Parameters
|
||||
none
|
||||
|
||||
#### Returns
|
||||
`nil`
|
||||
|
||||
#### Example
|
||||
```lua
|
||||
function long_running_function()
|
||||
while 1
|
||||
do
|
||||
if some_condition then break end
|
||||
-- do some heavy calculation here, for example
|
||||
tmr.wdclr()
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue