Debian Codegraph @

scripts/io_gen.py

raw symbols SCIP
1 #! /usr/bin/env python
2 ###############################################################################
3 #
4 # avarice - The "avarice" program.
5 # Copyright (C) 2004 Theodore A. Roth
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #
21 ###############################################################################
22 #
23 # $Id: io_gen.py 78 2004-01-29 17:54:47Z troth $
24 #
25
26 #
27 # This script is for generating the .io_reg field initializer of the
28 # DevSuppDefn for a specfic device. The input should be one of the io*.h files
29 # provided by avr-libc in the include/avr/ directory.
30 #
31 # Usage: io_gen.py <io_header>
32 #
33 # This best way to use this script is while using vim to edit the ioreg.cc.
34 # You can run the script from vim and have the output of the script inserted
35 # directly into the ioreg.cc file with a command like this:
36 #
37 # :r!../misc/io_gen.py ~/dev/tools/avr-libc-cvs/include/avr/iomega128.h
38 #
39
40 import os, sys, re
41
42 base_regx = r'[#]define\s*?(\S+)\s*?%s\s*[(]\s*?(\S+?)\s*?[)]'
43
44 re_io8 = re.compile (base_regx % ('_SFR_IO8'))
45 re_mem8 = re.compile (base_regx % ('_SFR_MEM8'))
46
47 # Open the input file.
48
49 try:
50 in_file_name = sys.argv[1]
51 except:
52 print 'Usage: %s <io_header>' % (os.path.basename (sys.argv[0]))
53 sys.exit (1)
54
55 f = open (in_file_name).read ()
56
57 register = {}
58
59 # Find all the _SFR_IO8 defs.
60
61 for name, addr_str in re_io8.findall (f):
62 addr = int (addr_str, 0) + 0x20
63 register[addr] = name
64
65 # Find all the _SFR_MEM8 defs.
66
67 for name, addr_str in re_mem8.findall (f):
68 addr = int (addr_str, 0)
69 register[addr] = name
70
71 # Print the field initializer to stdout.
72
73 addrs = register.keys ()
74 addrs.sort ()
75 print 'gdb_io_reg_def_type [PUT DEVICE NAME HERE]_io_registers[] ='
76 print '{'
77 for addr in addrs:
78 print ' { %-12s, 0x%X, 0x00 },' % ('"%s"' %(register[addr]), addr)
79 print ' /* May need to add SREG, SPL, SPH, and eeprom registers. */'
80 print ' { 0, 0, 0}'
81 print '}'