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
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')
-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
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/config/etRuntimeConfig.h2
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etDatatypes.h22
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etPlatform.c71
8 files changed, 164 insertions, 37 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
* */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/config/etRuntimeConfig.h b/runtime/org.eclipse.etrice.runtime.c/src/config/etRuntimeConfig.h
index 9ae2781bb..e19bba3e7 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/config/etRuntimeConfig.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/config/etRuntimeConfig.h
@@ -26,7 +26,7 @@
//#define ET_RUNTIME_ENDLESS
/* pool and block size */
-#define MESSAGE_POOL_MAX 50
+#define MESSAGE_POOL_MAX 10
#define MESSAGE_BLOCK_SIZE 64
/* enable multi threading (e.g. for protection of message queues) */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etDatatypes.h
index 10c4e98f6..7586d5dff 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etDatatypes.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etDatatypes.h
@@ -96,27 +96,23 @@ typedef int8 etAddressId;
#if defined __MINGW32__
- typedef CRITICAL_SECTION etMutex;
- typedef HANDLE etThread;
- typedef HANDLE etSema;
+ typedef CRITICAL_SECTION etOSMutexData;
+ typedef HANDLE etOSThreadData;
+ typedef HANDLE etOSSemaData;
+
- typedef int32 etStacksize;
- typedef int32 etPriority;
- typedef charPtr etThreadname;
#elif defined __GNUC__
/* dummy for LINUX/UNIX */
- typedef int etMutex;
- typedef int etThread;
- typedef int etSema;
-
- typedef int32 etStacksize;
- typedef int32 etPriority;
- typedef charPtr etThreadname;
+ typedef int etOSMutexData;
+ typedef int etOSThreadData;
+ typedef int etOSSemaData;
#else
#error
#endif
+
+
#endif /* _DATATYPES_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etPlatform.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etPlatform.c
index 593ccefc4..e29a8ec0a 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etPlatform.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/generic/etPlatform.c
@@ -10,7 +10,11 @@
*
*******************************************************************************/
-#include <etDatatypes.h>
+#include "etDatatypes.h"
+#include "platform/etPlatform.h"
+
+#include "debugging/etLogger.h"
+#include "debugging/etMSCLogger.h"
/* implemenatation for eTrice interfaces*/
@@ -28,44 +32,79 @@ void etUserExit(void){ }
#if defined __MINGW32__
/******************thread********************/
-void etThread_construct(etThread* self, const etThreadname name, void (*func)(void *), etStacksize stacksize, etPriority prio){
- *self = (HANDLE)_beginthread( func, stacksize, NULL );
- SetThreadPriority(*self,THREAD_PRIORITY_NORMAL);
+void etThread_construct(etThread* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etThread", "construct")
+ self->osData = (HANDLE)_beginthread( self->threadFunction, self->stacksize, self->threadFunctionData );
+ SetThreadPriority(self->osData, self->priority);
+ ET_MSC_LOGGER_SYNC_EXIT
}
-void etThread_destruct(etThread* self){}
+void etThread_destruct(etThread* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etThread", "destruct")
+ TerminateThread(self->osData, 0);
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+
+/******************thread helpers********************/
+void etThread_sleep(etInt32 millis){
+ ET_MSC_LOGGER_SYNC_ENTRY("etThread", "sleep")
+ Sleep(millis);
+ ET_MSC_LOGGER_SYNC_EXIT
+}
/*****************mutex**********************/
void etMutex_construct(etMutex* self){
- InitializeCriticalSection( self );
+ ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "construct")
+ InitializeCriticalSection( &(self->osData) );
+ ET_MSC_LOGGER_SYNC_EXIT
}
-void etMutex_destruct(etMutex* self){}
+void etMutex_destruct(etMutex* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "destruct")
+ DeleteCriticalSection( &(self->osData) );
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
void etMutex_enter(etMutex* self){
- EnterCriticalSection( self );
+ ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "enter")
+ EnterCriticalSection( &(self->osData) );
+ ET_MSC_LOGGER_SYNC_EXIT
}
void etMutex_leave(etMutex* self){
- LeaveCriticalSection( self );
+ ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "leave")
+ LeaveCriticalSection( &(self->osData) );
+ ET_MSC_LOGGER_SYNC_EXIT
}
/********************semaphore****************/
-void etSema_contruct(etSema* self){
- *self = CreateEvent( NULL, FALSE, FALSE, NULL );
+void etSema_construct(etSema* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etSema", "construct")
+ self->osData = CreateEvent( NULL, FALSE, FALSE, NULL );
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+void etSema_destruct(etSema* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etSema", "destruct")
+ // TODO: implement this function
+ ET_MSC_LOGGER_SYNC_EXIT
}
-void etSema_destruct(etSema* self){}
void etSema_wakeup(etSema* self){
- SetEvent(self);
+ ET_MSC_LOGGER_SYNC_ENTRY("etSema", "wakeup")
+ SetEvent( self->osData );
+ ET_MSC_LOGGER_SYNC_EXIT
}
void etSema_waitForWakeup(etSema* self){
- WaitForSingleObject( self, INFINITE );
+ ET_MSC_LOGGER_SYNC_ENTRY("etSema", "waitForWakeup")
+ WaitForSingleObject( self->osData, INFINITE );
+ ET_MSC_LOGGER_SYNC_EXIT
}
/*********************************************/
#elif defined __GNUC__
/******************thread********************/
-void etThread_construct(etThread* self, const etThreadname name, void (*func)(void *), etStacksize stacksize, etPriority prio){}
+void etThread_construct(etThread* self){}
void etThread_destruct(etThread* self){}
@@ -76,7 +115,7 @@ void etMutex_enter(etMutex* self){}
void etMutex_leave(etMutex* self){}
/********************semaphore****************/
-void etSema_contruct(etSema* self){}
+void etSema_construct(etSema* self){}
void etSema_destruct(etSema* self){}
void etSema_wakeup(etSema* self){}

Back to the top