-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESP32: Configurable WDT #3929
ESP32: Configurable WDT #3929
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that using the id
to determine if the other configuration options are used is the right move. The id
parameter is there because on some platforms you have to specify which timer to use as the watchdog timer but on the ESP32 there's a dedicated hardware block for the watchdog so this is unnecessary. Being able to set the timeout and panic status are certainly useful though; I think that a better option might be to set these up as keyword arguments rather than positional.
ports/esp32/machine_wdt.c
Outdated
if (n_args > 0) { | ||
id = mp_obj_get_int(args[0]); | ||
timeout = mp_obj_get_int(args[1]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any place where you read the value of args[2]
. It looks like this will always panic on timeout if you use id==1
.
ports/esp32/machine_wdt.c
Outdated
|
||
case 1: { | ||
mp_int_t rs_code = esp_task_wdt_init(timeout, panic); | ||
if(rs_code != ESP_OK) mp_raise_OSError(rs_code); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the coding conventions even blocks of code with a single command should use braces and a separate line. Also a space between if
and (rs_code
would be good.
I removed the id parameter and added support for the keyword arguments but the coverage decreased. How do i fix it? |
The coveralls coverage metrics are unreliable; it doesn't even run checks on the code in the ESP32 port so I wouldn't worry about it. |
ports/esp32/machine_wdt.c
Outdated
mp_map_init_fixed_table(&kw_args, n_kw, args + n_args); | ||
mp_arg_parse_all(n_args, args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, mp_args); | ||
|
||
if (mp_args[ARG_timeout].u_int == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be easier and less code if you simply put sensible defaults for the keyword arguments and then unconditionally called esp_task_wdt_init()
with whatever values you get from the keywords.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took as an example the file machine_uart.c to understand how to take the keyword arguments. What specifically does the mp_map_init_fixed_table()
method do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd tried to pin my comment on line 63; I'm not sure why it came out above.
What I was meaning is that if you set the default value for timeout
to something other than 0 (as discussed below) then you can skip the whole of the True side of the if (mp_args[ARG_timeout].u_int == 0)
statement and go strait to the code that is currently in the else
side.
ports/esp32/machine_wdt.c
Outdated
} | ||
static const mp_arg_t allowed_args[] = { | ||
{ MP_QSTR_timeout, MP_ARG_INT, {.u_int = 0} }, | ||
{ MP_QSTR_panic, MP_ARG_BOOL, {.u_bool = true} } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the current default behaviour to panic or to reset? As far as I can tell it currently resets so you should probably keep that behaviour. Doing a panic is less useful when running MicroPython.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nickovs,
thanks for the help!
Reset is the current default behaviour so i keep it as you suggest. I have also changed default timeout from 0 to 10s to avoid an immediately reset on WDT constructor call if no timeout arg is passed.
Thanks @dreasGh, that looks good to me, although I'm not a maintainer (just an interested party who's been using the watchdog timer on the ESP32 recently) so my say has limited weight. I guess my only remaining concern is if for production purposes it is really necessary to have the call to Anyway, thanks for submitting this. I will use it myself if/when it makes it into the master branch. |
@nickovs thank you very much for your help. |
@dreasGh Sorry if I was not clear. My suggestion was that the logging line should be removed altogether since it is probably not needed in production code. It takes up space for the instructions and the strings wherever you put it. |
ports/esp32/machine_wdt.c
Outdated
@@ -42,20 +43,30 @@ typedef struct _machine_wdt_obj_t { | |||
STATIC machine_wdt_obj_t wdt_default = {{&machine_wdt_type}}; | |||
|
|||
STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { | |||
mp_arg_check_num(n_args, n_kw, 0, 1, false); | |||
mp_arg_check_num(n_args, n_kw, 0, 2, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed if using mp_arg_parse_all
ports/esp32/machine_wdt.c
Outdated
id = mp_obj_get_int(args[0]); | ||
} | ||
static const mp_arg_t allowed_args[] = { | ||
{ MP_QSTR_timeout, MP_ARG_INT, {.u_int = 10} }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to add a line for the id
. Check how ports/stm32/wdt.c does it.
Also, the default timeout should be 5 seconds to retain the original behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the role of the id? The IDF documentation states that the function esp_task_wdt_init()
only has timeout and panic parameters.
Thanks for your patience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's so that it matches with other ports. In some cases there may be multiple WDT's and the id will select which one. It is an optional parameter so you can still do something like machine.WDT(timeout=5000)
.
Thanks for the contribution. It's definitely important to be able to set the timeout of the WDT. But note that the timeout should be given in milliseconds, following the stm32 and cc3200 ports. As for the As for the additions to .gitignore: usually such changes would be made in your own global git configuration, and then you can easily support any IDE or whatever you like. So I'd prefer not to merge those changes. |
…) and timeout managed in millis (5000 as default)
I added the id parameter, removed the panic (true as default value) to keep the default behavior and i managed the timeout in milliseconds (with 5000 as default value). |
Hi all, is there a plan to merge this to master soon? Is this waiting for appropriate approval or am I missing something in the history? |
Hi, news? |
Hi |
I'm using the WDT part and it works very well - would be great if that was promoted to master |
The simple fixes are as follows. @dreasGh |
Sorry for losing track of this. I've merged it (the WDT improvements) in fbd4e61, with some changes to the code layout. Note: the OTA addition and other changes here were not merged. |
ulab: update to 1.6.0
Hi,
this is my first PR so i hope i made it in the right way :).
I began to study a few days ago what is under micropython, i still have several doubts so i hope i have implemented everything in the right way.
This fix allow to configure WDT with their parameters (id, timeout and panic) so now is possible to initialize WDT as follows:
machine.WDT(1, 10, True)
if id 1 is specified, the default WDT will be updated with the new configurations.
I have also ignored some Visual Studio Code files.