Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageReceiver.h2
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c75
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h24
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.c60
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.h19
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etWakeupService.c33
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etWakeupService.h37
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/modelbase/etRTSystemServicesProtocol.h18
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/osal/etMutex.h23
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/osal/etSema.h25
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/osal/etThread.h23
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTime.h18
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTimer.h34
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h4
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etThread.c22
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etTimer.c59
16 files changed, 316 insertions, 160 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageReceiver.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageReceiver.h
index a569a0887..eb0a4ceec 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageReceiver.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageReceiver.h
@@ -18,7 +18,7 @@
#include "messaging/etMessage.h"
typedef void (*etActorReceiveMessage)(void* self, void* ifitem, const etMessage* msg);
-typedef void (*etDispatcherReceiveMessage)(const etMessage* msg);
+typedef etBool (*etDispatcherReceiveMessage)(const etMessage* msg);
typedef void (*etDispatcherExecute)(void);
#endif /* _ETMESSAGERECEIVER_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
index 3d119ea80..4f70b98e2 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
@@ -14,16 +14,26 @@
#include "etMessageService.h"
+#include "etSystemProtocol.h"
#include "debugging/etLogger.h"
#include "debugging/etMSCLogger.h"
-
+static void etMessageService_timerCallback(void* data);
/*
* initialize message service with all needed data and initialize message queue and message pool
*
*/
-void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher, etDispatcherExecute executeFct, enum etMessageService_execmode execmode){
+void etMessageService_init(
+ etMessageService* self,
+ etUInt8* buffer,
+ etUInt16 maxBlocks,
+ etUInt16 blockSize,
+ etStacksize stacksize,
+ etPriority priority,
+ etTime interval,
+ etDispatcherReceiveMessage msgDispatcher,
+ etMessageService_execmode execmode){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "init")
/* copy init data to self */
@@ -31,10 +41,9 @@ void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 max
self->messageBuffer.maxBlocks = maxBlocks;
self->messageBuffer.blockSize = blockSize;
self->msgDispatcher = msgDispatcher;
- self->executeFct = executeFct;
self->execmode = execmode;
- /* copy init queue and pool */
+ /* init queue and pool */
etMessageQueue_init( &(self->messagePool) ); /* the pool is also a queue*/
etMessageQueue_init( &(self->messageQueue) );
etMessageService_initMessagePool(self);
@@ -44,18 +53,40 @@ void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 max
etMutex_construct( &(self->queueMutex) );
etSema_construct( &(self->executionSemaphore) );
+ /* init thread */
+ etThread_construct(&self->thread, stacksize, priority, "MessageService", (etThreadFunction) etMessageService_execute, self);
+
+ if (execmode==EXECMODE_POLLED || execmode==EXECMODE_MIXED) {
+ /* init timer */
+ etTimer_construct(&self->timer, &interval, etMessageService_timerCallback, self);
+ }
+
ET_MSC_LOGGER_SYNC_EXIT
}
void etMessageService_start(etMessageService* self){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "start")
- etThread_construct( &(self->thread) );
+ etThread_start( &(self->thread) );
+ if (self->execmode==EXECMODE_POLLED || self->execmode==EXECMODE_MIXED) {
+ etTimer_start(&self->timer);
+ }
ET_MSC_LOGGER_SYNC_EXIT
}
void etMessageService_stop(etMessageService* self){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "stop")
- etThread_destruct( &(self->thread) );
+
+ if (self->execmode==EXECMODE_POLLED || self->execmode==EXECMODE_MIXED) {
+ etTimer_stop(&self->timer);
+ }
+
+ /* create a temporary port struct and send the terminate message */
+ etSystemProtocolConjPort port;
+ port.localId = 0;
+ port.msgService = self;
+ port.peerAddress = MESSAGESERVICE_ADDRESS;
+ etSystemProtocolConjPort_terminate(&port);
+
ET_MSC_LOGGER_SYNC_EXIT
}
@@ -134,13 +165,18 @@ void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buf
void etMessageService_deliverAllMessages(etMessageService* self){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "deliverAllMessages")
- while (TRUE){
- while (etMessageQueue_isNotEmpty(&self->messageQueue)){
- etMessage* msg = etMessageService_popMessage(self);
- self->msgDispatcher(msg);
- etMessageService_returnMessageBuffer(self, msg);
+ {
+ etBool cont = TRUE;
+ while (cont){
+ while (etMessageQueue_isNotEmpty(&self->messageQueue) && cont){
+ etMessage* msg = etMessageService_popMessage(self);
+ if (!self->msgDispatcher(msg))
+ cont = FALSE;
+ etMessageService_returnMessageBuffer(self, msg);
+ }
+ if (cont)
+ etSema_waitForWakeup(&self->executionSemaphore);
}
- etSema_waitForWakeup(&self->executionSemaphore);
}
ET_MSC_LOGGER_SYNC_EXIT
}
@@ -157,3 +193,18 @@ etInt16 etMessageService_getMessagePoolLowWaterMark(etMessageService* self){
ET_MSC_LOGGER_SYNC_EXIT
return lowWaterMark;
}
+
+static void etMessageService_timerCallback(void* data) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "timerCallback")
+ {
+ etMessageService* self = (etMessageService*) data;
+
+ /* create a temporary port struct and send the terminate message */
+ etSystemProtocolConjPort port;
+ port.localId = 0;
+ port.msgService = self;
+ port.peerAddress = MESSAGESERVICE_ADDRESS;
+ etSystemProtocolConjPort_poll(&port);
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h
index b37f98391..c06898f2b 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h
@@ -21,11 +21,14 @@
#include "osal/etMutex.h"
#include "osal/etThread.h"
#include "osal/etSema.h"
+#include "osal/etTimer.h"
+#define MESSAGESERVICE_ADDRESS 1
+#define BASE_ADDRESS 32
-enum etMessageService_execmode {
+typedef enum etMessageService_execmode {
EXECMODE_POLLED, EXECMODE_BLOCKED, EXECMODE_MIXED
-};
+} etMessageService_execmode;
typedef struct etBuffer{
etUInt8 *buffer; /** buffer points to the actual memory position for the message pool */
@@ -38,16 +41,25 @@ typedef struct etMessageService {
etMessageQueue messagePool; /** message pool that holds all free messages */
etBuffer messageBuffer; /** information about the message buffer that holds information about the actual memory position and size for the message pool */
etDispatcherReceiveMessage msgDispatcher; /** function pointer to the generated message dispatcher function */
- etDispatcherExecute executeFct; /** function pointer to the generated message execute function */
etThread thread; /** thread for the execution of the message service */
etMutex poolMutex; /** mutex for synchronizing the access to the message pool */
etMutex queueMutex; /** mutex for synchronizing the access to the message queue */
- etSema executionSemaphore; /** sempahore for waiting and waking up the execution */
- enum etMessageService_execmode execmode; /** execution mode*/
+ etSema executionSemaphore; /** semaphore for waiting and waking up the execution */
+ etTimer timer; /** timer for cyclic calls */
+ etMessageService_execmode execmode; /** execution mode*/
} etMessageService;
/* lifecycle functions to startup, execute and shutdown the message service */
-void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher, etDispatcherExecute executeFct, enum etMessageService_execmode execmode);
+void etMessageService_init(
+ etMessageService* self,
+ etUInt8* buffer,
+ etUInt16 maxBlocks,
+ etUInt16 blockSize,
+ etStacksize stacksize,
+ etPriority priority,
+ etTime interval,
+ etDispatcherReceiveMessage msgDispatcher,
+ etMessageService_execmode execmode);
void etMessageService_start(etMessageService* self);
void etMessageService_execute(etMessageService* self);
void etMessageService_stop(etMessageService* self);
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.c
index 8fb1516cc..d13520335 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.c
@@ -9,16 +9,74 @@
#include "debugging/etMSCLogger.h"
+/*--------------------- port methods */
+
+
+// getReplication
+etInt32 etSystemProtocolReplPort_getReplication(const etSystemProtocolReplPort* self) {
+ return ((etReplPort*)self)->size;
+}
+
+
+
void etSystemProtocolConjPort_poll(const etSystemProtocolConjPort* self) {
ET_MSC_LOGGER_SYNC_ENTRY("etSystemProtocolConjPort", "poll")
etPort_sendMessage(self, etSystemProtocol_IN_poll, 0, NULL);
ET_MSC_LOGGER_SYNC_EXIT
}
+void etSystemProtocolConjReplPort_poll_broadcast(const etSystemProtocolConjReplPort* self) {
+ int i;
+ ET_MSC_LOGGER_SYNC_ENTRY("etSystemProtocolConjReplPort", "poll")
+ for (i=0; i<((etReplPort*)self)->size; ++i) {
+ etPort_sendMessage(((etPort*)&((etReplPort*)self)->ports[i]), etSystemProtocol_IN_poll, 0, NULL);
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etSystemProtocolConjReplPort_poll(const etSystemProtocolConjReplPort* self, int idx) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etSystemProtocolConjReplPort", "poll")
+ if (0<=idx && idx<((etReplPort*)self)->size) {
+ etPort_sendMessage(((etPort*)&((etReplPort*)self)->ports[idx]), etSystemProtocol_IN_poll, 0, NULL);
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etSystemProtocolConjPort_terminate(const etSystemProtocolConjPort* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etSystemProtocolConjPort", "terminate")
+ etPort_sendMessage(self, etSystemProtocol_IN_terminate, 0, NULL);
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etSystemProtocolConjReplPort_terminate_broadcast(const etSystemProtocolConjReplPort* self) {
+ int i;
+ ET_MSC_LOGGER_SYNC_ENTRY("etSystemProtocolConjReplPort", "terminate")
+ for (i=0; i<((etReplPort*)self)->size; ++i) {
+ etPort_sendMessage(((etPort*)&((etReplPort*)self)->ports[i]), etSystemProtocol_IN_terminate, 0, NULL);
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etSystemProtocolConjReplPort_terminate(const etSystemProtocolConjReplPort* self, int idx) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etSystemProtocolConjReplPort", "terminate")
+ if (0<=idx && idx<((etReplPort*)self)->size) {
+ etPort_sendMessage(((etPort*)&((etReplPort*)self)->ports[idx]), etSystemProtocol_IN_terminate, 0, NULL);
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+
+// getReplication
+etInt32 etSystemProtocolConjReplPort_getReplication(const etSystemProtocolConjReplPort* self) {
+ return ((etReplPort*)self)->size;
+}
+
+
+
/*--------------------- debug helpers */
/* message names as strings for debugging (generate MSC) */
-static const char* const etSystemProtocol_messageStrings[] = {"MIN", "poll", "MAX"};
+static const char* const etSystemProtocol_messageStrings[] = {"MIN", "poll", "terminate", "MAX"};
const char* etSystemProtocol_getMessageString(int msg_id) {
if (msg_id<etSystemProtocol_MSG_MIN || msg_id>etSystemProtocol_MSG_MAX+1){
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.h
index f3f803fe9..730d5dbce 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.h
@@ -15,14 +15,31 @@
enum etSystemProtocol_msg_ids {
etSystemProtocol_MSG_MIN = 0,
etSystemProtocol_IN_poll = 1,
- etSystemProtocol_MSG_MAX = 2
+ etSystemProtocol_IN_terminate = 2,
+ etSystemProtocol_MSG_MAX = 3
};
/*--------------------- port structs and methods */
+typedef etPort etSystemProtocolPort;
+typedef etReplPort etSystemProtocolReplPort;
+
+
+
+
+etInt32 etSystemProtocolReplPort_getReplication(const etSystemProtocolReplPort* self);
typedef etPort etSystemProtocolConjPort;
+typedef etReplPort etSystemProtocolConjReplPort;
void etSystemProtocolConjPort_poll(const etSystemProtocolConjPort* self);
+void etSystemProtocolConjReplPort_poll_broadcast(const etSystemProtocolConjReplPort* self);
+void etSystemProtocolConjReplPort_poll(const etSystemProtocolConjReplPort* self, int idx);
+void etSystemProtocolConjPort_terminate(const etSystemProtocolConjPort* self);
+void etSystemProtocolConjReplPort_terminate_broadcast(const etSystemProtocolConjReplPort* self);
+void etSystemProtocolConjReplPort_terminate(const etSystemProtocolConjReplPort* self, int idx);
+
+
+etInt32 etSystemProtocolConjReplPort_getReplication(const etSystemProtocolConjReplPort* self);
/*--------------------- debug helpers */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etWakeupService.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etWakeupService.c
deleted file mode 100644
index ad288e9b5..000000000
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etWakeupService.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz (initial contribution)
- *
- *******************************************************************************/
-
-#include "etWakeupService.h"
-#include "etMessage.h"
-#include "etMessageService.h"
-
-
-/**
- * static instance of the execute Message
- */
-
-/**
- * calls cyclically all receiveMessage functions (at the right time) to deliver the poll message
- * */
-void etWakeupService_execute(etWakeupService* self) {
- int i;
- for (i=0; i<self->targetListLength; i++){
- /** send message call the receiveMessage function to deliver the execute message */
- etSystemProtocolConjPort_poll( &(self->targetList[i].messageServicePort) );
- }
-}
-
-
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etWakeupService.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etWakeupService.h
deleted file mode 100644
index c6c5d4ba1..000000000
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etWakeupService.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz (initial contribution)
- *
- *******************************************************************************/
-
-#ifndef _ETWAKEUPSERVICE_H_
-#define _ETWAKEUPSERVICE_H_
-
-#include "etDatatypes.h"
-#include "etSystemProtocol.h"
-
-#include "osal/etTime.h"
-
-
-
-typedef struct etWakeupTarget {
- etSystemProtocolConjPort messageServicePort; /** port to send the poll message to the message service */
- etTime wakeupTime; /** time for the cyclic wake up call */
-} etWakeupTarget;
-
-
-typedef struct etWakeupService {
- etWakeupTarget* targetList; /** array with targets to be called */
- etInt16 targetListLength; /** number of targets to be called */
-} etWakeupService;
-
-void etWakeupService_execute(etWakeupService* self);
-
-
-#endif /* _ETWAKEUPSERVICE_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/modelbase/etRTSystemServicesProtocol.h b/runtime/org.eclipse.etrice.runtime.c/src/common/modelbase/etRTSystemServicesProtocol.h
deleted file mode 100644
index aab631482..000000000
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/modelbase/etRTSystemServicesProtocol.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz (initial contribution)
- *
- *******************************************************************************/
-
-#ifndef _ETRTSYSTEMSERVICESPROTOCOL_H_
-#define _ETRTSYSTEMSERVICESPROTOCOL_H_
-
-
-
-#endif /* ETRTSYSTEMSERVICESPROTOCOL_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etMutex.h b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etMutex.h
index cff62f5f8..2c67cad14 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etMutex.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etMutex.h
@@ -23,16 +23,33 @@
/**
* etMutex holds the object data for a mutex (for self pointer)
- *
- * */
+ */
typedef struct etMutex {
etOSMutexData osData;
} etMutex;
+/**
+ * initializes the mutex
+ * \param self the 'this' pointer of the mutex
+ */
void etMutex_construct(etMutex* self);
+
+/**
+ * destroys the mutex
+ * \param self the 'this' pointer of the mutex
+ */
void etMutex_destruct(etMutex* self);
+
+/**
+ * lock the mutex
+ * \param self the 'this' pointer of the mutex
+ */
void etMutex_enter(etMutex* self);
-void etMutex_leave(etMutex* self);
+/**
+ * unlock the mutex
+ * \param self the 'this' pointer of the mutex
+ */
+void etMutex_leave(etMutex* self);
#endif /* _ETMUTEX_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etSema.h b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etSema.h
index 8ab3ecf82..31afdc271 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etSema.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etSema.h
@@ -15,22 +15,39 @@
/**
* etSema.h defines a generic interface for platform specific implementations of a semaphore
- *
- * */
+ */
#include "etDatatypes.h"
/**
* etSema holds the object data for a semaphore (for self pointer)
- *
- * */
+ */
typedef struct etSema {
etOSSemaData osData;
} etSema;
+/**
+ * initializes the semaphore
+ * \param self the 'this' pointer of the semaphore
+ */
void etSema_construct(etSema* self);
+
+/**
+ * destroys the semaphore
+ * \param self the 'this' pointer of the semaphore
+ */
void etSema_destruct(etSema* self);
+
+/**
+ * wakes up the semaphore
+ * \param self the 'this' pointer of the semaphore
+ */
void etSema_wakeup(etSema* self);
+
+/**
+ * make the semaphore waiting for a wakeup
+ * \param self the 'this' pointer of the semaphore
+ */
void etSema_waitForWakeup(etSema* self);
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etThread.h b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etThread.h
index 2262dd295..0355f0160 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etThread.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etThread.h
@@ -33,7 +33,7 @@ typedef void (*etThreadFunction)(void *);
/**
* etThread holds all data needed to handle a thread instance
* the struct has to be filled before calling etThread_construct except for osData and osId
- **/
+ */
typedef struct etThread{
etOSThreadData osData; /**< OS specific thread data (e.g. handle or id) -> is filled in by etThread_construct **/
etOSThreadId osId; /**< integer thread id (used e.g. for debugging) -> is filled in by etThread_construct **/
@@ -47,10 +47,27 @@ typedef struct etThread{
// TODO: add return values for error handling
/**
- * create and start a new thread
+ * initialize the thread data
+ * \param (uninitialized) self pointer to thread instance
+ * \param stacksize the size of the thread's stack
+ * \param prioritiy the thread priority
+ * \param threadName the name of the thread
+ * \param threadFunction the thread function
+ * \param threadFunctionData the data will be passed to the thread function
+ */
+void etThread_construct(
+ etThread* self,
+ etStacksize stacksize,
+ etPriority priority,
+ etThreadname threadName,
+ etThreadFunction threadFunction,
+ void* threadFunctionData);
+
+/**
+ * start a new thread
* \param self pointer to thread instance
*/
-void etThread_construct(etThread* self); /*TODO: add all neededarguments to constructor arguments */
+void etThread_start(etThread* self); /*TODO: add all neededarguments to constructor arguments */
/**
* stop and destroy a new thread
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTime.h b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTime.h
index 56f2db35b..a9c9450ce 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTime.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTime.h
@@ -15,8 +15,8 @@
/**
* etTime.h defines a generic interface for platform specific implementations of services around time
- *
- * */
+ */
+
#include "etDatatypes.h"
/**
@@ -31,20 +31,8 @@ typedef struct etTime {
* get current time from target hardware
* this is no real world clock time and date
* should be used only for relative time measurement
- * @return current target time as etTime*
+ * \param current target time as etTime*
*/
void getTimeFromTarget(etTime *t);
-/*
- * TODO: remove old API functions
-int isTimeGreaterThanActualTime(const etTime *t);
-etBool etTimer_executeNeeded(void);
-uint32 getTimeBaseNS(void);
-
-uint32 getTimeBaseUS(void);
-
-uint32 getTimeBaseMS(void);
-*/
-
-
#endif /* _ETTIME_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTimer.h b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTimer.h
index f782f9455..bdbac3fa6 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTimer.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/osal/etTimer.h
@@ -18,19 +18,47 @@
/**
+ * the prototype for the time callback function
+ */
+typedef void (*etTimerFunction)(void* data);
+
+/**
* etThread holds all data needed to handle a thread instance
* the struct has to be filled before calling etThread_construct except for osData and osId
**/
typedef struct etTimer{
etOSTimerData osTimerData; /**< OS specific timer id (e.g. handle or id) -> is filled in by etTimer_construct **/
- etTime timerInterval; /**< timer interval **/
- etTimerFunction timerFunction; /**< call back function to be called by timer -> has to be filled in by caller of etTimer_construct **/
+ etTime timerInterval; /**< timer interval **/
+ etTimerFunction timerFunction; /**< call back function to be called by timer -> has to be filled in by caller of etTimer_construct **/
+ void* timerFunctionData; /**< the data that are passed to the timer function **/
} etTimer;
+/**
+ * This method initializes the etTimer struct with the user settings
+ *
+ * \param self the 'this' pointer of the timer
+ * \param timerInterval the interval to be used for the timer
+ * \param timerFunction the user supplied callback function
+ * \param timerFunctionData the data that will be passed to the user callback function
+ */
+void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction timerFunction, void* timerFunctionData);
-void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction timerFunction);
+/**
+ * starts the timer
+ * \param self the 'this' pointer of the timer
+ */
void etTimer_start(etTimer* self);
+
+/**
+ * stops the timer
+ * \param self the 'this' pointer of the timer
+ */
void etTimer_stop(etTimer* self);
+
+/**
+ * destroys the timer
+ * \param self the 'this' pointer of the timer
+ */
void etTimer_destruct(etTimer* self);
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 b7cfa1077..03551675c 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
@@ -97,8 +97,4 @@ 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 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 61be3103d..9998d9b1a 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
@@ -25,8 +25,28 @@
void etThread_execute(etThread* self);
-void etThread_construct(etThread* self){
+void etThread_construct(
+ etThread* self,
+ etStacksize stacksize,
+ etPriority priority,
+ etThreadname threadName,
+ etThreadFunction threadFunction,
+ void* threadFunctionData)
+{
ET_MSC_LOGGER_SYNC_ENTRY("etThread", "construct")
+
+ /* fill in data */
+ self->stacksize = stacksize;
+ self->priority = priority;
+ self->threadName = threadName;
+ self->threadFunction = threadFunction;
+ self->threadFunctionData = threadFunctionData;
+
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etThread_start(etThread* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etThread", "start")
self->osData = (HANDLE)_beginthread( (etThreadFunction)etThread_execute, self->stacksize, self );
SetThreadPriority(self->osData, self->priority);
ET_MSC_LOGGER_SYNC_EXIT
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 7e98fc932..8d2adc797 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
@@ -26,42 +26,65 @@
/** 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 = timerFunction;
- if (hTimerQueue == NULL){
- /* the Windows timer queue is only needed once for all timers */
- hTimerQueue = CreateTimerQueue();
+VOID CALLBACK etTimer_callback(PVOID lpParameter, BOOLEAN TimerOrWaitFired);
+
+void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction timerFunction, void* timerFunctionData){
+ ET_MSC_LOGGER_SYNC_ENTRY("etTimer", "construct")
+ {
+ self->osTimerData = NULL;
+ self->timerInterval.sec = timerInterval->sec;
+ self->timerInterval.nSec = timerInterval->nSec;
+ self->timerFunction = timerFunction;
+ self->timerFunctionData = timerFunctionData;
if (hTimerQueue == NULL){
- etLogger_logError("etTimer_construct: CreateTimerQueue failed");
+ /* the Windows timer queue is only needed once for all timers */
+ hTimerQueue = CreateTimerQueue();
+ if (hTimerQueue == NULL){
+ etLogger_logError("etTimer_construct: CreateTimerQueue failed");
+ }
}
}
+ ET_MSC_LOGGER_SYNC_EXIT
}
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));
+ ET_MSC_LOGGER_SYNC_ENTRY("etTimer", "start")
+ {
+ /* calculate the time in milliseconds -> accuracy of nSec will get lost in windows! */
+ UINT elapse = etTimeHelpers_convertToMSec(&(self->timerInterval));
- 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");
+ if (hTimerQueue == NULL){
+ etLogger_logError("etTimer_start: no Timer Queue to create timer (NULL)");
+ }
+ else {
+ if (CreateTimerQueueTimer( &(self->osTimerData), hTimerQueue, etTimer_callback, self, 0, elapse, 0) == FALSE){
+ etLogger_logError("etTimer_start: Timer could not be created");
+ }
}
}
+ ET_MSC_LOGGER_SYNC_EXIT
}
void etTimer_stop(etTimer* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etTimer", "stop")
if (DeleteTimerQueueTimer(hTimerQueue, self->osTimerData, NULL) == FALSE){
etLogger_logError("etTimer_stop: Timer could not be stopped");
}
+ ET_MSC_LOGGER_SYNC_EXIT
}
void etTimer_destruct(etTimer* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etTimer", "destruct")
/* TODO: destroy hTimerQueue if last timer is destroyed */
/* DeleteTimerQueue(hTimerQueue); */
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+VOID CALLBACK etTimer_callback(PVOID lpParameter, BOOLEAN TimerOrWaitFired) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etTimer", "callback")
+ {
+ etTimer* self = (etTimer*) lpParameter;
+ self->timerFunction(self->timerFunctionData);
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
}

Back to the top