Re: byte data manipulation
- From: Joe Wright <joewwright@xxxxxxxxxxx>
- Date: Sun, 26 Apr 2009 13:24:09 -0400
Niv (KP) wrote:
On 25 Apr, 15:40, Ben Bacarisse <ben.use...@xxxxxxxxx> wrote:"Niv (KP)" <kev.pars...@xxxxxxxxxxxxxxxx> writes:
<snip>
Right, more details:Here you mean you don't access array_1 sequentially, yes? That
1. I what to create 2 arrays of 2Mbytes each.
2. Read in the input hex file, stripping of the preamble and checksum
bits, and putting the bytes (2 chars) into array_1.
3. Copy array_1 data to array_2, but in a non-linear fashion, using
lfsr or some such.
explains why you need the array.
4. Write out array_2 in a linear address fashion, adding the preambleEach line has 15 data bytes (30 hex chars) and one byte of checksum?
(easy) and calculating a new checksum for each line, where the new
output lines have 16 bytes (32 chars). The checksum is just the 8 bit
sum of the preceding values in the preamble and the 16 bytes,
discarding overflows.
If so, may not need array_2 at all. The output of the LFSR[1] can be
checksumed as you go and the output generated on the fly. Of course
there may be a reason to copy the data, but its not clear from the
description so far.
Is that enough info?Except for what bit you are having trouble with. I can offer a few
tips. Use unsigned char for the array (it will avoid problems with
bit-operations if char is signed on your system). Allocate it using
malloc since the size is not know until run-time:
unsigned char *buffer = malloc(<size in bytes goes here>);
The simplest way to read two hex chars and put the result into a
single byte is:
fscanf(file, "%2hhx", buffer + pos);
and increment pos as you go. The result of both malloc and fscanf
should be checked. If malloc returns NULL, the allocation failed.
If fscanf does not return 1 it did not read a number.
[1] Linear feedback shift register.
--
Ben.
The input file is in intel format "hexout", as follows;
colon, 1 byte data length, 2 bytes address, 1 byte data type, <length>
dtat bytes, checksum byte; all in hex,
e.g. : 20 0010 00 <32 data bytes> <checksum> (all without spaces
of course).
I need to read in all the data bytes, up to 2 meg, into an array, re-
arrange that array, easiest to copy to another array by indexing the
array pointer in a non-linear fashion, then write out the full 2 meg
of the new array, again in an intel format, with only 16 data bytes
per line. So, I'll need to calculate the new checksum over the length
byte, address bytes, type byte and data bytes; where the csum is just
the hex sum of all these, ignoring any carry.
Like I said, I have a fully working version in VHDL, which takes about
30 seconds to run, but ties up a simulator, if one was avaialable. So
I think an exe file is better. I can wrap the exe in a tcl frame to
get the input and output files/destination etc, but my C knowledge is
virtually nil. Trying to read "teach yourself in 24 hrs" but i need a
quick answer really, haven't got time to waste on learning allof C
right now, although I shall persevere with the learning!
Respectfully, you don't know what you need to know. Get this. It is the Intel Specification for the hex files you have.
http://microsym.com/editor/assets/intelhex.pdf
GIYF
--
Joe Wright
"Memory is the second thing to go. I forget what the first is."
.
- References:
- byte data manipulation
- From: Niv (KP)
- Re: byte data manipulation
- From: James Kuyper
- Re: byte data manipulation
- From: Niv (KP)
- Re: byte data manipulation
- From: Ben Bacarisse
- Re: byte data manipulation
- From: Niv (KP)
- byte data manipulation
- Prev by Date: Re: A lurker's take on C.L.C pedantry
- Next by Date: Re: Float comparison
- Previous by thread: Re: byte data manipulation
- Next by thread: Re: byte data manipulation
- Index(es):
Relevant Pages
|