Add TSX-3225 xtal footprint
[hw/altusmetrum] / scheme / gnet-tEDAx.scm
1 ;;; tEDAx plug-in for lepton-netlist
2 ;;; Copyright (C) 2018 Bdale Garbee
3 ;;;
4 ;;; This program is free software; you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation; either version 2 of the License, or
7 ;;; (at your option) any later version.
8 ;;;
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ;;; GNU General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program; if not, write to the Free Software
16 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 ;;; MA 02111-1301 USA.
18
19 ;; --------------------------------------------------------------------------
20 ;; The tEDAx format is documented at http://repo.hu/projects/tedax/
21 ;; --------------------------------------------------------------------------
22
23 (use-modules (gnetlist schematic))
24
25 ;;
26 ;; return device attribute
27 ;;
28 (define (tEDAx:get-device package)
29   (gnetlist:get-package-attribute package "device"))
30
31 ;;
32 ;; return footprint attribute (UNKNOWN if not defined)
33 ;;
34 (define (tEDAx:get-pattern package)
35   (let ((pattern (gnetlist:get-package-attribute package "footprint")))
36     (if (unknown? pattern) "UNKNOWN" pattern)))
37
38 ;;
39 ;; returns value attribute (empty if not defined)
40 ;;
41 (define (tEDAx:get-value package)
42   (let ((value (gnetlist:get-package-attribute package "value")))
43     (if (unknown? value) "" value)))
44
45 ;;
46 ;; emit header
47 ;;
48 (define (tEDAx:header)
49   (format #t "tEDAx v1\nbegin netlist v1 netlist\n\n"))
50
51 ;;
52 ;; emit trailer
53 ;;
54 (define (tEDAx:trailer)
55   (format #t "end netlist\n"))
56
57 ;;
58 ;; emit component related lines
59 ;;
60 (define (tEDAx:components ls)
61   (for-each
62    (lambda (package)
63      (format #t "\tfootprint ~A ~A\n\tdevice ~A ~A\n\tvalue ~A ~A\n\n"
64        package
65        (tEDAx:get-pattern package)
66        package
67        (tEDAx:get-device package)
68        package
69        (tEDAx:get-value package)))
70    ls))
71
72 ;;
73 ;; emit network related lines for current net
74 ;;
75 (define (tEDAx:display-connections netname nets)
76   (define package car)
77   (define pinnumber cdr)
78   (string-join
79    (map
80     (lambda (net)
81       (format #f "\tconn ~A ~A ~A\n"
82         netname
83         (package net)
84         (pinnumber net)))
85     nets)
86    ""))
87
88 ;;
89 ;; iterate over all nets
90 ;;
91 (define (tEDAx:nets netnames)
92   (for-each
93    (lambda (netname)
94      (format #t "~A\n"
95        (tEDAx:display-connections netname (get-all-connections netname))))
96    netnames))
97
98 ;;;
99 ;;; emit netlist in tEDAx interchange format
100 ;;;
101 (define (tEDAx output-filename)
102   (let ((nets (schematic-nets toplevel-schematic))
103         (packages (schematic-packages toplevel-schematic)))
104     (tEDAx:header)
105     (tEDAx:components packages)
106     (tEDAx:nets nets)
107     (tEDAx:trailer)))
108
109 ;; --------------------------------------------------------------------------