dsp5680xx - indent fix
[openocd/dsp568013.git] / tools / rlink_make_speed_table / rlink_make_speed_table.pl
blob910fbf822cea578ff6af87b8ffe97ce25e9650cc
1 #!/bin/perl
2 #***************************************************************************
3 #* Copyright (C) 2008 Lou Deluxe *
4 #* lou.openocd012@fixit.nospammail.net *
5 #* *
6 #* This program is free software; you can redistribute it and/or modify *
7 #* it under the terms of the GNU General Public License as published by *
8 #* the Free Software Foundation; either version 2 of the License, or *
9 #* (at your option) any later version. *
10 #* *
11 #* This program is distributed in the hope that it will be useful, *
12 #* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 #* GNU General Public License for more details. *
15 #* *
16 #* You should have received a copy of the GNU General Public License *
17 #* along with this program; if not, write to the *
18 #* Free Software Foundation, Inc., *
19 #* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 #***************************************************************************
22 # A simple utility to read a list of files (names composed by numeric prescaler arguments) and compose a C source file defining data structures which hold the binary data read from those files.
24 my @speed_table = ();
26 print <<HEADER;
27 /* This file was created automatically by the following script:
28 * $0
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
34 #include "rlink.h"
35 #include "st7.h"
37 HEADER
39 for $prescaler (sort {$b <=> $a} @ARGV) {
40 my(@ary) = (
41 byte_array_from_file(${prescaler} . "_init.dtc"),
42 byte_array_from_file(${prescaler} . "_call.dtc")
45 for $i (@ary) {
46 $i = sprintf("%d", $i);
48 $bytes = join(', ', @ary);
49 $bytes =~ s/(^|\s)(.{70}?\S*)/\2\n/go; # break up long lines
50 $bytes =~ s/\n +/\n/go;
51 $bytes =~ s/(^|\n)/\1\t/go; # format nicely
52 printf("static const u8 dtc_%d[] = {\n%s\n};\n\n", $prescaler, $bytes);
53 push(@speed_table, sprintf("\tdtc_%d, sizeof(dtc_%d), (ST7_FOSC * 2) / (1000 * %d), %d\n", $prescaler, $prescaler, $prescaler, $prescaler));
56 printf("const rlink_speed_table_t rlink_speed_table[] = {{\n%s}};\n\n", join("}, {\n", @speed_table));
57 printf("const size_t rlink_speed_table_size = sizeof(rlink_speed_table) / sizeof(*rlink_speed_table);\n\n");
60 sub byte_array_from_file {
61 my($filename) = @_;
63 my(@array, $text, $i) = ();
65 open(IN, '<', $filename) || die "$filename: $!";
66 undef($/);
67 $text = <IN>;
68 close(IN);
70 for($i = 0; $i < length($text); $i++) {
71 push(@array, ord(substr($text, $i, 1)));
74 @array;