Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2013-04-29 22:17:31 +0000
committerThomas Schuetz2013-04-29 22:17:31 +0000
commit9d880c611d45f933b7029e79b8776b2f4d429cee (patch)
treefd192b8dbbc9cb194bbbf63c421587886af62370 /runtime/org.eclipse.etrice.runtime.c/src/platforms
parent2903767e47d1d2a6d3135d7a26d2913987792f52 (diff)
downloadorg.eclipse.etrice-9d880c611d45f933b7029e79b8776b2f4d429cee.tar.gz
org.eclipse.etrice-9d880c611d45f933b7029e79b8776b2f4d429cee.tar.xz
org.eclipse.etrice-9d880c611d45f933b7029e79b8776b2f4d429cee.zip
[runtime.c] implementation of etTimer for MinGW and unit tests for etTimer
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/platforms')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h27
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etThread.c2
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c38
3 files changed, 42 insertions, 25 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h
index ff5f6ad61..b7cfa1077 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h
@@ -21,8 +21,8 @@
#include <stdio.h>
+#define WINVER 0x0500
#include <windows.h>
-#include <process.h>
/* unsigned integer datatypes */
typedef unsigned char uint8;
@@ -90,24 +90,15 @@ typedef int16 etAddressId;
* typedefs for OS-specific types
*/
- typedef CRITICAL_SECTION etOSMutexData;
- typedef HANDLE etOSThreadData;
- typedef DWORD etOSThreadId;
- typedef HANDLE etOSSemaData;
-
- typedef UINT_PTR etOSTimerId;
-
-//typedef TIMERPROC etTimerFunction;
-typedef VOID(CALLBACK *etTimerFunction)(HWND,UINT,UINT,DWORD);
-//typedef void (*etThreadFunction)(void *);
+typedef CRITICAL_SECTION etOSMutexData;
+typedef HANDLE etOSThreadData;
+typedef DWORD etOSThreadId;
+typedef HANDLE etOSSemaData;
+typedef HANDLE etOSTimerData;
+typedef DWORD etOSTimerId;
+typedef VOID(CALLBACK *etTimerFunction)(PVOID lpParam, BOOLEAN TimerOrWaitFired);
#define etTimerFunction_RETURN_VALUE VOID CALLBACK
-
-#define etTimerFunction_ARGUMENT_LIST HWND arg1, UINT arg2, UINT arg3, DWORD arg4
-
-
-//typedef void (*etTimerFunction)(void); /**< OS specific timer callback function **/
-//typedef VOID(CALLBACK *TIMERPROC)(HWND,UINT,UINT,DWORD);
-
+#define etTimerFunction_ARGUMENT_LIST PVOID lpParam, BOOLEAN TimerOrWaitFired
#endif /* _DATATYPES_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etThread.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etThread.c
index 14ea2b98a..61be3103d 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etThread.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etThread.c
@@ -21,6 +21,8 @@
#include "debugging/etLogger.h"
#include "debugging/etMSCLogger.h"
+#include <process.h>
+
void etThread_execute(etThread* self);
void etThread_construct(etThread* self){
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