| 76 |
"io90pwmx.h": ("AT90PWM3", "AT90PWM2"), |
"io90pwmx.h": ("AT90PWM3", "AT90PWM2"), |
| 77 |
# no XML file |
# no XML file |
| 78 |
#"ioat94k.h": "AT94k", |
#"ioat94k.h": "AT94k", |
| 79 |
"iocan128.h": "AT90CAN128", |
"iocanxx.h": ("AT90CAN128", "AT90CAN32", "AT90CAN64"), |
| 80 |
"iom103.h": "ATmega103", |
"iom103.h": "ATmega103", |
| 81 |
"iom128.h": "ATmega128", |
"iom128.h": "ATmega128", |
| 82 |
#"iom1280.h" => "iomxx0_1.h" |
#"iom1280.h" => "iomxx0_1.h" |
| 202 |
lines = h.readlines() |
lines = h.readlines() |
| 203 |
h.close() |
h.close() |
| 204 |
|
|
|
firstidx = 0 |
|
|
lastidx = -1 |
|
| 205 |
parseddev = parser.getContentHandler().dev |
parseddev = parser.getContentHandler().dev |
| 206 |
|
|
| 207 |
# first, clean out any existing interrupt vectors |
# Find any interrupt vector definitions, and rewrite them. |
| 208 |
for idx, line in enumerate(lines): |
endcount = len(lines) |
| 209 |
m = r.match(line) |
idx = 0 |
| 210 |
|
while idx < endcount: |
| 211 |
|
line = lines[idx] |
| 212 |
|
try: |
| 213 |
|
m = r.match(line) |
| 214 |
|
except TypeError: |
| 215 |
|
print line |
| 216 |
|
exit(0) |
| 217 |
if m != None: |
if m != None: |
| 218 |
if firstidx == 0: |
firstidx = idx |
|
firstidx = idx |
|
| 219 |
key = m.group(4) # this is the vector number |
key = m.group(4) # this is the vector number |
| 220 |
ele = parseddev.interrupts[key] |
ele = parseddev.interrupts[key] |
| 221 |
|
|
| 222 |
lastidx = idx |
if lines[idx - 1].find(ele.description.data) >= 0: |
|
|
|
|
if idx > 0 and lines[idx - 1].find(ele.description.data) >= 0: |
|
| 223 |
# there is a /* description */ comment in the previous line, |
# there is a /* description */ comment in the previous line, |
| 224 |
# drop it |
# drop it |
| 225 |
if idx - 1 < firstidx: |
if idx - 1 < firstidx: |
| 226 |
firstidx = idx - 1 |
firstidx = idx - 1 |
| 227 |
|
|
| 228 |
if re.match('^$', lines[idx + 1]): |
lastidx = idx + 1 |
| 229 |
# there is a blank line after the current one, drop it |
while r.match(lines[lastidx]) and r.match(lines[lastidx]).group(4) == key: |
| 230 |
lastidx = idx + 1 |
# more vector definitions follow, skip them |
| 231 |
|
lastidx += 1 |
| 232 |
while re.match('^$', lines[lastidx]): |
|
| 233 |
lastidx += 1 |
while re.match('^$', lines[lastidx]): |
| 234 |
|
# blank lines follow, skip them, too |
| 235 |
del lines[firstidx:lastidx] |
lastidx += 1 |
| 236 |
|
|
| 237 |
# now, build a new vector table |
# Now, lastidx points to the first line not belonging |
| 238 |
keys = parseddev.interrupts.keys() |
# to our current vector definition. lastidx - firtidx |
| 239 |
keys.sort(lambda x,y: cmp(int(x), int(y))) |
# is the number of lines affected. |
| 240 |
|
|
| 241 |
vecttext = [] |
count = lastidx - firstidx |
| 242 |
for key in keys: |
del lines[firstidx:lastidx] |
| 243 |
ele = parseddev.interrupts[key] |
|
| 244 |
if ele.name == 'NOT_USED': |
# now, build a new vector entry |
| 245 |
# ATmega3250/6450 plug a `hole' that way |
vecttext = [] |
| 246 |
continue |
newcount = 0 |
| 247 |
|
if len(ele.description.data) > 0: |
| 248 |
if len(ele.description.data) > 0: |
vecttext.append("/* " + ele.description.data + " */\n") |
| 249 |
vecttext.append("/* " + ele.description.data + " */\n") |
newcount += 1 |
| 250 |
vecttext.append("#define " + ele.sig_name.data + |
vecttext.append("#define " + ele.sig_name.data + |
| 251 |
create_tabs(ele.sig_name.data) + |
create_tabs(ele.sig_name.data) + |
| 252 |
"_VECTOR(" + key + ")\n") |
"_VECTOR(" + key + ")\n") |
| 253 |
try: |
newcount += 1 |
| 254 |
for x in ele.alt_name.data: |
try: |
| 255 |
vecttext.append("#define " + x + |
for x in ele.alt_name.data: |
| 256 |
create_tabs(x) + "_VECTOR(" + key + ")\n") |
vecttext.append("#define " + x + |
| 257 |
except AttributeError: |
create_tabs(x) + "_VECTOR(" + key + ")\n") |
| 258 |
# no alt_name present |
newcount += 1 |
| 259 |
pass |
except AttributeError: |
| 260 |
vecttext.append('\n') |
# no alt_name present |
| 261 |
|
pass |
| 262 |
# collect documentation for this vector |
vecttext.append('\n') |
| 263 |
try: |
newcount += 1 |
| 264 |
if type(devname) is TupleType: |
|
| 265 |
for d in devname: |
# insert new vector entry |
| 266 |
docs[ele.sig_name.data][2].append(d) |
lines[firstidx:firstidx] = vecttext |
| 267 |
else: |
|
| 268 |
docs[ele.sig_name.data][2].append(devname) |
endcount += newcount - count |
| 269 |
except KeyError: |
# back off beyond what we've just been working on |
| 270 |
if type(devname) is TupleType: |
idx = firstidx + newcount |
| 271 |
docs[ele.sig_name.data] = (ele.alt_name.data, |
|
| 272 |
ele.description.data, |
# collect documentation for this vector |
| 273 |
[]) |
try: |
| 274 |
for d in devname: |
if type(devname) is TupleType: |
| 275 |
docs[ele.sig_name.data][2].append(d) |
for d in devname: |
| 276 |
else: |
docs[ele.sig_name.data][2].append(d) |
| 277 |
docs[ele.sig_name.data] = (ele.alt_name.data, |
else: |
| 278 |
ele.description.data, |
docs[ele.sig_name.data][2].append(devname) |
| 279 |
[devname]) |
except KeyError: |
| 280 |
|
if type(devname) is TupleType: |
| 281 |
# insert new vector table |
docs[ele.sig_name.data] = (ele.alt_name.data, |
| 282 |
lines.insert(firstidx, vecttext) |
ele.description.data, |
| 283 |
|
[]) |
| 284 |
|
for d in devname: |
| 285 |
|
docs[ele.sig_name.data][2].append(d) |
| 286 |
|
else: |
| 287 |
|
docs[ele.sig_name.data] = (ele.alt_name.data, |
| 288 |
|
ele.description.data, |
| 289 |
|
[devname]) |
| 290 |
|
else: |
| 291 |
|
# no match, increment index |
| 292 |
|
idx += 1 |
| 293 |
|
|
| 294 |
newh = open(header, "w") |
newh = open(header, "w") |
| 295 |
for line in lines: |
for line in lines: |