View previous topic :: View next topic |
Author |
Message |
newguy
Joined: 24 Jun 2004 Posts: 1909
|
#locate to place a struct.... |
Posted: Wed May 14, 2014 11:00 am |
|
|
I have a program, already written & working, but I am probably going to tweak it a bit to make it execute a bit faster.
The problem I'm having is that, for readability, I extensively use structs to separate & identify two different serial ports/streams/links. I'd like to locate a specific buffer (a transmit buffer) in a pair of structs to the DMA RAM, but of course this produces an error.
I think I already know the answer, but I'll ask anyway: is there any way to force the compiler to locate a portion of a struct to a specific location in RAM?
What I want (but I suspect to be impossible):
Code: | #locate remote_bus.tx_buffer = 0x7800
#locate local_bus.tx_buffer = 0x7a00
|
What I'm dreading I'll have to do is remove the tx_buffer from the struct and end up doing things like this:
Code: | #locate remote_tx_buffer = 0x7800
#locate local_tx_buffer = 0x7a00 |
|
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Wed May 14, 2014 11:45 am |
|
|
The short answer is no you cannot locate only a portion of a struct to a different section from the rest of the struct. struct memory is contiguous.
One option you might try is to do what you dread, but in your struct use pointers to those buffers:
Code: |
#locate remote_tx_buffer = 0x7800
#locate local_tx_buffer = 0x7a00
typedef struct{
unsigned int8 *tx_buffer;
unsigned int8 var1;
unsigned int8 var2;
} bus_type;
bus_type remote_bus = {
&remote_tx_buffer[0],
0x00,
0xff
};
|
That way your struct can have any memory address, but you will always point to your specific location via the pointers |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu May 15, 2014 8:49 am |
|
|
Thanks. |
|
|
|