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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [tools/] [bin/] [hex2abs_split] - Blame information for rev 119

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

Line No. Rev Author Line
1 20 jt_eaton
eval 'exec `which perl` -S $0 ${1+"$@"}'
2
   if 0;
3
 
4
#/**********************************************************************/
5
#/*                                                                    */
6
#/*             -------                                                */
7
#/*            /   SOC  \                                              */
8
#/*           /    GEN   \                                             */
9
#/*          /    TOOL    \                                            */
10
#/*          ==============                                            */
11
#/*          |            |                                            */
12
#/*          |____________|                                            */
13
#/*                                                                    */
14
#/*  Converts a intel hex file into a 16 bit verilog readmemh format   */
15
#/*  split into 8 bit even and 8 bit odd files                         */
16
#/*                                                                    */
17
#/*  Author(s):                                                        */
18
#/*      - John Eaton, jt_eaton@opencores.org                          */
19
#/*                                                                    */
20
#/**********************************************************************/
21
#/*                                                                    */
22
#/*    Copyright (C) <2010>                     */
23
#/*                                                                    */
24
#/*  This source file may be used and distributed without              */
25
#/*  restriction provided that this copyright statement is not         */
26
#/*  removed from the file and that any derivative work contains       */
27
#/*  the original copyright notice and the associated disclaimer.      */
28
#/*                                                                    */
29
#/*  This source file is free software; you can redistribute it        */
30
#/*  and/or modify it under the terms of the GNU Lesser General        */
31
#/*  Public License as published by the Free Software Foundation;      */
32
#/*  either version 2.1 of the License, or (at your option) any        */
33
#/*  later version.                                                    */
34
#/*                                                                    */
35
#/*  This source is distributed in the hope that it will be            */
36
#/*  useful, but WITHOUT ANY WARRANTY; without even the implied        */
37
#/*  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR           */
38
#/*  PURPOSE.  See the GNU Lesser General Public License for more      */
39
#/*  details.                                                          */
40
#/*                                                                    */
41
#/*  You should have received a copy of the GNU Lesser General         */
42
#/*  Public License along with this source; if not, download it        */
43
#/*  from http://www.opencores.org/lgpl.shtml                          */
44
#/*                                                                    */
45
#/**********************************************************************/
46
 
47
# ToDO: add handling unaligned words
48
 
49
 
50
############################################################################
51
# General PERL config
52
############################################################################
53
use Getopt::Long;
54
use English;
55
use File::Basename;
56
 
57
$OUTPUT_AUTOFLUSH = 1; # set autoflush of stdout to TRUE.
58
 
59
 
60
############################################################################
61
### Process the options
62
############################################################################
63
 
64
Getopt::Long::config("require_order", "prefix=-");
65
GetOptions("h"
66
) || die "(use '$program_name -h' for help)";
67
 
68
 
69
##############################################################################
70
## Help option
71
##############################################################################
72
if ( ($opt_h eq "1") )
73
  { print "\n type test filename ( no extension)";
74
    print "\n";
75
    exit 1;
76
  }
77
 
78
 
79
 
80
#############################################################################
81
##
82
##  open intel hex  file  and read into array
83
##
84
#############################################################################
85
 
86
  my $prog_name         = $ARGV[0];
87
 
88
  my $input_file   = ${prog_name}.".hex";
89
  my $output_file_e  = ${prog_name}.".absE";
90
  my $output_file_o  = ${prog_name}.".absO";
91
 
92
  print "Reading hex File  $input_file\n";
93
  print "Writing abs File  $output_file_e\n";
94
  print "Writing abs File  $output_file_o\n";
95
 
96
  open  VERILOG_E , ">  $output_file_e";
97
  open  VERILOG_O , ">  $output_file_o";
98
  open   FILE, $input_file;
99
 
100
  open  DEFINES , ">  ROM_defines.v";
101
 
102
  while(){push @intel_hex, $_  ;}
103
 
104
 
105
#############################################################################
106
##
107
##  Clear a storage area for the 16 bit words
108
##
109
#############################################################################
110
 
111
 
112
   my  $x=0;
113
      while( $x <= 65535)
114
           {
115
           @Mem_e[$x] = "00";
116
           @Mem_o[$x] = "00";
117
            $x = $x+1;
118
           }
119
 
120
 
121
#############################################################################
122
##
123
##  Parse Data  into storage converting from 8 bit bytes to 16 bit words
124
##
125
#############################################################################
126
 
127
my  $pointer     = 0;
128
my $max_pointer = 0;
129
my $start_address = 65536;
130
 
131
 
132
  foreach $line (@intel_hex)
133
    {
134
    $colon     = substr($line, 0,1);
135
    $length    = (cvt(substr($line, 1,1))* 16) +   cvt(substr($line, 2,1));
136
    $address   = cvt(substr($line, 3,1));
137
    $address   = cvt(substr($line, 4,1))+($address *16)  ;
138
    $address   = cvt(substr($line, 5,1))+($address *16)  ;
139
    $address   = cvt(substr($line, 6,1))+($address *16)  ;
140
    $type      = substr($line, 7,2);
141
 
142
 
143
 
144
    if(($type eq  "00")          )
145
 
146
      {
147
      if( $address <= $start_address) {$start_address = $address;}
148
      $x=9;
149
      while( $x <= 7+($length *2))
150
           {
151
           $value_E = substr($line, $x,2);
152
           $value_O = substr($line, $x+2,2);
153
           $pointer = (($address/2) +($x-9)/4);
154
           if( $pointer > $max_pointer ) {$max_pointer = $pointer}
155
           @Mem_e[$pointer] = $value_E;
156
           @Mem_o[$pointer] = $value_O;
157
           $x= $x+4;
158
           }
159
 
160
 
161
     }
162
 
163
 
164
 
165
 
166
    }
167
 
168
 
169
#############################################################################
170
##
171
##  dump out up to the last word, undefined space is 000
172
##
173
#############################################################################
174
 
175
      $x = ($start_address/2);
176
      while( $x <= ($max_pointer))
177
           {
178
           printf VERILOG_E (" %s\n",@Mem_e[$x]);
179
           printf VERILOG_O (" %s\n",@Mem_o[$x]);
180
           $x = $x+1;
181
           }
182
 
183
 
184
        $words =  ($max_pointer) - ($start_address/2)+1;
185
       printf DEFINES ("`define PROG_FILE  /${prog_name}.abs16\n"  );
186
       printf DEFINES ("`define ROM_WIDTH 16\n"  );
187
       printf DEFINES ("`define ROM_WORDS $words \n"  );
188
 
189
 
190
#############################################################################
191
##
192
##  convert 0-9,A-F to decimal or 0 if out of range
193
##
194
#############################################################################
195
 
196
 
197
sub cvt {
198
 
199
$temp =    ord($_[0]);
200
if( $temp <= 48) { return 0 }
201
if( $temp <= 58) { return $temp - 48 }
202
if( $temp <= 64) { return 0 }
203
if( $temp <= 70) { return ($temp - 65)+10 }
204
return 0;
205
 
206
 
207
 
208
}
209
 
210
 
211
 
212
 
213
1
214
 
215
 

powered by: WebSVN 2.1.0

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