Browse Source

Added handling for History States

jos.itemis@gmail.com 13 years ago
parent
commit
016287ec8b

+ 60 - 5
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineC.xpt

@@ -19,14 +19,37 @@ Templates for the main statechart c file.
 «EXTENSION org::yakindu::sct::generator::c::templates::Naming»
  
 «DEFINE ActionCode FOR Step»
-//#warning ActionCode for Step not defined 
+#warning ActionCode for Step not defined 
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR SaveHistory»
+«IF this.comment != null -»
+	/* «this.comment» */
+«ENDIF»
+	«statemachineHandleName()»->base.base.history[«region.historyVector.offset»] = «statemachineHandleName()»->base.base.state[«region.stateVector.offset»];
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR HistoryEntry»
+«IF this.comment != null -»
+	/* «this.comment» */
+«ENDIF»
+if («statemachineHandleName()»->base.base.history[«region.historyVector.offset»] != last_state) {
+	«EXPAND ActionCode FOR historyStep-»
+} else {
+	«EXPAND ActionCode FOR initialStep-»
+}
+
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR StateSwitch»
 «IF this.comment != null -»
 	/* «this.comment» */
 «ENDIF -»
+«IF this.historyRegion != null»
+	switch(((StatemachineBase*)«statemachineHandleName()»)->history[ «historyRegion.historyVector.offset» ]) {
+«ELSE»
 	switch(((StatemachineBase*)«statemachineHandleName()»)->state[ «this.stateConfigurationIdx» ]) {
+«ENDIF»
 «FOREACH this.cases AS caseid -»
 		case _«caseid.state.simpleName» : {
 «EXPAND ActionCode FOR caseid.step-»
@@ -130,14 +153,12 @@ sc_boolean 
 «ENDDEFINE»
 
 «DEFINE StatementMethodsProto FOR ExecutionNode -»
-/* statement method prototypes */
   «FOREACH reactions.select(e|e.effect.caller.size > 0) AS r -»
 static void «r.reactFunction()»;
  «ENDFOREACH -»
 «ENDDEFINE»
 
 «DEFINE StatementMethodsImplement FOR ExecutionNode -»
-/* statement method implementations */
   «FOREACH reactions.select(e|e.effect.caller.size > 0) AS r -»
 void «r.reactFunction()»
 {   
@@ -224,13 +245,40 @@ static void 
 «IF this.exitSequence != null && exitSequence.caller.size > 0 -»
 void «this.exitSequence.exitSequenceFunction()»
 {
-«EXPAND ActionCode FOR this.exitSequence»
+«EXPAND ActionCode FOR exitSequence»
 }
 «ENDIF -»
 «ENDDEFINE»
 
+«DEFINE ShallowEnterSequenceProto FOR ExecutionRegion -»
+«IF shallowEnterSequence != null && shallowEnterSequence.caller.size > 0 -»
+static void «shallowEnterSequence.shallowEnterFunction()»;
+«ENDIF -»
+«ENDDEFINE»
+
+«DEFINE ShallowEnterSequenceImplement FOR ExecutionRegion -»
+«IF shallowEnterSequence != null && shallowEnterSequence.caller.size > 0 -»
+void «shallowEnterSequence.shallowEnterFunction()»
+{
+«EXPAND ActionCode FOR shallowEnterSequence»
+}
+«ENDIF -»
+«ENDDEFINE»
 
+«DEFINE DeepEnterSequenceProto FOR ExecutionRegion -»
+«IF deepEnterSequence != null && deepEnterSequence.caller.size > 0 -»
+static void «deepEnterSequence.deepEnterFunction()»;
+«ENDIF -»
+«ENDDEFINE»
 
+«DEFINE DeepEnterSequenceImplement FOR ExecutionRegion -»
+«IF deepEnterSequence != null && deepEnterSequence.caller.size > 0 -»
+void «deepEnterSequence.deepEnterFunction()»
+{
+«EXPAND ActionCode FOR deepEnterSequence»
+}
+«ENDIF -»
+«ENDDEFINE»
 
 «DEFINE file FOR ExecutionFlow»
 «FILE StName()+'.c'»
@@ -256,6 +304,8 @@ static 
 «EXPAND ExitSequenceProto FOREACH this.states -»
 «EXPAND EnterSequenceProto FOREACH this.regions -»
 «EXPAND ExitSequenceProto FOREACH this.regions -»
+«EXPAND ShallowEnterSequenceProto FOREACH this.regions -»
+«EXPAND DeepEnterSequenceProto FOREACH this.regions -»
 «EXPAND ReactMethodsProto FOREACH this.states -»
 «EXPAND ReactMethodsProto FOREACH this.nodes -»
 
@@ -269,6 +319,8 @@ static 
 «EXPAND ExitSequenceImplement FOREACH this.states -»
 «EXPAND EnterSequenceImplement FOREACH this.regions -»
 «EXPAND ExitSequenceImplement FOREACH this.regions -»
+«EXPAND ShallowEnterSequenceImplement FOREACH this.regions -»
+«EXPAND DeepEnterSequenceImplement FOREACH this.regions -»
 «EXPAND ReactMethodsImplement FOREACH this.states -»
 «EXPAND ReactMethodsImplement FOREACH this.nodes -»
 
@@ -279,12 +331,15 @@ void 
 «IF this.isSingleton()»
 	«statemachineHandleName()» = &static_«statemachineHandleName()»;
 «ENDIF»
-	statemachine_cy_init(&«statemachineHandleName()»->base, MAX_PARALLEL_STATES,
+	statemachine_cy_init(&«statemachineHandleName()»->base, MAX_PARALLEL_STATES, MAX_HISTORY_STATES,
 			event_last, timer, eventPool);
 
 	for (i = 0; i<MAX_PARALLEL_STATES; ++i)
 		«statemachineHandleName()»->base.base.state[i] = last_state;
 			
+	for (i = 0; i<MAX_HISTORY_STATES; ++i)
+		«statemachineHandleName()»->base.base.history[i] = last_state;
+
 «FOREACH this.scopes.getUsableScopes() AS interface -»
 «IF this.isSingleton() -»
      «interface.interfaceName()»_set_interface_singleton(&«statemachineHandleName()»->«interface.interfaceObjectName()»);

+ 5 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineH.xpt

@@ -34,6 +34,11 @@ extern "C" {
 #endif 
 
 #define MAX_PARALLEL_STATES «this.stateVector.size»
+«IF historyVector == null»
+#define MAX_HISTORY_STATES 0
+«ELSE»
+#define MAX_HISTORY_STATES «historyVector.size»
+«ENDIF»
 
 typedef void(*raiseEventFPtr)(_Event* evPtr);
 

+ 0 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Main.xpt

@@ -2,7 +2,6 @@
 
 Contais the root templates that call the different file templates.
 
-@author andreas muelder
 @auther axel terfloth
 @author joern seger
 

+ 19 - 2
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Naming.ext

@@ -49,8 +49,10 @@ cached String functionName(Step step) :
 	(step.isExitAction()) ? step.exitActionFunctionName() : (
 	(step.isEnterSequence()) ? step.enterSequenceFunctionName() : ( 
 	(step.isExitSequence()) ? step.exitSequenceFunctionName() : ( 
-	(step.isReactSequence()) ? step.reactSequenceFunctionName() :
-	" !! unknown function type !!" ))))));
+	(step.isReactSequence()) ? step.reactSequenceFunctionName() : (
+	(step.isShallowEnterSequence()) ? step.shallowEnterSequenceFunctionName() : (
+	(step.isDeepEnterSequence()) ? step.deepEnterSequenceFunctionName() : (
+	" !! unknown function type !!" )))))))));
 
 
 ExecutionState state(Step this) : (ExecutionState) this.eContainer;
@@ -63,6 +65,8 @@ boolean isExitAction(Step step) : ExecutionState.isInstance(step.eContainer) &&
 boolean isEnterSequence(Step step) : ExecutionScope.isInstance(step.eContainer) && step.scope().enterSequence == step;
 boolean isExitSequence(Step step) : ExecutionScope.isInstance(step.eContainer) && step.scope().exitSequence == step;
 boolean isReactSequence(Step step) : Sequence.isInstance(step) && step.name == "react";
+boolean isDeepEnterSequence(Step step) : Sequence.isInstance(step) && step.name == "deepEnterSequence";
+boolean isShallowEnterSequence(Step step) : Sequence.isInstance(step) && step.name == "shallowEnterSequence";
 
 
 /* If this is a singleton, we do not need any additional information for the 
@@ -100,6 +104,12 @@ String enterSequenceFunctionName(Step this) :
 String exitSequenceFunctionName(Step this) :  
 	  this.stName() + "_exitSequence_" + this.getStateName();
 
+String shallowEnterSequenceFunctionName(Step this) :  
+	  this.stName() + "_shallowEnterSequence_" + this.getStateName();
+
+String deepEnterSequenceFunctionName(Step this) :  
+	  this.stName() + "_deepEnterSequence_" + this.getStateName();
+
 String reactSequenceFunctionName(Step this) :  
 	  this.stName() + "_react_" + this.getStateName();
 
@@ -132,6 +142,12 @@ String enterSequenceFunction(Step this) :
 String exitSequenceFunction(Step this) :  
 	  this.exitSequenceFunctionName() + "("+ handleAddition() + ")";
 
+String shallowEnterFunction(Step this) :  
+	  this.shallowEnterSequenceFunctionName() + "("+ handleAddition() + ")";
+
+String deepEnterFunction(Step this) :  
+	  this.deepEnterSequenceFunctionName() + "("+ handleAddition() + ")";
+
 /* for some reason, this is handled completely different */ 
 String reactFunction(Reaction this) :  
 	  this.reactFunctionName() + "("+ handleAddition() + ")";
@@ -140,6 +156,7 @@ String reactFunction(ExecutionNode this) :
 	  this.reactFunctionName() + "("+ handleAddition() + ")";
 
 
+
 String getStateName(Step this) : this.eContainer.getStateName(); 
 String getStateName(emf::EObject this) : (this.eContainer != null)?this.eContainer.getStateName():"unkown";
 String getStateName(ExecutionEntry this) : this.simpleName;

+ 8 - 5
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/StatemachineBaseC.xpt

@@ -19,25 +19,28 @@ Templates for the main statechart c file.
 #include "StatemachineBase.h"
 #include <stdlib.h>
 
-void statemachineBase_init(StatemachineBase* handle, uint16_t maxStates, Timer* _timer)
+void statemachineBase_init(StatemachineBase* handle, uint16_t maxStates, uint16_t maxHistorys, Timer* _timer)
 {
 	handle->isStaticData = bool_false;
 	handle->timer = _timer;
 	handle->state = malloc(sizeof(uint32_t)*maxStates); /* memory allocation for all states */
-	handle->statePtr = 0; /* actual state referencer */
+	handle->history = malloc(sizeof(uint32_t)*maxHistorys); /* memory allocation for all histories */
 }
 
-void statemachineBase_init_staticData(StatemachineBase* handle, uint32_t* staticData, Timer* _timer)
+/* TODO: this concept needs rework */
+void statemachineBase_init_staticData(StatemachineBase* handle, uint32_t* staticData, uint16_t maxStates, Timer* _timer)
 {
 	handle->isStaticData = bool_true;
 	handle->timer = _timer;
 	handle->state = staticData;
-	handle->statePtr = 0; /* actual state referencer */
+	handle->history = staticData + maxStates;
 }
 
 void statemachineBase_destruct(StatemachineBase* handle) {
-	if (!handle->isStaticData)
+	if (!handle->isStaticData) {
 		free(handle->state);
+		free(handle->history);	
+	}
 }
 
 uint32_t statemachineBase_getState(StatemachineBase* handle, uint16_t pos)

+ 4 - 4
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/StatemachineBaseH.xpt

@@ -29,17 +29,17 @@ extern "C" {
 typedef struct {
 
 	uint32_t* state;
-	uint16_t statePtr;
+	uint32_t* history;
 
-	Timer* timer;
+	Timer*    timer;
 	sc_boolean isStaticData;
 
 } StatemachineBase;
 
 
-extern void statemachineBase_init(StatemachineBase* handle, uint16_t maxStates, Timer* timer);
+extern void statemachineBase_init(StatemachineBase* handle, uint16_t maxStates, uint16_t maxHistorys, Timer* timer);
 extern void statemachineBase_init_staticData(StatemachineBase* handle,
-		uint32_t* staticData, Timer* timer);
+		uint32_t* staticData, uint16_t maxStates, Timer* timer);
 
 extern void statemachineBase_destruct(StatemachineBase* handle);
 

+ 4 - 4
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Statemachine_cyC.xpt

@@ -20,12 +20,12 @@ Templates for the main statechart c file.
 #include "definition.h"
 #include "Statemachine_cy.h"
 
-void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
+void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates, uint16_t maxHistorys,
 		uint16_t maxEvents, Timer* timer, EventPool* eventPool) {
 
 	uint32_t i;
 
-	statemachineBase_init((StatemachineBase*) handle, maxStates, timer);
+	statemachineBase_init((StatemachineBase*) handle, maxStates, maxHistorys, timer);
 	eventSet_init(&handle->eventSet, maxEvents);
 
 	/* This is only a place for the pointers to the actual Events */
@@ -44,9 +44,9 @@ void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
 
 void statemachine_cy_init_staticData(Statemachine_cy* handle,
 		uint16_t maxEvents, Timer* timer, uint32_t* staticStateData,
-		sc_boolean* staticEventSet, EventType* eventTypes, _Event** staticListPtr, EventPool* eventPool) {
+		sc_boolean* staticEventSet, EventType* eventTypes, _Event** staticListPtr, EventPool* eventPool, uint16_t maxStates) {
 	statemachineBase_init_staticData((StatemachineBase*) handle,
-			staticStateData, timer);
+			staticStateData, maxStates, timer);
 	eventSet_init_staticData(&handle->eventSet, maxEvents, staticEventSet, eventTypes);
 
 	/* Hand out event List */

+ 2 - 2
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Statemachine_cyH.xpt

@@ -36,12 +36,12 @@ typedef struct {
   uint32_t   parallelPosition; 
 } Statemachine_cy ;
 
-extern void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
+extern void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates, uint16_t maxHistorys,
 		uint16_t maxEvents,	Timer* timer, EventPool* eventPool);
 
 extern void statemachine_cy_init_staticData(Statemachine_cy* handle,
 		uint16_t maxEvents, Timer* timer, uint32_t* staticStateData,
-		sc_boolean* staticEventSet, EventType* eventTypes, _Event** staticListPtr, EventPool* eventPool);
+		sc_boolean* staticEventSet, EventType* eventTypes, _Event** staticListPtr, EventPool* eventPool, uint16_t maxStates);
 
 extern void statemachine_cy_destruct(Statemachine_cy* handle);