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
Merged
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
26 changes: 24 additions & 2 deletions cores/nRF5/utility/SoftwareTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class SoftwareTimer
SoftwareTimer() { _handle = NULL; }
virtual ~SoftwareTimer() { if(_handle != NULL) xTimerDelete(_handle, 0); }

void begin(uint32_t ms, TimerCallbackFunction_t callback)
void begin(uint32_t ms, TimerCallbackFunction_t callback, bool repeating = true)
{
_handle = xTimerCreate(NULL, ms2tick(ms), true, NULL, callback);
_handle = xTimerCreate(NULL, ms2tick(ms), repeating, NULL, callback);
}

TimerHandle_t getHandle(void)
Expand All @@ -59,6 +59,28 @@ class SoftwareTimer

void start(void) { xTimerStart(_handle, 0); }
void stop (void) { xTimerStop (_handle, 0); }
void reset(void) { xTimerReset(_handle, 0); }

bool startFromISR(void) {
BaseType_t ret, xHigherPriorityTaskWoken = pdFALSE;
ret = xTimerStartFromISR(_handle, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
return (ret == pdPASS);
}

bool stopFromISR(void) {
BaseType_t ret, xHigherPriorityTaskWoken = pdFALSE;
ret = xTimerStopFromISR(_handle, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
return (ret == pdPASS);
}

bool resetFromISR(void) {
BaseType_t ret, xHigherPriorityTaskWoken = pdFALSE;
ret = xTimerResetFromISR(_handle, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
return (ret == pdPASS);
}

void setPeriod(uint32_t ms)
{
Expand Down