Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c
index 3cbd39fe6..7e98fc932 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c
@@ -19,25 +19,49 @@
#include "osal/etTimer.h"
#include "helpers/etTimeHelpers.h"
-void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction threadFunction){
- self->osTimerId = 0;
+#include "debugging/etLogger.h"
+#include "debugging/etMSCLogger.h"
+
+
+/** global handle for the Windows timer queue */
+static HANDLE hTimerQueue = NULL;
+
+void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction timerFunction){
+ self->osTimerData = NULL;
self->timerInterval.sec = timerInterval->sec;
self->timerInterval.nSec = timerInterval->nSec;
- self->timerFunction = threadFunction;
+ self->timerFunction = timerFunction;
+ if (hTimerQueue == NULL){
+ /* the Windows timer queue is only needed once for all timers */
+ hTimerQueue = CreateTimerQueue();
+ if (hTimerQueue == NULL){
+ etLogger_logError("etTimer_construct: CreateTimerQueue failed");
+ }
+ }
}
void etTimer_start(etTimer* self){
UINT elapse;
/* calculate the time in milliseconds -> accuracy will of nSec will get lost in windows! */
elapse = etTimeHelpers_convertToMSec(&(self->timerInterval));
- /*TODO: should we replace the forced cast by a platform specific implementation of the timer callback function? */
- self->osTimerId = SetTimer(NULL, 0, elapse, self->timerFunction);
+
+ if (hTimerQueue == NULL){
+ etLogger_logError("etTimer_start: no Timer Queue to create timer (NULL)");
+ }
+ else {
+ if (CreateTimerQueueTimer( &(self->osTimerData), hTimerQueue, self->timerFunction, NULL , 0, elapse, 0) == FALSE){
+ etLogger_logError("etTimer_start: Timer could not be created");
+ }
+ }
}
void etTimer_stop(etTimer* self){
- KillTimer(NULL, self->osTimerId);
+ if (DeleteTimerQueueTimer(hTimerQueue, self->osTimerData, NULL) == FALSE){
+ etLogger_logError("etTimer_stop: Timer could not be stopped");
+ }
}
void etTimer_destruct(etTimer* self){
- /* no implementation needed for this operating system */
+ /* TODO: destroy hTimerQueue if last timer is destroyed */
+ /* DeleteTimerQueue(hTimerQueue); */
}

Back to the top