private static IEnumerable <MCUDefinitionWithPredicate> ParsePeripheralRegisters(string dir, MCUFamilyBuilder fam) { var mainClassifier = fam.Definition.Subfamilies.First(f => f.IsPrimary); List <Task <MCUDefinitionWithPredicate> > tasks = new List <Task <MCUDefinitionWithPredicate> >(); Console.Write("Parsing {0} registers in background threads", fam.Definition.Name); RegisterParserErrors errors = new RegisterParserErrors(); foreach (var fn in Directory.GetFiles(dir, "*.h")) { string subfamily = Path.GetFileNameWithoutExtension(fn); if (subfamily.Length != 11 && subfamily.Length != 12) { continue; } /*if (subfamily != "stm32f301x8") * continue;*/ Func <MCUDefinitionWithPredicate> func = () => { RegisterParserConfiguration cfg = XmlTools.LoadObject <RegisterParserConfiguration>(fam.BSP.Directories.RulesDir + @"\PeripheralRegisters.xml"); var r = new MCUDefinitionWithPredicate { MCUName = subfamily, RegisterSets = PeripheralRegisterGenerator.GenerateFamilyPeripheralRegisters(fn, cfg, errors, fam.MCUs[0].Core), MatchPredicate = m => StringComparer.InvariantCultureIgnoreCase.Compare(mainClassifier.TryMatchMCUName(m.Name), subfamily) == 0, }; Console.Write("."); return(r); }; // func(); tasks.Add(Task.Run(func)); } Task.WaitAll(tasks.ToArray()); var errorCnt = errors.ErrorCount; if (errorCnt != 0) { // throw new Exception("Found " + errorCnt + " errors while parsing headers"); for (int i = 0; i < errors.ErrorCount; i++) { Console.WriteLine("\n er " + i + " - " + errors.DetalErrors(i)); } } Console.WriteLine("done"); return(from r in tasks select r.Result); }
private static IEnumerable <MCUDefinitionWithPredicate> ParsePeripheralRegisters(string dir, MCUFamilyBuilder fam) { List <MCUDefinitionWithPredicate> RegistersPeriphs = new List <MCUDefinitionWithPredicate>(); Dictionary <string, HardwareRegisterSet[]> periphs = PeripheralRegisterGenerator.GenerateFamilyPeripheralRegisters(dir); foreach (var subfamily in periphs.Keys) { MCUDefinitionWithPredicate mcu_def = new MCUDefinitionWithPredicate { MCUName = subfamily, RegisterSets = periphs[subfamily], MatchPredicate = m => GytTypMcuFile(subfamily, m.Name), }; RegistersPeriphs.Add(mcu_def); } return(RegistersPeriphs); }