Atmel_bsp_generator.Program.AtmelBSPBuilder.GetMemoryLayout C# (CSharp) Method

GetMemoryLayout() public method

public GetMemoryLayout ( MCUBuilder mcu, MCUFamilyBuilder family ) : MemoryLayout
mcu MCUBuilder
family MCUFamilyBuilder
return LinkerScriptGenerator.MemoryLayout
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes.
                MemoryLayout layout = new MemoryLayout();
                layout.Memories = new List<Memory>();
                layout.DeviceName = mcu.Name;
                string shName = mcu.Name;
                string aDirSam;
                if (mcu.Name.StartsWith("AT"))
                    shName = mcu.Name.Substring(2, mcu.Name.Length - 2);
                if (shName.StartsWith("SAMC") || shName.StartsWith("SAMD") || shName.StartsWith("SAMR") || shName.StartsWith("SAMB") || shName.StartsWith("SAML"))
                    aDirSam = "\\Sam0";
                else
                    aDirSam = "\\Sam";
                //  EAK                if (shName == "SAMD10D13A" || shName == "SAMD10D14A" || shName == "SAMD10D12A"|| shName == "SAMD11D14A")
                //  EAK                    shName = shName + "S";//Different Device ID (DID)
                string aFileName = family.BSP.Directories.InputDir + aDirSam +"\\Utils\\Cmsis\\" + family.FamilyFilePrefix + "\\Include\\" + shName;

                if (family.FamilyFilePrefix.ToUpper().StartsWith("SAMG"))
                    aFileName = family.BSP.Directories.InputDir + "\\Sam\\Utils\\Cmsis\\samg\\" + family.FamilyFilePrefix + "\\Include\\" + shName;

                if (family.Definition.Name.ToUpper() == "SAM4C" || family.Definition.Name.ToUpper() == "SAM4CM" || family.Definition.Name.ToUpper() == "SAM4CP" || family.Definition.Name.ToUpper() == "SAM4CM32")
                    aFileName = aFileName + "_0.h";
                else
                    aFileName = aFileName + ".h";

                int RAMStart = -1;
                int FLASHStart = -1;

                if (Regex.IsMatch(mcu.Name, "SAML21...B"))
                    aFileName = aFileName.Replace("\\Include\\S", "\\Include_b\\S");

                foreach (var ln in File.ReadAllLines(aFileName))
                {
                //                    var m = Regex.Match(ln, @"(#define [IH]?[HS]?[HMC]*RAM[C]?[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^uU]+)+.*");
                    var m = Regex.Match(ln, @"(#define [ID]*[IH]?[HS]?[HMC]*RAM[C]?[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^uU]+[L]?)+.*");

                    if (m.Success)
                    {
                        RAMStart = Convert.ToInt32(m.Groups[2].Value, 16);
                    }

                    m = Regex.Match(ln, @"(#define [I]?FLASH[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");
                    if (!m.Success)
                        m = Regex.Match(ln, @"(#define [I]?FLASH[0]?_CNC_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");
                    if (!m.Success)
                        m = Regex.Match(ln, @"(#define BOOTROM_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");//samb11
                    if (m.Success)
                    {
                        FLASHStart = Convert.ToInt32(m.Groups[2].Value, 16);
                    }
                    if (FLASHStart > -1 && RAMStart > -1)
                        break;
                }
                if (RAMStart == -1)
                    throw new Exception("no RAM Start");
                //    Console.WriteLine("RAMBase mcu {0} NO file :{1} ", mcu.Name, aFileName);
                if (FLASHStart == -1)
                    throw new Exception("no FLASH Start");
                 //   Console.WriteLine("FLASHBase mcu {0} NO file :{1} ",mcu.Name , aFileName);
                layout.Memories.Insert(0, new Memory
                {
                    Name = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.FLASH,
                    Start = (uint)FLASHStart,
                    Size = (uint)mcu.FlashSize
                });
                layout.Memories.Insert(0, new Memory
                {
                    Name = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.RAM,
                    Start = (uint)RAMStart,
                    Size = (uint)mcu.RAMSize
                });

                return layout;
            }