chiark / gitweb /
2ed595c7a17af1fdd0789595da03b307dbf9c44b
[trains.git] / pcb / generate-netspec.pl
1 #!/usr/bin/perl
2 # -*- fundamental -*-
3
4 use IO::Handle;
5
6 die unless @ARGV==1;
7 $ARGV[0] =~ m,\b(reversers|detectors)(?:\.net-spec)?$, or die;
8 $$1= 1;
9
10 @indiv= qw(
11                 icsp_pcq
12                 l_gnd
13                 led_red
14                 led_green
15         );
16
17 if ($reversers) {
18         push @indiv, qw(
19                 cdu_enable
20                 booster_retry
21                 booster_cutout
22                 booster_flag
23                 booster_dirn
24                 booster_pwm
25                 spare0
26                 spare1
27                 spare2
28                 rs232_rxin
29                 rs232_txout
30                 rs232_fcin
31                 rs232_fcout
32                 );
33         print "INDIV1 26 @indiv\n"; # 25-way D
34         %val = qw(
35                 q       5
36                 p       17
37                 x       qmid=
38                 o       8
39                 );
40 } else {
41         push @indiv, qw(
42                 spare0
43                 analogue
44                 rs232_rxin
45                 rs232_txout
46                 pwmout
47                 extint0
48                 extint1
49                 pt0..10
50                 );
51         %val = qw(
52                 q       20
53                 p       9
54                 x       q=
55                 o       4
56                 );
57 }
58
59 print "INDIV0 25 :1%13/2 @indiv\n"; # 26-way ribbon
60
61 $doing= 1;
62
63 while (<DATA>) {
64         if (m/^\^\=(reversers|detectors)\:\s*$/) {
65                 $doing= $$1;
66                 next;
67         }
68         next unless $doing;
69         s/\^(\w)/ die unless exists $val{$1}; $val{$1}; /ge;
70         print;
71 }
72
73 die $! if STDOUT->error;
74
75 __DATA__
76
77 l_gnd   Power
78 l_vcc   Power
79 rly_gnd Power
80 rly_v12 Power
81
82 !PIC-DEFINE 40
83                 1 mclr
84                 2 RA0..5 RE0..2
85                 11 l_vcc l_gnd clock
86                 14 RA6 RC0..3 RD0 RD1
87                 21 RD2 RD3 RC4..7 RD4..7
88                 31 l_gnd l_vcc
89                 33 RB0..7
90
91 !type Fat q0..^q qmid0..^q
92 !type Power ptdrain0..^p
93
94 # 32-way ribbon
95 BUS 32
96                       icsp_pdw 
97                 l_gnd icsp_pdrany 
98                 l_gnd icsp_pdrall 
99                 l_gnd clock 
100                 l_gnd l_vcc mclr
101                 l_gnd i2c_clock led_reflow i2c_data led_refhigh
102                 rly_gnd rly_v12
103                 cdu_gnd cdu_out
104
105 CAC05 2         l_gnd l_vcc
106 0-1/1 CPIC= 2   l_gnd l_vcc
107
108 0-^q/4 OC= 16==^o
109                 :1+2 sensei<..>
110                 :2+2 q*&
111                 :-1-2 l_gnd*&
112                 :-0-2 sense<..>
113
114 0-^q/1 BR= 4
115                 :1+2 sshort=*2
116                 :2 ^x
117                 :4 q
118
119 0-^q/1 RS= 2
120                 sensei= ^x
121
122 AC05 14
123                 :8+
124                 icsp_pdrall icsp_pdrall_mid icsp_pdrall_mid icsp_pd
125                 icsp_pdrany icsp_pd
126                 l_vcc
127                 :7-
128                 l_gnd
129                 icsp_pdw_mid icsp_pdw
130                 ptgate0 icsp_pd
131                 - l_gnd
132
133 RPDR 2          icsp_pdrall_mid l_vcc
134 RPDWU 2         icsp_pdw_mid l_vcc
135 RPDWI 2         icsp_pdw_mid icsp_pd
136 RPT0U 2         ptgate0 l_vcc
137
138 RPCI 2          icsp_pc icsp_pcq
139 RPCL 2          icsp_pc l_gnd
140 RPCPT 2         icsp_pc ptgate1
141
142 0-^p/1 PTFET= 3 ptgate= ptdrain= cdu_gnd
143 0-^p/1 PTD= 2   cdu_out ptdrain=
144 2-^p/8 RAP= 16  :1 pt<..> :-0- ptgate<..>
145
146 cdu_out         Power
147 cdu_gnd         Power
148
149 TS912 8
150                 :1 ledmid_red perpicled led_reflow
151                 :7- ledmid_green led_refhigh perpicled
152                 :4 l_gnd
153                 :8 l_vcc
154
155 RLG 2           ledmid_green led_green
156 RLR 2           ledmid_red led_red
157 RLL 2           perpicled l_gnd
158
159 ^=reversers:
160
161 !type Fat t0..5
162
163 !PIC-ASSIGN
164                 1 mclr
165                 spare0
166                 reverse0..2
167                 sense3
168                 reverse3..5
169                 sense2
170                 l_vcc l_gnd clock
171                 sense1
172                 pt17,booster_dirn
173                 pt16,booster_pwm
174                 sense0
175                 i2c_clock
176                 19 sense5..4
177                 :40-
178                 pt0,icsp_pd
179                 pt1,icsp_pc
180                 pt6,cdu_enable
181                 pt7,rs232_fcin
182                 pt2
183                 pt8,booster_retry,
184                 pt9,booster_cutout
185                 pt10,booster_flag
186                 l_vcc
187                 l_gnd
188                 pt3
189                 pt11,spare2
190                 pt12,spare1
191                 pt4
192                 pt13,rs232_rxin
193                 pt14,rs232_txout
194                 pt15,rs232_fcout
195                 i2c_data
196                 pt5
197                 21 perpicled
198
199 TERM 14
200                 1 t q
201                 :3+2 t0..5
202                 :4+2 q0..5
203
204 ULN 18
205                 :11 rlydrv5..0
206                 :8- reverse5..0 rly_gnd rly_gnd
207                 :9 rly_gnd
208                 :10 rly_v12
209
210 CULN 2          rly_gnd rly_v12
211
212 RAS 9
213                 l_vcc
214                 :2 sense3..0 sense5..4
215                 - perpicled
216
217 POINTS 25
218                 :1 ptdrain1..17
219                 :25 ptdrain0            
220
221 0-5/1 RLY= 16
222                 :1 rly_v12
223                 :4 q=
224                 :6 qmid=
225                 :8 t
226                 :9 qmid=
227                 :11 t
228                 :13 t=
229                 :16 rlydrv=
230
231 ^=detectors:
232
233 0-^q/8 RAS= 9
234                 l_vcc
235                 :2 sense<..>
236
237 !PIC-ASSIGN
238                 1 mclr
239                 pt4,analogue
240                 pt5,spare0
241                 sense0..6
242                 l_vcc l_gnd clock
243                 sense7..10
244                 i2c_clock
245                 sense11..12
246                 :40-
247                 pt0,icsp_pd
248                 pt1,icsp_pc
249                 pt2
250                 sense20..18
251                 pt6,extint1
252                 pt7,extint0
253                 l_vcc
254                 l_gnd
255                 sense17..15
256                 pt3,pwmout
257                 pt8,rs232_rxin
258                 pt9,rs232_txout
259                 sense14
260                 i2c_data
261                 sense13
262                 21 perpicled
263
264 TERM 22
265                 q0..20 q