Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / gnetlist / scheme / gnet-futurenet2.scm
blob4fcca150b56a880b9cc83b9558a0acc9772f983a
1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist - gEDA Netlist
3 ;;; FutureNet2 backend
4 ;;; Copyright (C) 2003, 2005-2010 Dan McMahill
5 ;;;
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.
10 ;;;
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.
15 ;;;
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 ;;; Notes about futurenet2 (.NV2) format pinlists
22 ;;;  
23 ;;;  - Case does not seem to be preserved so to avoid issues,
24 ;;;    simply output the netnames in all caps.
25 ;;;
26 ;;;  - Netname length is 8 characters max.  +,-, and _ are allowed
27 ;;;
28 ;;;  - How are DATA,3 and DATA,4 used?  In one example, DATA,4 is 
29 ;;;    not used.  In the other DATA,3 and DATA,4 are identical and
30 ;;;    appear to be set to the value (10.0k for example) of the part.
31 ;;;
32 ;;;    From Ferenc Marton (martonf at datapress dot hu):
33 ;;;
34 ;;;    These get combined in Ranger2 to produce the device
35 ;;;    description with a "," separating the two entries.
36 ;;;    DATA,3 is the "device name", max of 5 characters
37 ;;;    DATA,4 is the "device value", max of 13 characters.
38 ;;;    We could put the footprint into DATA,4
39 ;;;
40 ;;;  - In the "PIN" and "SIG" lines, what are the various fields really
41 ;;;    doing?
42 ;;;
43 ;;;    It seems that for a PIN line, the format is:
44 ;;;
45 ;;;    PIN,,<netname>,1-1,5,<net attribute number>,<pinnumber>
46 ;;;
47 ;;;    What are the "1-1" and the "5"?  On the <net attribute
48 ;;;    number> I've seen "23", "25", and "100".  Maybe these
49 ;;;    indicate signal vs power or some sort of routing preference?
50 ;;;
51 ;;;    For a SIG line, the format seems to be:
52 ;;;
53 ;;;    SIG,<netname>,1-1,5,<netname>
54 ;;;
55 ;;;    What exactly are "1-1" and "5"?  I think maybe the "1-1" part
56 ;;;    has something to do with sheet number in a multipage schematic.
57 ;;;
60 ;; This procedure takes a net name as determined by gnetlist and
61 ;; modifies it to be a valid FutureNet2 net name.
63 (define futurenet2:map-net-names
64   (lambda (net-name)
65     (let ((rx (make-regexp "^unnamed_net"))
66           (net-alias net-name)
67           )
68       ;; XXX we should use a dynamic regexp based on the current value
69       ;; for the unnamed net base string.
71       ;; Remove "unnamed_net" and replace with "NET"
72       (if (regexp-exec rx net-name) 
73             (set! net-alias (string-append "NET" (substring net-name 11)))
74             )
75       
76       ;; Truncate to 8 characters
77       (if (> (string-length net-alias) 8)
78           (set! net-alias (substring net-alias 0 8))
79           )
80       ;; Convert to all upper case
81       (string-upcase net-alias)
82       )
83     )
84   )
86 ;; This procedure takes a refdes as determined by gnetlist and
87 ;; modifies it to be a valid FutureNet2 refdes.
89 (define futurenet2:map-refdes
90   (lambda (refdes)
91     (let ((refdes-alias refdes)
92           )
94       ;; XXX do we need to truncate to 8 characters
95       ;; like with net names?
96 ;;      (if (> (string-length refdes-alias) 8)
97 ;;        (set! refdes-alias (substring refdes-alias 0 8))
98 ;;        )
100       ;; Convert to all upper case
101       (string-upcase refdes-alias)
102       )
103     )
104   )
106 ;; write out the pins for a particular component
107 (define futurenet2:component_pins
108   (lambda (port package pins)
109     (if (and (not (null? package)) (not (null? pins)))
110         (begin
111           (let (
112                 (pin (car pins)))
113             ;;  PIN,,NetName,1-1,5,20/23,pinnum
114             (display "PIN,," port)
116             (display 
117              (gnetlist:alias-net (car (gnetlist:get-nets package pin)))
118              port)
119             
120             ;; XXX I've seen 20, 23, and 100 in the position where the
121             ;; "23" is here.  Seems to be a property like signal vs
122             ;; power net.  Not sure how to support that.
123             (display ",1-1,5,23," port)
125             (display 
126              (gnetlist:get-attribute-by-pinnumber package pin "pinnumber")
127              port)
128             (newline port)
129             )
130           (futurenet2:component_pins port package (cdr pins))
131           )
132         )
133     )
134   )
136             
137 ;; write out the components
138 (define futurenet2:components
139    (lambda (port packages symcnt)
140       (if (not (null? packages))
141          (begin
142             (let ((pattern (gnetlist:get-package-attribute (car packages) 
143                                                            "pattern"))
144             ;; The above pattern should stay as "pattern" and not "footprint"
145                   (package (car packages)))
146               (display "(SYM," port)
147               (display symcnt port)
149               ;; write the reference designator
150               (display "\nDATA,2," port)
151               (display (gnetlist:alias-refdes package) port)
152               
153               ;; If there is a "value" attribute, output that.
154               ;; Otherwise output the "device" attribute (the symbol name).
155               (display "\nDATA,3," port)
156               (let 
157                   ((val (gnetlist:get-package-attribute package
158                                                         "value")) )
159                 (if (string=? val "unknown") 
160                     (set! val (gnetlist:get-package-attribute package "device") )
161                     )
162                 (display  val port)
163                 )
164               (display "\n" port)
166               ;; write the footprint
167               (display "DATA,4," port)
168               (display (gnetlist:get-package-attribute package
169                                                        "footprint")
170                        port)
171               (display "\n" port)
172               
173               ;; write the pins
174               (futurenet2:component_pins port package
175                                          (gnetlist:get-pins package))
177               ;; close the part
178               (display ")\n" port)
179               
180               )
181             (futurenet2:components port (cdr packages) (+ symcnt 1))
182             )
183          )
184       )
185    )
187 ;; write out the nets
188 (define futurenet2:write-net
189    (lambda (port netnames)
190       (if (not (null? netnames))
191          (let (
192                (netname (car netnames))
193                (alias (gnetlist:alias-net (car netnames)))
194                )
195            (display "SIG," port)
196            (display alias port)
197            (display ",1-1,5," port)
198            (display alias port)
199            (newline port)
200            (futurenet2:write-net port (cdr netnames))
201            )
202          )
203       )
204    )
206 ;; The top level netlister for futurenet2
207 (define futurenet2 
208    (lambda (filename)
209      (newline)
210      (display "---------------------------------\n")
211      (display "gEDA/gnetlist FutureNet2 Backend\n")
212      (display "This backend is EXPERIMENTAL\n")
213      (display "Use at your own risk!\n")
214      (display "\n")
215      (display "You may need to run the output netlist\n")
216      (display "through unix2dos before importing to\n")
217      (display "Ranger2 or other windows based layout tools\n")
218      (display "---------------------------------\n\n")
220       (let ((port (open-output-file filename))
221             (all-nets (gnetlist:get-all-unique-nets "dummy"))
222             )
223         
224         ;; initialize the net-name aliasing
225         (gnetlist:build-net-aliases futurenet2:map-net-names all-unique-nets)
227         ;; initialize the refdes aliasing
228         (gnetlist:build-refdes-aliases futurenet2:map-refdes packages)
230         ;; write the header
231         (display "PINLIST,2\n" port)
232         (display "(DRAWING,GEDA.PIN,1-1\n" port)
233         
234         ;; write the components
235         (futurenet2:components port packages 1)
236         (display ")\n" port)
237         
238         ;; write the nets
239         (futurenet2:write-net port all-nets)
240         
241         ;; terminating ")"
242         (display ")\n" port)
243         
244         ;; close netlist
245         (close-output-port port)
246         )
247       )
248    )