 | | From: | Peng | | Subject: | Efficient and elegant way to access memory | | Date: | Tue, 11 Jan 2005 21:16:04 +0000 |
|
|
 | Dear all,
I am a new student to ARM C. In my program, I need to access memory locations very often, here is my way of doing so.
volatile char * ip = (char*) 0x08000000; *ip = 100; printf("%x, %x", *ip, *(ip+1));
This works, but I know this looks very very ugly. I can't think of anything else to make it look good.
Also, I can't change a single bit in a byte very easily. What's the easiest way to do so?
Please help. Thanks very much.
Peng
|
|
 | | From: | Mayank Kaushik | | Subject: | Re: Efficient and elegant way to access memory | | Date: | 12 Jan 2005 06:57:18 -0800 |
|
|
 | well, u cud do this:
> Also, I can't change a single bit in a byte very easily. What's the > easiest way to do so?
to clear a byte: (here mask has a 1 in the position u want to touch, all others are zeroes)
bytetochange &= (~mask);
to set it:
bytetochange |= (mask);
but i guess this is not what ure looking for..
In the arm9 based at91rm9200 i work with, some of the ports have "output set" and "output reset" registers, so i can set or reset a particular bit by just writing at the correct place..
also, what does this do? >unsigned char _PA0:1; the colon, i mean..this must be compiler specific.. >}PORTA1 @(0x00); this line too.
|
|
 | | From: | fanpengyuan at gmail.com | | Subject: | Re: Efficient and elegant way to access memory | | Date: | 18 Jan 2005 13:10:45 -0800 |
|
|
 | Mayank Kaushik wrote: > to clear a byte: > (here mask has a 1 in the position u want to touch, all others are > zeroes) > > bytetochange &= (~mask); > > to set it: > > bytetochange |= (mask); > > but i guess this is not what ure looking for..
Not really. > > In the arm9 based at91rm9200 i work with, some of the ports have > "output set" and "output reset" registers, so i can set or reset a > particular bit by just writing at the correct place.. > > also, what does this do? > >unsigned char _PA0:1; > the colon, i mean..this must be compiler specific.. > >}PORTA1 @(0x00); > this line too.
Yes... They must be compiler specific. Is there a similar syntax for ARM compiler?
Thanks.
|
|
 | | From: | Sprow | | Subject: | Re: Efficient and elegant way to access memory | | Date: | Wed, 19 Jan 2005 20:38:30 GMT |
|
|
 | In article <1106082645.093620.94340@c13g2000cwb.googlegroups.com>, wrote: > Mayank Kaushik wrote: > > to clear a byte: > > (here mask has a 1 in the position u want to touch, all others are > > zeroes) > > > > bytetochange &= (~mask); > > > > to set it: > > > > bytetochange |= (mask); > > > > but i guess this is not what ure looking for.. > > Not really. > > > > In the arm9 based at91rm9200 i work with, some of the ports have > > "output set" and "output reset" registers, so i can set or reset a > > particular bit by just writing at the correct place.. > > > > also, what does this do? > > >unsigned char _PA0:1; > > the colon, i mean..this must be compiler specific..
Lookup "bitfields" in your C compiler reference.
> Yes... They must be compiler specific. Is there a similar syntax for > ARM compiler?
Lookup "bitfields" in your C compiler reference. Sprow.
|
|
 | | From: | Rob Fell | | Subject: | Re: Efficient and elegant way to access memory | | Date: | Thu, 20 Jan 2005 09:28:30 +0000 |
|
|
 | Sprow wrote:
> Lookup "bitfields" in your C compiler reference.
> Lookup "bitfields" in your C compiler reference.
But don't _ever_ use them :) It's non-portable.
|
|
 | | From: | Wilco Dijkstra | | Subject: | Re: Efficient and elegant way to access memory | | Date: | Thu, 20 Jan 2005 11:02:01 GMT |
|
|
 | "Rob Fell" wrote in message news:csntjs$jo1$1@cam-news1.cambridge.arm.com... > Sprow wrote: > > > Lookup "bitfields" in your C compiler reference. > > > > > Lookup "bitfields" in your C compiler reference. > > But don't _ever_ use them :) It's non-portable.
Bitfield semantics is perfectly portable since most compilers can switch between signed/unsigned containers. Bitfield layout is not portable. However the ARM EABI defines many things the C standard left out, and so bitfield layout is/will be portable between most compilers that target ARM. Extensions to place data in specific sections or at specific addresses are not portable of course, however they are needed by most applications.
Wilco
|
|
 | | From: | Rob Fell | | Subject: | Re: Efficient and elegant way to access memory | | Date: | Thu, 20 Jan 2005 11:47:14 +0000 |
|
|
 | Wilco Dijkstra wrote:
> Bitfield layout is not portable.
How true.
> However the ARM EABI defines many things the > C standard left out, and so bitfield layout is/will be portable > between most compilers that target ARM.
That's wonderful if the code you're writing will only ever run on an ARM. If you want _portable_ code bitfields are best avoided.
|
|
 | | From: | Peng | | Subject: | Re: Efficient and elegant way to access memory | | Date: | Tue, 11 Jan 2005 21:24:57 +0000 |
|
|
 | Peng wrote:
> Also, I can't change a single bit in a byte very easily. What's the > easiest way to do so? > To clarify my question, I have found an example for Motolora CPU.
<-- code --> extern volatile union{ struct{ unsigned char _PA0:1; unsigned char _PA1:1; unsigned char _PA2:1; unsigned char _PA3:1; unsigned char _PA4:1; unsigned char _PA5:1; unsigned char _PA6:1; unsigned char _PA7:1; } PORTA_BITS; unsigned char PORTA_BYTE; }PORTA1 @(0x00);
PORTA1 = 0x0800000;
#define PORTA PORTA1.PORTA_BYTE
#define PA0 PORTA1.PORTA_BITS._PA0 #define PA1 PORTA1.PORTA_BITS._PA1 #define Dir PORTA1.PORTA_BITS._PA2 #define A0 PORTA1.PORTA_BITS._PA3 #define nRST PORTA1.PORTA_BITS._PA4 #define nCS PORTA1.PORTA_BITS._PA5 #define nWR PORTA1.PORTA_BITS._PA6 #define nRD PORTA1.PORTA_BITS._PA7
<-- code end -->
In this way, I can read or write to a single big in the byte through PA0 to nRD, as well as to the whole byte with PORTA_BYTE.
I have tried this with ARM. It couldn't compile because of the line: }PORTA1 @(0X00); I think this is for Motolora only. True?
Any alternatives for similar way in ARM?
Thank you.
|
|
 | | From: | Peng | | Subject: | Re: Efficient and elegant way to access memory | | Date: | 20 Jan 2005 06:00:01 -0800 |
|
|
 | Rob Fell wrote: > Wilco Dijkstra wrote: > > > Bitfield layout is not portable. > > How true. > > > However the ARM EABI defines many things the > > C standard left out, and so bitfield layout is/will be portable > > between most compilers that target ARM. > > That's wonderful if the code you're writing will only ever run on an > ARM. If you want _portable_ code bitfields are best avoided.
Where can I find information about EABI online? It seems it's not on www.arm.com.
Also, I have found macros to set/unset single bits. http://www.somacon.com/blog/page25.php
Sorry if you already knew this.
|
|
 | | From: | Wilco Dijkstra | | Subject: | Re: Efficient and elegant way to access memory | | Date: | Thu, 20 Jan 2005 22:53:04 GMT |
|
|
 | "Peng" wrote in message news:1106229601.045045.26970@f14g2000cwb.googlegroups.com... > > Rob Fell wrote: > > Wilco Dijkstra wrote: > > > > > Bitfield layout is not portable. > > > > How true. > > > > > However the ARM EABI defines many things the > > > C standard left out, and so bitfield layout is/will be portable > > > between most compilers that target ARM. > > > > That's wonderful if the code you're writing will only ever run on an > > ARM. If you want _portable_ code bitfields are best avoided.
If you want portable code you wouldn't use C! Not using bitfields avoids only one of the countless implementation or undefined constructs. Avoiding all of them doesn't leave a usable language. However most compilers agree on these things, so theoretically non-portable code is portable in practice.
> Where can I find information about EABI online? It seems it's not on > www.arm.com.
http://www.arm.com/products/DevTools/ABI.html http://www.arm.com/products/DevTools/abi/aapcs.pdf
7.1.7 defines everything about bitfields and a lot more - this is the kind of uncompromising quality, clarity and attention to detail that the C standard is so severly lacking...
Wilco
|
|