Any way to force a byte array to start on a long 'border'?
homosapien
Posts: 147
I may be missing the obvious, but I am transferring data from EEPROM to a byte array in long-sized chunks (using longs for faster transfer than byes) using something like:
Is there any way to force SPIN to make the 'dataBuffer' array start on a long 'border'? (there may be other byte/word sized vars in the DAT section that change the position of the array). Currently I run the program and if the buffer is missing data due to non-long-alignment, I just add byte-sized vars in front of it to even it out. Is there a more elegant method to do this?
I know one can use this syntax to make a byte-sized array be long aligned:
But as far as I can tell this syntax seems to make the array use every fourth byte in memory, which I do NOT want due to memory constraints.
Thanks for any input,
Nate
DAT dataBuffer byte $0[100] 'buffer for ASCII data VAR long longsData 'holds length (in longs) of data stream PUB getIt | x repeat x from 0 to (longsData/4) long[@dataBuffer][x] := I2C.Readlong(P_EEPROM_SCL, $A0, EEPROM_ADDR_BASE + x*4)
Is there any way to force SPIN to make the 'dataBuffer' array start on a long 'border'? (there may be other byte/word sized vars in the DAT section that change the position of the array). Currently I run the program and if the buffer is missing data due to non-long-alignment, I just add byte-sized vars in front of it to even it out. Is there a more elegant method to do this?
I know one can use this syntax to make a byte-sized array be long aligned:
DAT byte long dataBuffer
But as far as I can tell this syntax seems to make the array use every fourth byte in memory, which I do NOT want due to memory constraints.
Thanks for any input,
Nate
Comments
Where lidx is the long index used to control the loop. Index 0 would fill bytes 0..3, 1 would fill 4..7, etc. I often use bytemove this way.
After thinking about a bit, I think something like this would do what I want (doing the transfer from EEPROM to byte array as fast as possible), while only using up/wasting 1 long:
No?
I usually use the VAR sections to define my (global) variables. It is my understanding that the the variables from a VAR section and a DAT section are the same except:
1) You can seed the vars in the DAT section.
2) DAT variables are shared among all instances of the object that defines them.
3) Apparently, the compiler does what you said WRT to the ordering in memory.
4) It is impossible to know for sure where in main memory any VAR or DAT variable will be located until the program is compiled. Then, if you know where one IN THE DAT sections is, you could count up/down to find the location of any other variable IN THE SAME DAT section.
5) ANY variable in the VAR section would need to be located using the @ sign, even after compiling.
Is this pretty much it?
So, I think you are saying I could do something like this (and save a little typing over what I had before):
I am just wondering, as the Propeller Tool that I am using is turning the screen a different shade of green at the 'l' of the second long, as if it thinks this is a new DAT section... It may be a glitch, I'll see if it complies and runs...
Nate
For that matter the first byte of each DAT section is guaranteed to be long-aligned, so if your byte array is the first thing after a DAT it should be aligned.
While VARs are separated by type, within each type I think they are arranged in memory in the order they are declared, so within a type you should be able to use @ to locate the first of a group of named vars and then calculate where the others are from that.
Nate
Andy
Would that also work with WORD for word alignment?
(Assuming a bunch of bytes had been declared)
That said, the byte array could also be specified as a word/long array (forced alignment) and the elements then accessed as label.byte[idx] (byte elements).