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

pointer to rom in struct

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



Joined: 25 Jul 2009
Posts: 5

View user's profile Send private message

pointer to rom in struct
PostPosted: Sat Jul 25, 2009 12:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 25, 2009 12:23 pm     Reply with quote

Read this thread, especially the comments near the end.
http://www.ccsinfo.com/forum/viewtopic.php?t=32604
socerba



Joined: 25 Jul 2009
Posts: 5

View user's profile Send private message

PostPosted: Sat Jul 25, 2009 12:38 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jul 26, 2009 3:10 am     Reply with quote

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







PostPosted: Sun Jul 26, 2009 4:25 am     Reply with quote

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
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