* doc/sdccman.lyx, support/scripts/inc2h-pic16.pl: updated list of
[fw/sdcc] / support / scripts / inc2h-pic16.pl
index 5910f7204e87976f24fd3577ae7a961c3f0d4753..0e5e715664258d508804cda1f0ccbf0a254712d7 100755 (executable)
@@ -2,6 +2,7 @@
 
 use strict;
 
+#
 # Parse MPASM include files to extract SDCC header/device library files
 # This script is (c) 2007 by Raphael Neider <rneider AT web.de>,
 # it is licensed under the terms of the GPL v2.
@@ -16,15 +17,23 @@ use strict;
 # 2. mv picDEVICE.h $SDCC/device/include/pic16
 # 3. mv picDEVICE.c $SDCC/device/lib/pic16/libdev
 # 4. add DEVICE to $SDCC/device/lib/pic16/pics.all (and .build)
-# 5. adjust $SDCC/device/lib/pic16/libio/*.ignore if the device
-#    does not support ADC, I2C, or USART
+# 5. either
+#    (a) adjust $SDCC/device/lib/pic16/libio/*.ignore
+#        if the device does not support ADC, I2C, or USART
+#        OR
+#    (b) adjust $SDCC/device/include/pic16/adc.h
+#        adding the new device to the correct ADC style class
 # 6. edit $SDCC/device/include/pic16/pic18fregs.h
-# 7. edit $SDCC/src/pic16/devices.inc
+# 7. edit $SDCC/device/include/pic16/pic16devices.txt
 #
 # The file format of steps 6 and 7 is self explanatory, in most
 # if not all cases you can copy and paste another device's records
 # and adjust them to the newly added device.
 #
+# Please try to add device families (with a common datasheet) rather
+# than a single device and use the .h and .c files of the largest
+# device for all (using #include "largest.c" and #include "largest.h").
+#
 
 my $SCRIPT = $0;
 $SCRIPT =~ s/.*\///g; # remove path prefix
@@ -150,7 +159,7 @@ while (<>) {
     
     if (/IFNDEF _*(18.*[0-9]+)/i) {
        $processor = lc($1);
-       LOG "Found processor: $processor.\n";
+       #LOG "Found processor: $processor.\n";
        setup($processor);
        next;
     }
@@ -200,7 +209,7 @@ while (<>) {
        my $addr = oct("0x" . $2);
        #LOG sprintf("Found device ID $1 at 0x%X.\n", $addr);
        if ($state != 6) {
-           print "\n// device IDs\n";
+           #print "\n// device IDs\n";
            $state = 6;
        }
        DEFINE ($1, sprintf ("0x%X", $addr));
@@ -211,7 +220,7 @@ while (<>) {
        my $addr = oct("0x" . $2);
        #LOG sprintf("Found ID location: $1 at 0x%X.\n", $addr);
        if ($state != 5) {
-           print "\n// ID locations\n";
+           #print "\n// ID locations\n";
            $state = 5;
        }
        DEFINE ($1, sprintf ("0x%X", $addr));
@@ -221,7 +230,7 @@ while (<>) {
     # extract configuration bits
     if (/Configuration Bits/i) {
        $state = 3;
-       printf "\n\n// Configuration Bits\n";
+       #print "\n\n// Configuration Bits\n";
        header "\n\n// Configuration Bits\n";
        next;
     }
@@ -229,6 +238,9 @@ while (<>) {
     if ($state == 3 and /(_\w+) EQU H'([0-9a-f]+)/i) {
        $name = $1;
        my $addr = oct("0x" . $2);
+       # convert to double underscore form for SDCC internal consistency
+       $name =~ s/^_//g;
+       $name = "__".$name;
        #LOG sprintf("Found config word $1 at 0x%X.\n", $addr);
        DEFINE ($name, sprintf ("0x%X", $addr));
        next;
@@ -237,7 +249,7 @@ while (<>) {
     if (($state == 3 or $state == 4) and /;--+ ((\w+) Options) --/i) {
        $name = uc($2);
        $state = 4;
-       print "\n// $1\n";
+       #print "\n// $1\n";
        header "\n// $1\n";
        next;
     }
@@ -269,7 +281,7 @@ while (<>) {
        );
        next;
     } elsif ($state == 2 and /(\w+) EQU ([0-9]+)/i) {
-       print "@@@@ FOUND $1 $2 for $name\n";
+       #print "@@@@ FOUND $1 $2 for $name\n";
        my $bit = 0+$2;
        #LOG "Found bit declaration: $1 as bit $bit in reg $name.\n";
        push @{$sfrs->{"$name"}->{"bit$bit"}}, $1;
@@ -281,7 +293,7 @@ while (<>) {
     }
 
     # unknown/unhandled line
-    print "// $_\n";
+    #print "// $_\n";
 }
 
 header "\n";
@@ -301,7 +313,7 @@ foreach my $idx (sort keys %$namelut) {
        header sprintf ("extern __sfr __at (0x%03X) %s;\n", $idx, $reg);
        library sprintf (      "__sfr __at (0x%03X) %s;\n", $idx, $reg);
 
-       print sprintf ("$reg @ %X (<= %d bit names)\n", $sfrs->{"$reg"}->{"addr"}, $names);
+       #print sprintf ("$reg @ %X (<= %d bit names)\n", $sfrs->{"$reg"}->{"addr"}, $names);
        if ($names > 0) {
            header sprintf ("typedef union {\n");