Beispiel #1
0
        private void GenerateSpice(DesignEntity de, Tonka.SPICEModel spiceObj)
        {
            var ancestor = de.Parent;

            while (ancestor != null)
            {
                if (ComponentNodeMap.ContainsKey(ancestor))
                {
                    return;
                }
                ancestor = ancestor.Parent;
            }

            var nodes     = circuit_obj.nodes;
            var spiceType = GetSpiceType(de);

            if (Grounds.Any(spiceType.Item2.Contains))  // is a ground node skip it
            {
                return;
            }

            var node = new Spice.Node();

            node.name      = de.Name;
            node.type      = spiceType.Item1;
            node.classType = spiceType.Item2;

            // error checking
            if (node.type == (char)0)
            {
                CodeGenerator.Logger.WriteWarning("Missing Spice Type for component {0}", de.Name);
            }
            if (node.type == 'X' && node.classType == "")
            {
                CodeGenerator.Logger.WriteWarning("Missing Subcircuit Type for component {0}, should be X.<subckt-type>", de.Name);
            }

            if (node.classType != "" && !circuit_obj.subcircuits.ContainsKey(node.classType))
            {
                circuit_obj.subcircuits.Add(node.classType, de.SpiceLib);
            }

            foreach (var par in spiceObj.Children.SPICEModelParameterCollection)
            {
                if (node.parameters.ContainsKey(par.Name))
                {
                    CodeGenerator.Logger.WriteError("Duplicate Parameter: {0}: in Component <a href=\"mga:{2}\">{1}</a>",
                                                    par.Name,
                                                    de.Name,
                                                    de.Impl.ID);
                }
                else
                {
                    node.parameters.Add(par.Name, FindTestBenchParameter(par) ?? par.Attributes.Value.Replace("$", "$$"));
                }
            }

            nodes.Add(node);
            ComponentNodeMap[de] = node;
        }
Beispiel #2
0
        public override void visit(Component obj)
        {
            DesignEntity de = obj;

            CodeGenerator.Logger.WriteDebug(
                "SpiceVisitor::visit({0})",
                obj.Name);

            // create a signal container for this component
            var siginfo_obj = new Spice.SignalContainer()
            {
                name  = de.Name,
                gmeid = de.Impl.ID
            };

            ObjectSiginfoMap.Add(de, siginfo_obj);
            var siginfo_parent = this.siginfo_obj;

            if (de.Parent != null && ObjectSiginfoMap.ContainsKey(de.Parent))
            {
                siginfo_parent = ObjectSiginfoMap[de.Parent] as Spice.SignalContainer;
            }
            siginfo_parent.signals.Add(siginfo_obj);

            var spiceObjs = obj.Impl.Children.SPICEModelCollection;
            var spiceObj  = CyPhyBuildVisitor.GetSpiceModel(obj, spiceObjs);

            if (spiceObj == null) // no spice model in this component, skip from generating
            {
                return;
            }
            GenerateSpice(de, spiceObj);
        }
Beispiel #3
0
        public int CompareTo(DesignEntity other)
        {
            int name = this.Name.CompareTo(other.Name);

            if (name == 0)
            {
                return(this.Impl.ID.CompareTo(other.Impl.ID));
            }
            return(name);
        }
Beispiel #4
0
        private Tuple <char, string> GetSpiceType(DesignEntity obj)
        {
            var spiceObjs = (obj.Impl is Tonka.ComponentType) ?
                            (obj.Impl as Tonka.ComponentType).Children.SPICEModelCollection :
                            (obj.Impl as Tonka.ComponentAssembly).Children.SPICEModelCollection;

            Tonka.SPICEModel spiceObj = CyPhyBuildVisitor.GetSpiceModel(obj, spiceObjs);

            string[] spiceType = (spiceObj != null) ? spiceObj.Attributes.Class.Split(new char[] { ':', ' ', '.' }) : null;

            char   baseType  = (spiceType != null && spiceType.Count() > 0 && spiceType[0].Length > 0) ? spiceType[0][0] : (char)0;
            string classType = (spiceType != null && spiceType.Count() > 1) ? spiceType[1] : "";

            var tuple = new Tuple <char, string>(baseType, classType);

            return(tuple);
        }
Beispiel #5
0
        public static Tonka.SPICEModel GetSpiceModel(DesignEntity de, IEnumerable <Tonka.SPICEModel> spiceModels)
        {
            var spiceModelsList = spiceModels.ToList();

            if (spiceModelsList.Count == 0)
            {
                return(null);
            }
            if (de.SystemUnderTest.selectedSpiceModels != null)
            {
                return(spiceModels.Where(sm => de.SystemUnderTest.selectedSpiceModels.Contains(sm.Impl)).FirstOrDefault());
            }
            else
            {
                // TODO if (spiceModelsList.Count > 1) warn SpiceModel was picked arbitrarily
                return(spiceModels.OrderBy(x => x.Name + "_" + x.Guid.ToString("D")).FirstOrDefault());
            }
        }
Beispiel #6
0
        private void GetSpiceModel(Tonka.SPICEModel spiceModel, DesignEntity de, bool isTestComponent)
        {
            String spiceClass = spiceModel.Attributes.Class;

            if (String.IsNullOrWhiteSpace(spiceClass))
            {
                Logger.WriteWarning("Component <a href=\"mga:{0}\">{1}</a> has a SPICE model, but its class is not specified",
                                    Traceability.GetID(de.Impl.Impl),
                                    de.Impl.Name);
            }

            // If this SPICE class requires a model file to be provided, try to find it and load it.
            if (SpiceClassRequiresModel(spiceClass))
            {
                try
                {
                    String spiceAbsPath;
                    if (spiceModel.TryGetResourcePath(out spiceAbsPath, ComponentLibraryManager.PathConvention.REL_TO_PROJ_ROOT))
                    {
                        spiceAbsPath = Path.Combine(this.ProjectDirectory, spiceAbsPath);
                        de.SpiceLib  = File.ReadAllText(spiceAbsPath);
                    }
                    else
                    {
                        throw new ApplicationException("SPICE model has no associated Resource");
                    }
                }
                catch (Exception e)
                {
                    de.SpiceLib = "";
                    if (!isTestComponent)
                    {
                        Logger.WriteError("Error Loading Spice Library of <a href=\"mga:{0}\">{1}</a>: {2}",
                                          Traceability.GetID(de.Impl.Impl), de.Impl.Name, e.Message);
                    }
                }
            }
        }
        /// <summary>
        /// Avoid doing this each frame, it looks up the name via doing a GetDataBlob and an List.IndexOf()
        /// </summary>
        public string GetName()
        {
            string designName = DesignEntity.GetDataBlob <NameDB>().DefaultName;

            return(designName + " " + ParentInstances.GetComponentsBySpecificDesign(DesignEntity.Guid).IndexOf(this));
        }