Skip to content

Commit f56500e

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents fca7a2e + b71c7b7 commit f56500e

File tree

7 files changed

+73
-80
lines changed

7 files changed

+73
-80
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ msgstr ""
9090
msgid "%q and %q must share a clock unit"
9191
msgstr ""
9292

93+
#: ports/nrf/common-hal/watchdog/WatchDogTimer.c
94+
msgid "%q cannot be changed once mode is set to %q"
95+
msgstr ""
96+
9397
#: shared-bindings/microcontroller/Pin.c
9498
msgid "%q contains duplicate pins"
9599
msgstr ""
@@ -912,10 +916,6 @@ msgstr ""
912916
msgid "Error in safemode.py."
913917
msgstr ""
914918

915-
#: shared-bindings/ssl/SSLSocket.c
916-
msgid "Error: Failure to bind"
917-
msgstr ""
918-
919919
#: shared-bindings/alarm/__init__.c
920920
msgid "Expected a kind of %q"
921921
msgstr ""

ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {
8585
}
8686

8787
void common_hal_watchdog_set_timeout(watchdog_watchdogtimer_obj_t *self, mp_float_t new_timeout) {
88-
if (!(self->timeout < new_timeout || self->timeout > new_timeout)) {
89-
return;
90-
}
91-
9288
mp_arg_validate_int_max(new_timeout, 16, MP_QSTR_timeout);
9389
self->timeout = new_timeout;
9490

ports/espressif/common-hal/watchdog/WatchDogTimer.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "shared-bindings/microcontroller/__init__.h"
3131

3232
#include "common-hal/watchdog/WatchDogTimer.h"
33+
#include "bindings/espidf/__init__.h"
3334

3435
#include "esp_task_wdt.h"
3536

@@ -66,36 +67,35 @@ void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
6667
}
6768
}
6869

69-
static void wdt_config(uint32_t timeout, watchdog_watchdogmode_t mode) {
70-
// enable panic hanler in WATCHDOGMODE_RESET mode
70+
static void wdt_config(uint32_t timeout_ms, watchdog_watchdogmode_t mode) {
71+
// enable panic handler in WATCHDOGMODE_RESET mode
7172
// initialize Task Watchdog Timer (TWDT)
7273
esp_task_wdt_config_t twdt_config = {
73-
.timeout_ms = timeout,
74-
.idle_core_mask = (1 << portNUM_PROCESSORS) - 1, // Bitmask of all cores
74+
.timeout_ms = timeout_ms,
75+
.idle_core_mask = 0, // Don't monitor idle tasks just the ones we add.
7576
.trigger_panic = (mode == WATCHDOGMODE_RESET),
7677
};
78+
// Reconfigure if we are already running.
7779
if (esp_task_wdt_init(&twdt_config) != ESP_OK) {
78-
mp_raise_msg(&mp_type_MemoryError, NULL);
80+
CHECK_ESP_RESULT(esp_task_wdt_reconfigure(&twdt_config));
7981
}
80-
esp_task_wdt_add(NULL);
82+
CHECK_ESP_RESULT(esp_task_wdt_add(NULL));
8183
}
8284

8385
mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {
8486
return self->timeout;
8587
}
8688

8789
void common_hal_watchdog_set_timeout(watchdog_watchdogtimer_obj_t *self, mp_float_t new_timeout) {
88-
if (!(self->timeout < new_timeout || self->timeout > new_timeout)) {
89-
return;
90-
}
90+
uint64_t new_timeout_ms = new_timeout * 1000;
9191

92-
if ((uint64_t)new_timeout > UINT32_MAX) {
93-
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be <= %u"), MP_QSTR_timeout, UINT32_MAX);
92+
if (new_timeout_ms > UINT32_MAX) {
93+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be <= %u"), MP_QSTR_timeout, UINT32_MAX / 1000);
9494
}
9595
self->timeout = new_timeout;
9696

9797
if (self->mode != WATCHDOGMODE_NONE) {
98-
wdt_config(new_timeout, self->mode);
98+
wdt_config(new_timeout_ms, self->mode);
9999
}
100100
}
101101

@@ -114,7 +114,7 @@ void common_hal_watchdog_set_mode(watchdog_watchdogtimer_obj_t *self, watchdog_w
114114
break;
115115
case WATCHDOGMODE_RAISE:
116116
case WATCHDOGMODE_RESET:
117-
wdt_config(self->timeout, new_mode);
117+
wdt_config(self->timeout * 1000, new_mode);
118118
break;
119119
default:
120120
return;

ports/nrf/common-hal/watchdog/WatchDogTimer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ void common_hal_watchdog_set_timeout(watchdog_watchdogtimer_obj_t *self, mp_floa
121121
}
122122
nrfx_timer_clear(timer);
123123
nrfx_timer_compare(timer, NRF_TIMER_CC_CHANNEL0, ticks, true);
124+
} else if (self->mode == WATCHDOGMODE_RESET) {
125+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("%q cannot be changed once mode is set to %q"), MP_QSTR_timeout, MP_QSTR_RESET);
124126
}
125127

126128
self->timeout = timeout;

ports/raspberrypi/common-hal/watchdog/WatchDogTimer.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
#include "hardware/watchdog.h"
3535

36-
#define WATCHDOG_ENABLE watchdog_enable(self->timeout * 1000, false)
37-
3836
void common_hal_watchdog_feed(watchdog_watchdogtimer_obj_t *self) {
3937
watchdog_update();
4038
}
@@ -52,16 +50,12 @@ mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {
5250
}
5351

5452
void common_hal_watchdog_set_timeout(watchdog_watchdogtimer_obj_t *self, mp_float_t new_timeout) {
55-
if (!(self->timeout < new_timeout || self->timeout > new_timeout)) {
56-
return;
57-
}
58-
5953
// max timeout is 8.388607 sec, this is rounded down to 8 sec
6054
mp_arg_validate_int_max(new_timeout, 8, MP_QSTR_timeout);
6155
self->timeout = new_timeout;
6256

6357
if (self->mode == WATCHDOGMODE_RESET) {
64-
WATCHDOG_ENABLE;
58+
watchdog_enable(self->timeout * 1000, false);
6559
}
6660
}
6761

@@ -82,7 +76,7 @@ void common_hal_watchdog_set_mode(watchdog_watchdogtimer_obj_t *self, watchdog_w
8276
mp_raise_NotImplementedError(NULL);
8377
break;
8478
case WATCHDOGMODE_RESET:
85-
WATCHDOG_ENABLE;
79+
watchdog_enable(self->timeout * 1000, false);
8680
break;
8781
default:
8882
return;

ports/silabs/common-hal/watchdog/WatchDogTimer.c

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -57,62 +57,63 @@ void common_hal_watchdog_set_timeout(watchdog_watchdogtimer_obj_t *self,
5757
uint64_t timeout = new_timeout * 1000;
5858
mp_arg_validate_int_max(timeout, 256000, MP_QSTR_WatchDogTimeout);
5959

60-
if ((uint32_t)self->timeout != (uint32_t)new_timeout) {
61-
62-
// Watchdog Initialize settings
63-
WDOG_Init_TypeDef wdogInit = WDOG_INIT_DEFAULT;
64-
65-
switch ((uint32_t)new_timeout)
66-
{
67-
case 1:
68-
wdogInit.perSel = wdogPeriod_1k;
69-
break;
70-
case 2:
71-
wdogInit.perSel = wdogPeriod_2k;
72-
break;
73-
case 4:
74-
wdogInit.perSel = wdogPeriod_4k;
75-
break;
76-
case 8:
77-
wdogInit.perSel = wdogPeriod_8k;
78-
break;
79-
case 16:
80-
wdogInit.perSel = wdogPeriod_16k;
81-
break;
82-
case 32:
83-
wdogInit.perSel = wdogPeriod_32k;
84-
break;
85-
case 64:
86-
wdogInit.perSel = wdogPeriod_64k;
87-
break;
88-
case 128:
89-
wdogInit.perSel = wdogPeriod_128k;
90-
break;
91-
case 256:
92-
wdogInit.perSel = wdogPeriod_256k;
93-
break;
94-
default:
95-
mp_raise_ValueError(
96-
MP_ERROR_TEXT("Timeout value supported: 1,2,4,8,16,32,64,128,256"));
60+
// Only reset the watchdog to update the timer if mode has already been set.
61+
if (self->mode != WATCHDOGMODE_RESET) {
62+
return;
63+
}
64+
// Watchdog Initialize settings
65+
WDOG_Init_TypeDef wdogInit = WDOG_INIT_DEFAULT;
66+
67+
switch ((uint32_t)new_timeout)
68+
{
69+
case 1:
70+
wdogInit.perSel = wdogPeriod_1k;
71+
break;
72+
case 2:
73+
wdogInit.perSel = wdogPeriod_2k;
74+
break;
75+
case 4:
76+
wdogInit.perSel = wdogPeriod_4k;
77+
break;
78+
case 8:
79+
wdogInit.perSel = wdogPeriod_8k;
80+
break;
81+
case 16:
82+
wdogInit.perSel = wdogPeriod_16k;
83+
break;
84+
case 32:
85+
wdogInit.perSel = wdogPeriod_32k;
86+
break;
87+
case 64:
88+
wdogInit.perSel = wdogPeriod_64k;
89+
break;
90+
case 128:
91+
wdogInit.perSel = wdogPeriod_128k;
92+
break;
93+
case 256:
94+
wdogInit.perSel = wdogPeriod_256k;
95+
break;
96+
default:
97+
mp_raise_ValueError(
98+
MP_ERROR_TEXT("Timeout value supported: 1,2,4,8,16,32,64,128,256"));
9799

98-
}
100+
}
99101

100-
self->timeout = new_timeout;
101-
// Enable clock for the WDOG module; has no effect on xG21
102-
CMU_ClockEnable(cmuClock_WDOG0, true);
102+
self->timeout = new_timeout;
103+
// Enable clock for the WDOG module; has no effect on xG21
104+
CMU_ClockEnable(cmuClock_WDOG0, true);
103105

104-
// ULFRCO as clock source
105-
CMU_ClockSelectSet(cmuClock_WDOG0, cmuSelect_ULFRCO);
106+
// ULFRCO as clock source
107+
CMU_ClockSelectSet(cmuClock_WDOG0, cmuSelect_ULFRCO);
106108

107-
wdogInit.em1Run = true;
108-
wdogInit.em2Run = true;
109-
wdogInit.em3Run = true;
109+
wdogInit.em1Run = true;
110+
wdogInit.em2Run = true;
111+
wdogInit.em3Run = true;
110112

111-
// Initializing watchdog with chosen settings
112-
WDOGn_Init(DEFAULT_WDOG, &wdogInit);
113+
// Initializing watchdog with chosen settings
114+
WDOGn_Init(DEFAULT_WDOG, &wdogInit);
113115

114-
_wdt_init = true;
115-
}
116+
_wdt_init = true;
116117
}
117118

118119
watchdog_watchdogmode_t common_hal_watchdog_get_mode

shared-bindings/watchdog/WatchDogTimer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(watchdog_watchdogtimer_deinit_obj, watchdog_wat
8585

8686
//| timeout: float
8787
//| """The maximum number of seconds that can elapse between calls
88-
//| to `feed()`"""
88+
//| to `feed()`. Setting the timeout will also feed the watchdog."""
8989
STATIC mp_obj_t watchdog_watchdogtimer_obj_get_timeout(mp_obj_t self_in) {
9090
watchdog_watchdogtimer_obj_t *self = MP_OBJ_TO_PTR(self_in);
9191
return mp_obj_new_float(common_hal_watchdog_get_timeout(self));

0 commit comments

Comments
 (0)