ARM Technical Support Knowledge Articles

USING THE MVAR MACRO FOR FIXED VARIABLE LOCATION

Applies to: C166 C Compiler

Answer


Information in this article applies to:


QUESTION

I have a question about locating variables at absolute memory addresses using the C166 compiler. With the C51 compiler, it was no problem to define a variable at an absolute memory address (int x _at_ 0x1234).

I need to make sure that all my variables are at absolute memory addresses, because after a reset or even a program update, I need to access all values as they were when the machine was turned off. The C166 manual says either to use the linker controls to locate variables or to use the MVAR macro to access the memory.

It seems that the MVAR macro would make it very "painful" to write a program (if you must use MVAR whenever you access a variable). Using the linker sounds better, but for a couple of hundred variables this may be too long for a link command. Any help will be appreciated.

ANSWER

There is an easy way to use the MVAR macro for your application. In the following code, you can define variables using #define...

#include <absacc.h>

#define x MVAR (unsigned char, 0x100000)
#define y MVAR (unsigned int, 0x100010)
#define z MVAR (long, 0x100020)

void main (void)
{
x = 1;
y = 1000;
z = 1000000;
}

Then, when you use the defined variable name (x, y, or z in this case) the MVAR macro accesses the correct memory location. This should help and it only requires that you write "special" code for the variable "declaration" or definition as it is in this case.

MORE INFORMATION

Article last edited on: 2005-07-15 10:15:34

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential