Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2012-01-31 21:25:45 +0000
committerThomas Schuetz2012-01-31 21:25:45 +0000
commit01de373df4a524f266ad4250ea54d9aa30299920 (patch)
treeea2f77be21334d9daaf0156986d25e1a3e5b0a6f /plugins/org.eclipse.etrice.generator.c/src/org/eclipse
parent010759ae39852112ad533827402087c0e3daef59 (diff)
downloadorg.eclipse.etrice-01de373df4a524f266ad4250ea54d9aa30299920.tar.gz
org.eclipse.etrice-01de373df4a524f266ad4250ea54d9aa30299920.tar.xz
org.eclipse.etrice-01de373df4a524f266ad4250ea54d9aa30299920.zip
[generator.c] added const instances for ROM
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.c/src/org/eclipse')
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend240
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend4
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend4
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend29
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend92
5 files changed, 247 insertions, 122 deletions
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend
index 44fe509a8..f9583c2fa 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend
@@ -56,22 +56,17 @@ class ActorClassGen {
}
def generateHeaderFile(Root root, ExpandedActorClass xpac, ActorClass ac) {'''
- #ifndef _«xpac.name»_H_
- #define _«xpac.name»_H_
+ /**
+ * @author generated by eTrice
+ *
+ * Header File of ActorClass «xpac.name»
+ *
+ */
+
+ «generateIncludeGuardBegin(xpac.name)»
#include "etDatatypes.h"
- package «ac.getPackage»;
-
-««« import org.eclipse.etrice.runtime.java.messaging.Address;
-««« import org.eclipse.etrice.runtime.java.messaging.IRTObject;
-««« import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;
-««« import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;
-««« import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;
-««« import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;
-««« import org.eclipse.etrice.runtime.java.debugging.DebuggingService;
-
-
«FOR dataClass : root.getReferencedDataClasses(ac)»#include "«dataClass.name».h"
«ENDFOR»
@@ -80,110 +75,145 @@ class ActorClassGen {
«helpers.UserCode(ac.userCode1)»
+ typedef struct «xpac.name» «xpac.name»;
- public «IF ac.abstract»abstract «ENDIF»class «ac.name» extends «IF ac.base!=null»«ac.base.name»«ELSE»ActorClassBase«ENDIF» {
-
- «helpers.UserCode(ac.userCode2)»
-
- //--------------------- ports
- «FOR ep : ac.getEndPorts()»
- protected «ep.getPortClassName()» «ep.name» = null;
- «ENDFOR»
- //--------------------- saps
- «FOR sap : ac.strSAPs»
- protected «sap.getPortClassName()» «sap.name» = null;
- «ENDFOR»
- //--------------------- services
- «FOR svc : ac.serviceImplementations»
- protected «svc.getPortClassName()» «svc.spp.name» = null;
- «ENDFOR»
-
- //--------------------- interface item IDs
+ /* const part of ActorClass (ROM) */
+ typedef struct «xpac.name»_const {
+ const «xpac.name»* actor;
+ /* Ports */
«FOR ep : ac.getEndPorts()»
- protected static final int IFITEM_«ep.name» = «xpac.getInterfaceItemLocalId(ep)+1»;
- «ENDFOR»
- «FOR sap : ac.strSAPs»
- protected static final int IFITEM_«sap.name» = «xpac.getInterfaceItemLocalId(sap)+1»;
+ const «ep.getPortClassName()» «ep.name»;
«ENDFOR»
- «FOR svc : ac.serviceImplementations»
- protected static final int IFITEM_«svc.spp.name» = «xpac.getInterfaceItemLocalId(svc.spp)+1»;
- «ENDFOR»
-
- «helpers.Attributes(ac.attributes)»
- «helpers.OperationsDeclaration(ac.operations, ac.name)»
-
- //--------------------- construction
- public «ac.name»(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
- «IF ac.base==null»
- super(parent, name, port_addr[0][0], peer_addr[0][0]);
- «ELSE»
- super(parent, name, port_addr, peer_addr);
- «ENDIF»
- setClassName("«ac.name»");
-
- «ac.attributes.attributeInitialization»
-
- // own ports
- «FOR ep : ac.getEndPorts()»
- «ep.name» = new «ep.getPortClassName()»(this, "«ep.name»", IFITEM_«ep.name», «IF ep.multiplicity==1»0, «ENDIF»port_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF», peer_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF»);
- «ENDFOR»
- // own saps
- «FOR sap : ac.strSAPs»
- «sap.name» = new «sap.getPortClassName()»(this, "«sap.name»", IFITEM_«sap.name», 0, port_addr[IFITEM_«sap.name»][0], peer_addr[IFITEM_«sap.name»][0]);
- «ENDFOR»
- // own service implementations
- «FOR svc : ac.serviceImplementations»
- «svc.spp.name» = new «svc.getPortClassName()»(this, "«svc.spp.name»", IFITEM_«svc.spp.name», port_addr[IFITEM_«svc.spp.name»], peer_addr[IFITEM_«svc.spp.name»]);
- «ENDFOR»
- }
+ } «xpac.name»_const;
- //--------------------- lifecycle functions
- public void init(){
- initUser();
- }
-
- public void start(){
- startUser();
- }
-
- «IF !ac.overridesStop()»
- public void stop(){
- stopUser();
- }
- «ENDIF»
-
- public void destroy(){
- destroyUser();
- }
-
- «IF ac.stateMachine != null»
- «stateMachineGen.genStateMachine(xpac, ac)»
- «ELSEIF !xpac.hasStateMachine()»
- //--------------------- no state machine
- @Override
- public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data) {
- handleSystemEvent(ifitem, evt, data);
- }
-
- @Override
- public void executeInitTransition(){
- }
- «ENDIF»
+ /* variable part of ActorClass (RAM) */
+ struct «xpac.name» {
+ const «xpac.name»_const* constData;
};
+
+ void «xpac.name»_ReceiveMessage(void* self, etInt16 localId, const etMessage*);
+
+
+««« public «IF ac.abstract»abstract «ENDIF»class «ac.name» extends «IF ac.base!=null»«ac.base.name»«ELSE»ActorClassBase«ENDIF» {
+«««
+«««
+««« //--------------------- ports
+««« «FOR ep : ac.getEndPorts()»
+««« protected «ep.getPortClassName()» «ep.name» = null;
+««« «ENDFOR»
+««« //--------------------- saps
+««« «FOR sap : ac.strSAPs»
+««« protected «sap.getPortClassName()» «sap.name» = null;
+««« «ENDFOR»
+««« //--------------------- services
+««« «FOR svc : ac.serviceImplementations»
+««« protected «svc.getPortClassName()» «svc.spp.name» = null;
+««« «ENDFOR»
+«««
+««« //--------------------- interface item IDs
+««« «FOR ep : ac.getEndPorts()»
+««« protected static final int IFITEM_«ep.name» = «xpac.getInterfaceItemLocalId(ep)+1»;
+««« «ENDFOR»
+««« «FOR sap : ac.strSAPs»
+««« protected static final int IFITEM_«sap.name» = «xpac.getInterfaceItemLocalId(sap)+1»;
+««« «ENDFOR»
+««« «FOR svc : ac.serviceImplementations»
+««« protected static final int IFITEM_«svc.spp.name» = «xpac.getInterfaceItemLocalId(svc.spp)+1»;
+««« «ENDFOR»
+«««
+««« «helpers.Attributes(ac.attributes)»
+««« «helpers.OperationsDeclaration(ac.operations, ac.name)»
+«««
+««« //--------------------- construction
+««« public «ac.name»(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
+««« «IF ac.base==null»
+««« super(parent, name, port_addr[0][0], peer_addr[0][0]);
+««« «ELSE»
+««« super(parent, name, port_addr, peer_addr);
+««« «ENDIF»
+««« setClassName("«ac.name»");
+«««
+««« «ac.attributes.attributeInitialization»
+«««
+««« // own ports
+««« «FOR ep : ac.getEndPorts()»
+««« «ep.name» = new «ep.getPortClassName()»(this, "«ep.name»", IFITEM_«ep.name», «IF ep.multiplicity==1»0, «ENDIF»port_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF», peer_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF»);
+««« «ENDFOR»
+««« // own saps
+««« «FOR sap : ac.strSAPs»
+««« «sap.name» = new «sap.getPortClassName()»(this, "«sap.name»", IFITEM_«sap.name», 0, port_addr[IFITEM_«sap.name»][0], peer_addr[IFITEM_«sap.name»][0]);
+««« «ENDFOR»
+««« // own service implementations
+««« «FOR svc : ac.serviceImplementations»
+««« «svc.spp.name» = new «svc.getPortClassName()»(this, "«svc.spp.name»", IFITEM_«svc.spp.name», port_addr[IFITEM_«svc.spp.name»], peer_addr[IFITEM_«svc.spp.name»]);
+««« «ENDFOR»
+««« }
+«««
+«««
+««« //--------------------- lifecycle functions
+««« public void init(){
+««« initUser();
+««« }
+«««
+««« public void start(){
+««« startUser();
+««« }
+«««
+««« «IF !ac.overridesStop()»
+««« public void stop(){
+««« stopUser();
+««« }
+««« «ENDIF»
+«««
+««« public void destroy(){
+««« destroyUser();
+««« }
+«««
+«««
+«««
+««« «IF ac.stateMachine != null»
+««« «stateMachineGen.genStateMachine(xpac, ac)»
+««« «ELSEIF !xpac.hasStateMachine()»
+««« //--------------------- no state machine
+««« @Override
+««« public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data) {
+««« handleSystemEvent(ifitem, evt, data);
+««« }
+«««
+««« @Override
+««« public void executeInitTransition(){
+««« }
+««« «ENDIF»
+««« };
+
+ «helpers.UserCode(ac.userCode2)»
- #endif /* _«xpac.name»_H_ */
+ «generateIncludeGuardEnd(xpac.name)»
'''
}
def generateSourceFile(Root root, ExpandedActorClass xpac, ActorClass ac) {'''
- #include "«xpac.getCHeaderFileName»"
-
- '''
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of ActorClass «xpac.name»
+ *
+ */
+
+ #include "«xpac.getCHeaderFileName»"
+
+ «helpers.UserCode(xpac.userCode3)»
+
+ void «xpac.name»_ReceiveMessage(void* self, etInt16 localId, const etMessage*){
+ etLogger_logInfoF("«xpac.name»_ReceiveMessage");
+ }
+
+ '''
}
- def msgArgs(Message msg) {
- '''«IF msg.data!=null»«msg.data.defaultValue()»«ENDIF»'''
- }
+// def msgArgs(Message msg) {
+// '''«IF msg.data!=null»«msg.data.defaultValue()»«ENDIF»'''
+// }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
index ecb13f00e..25bb074b7 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
@@ -80,6 +80,10 @@ class CExtensions implements ILanguageExtension {
return rc.name+".c";
}
+ def String getInstSourceFileName(RoomClass rc) {
+ return rc.name+"_Inst.h";
+ }
+
def getIncludeGuardString(String filename){
'''_«filename.toUpperCase»_H_'''
}
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend
index ec4181d09..c4398b24a 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend
@@ -42,8 +42,8 @@ class MainGen implements IGenerator {
def void doGenerate(Root e) {
dataClassGen.doGenerate(e);
- //protocolClassGen.doGenerate(e);
- //actorClassGen.doGenerate(e);
+ protocolClassGen.doGenerate(e);
+ actorClassGen.doGenerate(e);
subsystemClassGen.doGenerate(e);
if (!e.library) {
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend
index 4210fe897..21165613e 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend
@@ -51,21 +51,23 @@ class ProtocolClassGen {
def generateHeaderFile(Root root, ProtocolClass pc) {'''
- #ifndef _«pc.name»_H_
- #define _«pc.name»_H_
+ /**
+ * @author generated by eTrice
+ *
+ * Header File of ProtocolClass «pc.name»
+ *
+ */
+
+ «generateIncludeGuardBegin(pc.name)»
#include "etDatatypes.h"
+ #include "etPort.h"
«helpers.UserCode(pc.userCode1)»
«FOR dataClass : root.getReferencedDataClasses(pc)»#include "«dataClass.name».h"
«ENDFOR»
- typedef struct {
-
-
- } «pc.name»;
-
/* message IDs */
enum {
«pc.name»_MSG_MIN = 0,
@@ -95,12 +97,19 @@ class ProtocolClassGen {
«helpers.UserCode(pc.userCode2)»
- #endif /* _«pc.name»_H_ */
+ «generateIncludeGuardEnd(pc.name)»
'''
}
def generateSourceFile(Root root, ProtocolClass pc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of ProtocolClass «pc.name»
+ *
+ */
+
#include "«pc.getCHeaderFileName»"
/*--------------------- port classes */
@@ -237,8 +246,8 @@ class ProtocolClassGen {
typedef etPort «portClassName»;
- «ClassOperationSignature(portClassName, "MyOperation1", "int a, int b", "void", true)»
- «ClassOperationSignature(portClassName, "MyOperation2", "", "int", false)»
+««« «ClassOperationSignature(portClassName, "MyOperation1", "int a, int b", "void", true)»
+««« «ClassOperationSignature(portClassName, "MyOperation2", "", "int", false)»
'''
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend
index 85e6a6dd0..e3e89029e 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend
@@ -49,6 +49,10 @@ class SubSystemClassGen {
fileAccess.setOutputPath(path)
fileAccess.generateFile(file, root.generateSourceFile(ssi, ssi.subSystemClass))
+ file = ssi.subSystemClass.getInstSourceFileName
+ logger.logInfo("generating SubSystemClass instance file: '"+file+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(file, root.generateInstanceFile(ssi, ssi.subSystemClass))
}
}
@@ -67,13 +71,13 @@ class SubSystemClassGen {
* init -> start -> run (loop) -> stop -> destroy
*/
- void «ssc.name»_init(void); // lifecycle init
- void «ssc.name»_start(void); // lifecycle start
+ void «ssc.name»_init(void); /* lifecycle init */
+ void «ssc.name»_start(void); /* lifecycle start */
- void «ssc.name»_run(void);
+ void «ssc.name»_run(void); /* lifecycle run */
- void «ssc.name»_stop(void); // lifecycle stop
- void «ssc.name»_destroy(void); // lifecycle destroy
+ void «ssc.name»_stop(void); /* lifecycle stop */
+ void «ssc.name»_destroy(void); /* lifecycle destroy */
«generateIncludeGuardEnd(ssc.name)»
@@ -92,6 +96,9 @@ class SubSystemClassGen {
#include "«ssc.getCHeaderFileName»"
+ /* include instances for all classes */
+ #include "«ssc.getInstSourceFileName»"
+
#include "etLogger.h"
/* data for SubSysten «ssc.name» */
@@ -103,6 +110,10 @@ class SubSystemClassGen {
void «ssc.name»_init(void){
etLogger_logInfoF("%s_init", «ssc.name»Inst.name);
+
+ /* initialization of all message services */
+ etMessageService_init(&msgService_Thread1, msgBuffer_Thread1, MESSAGE_POOL_MAX, MESSAGE_BLOCK_SIZE);
+
}
void «ssc.name»_start(void){
@@ -128,6 +139,77 @@ class SubSystemClassGen {
'''
}
+ def generateInstanceFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * Instance File of SubSystemClass «ssc.name»
+ * - instantiation of all actor instances and port instances
+ * - configuration of data and connection of ports
+ */
+
+ #include "etMessageService.h"
+
+ /* instantiation of message services */
+ #define MESSAGE_POOL_MAX 10
+ #define MESSAGE_BLOCK_SIZE 32
+ /* MessageService for Thread1 */
+ uint8 msgBuffer_Thread1[MESSAGE_POOL_MAX*MESSAGE_BLOCK_SIZE];
+ etMessageService msgService_Thread1;
+
+
+ /* include all used ActorClasses */
+ /* TODO: only include used Actor Classes for current SubSystem */
+ «FOR actorClass : root.getUsedActorClasses()»#include "«actorClass.name».h"
+ «ENDFOR»
+
+ /* include all used ProtcolClasses */
+ «FOR protocolClass : root.getUsedProtocolClasses()»#include "«protocolClass.name».h"
+ «ENDFOR»
+
+
+ /* declarations of all ActorClass instances (const and variable structs) */
+
+ /* forward declaration of varible actor structs */
+ «FOR ai : ssi.allContainedInstances»
+ static «ai.actorClass.name» «ai.path.getPathName()»;
+ «ENDFOR»
+
+ «FOR ai : ssi.allContainedInstances»
+
+ /* instance «ai.path.getPathName()» */
+ static const «ai.actorClass.name»_const «ai.path.getPathName()»_const = {
+ &«ai.path.getPathName()»,
+ /* Ports: {myActor, etReceiveMessage, msgService, peerAddress, localId} */
+ «FOR port : ai.actorClass.endPorts»
+ {&«ai.path.getPathName()», NULL, &msgService_Thread1, 1, 123} /* Port «port.name» */
+ «ENDFOR»
+
+ };
+ static «ai.actorClass.name» «ai.path.getPathName()» = {&«ai.path.getPathName()»_const};
+ «ENDFOR»
+
+
+««« «FOR ai : ssi.allContainedInstances»
+««« // actor instance «ai.path» itself => Systemport Address
+««« // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport)
+««« Address addr_item_«ai.path.getPathName()» = new Address(0,«ai.threadId»,«ai.objId»);
+««« // interface items of «ai.path»
+««« «FOR pi : ai.orderedIfItemInstances»
+««« «IF pi instanceof ServiceImplInstance || pi.peers.size>1»
+««« «FOR peer : pi.peers»
+««« «var i = pi.peers.indexOf(peer)»
+««« Address addr_item_«pi.path.getPathName()»_«i» = new Address(0,«pi.threadId»,«pi.objId+i»);
+««« «ENDFOR»
+««« «ELSE»
+««« Address addr_item_«pi.path.getPathName()» = new Address(0,«ai.threadId»,«pi.objId»);
+««« «ENDIF»
+««« «ENDFOR»
+««« «ENDFOR»
+
+ '''
+ }
+
// «var models = root.getReferencedModels(ssc)»
// «FOR model : models»import «model.name».*;«ENDFOR»

Back to the top