2 # Automatically generates the StellarisParts struct in src/flash/nor/stellaris.c
3 # Uses the header files from TI/Luminary's StellarisWare complete Firmware Development Package
4 # available from: http://www.luminarymicro.com/products/software_updates.html
6 $comment = "// Autogenerated by contrib/gen-stellaris-part-header.pl
7 // From Stellaris Firmware Development Package revision";
9 $struct_header = "static const struct {
13 } StellarisParts[] = {
16 $struct_footer = "\t{0xFF, 0x00, \"Unknown Part\"}\n};\n";
18 $#ARGV == 1 || die "Usage: $0 <inc directory> <output file>\n";
19 -d
$ARGV[0] || die $ARGV[0]." is not a directory\n";
21 -f
$ARGV[1] || die $ARGV[1]." is not a file\n";
23 print STDERR
"Scanning $dir, Updating $file\n";
25 opendir(DIR
, $dir) || die "can't open $dir: $!";
26 @files = readdir(DIR
);
29 @header_files = sort(grep(/lm.+\.h/, @files));
32 $new_struct = $struct_header;
33 process_file
(@header_files);
34 $new_struct .= $struct_footer;
36 $dump = "$comment $ver\n$new_struct";
39 open(INPUT
, $file) || die "can't open $file: $!";
44 $old_struct = qr/((^\/\
/.*?\n)*)\Q$struct_header\E.*?$struct_footer/sm;
45 $contents =~ s/$old_struct/$dump/;
46 open(OUTPUT
, ">$file") || die "can't open file $file for writing: $!";
47 print OUTPUT
$contents;
51 foreach $h_file (@_) {
52 ($base) = ($h_file =~ m/lm..(.{3,7})\.h/ig);
55 open(FILE
, "$dir/$h_file");
59 if ($content =~ /This is part of revision (\d+) of/) {
60 if ($ver != 0 and $ver != $1) {
61 print STDERR
"File version mismatch: $ver != $1\n";
68 if ($content =~ /SYSCTL_DID0_CLASS_[^M].+?0x(\S+)/s) {
69 $class = hex($1) >> 16;
71 # attempt another way to get class
72 if ($content =~ /\s(\S+)-class/) {
73 $class = getclass
($1);
75 print STDERR
"$h_file unknown class\n";
79 print STDERR
"$h_file is missing SYSCTL_DID0_CLASS_\n";
85 if ($content =~ /SYSCTL_DID1_PRTNO_$base.+0x(\S+)/) {
87 $base = "LM3S" . $base;
89 # LM4F have a changed header
90 if ($content =~ /SYSCTL_DID1_PRTNO_LM4F$base.+?0x(\S+)/s) {
92 $base = "LM4F" . $base;
94 print STDERR
"$h_file is missing SYSCTL_DID1_PRTNO\n";
99 $new_member = sprintf "{0x%02X, 0x%02X, \"%s\"},", $class, $prtno >> 16, $base;
101 #$new_struct .= "\t//$new_member\t// Invalid\n";
103 $new_struct .= "\t$new_member\n";
110 if ($class =~ /Sandstorm/i) {
112 } elsif ($class =~ /Fury/i) {
114 } elsif ($class =~ /DustDevil/i) {
116 } elsif ($class =~ /Tempest/i) {
118 } elsif ($class =~ /Blizzard/i) {
120 } elsif ($class =~ /Firestorm/i) {