public static void SetComboBoxValue(ComboBox comboBox, string val) { for (int i = 0; i < comboBox.Items.Count; i++) { if (comboBox.Items[i] is PropertyEntry.Enumerated.Suggestion && (comboBox.Items[i] as PropertyEntry.Enumerated.Suggestion).InternalValue == val) { comboBox.SelectedIndex = i; return; } } var item = new PropertyEntry.Enumerated.Suggestion { InternalValue = val }; comboBox.Items.Add(item); comboBox.SelectedItem = item; }
//parsing KConfig static PropertyList ParserKConfig(string pKFile) { string typ = ""; string name = "", UID = "", min = "", max = ""; bool newProperty = false, flHelp = false, flEnum = false; var def = ""; string lstHelp = ""; List <PropertyEntry> ListProperties = new List <PropertyEntry>(); PropertyEntry PropEntry = new PropertyEntry.Boolean(); bool BoolNameChoice = false; PropertyEntry.Enumerated.Suggestion SugEnum = null;// new PropertyEntry.Enumerated.Suggestion(); List <PropertyEntry.Enumerated.Suggestion> lstSugEnum = new List <PropertyEntry.Enumerated.Suggestion>(); int aCounrEnumDef = 0; int resParse; string lnHist = ""; foreach (var ln in File.ReadAllLines(pKFile)) { if (ln.Contains("menu \"Example Configuration\"")) { resParse = 3; } Match m = Regex.Match(ln, "^(menuconfig|config|choice)[ ]+([A-Z0-9_]+)"); if (m.Success) { if (flEnum) { SugEnum = new PropertyEntry.Enumerated.Suggestion(); SugEnum.InternalValue = m.Groups[2].Value; if (m.Groups[2].Value == def) { def = $"{aCounrEnumDef}"; } aCounrEnumDef++; } if (m.Groups[1].Value == "choice") { BoolNameChoice = true; flEnum = true; } if (m.Groups[1].Value == "config") { BoolNameChoice = false; } if (name != "")//save { if (typ == "string") { PropEntry = new PropertyEntry.String { Name = name, UniqueID = UID, Description = lstHelp, DefaultValue = def }; } if (typ == "int") { PropEntry = new PropertyEntry.Integral { Name = name, UniqueID = UID, Description = lstHelp, DefaultValue = Int32.TryParse(def, out resParse) ? Int32.Parse(def) : 0, MinValue = Int32.TryParse(min, out resParse) ? Int32.Parse(min) : 0, MaxValue = Int32.TryParse(max, out resParse) ? Int32.Parse(max) : 0x0FFFFFFF }; // break; } if (typ == "bool") { PropEntry = new PropertyEntry.Boolean { Name = name, UniqueID = UID, Description = lstHelp, DefaultValue = def.ToLower().Contains("y") ? true : false }; // break; } ListProperties.Add(PropEntry); if (!flEnum) { lstHelp = "";//.Clear(); } flHelp = false; } UID = m.Groups[2].Value; newProperty = true; } if (!newProperty) { continue; } if (flHelp && !ln.TrimStart().StartsWith("#") && ln.Length > 1) { lstHelp += ln.Trim(); } m = Regex.Match(ln, "^[ \t]+(int|bool|hex|prompt)[ ]+[\"]?([\\w0-9_ ]*)[\"]?"); if (m.Success) { if (flEnum) { if (m.Groups[1].Value == "bool" && !BoolNameChoice) { SugEnum.UserFriendlyName = m.Groups[2].Value; lstSugEnum.Add(SugEnum); continue; } // if (m.Groups[1].Value == "prompt") // throw new Exception(" no endchoice "+ lnHist); } typ = m.Groups[1].Value; name = m.Groups[2].Value; // if (typ == "prompt") flEnum = true; continue; } m = Regex.Match(ln, "^[ \t]+default[ \t]([\\w\\d]+)"); if (m.Success) { def = m.Groups[1].Value; continue; } m = Regex.Match(ln, "^[ \t]+range[ \t]([\\w\\d]+)[ \t]+([\\w\\d]+)"); if (m.Success) { min = m.Groups[1].Value; max = m.Groups[2].Value; continue; } if (Regex.IsMatch(ln, "^[ \t]+help[ \t]*")) { flHelp = true; continue; } if (Regex.IsMatch(ln, "^[ \t]*endchoice[ \t]*")) // end prompt { if (typ != "prompt" && typ != "bool") { throw new Exception(" no prompt in endchoice"); } flEnum = false; PropEntry = new PropertyEntry.Enumerated { Name = name, // UniqueID = UID, Description = lstHelp, DefaultEntryIndex = 1,// def.ToLower().StartsWith("y") ? true : false SuggestionList = lstSugEnum.ToArray() }; // break; ListProperties.Add(PropEntry); lstHelp = "";//.Clear(); flHelp = false; aCounrEnumDef = 0; } lnHist = ln; } // end file //save old record , need it to new function or class if (typ == "int") { PropEntry = new PropertyEntry.Integral { Name = name, UniqueID = UID, Description = lstHelp, DefaultValue = Int32.TryParse(def, out resParse) ? Int32.Parse(def) : 0, MinValue = Int32.TryParse(min, out resParse) ? Int32.Parse(min) : 0, MaxValue = Int32.TryParse(max, out resParse) ? Int32.Parse(max) : 0x0FFFFFFF }; // break; } if (typ == "bool") { PropEntry = new PropertyEntry.Boolean { Name = name, UniqueID = UID, Description = lstHelp, DefaultValue = def.ToLower().Contains("y") ? true : false }; // break; } ListProperties.Add(PropEntry); //----------------------- List <PropertyGroup> lstPrGr = new List <PropertyGroup>(); PropertyGroup PrGr = new PropertyGroup(); PrGr.Properties = ListProperties; lstPrGr.Add(PrGr); PropertyList ConfigurableProperties = new PropertyList { PropertyGroups = lstPrGr }; return(ConfigurableProperties); }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: nrf5x.exe <Nordic SW package directory>"); } bool usingIoTSDK = false; if (Directory.Exists(Path.Combine(args[0], @"components\iot\ble_6lowpan"))) { usingIoTSDK = true; Console.WriteLine("Detected IoT SDK"); } NordicBSPBuilder bspBuilder; if (usingIoTSDK) { bspBuilder = new NordicBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules_iot")); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("s1xx_iot", 0x1f000, 0x2800, "nrf52", "IoT")); } else { bspBuilder = new NordicBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S130", 0x1b000, 0x13c8, "nrf51", "Bluetooth LE Universal")); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S132", 0x20000, 0x2168, "nrf52832", "Bluetooth LE")); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S140", 0x21000, 0x2780, "nrf52840", "Bluetooth LE")); } List <MCUBuilder> devices = new List <MCUBuilder>(); if (!usingIoTSDK) { foreach (string part in new string[] { "nRF51822", "nRF51422" }) { devices.Add(new MCUBuilder { Name = part + "_XXAA", FlashSize = 256 * 1024, RAMSize = 16 * 1024, Core = CortexCore.M0 }); devices.Add(new MCUBuilder { Name = part + "_XXAB", FlashSize = 128 * 1024, RAMSize = 16 * 1024, Core = CortexCore.M0 }); devices.Add(new MCUBuilder { Name = part + "_XXAC", FlashSize = 256 * 1024, RAMSize = 32 * 1024, Core = CortexCore.M0 }); } } devices.Add(new MCUBuilder { Name = "nRF52832_XXAA", FlashSize = 512 * 1024, RAMSize = 64 * 1024, Core = CortexCore.M4 }); devices.Add(new MCUBuilder { Name = "nRF52840_XXAA", FlashSize = 1024 * 1024, RAMSize = 256 * 1024, Core = CortexCore.M4 }); List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) { allFamilies.Add(new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(fn))); } var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allFamilies); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <MCUFamilyBuilder.CopiedSample> exampleDirs = new List <MCUFamilyBuilder.CopiedSample>(); bool noPeripheralRegisters = true; List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); flags = flags.Merge(commonPseudofamily.Definition.CompilationFlags); List <ConditionalToolFlags> condFlags = new List <ConditionalToolFlags>(); foreach (var fam in allFamilies) { Console.WriteLine("Processing " + fam.Definition.Name + " family..."); string famBase = fam.Definition.Name.Substring(0, 5).ToLower(); var rejectedMCUs = fam.RemoveUnsupportedMCUs(true); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } List <Framework> bleFrameworks = new List <Framework>(); foreach (var line in File.ReadAllLines(bspBuilder.Directories.RulesDir + @"\BLEFrameworks.txt")) { int idx = line.IndexOf('|'); string dir = line.Substring(0, idx); string desc = line.Substring(idx + 1); string id = Path.GetFileName(dir); if (!id.StartsWith("ble_")) { id = "ble_" + id; } if (dir.StartsWith("services\\", StringComparison.CurrentCultureIgnoreCase)) { id = "ble_svc_" + id.Substring(4); } bleFrameworks.Add(new Framework { Name = string.Format("Bluetooth LE - {0} ({1})", desc, Path.GetFileName(dir)), ID = "com.sysprogs.arm.nordic." + famBase + "." + id, ClassID = "com.sysprogs.arm.nordic.nrfx." + id, ProjectFolderName = "BLE " + desc, DefaultEnabled = false, CopyJobs = new CopyJob[] { new CopyJob { SourceFolder = allFamilies[0].Definition.PrimaryHeaderDir + @"\..\components\ble\" + dir, TargetFolder = dir, FilesToCopy = "*.c;*.h", } } }); } fam.Definition.AdditionalFrameworks = fam.Definition.AdditionalFrameworks.Concat(bleFrameworks).ToArray(); // Startup Files StartupFileGenerator.InterruptVectorTable[] aStartupVectors; if (usingIoTSDK) { aStartupVectors = new StartupFileGenerator.InterruptVectorTable[] { GenerateStartupFile(fam.Definition.StartupFileDir, "nRF52") } } ; else { aStartupVectors = new StartupFileGenerator.InterruptVectorTable[] { GenerateStartupFile(fam.Definition.StartupFileDir, "nRF51"), GenerateStartupFile(fam.Definition.StartupFileDir, "nRF52") } }; fam.AttachStartupFiles(aStartupVectors); // SVD Files var aMcuDef1 = (new MCUDefinitionWithPredicate[] { SVDParser.ParseSVDFile(Path.Combine(fam.Definition.PrimaryHeaderDir, "nRF51.svd"), "nRF51") }); aMcuDef1[0].MatchPredicate = m => m.Name.StartsWith("nRF51"); var aMcuDef2 = (new MCUDefinitionWithPredicate[] { SVDParser.ParseSVDFile(Path.Combine(fam.Definition.PrimaryHeaderDir, "nRF52.svd"), "nRF52") }); aMcuDef2[0].MatchPredicate = m => m.Name.StartsWith("nRF52"); fam.AttachPeripheralRegisters(aMcuDef1.Concat(aMcuDef2)); var famObj = fam.GenerateFamilyObject(true); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); familyDefinitions.Add(famObj); fam.GenerateLinkerScripts(false); SysVarEntry defaultConfigFolder51 = new SysVarEntry { Key = "com.sysprogs.nordic.default_config_suffix", Value = "pca10040/s132" }; // s132_pca10036" }; SysVarEntry defaultConfigFolder52 = new SysVarEntry { Key = "com.sysprogs.nordic.default_config_suffix", Value = "pca10028/s130" }; // s130_pca10028" }; foreach (var mcu in fam.MCUs) { var mcuDef = mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters); var compatibleSoftdevs = new PropertyEntry.Enumerated.Suggestion[] { new PropertyEntry.Enumerated.Suggestion { InternalValue = "nosoftdev", UserFriendlyName = "None" } }.Concat(bspBuilder.SoftDevices.Where(sd => sd.IsCompatible(mcu.Name)).Select(s => new PropertyEntry.Enumerated.Suggestion { InternalValue = s.Name, UserFriendlyName = s.UserFriendlyName })).ToArray(); if (mcuDef.ConfigurableProperties == null) { mcuDef.ConfigurableProperties = new PropertyList { PropertyGroups = new List <PropertyGroup>() } } ; mcuDef.ConfigurableProperties.PropertyGroups.Add(new PropertyGroup { Properties = new List <PropertyEntry> { new PropertyEntry.Enumerated { UniqueID = NordicBSPBuilder.SoftdevicePropertyID, Name = "Softdevice", DefaultEntryIndex = 1, SuggestionList = compatibleSoftdevs, } } }); if (mcu.Name.StartsWith("nRF52")) { var prop = mcuDef.ConfigurableProperties.PropertyGroups[0].Properties.Find(p => p.UniqueID == "com.sysprogs.bspoptions.arm.floatmode") as PropertyEntry.Enumerated; var idx = Array.FindIndex(prop.SuggestionList, p => p.UserFriendlyName == "Hardware"); prop.DefaultEntryIndex = idx; prop.SuggestionList[idx].UserFriendlyName = "Hardware (required when using a softdevice)"; //Otherwise the system_nrf52.c file won't initialize the FPU and the internal initialization of the softdevice will later fail. mcuDef.AdditionalSystemVars = LoadedBSP.Combine(mcuDef.AdditionalSystemVars, new SysVarEntry[] { defaultConfigFolder51 }); } else { mcuDef.AdditionalSystemVars = LoadedBSP.Combine(mcuDef.AdditionalSystemVars, new SysVarEntry[] { defaultConfigFolder52 }); } mcuDefinitions.Add(mcuDef); } if (fam.Definition.ConditionalFlags != null) { condFlags.AddRange(fam.Definition.ConditionalFlags); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in fam.CopySamples(null, new SysVarEntry[] { defaultConfigFolder51 })) { exampleDirs.Add(sample); } // var prioritizer = new SamplePrioritizer(Path.Combine(bspBuilder.Directories.RulesDir, "SamplePriorities.txt")); // exampleDirs.Sort((a, b) => prioritizer.Prioritize(a.RelativePath, b.RelativePath)); } bspBuilder.GenerateSoftdeviceLibraries(); Console.WriteLine("Building BSP archive..."); string strPackageID, strPackageDesc, strPAckVersion; if (usingIoTSDK) { strPackageID = "com.sysprogs.arm.nordic.nrf5x-iot"; strPackageDesc = "Nordic NRF52 IoT"; strPAckVersion = "0.9"; foreach (var mcu in mcuDefinitions) { mcu.UserFriendlyName = mcu.ID + " (IoT)"; } } else { strPackageID = "com.sysprogs.arm.nordic.nrf5x"; strPackageDesc = "Nordic NRF5x Devices"; strPAckVersion = "13.0-alpha"; } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = strPackageID, PackageDescription = strPackageDesc, GNUTargetID = "arm-eabi", GeneratedMakFileName = "nrf5x.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.Where(s => !s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), TestExamples = exampleDirs.Where(s => s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), PackageVersion = strPAckVersion, FileConditions = bspBuilder.MatchedFileConditions.ToArray(), MinimumEngineVersion = "5.0", ConditionalFlags = condFlags.ToArray(), }; bspBuilder.Save(bsp, true); } } }