At 04:40 PM 4/29/06 +0000, rtstofer wrote:
>I had the same problem when I ported the FAT code from AVRLib to my
>LPC2106 project. I went with the non-portable approach:
>
>struct bootsector710 {
> unsigned int bsJump:24;
> unsigned char bsOEMName[8];
> unsigned char bsBPB[53];
> unsigned char bsExt[26];
> unsigned char bsBootCode[418];
> unsigned char bsBootSectSig2;
> unsigned char bsBootSectSig3;
> unsigned char bsBootSectSig0;
> unsigned char bsBootSectSig1;
>#define BOOTSIG0 0x55
>#define BOOTSIG1 0xaa
>#define BOOTSIG2 0
>#define BOOTSIG3 0
>} __attribute__ ((packed)); <=== non-portable
>
>I didn't have the ability to change the structure - that's the way the
>data is set out on the disk.
>
>These structs are defined and accessed in a single source file. I can
>live with it.
Which leads to a third semi-portable possibility
struct bootsectorport {
unsigned int bsJump:24;
unsigned char bsOEMName[8];
unsigned char bsBPB[53];
unsigned char bsExt[26];
unsigned char bsBootCode[418];
unsigned char bsBootSectSig2;
unsigned char bsBootSectSig3;
unsigned char bsBootSectSig0;
unsigned char bsBootSectSig1;
};
struct bootsector710 a;
struct bootsectorport b;
And to convert from a to b
b.bsJump = a.bsJump;
memcpy( b.bsOEMName, a.bsOEMName, sizeof(b.bsOEMName));
etc..
A little cleaner looking than massaging byte by byte. You have to change
how you define the packed structure when porting but that can be confined
to a small area. Not truly portable but it covers a lot of cases.
Robert
" 'Freedom' has no meaning of itself. There are always restrictions, be
they legal, genetic, or physical. If you don't believe me, try to chew a
radio signal. " -- Kelvin Throop, III
http://www.aeolusdevelopment.com/Message
Re: [lpc2000] Re: LPC2148 and words on odd addresses.
2006-04-29 by Robert Adsett
Attachments
- No local attachments were found for this message.