Placing variables into specific memoery locations on the MCF52233

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Placing variables into specific memoery locations on the MCF52233

3,432 次查看
Eqqman
Contributor I

Hello-

 

On the PIC series of Microcontollers I can do the following:

#pragma udata myData=0x2000

unsigned char value;

/*

 any other variables I wish to declare

*/

#pragma udata

 

This will place the variable 'value' at memory location 0x2000 in RAM with any other variables following consecutively after that until the subsequent pragma.  I'd like to know how to do this same process on the MCF52233.  I found a pragma that looked very similar to what I wanted, but it didn't use any numbers so I wasn't clear on how I could tell exactly where in memory that section would go.  The pragma I found appeared to allow me to name a section of memory but that section could still be placed in an arbitrary memory location.  How do I place data exactly where I want it?

标签 (1)
0 项奖励
回复
7 回复数

2,125 次查看
ChrisJohns
Contributor I

You typically have 2 ways. The first way is C with no specific tricks:

 

#define UDATA_BASE ((unsigned char*) 0x2000)

#define value *(UDATA_DATA + 0)

 

 If you have a few variables at this address place them in a structure.

 

The second way is to use the linker command file and that depends on your compiler. The manual should contain examples.

0 项奖励
回复

2,125 次查看
Eqqman
Contributor I
Since in your example 'value' is an untyped symbol that represents a literal value and not an L-value I'm not not sure how I could successfully get a structure to be stored at the address represented by 'value'.
0 项奖励
回复

2,125 次查看
pgo
Senior Contributor V

Dear eqqman,

 

The example given by Chris is correct.  value is an lvalue.

 

Another alternative that is codewarrior specific is to use the '@' notation as shown in the examples below:

 

 

int example1@0x1000; // Codewarrior specific method
#define EXAMPLE2 (*(volatile unsigned int *) 0x1000)  // Standard C

 

int main(void)
{

   example1 = 0x12345678;
   EXAMPLE2 = 0x12345678;
  
}
 

 

Both assignments produce similar code.  The second is more portable but since accesssing a specific location is almost certainly target specific I can't really see much argument about this being an advantage.

 

The advantage of the 1st is that example1 will appear as a variable in the debugger - EXAMPLE2 is invisible since while an lvalue it's not actually a named variable, just pointer magic.

 

bye

Message Edited by pgo on 2009-04-19 12:58 PM
0 项奖励
回复

2,125 次查看
Eqqman
Contributor I

Ah-

 

So if I have 

struct globals{

/* dat atype 1 */ value1;

/* datatype 2, etc. */ value2;

};

 

I can do 

#define MEMORY (*(volatile globals *) 0x1000) 

MEMORY.value1 = whatever

 

without any of the structure members being named in the debugger?

0 项奖励
回复

2,125 次查看
pgo
Senior Contributor V

Dear Eqqman,

 

That looks about right but I would prefer the @notation.

 

A more complete example:

 

int example1@0x1000;
#define EXAMPLE2 (*(volatile unsigned int *) 0x1000)

typedef struct
{
   int  m1;
   char m2;
} aStruct;

#define EXAMPLE3 (*(volatile aStruct *) 0x1000) // A structure @ 0x1000
#define EXAMPLE4 ((volatile aStruct *) 0x1000)  // A ptr to a struct @ 0x1000

aStruct example5 @0x1000; // A structure @ 0x1000
aStruct volatile  *const example6 = ((volatile aStruct *) 0x1000); // A ptr to a struct @ 0x1000

 

int main(void)
{

   example1 = 0x12345678;
   EXAMPLE2 = 0x12345678;

   EXAMPLE3.m1 = 1234;
   EXAMPLE4->m2 = 'a';

   example5.m1 = 1234;
   example6->m2 = 'b';
     
}

 

 

It's informative to try dissassembling these in codewarrior to check the code produced.

 

bye

0 项奖励
回复

2,125 次查看
CrasyCat
Specialist III

Hello

 

Notation @ is not standard ANSI C.

So an ANSI C compiler might not support it.

 

You can submit a Feature request for support of that notation in the compiler through our on-line support web site if you want to see that extension in CodeWarrior some day.

 

I would recommend you to submit a service request for that.

Click here to submit a service request.

 

CrasyCat

0 项奖励
回复

2,125 次查看
pgo
Senior Contributor V

Dear CrazyCat,

 

I don't understand your comment about the service request.

 

The example I gave is for the codewarrior CFV2,3,4 compiler so obviously it supports it already :smileyhappy:

 

The compilers for other targets support this notation as well - They better since they use it in the supplied target header files.  However, I note that the header files for the CFV2,3,4 use the pointer casting method.

 

bye

 

Message Edited by pgo on 2009-04-21 01:22 PM
0 项奖励
回复