浏览代码

Added new functions regarding timer event handling

jos.itemis@gmail.com 13 年之前
父节点
当前提交
5df3db15d1

+ 1 - 1
plugins/org.yakindu.sct.generator.c/.settings/org.eclipse.core.resources.prefs

@@ -1,4 +1,4 @@
-#Fri Sep 09 10:16:39 CEST 2011
+#Mon Nov 28 09:33:07 CET 2011
 eclipse.preferences.version=1
 encoding//.settings/org.eclipse.xtend.shared.ui.prefs=Cp1252
 encoding/<project>=Cp1252

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

@@ -23,19 +23,27 @@ Templates for the main statechart cpp file.
 #include "Event.h"
 
 typedef enum {
-«FOREACH this.declaredEvents() AS ev»
+«FOREACH this.declaredEvents() AS ev -»
   ev_«((EventDefinition)ev).name.toLowerCase()»,
-«ENDFOREACH»
+«ENDFOREACH -»
+«FOREACH this.declaredTimerEvents() AS ev -»
+  ev_«((TimeEvent)ev).name.toLowerCase()»,
+«ENDFOREACH -»
   event_last
 } EventID;
 
 «FOREACH this.declaredEvents() AS ev»
 typedef struct { 
   _Event baseEvent;
-  «IF ((EventDefinition)ev).type != Type::void»
+  «IF ((EventDefinition)ev).type != Type::void -»
   «eventTypeToString(((EventDefinition)ev).type)» value;    
-  «ENDIF»
+  «ENDIF -»
 } «((EventDefinition)ev).name»;
+«ENDFOREACH -»
+«FOREACH this.declaredTimerEvents() AS ev»
+typedef struct { 
+  _Event baseEvent;
+} «((TimeEvent)ev).name»;
 «ENDFOREACH»
  
 

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

@@ -21,8 +21,9 @@ Templates for the main statechart c file.
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR StateSwitch»
-// ActionCode for StateSwitch
-// «this.comment»
+«IF this.comment != null»
+/* «this.comment» */
+«ENDIF»
 	switch(((StatemachineBase*)handle)->state[0/* TODO: must be set correctly */]) {
 «FOREACH this.cases AS caseid»
   case _«caseid.state.simpleName» : {
@@ -35,6 +36,21 @@ Templates for the main statechart c file.
 	}
 «ENDDEFINE»
 
+«DEFINE ActionCode FOR ScheduleTimeEvent»
+«IF this.comment != null»
+/* «this.comment» */
+«ENDIF»
+	(*((StatemachineBase*)handle)->timer->setTimer)(ev_«this.timeEvent.name.toFirstLower()», «this.timeValue.toCCode()», «IF this.timeEvent.periodic == true -»bool_true«ELSE -»bool_false«ENDIF -»);
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR UnscheduleTimeEvent»
+«IF this.comment != null»
+/* «this.comment» */
+	(*((StatemachineBase*)handle->timer->unsetTimer)(ev_«this.name.toFirstLower()»);
+«ENDIF»
+
+«ENDDEFINE»
+
 «DEFINE ActionCode FOR Execution»
 	«this.statement.toCCode()»
 «ENDDEFINE»

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

@@ -31,12 +31,17 @@ extern void dummyTimer_init(Timer* handle);
 
 «FILE 'DummyTimer.c'»
 #include "DummyTimer.h"
+#include <stdio.h>
 
 void setTimer(const uint32_t evid, const uint32_t time_ms, boolean periodic)
-{}
+{
+	printf("set event <%d> with time %dms\n", evid, time_ms);
+}
 
 void unsetTimer(const uint32_t evid)
-{}
+{
+	printf("unset event <%d>\n", evid);
+}
 
 void dummyTimer_init(Timer* handle)
 {

+ 4 - 16
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Expression.ext

@@ -86,21 +86,11 @@ String toCCode(ElementReferenceExpression ref) :
 String toCCode(Declaration dec) :
 	"Declartion type not specified";
 
-String toCCode(Clock clockDef) :
-	"Clock to C not defined";
-	
-String toCCode(Operation op) :
-	"Operation to C not defined";
-
-String toCCode(LocalReaction localReac) :
-	"Local Reaction to C not defined";
-
-String toCCode(Entrypoint op) :
-	"Entrypoint to C not defined";
-
-String toCCode(Exitpoint op) :
-	"Exitpoint to C not defined";
+String toCCode(TimeEvent time_ev) :
+    " ( eventSet_check( &handle->base.eventSet, ev_" + time_ev.name.toLowerCase() + ") ) ";
 
+String toCCode(VariableDefinition var) :
+    " handle->"+ var.getInterface() + "." + var.name.toLowerCase() + " ";
 	
 String toCCode(EventDefinition evDef) :
     " ( eventSet_check( &handle->base.eventSet, ev_" + evDef.name.toLowerCase() + ") ) ";
@@ -123,8 +113,6 @@ String interfaceObjectName(InterfaceScope this) : "interface" + ((this.name == n
 String getInterface(VariableDefinition var) :
 	((InterfaceScope)var.eContainer).interfaceObjectName();
 
-String toCCode(VariableDefinition var) :
-    " handle->"+ var.getInterface() + "." + var.name.toLowerCase() + " ";
 
 String getOperator(AdditiveOperator operator) : 
     switch(operator) {

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

@@ -108,7 +108,7 @@ void 
 «FOREACH interface.declarations.typeSelect(VariableDefinition) AS variable -»
 «IF variable.initialValue != null»
 «REM»change to correctLValue«ENDREM»
-	handle->«variable.name» = «variable.initialValue.toCCode()»;
+	handle->«variable.name» = «variable.initialValue.correctLValue()»;
 «ENDIF»
 «ENDFOREACH»
 

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

@@ -8,6 +8,7 @@ ExecutionFlow getExecutionFlow(InterfaceScope this) : ((ExecutionFlow)this.eCont
 String scName(Expression statement) : ((ExecutionFlow)statement.eRootContainer).name ;
 
 List[EventDefinition] declaredEvents(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(EventDefinition);
+List[TimeEvent] declaredTimerEvents(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(TimeEvent);
 
 List[VariableDefinition] declaredVariables(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(VariableDefinition);
 
@@ -53,11 +54,10 @@ String interfaceName(InterfaceScope this) : this.getExecutionFlow().name.toFirst
 String interfaceClassName(InterfaceScope this) : this.getExecutionFlow().name.toFirstUpper() + "If" + ((this.name == null)?"":this.name.toFirstUpper());
 String interfaceObjectName(InterfaceScope this) : "interface" + ((this.name == null)?"":this.name.toFirstUpper());
 
-String getEventEnumName(EventDefinition this) : "ev_" + this.name;
+String getEventEnumName(EventDefinition this) : "ev_" + this.name.toFirstLower();
 
-/**
 String correctLValue(String literal) :
     (literal == "true" ? "bool_true" :
 	(literal == "false" ? "bool_false" :
 	literal ));
-**/    
+