Add control.set/feedWatchdog() on esp32 (#1303)

* Add control.set/feedWatchdog() on esp32

* re-generate shims
This commit is contained in:
Michał Moskal 2021-12-01 14:39:32 -08:00 коммит произвёл GitHub
Родитель d9c2ec9788
Коммит 4ed2530fc9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 60 добавлений и 4 удалений

Просмотреть файл

@ -1,5 +1,7 @@
#include "pxt.h"
#include "esp_task_wdt.h"
namespace pxt {
static DevicePin **pinPtrs;
static uint8_t numPinPtrs;
@ -17,8 +19,7 @@ DevicePin *getPin(int id) {
if (ptr == 0) {
pinPtrs = (DevicePin **)realloc(pinPtrs, (numPinPtrs + 1) * sizeof(void *));
// GCTODO
pinPtrs[numPinPtrs++] =
new DevicePin(id);
pinPtrs[numPinPtrs++] = new DevicePin(id);
ptr = numPinPtrs;
pinPos[id] = ptr;
}
@ -57,8 +58,8 @@ DevicePin *lookupPinCfg(int key) {
namespace pins {
/**
* Get a pin by configuration id (DAL.CFG_PIN...)
*/
* Get a pin by configuration id (DAL.CFG_PIN...)
*/
//%
DigitalInOutPin pinByCfg(int key) {
return pxt::lookupPinCfg(key);
@ -74,3 +75,28 @@ Buffer createBuffer(int size) {
}
} // namespace pins
namespace control {
/**
* Enable a watchdog timer that need to be fed or it will reset the device.
* If timeout is not positive, the watchdog is disabled.
*/
//%
void setWatchdog(int timeout_s) {
if (timeout_s > 0) {
esp_task_wdt_init(timeout_s, true);
esp_task_wdt_add(NULL);
} else {
esp_task_wdt_delete(NULL);
}
}
/**
* Reset timeout on previously enabled watchdog.
*/
//%
void feedWatchdog() {
esp_task_wdt_reset();
}
} // namespace control

15
libs/core---esp32/shims.d.ts поставляемый
Просмотреть файл

@ -14,6 +14,21 @@ declare namespace pins {
//% shim=pins::createBuffer
function createBuffer(size: int32): Buffer;
}
declare namespace control {
/**
* Enable a watchdog timer that need to be fed or it will reset the device.
* If timeout is not positive, the watchdog is disabled.
*/
//% shim=control::setWatchdog
function setWatchdog(timeout_s: int32): void;
/**
* Reset timeout on previously enabled watchdog.
*/
//% shim=control::feedWatchdog
function feedWatchdog(): void;
}
declare interface DigitalInOutPin {

15
libs/core---esp32s2/shims.d.ts поставляемый
Просмотреть файл

@ -14,6 +14,21 @@ declare namespace pins {
//% shim=pins::createBuffer
function createBuffer(size: int32): Buffer;
}
declare namespace control {
/**
* Enable a watchdog timer that need to be fed or it will reset the device.
* If timeout is not positive, the watchdog is disabled.
*/
//% shim=control::setWatchdog
function setWatchdog(timeout_s: int32): void;
/**
* Reset timeout on previously enabled watchdog.
*/
//% shim=control::feedWatchdog
function feedWatchdog(): void;
}
declare interface DigitalInOutPin {