Skip to content
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

Extend SoftwareTimer with option to make it non-repeating, add reset function & ISR-safe functions. #260

Merged
merged 4 commits into from
May 15, 2019

Conversation

MacGyverNL
Copy link
Contributor

The SoftwareTimer provided by the library is missing a function for resetting it.

Also, I want to reset this timer from an ISR attached by attachInterrupt. Based on the documentation at https://www.freertos.org/FreeRTOS-timers-xTimerResetFromISR.html, I figured it was necessary to use the ISR-safe functions, so there's ISR-safe equivalents included. I'm not quite certain about their name, though; I used ISR because that was what was in my head at the time but it might be more appropriate to name them more in line with Arduino-style "attachInterrupt" thus becoming "resetFromInterrupt" etc.

Finally, the timer I want must be non-repeating, only getting started when an interrupt tells it to start. So I added a begin()-function that adds a boolean to its signature to specify whether the timer repeats if it ticks over or suspends.

See
https://github.com/MacGyverNL/bluepedal/blob/02213ee9dcc495ccdc47f572892f7388aac09a55/bluepedal/bluepedal.ino#L190
and
https://github.com/MacGyverNL/bluepedal/blob/02213ee9dcc495ccdc47f572892f7388aac09a55/bluepedal/bluepedal.ino#L281
for context of how I'm using them to implement a loopless HID.

@MacGyverNL MacGyverNL changed the base branch from master to develop May 3, 2019 01:29
@MacGyverNL MacGyverNL changed the base branch from develop to master May 3, 2019 01:30
Copy link
Member

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, there is only a couple of slight change request. I am open for discussion.

cores/nRF5/utility/SoftwareTimer.h Outdated Show resolved Hide resolved
cores/nRF5/utility/SoftwareTimer.h Outdated Show resolved Hide resolved
@hathach
Copy link
Member

hathach commented May 3, 2019

Also if you are using attachInterrupt() but didn't need spot-on time, you can have the attachInterrupt() defer callback using ISR_DEFRRED option.

@MacGyverNL
Copy link
Contributor Author

Also if you are using attachInterrupt() but didn't need spot-on time, you can have the attachInterrupt() defer callback using ISR_DEFRRED option.

I'm aware of the option, thanks. Most relevant for me is the behaviour of ISR_DEFERRED when multiple interrupts happen before the ISR is run, however -- does it run trhe ISR once for every single one or are all the interrupts rolled into a single run?

Regardless, assuming at some point someone will need spot-on timing for the ISR, and still need to also fire up a timer based on it, I think these additions should be made.

@hathach hathach merged commit 4e07305 into adafruit:master May 15, 2019
@hathach
Copy link
Member

hathach commented May 15, 2019

thanks for the PR and follow up :)

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