Skip to content

Commit 1d4bf8a

Browse files
robert-hhdpgeorge
authored andcommitted
esp32/machine_timer: Fix timer.value() for an uninitialized timer.
Raises a value error in that case, which happens after a timer was created but not initialized, or after calling `timer.deinit()`. Fixes issue #17033. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent d737112 commit 1d4bf8a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

ports/esp32/machine_timer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init)
246246

247247
static mp_obj_t machine_timer_value(mp_obj_t self_in) {
248248
machine_timer_obj_t *self = self_in;
249+
if (self->handle == NULL) {
250+
mp_raise_ValueError(MP_ERROR_TEXT("timer not set"));
251+
}
249252
uint64_t result = timer_ll_get_counter_value(self->hal_context.dev, self->index);
250253
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)(result / (TIMER_SCALE / 1000))); // value in ms
251254
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy