From afc4b117aab39c0f6f726c4efdaa83f441faf61c Mon Sep 17 00:00:00 2001 From: Thomas Schuetz Date: Sun, 26 Feb 2012 15:58:40 +0100 Subject: [runtime.c] reorganized runtime.c for separation of common and platform specific parts, adapted include pathes, C-generator and tests --- .../src/common/messaging/etMessage.c | 25 +++++ .../src/common/messaging/etMessage.h | 26 ++++++ .../src/common/messaging/etMessageQueue.c | 99 ++++++++++++++++++++ .../src/common/messaging/etMessageQueue.h | 45 +++++++++ .../src/common/messaging/etMessageReceiver.h | 23 +++++ .../src/common/messaging/etMessageService.c | 103 +++++++++++++++++++++ .../src/common/messaging/etMessageService.h | 50 ++++++++++ 7 files changed, 371 insertions(+) create mode 100644 runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessage.c create mode 100644 runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessage.h create mode 100644 runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c create mode 100644 runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h create mode 100644 runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageReceiver.h create mode 100644 runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c create mode 100644 runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h (limited to 'runtime/org.eclipse.etrice.runtime.c/src/common/messaging') diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessage.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessage.c new file mode 100644 index 000000000..224461432 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessage.c @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2011 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 "messaging/etMessage.h" + +#include "debugging/etMSCLogger.h" + +#include + +void etMessage_init(etMessage* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessage", "init") + self->next = NULL; + self->address = 0; + self->evtID = 0; + ET_MSC_LOGGER_SYNC_EXIT +} diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessage.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessage.h new file mode 100644 index 000000000..7bba6a1f3 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessage.h @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2011 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 _ETMESSAGE_H_ +#define _ETMESSAGE_H_ + +#include "etDatatypes.h" + +typedef struct etMessage{ + struct etMessage* next; + etInt16 address; + etInt16 evtID; +} etMessage; + +void etMessage_init(etMessage* self); + +#endif /* _ETMESSAGE_H_ */ 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 new file mode 100644 index 000000000..2ba045420 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2011 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 "messaging/etMessageQueue.h" + +#include "debugging/etMSCLogger.h" + +void etMessageQueue_init(etMessageQueue* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "init") + self->first = NULL; + self->last = NULL; + self->highWaterMark = 0; + self->size = 0; + ET_MSC_LOGGER_SYNC_EXIT +} + + +void etMessageQueue_push(etMessageQueue* self, etMessage* msg){ + // TODO: optimize queue for concurrent push / pop + ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "push") + if (self->first == NULL) { + /*no message in queue*/ + self->first = self->last = msg; + } + else { + /*at least one message in queue*/ + self->last->next = msg; + self->last = msg; + } + msg->next = NULL; /*TODO: optimization: this line could be removed if we assume that all messages are initialized*/ + + if (++self->size > self->highWaterMark) + self->highWaterMark++; + + ET_MSC_LOGGER_SYNC_EXIT +} + +etMessage* etMessageQueue_pop(etMessageQueue* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "pop") + etMessage* pop_msg = self->first; + if(self->first == NULL){ + /*no message in queue*/ + ET_MSC_LOGGER_SYNC_EXIT + return NULL; + } + if (self->first->next==NULL){ + /*only one message in queue*/ + self->first = self->last = NULL; + } + else { + /*more than one message in queue -> set first to nex message*/ + self->first = self->first->next; + } + + pop_msg->next=NULL; + self->size--; + + ET_MSC_LOGGER_SYNC_EXIT + return pop_msg; +} + +etInt16 etMessageQueue_getSize(etMessageQueue* self) { + ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getSize") + ET_MSC_LOGGER_SYNC_EXIT + return self->size; +} + +etMessage* etMessageQueue_getFirst(etMessageQueue* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getFirst") + ET_MSC_LOGGER_SYNC_EXIT + return self->first; +} + +etMessage* etMessageQueue_getLast(etMessageQueue* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getLast") + ET_MSC_LOGGER_SYNC_EXIT + return self->last; +} + +etBool etMessageQueue_isNotEmpty(etMessageQueue* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "isNotEmpty") + ET_MSC_LOGGER_SYNC_EXIT + return self->last != NULL; +} + +etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self) { + ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getHightWaterMark") + ET_MSC_LOGGER_SYNC_EXIT + return self->highWaterMark; +} 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 new file mode 100644 index 000000000..473df5c0f --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011 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 _ETMESSAGEQUEUE_H_ +#define _ETMESSAGEQUEUE_H_ + +#include "messaging/etMessage.h" +#include + +typedef struct etMessageQueue { + etMessage* first; + etMessage* last; + etInt16 highWaterMark; + etInt16 size; + +} 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); + + + +#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 new file mode 100644 index 000000000..5c6aa690a --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageReceiver.h @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2012 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 _ETMESSAGERECEIVER_H_ +#define _ETMESSAGERECEIVER_H_ + +#include "messaging/etMessage.h" + +typedef void (*etActorReceiveMessage)(void* self, void* ifitem, const etMessage* msg); +typedef void (*etDispatcherReceiveMessage)(const etMessage* msg); + +#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 new file mode 100644 index 000000000..b7c91faf8 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2011 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 "etMessageService.h" + + +#include "debugging/etLogger.h" +#include "debugging/etMSCLogger.h" + +void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "init") + self->messageBuffer.buffer = buffer; + self->messageBuffer.maxBlocks = maxBlocks; + self->messageBuffer.blockSize = blockSize; + self->msgDispatcher = msgDispatcher; + + etMessageQueue_init(&self->messagePool); + etMessageQueue_init(&self->messageQueue); + + etMessageService_initMessagePool(self); + ET_MSC_LOGGER_SYNC_EXIT +} + +/* + * initialize message pool with block buffer + * all blocks are added to pool + */ +void etMessageService_initMessagePool(etMessageService* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "initMessagePool") + etInt16 i; + + for (i=0; imessageBuffer.maxBlocks; i++){ + etMessage* block = (etMessage*) &self->messageBuffer.buffer[i*self->messageBuffer.blockSize]; + etMessageQueue_push(&self->messagePool, block); + } + ET_MSC_LOGGER_SYNC_EXIT +} + +void etMessageService_pushMessage(etMessageService* self, etMessage* msg){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "pushMessage") + etMessageQueue_push(&self->messageQueue, msg); + ET_MSC_LOGGER_SYNC_EXIT +} + +etMessage* etMessageService_popMessage(etMessageService* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "popMessage") + etMessage* msg = etMessageQueue_pop(&self->messageQueue); + ET_MSC_LOGGER_SYNC_EXIT + return msg; +} + + +etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 size){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "getMessageBuffer") + if (size<=self->messageBuffer.blockSize){ + if (self->messagePool.size>0){ + etMessage* msg = etMessageQueue_pop(&self->messagePool); + ET_MSC_LOGGER_SYNC_EXIT + return msg; + } + } + ET_MSC_LOGGER_SYNC_EXIT + return NULL; +} + +void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buffer){ + ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "returnMessageBuffer") + etMessageQueue_push(&self->messagePool, buffer); + ET_MSC_LOGGER_SYNC_EXIT +} + +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); + } + 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); + ET_MSC_LOGGER_SYNC_EXIT + return lowWaterMark; +} 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 new file mode 100644 index 000000000..f978e1eb7 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2011 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 _ETMESSAGESERVICE_H_ +#define _ETMESSAGESERVICE_H_ + +#include +#include "etDatatypes.h" +#include "messaging/etMessageQueue.h" +#include "messaging/etMessageReceiver.h" + +typedef struct etBuffer{ + etUInt8 *buffer; + etUInt16 maxBlocks; + etUInt16 blockSize; +} etBuffer; + +typedef struct etMessageService { + etMessageQueue messageQueue; + etMessageQueue messagePool; + etBuffer messageBuffer; + etDispatcherReceiveMessage msgDispatcher; +} etMessageService; + +void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher); + +void etMessageService_initMessagePool(etMessageService* self); + +void etMessageService_pushMessage(etMessageService* self, etMessage* msg); +etMessage* etMessageService_popMessage(etMessageService* self); + +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); + + +#endif /* RMESSAGESERVICE_H_ */ -- cgit v1.2.3