5 This script generates a C header file that maps the target device (as
6 indicated via the sdcc generated -Dpic16cxxx or -Dpic12fxxx or -Dpic16fxxx
7 macro) to its device family and the device families to their respective
8 style of ADC, USART and SSP programming for use in the SDCC PIC14 I/O library.
10 Copyright 2010 Raphael Neider <rneider AT web.de>
12 Copyright 2012-2014 Molnar Karoly <molnarkaroly@users.sf.net>
14 This file is part of SDCC.
16 SDCC is free software: you can redistribute it and/or modify it under
17 the terms of the GNU General Public License as published by the Free
18 Software Foundation, either version 2 of the License, or (at your
19 option) any later version.
21 SDCC is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 You should have received a copy of the GNU General Public License
27 along with SDCC. If not, see <http://www.gnu.org/licenses/>.
29 Usage: perl pic16fam-h-gen.pl [-i|-p|-h]
31 This will create pic16fam.h.gen in your current directory.
32 Check sanity of the file and move it to .../include/pic14/pic16fam.h.
33 If you assigned new I/O styles, implement them in
34 .../include/pic14/{adc,i2c,pwm,spi,usart}.h and
35 .../lib/pic14/libio/*/*.c
43 no if $] >= 5.018, warnings
=> "experimental::smartmatch"; # perl 5.16
45 use feature
'switch'; # Starting from 5.10.1.
47 use constant FALSE
=> 0;
48 use constant TRUE
=> 1;
50 use constant SECT_NONE
=> 0;
51 use constant SECT_REG
=> 1;
52 use constant SECT_ENH
=> 2;
53 use constant SECT_PER
=> 3;
55 my $head = '__SDCC_PIC';
57 my $gen_ignore_lists = FALSE
;
58 my $gen_mcu_lists = FALSE
;
61 my @enhanced_mcu = ();
63 my %peripherals_by_names = ();
64 my $actual_peripheral;
71 my $update = 'Please update your pic14/pic16fam.h manually and/or inform the maintainer.';
75 #-------------------------------------------------------------------------------
80 my $al = $_[1] - length($Text);
82 # One space will surely becomes behind it.
85 return ($Text . (' ' x
$al));
88 #-------------------------------------------------------------------------------
90 sub find_in_supported
($$)
92 my ($Hash, $Name) = @_;
96 return TRUE
if ($_ > 0 && $Name ~~ @
{${$Hash}{$_}});
102 #-------------------------------------------------------------------------------
105 This procedure give a list (id=0) to the peripherals, in which are
106 included the not supported devices.
109 sub create_ignore_lists
()
111 my @full_mcu_list = (@regular_mcu, @enhanced_mcu);
113 foreach (keys %peripherals_by_names)
115 my $peri = $peripherals_by_names{$_};
116 my @ignore_list = ();
118 foreach (@full_mcu_list)
120 push(@ignore_list, $_) if (! find_in_supported
($peri, $_) && ! ($_ ~~ @ignore_list));
123 @
{${$peri}{0}} = @ignore_list;
127 #-------------------------------------------------------------------------------
131 my ($Str1, $Str2) = @_;
133 if (${$Str1} =~ /^\d/o && ${$Str2} =~ /^\d/o)
135 # $Str1 number and $Str2 number
136 return (int(${$Str1}) <=> int(${$Str2}));
139 return (${$Str1} cmp ${$Str2});
142 #-------------------------------------------------------------------------------
146 my @a_s = ($a =~ /(\d+|\D+)/go);
147 my @b_s = ($b =~ /(\d+|\D+)/go);
148 my ($i, $k, $end, $ret);
169 for ($i = 0; $i < $end; ++$i)
171 $k = smartCompare
(\
$a_s[$i], \
$b_s[$i]);
173 return $k if ($k != 0);
179 #-------------------------------------------------------------------------------
184 my @fields = split(':', $line);
186 die "Invalid record: >$line<" if (@fields != 2);
188 $id = int($fields[0]);
189 push(@
{${$_[0]}{$id}}, map { uc($_); } split(',', $fields[1])) if ($id > 0);
192 #-------------------------------------------------------------------------------
195 Creates the ignore files of peripherals from the ignore lists.
198 sub generate_ignore_files
()
200 foreach (keys %peripherals_by_names)
202 $fname = "$_.ignore$tail";
203 open(FH
, '>', $fname) or die "Could not open: \"$fname\"";
204 print FH
join("\n", map { lc($_); } sort smartSort @
{${$peripherals_by_names{$_}}{0}}) . "\n";
209 #-------------------------------------------------------------------------------
212 Creates the lists of MCUs.
215 sub generate_mcu_files
()
217 $fname = "mcu.regular$tail";
218 open(FH
, '>', $fname) or die "Could not open: \"$fname\"";
219 print FH
join("\n", map { lc($_); } sort smartSort
@regular_mcu) . "\n";
222 $fname = "mcu.enhanced$tail";
223 open(FH
, '>', $fname) or die "Could not open: \"$fname\"";
224 print FH
join("\n", map { lc($_); } sort smartSort
@enhanced_mcu) . "\n";
228 #-------------------------------------------------------------------------------
230 sub print_peripheral
($)
233 my $array = $peripherals_by_names{$_};
234 my $def = align
("#define __SDCC_${Name}_STYLE", 30);
239 * Define $Name style per device family.
241 #undef __SDCC_${Name}_STYLE
246 foreach (sort keys %{$array})
248 my $fams = "defined($head" . join(") || \\\n defined($head", sort smartSort @
{$array->{$_}}) . ')';
250 print FH
"$cpp$fams\n$def$_\n\n";
256 #warning No $Name style associated with the target device.
264 #-------------------------------------------------------------------------------
266 for (my $i = 0; $i < @ARGV; )
268 my $opt = $ARGV[$i++];
272 when (/^-(i|-gen-ignore)$/o)
274 # This command creates the PERIPHERAL.ignore.gen files.
275 $gen_ignore_lists = TRUE
;
278 when (/^-(p|-gen-processor-lists)$/o)
280 # This command creates the mcu.{enhanced,regular}.gen files.
281 $gen_mcu_lists = TRUE
;
286 # This command creates the PERIPHERAL.ignore.gen and
287 # the mcu.{enhanced,regular}.gen files.
288 $gen_ignore_lists = TRUE
;
289 $gen_mcu_lists = TRUE
;
292 when (/^-(h|-help)$/o)
299 This command creates the PERIPHERAL.ignore$tail files.
301 -p or --gen-processor-lists
302 This command creates the mcu.{enhanced,regular}$tail files.
313 $section = SECT_NONE
;
315 # While reading skips the blank or comment lines.
316 foreach (grep(! /^\s*$|^\s*#/o, <DATA
>))
319 s/\s*//go; # strip whitespace
323 if ($line =~ /^SECTION=(\S+)$/o)
327 when ('REGULAR') { $section = SECT_REG
; }
328 when ('ENHANCED') { $section = SECT_ENH
; }
334 die "The $name peripheral already exist!" if (defined($peripherals_by_names{$name}));
336 $actual_peripheral = {};
337 $peripherals_by_names{$name} = $actual_peripheral;
349 push(@regular_mcu, map { uc($_); } split(',', $line));
354 push(@enhanced_mcu, map { uc($_); } split(',', $line));
359 collector
($actual_peripheral);
362 } # foreach (grep(! /^\s*$|^\s*#/o, <DATA>))
364 create_ignore_lists
();
366 generate_ignore_files
() if ($gen_ignore_lists);
367 generate_mcu_files
() if ($gen_mcu_lists);
369 $fname = "pic16fam.h$tail";
370 open(FH
, '>', $fname) or die "Could not open: \"$fname\"";
374 * pic16fam.h - PIC14 families
376 * This file is has been generated using $0 .
378 #ifndef __SDCC_PIC16FAM_H__
379 #define __SDCC_PIC16FAM_H__ 1
382 * Define device class.
384 #undef __SDCC_PIC14_ENHANCED
389 my $memb = "defined($head" . join(") || \\\n defined($head", sort smartSort
@enhanced_mcu) . ')';
392 #define __SDCC_PIC14_ENHANCED 1
399 foreach (sort smartSort
keys %peripherals_by_names)
401 print_peripheral
($_);
404 print FH
"#endif /* !__SDCC_PIC16FAM_H__ */\n";
409 ################################################################################
411 # This list contains the names of the regular devices.
412 # (Of course only them which are the sdcc also know.)
417 10f320
,10f322
,12f609
,12f615
,12f617
,12f629
,12f635
,12f675
,12f683
,12f752
418 16c62
,16c63a
,16c65b
,16c71
,16c72
,16c73b
,16c74b
,16c432
,16c433
,16c554
419 16c557
,16c558
,16c620
,16c620a
,16c621
,16c621a
,16c622
,16c622a
,16c710
,16c711
420 16c715
,16c717
,16c745
,16c765
,16c770
,16c771
,16c773
,16c774
,16c781
,16c782
421 16c925
,16c926
,16f72
,16f73
,16f74
,16f76
,16f77
,16f84
,16f84a
,16f87
422 16f88
,16f610
,16f616
,16f627
,16f627a
,16f628
,16f628a
,16f630
,16f631
,16f636
423 16f639
,16f648a
,16f676
,16f677
,16f684
,16f685
,16f687
,16f688
,16f689
,16f690
424 16f707
,16f716
,16f720
,16f721
,16f722
,16f722a
,16f723
,16f723a
,16f724
,16f726
425 16f727
,16f737
,16f747
,16f753
,16f767
,16f777
,16f785
,16f818
,16f819
,16f870
426 16f871
,16f872
,16f873
,16f873a
,16f874
,16f874a
,16f876
,16f876a
,16f877
,16f877a
427 16f882
,16f883
,16f884
,16f886
,16f887
,16f913
,16f914
,16f916
,16f917
,16f946
430 ################################################################################
432 # This list in turn exclusively contains the names of the enhanced devices.
433 # (Only them which are the sdcc also know.)
438 12f1501
,12f1571
,12f1572
,12f1612
,12f1822
,12f1840
,12lf
1552,16f1454
,16f1455
,16f1458
439 16f1459
,16f1503
,16f1507
,16f1508
,16f1509
,16f1512
,16f1513
,16f1516
,16f1517
,16f1518
440 16f1519
,16f1526
,16f1527
,16f1613
,16f1703
,16f1704
,16f1705
,16f1707
,16f1708
,16f1709
441 16f1713
,16f1716
,16f1717
,16f1718
,16f1719
,16f1782
,16f1783
,16f1784
,16f1786
,16f1787
442 16f1788
,16f1789
,16f1823
,16f1824
,16f1825
,16f1826
,16f1827
,16f1828
,16f1829
,16f1847
443 16f1933
,16f1934
,16f1936
,16f1937
,16f1938
,16f1939
,16f1946
,16f1947
,16lf
1554,16lf
1559
444 16lf
1704,16lf
1708,16lf
1902,16lf
1903,16lf
1904,16lf
1906,16lf
1907
446 ################################################################################
448 # <id>:<head>{,<member>}
450 # Each line provides a colon separated list of
452 # * a numeric family name, derived from the first family member as follows:
454 # ADC : <num1>(c|f|hv|lf)<num2>.? -> printf("%u%04u1", <num1>, <num2>)
455 # CCP : <num1>(c|f|hv|lf)<num2>.? -> printf("%u%04u2", <num1>, <num2>)
456 # PWM : <num1>(c|f|hv|lf)<num2>.? -> printf("%u%04u3", <num1>, <num2>)
457 # I2C : <num1>(c|f|hv|lf)<num2>.? -> printf("%u%04u4", <num1>, <num2>)
458 # SPI : <num1>(c|f|hv|lf)<num2>.? -> printf("%u%04u5", <num1>, <num2>)
459 # USART : <num1>(c|f|hv|lf)<num2>.? -> printf("%u%04u6", <num1>, <num2>)
461 # * a comma-separated list of members of a device family.
463 # The rules basis of which members of a family belong together:
465 # a.) The connectors of peripheral are located on the same pin.
467 # b.) In the periphery - in context with other peripherals - should be
468 # used in the same way. (Pin relocation. Other peripheral to use
469 # the same pin? Peripheral initialization. ...)
471 # This data has been gathered manually from data sheets published by
472 # Microchip Technology Inc.
477 10032001:10f320
,10f322
489 16007100:16c71
,16c710
,16c711
491 16007300:16c73b
,16c74b
,16c745
,16c765
,16f73
,16f76
494 16071700:16c717
,16c770
,16c771
497 16078100:16c781
,16c782
498 16092500:16c925
,16c926
,16f872
501 16061601:16f616
,16hv616
502 16067601:16f676
,16f684
503 16067701:16f677
,16f685
504 16068701:16f687
,16f689
,16f690
508 16072001:16f720
,16f721
509 16072201:16f722
,16f722a
,16f723
,16f723a
,16f726
510 16072401:16f724
,16f727
511 16073701:16f737
,16f767
512 16074701:16f747
,16f777
513 16075301:16f753
,16hv753
515 16081801:16f818
,16f819
516 16087001:16f870
,16f873
,16f876
517 16087101:16f871
,16f874
,16f877
518 16087301:16f873a
,16f876a
519 16087401:16f874a
,16f877a
520 16088201:16f882
,16f883
,16f886
521 16088401:16f884
,16f887
522 16091301:16f913
,16f916
523 16091401:16f914
,16f917
,16f946
528 16150801:16f1508
,16f1509
529 16151201:16f1512
,16f1513
530 16151601:16f1516
,16f1518
531 16151701:16f1517
,16f1519
532 16152601:16f1526
,16f1527
535 16170401:16f1704
,16f1705
,16lf
1704
537 16170801:16f1708
,16lf
1708
539 16171301:16f1713
,16f1716
,16f1718
540 16171701:16f1717
,16f1719
541 16178201:16f1782
,16f1783
542 16178401:16f1784
,16f1787
547 16182401:16f1824
,16f1825
548 16182601:16f1826
,16f1827
,16f1847
549 16182801:16f1828
,16f1829
550 16193301:16f1933
,16f1936
,16f1938
551 16193401:16f1934
,16f1937
,16f1939
552 16194601:16f1946
,16f1947
555 16190201:16lf
1902,16lf
1903
556 16190401:16lf
1904,16lf
1907
568 16006310:16c63a
,16c65b
570 16007310:16c73b
,16c74b
,16f73
,16f74
,16f76
,16f77
571 16071710:16c717
,16c770
,16c771
572 16074510:16c745
,16c765
573 16077310:16c773
,16c774
574 16092510:16c925
,16c926
,16f872
577 16061611:16f616
,16hv616
578 16062711:16f627
,16f627a
,16f628
,16f628a
,16f648a
581 16068711:16f687
,16f689
585 16072011:16f720
,16f721
586 16072211:16f722
,16f722a
,16f723
,16f723a
,16f726
587 16072411:16f724
,16f727
588 16073711:16f737
,16f747
,16f767
,16f777
589 16075311:16f753
,16hv753
591 16081811:16f818
,16f819
592 16087011:16f870
,16f871
593 16087311:16f873
,16f874
,16f876
,16f877
594 16087311:16f873a
,16f874a
,16f876a
,16f877a
595 16088211:16f882
,16f883
,16f886
596 16088411:16f884
,16f887
597 16091311:16f913
,16f916
598 16091411:16f914
,16f917
,16f946
599 16151211:16f1512
,16f1513
,16f1516
,16f1518
600 16151711:16f1517
,16f1519
601 16152611:16f1526
,16f1527
604 16170411:16f1704
,16f1705
,16lf
1704
606 16170811:16f1708
,16lf
1708
608 16171311:16f1713
,16f1716
,16f1718
609 16171711:16f1717
,16f1719
610 16178211:16f1782
,16f1783
611 16178411:16f1784
,16f1787
619 16182711:16f1827
,16f1847
622 16193311:16f1933
,16f1936
,16f1938
623 16193411:16f1934
,16f1937
,16f1939
624 16194611:16f1946
,16f1947
628 10032021:10f320
,10f322
639 16006320:16c63a
,16c65b
641 16007320:16c73b
,16c74b
,16f73
,16f74
,16f76
,16f77
642 16071720:16c717
,16c770
,16c771
643 16074520:16c745
,16c765
644 16077320:16c773
,16c774
645 16092520:16c925
,16c926
,16f872
648 16061621:16f616
,16hv616
649 16062721:16f627
,16f627a
,16f628
,16f628a
,16f648a
652 16068721:16f687
,16f689
656 16072021:16f720
,16f721
657 16072221:16f722
,16f722a
,16f723
,16f723a
,16f726
658 16072421:16f724
,16f727
659 16073721:16f737
,16f747
,16f767
,16f777
660 16075321:16f753
,16hv753
662 16081821:16f818
,16f819
663 16087021:16f870
,16f871
664 16087321:16f873
,16f874
,16f876
,16f877
665 16087321:16f873a
,16f874a
,16f876a
,16f877a
666 16088221:16f882
,16f883
,16f886
667 16088421:16f884
,16f887
668 16091321:16f913
,16f916
669 16091421:16f914
,16f917
,16f946
675 16150821:16f1508
,16f1509
676 16151221:16f1512
,16f1513
,16f1516
,16f1518
677 16151721:16f1517
,16f1519
680 16170421:16f1704
,16f1705
,16lf
1704
682 16170821:16f1708
,16lf
1708
684 16171321:16f1713
,16f1716
,16f1718
685 16171721:16f1717
,16f1719
686 16178221:16f1782
,16f1783
687 16178421:16f1784
,16f1787
695 16182721:16f1827
,16f1847
698 16193321:16f1933
,16f1936
,16f1938
699 16193421:16f1934
,16f1937
,16f1939
700 16194621:16f1946
,16f1947
709 16006330:16c63a
,16c65b
711 16007330:16c73b
,16c74b
,16f73
,16f74
,16f76
,16f77
712 16071730:16c717
,16c770
,16c771
713 16077330:16c773
,16c774
714 16092530:16c925
,16c926
719 16068731:16f687
,16f689
,16f690
721 16072031:16f720
,16f721
722 16072231:16f722
,16f722a
,16f723
,16f723a
,16f726
723 16072431:16f724
,16f727
724 16073731:16f737
,16f747
,16f767
,16f777
725 16081831:16f818
,16f819
727 16087331:16f873
,16f874
,16f876
,16f877
728 16087331:16f873a
,16f874a
,16f876a
,16f877a
729 16088231:16f882
,16f883
,16f886
730 16088431:16f884
,16f887
731 16091331:16f913
,16f916
732 16091431:16f914
,16f917
,16f946
737 16150831:16f1508
,16f1509
738 16151231:16f1512
,16f1513
,16f1516
,16f1518
739 16151731:16f1517
,16f1519
740 16152631:16f1526
,16f1527
742 16170431:16f1704
,16f1705
,16lf
1704
744 16170831:16f1708
,16lf
1708
746 16171331:16f1713
,16f1716
,16f1718
747 16171731:16f1717
,16f1719
748 16178231:16f1782
,16f1783
749 16178431:16f1784
,16f1787
757 16182731:16f1827
,16f1847
760 16193331:16f1933
,16f1936
,16f1938
761 16193431:16f1934
,16f1937
,16f1939
762 16194631:16f1946
,16f1947
771 16006340:16c63a
,16c65b
773 16007340:16c73b
,16c74b
,16f73
,16f74
,16f76
,16f77
774 16071740:16c717
,16c770
,16c771
775 16077340:16c773
,16c774
776 16092540:16c925
,16c926
781 16068741:16f687
,16f689
,16f690
783 16072041:16f720
,16f721
784 16072241:16f722
,16f722a
,16f723
,16f723a
,16f726
785 16072441:16f724
,16f727
786 16073741:16f737
,16f747
,16f767
,16f777
787 16081841:16f818
,16f819
789 16087341:16f873
,16f874
,16f876
,16f877
790 16087341:16f873a
,16f874a
,16f876a
,16f877a
791 16088241:16f882
,16f883
,16f886
792 16088441:16f884
,16f887
793 16091341:16f913
,16f916
794 16091441:16f914
,16f917
,16f946
799 16150841:16f1508
,16f1509
800 16151241:16f1512
,16f1513
,16f1516
,16f1518
801 16151741:16f1517
,16f1519
802 16152641:16f1526
,16f1527
804 16170441:16f1704
,16f1705
,16lf
1704
806 16170841:16f1708
,16lf
1708
808 16171341:16f1713
,16f1716
,16f1718
809 16171741:16f1717
,16f1719
810 16178241:16f1782
,16f1783
811 16178441:16f1784
,16f1787
819 16182741:16f1827
,16f1847
822 16193341:16f1933
,16f1936
,16f1938
823 16193441:16f1934
,16f1937
,16f1939
824 16194641:16f1946
,16f1947
832 16006350:16c63a
,16c65b
833 16007350:16c73b
,16c74b
,16c745
,16c765
,16f73
,16f74
,16f76
,16f77
834 16077350:16c773
,16c774
837 16062751:16f627
,16f627a
,16f628
,16f628a
,16f648a
838 16068751:16f687
,16f689
,16f690
841 16072051:16f720
,16f721
842 16072251:16f722
,16f722a
,16f723
,16f723a
,16f726
843 16072451:16f724
,16f727
844 16073751:16f737
,16f747
,16f767
,16f777
845 16087051:16f870
,16f871
,16f873
,16f874
,16f876
,16f877
846 16087351:16f873a
,16f874a
,16f876a
,16f877a
847 16088251:16f882
,16f883
,16f886
848 16088451:16f884
,16f887
849 16091351:16f913
,16f916
850 16091451:16f914
,16f917
,16f946
854 16150851:16f1508
,16f1509
855 16151251:16f1512
,16f1513
,16f1516
,16f1518
856 16151751:16f1517
,16f1519
857 16152651:16f1526
,16f1527
858 16170451:16f1704
,16f1705
,16lf
1704
859 16170851:16f1708
,16lf
1708
861 16171351:16f1713
,16f1716
,16f1718
862 16171751:16f1717
,16f1719
863 16178251:16f1782
,16f1783
864 16178451:16f1784
,16f1787
871 16182651:16f1826
,16f1827
,16f1847
874 16193351:16f1933
,16f1936
,16f1938
875 16193451:16f1934
,16f1937
,16f1939
876 16194651:16f1946
,16f1947
879 16190451:16lf
1904,16lf
1907