From 75d2a8009e15cb3a4bb68914b84ff773bfb9f26b Mon Sep 17 00:00:00 2001 From: Pol Van Aubel Date: Thu, 2 May 2019 01:07:22 +0200 Subject: [PATCH 1/4] Extend SoftwareTimer with ISR-safe functions. --- cores/nRF5/utility/SoftwareTimer.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cores/nRF5/utility/SoftwareTimer.h b/cores/nRF5/utility/SoftwareTimer.h index ac724431..a36731d1 100644 --- a/cores/nRF5/utility/SoftwareTimer.h +++ b/cores/nRF5/utility/SoftwareTimer.h @@ -52,6 +52,11 @@ class SoftwareTimer _handle = xTimerCreate(NULL, ms2tick(ms), true, NULL, callback); } + void begin(uint32_t ms, TimerCallbackFunction_t callback, bool repeating) + { + _handle = xTimerCreate(NULL, ms2tick(ms), repeating, NULL, callback); + } + TimerHandle_t getHandle(void) { return _handle; @@ -59,6 +64,17 @@ class SoftwareTimer void start(void) { xTimerStart(_handle, 0); } void stop (void) { xTimerStop (_handle, 0); } + void reset(void) { xTimerReset(_handle, 0); } + + BaseType_t startFromISR(BaseType_t* pxHigherPriorityTaskWoken) { + return xTimerStartFromISR(_handle, pxHigherPriorityTaskWoken); + } + BaseType_t stopFromISR(BaseType_t* pxHigherPriorityTaskWoken) { + return xTimerStopFromISR (_handle, pxHigherPriorityTaskWoken); + } + BaseType_t resetFromISR(BaseType_t* pxHigherPriorityTaskWoken) { + return xTimerResetFromISR(_handle, pxHigherPriorityTaskWoken); + } void setPeriod(uint32_t ms) { From 6b9331883d8ea56b710af28c6c444f57cc8c4c53 Mon Sep 17 00:00:00 2001 From: Pol Van Aubel Date: Fri, 3 May 2019 11:34:08 +0200 Subject: [PATCH 2/4] Add default and clean up superfluous begin function. --- cores/nRF5/utility/SoftwareTimer.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cores/nRF5/utility/SoftwareTimer.h b/cores/nRF5/utility/SoftwareTimer.h index a36731d1..dbeb01d4 100644 --- a/cores/nRF5/utility/SoftwareTimer.h +++ b/cores/nRF5/utility/SoftwareTimer.h @@ -47,12 +47,7 @@ class SoftwareTimer SoftwareTimer() { _handle = NULL; } virtual ~SoftwareTimer() { if(_handle != NULL) xTimerDelete(_handle, 0); } - void begin(uint32_t ms, TimerCallbackFunction_t callback) - { - _handle = xTimerCreate(NULL, ms2tick(ms), true, NULL, callback); - } - - void begin(uint32_t ms, TimerCallbackFunction_t callback, bool repeating) + void begin(uint32_t ms, TimerCallbackFunction_t callback, bool repeating = true) { _handle = xTimerCreate(NULL, ms2tick(ms), repeating, NULL, callback); } From 5b6e35d4e08471d5128cc328fc71d8532c5c08a8 Mon Sep 17 00:00:00 2001 From: Pol Van Aubel Date: Sat, 4 May 2019 04:23:39 +0200 Subject: [PATCH 3/4] Add defaults for pxHigherPriorityTaskWoken. --- cores/nRF5/utility/SoftwareTimer.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/nRF5/utility/SoftwareTimer.h b/cores/nRF5/utility/SoftwareTimer.h index dbeb01d4..ba6920f6 100644 --- a/cores/nRF5/utility/SoftwareTimer.h +++ b/cores/nRF5/utility/SoftwareTimer.h @@ -61,13 +61,13 @@ class SoftwareTimer void stop (void) { xTimerStop (_handle, 0); } void reset(void) { xTimerReset(_handle, 0); } - BaseType_t startFromISR(BaseType_t* pxHigherPriorityTaskWoken) { + BaseType_t startFromISR(BaseType_t* pxHigherPriorityTaskWoken = NULL) { return xTimerStartFromISR(_handle, pxHigherPriorityTaskWoken); } - BaseType_t stopFromISR(BaseType_t* pxHigherPriorityTaskWoken) { + BaseType_t stopFromISR(BaseType_t* pxHigherPriorityTaskWoken = NULL) { return xTimerStopFromISR (_handle, pxHigherPriorityTaskWoken); } - BaseType_t resetFromISR(BaseType_t* pxHigherPriorityTaskWoken) { + BaseType_t resetFromISR(BaseType_t* pxHigherPriorityTaskWoken = NULL) { return xTimerResetFromISR(_handle, pxHigherPriorityTaskWoken); } From 2ce11a601a80ff5f19b99fefd1c4869f38e7aebd Mon Sep 17 00:00:00 2001 From: Pol Van Aubel Date: Tue, 14 May 2019 22:25:31 +0200 Subject: [PATCH 4/4] Abstract away scheduler wake. --- cores/nRF5/utility/SoftwareTimer.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/cores/nRF5/utility/SoftwareTimer.h b/cores/nRF5/utility/SoftwareTimer.h index ba6920f6..e39b7301 100644 --- a/cores/nRF5/utility/SoftwareTimer.h +++ b/cores/nRF5/utility/SoftwareTimer.h @@ -61,14 +61,25 @@ class SoftwareTimer void stop (void) { xTimerStop (_handle, 0); } void reset(void) { xTimerReset(_handle, 0); } - BaseType_t startFromISR(BaseType_t* pxHigherPriorityTaskWoken = NULL) { - return xTimerStartFromISR(_handle, pxHigherPriorityTaskWoken); + bool startFromISR(void) { + BaseType_t ret, xHigherPriorityTaskWoken = pdFALSE; + ret = xTimerStartFromISR(_handle, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + return (ret == pdPASS); } - BaseType_t stopFromISR(BaseType_t* pxHigherPriorityTaskWoken = NULL) { - return xTimerStopFromISR (_handle, pxHigherPriorityTaskWoken); + + bool stopFromISR(void) { + BaseType_t ret, xHigherPriorityTaskWoken = pdFALSE; + ret = xTimerStopFromISR(_handle, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + return (ret == pdPASS); } - BaseType_t resetFromISR(BaseType_t* pxHigherPriorityTaskWoken = NULL) { - return xTimerResetFromISR(_handle, pxHigherPriorityTaskWoken); + + bool resetFromISR(void) { + BaseType_t ret, xHigherPriorityTaskWoken = pdFALSE; + ret = xTimerResetFromISR(_handle, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + return (ret == pdPASS); } void setPeriod(uint32_t ms)