Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] use of specifin RAM location [RSS Feed]

#1 Nov. 28, 2005 08:04:51

v.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] use of specifin RAM location


Hello all,I'm working onavr-gcc (GCC) 3.4.3 compiler and target MCU is Atmega 16i want to declare some variables, such that hey
will take specific ram locations...for ex: as we do in assembly code as, org (ramend-4) date:   .byte
1month:   .byte 1 how to achieve this in c? Thank you,regards,varsha--***********************Confidentiality Notice***************************The information contained in this electronic message and any attachmentsto this message are intended for the exclusive use of the addressee(s)and may contain confidential or privileged information. If you are notthe intended recipient, please notify the sender at Divinet or immediately and destroy all copies of thismessage and any attachments.************************************************************************_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Nov. 28, 2005 16:00:18

Kevin N.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] use of specifin RAM location


On Mon, 28 Nov 2005, varsha wrote:

> I'm working on avr-gcc (GCC) 3.4.3 compiler and target MCU is Atmega 16
> i want to declare some variables, such that hey will take specific ram
> locations...
>
> how to achieve this in c?

What's the point of using the abstraction of the C language, then? The
compiler should handle those details for you.

Perhaps I'm misunderstanding your question. You can store data in EEPROM
at specific locations, or in flash, letting the compiler choose the location.
You can read more about it in avr-libc Library Reference or FAQ.

--Kevin




_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 Nov. 28, 2005 22:38:44

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] use of specifin RAM location


I have the same problem, and the point is that part of my external
memory is inside an FPGA, basically under control of the FPGA (It's
high-speed ADC data), while another part is external SRAM which I use
for my heap etc.

I access the FPGA memory at the moment using pointers which I initialise
to the right value. I don't yet have a method mapped out for the SRAM -
it's on the next version of the board (the present version has no
external SRAM).

I will have a need to allocate some large-ish arrays in the external
SRAM in the next hardware version.

Memory-mapped peripherals need to be accessed at particular addresses
also, however these don't usually need allocation (and hence can be
accessed via pointers initialised to the correct address).

Cheers,
Matthew van de Werken - Electronics Engineer
CSIRO E&M - Rock Mass Characterisation - 1 Technology Court - Pullenvale
- 4069
p: (07) 3327 4142 * f: (07) 3327 4455 * e:
"We do not inherit the earth from our ancestors, we borrow it from our
children."
-- Native American Proverb

> -----Original Message-----
> From:
>
>
> org] On Behalf Of Kevin Neff
> Sent: Tuesday, 29 November 2005 1:09 AM
> To: varsha
> Cc: avr-gcc-l***@*ongnu.org
> Subject: Re: use of specifin RAM location
>
>
>
> On Mon, 28 Nov 2005, varsha wrote:
>
> > I'm working on avr-gcc (GCC) 3.4.3 compiler and target MCU
> is Atmega
> > 16 i want to declare some variables, such that hey will
> take specific
> > ram locations...
> >
> > how to achieve this in c?
>
> What's the point of using the abstraction of the C language,
> then? The compiler should handle those details for you.
>
> Perhaps I'm misunderstanding your question. You can store
> data in EEPROM at specific locations, or in flash, letting
> the compiler choose the location. You can read more about it
> in avr-libc Library Reference or FAQ.
>
> --Kevin
>
>
>
>
> _______________________________________________
> AVR-GCC-list mailing list
> AVR-GCC-l***@*ongnu.org
>http://lists.nongnu.org/mailman/listinfo/avr-gcc-list>


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#4 Nov. 29, 2005 00:17:15

Daniel O.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] use of specifin RAM location


On Tue, 29 Nov 2005 09:05, wrote:
> I have the same problem, and the point is that part of my external
> memory is inside an FPGA, basically under control of the FPGA (It's
> high-speed ADC data), while another part is external SRAM which I use
> for my heap etc.

You should be able to do..
char *foo;
foo = 0x1234;

for (i = 0; i < 10; i++)
putc(foo);

or similar..

> I access the FPGA memory at the moment using pointers which I initialise
> to the right value. I don't yet have a method mapped out for the SRAM -
> it's on the next version of the board (the present version has no
> external SRAM).
>
> I will have a need to allocate some large-ish arrays in the external
> SRAM in the next hardware version.

I don't think it would be any different to the above unless you are using a
malloc routine, in which case you would need to tell it to not allocate
memory in certain places.

--
Daniel O'Connor software and network engineer
for Genesis Software -http://www.gsoft.com.au"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8CpgpqlHeaG79fb.pgpDescription:PGP signature_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Attachments:
attachment pgpqlHeaG79fb.pgp (187 bytes)

Offline

#5 Nov. 29, 2005 00:47:05

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] use of specifin RAM location


That's exactly how I've done it at the moment.

Cheers,
Matthew van de Werken - Electronics Engineer
CSIRO E&M - Rock Mass Characterisation - 1 Technology Court - Pullenvale
- 4069
p: (07) 3327 4142 * f: (07) 3327 4455 * e:
"We do not inherit the earth from our ancestors, we borrow it from our
children."
-- Native American Proverb

> -----Original Message-----
> From: Daniel O'Connor
> Sent: Tuesday, 29 November 2005 10:13 AM
> To: avr-gcc-l***@*ongnu.org
> Cc: Van De Werken, Matt (E&M, QCAT)
> Subject: Re: use of specifin RAM location
>
>
> On Tue, 29 Nov 2005 09:05, wrote:
> > I have the same problem, and the point is that part of my external
> > memory is inside an FPGA, basically under control of the FPGA (It's
> > high-speed ADC data), while another part is external SRAM
> which I use
> > for my heap etc.
>
> You should be able to do..
> char *foo;
> foo = 0x1234;
>
> for (i = 0; i < 10; i++)
> putc(foo);
>
> or similar..
>
> > I access the FPGA memory at the moment using pointers which I
> > initialise to the right value. I don't yet have a method mapped out
> > for the SRAM - it's on the next version of the board (the present
> > version has no external SRAM).
> >
> > I will have a need to allocate some large-ish arrays in the
> external
> > SRAM in the next hardware version.
>
> I don't think it would be any different to the above unless
> you are using a
> malloc routine, in which case you would need to tell it to
> not allocate
> memory in certain places.
>
> --
> Daniel O'Connor software and network engineer
> for Genesis Software -http://www.gsoft.com.au> "The nice thing about standards is that there
> are so many of them to choose from."
> -- Andrew Tanenbaum
> GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
>


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#6 Nov. 29, 2005 01:24:21

Daniel O.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] use of specifin RAM location


On Tue, 29 Nov 2005 11:11, wrote:
> That's exactly how I've done it at the moment.

Heh, sorry, I sort of was replying to the original poster's email via yours :)

--
Daniel O'Connor software and network engineer
for Genesis Software -http://www.gsoft.com.au"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8CpgpiUF3e2Ra0U.pgpDescription:PGP signature_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Attachments:
attachment pgpiUF3e2Ra0U.pgp (187 bytes)

Offline

#7 Nov. 29, 2005 03:01:57

David K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] use of specifin RAM location


On Tue, Nov 29, 2005 at 08:35:05AM +1000, wrote:I have the same problem, and the point is that part of my external
memory is inside an FPGA, basically under control of the FPGA (It's
high-speed ADC data), while another part is external SRAM which I use
for my heap etc.I access the FPGA memory at the moment using pointers which Iinitialiseto the right value. I don't yet have a method mapped out for theSRAM -it's on the next version of the board (the present version has no
external SRAM).

I will have a need to allocate some large-ish arrays in the external
SRAM in the next hardware version.

Memory-mapped peripherals need to be accessed at particular addresses
also, however these don't usually need allocation (and hence can be
accessed via pointers initialised to the correct address).The cleanest way to pull this off would be to lay a structure on the
memory-mapped device and allocate it in a named section. Seehttp://gcc.gnu.org/onlinedocs/gcc-3.4.3/gcc/Variable-Attributes.html#Variable-AttributesThen in the linking stage define the location of the FPGA something like
this in Makefile:

LDFLAGS= -Wl,-Map, \
-Wl,--section-start=.eeprom=0x00810001 \
-Wl,--section-start=.fpga1=0x6000 \
-Wl,--section-start=.hsa2d=0x7000 \
-Wl,--section-start=.sram=0x2000

Just use the __attribute__ to tag variables as section .sram and the
compiler will find places for them if you don't care about the order.

--
David Kelly N4HHE,
========================================================================
Whom computers would destroy, they must first drive mad.


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#8 Nov. 29, 2005 03:22:12

David K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] use of specifin RAM location


On Nov 28, 2005, at 9:01 PM, David Kelly wrote:Then in the linking stage define the location of the FPGA somethinglikethis in Makefile:

LDFLAGS= -Wl,-Map, \
-Wl,--section-start=.eeprom=0x00810001 \
-Wl,--section-start=.fpga1=0x6000 \
-Wl,--section-start=.hsa2d=0x7000 \
-Wl,--section-start=.sram=0x2000

Just use the __attribute__ to tag variables as section .sram and the
compiler will find places for them if you don't care about the order.Oops, come to think of it "data-memory mapped" needs 0x800000 addedas an offset so to indicate which memory space it belongs. Add0x810000 for EEPROM as shown. Most of the above lands in FLASH codespace.--
David Kelly N4HHE,
========================================================================
Whom computers would destroy, they must first drive mad.



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#9 Nov. 29, 2005 16:35:17

Eric W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] use of specifin RAM location


David Kelly wrote:The cleanest way to pull this off would be to lay a structure on the
memory-mapped device and allocate it in a named section. Seehttp://gcc.gnu.org/onlinedocs/gcc-3.4.3/gcc/Variable-Attributes.html#Variable-AttributesThen in the linking stage define the location of the FPGA something like
this in Makefile:

LDFLAGS= -Wl,-Map, \
-Wl,--section-start=.eeprom=0x00810001 \
-Wl,--section-start=.fpga1=0x6000 \
-Wl,--section-start=.hsa2d=0x7000 \
-Wl,--section-start=.sram=0x2000

Just use the __attribute__ to tag variables as section .sram and the
compiler will find places for them if you don't care about the order.... Depending on your definition of "cleanest way". ;-)If the FPGA will be updating these memory locations indpendent of thecode, then these will act a lot like processor registers. So, firstly,you'll want to make sure that these memory locations are marked as"volatile".You can declare your variables similarly as registers are declared:

#include <stdint.h>
#define VARIABLE (*((volatile uint8_t *)0x1234))
...
VARIABLE = 0x01;
uint8_t foo = VARIABLE;If you want to declare an array of uint8_t, then don't derefence thepointer in the definition:#include <stdint.h>
#define VARIABLE ((volatile uint8_t *)0x1234)
...
VARIABLE = 0x01;
uint8_t foo = VARIABLE;


HTH
Eric


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#10 Nov. 30, 2005 12:28:19

Bjarne L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] use of specifin RAM location


varsha wrote:Hello all,
I'm working on avr-gcc (GCC) 3.4.3 compiler and target MCU is Atmega 16i want to declare some variables, such that hey will take specific ramlocations...for ex:One way of doing this, is:
1: Write the adresse
2: Cast it to a pointer of the appropiate type
3: Dereference the pointer

*((int*)0x1234) = 1;

-- or --

typedef
{
char reg1;
char reg1;
} TDeviceX;

((TDeviceX*)0x1234)->reg1 = 255;Of cause, you should not allocate variables this way that is alsoallocated by the linked.-Bjarne

--


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] use of specifin RAM location [RSS Feed]

Board footer

Moderator control

Enjoy the 24th of April
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support