[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-chat] Forcing C++ object instances to certain memory locations
From: |
David A. Lyons |
Subject: |
Re: [avr-chat] Forcing C++ object instances to certain memory locations |
Date: |
Sat, 5 Feb 2011 15:21:02 -0800 |
I don't know whether it's possible, but if the address only becomes at link
time you'd be preventing some optimization that could have happened at compile
time (the sbi and cbi instructions spring to mind, but I expect there other
advantages).
--Dave
On Feb 5, 2011, at 3:14 AM, Rick Mann wrote:
> As part of an experiment I'm conducting in creating a C++ wrapper around AVR
> hardware, I'd like to get C++ objects I've instantiated to live in certain
> parts of the address space.
>
> I have an AVRPort object that looks something like this (simplified):
>
> class
> AVRPort
> {
> public:
> AVRRegisterT mPin;
> AVRRegisterT mDirection;
> AVRRegisterT mPort;
>
> typedef volatile uint8_t AVRRegisterT;
>
> // methods...
> };
>
> The PIN, DDR, and PORT registers for port A live at 0x0000, 0x0001, and
> 0x0002. Now, I can access port A successfully via my class by defining this:
>
> #define gPortA ((AVRPort*) 0x00)
> #define gPortB ((AVRPort*) 0x03)
>
> But I'd much rather define it like this:
>
> extern AVRPort PortA;
> extern AVRPort PortB;
>
> ...
>
> AVRPort PortA;
> AVRPort PortB;
>
> and have it end up in the right place in memory. It seems like it should be
> possible, using a linker script, to put it in the right section.
>
> Is this possible? My current Makefile doesn't seem to use an explicit linker
> script, and it's working fairly well, so I'm hesitant to jump in there and
> break everything by trying to craft one. I'm using a Makefile that came with
> the ChibiOS AVR port.
>
> Suggestions much appreciated. Thanks!
>
> --
> Rick