public void GenerateDataTypesFile(String folder) { String FileName = folder + "\\" + Properties.Resources.RTE_DATATYPES_H_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, Properties.Resources.RTE_DATATYPES_H_FILENAME, Properties.Resources.DATATYPES_H_FILE_DESCRIPTION); String guardDefine = RteFunctionsGenerator.OpenGuardDefine(writer); writer.WriteLine(); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_RETURN_CODES_FILENAME); writer.WriteLine(); WriteStaticGlobal(writer); WriteBaseDataTypes(writer); WriteEnumDataTypes(writer); WriteSimpleDataTypes(writer); ComplexDataTypesList sortedComplexDataTypes = SortComplexDataTypeWithDependencies(); WriteComplexDataTypes(sortedComplexDataTypes, writer); GenerateComponentsDataTypes(writer); RteFunctionsGenerator.CloseGuardDefine(writer); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
public void WriteSimpleDataType(StreamWriter writer, SimpleDataType datatype) { writer.WriteLine("/* Datatype : " + datatype.Name + " */"); /* Write limits */ String upperLimit = datatype.Name + "_UPPER_LIMIT"; string maxValue = datatype.MaxValue; string minValue = datatype.MinValue; if (datatype.GetBaseDataType() == AutosarApplication.GetInstance().BaseDataTypes.float32) { minValue = acceptFloatValue(datatype.MinValue); maxValue = acceptFloatValue(datatype.MaxValue); } writer.WriteLine(RteFunctionsGenerator.CreateDefine(upperLimit, maxValue)); String lowerLimit = datatype.Name + "_LOWER_LIMIT"; writer.WriteLine(RteFunctionsGenerator.CreateDefine(lowerLimit, minValue)); /* Write datatype */ String dataTypeName = AutosarApplication.GetInstance().GetDataTypeName(datatype.BaseDataTypeGUID); string typedef = RteFunctionsGenerator.FillStringForCount("typedef " + dataTypeName, ' ', 24); writer.WriteLine(typedef + datatype.Name + ";"); writer.WriteLine(""); /* Generate an array if it existis*/ ArrayDataTypeGenerator.GenerateArrayForDataType(writer, datatype); }
String GenerateComplexDatatypeDefaultValue(ComplexDataType datatype, int indent) { String strIndent = RteFunctionsGenerator.FillStringForCount("", ' ', indent); String str = "{" + Environment.NewLine; for (int i = 0; i < datatype.Fields.Count; i++) { ComplexDataTypeField field = datatype.Fields[i]; if (IsDatatypeSimple(field.DataTypeGUID)) { str += RteFunctionsGenerator.GenerateDefaultValueForSimpleDataTypeField(field.Name, indent + 4); } else { ComplexDataType complexDt = AutosarApplication.GetInstance().ComplexDataTypes.FindObject(field.DataTypeGUID); str += RteFunctionsGenerator.FillStringForCount("", ' ', indent + 4) + "." + field.Name + " = " + Environment.NewLine; str += RteFunctionsGenerator.FillStringForCount("", ' ', indent + 4) + GenerateComplexDatatypeDefaultValue(complexDt, indent + 4); } if (i != datatype.Fields.Count - 1) { str += "," + Environment.NewLine; } } str += Environment.NewLine + strIndent + "}"; return(str); }
public void GenerateConnections() { String filename = RteFunctionsGenerator.GetRteFolder() + "\\" + Properties.Resources.RTE_CONNECTIONS_C_FILENAME; StreamWriter writer = new StreamWriter(filename); RteFunctionsGenerator.GenerateFileTitle(writer, filename, "Implementation for RTE connections source file"); /*Add #include */ RteFunctionsGenerator.AddInclude(writer, "<string.h>"); switch (AutosarApplication.GetInstance().MCUType.Type) { case MCUTypeDef.STM32F1xx: { RteFunctionsGenerator.AddInclude(writer, "<stm32f1xx.h>"); break; } case MCUTypeDef.STM32F4xx: { RteFunctionsGenerator.AddInclude(writer, "<stm32f4xx.h>"); break; } } RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_DATATYPES_H_FILENAME); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.SYSTEM_ERRORS_H_FILENAME); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_EXTERNAL_RUNNABLES_H_FILENAME); /* Include */ writer.WriteLine(""); /* Create extern variables */ GenerateAllComponentInstances(writer); /* Generate all rte write functions */ foreach (ComponentDefenition compDef in AutosarApplication.GetInstance().ComponentDefenitionsList) { writer.WriteLine("/**************************************************"); writer.WriteLine(" " + compDef.Name); writer.WriteLine("***************************************************/"); /* Check if this components exists */ if (AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef).Count > 0) { if (compDef.Name == "DistanceProtector") { } CreateRteWriteFunctions(writer, compDef); CreateRteReadFunctions(writer, compDef); CreateRteCallFunctions(writer, compDef); CreateRtePimFunctions(writer, compDef); CreateRteCDataFunctions(writer, compDef); } } writer.Close(); }
public void WriteEnumDataType(StreamWriter writer, EnumDataType datatype) { writer.WriteLine("/* Enum Datatype : " + datatype.Name + " */"); /* Write datatype */ writer.WriteLine("typedef enum "); writer.WriteLine("{"); /* Write values */ for (int i = 0; i < datatype.Fields.Count; i++) { writer.Write(RteFunctionsGenerator.CreateEnumValue(datatype.Fields[i])); writer.WriteLine(","); } /* Write elements count */ //writer.WriteLine(" " + datatype.Name + "_ELEMENTS_COUNT"); writer.WriteLine("} " + datatype.Name + ";"); writer.WriteLine(""); int minLimit = datatype.GetLimit(LimitType.ltLowerLimit); String defineMin = RteFunctionsGenerator.CreateDefine(datatype.Name + "_LOWER_LIMIT", minLimit.ToString()); writer.WriteLine(defineMin); int upperLimit = datatype.GetLimit(LimitType.ltUpperLimit); String defineMax = RteFunctionsGenerator.CreateDefine(datatype.Name + "_UPPER_LIMIT", upperLimit.ToString()); writer.WriteLine(defineMax); writer.WriteLine(""); /* Generate an array if it existis*/ ArrayDataTypeGenerator.GenerateArrayForDataType(writer, datatype); }
void GenerateRteCDataFunction(StreamWriter writer, ComponentDefenition compDef, CDataDefenition cdataDef) { String returnValue = cdataDef.DataTypeName + " "; String RteFuncName = RteFunctionsGenerator.GenerateFullCDataFunctionName(compDef, cdataDef); String fieldVariable = RteFunctionsGenerator.GenerateMultipleInstanceFunctionArguments(compDef.MultipleInstantiation); writer.WriteLine(returnValue + RteFuncName + fieldVariable); writer.WriteLine("{"); if (!compDef.MultipleInstantiation) //single instantiation component { ComponentInstancesList components = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef); if (components.Count > 0) { /* At least one component exists at this step */ ComponentInstance compInstance = components[0]; String compName = RteFunctionsGenerator.GenerateComponentName(compInstance.Name); String field = RteFunctionsGenerator.GenerateRteCDataFieldInComponentDefenitionStruct(compDef, cdataDef); writer.WriteLine(" return " + compName + "." + field + ";"); } } else //multiple instantiation component { String field = RteFunctionsGenerator.GenerateRteCDataFieldInComponentDefenitionStruct(compDef, cdataDef); writer.WriteLine(" return ((" + compDef.Name + "*)instance)->" + field + ";"); } writer.WriteLine("}"); writer.WriteLine(""); }
void Generate_RteTaskScheduler_Header_File() { String FileName = RteFunctionsGenerator.GetRteFolder() + "\\" + Properties.Resources.RTE_TASK_SCHEDULER_H_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, FileName, Properties.Resources.RTE_TASK_SCHEDULER_FILE_DESCRIPTION); RteFunctionsGenerator.OpenGuardDefine(writer); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_DATATYPES_H_FILENAME); writer.WriteLine(); writer.WriteLine("extern volatile boolean timeEventOccured;"); writer.WriteLine(); writer.WriteLine("void DoScheduling(void);"); writer.WriteLine(); RteFunctionsGenerator.CloseGuardDefine(writer); writer.WriteLine(); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
void GenerateComponent(ComponentDefenition component) { /* Generate component Folder */ String componentFolder = RteFunctionsGenerator.GetComponentsFolder() + "\\" + component.Name; String rteDir = RteFunctionsGenerator.GetRteFolder() + "\\"; String incDir = componentFolder + "\\include\\"; String srcDir = componentFolder + "\\src\\"; Directory.CreateDirectory(incDir); Directory.CreateDirectory(srcDir); /* Fill sections of code */ /* Each component runnable shall be in its own file */ foreach (PeriodicRunnableDefenition runnable in component.Runnables) { CreateRunnable(srcDir, runnable); } /* Each Server port functions shall be in its own file */ foreach (PortDefenition port in component.Ports) { if (port.PortType == PortType.Server) { CreateServerCalls(srcDir, component, port); } } /* Generate funcitons for Sender-Receiver ports and call operations from client ports */ CreateRteIncludes(rteDir, component); CreateComponentIncludes(incDir, component); }
void GenerateRteWritePortFieldFunction(StreamWriter writer, ComponentDefenition compDef, PortDefenition port, SenderReceiverInterfaceField field) { String returnValue = Properties.Resources.STD_RETURN_TYPE; String RteFuncName = RteFunctionsGenerator.GenerateReadWriteConnectionFunctionName(port, field); String fieldVariable = RteFunctionsGenerator.GenerateSenderReceiverInterfaceArguments(field, port.PortType, compDef.MultipleInstantiation); writer.WriteLine(returnValue + RteFuncName + fieldVariable); writer.WriteLine("{"); if (!compDef.MultipleInstantiation) //single instantiation component { ComponentInstancesList components = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef); if (components.Count > 0) { ComponentInstance compInstance = components[0]; String compName = RteFunctionsGenerator.GenerateComponentName(compInstance.Name); String fieldName = RteFunctionsGenerator.GenerateRteWriteFieldInComponentDefenitionStruct(port, field); writer.WriteLine(" " + compName + "." + fieldName + " = *" + field.Name + ";"); } } else //multiple instantiation component { String rteStructFieldName = RteFunctionsGenerator.GenerateRteWriteFieldInComponentDefenitionStruct(port, field); String instanceLine = "((" + compDef.Name + "*)instance)->" + rteStructFieldName + " = *" + field.Name + ";"; writer.WriteLine(" " + instanceLine); } writer.WriteLine(" return " + Properties.Resources.RTE_E_OK + ";"); writer.WriteLine("}"); writer.WriteLine(""); //} }
void WriteAllErrors(StreamWriter writer) { AutosarApplication.GetInstance().SystemErrors.SortErrorsByID(); foreach (SystemErrorObject obj in AutosarApplication.GetInstance().SystemErrors) { writer.WriteLine(RteFunctionsGenerator.CreateDefine(obj.Name, obj.Value.ToString())); } }
void GenerateOsTaskFunctionCallOfRunnables(StreamWriter writer, OsTask osTask) { String osTaskName = RteFunctionsGenerator.GenerateRteOsTaskFunctionName(osTask); writer.WriteLine("void " + osTaskName + "(void)"); writer.WriteLine("{"); WriteCallOfOsRunnables(writer, osTask); writer.WriteLine("}"); writer.WriteLine(""); }
void Generate_RunTimeEnvironment_Header_File() { String FileName = RteFunctionsGenerator.GetRteFolder() + "\\" + Properties.Resources.RTE_RUNTIME_ENVIRONMENT_H_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, FileName, Properties.Resources.RTE_RUNTIME_ENVIRONMENT_FILE_DESCRIPTION); RteFunctionsGenerator.OpenGuardDefine(writer); writer.WriteLine(); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_DATATYPES_H_FILENAME); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_EXTERNAL_RUNNABLES_H_FILENAME); RteFunctionsGenerator.AddInclude(writer, "<stm32f4xx.h>"); writer.WriteLine(); writer.WriteLine("/* Time periods */"); writer.WriteLine(RteFunctionsGenerator.CreateDefine("SYSTICK_FREQUENCY", AutosarApplication.GetInstance().SystickFrequencyHz.ToString())); writer.WriteLine(); /* Create defines for each frequency */ List <double> frequencys = GetDifferentFrequences(); foreach (double frequency in frequencys) { String freqName = RteFunctionsGenerator.CreateFrequencyDefineName(frequency); String freqValue = ""; int freq = (int)Math.Floor((double)AutosarApplication.GetInstance().SystickFrequencyHz / frequency); freqValue = freq.ToString(); writer.WriteLine(RteFunctionsGenerator.CreateDefine(freqName, freqValue.ToString())); } writer.WriteLine(); writer.WriteLine("/*"); writer.WriteLine(" * Rte tasks "); writer.WriteLine(" */"); foreach (OsTask osTask in AutosarApplication.GetInstance().OsTasks) { String osTaskName = RteFunctionsGenerator.GenerateRteOsTaskFunctionName(osTask); writer.WriteLine("void " + osTaskName + "(void);"); } writer.WriteLine(); RteFunctionsGenerator.CloseGuardDefine(writer); writer.WriteLine(); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
void WriteCallOfOsRunnables(StreamWriter writer, OsTask osTask) { if (osTask.Runnables.Count > 0) { double lastPeriod = -1; int changeIndex = 0; bool wasBracersOpen = false; for (int runnableIndex = 0; runnableIndex < osTask.Runnables.Count; runnableIndex++) { PeriodicRunnableDefenition runnableDefenition = AutosarApplication.GetInstance().FindRunnableDefenition(osTask.Runnables[runnableIndex].DefenitionGuid); if ((runnableDefenition != null) && (osTask.PeriodMs != runnableDefenition.PeriodMs)) { /* Close previous period */ if ((lastPeriod != runnableDefenition.PeriodMs) && wasBracersOpen) { writer.WriteLine(" }"); } /* Add open bracers */ if (lastPeriod != runnableDefenition.PeriodMs) { lastPeriod = runnableDefenition.PeriodMs; String periodVariableName = osTask.Name + "_" + RteFunctionsGenerator.CreateFrequencyDefineName(runnableDefenition.PeriodMs) + "_" + changeIndex.ToString(); int ostatok = (int)(runnableDefenition.PeriodMs / osTask.PeriodMs); changeIndex++; writer.WriteLine(" if (++" + periodVariableName + " >= " + ostatok + ")"); writer.WriteLine(" {"); writer.WriteLine(" " + periodVariableName + " = 0u;"); } wasBracersOpen = true; writer.WriteLine(" " + RteFunctionsGenerator.Generate_CallOfRunnable(osTask.Runnables[runnableIndex])); } else { if (wasBracersOpen) { wasBracersOpen = false; writer.WriteLine(" }"); } lastPeriod = osTask.PeriodMs; writer.WriteLine(" " + RteFunctionsGenerator.Generate_CallOfRunnable(osTask.Runnables[runnableIndex])); } } if (wasBracersOpen) { writer.WriteLine(" }"); } } }
void Generate_ExternalRunnables_File() { String FileName = RteFunctionsGenerator.GetRteFolder() + "\\" + Properties.Resources.RTE_EXTERNAL_RUNNABLES_H_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, FileName, Properties.Resources.RTE_EXTERNAL_RUNNABLES_FILE_DESCRIPTION); RteFunctionsGenerator.OpenGuardDefine(writer); writer.WriteLine(); writer.WriteLine("/* Declaration of all periodic runnables */"); writer.WriteLine(); foreach (ComponentDefenition compDefinition in AutosarApplication.GetInstance().ComponentDefenitionsList) { foreach (PeriodicRunnableDefenition runnable in compDefinition.Runnables) { writer.WriteLine(RteFunctionsGenerator.Generate_RunnableFunction(compDefinition, runnable) + ";"); } } writer.WriteLine(); writer.WriteLine("/* Declaration of all server call functions */"); writer.WriteLine(); foreach (ComponentDefenition componentDefenition in AutosarApplication.GetInstance().ComponentDefenitionsList) { foreach (PortDefenition port in componentDefenition.Ports) { if (port.PortType == PortType.Server) { ClientServerInterface csInterface = AutosarApplication.GetInstance().ClientServerInterfaces.FindObject(port.InterfaceGUID); if (csInterface != null) { foreach (ClientServerOperation operation in csInterface.Operations) { String funcName = RteFunctionsGenerator.Generate_RteCall_ConnectionGroup_FunctionName(componentDefenition, port, operation); String funcArguments = RteFunctionsGenerator.GenerateClientServerInterfaceArguments(operation, componentDefenition.MultipleInstantiation); writer.WriteLine(Properties.Resources.STD_RETURN_TYPE + funcName + funcArguments + ";"); } } } } } writer.WriteLine(); RteFunctionsGenerator.CloseGuardDefine(writer); writer.WriteLine(); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
void writeInitOsTask(StreamWriter writer, OsTask task, RteOsInterfaceGenerator osGenerator) { String rteTaskName = GenerateRteOsTaskName(task); String funcName = RteFunctionsGenerator.GenerateRteOsTaskFunctionName(task); String stackSize = (task.StackSizeInBytes / 2).ToString(); writer.WriteLine(" " + osGenerator.CreateTask() + "("); writer.WriteLine(" " + funcName + ", /* Pointer to the function that implements the task. */"); writer.WriteLine(" \"" + task.Name + "\", /* Text name given to the task. */"); writer.WriteLine(" " + stackSize + ", /* The size of the stack in words */"); writer.WriteLine(" (void*)0, /* A reference to xParameters is used as the task parameter. */"); writer.WriteLine(" " + task.Priority + ", /* Task priority */"); writer.WriteLine(" &" + rteTaskName + "); /* The handle to the task being created will be placed there */"); writer.WriteLine(); }
void Generate_RunTimeEnvironment_Source_File_FREERTOS() { RteOsInterfaceGenerator osGenerator = new RteFreeRtosGenerator(); String FileName = RteFunctionsGenerator.GetRteFolder() + "\\" + Properties.Resources.RTE_RUNTIME_ENVIRONMENT_C_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, FileName, Properties.Resources.RTE_RUNTIME_ENVIRONMENT_FILE_DESCRIPTION); RteFunctionsGenerator.OpenGuardDefine(writer); writer.WriteLine(); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_RUNTIME_ENVIRONMENT_H_FILENAME); writer.WriteLine(); writer.WriteLine("/* Scheduler variables */"); foreach (OsTask osTask in AutosarApplication.GetInstance().OsTasks) { List <double> frequences = PeriodChangeTimes(osTask); List <String> freqVariableNames = new List <string>(); for (int i = 0; i < frequences.Count; i++) { String freqName = osTask.Name + "_" + RteFunctionsGenerator.CreateFrequencyDefineName(frequences[i]) + "_" + i.ToString(); freqVariableNames.Add(freqName); String variableDeclaration = RteFunctionsGenerator.GenerateVariable(freqName, "uint32", true, 0, "0"); writer.WriteLine(variableDeclaration); } writer.WriteLine(); } /* Declare variables for scheduling */ WriteAllTasksVariables(writer, osGenerator); WriteAllExternComponentInstances(writer); /* End declare variables */ WriteAllOsTasks_FREERTOS(writer, osGenerator); WriteInitOsTasks(writer, osGenerator); writer.WriteLine(); RteFunctionsGenerator.CloseGuardDefine(writer); writer.WriteLine(); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
void WriteZeroDefaultValueForSenderPort(StreamWriter writer, PortDefenition portDef, SenderReceiverInterface srInterface) { for (int j = 0; j < srInterface.Fields.Count; j++) { SenderReceiverInterfaceField field = srInterface.Fields[j]; writer.Write(" ." + RteFunctionsGenerator.GenerateRteWriteFieldInComponentDefenitionStruct(portDef, field) + " = "); WriteZeroDefaultValue(writer, field.DataType); if (j < srInterface.Fields.Count - 1) { writer.WriteLine(","); } } }
public void GenerateReturnCodesFile(String folder) { String FileName = folder + "\\" + Properties.Resources.RTE_RETURN_CODES_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, Properties.Resources.RTE_RETURN_CODES_FILENAME, "This file contains return codes of the RTE functions."); String guardDefine = RteFunctionsGenerator.OpenGuardDefine(writer); writer.WriteLine("/* Rte return codes */"); writer.WriteLine(RteFunctionsGenerator.CreateDefine(Properties.Resources.RTE_E_OK, "((uint32)0xFF)")); writer.WriteLine(RteFunctionsGenerator.CreateDefine(Properties.Resources.RTE_E_UNCONNECTED, "((uint32)0xFE)")); writer.WriteLine(); RteFunctionsGenerator.CloseGuardDefine(writer); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
void CreateComponentIncludes(String dir, ComponentDefenition componentDefenition) { String filename = dir + componentDefenition.Name + ".h"; StreamWriter writer = new StreamWriter(filename); RteFunctionsGenerator.GenerateFileTitle(writer, filename, "Implementation for header of " + componentDefenition.Name); RteFunctionsGenerator.OpenGuardDefine(writer); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.IncludesLine); RteFunctionsGenerator.AddInclude(writer, "Rte_" + componentDefenition.Name + ".h"); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfIncludesLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.MacrosLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfMacrosLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.TypeDefenitionsLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfTypeDefenitionsLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.ExternalVariablesLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfExternalVariableLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.GlobalFunctionsDeclarationLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfGlobalFunctionsDeclarationLine); writer.WriteLine(""); RteFunctionsGenerator.CloseGuardDefine(writer); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
void GenerateStaticVariablesForSenderPortsWithoutMultipleInstantiation(StreamWriter writer, PortPainter port, SenderReceiverInterfaceField field) { /* Declare variable and its default value */ IElementWithPorts compInst = AutosarApplication.GetInstance().FindComponentInstanceByPortGuid(port.GUID); String staticVariableName = RteFunctionsGenerator.GenerateRte_Component_SRInterface_Name(compInst.Name, port.Name, field); if (!field.IsPointer) { writer.Write("static " + field.DataTypeName + " " + staticVariableName + " ="); writer.Write(GenerateRteComponentSenderReceiverInterfaceField_DefaultValue(compInst.Name, port.Name, field)); } else { writer.Write("static " + field.DataTypeName + "* " + staticVariableName + " = 0"); } writer.WriteLine(";"); writer.WriteLine(""); }
public static void GenerateArrayForDataType(StreamWriter writer, IGUID datatype) { foreach (ArrayDataType arrayDT in AutosarApplication.GetInstance().ArrayDataTypes) { if (arrayDT.DataTypeGUID.Equals(datatype.GUID)) { /* Write array size */ String arraySizeNameMacro = arrayDT.Name + "_ELEMENTS_COUNT"; writer.WriteLine(RteFunctionsGenerator.CreateDefine(arraySizeNameMacro, arrayDT.Size.ToString() + "U")); writer.WriteLine(); /* Write a structure with array */ writer.WriteLine("typedef struct"); writer.WriteLine("{"); writer.WriteLine(" " + datatype.Name + " Values[" + arrayDT.Size + "];"); writer.WriteLine("} " + arrayDT.Name + ";"); writer.WriteLine(); } } }
public bool Generate() { /* Create base folders */ Directory.CreateDirectory(RteFunctionsGenerator.GetComponentsFolder()); Directory.CreateDirectory(RteFunctionsGenerator.GetRteFolder()); GenerateDataTypesFile(); GenerateComponentsFiles(); GenerateConnections(); GenerateScheduler(); ReturnCodesGenerator returnCodesGenerator = new ReturnCodesGenerator(); returnCodesGenerator.GenerateReturnCodesFile(RteFunctionsGenerator.GetRteFolder()); /* Create system errors file */ SystemErrorGenerator systemErrorGenerator = new SystemErrorGenerator(); systemErrorGenerator.GenerateSystemErrorsFile(RteFunctionsGenerator.GetRteFolder()); return(true); }
public void GenerateSystemErrorsFile(String folder) { String FileName = folder + "\\" + Properties.Resources.SYSTEM_ERRORS_H_FILENAME; StreamWriter writer = new StreamWriter(FileName); RteFunctionsGenerator.GenerateFileTitle(writer, Properties.Resources.RTE_DATATYPES_H_FILENAME, Properties.Resources.DATATYPES_H_FILE_DESCRIPTION); String guardDefine = RteFunctionsGenerator.OpenGuardDefine(writer); writer.WriteLine("/* Rte return codes */"); writer.WriteLine(RteFunctionsGenerator.CreateDefine(Properties.Resources.RTE_E_OK, "((uint32)0xFF)")); writer.WriteLine(RteFunctionsGenerator.CreateDefine(Properties.Resources.RTE_E_UNCONNECTED, "((uint32)0xFE)")); writer.WriteLine(); writer.WriteLine("/* System errors */"); WriteErrorsCount(writer); writer.WriteLine(); WriteAllErrors(writer); writer.WriteLine(); RteFunctionsGenerator.CloseGuardDefine(writer); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
void GenerateOsTaskFunctionCallOfRunnables_FREERTOS(StreamWriter writer, OsTask osTask, RteOsInterfaceGenerator osGenerator) { String osTaskName = RteFunctionsGenerator.GenerateRteOsTaskFunctionName(osTask); writer.WriteLine("static void " + osTaskName + "(void * pvParameters)"); writer.WriteLine("{"); String lastTickVariableName = "xLastWakeTime"; String xPeriodVariableName = "xPeriod"; writer.WriteLine(" " + osGenerator.TickDataType() + " " + lastTickVariableName + ";"); double sysTickFreq = AutosarApplication.GetInstance().SystickFrequencyHz; double delayValue = (double)(osTask.PeriodMs * sysTickFreq / 1000.0d); writer.WriteLine(" const " + osGenerator.TickDataType() + " " + xPeriodVariableName + " = " + ((int)(osTask.PeriodMs * 1000.0f)).ToString() + "u * " + ((int)sysTickFreq).ToString() + "u / 1000000u;"); writer.WriteLine(" " + lastTickVariableName + " = " + osGenerator.GetTickCount() + ";"); writer.WriteLine(" while(1)"); writer.WriteLine(" {"); WriteCallOfOsRunnables(writer, osTask); writer.WriteLine(" " + osGenerator.DelayUntil() + "(&" + lastTickVariableName + ", " + xPeriodVariableName + ");"); writer.WriteLine(" }"); writer.WriteLine("}"); writer.WriteLine(""); }
/* Generate funcitons for Sender-Receiver ports and call operations from client ports */ public void CreateRteIncludes(String dir, ComponentDefenition componentDefenition) { String filename = dir + "\\" + "Rte_" + componentDefenition.Name + ".h"; StreamWriter writer = new StreamWriter(filename); RteFunctionsGenerator.GenerateFileTitle(writer, filename, "Implementation for " + componentDefenition.Name + " header file"); string guardDefine = RteFunctionsGenerator.OpenGuardDefine(writer); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.IncludesLine); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.SYSTEM_ERRORS_H_FILENAME); RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_DATATYPES_H_FILENAME); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfIncludesLine); writer.WriteLine(""); /* MACROS */ writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.MacrosLine); /* Write all runnables frequences */ writer.WriteLine("/* Runnables frequences */"); foreach (PeriodicRunnableDefenition runnable in componentDefenition.Runnables) { String runnableFreqMacroName = "Rte_Period_" + componentDefenition.Name + "_ru" + runnable.Name; String define = RteFunctionsGenerator.CreateDefine(runnableFreqMacroName, (runnable.PeriodMs * 1000).ToString() + "UL"); writer.WriteLine(define); } /* Write all pims */ foreach (PimDefenition pim in componentDefenition.PerInstanceMemoryList) { String define = RteFunctionsGenerator.CreateDefine(RteFunctionsGenerator.GenerateShortPimFunctionName(pim), RteFunctionsGenerator.GenerateFullPimFunctionName(componentDefenition, pim), false); writer.WriteLine(define); } /* Write all cdata */ foreach (CDataDefenition cdata in componentDefenition.CDataDefenitions) { String define = RteFunctionsGenerator.CreateDefine(RteFunctionsGenerator.GenerateShortCDataFunctionName(cdata), RteFunctionsGenerator.GenerateFullCDataFunctionName(componentDefenition, cdata), false); writer.WriteLine(define); } String externFunctions = ""; /* Add defines for all ports */ foreach (PortDefenition portDefenition in componentDefenition.Ports) { if ((portDefenition.PortType == PortType.Sender) || (portDefenition.PortType == PortType.Receiver)) { SenderReceiverInterface srInterface = AutosarApplication.GetInstance().SenderReceiverInterfaces.FindObject(portDefenition.InterfaceGUID); foreach (SenderReceiverInterfaceField field in srInterface.Fields) { String funcName = RteFunctionsGenerator.GenerateReadWriteFunctionName(portDefenition, field); String RteFuncName = RteFunctionsGenerator.GenerateReadWriteConnectionFunctionName(portDefenition, field); writer.WriteLine(RteFunctionsGenerator.CreateDefine(funcName, RteFuncName, false)); String fieldVariable = RteFunctionsGenerator.GenerateSenderReceiverInterfaceArguments(field, portDefenition.PortType, componentDefenition.MultipleInstantiation); externFunctions += Properties.Resources.STD_RETURN_TYPE + funcName + fieldVariable + ";" + Environment.NewLine; } } else if (portDefenition.PortType == PortType.Client) { ClientServerInterface csInterface = AutosarApplication.GetInstance().ClientServerInterfaces.FindObject(portDefenition.InterfaceGUID); foreach (ClientServerOperation operation in csInterface.Operations) { String funcName = RteFunctionsGenerator.Generate_RteCall_FunctionName(portDefenition, operation); String RteFuncName = RteFunctionsGenerator.Generate_RteCall_ConnectionGroup_FunctionName(componentDefenition, portDefenition, operation); String funcArgument = RteFunctionsGenerator.GenerateClientServerInterfaceArguments(operation, componentDefenition.MultipleInstantiation); writer.WriteLine(RteFunctionsGenerator.CreateDefine(funcName, RteFuncName, false)); externFunctions += Properties.Resources.STD_RETURN_TYPE + funcName + funcArgument + ";" + Environment.NewLine; } } else if (portDefenition.PortType == PortType.Server) { ClientServerInterface csInterface = AutosarApplication.GetInstance().ClientServerInterfaces.FindObject(portDefenition.InterfaceGUID); foreach (ClientServerOperation operation in csInterface.Operations) { String funcName = RteFunctionsGenerator.Generate_RteCall_FunctionName(portDefenition, operation); String RteFuncName = RteFunctionsGenerator.Generate_RteCall_ConnectionGroup_FunctionName(componentDefenition, portDefenition, operation); String funcArgument = RteFunctionsGenerator.GenerateClientServerInterfaceArguments(operation, componentDefenition.MultipleInstantiation); writer.WriteLine(RteFunctionsGenerator.CreateDefine(funcName, RteFuncName, false)); } } } writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfMacrosLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.RteFunctionsDefenitionsLine); writer.WriteLine(""); /* Add function */ writer.Write(externFunctions); /* Add Pim's functions */ foreach (PimDefenition pimDefenition in componentDefenition.PerInstanceMemoryList) { String datatype = pimDefenition.DataTypeName; String pimFuncName = RteFunctionsGenerator.GenerateShortPimFunctionName(pimDefenition); String arguments = "("; if (componentDefenition.MultipleInstantiation) { arguments += RteFunctionsGenerator.ComponentInstancePointerDatatype + " instance"; } arguments += ");"; writer.WriteLine(datatype + " * " + pimFuncName + arguments); } /* Add CData functions */ foreach (CDataDefenition cdataDefenition in componentDefenition.CDataDefenitions) { String datatype = cdataDefenition.DataTypeName; String cdataFuncName = RteFunctionsGenerator.GenerateShortCDataFunctionName(cdataDefenition); String arguments = "("; if (componentDefenition.MultipleInstantiation) { arguments += RteFunctionsGenerator.ComponentInstancePointerDatatype + " instance"; } arguments += ");"; writer.WriteLine(datatype + " " + cdataFuncName + arguments); } writer.WriteLine(RteFunctionsGenerator.EndOfRteFunctionsDefenitionsLine); writer.WriteLine(""); writer.WriteLine(""); RteFunctionsGenerator.CloseGuardDefine(writer); writer.Close(); }
void CreateServerCalls(String dir, ComponentDefenition compDefenition, PortDefenition portDefenition) { String filename = dir + compDefenition.Name + "_" + portDefenition.Name + ".c"; StreamWriter writer = new StreamWriter(filename); RteFunctionsGenerator.GenerateFileTitle(writer, filename, "Implementation for " + compDefenition.Name + " " + portDefenition.Name); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.IncludesLine); RteFunctionsGenerator.AddInclude(writer, compDefenition.Name + ".h"); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfIncludesLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.MacrosLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfMacrosLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.TypeDefenitionsLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfTypeDefenitionsLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.VariablesLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfVariableLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.LocalFunctionsDeclarationLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfLocalFunctionsDeclarationLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.LocalFunctionsDefenitionsLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfLocalFunctionsDefenitionsLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.GlobalFunctionsDefenitionsLine); writer.WriteLine(""); ClientServerInterface csInterface = AutosarApplication.GetInstance().ClientServerInterfaces.FindObject(portDefenition.InterfaceGUID); if (csInterface != null) { foreach (ClientServerOperation operation in csInterface.Operations) { /* Fill functions which component could use */ /* Fill all function names which component could use*/ WriteAllFunctionWhichComponentCouldUse(compDefenition, writer); String funcName = RteFunctionsGenerator.Generate_RteCall_FunctionName(portDefenition, operation); String funcArgument = RteFunctionsGenerator.GenerateClientServerInterfaceArguments(operation, compDefenition.MultipleInstantiation); writer.WriteLine(Properties.Resources.STD_RETURN_TYPE + funcName + funcArgument); writer.WriteLine("{"); writer.WriteLine(" return " + Properties.Resources.RTE_E_OK + ";"); writer.WriteLine("}"); writer.WriteLine(""); } writer.WriteLine(RteFunctionsGenerator.EndOfGlobalFunctionsDefenitionsLine); writer.WriteLine(""); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); } else { System.Windows.MessageBox.Show(portDefenition.GUID.ToString("B") + " not found in interfaces!"); } }
private static void WriteAllFunctionWhichComponentCouldUse(ComponentDefenition compDefenition, StreamWriter writer) { List <String> lines = new List <string>(); /* Write function name and its body */ foreach (PimDefenition pimDefenition in compDefenition.PerInstanceMemoryList) { lines.Add(" * " + RteFunctionsGenerator.GenerateShortPimFunctionName(pimDefenition)); } foreach (CDataDefenition cdataDefenition in compDefenition.CDataDefenitions) { lines.Add(" * " + RteFunctionsGenerator.GenerateShortCDataFunctionName(cdataDefenition)); } foreach (PortDefenition port in compDefenition.Ports) { if (port.PortType == PortType.Receiver) { SenderReceiverInterface srInterface = AutosarApplication.GetInstance().SenderReceiverInterfaces.FindObject(port.InterfaceGUID); foreach (SenderReceiverInterfaceField field in srInterface.Fields) { lines.Add(" * " + RteFunctionsGenerator.GenerateReadWriteFunctionName(port, field)); } } } foreach (PortDefenition port in compDefenition.Ports) { if (port.PortType == PortType.Sender) { SenderReceiverInterface srInterface = AutosarApplication.GetInstance().SenderReceiverInterfaces.FindObject(port.InterfaceGUID); foreach (SenderReceiverInterfaceField field in srInterface.Fields) { lines.Add(" * " + RteFunctionsGenerator.GenerateReadWriteFunctionName(port, field)); } } } foreach (PortDefenition port in compDefenition.Ports) { if (port.PortType == PortType.Client) { ClientServerInterface csInterface = AutosarApplication.GetInstance().ClientServerInterfaces.FindObject(port.InterfaceGUID); foreach (ClientServerOperation operation in csInterface.Operations) { lines.Add(" * " + RteFunctionsGenerator.Generate_RteCall_FunctionName(port, operation)); } } } if (lines.Count > 0) { writer.WriteLine("/* "); writer.WriteLine(" * This RTE function could be used: "); foreach (String str in lines) { writer.WriteLine(str); } writer.WriteLine(" */"); } }
void CreateRunnable(String dir, PeriodicRunnableDefenition runnable) { ComponentDefenition compDefenition = AutosarApplication.GetInstance().FindComponentDefenitionByRunnnable(runnable); String filename = dir + compDefenition.Name + "_" + runnable.Name + ".c"; StreamWriter writer = new StreamWriter(filename); RteFunctionsGenerator.GenerateFileTitle(writer, filename, "Implementation for " + compDefenition.Name + "_" + runnable.Name); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.IncludesLine); RteFunctionsGenerator.AddInclude(writer, compDefenition.Name + ".h"); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfIncludesLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.MacrosLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfMacrosLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.TypeDefenitionsLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfTypeDefenitionsLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.VariablesLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfVariableLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.LocalFunctionsDeclarationLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfLocalFunctionsDeclarationLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.LocalFunctionsDefenitionsLine); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfLocalFunctionsDefenitionsLine); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.GlobalFunctionsDefenitionsLine); writer.WriteLine(""); /* Fill all function names which component could use*/ WriteAllFunctionWhichComponentCouldUse(compDefenition, writer); writer.WriteLine(RteFunctionsGenerator.Generate_RunnableFunction(compDefenition, runnable)); writer.WriteLine("{"); writer.WriteLine(" "); writer.WriteLine("}"); writer.WriteLine(""); writer.WriteLine(RteFunctionsGenerator.EndOfGlobalFunctionsDefenitionsLine); writer.WriteLine(""); RteFunctionsGenerator.WriteEndOfFile(writer); writer.Close(); }
void GenerateRteCallPortFieldFunction(StreamWriter writer, ComponentDefenition compDef, PortDefenition port, ClientServerOperation operation) { String returnValue = Properties.Resources.STD_RETURN_TYPE; String RteFuncName = RteFunctionsGenerator.Generate_RteCall_ConnectionGroup_FunctionName(compDef, port, operation); String fieldVariable = RteFunctionsGenerator.GenerateClientServerInterfaceArguments(operation, compDef.MultipleInstantiation); writer.WriteLine(returnValue + RteFuncName + fieldVariable); writer.WriteLine("{"); if (!compDef.MultipleInstantiation) //single instantiation component { ComponentInstancesList components = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef); if (components.Count > 0) { ComponentInstance compInstance = components[0]; PortPainter portPainter = compInstance.Ports.FindPortByItsDefenition(port); ComponentInstance oppositCompInstance; PortPainter oppositePort; AutosarApplication.GetInstance().GetOppositePortAndComponent(portPainter, out oppositCompInstance, out oppositePort); if (oppositCompInstance != null) { String functionName = RteFunctionsGenerator.Generate_RteCall_ConnectionGroup_FunctionName(oppositCompInstance.ComponentDefenition, oppositePort.PortDefenition, operation); String arguments = RteFunctionsGenerator.Generate_ClientServerPort_Arguments(oppositCompInstance, operation, oppositCompInstance.ComponentDefenition.MultipleInstantiation); writer.WriteLine(" return " + functionName + arguments + ";"); } else { writer.WriteLine(" return " + Properties.Resources.RTE_E_UNCONNECTED + ";"); } } } else //multiple instantiation component { ComponentInstancesList components = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef); if (components.Count > 0) { writer.WriteLine(" switch(((" + compDef.Name + "*)" + "instance)->index)"); writer.WriteLine(" {"); for (int i = 0; i < components.Count; i++) { ComponentInstance compInstance = components[i]; PortPainter portPainter = compInstance.Ports.FindPortByItsDefenition(port); ComponentInstance oppositCompInstance; PortPainter oppositePort; AutosarApplication.GetInstance().GetOppositePortAndComponent(portPainter, out oppositCompInstance, out oppositePort); writer.WriteLine(" case " + i.ToString() + ": "); writer.WriteLine(" {"); if (oppositCompInstance != null) { String functionName = RteFunctionsGenerator.Generate_RteCall_ConnectionGroup_FunctionName(oppositCompInstance.ComponentDefenition, oppositePort.PortDefenition, operation); String arguments = RteFunctionsGenerator.Generate_ClientServerPort_Arguments(oppositCompInstance, operation, oppositCompInstance.ComponentDefenition.MultipleInstantiation); writer.WriteLine(" return " + functionName + arguments + ";"); } else { writer.WriteLine(" return " + Properties.Resources.RTE_E_UNCONNECTED + ";"); } writer.WriteLine(" }"); } writer.WriteLine(" }"); } writer.WriteLine(" return " + Properties.Resources.RTE_E_UNCONNECTED + ";"); } writer.WriteLine("}"); writer.WriteLine(""); }
void GenerateDataTypesFile() { RteDataTypesGenerator dataTypesGenerator = new RteDataTypesGenerator(); dataTypesGenerator.GenerateDataTypesFile(RteFunctionsGenerator.GetRteFolder()); }