Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
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.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
7 files changed, 159 insertions, 91 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_ */

Back to the top