Skip to content

Fix periodic timers firing only once #87

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions freertos-rust/src/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<D: DurationTicks> TimerBuilder<D> {
/// Note that the newly created timer must be started.
pub fn create<F>(&self, callback: F) -> Result<Timer, FreeRtosError>
where
F: Fn(Timer) -> (),
F: Fn(&Timer) -> (),
F: Send + 'static,
{
Timer::spawn(
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Timer {
name: &str,
period_ticks: FreeRtosTickType,
auto_reload: bool,
callback: Box<dyn Fn(Timer) + Send + 'a>,
callback: Box<dyn Fn(&Timer) + Send + 'a>,
) -> Result<Timer, FreeRtosError> {
let f = Box::new(callback);
let param_ptr = &*f as *const _ as *mut _;
Expand Down Expand Up @@ -119,10 +119,11 @@ impl Timer {
{
let timer = Timer { handle };
if let Ok(callback_ptr) = timer.get_id() {
let b = Box::from_raw(callback_ptr as *mut Box<dyn Fn(Timer)>);
b(timer);
let b = Box::from_raw(callback_ptr as *mut Box<dyn Fn(&Timer)>);
b(&timer);
let _ = Box::into_raw(b);
}
mem::forget(timer);
}
}
}
Expand All @@ -139,7 +140,7 @@ impl Timer {
callback: F,
) -> Result<Timer, FreeRtosError>
where
F: Fn(Timer) -> (),
F: Fn(&Timer) -> (),
F: Send + 'static,
{
unsafe { Timer::spawn_inner(name, period_tick, auto_reload, Box::new(callback)) }
Expand Down