Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2013-01-04 11:16:07 -0500
committerThomas Schuetz2013-01-04 11:16:07 -0500
commitd098da1cde5c178c682c57533e514b3e4976250e (patch)
treecea8f78fe0090de6d3f38f80a36aa5dcf075e981 /runtime/org.eclipse.etrice.runtime.c/src/common
parentec0a83ccb44871498c61260c961a911ec2663531 (diff)
downloadorg.eclipse.etrice-d098da1cde5c178c682c57533e514b3e4976250e.tar.gz
org.eclipse.etrice-d098da1cde5c178c682c57533e514b3e4976250e.tar.xz
org.eclipse.etrice-d098da1cde5c178c682c57533e514b3e4976250e.zip
[runtime.c , generator.c.reference] first running version of C reference
code with new runtime API - synchronization does not work yet! Change-Id: Ib37b1a0ea7f3d790cb655d68240c36fe9840dc98
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/common')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.c6
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.h6
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c41
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h17
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/platform/etPlatform.h36
5 files changed, 99 insertions, 7 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.c b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.c
index fa0fc43e1..d9dd15e66 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.c
@@ -63,3 +63,9 @@ void etMSCLogger_asyncIn(char* sourceName, char* messageName, char* targetName){
etLogger_fprintf(etMSCLogger_fileHandle, "%s --> %s %s\n", sourceName, targetName, messageName);
}
}
+
+void etMSCLogger_setState(char* objectName, char* stateName){
+ if (etMSCLogger_fileHandle != NULL) {
+ etLogger_fprintf(etMSCLogger_fileHandle, "%s >>> %s\n", objectName, stateName);
+ }
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.h b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.h
index 2ab4c8ecf..6138fb45a 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/debugging/etMSCLogger.h
@@ -27,6 +27,8 @@ void etMSCLogger_syncReturn(char* sourceName, char* targetName);
void etMSCLogger_asyncOut(char* sourceName, char* messageName, char* targetName);
void etMSCLogger_asyncIn(char* sourceName, char* messageName, char* targetName);
+void etMSCLogger_setState(char* objectName, char* stateName);
+
#ifdef ET_MSC_LOGGER_ACTIVATE
#define ET_MSC_LOGGER_OPEN(object) \
etMSCLogger_open("tmp", "msc"); \
@@ -40,10 +42,14 @@ void etMSCLogger_asyncIn(char* sourceName, char* messageName, char* targetName);
etMSCLogger_syncCall(sourceName, message, targetName); \
etMSCLogger_setObjectName(targetName);
+
#define ET_MSC_LOGGER_SYNC_EXIT \
etMSCLogger_syncReturn(sourceName, targetName); \
etMSCLogger_setObjectName(sourceName);
+ #define ET_MSC_LOGGER_CHANGE_STATE(objectName, stateName) \
+ etMSCLogger_setState(objectName, stateName);
+
#else
#define ET_MSC_LOGGER_OPEN
#define ET_MSC_LOGGER_CLOSE
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..59e205e99 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
@@ -17,20 +17,55 @@
#include "debugging/etLogger.h"
#include "debugging/etMSCLogger.h"
+
+
+/*
+ * 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){
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;
- etMessageQueue_init(&self->messagePool);
- etMessageQueue_init(&self->messageQueue);
-
+ /* copy 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) );
+
ET_MSC_LOGGER_SYNC_EXIT
}
+void etMessageService_start(etMessageService* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "start")
+ etThread_construct( &(self->thread) );
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etMessageService_stop(etMessageService* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "stop")
+ etThread_destruct( &(self->thread) );
+ 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
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..f91cb3f82 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
@@ -17,6 +17,8 @@
#include "etDatatypes.h"
#include "messaging/etMessageQueue.h"
#include "messaging/etMessageReceiver.h"
+#include "platform/etPlatform.h"
+
typedef struct etBuffer{
etUInt8 *buffer;
@@ -29,20 +31,31 @@ typedef struct etMessageService {
etMessageQueue messagePool;
etBuffer messageBuffer;
etDispatcherReceiveMessage msgDispatcher;
+ etThread thread;
+ etMutex poolMutex;
+ etMutex queueMutex;
+ etSema executionSemaphore; /* sempahore for waiting and waking up the execution */
} 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_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/platform/etPlatform.h b/runtime/org.eclipse.etrice.runtime.c/src/common/platform/etPlatform.h
index 3402f1790..66d56c894 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/platform/etPlatform.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/platform/etPlatform.h
@@ -23,23 +23,55 @@
/* platform specific functions */
/******************thread********************/
-void etThread_construct(etThread* self, const etThreadname name, void (*func)(void *), etStacksize stacksize, etPriority prio);
+
+typedef int32 etStacksize;
+typedef int32 etPriority;
+typedef charPtr etThreadname;
+typedef void (*etThreadFunction)(void *);
+
+typedef struct etThread{
+ etOSThreadData osData; /* OS specific thread data (e.g. handle or id) */
+ etStacksize stacksize;
+ etPriority priority;
+ etThreadname threadName;
+ etThreadFunction threadFunction;
+ void* threadFunctionData;
+} etThread;
+
+
+void etThread_construct(etThread* self);
void etThread_destruct(etThread* self);
+/******************thread helpers********************/
+void etThread_sleep(etInt32 millis);
+
+
/*****************mutex**********************/
+
+typedef struct etMutex {
+ etOSMutexData osData;
+} etMutex;
+
void etMutex_construct(etMutex* self);
void etMutex_destruct(etMutex* self);
void etMutex_enter(etMutex* self);
void etMutex_leave(etMutex* self);
/********************semaphore****************/
-void etSema_contruct(etSema* self);
+
+typedef struct etSema {
+ etOSSemaData osData;
+} etSema;
+
+void etSema_construct(etSema* self);
void etSema_destruct(etSema* self);
void etSema_wakeup(etSema* self);
void etSema_waitForWakeup(etSema* self);
/*********************************************/
+
+
/*
* Platform startup and shutdown -> generated code for SubSystemClass uses these interfaces
* */

Back to the top