|
|
View previous topic :: View next topic |
Author |
Message |
socerba
Joined: 25 Jul 2009 Posts: 5
|
pointer to rom in struct |
Posted: Sat Jul 25, 2009 12:18 pm |
|
|
I have a struct with pointers.
Code: |
...
struct message
{
int8 iDelayMsKey;
int16 iDelayMsBefore;
int8 iSize;
BYTE *aiKey[];
BYTE *aiMod[];
};
...
BYTE *aiMsg1[] = {1,1,1,1};
BYTE *aiMsgMod1[] = {1,1,1,1};
...
struct message aMessage[] =
{
{1,1,1,aiMsg1,aiMsgMod1},
{2,2,2,aiMsg2,aiMsgMod2}
};
...
// Code use the struct
void function()
{
int8 a = 0;
int8 b = 0;
a = aMessage[0].aiKey[0];
b = aMessage[0].aiKeyMod[0];
}
|
When all is in ram work without problems. But if I try to set rom on array's byte and struct...
Code: |
...
struct message
{
int8 iDelayMsKey;
int16 iDelayMsBefore;
int8 iSize;
rom BYTE *aiKey[];
rom BYTE *aiMod[];
};
...
rom BYTE *aiMsg1[] = {1,1,1,1};
rom BYTE *aiMsgMod1[] = {1,1,1,1};
...
struct message aMessage[] =
{
{1,1,1,aiMsg1,aiMsgMod1},
{2,2,2,aiMsg2,aiMsgMod2}
};
...
// Code use the struct
void function()
{
int8 a = 0;
int8 b = 0;
a = aMessage[0].aiKey[0];
b = aMessage[0].aiKeyMod[0];
}
|
... give me an error on row of assign ( a = aMessage[0].aiKey[0]; ) and tell me: Error 53 Expecting function name. Why? How to can I resolve?
I tried to search in the forum but I don't understand as resolve the problem.
I trying this code on 18F2550 PCH 4.088.
Sorry if my question is stupid. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
socerba
Joined: 25 Jul 2009 Posts: 5
|
|
Posted: Sat Jul 25, 2009 12:38 pm |
|
|
This comments?
Ttelmah wrote: | No.
Remember that constants, are stored in the ROM, as opposed to normal variables being in RAM. To declare a constant 'inside' a structure, would require a complete change of access mode for just the one value...
What you can do, is have a constant data array, and store the index used to access a particular value inside a structure.
A structure is a single entity, and the whole entity must either be 'constant', or variable.
|
I have read also the readme.txt on CCS Compiler:
Code: |
Declaration Result
----------- ----------------------------------------
char id; id is stored in RAM
char rom id; id is stored in ROM
rom char id; id is stored in ROM
rom char * id; id is stored in RAM, is a pointer to ROM
rom char rom * id; id is stored in RAM, is a pointer to ROM
char rom * id; id is stored in RAM, is a pointer to ROM
char * rom id; id is stored in ROM, is a pointer to RAM
rom char * rom id; id is stored in ROM, is a pointer to ROM
|
So I think with my declaration the struct is in RAM but the pointer is a pointer to ROM, is correct? |
|
|
socerba
Joined: 25 Jul 2009 Posts: 5
|
|
Posted: Sun Jul 26, 2009 3:10 am |
|
|
I resolved my problem, with this solution:
Code: |
struct message
{
int8 iDelayMsKey;
int16 iDelayMsBefore;
int8 iSize;
int16 iPKey;
int16 iPMod;
/*BYTE *aiKey[];
BYTE *aiMod[];*/
}
|
So I have the address of array in rom. In the function I read the byte and use it:
Code: |
// Code use the struct
void function()
{
int8 iBuf = 0;
int8 a = 0;
int8 b = 0;
read_program_memory(aMessage[iNdx].iPMod,&iBuf,1);
a = iBuf;
read_program_memory(aMessage[iNdx].iPKey,&iBuf,1);
b = iBuf;
// I can access to byte with aMessage[iNdx].iPKey + Index
}
|
Maybe it works also with BYTE * a[], but is more rapid use int16, without cast.
Why CCS C Compiler don't it automatically? A compiler should be to do it automatically so help a programmer. Maybe is better use asm. |
|
|
Ttelmah Guest
|
|
Posted: Sun Jul 26, 2009 4:25 am |
|
|
Have to agree 'wholeheartedly'.
On the older PIC16 chips, without any ability to perform table reads into the ROM, the CCS limitations 'make sense'. With the newer chips, they have added functionality to do some parts of things, but never seem to have made the next 'jump' to making it perform quite basic ROM tasks for you....
What you are doing, is basically what I described, just storing the address of the base of the whole array, and calculating the offsets yourself. However it does seem that the code used for 'read_program_memory', is more efficient than the code CCS use internally for accessing a ROM array. Duh....
Best Wishes |
|
|
|
|
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
|