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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [tools/] [bin/] [hex2abs12] - Blame information for rev 21

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 12 bit verilog readmemh format   */
15
#/*                                                                    */
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  = ${prog_name}.".abs12";
90
 
91
 
92
  print "Reading hex File  $input_file\n";
93
  print "Writing abs File  $output_file\n";
94
 
95
 
96
  open  VERILOG , ">  $output_file";
97
  open   FILE, $input_file;
98
 
99
  open  DEFINES , ">  ROM_defines.v";
100
 
101
  while(){push @intel_hex, $_  ;}
102
 
103
 
104
#############################################################################
105
##
106
##  Clear a storage area for the 12 bit words
107
##
108
#############################################################################
109
 
110
 
111
   my  $x=0;
112
      while( $x <= 65535)
113
           {
114
           @Mem[$x] = "000";
115
            $x = $x+1;
116
           }
117
 
118
 
119
#############################################################################
120
##
121
##  Parse Data  into storage converting from 8 bit bytes to 16 bit words
122
##
123
#############################################################################
124
 
125
my  $pointer     = 0;
126
my $max_pointer = 0;
127
my $start_address = 65536;
128
 
129
 
130
  foreach $line (@intel_hex)
131
    {
132
    $colon     = substr($line, 0,1);
133
    $length    = (cvt(substr($line, 1,1))* 16) +   cvt(substr($line, 2,1));
134
    $address   = cvt(substr($line, 3,1));
135
    $address   = cvt(substr($line, 4,1))+($address *16)  ;
136
    $address   = cvt(substr($line, 5,1))+($address *16)  ;
137
    $address   = cvt(substr($line, 6,1))+($address *16)  ;
138
    $type      = substr($line, 7,2);
139
 
140
 
141
 
142
    if(($type eq  "00")          )
143
 
144
      {
145
      if( $address <= $start_address) {$start_address = $address;}
146
      $x=9;
147
      while( $x <= 7+($length *2))
148
           {
149
           $value_E = substr($line, $x,2);
150
           $value_O = substr($line, $x+3,1);
151
           $pointer = (($address/2) +($x-9)/4);
152
           if( $pointer > $max_pointer ) {$max_pointer = $pointer}
153
           @Mem[$pointer] = $value_O.$value_E;
154
           $x= $x+4;
155
           }
156
 
157
 
158
     }
159
 
160
 
161
 
162
 
163
    }
164
 
165
 
166
#############################################################################
167
##
168
##  dump out up to the last word, undefined space is 000
169
##
170
#############################################################################
171
 
172
      $x = ($start_address/2);
173
      while( $x <= ($max_pointer))
174
           {
175
           printf VERILOG ("%s\n",@Mem[$x]);
176
           $x = $x+1;
177
           }
178
 
179
 
180
        $words =  ($max_pointer) - ($start_address/2)+1;
181
       printf DEFINES ("`define PROG_FILE  /${prog_name}.abs12\n"  );
182
       printf DEFINES ("`define ROM_WIDTH 12\n"  );
183
       printf DEFINES ("`define ROM_WORDS $words \n"  );
184
 
185
 
186
#############################################################################
187
##
188
##  convert 0-9,A-F to decimal or 0 if out of range
189
##
190
#############################################################################
191
 
192
 
193
sub cvt {
194
 
195
$temp =    ord($_[0]);
196
if( $temp <= 48) { return 0 }
197
if( $temp <= 58) { return $temp - 48 }
198
if( $temp <= 64) { return 0 }
199
if( $temp <= 70) { return ($temp - 65)+10 }
200
return 0;
201
 
202
 
203
 
204
}
205
 
206
 
207
 
208
 
209
1
210
 
211
 

powered by: WebSVN 2.1.0

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