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.
 
 
 
 
 
 

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