-
Notifications
You must be signed in to change notification settings - Fork 179
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
Implement watchdog interface #182
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.
The overall comment whether this API is safe (and can be made safe in the first place) is the biggest question for me.
Hmmm, if the API is not safe (as I suspect), maybe a safer API would be something where
The only question is if you have the use case where you need to "feed" the watchdog for "another" task which is not your current task. But even with the existing approach, I don't think this is possible, or if it is possible, this is so by accident. |
Of course we still have |
I thought of a single watchdog instance to configure it. Else, where does the configuration happen to make it clear the global watchdog is configured?
That's a good point. I tested it without removing the task from the watchdog, and it crashed. I thought on this a second time, could there be a use case where you don't want to unsubscribe from the watchdog when the thread terminates and want the watchdog behavior to be triggered? But I don't think so.
It isn't possible to feed the watchdog of a specific task. esp-idf impl
I think using this you can break most of the apis when it depends on dropping at the end. Concept// send, sync, clone
struct WatchdogManager;
let twdt = peripherals.TWDT;
let mut wd_manager = watchdog::task::WatchdogManager::new(twdt); // init configure
let mut wd_manager = watchdog::task::WatchdogManager::new_configure(twdt, Config {});
wd_manager.reconfigure(Config {});
{
let watchdog: impl Watchdog = wd_manager.subscribe_current();
watchdog.feed();
drop(watchdog);
} |
That's OK and can still be modeled, as per your concept below.
But when the thread terminates and you are still subscribed, your program will crash (just as you confirmed above), because
Indeed. However, it is possible to add a task to the watchdog from another thread ( esp_err_t esp_task_wdt_add(TaskHandle_t task_handle)
Sure, but you shouldn't crash though. Regardless, this is the best we can do anyway with the existing ESP IDF C APIs which do not support
For symmetry,
Obviously,
Yes. Taking
Actually,
Optional but possible, IMO.
The struct can be named as a variation of the
But overall, yes - the concept should work. |
Now I implemented my concept following the naming conventions. |
let mut another_driver = driver.to_owned();
let mut watchdog = driver.watch_current_task()?;
let mut watchdog_2 = another_driver.watch_current_task()?; Currently, this will fail with Solutions:
|
You should 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.
Final set of primarily stylistic changes prior to merge.
@teamplayer3 Still failing for the |
@ivmarkov found the mistake, please rerun. |
@ivmarkov What should I do with
|
^^^ Make it public. |
Hopefully the last time! |
How can I fix the current error in |
No idea what is going on with the CI. It seems to be a CI problem, yet it is failing only with this PR. Let me merge and see if the main CI would build. |
I tried implementing a TWDT interface. Added an example in the
watchdog::task
module on how I thought of using this implementation. To access the watchdog functionality, I implemented aTask
struct in moduletask
.I don't know if
esp-idf-hal
is the correct crate to implement it.My thoughts on the implementation:
reconfigure()
can be calledTask::current()
accesses the current taskWhile implementing, I noticed that the interface of TWDT changed a little from
v4.4
tomaster
. So in the future, some adjustments must be done to upgrade.