Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-05-03 13:36:27 -0400
committerHenrik Rentz-Reichert2013-05-03 13:36:27 -0400
commit888b3e7bb9a93185babc3f5609397ac741dddc0b (patch)
tree8e73713f0112a366878dd077afc16f2de7826768 /runtime/org.eclipse.etrice.runtime.c/src/common/messaging
parent72d62b85fd7827cf9613bfde265324fb565870ba (diff)
parentee471f38eb0e1cf3b363fd3fd5206c2c33d05f47 (diff)
downloadorg.eclipse.etrice-888b3e7bb9a93185babc3f5609397ac741dddc0b.tar.gz
org.eclipse.etrice-888b3e7bb9a93185babc3f5609397ac741dddc0b.tar.xz
org.eclipse.etrice-888b3e7bb9a93185babc3f5609397ac741dddc0b.zip
Merge remote-tracking branch 'origin/CGenPhysical'
Conflicts: examples/org.eclipse.etrice.generator.c.reference/model/cGenRef.room plugins/org.eclipse.etrice.core.etmap/xtend-gen/org/eclipse/etrice/core/etmap/generator/ETMapGenerator.java plugins/org.eclipse.etrice.core.etphys.ui/src-gen/org/eclipse/etrice/core/etphys/ui/contentassist/antlr/internal/InternalETPhysLexer.java plugins/org.eclipse.etrice.core.etphys/.launch/Generate Language Infrastructure (org.eclipse.etrice.core.etphys).launch plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/ETPhys.ecore plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/parser/antlr/internal/InternalETPhysLexer.java plugins/org.eclipse.etrice.core.etphys/xtend-gen/org/eclipse/etrice/core/etphys/generator/ETPhysGenerator.java plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/etricegen/Root.java plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/StateMachineGen.xtend plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.xtend plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/DataClassGen.java plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/Initialization.java plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.java plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.java plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.java plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.java plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/Initialization.java plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/MainGen.java plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.java plugins/org.eclipse.etrice.generator.doc/xtend-gen/org/eclipse/etrice/generator/doc/gen/DocGen.java plugins/org.eclipse.etrice.generator.doc/xtend-gen/org/eclipse/etrice/generator/doc/gen/InstanceDiagramGen.java plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemClassGen.java plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/SubSystemRunnerGen.java plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/VariableServiceGen.java plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/RoomExtensions.xtend plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericActorClassGenerator.java plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericProtocolClassGenerator.java plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/PrepareFileSystem.java plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ProcedureHelpers.java plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/RoomExtensions.java plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.modellib.c.zip plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.modellib.cpp.zip plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.modellib.java.zip plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.runtime.c.zip plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.runtime.cpp.zip plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.runtime.java.zip plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.tutorials.c.zip plugins/org.eclipse.etrice.ui.runtime/create_contents.xml runtime/org.eclipse.etrice.modellib.c/.gitignore runtime/org.eclipse.etrice.runtime.c/.cproject runtime/org.eclipse.etrice.runtime.c/src/common/platform/etPlatform.h runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etDatatypes.h runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etLogger.c runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etPlatform.c
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/common/messaging')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c18
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h9
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageReceiver.h3
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c135
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h53
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.c89
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.h51
7 files changed, 325 insertions, 33 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c
index 16583e7d6..145432dd1 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c
@@ -19,6 +19,7 @@ void etMessageQueue_init(etMessageQueue* self){
self->first = NULL;
self->last = NULL;
self->highWaterMark = 0;
+ self->lowWaterMark = 0;
self->size = 0;
ET_MSC_LOGGER_SYNC_EXIT
}
@@ -64,6 +65,9 @@ etMessage* etMessageQueue_pop(etMessageQueue* self){
pop_msg->next=NULL;
self->size--;
+ if (self->size < self->lowWaterMark)
+ self->lowWaterMark--;
+
ET_MSC_LOGGER_SYNC_EXIT
return pop_msg;
}
@@ -93,7 +97,19 @@ etBool etMessageQueue_isNotEmpty(etMessageQueue* self){
}
etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self) {
- ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getHightWaterMark")
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getHighWaterMark")
ET_MSC_LOGGER_SYNC_EXIT
return self->highWaterMark;
}
+
+etInt16 etMessageQueue_getLowWaterMark(etMessageQueue* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getLowWaterMark")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->lowWaterMark;
+}
+
+void etMessageQueue_resetLowWaterMark(etMessageQueue* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "resetLowWaterMark")
+ self->lowWaterMark = self->size;
+ ET_MSC_LOGGER_SYNC_EXIT
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h
index f305d1aa9..a9a6cb13e 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h
@@ -20,6 +20,7 @@ typedef struct etMessageQueue {
etMessage* first;
etMessage* last;
etInt16 highWaterMark;
+ etInt16 lowWaterMark;
etInt16 size;
} etMessageQueue;
@@ -27,19 +28,17 @@ typedef struct etMessageQueue {
void etMessageQueue_init(etMessageQueue* self);
void etMessageQueue_push(etMessageQueue* self, etMessage* msg);
-
etMessage* etMessageQueue_pop(etMessageQueue* self);
etMessage* etMessageQueue_getFirst(etMessageQueue* self);
-
etMessage* etMessageQueue_getLast(etMessageQueue* self);
etBool etMessageQueue_isNotEmpty(etMessageQueue* self);
-etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self);
-
etInt16 etMessageQueue_getSize(etMessageQueue* self);
-
+etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self);
+etInt16 etMessageQueue_getLowWaterMark(etMessageQueue* self);
+void etMessageQueue_resetLowWaterMark(etMessageQueue* self);
#endif /* _RMESSAGEQUEUE_H_ */
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 a1bd92ce2..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,6 +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 3755d2107..b2140166a 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,23 +14,92 @@
#include "etMessageService.h"
+#include "etSystemProtocol.h"
#include "debugging/etLogger.h"
#include "debugging/etMSCLogger.h"
-void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher){
+static void etMessageService_timerCallback(void* data);
+static void etMessageService_deliverAllMessages(etMessageService* self);
+
+/*
+ * 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,
+ etStacksize stacksize,
+ etPriority priority,
+ etTime interval,
+ etDispatcherReceiveMessage msgDispatcher,
+ etMessageService_execmode execmode){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "init")
+
+ /* copy init data to self */
self->messageBuffer.buffer = buffer;
self->messageBuffer.maxBlocks = maxBlocks;
self->messageBuffer.blockSize = blockSize;
self->msgDispatcher = msgDispatcher;
+ self->execmode = execmode;
- etMessageQueue_init(&self->messagePool);
- etMessageQueue_init(&self->messageQueue);
-
+ /* init queue and pool */
+ etMessageQueue_init( &(self->messagePool) ); /* the pool is also a queue*/
+ etMessageQueue_init( &(self->messageQueue) );
etMessageService_initMessagePool(self);
+
+ /* init mutexes and semaphores */
+ etMutex_construct( &(self->poolMutex) );
+ etMutex_construct( &(self->queueMutex) );
+ etSema_construct( &(self->executionSemaphore) );
+
+ /* init thread */
+ etThread_construct(&self->thread, stacksize, priority, "MessageService", (etThreadFunction) etMessageService_deliverAllMessages, 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_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")
+
+ 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
}
+void etMessageService_destroy(etMessageService* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "destroy")
+ etMutex_destruct( &(self->poolMutex) );
+ etMutex_destruct( &(self->queueMutex) );
+ etSema_destruct( &(self->executionSemaphore) );
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+
/*
* initialize message pool with block buffer
* all blocks are added to pool
@@ -43,18 +112,24 @@ void etMessageService_initMessagePool(etMessageService* self){
etMessage* block = (etMessage*) &self->messageBuffer.buffer[i*self->messageBuffer.blockSize];
etMessageQueue_push(&self->messagePool, block);
}
+ etMessageQueue_resetLowWaterMark(&self->messagePool);
ET_MSC_LOGGER_SYNC_EXIT
}
void etMessageService_pushMessage(etMessageService* self, etMessage* msg){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "pushMessage")
+ etMutex_enter(&self->queueMutex);
etMessageQueue_push(&self->messageQueue, msg);
+ etSema_wakeup(&self->executionSemaphore);
+ etMutex_leave(&self->queueMutex);
ET_MSC_LOGGER_SYNC_EXIT
}
etMessage* etMessageService_popMessage(etMessageService* self){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "popMessage")
+ etMutex_enter(&self->queueMutex);
etMessage* msg = etMessageQueue_pop(&self->messageQueue);
+ etMutex_leave(&self->queueMutex);
ET_MSC_LOGGER_SYNC_EXIT
return msg;
}
@@ -62,42 +137,70 @@ etMessage* etMessageService_popMessage(etMessageService* self){
etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 size){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "getMessageBuffer")
+ etMutex_enter(&self->poolMutex);
if (size<=self->messageBuffer.blockSize){
if (self->messagePool.size>0){
etMessage* msg = etMessageQueue_pop(&self->messagePool);
+ etMutex_leave(&self->poolMutex);
ET_MSC_LOGGER_SYNC_EXIT
return msg;
}
+ else {
+ etLogger_logErrorF("etMessageService_getMessageBuffer: message pool empty: %d", etMessageService_getMessagePoolLowWaterMark(self));
+ }
}
+ else {
+ etLogger_logErrorF("etMessageService_getMessageBuffer: message too big: %d, blockSize: %d", size, self->messageBuffer.blockSize);
+ }
+ etMutex_leave(&self->poolMutex);
ET_MSC_LOGGER_SYNC_EXIT
return NULL;
}
void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buffer){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "returnMessageBuffer")
+ etMutex_enter(&self->poolMutex);
etMessageQueue_push(&self->messagePool, buffer);
+ etMutex_leave(&self->poolMutex);
ET_MSC_LOGGER_SYNC_EXIT
}
-void etMessageService_deliverAllMessages(etMessageService* self){
+static void etMessageService_deliverAllMessages(etMessageService* self){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "deliverAllMessages")
- 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);
+ }
}
ET_MSC_LOGGER_SYNC_EXIT
}
-void etMessageService_execute(etMessageService* self){
- ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "execute")
- etMessageService_deliverAllMessages(self);
- ET_MSC_LOGGER_SYNC_EXIT
-}
-
etInt16 etMessageService_getMessagePoolLowWaterMark(etMessageService* self){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "getMessagePoolLowWaterMark")
- etInt16 lowWaterMark = self->messageBuffer.maxBlocks - etMessageQueue_getHighWaterMark(&self->messageQueue);
+ etInt16 lowWaterMark = etMessageQueue_getLowWaterMark(&self->messagePool);
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 0303bbf0c..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
@@ -18,31 +18,64 @@
#include "messaging/etMessageQueue.h"
#include "messaging/etMessageReceiver.h"
+#include "osal/etMutex.h"
+#include "osal/etThread.h"
+#include "osal/etSema.h"
+#include "osal/etTimer.h"
+
+#define MESSAGESERVICE_ADDRESS 1
+#define BASE_ADDRESS 32
+
+typedef enum etMessageService_execmode {
+ EXECMODE_POLLED, EXECMODE_BLOCKED, EXECMODE_MIXED
+} etMessageService_execmode;
+
typedef struct etBuffer{
- etUInt8 *buffer;
- etUInt16 maxBlocks;
- etUInt16 blockSize;
+ etUInt8 *buffer; /** buffer points to the actual memory position for the message pool */
+ etUInt16 maxBlocks; /** number of blocks for the message pool */
+ etUInt16 blockSize; /** size of blocks for the message pool */
} etBuffer;
typedef struct etMessageService {
- etMessageQueue messageQueue;
- etMessageQueue messagePool;
- etBuffer messageBuffer;
- etDispatcherReceiveMessage msgDispatcher;
+ etMessageQueue messageQueue; /** message queue that holds all used messages */
+ 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 */
+ 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; /** semaphore for waiting and waking up the execution */
+ etTimer timer; /** timer for cyclic calls */
+ etMessageService_execmode execmode; /** execution mode*/
} etMessageService;
-void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher);
+/* lifecycle functions to startup, execute and shutdown the message service */
+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);
+void etMessageService_destroy(etMessageService* self);
+/* initialization of message pool */
void etMessageService_initMessagePool(etMessageService* self);
+/* message queue interface for push and pop messages */
void etMessageService_pushMessage(etMessageService* self, etMessage* msg);
etMessage* etMessageService_popMessage(etMessageService* self);
+/* message pool interface to get and return (push and pop) messages */
etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 size);
void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buffer);
-void etMessageService_execute(etMessageService* self);
-
/* functions for debug and service information */
etInt16 etMessageService_getMessagePoolLowWaterMark(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
new file mode 100644
index 000000000..d13520335
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.c
@@ -0,0 +1,89 @@
+/**
+ * @author generated by eTrice
+ *
+ * Source File of ProtocolClass etSystemProtocol
+ *
+ */
+
+#include "etSystemProtocol.h"
+#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", "terminate", "MAX"};
+
+const char* etSystemProtocol_getMessageString(int msg_id) {
+ if (msg_id<etSystemProtocol_MSG_MIN || msg_id>etSystemProtocol_MSG_MAX+1){
+ /* id out of range */
+ return "Message ID out of range";
+ }
+ else{
+ return etSystemProtocol_messageStrings[msg_id];
+ }
+}
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
new file mode 100644
index 000000000..730d5dbce
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.h
@@ -0,0 +1,51 @@
+/**
+ * @author generated by eTrice
+ *
+ * Header File of ProtocolClass etSystemProtocol
+ *
+ */
+
+#ifndef _ETSYSTEMPROTOCOL_H_
+#define _ETSYSTEMPROTOCOL_H_
+
+#include "etDatatypes.h"
+#include "modelbase/etPort.h"
+
+/* message IDs */
+enum etSystemProtocol_msg_ids {
+ etSystemProtocol_MSG_MIN = 0,
+ etSystemProtocol_IN_poll = 1,
+ 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 */
+
+/* get message string for message id */
+const char* etSystemProtocol_getMessageString(int msg_id);
+
+
+#endif /* _ETSYSTEMPROTOCOL_H_ */
+

Back to the top