From: Philipp K. K. <pk...@sp...> - 2006-03-28 11:53:04
|
Raphael Neider wrote: >>> Something along this lines may work: >>> >>> void MINOR_VERSION (void) _naked >>> { >>> _asm >>> .area MY_VERSION (ABS) >>> .org 0xaffe >>> .db 0x01 >>> _endasm; >>> } >> Thanks; it works (when at the end of the file, otherwise everything in >> the file is at 0xaffe), but changes the type of MY_VERSION from uint8_t >> to void(* )(void). >> I want to access MY_VERSION from both inside my code (where I'd prefer >> it to have the type uint8_t) and from a peripheral, which can access the >> memory (which is why I need the fixed location). > > Just an idea (untested): Possibly you can > > #define MY_VERSION (*((uint8_t *)((void *)&MY_VERSION))) > > *after* the function definition to implicitly cast the type for use in C > (or rename MY_VERSION in the _asm-block to MY_VERSION2 and > define the above macro whereever suitable---breaks symbolic > references across object files, though, since MY_VERSION is no longer > a (global) symbol.). > The weird cast might even be stripped down to (*(uint8_t *)MY_VERSION), > I cannot try it out right now... > > Regards, > Raphael Neider Thanks, here's my final working version (I had to add another .area, otherwise the rest of the file would be placed at wrong locations): void MINOR_VERSION_DATA(void) _naked { _asm .area MY_VERSION (ABS) .org 0xbffe .db 0x01 .area _CODE _endasm; } #define MINOR_VERSION (*(uint8_t *)((void *)(&MINOR_VERSION_DATA))) I still think that there should be a simpler and more elegant way to do this though. I can't try out the #pragma constseg solution suggested my martenbrook, since I use the Debian packages, which don't include that feature yet. Philipp |