X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=support%2Fscripts%2Finc2h.pl;h=82e39cfc2142c9c32891c28d4976c5575c6e9a45;hb=7e0bd245f87e7a3e4dd73ee7920dbaa2d89317bb;hp=63b693cb0ef0d85ae29250d4f36f33580635b623;hpb=43082e9855dafdd47d0dc6649c63e47ad7a842c0;p=fw%2Fsdcc diff --git a/support/scripts/inc2h.pl b/support/scripts/inc2h.pl index 63b693cb..82e39cfc 100755 --- a/support/scripts/inc2h.pl +++ b/support/scripts/inc2h.pl @@ -24,19 +24,32 @@ $rcsid = q~$Id$~; if ($#ARGV < 0 || $#ARGV > 1 ) { Usage(); } -$processor = shift; +$processor = uc(shift); $path = shift; -$processor = uc $processor; -# Nathan Hurst : find gputils on Debian -if ($path eq '') { - if ( -x "/usr/share/gputils") { - $path = "/usr/share/gputils"; - } elsif ( -x "/usr/share/gpasm") { - $path = "/usr/share/gpasm"; - } else { - die "Could not find gpasm includes.\n"; +if ($^O eq 'MSWin32') { + if ($path eq '') { + if (defined($path = $ENV{'GPUTILS_HEADER_PATH'}) || defined($path = $ENV{'GPUTILS_LKR_PATH'})) { + $path .= '\\..'; + } + else { + die "Could not find gpasm includes.\n"; + } + } + $path_delim = '\\'; +} +else { + # Nathan Hurst : find gputils on Debian + if ($path eq '') { + if ( -x "/usr/share/gputils") { + $path = "/usr/share/gputils"; + } elsif ( -x "/usr/share/gpasm") { + $path = "/usr/share/gpasm"; + } else { + die "Could not find gpasm includes.\n"; + } } + $path_delim = '/'; } # @@ -116,28 +129,44 @@ while () { # } # } +# Create header for pic${processor}.c file +$lcproc = "pic" . lc($processor); +$c_head = < + +EOT + # # Convert the file. # $defaultType = 'other'; -$includeFile = "$path/header/p" . lc $processor . ".inc"; +$includeFile = $path.$path_delim.'header'.$path_delim.'p'.lc($processor).'.inc'; +$defsFile = "pic" . lc($processor) . ".c"; open(HEADER, "<$includeFile") || die "$programName: Error: Cannot open include file $includeFile ($!)\n"; while (
) { - if (/^;-* (\S+) Bits/i) { - if (defined($alias{$1})) { - $defaultType = "bits $alias{$1}"; - } else { - $defaultType = "bits $1"; + if (/^;-+ (\S+) Bits/i) { + # also accept "UIE/UIR Bits" + foreach $name (split(/\//, $1)) { + if (defined($alias{$name})) { + $defaultType = "bits $alias{$name}"; + } else { + $defaultType = "bits $name"; + } } s/;/\/\//; $body .= "$_"; - } elsif (/^;-* Register Files/i) { + } elsif (/^;-+ Register Files/i) { $defaultType = 'sfr'; s/;/\/\//; $body .= "$_"; - } elsif (/^;=*/i) { + } elsif (/^;=+/i) { $defaultType = ''; s/;/\/\//; $body .= "$_"; @@ -190,7 +219,8 @@ while (
) { } else { $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $value); } - $body .= sprintf("sfr at %-30s %s;$rest\n", "${name}_ADDR", $name); + $body .= sprintf("extern __sfr __at %-30s $name;$rest\n", "(${name}_ADDR)" ); + $c_head .= sprintf("__sfr __at %-30s $name;\n", "(${name}_ADDR)"); $addr{"p$processor", "$name"} = "0x$value"; } elsif ($type eq 'volatile') { # @@ -200,7 +230,8 @@ while (
) { $pragmas .= sprintf("#pragma memmap %s_ADDR %s_ADDR " . "SFR %s\t// %s\n", $name, $name, $bitmask, $name); - $body .= sprintf("data at %-30s %s;$rest\n", "${name}_ADDR volatile char", $name); + $body .= sprintf("extern __data __at %-30s $name;$rest\n", "(${name}_ADDR) volatile char"); + $c_head .= sprintf("__data __at %-30s $name;\n", "(${name}_ADDR) volatile char"); if (defined $addr{"p$processor", "$name"}) { $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $addr{"p$processor", "$name"}); } else { @@ -210,7 +241,13 @@ while (
) { ($junk, $register) = split(/\s/, $type); $bit = hex($value); $addr = $addr{"$register"}; - $body .= "BIT_AT(${register}_ADDR,$bit)\t$name;$rest\n"; + # prepare struct declaration + for ($k=0; $k < scalar @{$bits{"$register"}->{oct($bit)}}; $k++) { + $name = "" if ($bits{"$register"}->{oct($bit)} eq $name) + } + if ($name ne "") { + push @{$bits{"$register"}->{oct($bit)}}, $name; + } } else { # # Other registers, bits and/or configurations. @@ -236,8 +273,7 @@ while (
) { # $body .= "\n"; } elsif (/__MAXRAM\s+H'([0-9a-fA-F]+)'/) { - $maxram .= "//\n// Memory organization.\n//\n" - . sprintf("#pragma maxram 0x%s\n\n", $1); + $maxram .= "//\n// Memory organization.\n//\n"; $pragmas = $maxram . $ram{"p$processor"} . "\n" . $pragmas; @@ -274,21 +310,72 @@ $header .= <{oct($i)}}; + if ($max < scalar @names) { $max = scalar @names; } + if ($idx >= scalar @names) { + $structs .= " unsigned char :1;\n"; + } else { # (1 == scalar @names) { + $structs .= " unsigned char " . $names[$idx] . ":1;\n"; +# } else { +# $structs .= " union {\n"; +# foreach $name (@names) { +# $structs .= " unsigned char " . $name . ":1;\n"; +# } # foreach +# $structs .= " };\n"; + } + } # for + $structs .= " };\n"; + $idx++; + } while ($idx < $max); + $structs .= "} __${reg}_bits_t;\n"; + $structs .= "extern volatile __${reg}_bits_t __at(${reg}_ADDR) ${reg}_bits;\n\n"; + $c_head .= "volatile __${reg}_bits_t __at(${reg}_ADDR) ${reg}_bits;\n"; + + # emit defines for individual bits + for ($i=0; $i < 8; $i++) + { + @names = @{$bits{$reg}->{oct($i)}}; + foreach $field (@names) { + $structs .= sprintf("#define %-20s ${reg}_bits.$field\n", $field); + } # foreach + } + $structs .= "\n"; +} # foreach + print $header . $addresses . "\n" . $pragmas . "\n\n" - . $body + . $body . "\n" + . $structs . "#endif\n"; +open(DEFS, ">$defsFile") or die "Could not open $defsFile for writing."; +print DEFS $c_head . "\n"; +close DEFS; + sub Usage { print STDERR <