problem in declaring variables and pointer at absolute address

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

problem in declaring variables and pointer at absolute address

8,118 Views
gauri_mahajan
Contributor I
I am working on 68HC11E9 processor and writing code in C for IAR embedded workbench compiler . I need to declare variables and pointer at absolute addresses in npage area (at 0x170). This IAR compiler doesn't support "@" operator and also it doesn't support "#pragma location = " declaration. 
 
 I have tried one more option to create a seperate data segment in RAM and then do it. But that also doesn't work.
 
Can anybody help me in how to do this?
 
Thanks and regards,
 
Gauri
Labels (1)
0 Kudos
8 Replies

799 Views
CrasyCat
Specialist III

Hello

I am not familiar with IAR front-end. However defining your variable as follows is fully ANSI C compliant, so IAR compiler should support that too:

     #define data (*((char *) 0x0170))

You can then initialize this variable in following way:

    data = 8;

CrasyCat

0 Kudos

799 Views
gauri_mahajan
Contributor I
This way I am able to declare variable , but unable to use it in program. there compiler gives error. Also I wish to have pointer located at a specific memory location. This way , it is not possible.
0 Kudos

799 Views
Sten
Contributor IV

The way CrazyCat described is what IAR themselves use (see IO6811.H for example), and it works fully in my programs.

What error do you get?

0 Kudos

799 Views
gauri_mahajan
Contributor I
I get an error "Argument of binary operator missing" at the line "data = 8".
If I comment the line "data = 8", the program compiles without error for #define statement.
0 Kudos

799 Views
Sten
Contributor IV
I just tested the CrazyCat's lines in one of my project, and they compile without errors. I am using  "Micro Series 68HC11 C-Compiler V3.31C/DXT".
Are you sure you haven't added a semicolon to the #define-line?

0 Kudos

799 Views
gauri_mahajan
Contributor I
yes, you are right. I have given semicolon at the end. So I was getting the error. So I could place a variable at a perticular location. Thanks.
 
But I also need to place a pointer at specific location. Can you please help me....
0 Kudos

799 Views
Sten
Contributor IV

I do not understand why you would need a pointer to be in a specific position (and not point to a specific position), but here is a way to do it:

#define data (*((char *) 0x170))    // define a variable at address 0x170
#define pdata (*((char **)0x172)) // define a pointer to a char at address 0x172

  data = 8;  // the char at 0x170 will be set to 8
  pdata = (char *) 0x170; // the pointer at 0x172 will be set to 0x170
  *pdata = 8;  // the char pointed to by 0x172 is set to 8 (same as data = 8)

0 Kudos

799 Views
gauri_mahajan
Contributor I
Thank you Sten! It solved my problem.
 
The requirement was for a function to check RAM. This function's variables also reside in the same RAM. So these variables need to be at specific addresses.
 
Thank you all who helped me.
 
Regards,
 
Gauri
0 Kudos