Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2013-04-10 02:00:18 -0400
committerThomas Schuetz2013-04-10 02:00:18 -0400
commitbdeb20297bf7a180e1ade30970f72696f40204c2 (patch)
tree94e340624c9309b03b2f97a4ed832122657e3198 /runtime/org.eclipse.etrice.runtime.c/src/common/messaging
parent95537aab385a67c1423fc8961763dd8b43c3f836 (diff)
downloadorg.eclipse.etrice-bdeb20297bf7a180e1ade30970f72696f40204c2.tar.gz
org.eclipse.etrice-bdeb20297bf7a180e1ade30970f72696f40204c2.tar.xz
org.eclipse.etrice-bdeb20297bf7a180e1ade30970f72696f40204c2.zip
[runtime.c, generator.c] added WakeupService and changes for polled
execution for multi threading Change-Id: Ic911d89af77150210ce9e7b1ba023a8acfdfc5e3
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/common/messaging')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageReceiver.h1
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c10
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h31
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.c31
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.h34
-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.h42
7 files changed, 168 insertions, 14 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 a1bd92ce2..a569a0887 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
@@ -19,5 +19,6 @@
typedef void (*etActorReceiveMessage)(void* self, void* ifitem, const etMessage* msg);
typedef void (*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 de713f568..3d119ea80 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
@@ -23,7 +23,7 @@
* 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){
+void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher, etDispatcherExecute executeFct, enum etMessageService_execmode execmode){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "init")
/* copy init data to self */
@@ -31,6 +31,8 @@ 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 */
etMessageQueue_init( &(self->messagePool) ); /* the pool is also a queue*/
@@ -110,6 +112,12 @@ etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 si
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
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 f91cb3f82..7bfeaa2a0 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
@@ -20,26 +20,31 @@
#include "platform/etPlatform.h"
+enum etMessageService_execmode {
+ EXECMODE_POLLED, EXECMODE_BLOCKED, EXECMODE_MIXED
+};
+
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;
- etThread thread;
- etMutex poolMutex;
- etMutex queueMutex;
- etSema executionSemaphore; /* sempahore for waiting and waking up the execution */
+ 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 */
+ 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*/
} etMessageService;
-
/* lifecycle functions to startup, execute and shutdown the message service */
-void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher);
+void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher, etDispatcherExecute executeFct, enum 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
new file mode 100644
index 000000000..8fb1516cc
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.c
@@ -0,0 +1,31 @@
+/**
+ * @author generated by eTrice
+ *
+ * Source File of ProtocolClass etSystemProtocol
+ *
+ */
+
+#include "etSystemProtocol.h"
+#include "debugging/etMSCLogger.h"
+
+
+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
+}
+
+/*--------------------- debug helpers */
+
+/* message names as strings for debugging (generate MSC) */
+static const char* const etSystemProtocol_messageStrings[] = {"MIN", "poll", "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..f3f803fe9
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etSystemProtocol.h
@@ -0,0 +1,34 @@
+/**
+ * @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_MSG_MAX = 2
+};
+
+/*--------------------- port structs and methods */
+typedef etPort etSystemProtocolConjPort;
+
+
+void etSystemProtocolConjPort_poll(const etSystemProtocolConjPort* self);
+
+/*--------------------- debug helpers */
+
+/* get message string for message id */
+const char* etSystemProtocol_getMessageString(int msg_id);
+
+
+#endif /* _ETSYSTEMPROTOCOL_H_ */
+
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
new file mode 100644
index 000000000..ad288e9b5
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etWakeupService.c
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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
new file mode 100644
index 000000000..c8a54213a
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etWakeupService.h
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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"
+
+/**
+ * time definition composed by the number of seconds and the number of nano seconds
+ */
+typedef struct etTime {
+ etInt32 seconds;
+ etInt32 nseconds;
+} etTime;
+
+
+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_ */

Back to the top