You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

76 lines
2.9 KiB

  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. #***************************************************************************
  21. # 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.
  22. my @speed_table = ();
  23. print <<HEADER;
  24. /* This file was created automatically by the following script:
  25. * $0
  26. */
  27. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30. #include "rlink.h"
  31. #include "st7.h"
  32. HEADER
  33. for $prescaler (sort {$b <=> $a} @ARGV) {
  34. my(@ary) = (
  35. byte_array_from_file(${prescaler} . "_init.dtc"),
  36. byte_array_from_file(${prescaler} . "_call.dtc")
  37. );
  38. for $i (@ary) {
  39. $i = sprintf("%d", $i);
  40. }
  41. $bytes = join(', ', @ary);
  42. $bytes =~ s/(^|\s)(.{70}?\S*)/\2\n/go; # break up long lines
  43. $bytes =~ s/\n +/\n/go;
  44. $bytes =~ s/(^|\n)/\1\t/go; # format nicely
  45. printf("static const u8 dtc_%d[] = {\n%s\n};\n\n", $prescaler, $bytes);
  46. push(@speed_table, sprintf("\tdtc_%d, sizeof(dtc_%d), (ST7_FOSC * 2) / (1000 * %d), %d\n", $prescaler, $prescaler, $prescaler, $prescaler));
  47. }
  48. printf("const rlink_speed_table_t rlink_speed_table[] = {{\n%s}};\n\n", join("}, {\n", @speed_table));
  49. printf("const size_t rlink_speed_table_size = sizeof(rlink_speed_table) / sizeof(*rlink_speed_table);\n\n");
  50. sub byte_array_from_file {
  51. my($filename) = @_;
  52. my(@array, $text, $i) = ();
  53. open(IN, '<', $filename) || die "$filename: $!";
  54. undef($/);
  55. $text = <IN>;
  56. close(IN);
  57. for($i = 0; $i < length($text); $i++) {
  58. push(@array, ord(substr($text, $i, 1)));
  59. }
  60. @array;
  61. }