OpenCores
URL https://opencores.org/ocsvn/rs232_syscon/rs232_syscon/trunk

Subversion Repositories rs232_syscon

[/] [rs232_syscon/] [web_uploads/] [srec_to_rs232.pl] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 root
#!/usr/bin/perl -w
2
print "\nMotorola S-record to rs232_syscon command translator.";
3
print "\nFilename to translate? ";
4
$filename = <STDIN>;
5
chomp ($filename);
6
print "\nReading file \"$filename\"\n";
7
open (SRECORDFILE,$filename) ||
8
  die "\nCan't open \"$filename\" for input.\n";
9
 
10
# Handle getting a new extension for the output filename
11
$i = index($filename,".");
12
   # If no period is found, simply add the extension to the end.
13
if ($i < 0) { $i = length($filename); }
14
substr($filename,$i,4) = ".232";
15
 
16
# Open the output file
17
open (OUTPUTFILE,">".$filename) ||
18
  die "\nCan't open \"$filename\" for output.\n";
19
 
20
$line_number = 0;
21
while ($line = <SRECORDFILE>) {
22
  # increment the line number counter
23
  $line_number += 1;
24
  # ignore lines that begin with semicolon
25
  if (index($line,";")==0) { next; }
26
  # Get the position of the start of data
27
  # (Usually there is a colon at the very start of the line...)
28
  $i = index($line,":");
29
  if ($i < 0) {
30
    print "\nError!  No colon found on line: $line_number";
31
    last;
32
    }
33
  # Get the length of the line
34
  $line_length = hex(substr($line,($i+1),2));
35
  if ($line_length == 0) {
36
    print "0";
37
    next;
38
    }
39
 
40
  # Extract the starting address
41
  $line_starting_address = hex(substr($line,($i+3),4));
42
 
43
  # Extract the data substring - length is in units of bytes,
44
  # but each character is 1/2 byte, so multiply by 2.
45
  $line_data = substr($line,($i+9),($line_length*2));
46
 
47
  # Send data characters to output file as rs232_syscon commands
48
  # increment by 2 in order to send 1 byte per command...
49
  for ($i=0;$i<($line_length*2);$i+=2) {
50
    $j = $line_starting_address + $i/2;
51
    $j = sprintf "%lx",$j;  # Convert address to hexadecimal
52
    $byte = substr($line_data,$i,2);
53
    print OUTPUTFILE "w $j $byte\n";
54
  }
55
 
56
# Verbose debug information...
57
#  print "\nline $line_number: starts at $line_starting_address ";
58
#  print "length is $line_length ";
59
#  print "data is $line_data ";
60
  # Print a little period for each line processed...
61
  # (to complement the 0 printed for zero length lines encountered.)
62
  print ".";
63
  }
64
 
65
#Close all open files
66
close (SRECORDFILE);
67
close (OUTPUTFILE);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.