Skip to content

Conversation

michael-p
Copy link
Contributor

Creating a Timer with auto_reload set to true (the default) results in the timer callback being invoked just once, not periodic.

The problem is that the Drop implementation of Timer stops the timer, and since the timer_callback function constructs a Timer out of thin air and passes that by value to the timer callback Box<dyn Fn(Timer)> the timer gets dropped when the callback ends and stops. Relevant code: https://github.com/lobaro/FreeRTOS-rust/blob/master/freertos-rust/src/timers.rs#L120

This was introduced in #57. Previously, Timer had a detached flag that prevented it from being stopped in its destructor in this situation. Instead of trying to revert this this PR changes the API so that timer callbacks get passed in the Timer by reference. I think this makes more sense than giving ownership of the timer to its own callback.

@schteve
Copy link
Collaborator

schteve commented May 8, 2025

Agree this seems like a better way to handle the timer being passed to the callback.

@schteve schteve merged commit 6615a78 into lobaro:master May 8, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants