Accessing Program/Data hard addresses  in C: Please help!!!

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

Accessing Program/Data hard addresses  in C: Please help!!!

4,643 Views
NeedHelp
Contributor I
Background:
The bootloader and OS are sharing the same UART and the OS needs to access some variables defined in the UART section of the bootloader.
Using the Keil compiler all I had to do was:
On the BL side:
unsigned int x _at_ SOME_HARD_CODED_VECTOR;
On the OS side:
unsigned int x _at_ SOME_HARD_CODED_VECTOR;
and both would essentially refer to the same address location.
 
However, code warrior doesnt support the _at_ keyword. How do I go about doing this in code warrior?
Basically how do I define
int x;
int * y;
In the bootloader and also have access to it from the OS?
 
Please help! The datasheet shows accessing memory locations in assembly using P:$xxxx and D:$xxxx but how do I do it in C?
Thanks a bunch!
 
Labels (1)
Tags (1)
0 Kudos
12 Replies

733 Views
bigmac
Specialist III
Hello,
 
If the variables are at a known fixed location, or can be made so, you might also define the absolute address of the variable within its definition.
 
#define VAR_LOC  0x1234
 
volatile int var1 @VAR_LOC;
 
Regards,
Mac
 
0 Kudos

733 Views
Lundin
Senior Contributor IV
ISO C conformant version of the same:

#define var1 (*((volatile unsigned int*)0x1234))
0 Kudos

733 Views
NeedHelp
Contributor I
Thanks a bunch and thank god its friday!
 
0 Kudos

733 Views
NeedHelp
Contributor I
Hello Mac,
Thanks for your suggestion. For some reason I am getting a compile time error.
This is what I have in my code:
 
#define VAR_LOC  0x1234
volatile int var1 @VAR_LOC;
 
When I compile it says:
Error  : ";" expected
packet.c line 77 volatile int var1 @VAR_LOC;
-with a underscore under @
 
Im using codewarrior 5.6.1.1658.
 
:smileysad:
 
Any other suggestion(s)? Thank you!
 
0 Kudos

733 Views
bigmac
Specialist III
Hello,
 
I had no problem compiling and linking the code.  Can I assume that line 77 contains the global definition of the variable, and is not within a function?  Sometimes, this sort of error can indicate a missing semicolon within a few lines above the indicated line.  See if the following code will compile (assuming 0x1234 represents a RAM address for the MCU derivative you are using.
 
#define VAR_LOC  0x1234
volatile int var1 @VAR_LOC;
 
void main (void)
{
   var1 = 1000;
 
   for ( ; ; );
}
 
Regards,
Mac
 
0 Kudos

733 Views
Lundin
Senior Contributor IV
The problem appears because the OP is most likely using the pre-defined register map included in Codewarrior, which maps all registers to their correct addresses.

If you try to use the "@" syntax as in your example when the register is already defined, the linker will try to allocate a new variable on the same spot.

The code I posted allocates no variable, but just accesses a certain address, therefore it should work. It is also better, since it follows the C standard.

Instead of using the "@" syntax, you could use the #pragma DATA_SEG syntax. It makes the code portable.

ISO C conformant means just that: that the code you have written follows the C programming standard and is therefore portable. Knowing what is standard and what isn't is very basic knowledge for a professional programmer.
0 Kudos

733 Views
NeedHelp
Contributor I
Dear all,
Thanks for your reply and tips. I still do not understand how to use variable(s) declared using the #pragma DATA_SEG syntax. You are dealing with a novince programmer - needless to say - so please bare with me and my questions!
1. I want to store a bunch of variables in data memory inside my bootloader code like a int *, int [], char etc. at memory location(s) ALPHA, BETA, THETA.. etc (for argument sake lets assume these addresses are valid). 
My  bootloader invokes my RTOS code ( In Keil I simply do: ((void (code *) (void)) CVECT_BOOT)(); - the bootloader transfers control over to the RTOS residing at address location CVECT_BOOT - Still need to figure how to do this in CW but thats another question Ill be bothering you later with). Once inside my RTOS how do I access those same variables declared and defined in my bootloader? For this I am assuming I need to know the "physical" address location and not the "name" of my data segment?
2. What would I do if I needed to do the same thing but this time my information is in program memory and not in data memory? I want to share my decode and encode array for manchester encoding in program memory.  
 
Since my foundation is so shaky I would appreciate if you could suggest some books/notes as well.
Thanks.
NeedHelp - no kiddin!
 
 


Message Edited by NeedHelp on 2008-04-28 07:17 PM
0 Kudos

733 Views
trytohelp
NXP Employee
NXP Employee
Hi,
 
Pragma like DATA_SEG, CONST_SEG , CODE_SEG are not valid for DSC product.
This can be used only on HC08 and HC12 product.
Using this pragma you can define a specific memory segment.
In the prm file (linker parameter file) you must define the segment in a phisical memory area.
Attached to this post you will find an example.
Hope this will help you.
 
for details please jhave a look to the compiler manual and in the smartlinker section of Build_Tools_Utilities.pdf.
 
Regards
Pascal
 
Message Edited by t.dowe on 2009-10-15 05:43 PM
0 Kudos

733 Views
trytohelp
NXP Employee
NXP Employee
Hi
 
This request has been duplicated.
 
We don't support the same syntax.
See below extract of the 56800x_Build_Tools_Reference.pdf manual.
 
Specifying Variable Addresses in C
The user can tell the compiler to specify the address of a variable in a C file using the :
operator. The constant value following the : operator is the word address of the global
variable (i.e., int OneReg : 0xBCD ; specifies that the global variable OneReg
resides at word address 0xBCD).
 
 
Hope this will help you
Pascal
0 Kudos

733 Views
NeedHelp
Contributor I
Hi there,
Rest assured there are no typos in the code. I think its got something to do with the C code being "ISO C conformant" - whetever that means I have no clue.
Thanks.
 
0 Kudos

733 Views
CompilerGuru
NXP Employee
NXP Employee
I have the feeling that we might guess incorrectly because of the lack of knowledge which core you are targeting.
Please specify which CPU, which derivative and which version of CW you are using,
given the version "5.6.1.1658" (not sure what this version refers too, if this is a product version or just the version of some part of the product) and that you did previously post in the DSP56xxx message board,
I'm not sure the @ syntax applies. The @ syntax does exist for the HC08/HC12 tools, I'm not not sure of the support for the DSP's, I doubt that they have it.

Daniel
0 Kudos

732 Views
NeedHelp
Contributor I
The target is a MC56F8014. When I goto help->about metrowerks codewarrior it says codewarrior ide version 5.6.1.1568.
Compiler : Metrowerks DSP C Compiler. (cant find the exact version #.. where do I look for it?)
Hope this helps,
Thanks.
0 Kudos