CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

RAM Problem: Actual Addresses does not match Symbol Table

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

RAM Problem: Actual Addresses does not match Symbol Table
PostPosted: Tue Mar 06, 2007 9:36 am     Reply with quote

Hi,
I'm facing with a strange RAM allocation problem.

My Intention:
I want to use 3 buffers and they'll have some variables mapped to them.

Problem:
If I check the Symbol Table, everything is fine. All variables are mapped to correct positions. But if I try to change a mapped var OK it changes but the related Buffer data does not change. Still remains zero. I wrote some RS232 code to debug. Then saw that the some of the addresses are not like in the symbol table.

Part of the Symbol Table:
Code:

000 @SCRATCH
001 @SCRATCH
001 _RETURN_
002 @SCRATCH
003 @SCRATCH
004 @SCRATCH
005 @INTERRUPT_AREA
.
.
.
017 @INTERRUPT_AREA
018-019 strtok.save
01A-0A9 EEPROMBuffer
01A-01D MtrSerialNumber
.
.
.
0AA-129 RoamingBuffer
0AA-0AD RmgCustID
.
.
.
[b]12A-139 TempBuffer[/b]
.
.


Here is the actual Addresses:
Code:

EEPROMBuffer => 0x001A (as expected)
RoamingBuffer => 0x00AA (as expected)
TempBuffer => 0x012C (should be 0x012A)


here is the code for definitons
Code:

#define EEPROM_PAGE_COUNT 0x10
#define EEPROM_BUFFER_SIZE 144
#define ROAMING_PAGE_COUNT 0x16
#define ROAMING_BUFFER_SIZE 128
#define BUFFERS_START 0x001A
static unsigned int EEPROMBuffer[EEPROM_BUFFER_SIZE];
#locate EEPROMBuffer = BUFFERS_START
static unsigned int RoamingBuffer[ROAMING_BUFFER_SIZE];
#locate RoamingBuffer = BUFFERS_START + EEPROM_BUFFER_SIZE
static unsigned int TempBuffer[16];
#locate TempBuffer = BUFFERS_START + EEPROM_BUFFER_SIZE + ROAMING_BUFFER_SIZE


Here is the RS232 code for taking the values and addresses:
Code:

DebugMessage("\nEEPROM Buffer Location: ");
fprintf(CPORT," 0x%4LX\n", EEPROMBuffer);
DebugMessage("\nRoaming Buffer Location: ");
fprintf(CPORT," 0x%4LX\n", RoamingBuffer);
DebugMessage("\nTemporary Buffer Location: ");
fprintf(CPORT," 0x%4LX\n", TempBuffer);


For example, trying to change RmgCustID variable does not change RoamingBuffer[0]...[3]

P.S: Code is checked with both versions, 4.023 and 3.212.
_________________
/// KMT
/// www.muratursavas.com


Last edited by KaraMuraT on Wed Mar 07, 2007 1:00 am; edited 3 times in total
Ttelmah
Guest







PostPosted: Tue Mar 06, 2007 10:16 am     Reply with quote

_What chip_.
#locate, is not the command to do what you want. Use #byte. #locate, should reserve the area, preventing other variables from accessing the area.
Code:

#define EEPROM_PAGE_COUNT 0x10
#define EEPROM_BUFFER_SIZE 144
#define ROAMING_PAGE_COUNT 0x16
#define ROAMING_BUFFER_SIZE 128
#define BUFFERS_START 0x001A
static unsigned int EEPROMBuffer[EEPROM_BUFFER_SIZE];
#byte EEPROMBuffer = BUFFERS_START
static unsigned int RoamingBuffer[ROAMING_BUFFER_SIZE];
#byte RoamingBuffer = BUFFERS_START + EEPROM_BUFFER_SIZE
static unsigned int TempBuffer[16];
#byte TempBuffer = BUFFERS_START + EEPROM_BUFFER_SIZE + ROAMING_BUFFER_SIZE
int32 RmgCustID;
#byte RmgCustID=BUFFERS_START + EEPROM_BUFFER_SIZE

Then the line:

RmgCustID=100L;

Generates:
.................... RmgCustID=100L;
02AC: MOVLB 0
02AE: CLRF xAD
02B0: CLRF xAC
02B2: CLRF xAB
02B4: MOVLW 64
02B6: MOVWF xAA

Which puts the right bytes into the first four locations of 'Roaming buffer'.

Best Wishes
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Wed Mar 07, 2007 12:28 am     Reply with quote

Sorry Ttelmah I forgot to give Chip ID. it's PIC18F4620 Rev A4

I read about #locate as "it prevents overwrites from the other vars" but thought that its about not automatically locating the other variables.

The memory usage dropped to half size.

it helped a lot, thank you very much.
_________________
/// KMT
/// www.muratursavas.com
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Wed Mar 07, 2007 1:00 am     Reply with quote

Now I saw something... If I use #byte for every var, the buffers are overwritten by also automatically located variables. That's not what I want. The buffers have to be overwritten by just the mapped variables.

I tried to use "#byte" for buffers and "#locate" for the mapped variables, but this causes to overwrite the holes between mapped variables.

I think the best way is using #byte keyword for both buffers and mapped variables and putting them at the end of RAM. Of course it will change according to RAM size. Am I right? Or do you have another advice?

By the way I've noticed that last 15 bytes is reserved for PSP, CCP and read/write flash operations.
_________________
/// KMT
/// www.muratursavas.com
Ttelmah
Guest







PostPosted: Wed Mar 07, 2007 4:05 am     Reply with quote

Do you have to force the variables to a fixed location?.
Consider some other possibilities:
1) Just declare the normal array, as a union wth the other data.
2) Declare the initial array, and then use #byte to map the other variables 'inside' this.
3) Remember that you can use #reserve to mark an area (so the default declarations will not use it), and then #byte to locate a series of variables 'into' this area.
The last ought to do what you want.

Best Wishes
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Wed Mar 07, 2007 4:31 am     Reply with quote

Yes, I have to fix locations "related to buffer" not related to RAM addresses. Therefore the #reserve solution seems reasonable.

The solution I told before, works fine now. If I'll have to change it I'll try the solutions you mentioned.

Thanks for your help.
_________________
/// KMT
/// www.muratursavas.com
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group