1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist - gEDA Netlist
3 ;;; Copyright (C) 1998-2010 Ales Hvezda
4 ;;; Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
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.
20 (define vipec:analysis-templates
25 (list "value" "R=" #t)))
28 (define vipec:component-templates
31 (cons "RESISTOR" "RES")
33 (list "value" "R=" #t "use value attrib for resistance")))
35 (cons "INDUCTOR" "IND")
37 (list "value" "L=" #t "use value attrib for inductance")
40 (cons "CAPACITOR" "CAP")
42 (list "value" "C=" #t "use value attrib for capacitance")))
47 (list "length" "E=" #t "length attrib for length")
48 (list "F" "F=" #t "F attrib for frequency")))
57 (cons "SPARAMBLOCK" "BLOCK")
59 (list "filename" "" #t "filename attrib for sparams")))
62 (define vipec:get-template
63 (lambda (templates device)
64 (if (not (null? templates))
65 (if (string=? device (car (car (car templates))))
67 (vipec:get-template (cdr templates) device))
69 (display "Template not found ")
72 (cons (cons device "error") '())))))
74 (define (vipec:write-net-name-of-node uref number-of-pin netnumbers port)
77 (let ((pin-name (number->string i)))
78 (display (get-net-number (car (gnetlist:get-nets uref (gnetlist:get-attribute-by-pinseq uref pin-name "pinnumber"))) netnumbers) port)
79 (write-char #\space port))))
81 (define vipec:write-attribs
82 (lambda (package attribs port term)
83 (if (not (null? attribs))
84 (let ((attrib (car attribs))
85 (value (gnetlist:get-package-attribute package (car(car attribs)))))
86 (if (not (string=? value "unknown"))
88 (display (cadr attrib) port)
91 (if (and (caddr attrib)(not (null? (cdddr attrib))))
93 (display (cadr attrib) port)
94 (display (cadddr attrib) port)
95 (display term port))))
96 (vipec:write-attribs package (cdr attribs) port term)))))
98 (define vipec:write-gen-component
99 (lambda (package port netnumbers)
100 (let ((template (vipec:get-template vipec:component-templates (get-device package))))
102 (display (cdr (car template)) port)
104 (vipec:write-net-name-of-node package
105 (length (gnetlist:get-pins package)) netnumbers port)
106 (vipec:write-attribs package (cdr template) port "\t")
107 (display (string-append "\t% " package) port)
110 (define vipec:component-writing
111 (lambda (port ls netnumbers)
113 (let ((package (car ls))
114 (device (get-device (car ls))))
116 ((string=? device "VIPEC") #t)
117 ((string=? device "SMITH") #t)
118 ((string=? device "GRID") #t)
119 (else (vipec:write-gen-component package port netnumbers)))
120 (vipec:component-writing port (cdr ls) netnumbers)))))
122 (define vipec:misc-components
123 (lambda (netnumbers port)
124 ;; (display "\tRES\t0 " port)
125 ;; (display (get-net-number "GND" netnumbers) port)
126 ;; (display " R=0.00001\t% Assign ground net\n" port)
127 (display "\tDEF2P\t" port)
128 (display (get-net-number "PORT1" netnumbers) port)
130 (display (get-net-number "PORT2" netnumbers) port)
131 (display "\n\tTERM\t50 50\n" port)))
135 (display "% ViPEC RF Netlister\n" port)
136 (display "% Written by Matthew Ettus\n" port)
137 (display "% Based on code by Bas Gieltjes\n" port)))
139 (define vipec:analysis-block
140 (lambda (packages port)
141 (if (not (null? packages))
143 (if (string=? (get-device (car packages)) "VIPEC")
144 (let ((template (vipec:get-template vipec:analysis-templates "VIPEC")))
145 (vipec:write-attribs (car packages) (cdr template) port "\n")
147 (vipec:analysis-block (cdr packages) port)))))
150 (lambda (output-filename)
151 (let ((port (open-output-file output-filename))
152 (netnumbers (number-nets all-unique-nets 1)))
154 (display "CKT\n" port)
155 (vipec:component-writing port packages netnumbers)
156 (vipec:misc-components netnumbers port)
158 (vipec:analysis-block packages port)
159 (close-output-port port))))