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 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 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("");
        }
        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();
        }