Esempio n. 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;
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
                    }
                }
            }
        }
Esempio n. 4
0
        public override void visit(Component obj)
        {
            Logger.WriteDebug("CyPhyBuildVisitor::visit({0})", obj.Impl.Path);

            var component = obj.Impl;
            var ca        = obj.Parent;

            var  compBase        = obj.Impl.ArcheType;
            bool isTestComponent = component is Tonka.TestComponent;

            Tonka.SchematicModel schematicModel = null;

            //////////// EDA /////////////
            if (mode == CodeGenerator.Mode.EDA)
            {
                var edaModel = component.Children.EDAModelCollection.FirstOrDefault();

                if (edaModel == null)
                {
                    Logger.WriteInfo("Skipping Component <a href=\"mga:{0}\">{1}</a> (no EDA model)",
                                     Traceability.GetID(obj.Impl.Impl), obj.Impl.Name);
                    return;
                }
                schematicModel = edaModel;

                // try and load the resource

                bool   hasResource = false;
                String schAbsPath  = "";
                try
                {
                    hasResource = edaModel.TryGetResourcePath(out schAbsPath, ComponentLibraryManager.PathConvention.REL_TO_PROJ_ROOT);
                    schAbsPath  = Path.Combine(this.ProjectDirectory, schAbsPath);
                }
                catch (NotSupportedException ex)
                {
                    // test component will not have / should not have resource
                    hasResource = false;
                }
                if (!hasResource && !isTestComponent)
                {
                    Logger.WriteError("Couldn't determine path of schematic file for component <a href=\"mga:{0}\">{1}</a>. It may not be linked to a Resource object.",
                                      Traceability.GetID(obj.Impl.Impl), obj.Impl.Name);
                    return;
                }

                bool failedToLoadSchematicLib = false;
                try
                {
                    obj.SchematicLib = Eagle.eagle.LoadFromFile(schAbsPath);
                }
                catch (Exception e)
                {
                    failedToLoadSchematicLib = true;
                    if (!isTestComponent) // test components don't need to have schematic
                    {
                        // Try to get the ID of the pre-Elaborated object so that the error message
                        // will be more meaningful.
                        String compOriginalID = null;
                        Logger.WriteError("Error Loading Schematic Library of <a href=\"mga:{0}\">{1}</a>: {2}",
                                          Traceability.GetID(obj.Impl.Impl), obj.Impl.Name, e.Message);
                        throw;
                    }
                }

                if (failedToLoadSchematicLib)
                {
                    obj.SchematicLib = new Eagle.eagle();
                }

                foreach (var param in edaModel.Children.EDAModelParameterCollection)
                {
                    var val    = param.Attributes.Value;
                    var valSrc = param.SrcConnections
                                 .EDAModelParameterMapCollection
                                 .Select(p => p.SrcEnd)
                                 .FirstOrDefault();

                    if (valSrc != null)
                    {
                        var valProp = valSrc as Tonka.Property;
                        if (valProp != null)
                        {
                            val = valProp.Attributes.Value;
                        }
                        var valParam = valSrc as Tonka.Parameter;
                        if (valParam != null)
                        {
                            val = valParam.Attributes.Value;
                        }
                    }

                    var param_obj = new Parameter()
                    {
                        Name  = param.Name,
                        Value = val
                    };
                    obj.Parameters.Add(param_obj);
                }
            }
            ///////////// SPICE //////////////
            else if (mode == CodeGenerator.Mode.SPICE || mode == CodeGenerator.Mode.SPICE_SI)
            {
                var spiceModels             = obj.Impl.Children.SPICEModelCollection;
                Tonka.SPICEModel spiceModel = GetSpiceModel(obj, spiceModels);

                if (spiceModel == null)
                {
                    if (spiceModels.Count() == 0)
                    {
                        Logger.WriteInfo("Skipping Component <a href=\"mga:{0}\">{1}</a> (no SPICE model)",
                                         Traceability.GetID(obj.Impl.Impl), obj.Impl.Name);
                    }
                    return;
                }
                schematicModel = spiceModel;
                GetSpiceModel(spiceModel, obj, isTestComponent);

                foreach (var param in spiceModel.Children.SPICEModelParameterCollection)
                {
                    var val    = param.Attributes.Value;
                    var valSrc = param.SrcConnections
                                 .SPICEModelParameterMapCollection
                                 .Select(p => p.SrcEnd)
                                 .FirstOrDefault();

                    if (valSrc != null)
                    {
                        var valProp = valSrc as Tonka.Property;
                        if (valProp != null)
                        {
                            val = valProp.Attributes.Value;
                        }
                        var valParam = valSrc as Tonka.Parameter;
                        if (valParam != null)
                        {
                            val = valParam.Attributes.Value;
                        }
                    }

                    var param_obj = new Parameter()
                    {
                        Name  = param.Name,
                        Value = val
                    };
                    obj.Parameters.Add(param_obj);
                }
            }
            else
            {
                throw new NotSupportedException(String.Format("Mode {0} is not supported by visit(Component)", mode.ToString()));
            }

            // Both EDA and SPICE models have these ports in common.
            if (schematicModel != null)
            {
                foreach (var port in schematicModel.Children.SchematicModelPortCollection)
                {
                    var port_obj = new Port(port)
                    {
                        Parent = obj,
                    };
                    obj.Ports.Add(port_obj);
                    CyPhyBuildVisitor.Ports.Add(port.ID, port_obj);
                    Logger.WriteInfo("Mapping Port <a href=\"mga:{0}\">{1}</a> with ID {2}", Traceability.GetID(port.Impl), port.Name, port.ID);
                }
            }
        }
Esempio n. 5
0
        public override void visit(ComponentAssembly obj)
        {
            Logger.WriteDebug("CyPhyBuildVisitor::visit({0})", obj.Impl.Path);

            var ca = obj.Impl;

            if (mode == CodeGenerator.Mode.SPICE || mode == CodeGenerator.Mode.SPICE_SI)
            {
                var spiceModels             = obj.Impl.Children.SPICEModelCollection;
                Tonka.SPICEModel spiceModel = GetSpiceModel(obj, spiceModels);

                if (spiceModel != null)
                {
                    GetSpiceModel(spiceModel, obj, isTestComponent: false);
                    foreach (var port in spiceModel.Children.SchematicModelPortCollection)
                    {
                        var port_obj = new Port(port)
                        {
                            Parent = obj,
                        };
                        obj.Ports.Add(port_obj);
                        CyPhyBuildVisitor.Ports.Add(port.ID, port_obj);
                        Logger.WriteInfo("Mapping Port <a href=\"mga:{0}\">{1}</a> with ID {2}", Traceability.GetID(port.Impl), port.Name, port.ID);
                    }
                }
            }


            // ------- ComponentAssemblies -------
            foreach (var innerComponentAssembly in ca.Children.ComponentAssemblyCollection)
            {
                var innerComponentAssembly_obj = new ComponentAssembly(innerComponentAssembly)
                {
                    Parent          = obj,
                    SystemUnderTest = this.systemUnderTest
                };
                obj.ComponentAssemblyInstances.Add(innerComponentAssembly_obj);
            }

            // ------- Components -------
            foreach (var component in ca.Children.ComponentCollection)
            {
                var component_obj = new Component(component)
                {
                    Parent          = obj,
                    SystemUnderTest = this.systemUnderTest
                };
                obj.ComponentInstances.Add(component_obj);
                CyPhyBuildVisitor.Components.Add(component.ID, component_obj);   // Add to global component list, component type ID-s?
                var componentInstanceGUID = Layout.LayoutGenerator.GetComponentID(component);
                //GME.CSharp.GMEConsole console = GME.CSharp.GMEConsole.CreateFromProject(component.Impl.Project);
                //console.Info.WriteLine(componentInstanceGUID);
                try
                {
                    CyPhyBuildVisitor.ComponentInstanceGUIDs.Add(componentInstanceGUID, component_obj);   // component instance guid-s?
                }
                catch (ArgumentException e)
                {
                    throw new ArgumentException(e.Message + " " + componentInstanceGUID);
                }
            }
        }