1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist - gEDA Netlist
3 ;;; Backend for cascade (http://rfcascade.sourceforge.net)
4 ;;; Copyright (C) 2003-2010 Dan McMahill
6 ;;; This program is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 2 of the License, or
9 ;;; (at your option) any later version.
11 ;;; This program is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with this program; if not, write to the Free Software
18 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 ;; Locate and print out the global defaults if the element exists
22 (define cascade:write-defaults-top
24 (if (not (null? pkgs))
25 (let ( (pkg (car pkgs)) )
26 (if (string=? (get-device pkg) "cascade-defaults-top")
28 (display "# Initial global defaults\n" port)
29 (display "defaults " port)
31 (let ((val (gnetlist:get-package-attribute pkg attrib)))
32 (if (not (string=? val "unknown"))
33 (display (string-append attrib "=" val " ") port)
37 (list "rin" "RIN" "rout" "ROUT" "rho" "RHO")
42 (cascade:write-defaults-top port (cdr pkgs))
49 ;; Locate and print out the "source" line and return the refdes of
50 ;; the first element in the cascade
51 (define cascade:write-source
53 (if (not (null? pkgs))
54 (let ( (package (car pkgs) )
57 (if (string=? (get-device package) "cascade-source")
59 (set! sourcenet (gnetlist:get-nets package "1"))
60 (display "source " port)
62 (let ((val (gnetlist:get-package-attribute package attrib)))
63 (if (not (string=? val "unknown"))
64 (display (string-append attrib "=" val " ") port)
68 (list "c" "C" "cn0" "CN0" "cn" "CN" "bw" "BW")
72 (if (string=? (caadr sourcenet) package)
77 (cascade:write-source port (cdr pkgs) )
80 ;; the list of packages is now empty
86 ;; recursively follow the cascade and print out each element as its
88 (define cascade:follow-cascade
92 (let ( (outnet (gnetlist:get-nets pkg "2"))
95 ;; Is this a "defaults" element or a normal element?
96 ;; If its a defaults element, then print "defaults"
97 ;; instead of the reference designator because thats
98 ;; a keyword for cascade.
99 (if (string=? (get-device pkg) "cascade-defaults")
100 (display "defaults " port)
101 (display (string-append pkg " ") port)
104 ;; spit out all the relevant attributes for element or
106 (map (lambda (attrib)
107 (let ((val (gnetlist:get-package-attribute pkg attrib)))
108 (if (not (string=? val "unknown"))
109 (display (string-append attrib "=" val " ") port)
113 (list "g" "G" "gp" "GP" "gv" "GV" "nf" "NF" "iip3"
114 "IIP3" "r" "R" "rin" "RIN" "rout" "ROUT"
119 ;;(display "cascade:follow-cascade -- outnet = ")
122 (if (>= (length outnet) 3)
123 (if (string=? (caadr outnet) pkg)
124 (cascade:follow-cascade port(caaddr outnet))
125 (cascade:follow-cascade port (caadr outnet))
134 ;; The top level netlister for cascade
138 (display "---------------------------------\n")
139 (display "gEDA/gnetlist Cascade Backend\n")
141 (display "---------------------------------\n\n")
143 (display (string-append "Writing to output file \"" filename
145 (let ((port (open-output-file filename))
150 (display "# Cascade (http://rfcascade.sourceforge.net)\n"
152 (display "# Created with gEDA/gnetlist\n\n" port)
154 ;; Write out an initial "defaults" line if it exists
155 (cascade:write-defaults-top port packages)
157 ;; Write out the "source" line and keep track of what its
158 ;; connected to. If we couldn't find the source, then
160 (display "# Source definition\n" port)
161 (set! first_block (cascade:write-source port packages))
162 (if (null? first_block)
163 (error "You must include a source element in your schematic!")
166 ;; write the components
167 (display "\n# Cascaded system\n" port)
168 (cascade:follow-cascade port first_block)
172 (display "# End of netlist created by gEDA/gnetlist\n\n" port)
175 (close-output-port port)