2 BCU SDK bcu development enviroment
3 Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 GroupObjectFlag (GroupObject
& o
, BCUType b
)
26 if (o
.ObjAddress () == 0)
50 if (o
.ReceiveAddress ())
54 if (o
.SendAddress_lineno
|| o
.ReadRequestAddress_lineno
)
56 if (o
.UpdateAddress () || b
== BCU_bcu12
)
62 hasAddress (Array
< eibgaddr_t
> &a
, eibgaddr_t addr
)
65 for (i
= 0; i
< a (); i
++)
72 addAddress (Array
< eibgaddr_t
> &a
, eibgaddr_t addr
)
74 if (hasAddress (a
, addr
))
82 BuildObjAddress (GroupObject
& o
, BCUType b
)
86 o
.ObjAddress
.resize (0);
87 for (i
= 0; i
< o
.ReceiveAddress (); i
++)
89 if (o
.ReceiveAddress
[i
] < 0 || o
.ReceiveAddress
[i
] > 0xffff)
90 die (_("line %d: invalid group address %X"), o
.lineno
,
92 if (addAddress (o
.ObjAddress
, o
.ReceiveAddress
[i
]))
95 ("line %d: unsupported combination of group addresses, merging them"),
100 for (i
= 0; i
< o
.ReadAddress (); i
++)
102 if (o
.ReadAddress
[i
] < 0 || o
.ReadAddress
[i
] > 0xffff)
103 die (_("line %d: invalid group address %X"), o
.lineno
,
105 if (addAddress (o
.ObjAddress
, o
.ReadAddress
[i
]))
108 ("line %d: unsupported combination of group addresses, merging them"),
113 if (o
.UpdateAddress () && b
== BCU_bcu12
)
114 die (_("line %d: UpdateAddress not supported"), o
.lineno
);
115 for (i
= 0; i
< o
.UpdateAddress (); i
++)
117 if (o
.UpdateAddress
[i
] < 0 || o
.UpdateAddress
[i
] > 0xffff)
118 die (_("line %d: invalid group address %X"), o
.lineno
,
120 if (addAddress (o
.ObjAddress
, o
.UpdateAddress
[i
]))
123 ("line %d: unsupported combination of group addresses, merging them"),
128 if (o
.SendAddress_lineno
)
130 if (o
.SendAddress
< 0 || o
.SendAddress
> 0xffff)
131 die (_("line %d: invalid group address %X"), o
.lineno
, o
.SendAddress
);
132 if (addAddress (o
.ObjAddress
, o
.SendAddress
))
135 ("line %d: unsupported combination of group addresses, merging them"),
140 if (o
.ReadRequestAddress_lineno
)
142 if (o
.ReadRequestAddress
< 0 || o
.ReadRequestAddress
> 0xffff)
143 die (_("line %d: invalid group address %X"), o
.lineno
,
144 o
.ReadRequestAddress
);
145 if (addAddress (o
.ObjAddress
, o
.ReadRequestAddress
))
148 ("line %d: unsupported combination of group addresses, merging them"),
151 if (o
.ReadRequestAddress_lineno
&& o
.SendAddress_lineno
)
152 if (o
.ReadRequestAddress
!= o
.SendAddress
)
153 warn (_("line %d: different outgoing addresses, only one is used"),
158 BuildObjNo (GroupObject
& o
, int &objno
)
167 AddrNo (Array
< eibgaddr_t
> a
, eibgaddr_t ga
)
170 for (i
= 0; i
< a (); i
++)
173 die (_("internal error"));
177 BuildAddrTable (AddrTable
& t
, Device
& d
)
183 for (i
= 0; i
< d
.GroupObjects (); i
++)
184 for (j
= 0; j
< d
.GroupObjects
[i
].ObjAddress (); j
++)
185 addAddress (t
.addr
, d
.GroupObjects
[i
].ObjAddress
[j
]);
188 for (i
= 0; i
< d
.GroupObjects (); i
++)
189 maxs
+= d
.GroupObjects
[i
].ObjAddress ();
191 t
.ObjNo
.resize (maxs
);
192 t
.Addr
.resize (maxs
);
193 for (i
= 0; i
< maxs
; i
++)
195 for (i
= 0; i
< d
.GroupObjects (); i
++)
196 if (d
.GroupObjects
[i
].SendAddress_lineno
)
199 t
.ObjNo
[i
] = d
.GroupObjects
[i
].ObjNo
;
200 t
.Addr
[i
] = AddrNo (t
.addr
, d
.GroupObjects
[i
].SendAddress
);
202 else if (d
.GroupObjects
[i
].ReadRequestAddress_lineno
)
205 t
.ObjNo
[i
] = d
.GroupObjects
[i
].ObjNo
;
206 t
.Addr
[i
] = AddrNo (t
.addr
, d
.GroupObjects
[i
].ReadRequestAddress
);
209 while (fn
< maxs
&& used
[fn
])
211 for (i
= 0; i
< d
.GroupObjects (); i
++)
212 for (j
= 0; j
< d
.GroupObjects
[i
].ObjAddress (); j
++)
213 if ((!d
.GroupObjects
[i
].SendAddress_lineno
&&
214 (!d
.GroupObjects
[i
].ReadRequestAddress_lineno
||
215 d
.GroupObjects
[i
].ReadRequestAddress
!=
216 d
.GroupObjects
[i
].ObjAddress
[j
]))
217 || (d
.GroupObjects
[i
].SendAddress_lineno
218 && d
.GroupObjects
[i
].SendAddress
!=
219 d
.GroupObjects
[i
].ObjAddress
[j
]))
222 t
.ObjNo
[fn
] = d
.GroupObjects
[i
].ObjNo
;
223 t
.Addr
[fn
] = AddrNo (t
.addr
, d
.GroupObjects
[i
].ObjAddress
[j
]);
225 while (fn
< maxs
&& used
[fn
])
231 printAddrTab (FILE * f
, Device
& d
)
236 for (i
= 0; i
< d
.GroupObjects (); i
++)
237 BuildObjAddress (d
.GroupObjects
[i
], d
.BCU
);
238 for (i
= 0; i
< d
.GroupObjects (); i
++)
239 BuildObjNo (d
.GroupObjects
[i
], objno
);
241 BuildAddrTable (t
, d
);
244 fprintf (f
, "\t.section .addrtab\n");
245 fprintf (f
, "addrtab:\n");
246 fprintf (f
, "\t.byte %d\n", t
.addr () + 1);
247 fprintf (f
, "\t.hword 0x%04X # physical address\n", d
.PhysicalAddress
);
248 for (i
= 0; i
< t
.addr (); i
++)
249 fprintf (f
, "\t.hword 0x%04X\n", t
.addr
[i
]);
250 if (d
.BCU
!= BCU_bcu12
)
251 fprintf (f
, "\t.byte 0 #Checksum\n");
252 fprintf (f
, "addrtab_end:\n");
253 fprintf (f
, "\t.section .assoctab\n");
254 fprintf (f
, "assoctab:\n");
255 fprintf (f
, "\t.byte %d\n", maxs
);
256 for (i
= 0; i
< maxs
; i
++)
257 fprintf (f
, "\t.byte %d, %d\n", t
.Addr
[i
] + 1, t
.ObjNo
[i
]);
258 if (d
.BCU
!= BCU_bcu12
)
259 fprintf (f
, "\t.byte 0 #Checksum\n");
260 fprintf (f
, "assoctab_end:\n");
263 die (_("to many communication objectes"));
267 printPseudoAddrTab (FILE * f
, Device
& d
)
270 if (!d
.Test_Addr_Count_lineno
)
272 d
.Test_Addr_Count
= d
.GroupObjects ();
274 if (d
.Test_Addr_Count
< 0 || d
.Test_Addr_Count
> 0x7e)
275 die (_("invalid value %d for Test_Addr_Count"), d
.Test_Addr_Count
);
276 if (d
.Test_Assoc_Count
< 0 || d
.Test_Assoc_Count
> 0xff)
277 die (_("invalid value %d for Test_Assoc_Count"), d
.Test_Assoc_Count
);
278 if (!d
.Test_Assoc_Count_lineno
)
280 d
.Test_Assoc_Count
= d
.GroupObjects ();
282 fprintf (f
, "\t.section .addrtab\n");
283 fprintf (f
, "addrtab:\n");
284 fprintf (f
, "\t.byte %d\n", d
.Test_Addr_Count
+ 1);
285 fprintf (f
, "\t.hword 0x0000 # physical address\n");
286 for (i
= 0; i
< d
.Test_Addr_Count
; i
++)
287 fprintf (f
, "\t.hword 0x0000\n");
288 if (d
.BCU
!= BCU_bcu12
)
289 fprintf (f
, "\t.byte 0 #Checksum\n");
290 fprintf (f
, "addrtab_end:\n");
292 fprintf (f
, "\t.section .assoctab\n");
293 fprintf (f
, "assoctab:\n");
294 fprintf (f
, "\t.byte %d\n", d
.Test_Assoc_Count
);
295 for (i
= 0; i
< d
.Test_Assoc_Count
; i
++)
296 fprintf (f
, "\t.byte 0, 0\n");
297 if (d
.BCU
!= BCU_bcu12
)
298 fprintf (f
, "\t.byte 0 #Checksum\n");
299 fprintf (f
, "assoctab_end:\n");
301 for (i
= 0; i
< d
.GroupObjects (); i
++)
302 d
.GroupObjects
[i
].ObjNo
= i
;
303 d
.ObjCount
= d
.GroupObjects ();
305 die (_("to many communication objectes"));