View previous topic :: View next topic |
Author |
Message |
KaraMuraT
Joined: 16 May 2006 Posts: 65 Location: Ankara/Turkey
|
RAM Problem: Actual Addresses does not match Symbol Table |
Posted: Tue Mar 06, 2007 9:36 am |
|
|
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
|
|
Posted: Tue Mar 06, 2007 10:16 am |
|
|
_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
|
|
Posted: Wed Mar 07, 2007 12:28 am |
|
|
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
|
|
Posted: Wed Mar 07, 2007 1:00 am |
|
|
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
|
|
Posted: Wed Mar 07, 2007 4:05 am |
|
|
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
|
|
Posted: Wed Mar 07, 2007 4:31 am |
|
|
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 |
|
|
|