In packing the structure, just beware of ALWAYS aligning a word
variable to an even address, otherwise you'll end up in a mess.
As a matter of fact, if you call a word instruction (like mov.w) with
a word argument aligned at an odd address, the msp430 will zero out
the most significant byte of the word.

R#

2009/7/24 Frank Harvey <[email protected]>:
> I added arg -fpack-struct to the msp430-gcc command and the addresses started 
> incrementing by 1 as you would expect.
>
> msp430-gcc -S -fpack-struct main.c
>
> The problem smells like an old one I encountered on other machines where the 
> structs are actually the size you'd think - but, when something goes to 
> assign memory addresses to them, it pads the length to make it come out to 
> the next word boundary. This is generally "a speed thing" but it plays havoc 
> if you're trying to exactly map a set of structs over a just-arrived 
> communications message.
>
> frank
>
>
> --- On Wed, 7/22/09, Stephen Douthit <[email protected]> wrote:
>
>> From: Stephen Douthit <[email protected]>
>> Subject: Re: [Mspgcc-users] problem with iomacros.h
>> To: "GCC for MSP430 - http://mspgcc.sf.net"; 
>> <[email protected]>
>> Date: Wednesday, July 22, 2009, 7:58 PM
>> On Wed, Jul 22, 2009 at 4:06 AM,
>> Rainer Haape <[email protected]>
>> wrote:
>>
>> > Hello,
>> > I have a problem with iomacros.h under linux with the
>> latest Versions of
>> > mspgcc.
>> > All ioregisters seem to be 16 Bit instead of 8 Bit, so
>> all but one adresses
>> > are wrong.
>> > The following lines in c:
>> >
>> > #include <msp430x16x.h>
>> > #include <iomacros.h>
>> >
>> > int main (void)
>> > {
>> >  char i;
>> >  i = port1.in.pin1;
>>     // 0x0020
>> >  port1.out.pin1 = 1;
>>    // 0x0021
>> >  port1.dir.pin1 = 1;
>>    // 0x0022
>> >  i = port1.ifg.pin1;
>>    // 0x0023
>> >  port1.ie.pin1 = 1;
>>     // 0x0025
>> >  port1.ies.pin1 = 1;
>>    // 0x0024
>> >  port1.sel.pin1 = 1;
>>    // 0x0026
>> > }
>> >
>> > were compiled to:
>> > --- snip ---
>> >
>> > int main (void)
>> > {
>> >    4036:       31
>> 40 00 39     mov
>>    #14592, r1      ;#0x3900
>> >  char i;
>> >  i = port1.in.pin1;
>> >    403a:       e2
>> b3 20 00
>>    bit.b   #2,
>>    &0x0020 ;r3 As==10
>> >    403e:       4f
>> 43
>>    clr.b   r15
>> >    4040:       4f
>> 63
>>    adc.b   r15
>> >  port1.out.pin1 = 1;
>> >    4042:       e2
>> d3 22 00
>>    bis.b   #2,
>>    &0x0022 ;r3 As==10
>> >  port1.dir.pin1 = 1;
>> >    4046:       e2
>> d3 24 00
>>    bis.b   #2,
>>    &0x0024 ;r3 As==10
>> >  i = port1.ifg.pin1;
>> >    404a:       e2
>> b3 26 00
>>    bit.b   #2,
>>    &0x0026 ;r3 As==10
>> >    404e:       4f
>> 43
>>    clr.b   r15
>> >    4050:       4f
>> 63
>>    adc.b   r15
>> >  port1.ie.pin1 = 1;
>> >    4052:       e2
>> d3 2a 00
>>    bis.b   #2,
>>    &0x002a ;r3 As==10
>> >  port1.ies.pin1 = 1;
>> >    4056:       e2
>> d3 28 00
>>    bis.b   #2,
>>    &0x0028 ;r3 As==10
>> >  port1.sel.pin1 = 1;
>> >    405a:       e2
>> d3 2c 00
>>    bis.b   #2,
>>    &0x002c ;r3 As==10
>> > }
>> >
>> > --- snip ---
>> >
>> > What is going wrong?
>> >
>> > Thank you in advance,
>> > Rainer Haape
>> > [email protected]
>> >
>> >
>> >
>> >
>> ------------------------------------------------------------------------------
>> > _______________________________________________
>> > Mspgcc-users mailing list
>> > [email protected]
>> > https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>> >
>>
>>
>> I built the mspgcc toolchain on a Debian(Lenny) setup a few
>> days ago, but
>> hadn't tried it out until I saw your message.
>>
>> I got the same results you did, but after poking around the
>> code a little I
>> don't think there's anything wrong in iomacros.h.
>> Instead, it looks like
>> for some reason the ioregister_t union from
>> msp430/iostructures.h is getting
>> compled to twice the expected size.
>>
>> #include <msp430/iostructures.h>
>>
>> void main (void)
>> {
>>   char i;
>>   i=sizeof(char);
>>   i=sizeof(ioregister_t);
>> }
>>
>> compiles to:
>>
>> void main (void)
>> {
>>     fc36:       31 40 7e
>> 02     mov
>>    #638,   r1
>>   ;#0x027e
>>     fc3a:       04
>> 41           mov
>>    r1,     r4
>>   char i;
>>   i=sizeof(char);
>>     fc3c:       d4 43 00
>> 00     mov.b   #1,
>>    0(r4)   ;r3 As==01,
>> 0x0000(r4)
>>   i=sizeof(ioregister_t);
>>     fc40:       e4 43 00
>> 00     mov.b   #2,
>>    0(r4)   ;r3 As==10,
>> 0x0000(r4)
>> }
>>
>> googling for mspgcc union errors gave me a bunch of reports
>> of misaligned
>> int reads from int/char unions, but nothing about the size
>> of the union
>> going haywire.
>>
>> Has anyone else seen/fixed this?
>>
>> Thanks,
>> Steve
>>
>> -----Inline Attachment Follows-----
>>
>> ------------------------------------------------------------------------------
>>
>> -----Inline Attachment Follows-----
>>
>> _______________________________________________
>> Mspgcc-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Mspgcc-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>

Reply via email to