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();
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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();
        }
        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 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 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();
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        void GenerateDataTypesFile()
        {
            RteDataTypesGenerator dataTypesGenerator = new RteDataTypesGenerator();

            dataTypesGenerator.GenerateDataTypesFile(RteFunctionsGenerator.GetRteFolder());
        }
        void Generate_RteTaskScheduler_Source_File()
        {
            String       FileName = RteFunctionsGenerator.GetRteFolder() + "\\" + Properties.Resources.RTE_TASK_SCHEDULER_C_FILENAME;
            StreamWriter writer   = new StreamWriter(FileName);

            RteFunctionsGenerator.GenerateFileTitle(writer, FileName, Properties.Resources.RTE_RUNTIME_ENVIRONMENT_FILE_DESCRIPTION);

            writer.WriteLine();
            RteFunctionsGenerator.AddInclude(writer, Properties.Resources.RTE_RUNTIME_ENVIRONMENT_H_FILENAME);
            writer.WriteLine();

            int tasksCount = AutosarApplication.GetInstance().OsTasks.Count;

            writer.WriteLine(RteFunctionsGenerator.CreateDefine("RTE_TASKS_COUNT", tasksCount.ToString(), false));

            int stepsCount = AutosarApplication.GetInstance().OsTasks.GetSchedulerNecessaryStepsCount();

            writer.WriteLine();
            writer.WriteLine(RteFunctionsGenerator.CreateDefine("RTE_SCHEDULER_STEPS", stepsCount.ToString(), false));

            writer.WriteLine();
            writer.WriteLine("/* One Rte Task pointer */");
            writer.WriteLine("typedef void (*Rte_Scheduler_Task)();");

            writer.WriteLine();
            writer.WriteLine("/* One step of scheduler */");
            writer.WriteLine("typedef  Rte_Scheduler_Task Rte_Scheduler_Step[RTE_TASKS_COUNT];");

            writer.WriteLine();
            writer.WriteLine("/* All possible steps in scheduler */");
            writer.WriteLine("typedef  Rte_Scheduler_Step Rte_Scheduler_Sequence[RTE_SCHEDULER_STEPS];");

            writer.WriteLine();
            writer.WriteLine("static uint32 schedulingCounter = 0u;");

            writer.WriteLine();
            writer.WriteLine("volatile boolean timeEventOccured = FALSE;");

            writer.WriteLine();
            writer.WriteLine("static Rte_Scheduler_Sequence  taskScheduling =");
            writer.WriteLine("{");
            /* Sort tasks by priority is necessary */
            AutosarApplication.GetInstance().OsTasks.DoSort();
            double systickfreq           = AutosarApplication.GetInstance().SystickFrequencyHz;
            int    schedulerStepMicrosec = (int)((1000.0d / systickfreq) * 1000.0);

            for (int i = 0; i < stepsCount; i++)
            {
                writer.WriteLine("    {");
                int writtenFunctions = 0;
                for (int j = 0; j < tasksCount; j++)
                {
                    OsTask task             = AutosarApplication.GetInstance().OsTasks[j];
                    bool   includeCondition = true;

                    int TaskMicrosec = (int)(task.PeriodMs * 1000);

                    int ost = schedulerStepMicrosec * i % TaskMicrosec;
                    includeCondition = (ost == 0);
                    if (includeCondition)
                    {
                        String osTaskName = RteFunctionsGenerator.GenerateRteOsTaskFunctionName(task);
                        writer.Write("        " + osTaskName);
                        if (writtenFunctions < tasksCount - 1)
                        {
                            writer.WriteLine(",");
                        }
                        else
                        {
                            writer.WriteLine();
                        }
                        writtenFunctions++;
                    }
                }

                /* Write necessary NULLs */
                for (int j = writtenFunctions; j < tasksCount; j++)
                {
                    writer.Write("        NULL");
                    if (j < tasksCount - 1)
                    {
                        writer.WriteLine(",");
                    }
                    else
                    {
                        writer.WriteLine();
                    }
                }
                writer.Write("    }");
                if (i < stepsCount - 1)
                {
                    writer.WriteLine(",");
                }
                else
                {
                    writer.WriteLine();
                }
            }
            writer.WriteLine("};");
            writer.WriteLine();

            /* Writing DoScheduling function */
            writer.WriteLine("void DoScheduling(void)");
            writer.WriteLine("{");
            writer.WriteLine("    if (FALSE != timeEventOccured)");
            writer.WriteLine("    {");
            writer.WriteLine("        uint32 index = schedulingCounter % RTE_SCHEDULER_STEPS;");
            writer.WriteLine("        for (uint32 i = 0; i < RTE_TASKS_COUNT; i++)");
            writer.WriteLine("        {");
            writer.WriteLine("            if (NULL != taskScheduling[index][i])");
            writer.WriteLine("            {");
            writer.WriteLine("                taskScheduling[index][i]();");
            writer.WriteLine("            }");
            writer.WriteLine("            else");
            writer.WriteLine("            {");
            writer.WriteLine("                break;");
            writer.WriteLine("            }");
            writer.WriteLine("        }");
            writer.WriteLine("        schedulingCounter++;");
            writer.WriteLine("        timeEventOccured = FALSE;");
            writer.WriteLine("    }");
            writer.WriteLine("}");


            RteFunctionsGenerator.WriteEndOfFile(writer);
            writer.Close();
        }