コード例 #1
0
        static int GetRegValueFromFields(register r)
        {
            int rv = 0;

            foreach (var f in r.fields)
            {
                rv += f.value << f.bitOffset;
            }

            return(rv);
        }
コード例 #2
0
        //older format - register have no values; fields have; registers get value from fields
        static List <register> ProcessXML_IPXact(XElement root)
        {
            List <register> phyregs = new List <register>();
            //var mmaps = root.Elements().Last();
            var mmaps     = root.Elements().Where(x => x.Name.LocalName.Contains("memoryMaps")).First();
            var mmap      = mmaps.Elements().First();
            var addrBlock = mmap.Elements().First(x => x.Name.LocalName.Contains("addressBlock"));

            //Console.WriteLine(addrBlock.Elements().Count());
            var regs = addrBlock.Elements().Where(x => x.Name.LocalName == "register");  //all the registers

            Console.WriteLine(regs.Count());
            foreach (var z in regs)
            {
                //skip ROM/RAM register - name starts with RAWMEM_DIG_ROM or RAWMEM_DIG_RAM
                var reg_name = z.Elements().First().Value;
                //Debug.WriteLine(reg_name);

                //var addr = z.Elements().First(x => x.Name.LocalName == "addressOffset").Value;
                //char msb = addr.ToCharArray()[2];

                if (!reg_name.StartsWith("RAWMEM_DIG_R"))
                {
                    var xr = new register();
                    xr.name        = reg_name;
                    xr.description = z.Elements().First(x => x.Name.LocalName == "description").Value;
                    xr.Offset      = IntParse(z.Elements().First(x => x.Name.LocalName == "addressOffset").Value);


                    var fields = z.Elements().Where(x => x.Name.LocalName == "field");
                    foreach (var f in fields)
                    {
                        var n = f.Elements().First(x => x.Name.LocalName == "name").Value;
                        //description may not exist for some fields; must use FirstOrDefault()
                        string d = f.Elements().FirstOrDefault(x => x.Name.LocalName == "description")?.Value ?? string.Empty;

                        var offset     = f.Elements().First(x => x.Name.LocalName == "bitOffset").Value;
                        var resets     = f.Elements().First(x => x.Name.LocalName == "resets");
                        var resetvalue = IntParse(resets.Descendants().First(x => x.Name.LocalName == "value").Value);
                        //var resetmask = resets.Descendants().First(x => x.Name.LocalName == "mask").Value;
                        var w   = f.Elements().First(x => x.Name.LocalName == "bitWidth").Value;
                        var acc = f.Elements().First(x => x.Name.LocalName == "access").Value;

                        field ff = new field
                        {
                            name        = n,
                            description = d,
                            bitOffset   = int.Parse(offset),
                            value       = resetvalue,

                            bitWidth = int.Parse(w)
                        };
                        if (acc == "read-only")
                        {
                            ff.Access = AccessType.R;
                        }
                        else if (acc == "read-write")
                        {
                            ff.Access = AccessType.RW;
                        }
                        else
                        {
                            throw new Exception("unexpected access type for field " + n);
                        }

                        xr.fields.Add(ff);
                    }

                    //no "register" reset value in older format; only in fields; need to calculate

                    xr.resetValue = GetRegValueFromFields(xr);
                    phyregs.Add(xr);
                }
            }
            return(phyregs);
        }
コード例 #3
0
        //newer format - register have values; fields do not; fields get value from register
        static List <register> ProcessXML_SNPS(XElement root)
        {
            List <register> phyregs = new List <register>();
            //foreach(var x in root.Elements())
            //{
            //    Console.WriteLine(x.Name.LocalName);
            //}

            var ver = root.Elements().Where(x => x.Name.LocalName.Contains("version")).First().Value;

            Console.WriteLine("version " + ver);

            var mmaps     = root.Elements().Where(x => x.Name.LocalName.Contains("memoryMaps")).First();
            var mmap      = mmaps.Elements().First();
            var addrBlock = mmap.Elements().First(x => x.Name.LocalName.Contains("addressBlock"));

            //Console.WriteLine(addrBlock.Elements().Count());
            var regs = addrBlock.Elements().Where(x => string.Compare(x.Name.LocalName, "register", StringComparison.OrdinalIgnoreCase) == 0);  //all the registers

            Console.WriteLine(regs.Count());
            foreach (var z in regs)
            {
                //skip ROM/RAM register - name starts with RAWMEM_DIG_ROM or RAWMEM_DIG_RAM
                var reg_name = z.Elements().First().Value;
                //Debug.WriteLine(reg_name);

                //var addr = z.Elements().First(x => x.Name.LocalName == "addressOffset").Value;
                //char msb = addr.ToCharArray()[2];

                if (!reg_name.StartsWith("RAWMEM_DIG_R"))
                {
                    var xr = new register();
                    xr.name        = reg_name;
                    xr.description = z.Elements().First(x => x.Name.LocalName == "description").Value;
                    xr.Offset      = IntParse(z.Elements().First(x => x.Name.LocalName == "addressOffset").Value);
                    xr.resetValue  = IntParse(z.Elements().First(x => x.Name.LocalName == "reset").Elements().First().Value);
                    //xr.resetMask = z.Elements().First(x => x.Name.LocalName == "reset").Elements().Last().Value;

                    var fields = z.Elements().Where(x => x.Name.LocalName == "field");
                    foreach (var f in fields)
                    {
                        var n = f.Elements().First(x => x.Name.LocalName == "name").Value;
                        //description may not exist for some fields; must use FirstOrDefault()
                        string d = f.Elements().FirstOrDefault(x => x.Name.LocalName == "description")?.Value ?? string.Empty;

                        var offset = f.Elements().First(x => x.Name.LocalName == "bitOffset").Value;
                        //var resets = f.Elements().First(x => x.Name.LocalName == "resets");
                        //var resetvalue = resets.Descendants().First(x => x.Name.LocalName == "value").Value;
                        var w   = f.Elements().First(x => x.Name.LocalName == "bitWidth").Value;
                        var acc = f.Elements().First(x => x.Name.LocalName == "access").Value;

                        field ff = new field
                        {
                            name        = n,
                            description = d,
                            bitOffset   = int.Parse(offset),
                            bitWidth    = int.Parse(w)
                        };
                        ff.value = GetFieldValue(xr.resetValue, ff.bitOffset, ff.bitWidth);

                        if (acc == "read-only")
                        {
                            ff.Access = AccessType.R;
                        }
                        else if (acc == "read-write")
                        {
                            ff.Access = AccessType.RW;
                        }
                        else
                        {
                            throw new Exception("unexpected access type for field " + n);
                        }

                        xr.fields.Add(ff);
                    }
                    phyregs.Add(xr);
                }
            }
            return(phyregs);
        }