Example #1
0
        public void Reset()
        {
            clkFreq           = 8000000;
            device            = "atmega168";
            packStructs       = true;
            shortEnums        = true;
            unsignedBitfields = true;
            unsignedChars     = true;
            useInitStack      = false;
            initStackAddr     = ushort.MaxValue;
            otherOpt          = "";
            linkerOpt         = "";
            outputDir         = "output";
            optimization      = "-Os";

            burnPart = device;
            burnProg = "avrisp";
            burnOpt  = "";

            fileList.Clear();
            IncludeDirList.Clear();
            LibraryDirList.Clear();
            LinkObjList.Clear();
            LinkLibList.Clear();
            MemorySegList.Clear();

            isReady = false;
        }
Example #2
0
        public bool Open(string path)
        {
            bool success = true;

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);

                XmlElement docx = doc.DocumentElement;

                XmlElement param;
                param = (XmlElement)docx.GetElementsByTagName("DirPath")[0];
                string xDirPath = Program.CleanFilePath(param.InnerText);
                param         = (XmlElement)docx.GetElementsByTagName("ClockFreq")[0];
                ClockFreq     = decimal.Parse(param.InnerText);
                param         = (XmlElement)docx.GetElementsByTagName("Device")[0];
                Device        = param.InnerText;
                param         = (XmlElement)docx.GetElementsByTagName("LinkerOpt")[0];
                LinkerOptions = param.InnerText;
                param         = (XmlElement)docx.GetElementsByTagName("OtherOpt")[0];
                OtherOptions  = param.InnerText;
                param         = (XmlElement)docx.GetElementsByTagName("OutputDir")[0];
                OutputDir     = param.InnerText;
                param         = (XmlElement)docx.GetElementsByTagName("Optimization")[0];
                Optimization  = param.InnerText;

                param         = (XmlElement)docx.GetElementsByTagName("UseInitStack")[0];
                UseInitStack  = param.InnerText.ToLower().Trim() == "true";
                param         = (XmlElement)docx.GetElementsByTagName("InitStackAddr")[0];
                InitStackAddr = Convert.ToUInt32("0x" + param.InnerText, 16);

                param             = (XmlElement)docx.GetElementsByTagName("PackStructs")[0];
                PackStructs       = param.InnerText.ToLower().Trim() == "true";
                param             = (XmlElement)docx.GetElementsByTagName("ShortEnums")[0];
                ShortEnums        = param.InnerText.ToLower().Trim() == "true";
                param             = (XmlElement)docx.GetElementsByTagName("UnsignedBitfields")[0];
                UnsignedBitfields = param.InnerText.ToLower().Trim() == "true";
                param             = (XmlElement)docx.GetElementsByTagName("UnsignedChars")[0];
                UnsignedChars     = param.InnerText.ToLower().Trim() == "true";

                param          = (XmlElement)docx.GetElementsByTagName("BurnPart")[0];
                BurnPart       = param.InnerText;
                param          = (XmlElement)docx.GetElementsByTagName("BurnProgrammer")[0];
                BurnProgrammer = param.InnerText;
                param          = (XmlElement)docx.GetElementsByTagName("BurnOptions")[0];
                BurnOptions    = param.InnerText;

                IncludeDirList.Clear();
                XmlElement  container = (XmlElement)docx.GetElementsByTagName("IncludeDirList")[0];
                XmlNodeList list      = container.GetElementsByTagName("DirPath");
                foreach (XmlElement i in list)
                {
                    IncludeDirList.Add(i.InnerText);
                }

                LibraryDirList.Clear();
                container = (XmlElement)docx.GetElementsByTagName("IncludeDirList")[0];
                list      = container.GetElementsByTagName("DirPath");
                foreach (XmlElement i in list)
                {
                    LibraryDirList.Add(i.InnerText);
                }

                LinkObjList.Clear();
                container = (XmlElement)docx.GetElementsByTagName("LinkObjList")[0];
                list      = container.GetElementsByTagName("Obj");
                foreach (XmlElement i in list)
                {
                    LinkObjList.Add(i.InnerText);
                }

                LinkLibList.Clear();
                container = (XmlElement)docx.GetElementsByTagName("LinkLibList")[0];
                list      = container.GetElementsByTagName("Lib");
                foreach (XmlElement i in list)
                {
                    LinkLibList.Add(i.InnerText);
                }

                MemorySegList.Clear();
                container = (XmlElement)docx.GetElementsByTagName("MemorySegList")[0];
                list      = container.GetElementsByTagName("Segment");
                foreach (XmlElement i in list)
                {
                    XmlElement type = (XmlElement)i.GetElementsByTagName("Type")[0];
                    XmlElement name = (XmlElement)i.GetElementsByTagName("Name")[0];
                    XmlElement addr = (XmlElement)i.GetElementsByTagName("Addr")[0];
                    MemorySegList.Add(new MemorySegment(type.InnerText, name.InnerText, Convert.ToUInt32(addr.InnerText, 16)));
                }

                FileList.Clear();
                container = (XmlElement)docx.GetElementsByTagName("FileList")[0];
                list      = container.GetElementsByTagName("File");

                string dirPath = Program.CleanFilePath(path);
                dirPath = dirPath.Substring(0, dirPath.LastIndexOf('\\'));

                List <ProjectFile> flistOld = new List <ProjectFile>();
                List <ProjectFile> flistNew = new List <ProjectFile>();

                foreach (XmlElement i in list)
                {
                    XmlElement relPath = (XmlElement)i.GetElementsByTagName("RelPath")[0];
                    XmlElement toComp  = (XmlElement)i.GetElementsByTagName("ToCompile")[0];
                    XmlElement opt     = (XmlElement)i.GetElementsByTagName("Options")[0];

                    string newPath = dirPath + "\\" + Program.CleanFilePath(relPath.InnerText);
                    string oldPath = xDirPath + "\\" + Program.CleanFilePath(relPath.InnerText);

                    ProjectFile newFile = new ProjectFile(newPath, dirPath.Substring(0, path.LastIndexOf('\\')));
                    flistNew.Add(newFile);

                    if (xDirPath != dirPath)
                    {
                        ProjectFile oldFile = new ProjectFile(oldPath, xDirPath);
                        flistOld.Add(oldFile);
                    }
                }

                int newCnt = 0;
                int oldCnt = 0;
                int total  = flistNew.Count;

                if (flistOld.Count > 0)
                {
                    for (int i = 0; i < total && newCnt < (total + 1) / 2 && oldCnt < (total + 1) / 2; i++)
                    {
                        if (flistNew[i].Exists)
                        {
                            newCnt++;
                        }
                        if (flistOld[i].Exists)
                        {
                            oldCnt++;
                        }
                    }
                }
                else
                {
                    newCnt = total;
                }

                if (newCnt >= oldCnt)
                {
                    foreach (ProjectFile file in flistNew)
                    {
                        fileList.Add(file.FileName, file);
                    }
                    xDirPath = dirPath;
                }
                else
                {
                    foreach (ProjectFile file in flistOld)
                    {
                        fileList.Add(file.FileName, file);
                    }
                    dirPath = xDirPath;
                }
            }
            catch
            {
                success = false;
            }

            if (success)
            {
                filePath = path;
                isReady  = true;
            }

            return(success);
        }