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 CCS Technical Support

Copying structs from rom

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



Joined: 23 Aug 2006
Posts: 19

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

Copying structs from rom
PostPosted: Sun Nov 12, 2006 1:03 am     Reply with quote

Hi,
I have a large struct that I would like to place in prom (as a const) and be copied to a ram version at startup. I use an ordinary assignment for this:

typedef struct
{
... contents
} S;

S a;
S b;

...

a = b is ok, all variables in b gets copied to a, but if I change
S b;
to
const S b;

the assignment fails (i.e. no data is copied). Furthermore, this seems
to take a very long time to single step in the debugger, actually I have never had the patience to wait it out (minutes).

Anyone know anything about this ? I use version 4.014.
Best Regards,
Thomas Johansson
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 12, 2006 1:33 am     Reply with quote

I made the test program shown below, and it works OK with
PCH vs. 3.249. It displays the following output:
Quote:

Before: 0 0 0

After: 1 2 3 Hello World

Code:

#include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000) 
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

typedef struct
{
int8 val1;
int8 val2;
int8 val3;
int8 buf[20];
}S;
   
const S a = {1,2,3, "Hello World"};
   
S b;   

//====================================
void main()
{
b = 0;
printf("Before: %u %u %u %s \n\r", b.val1, b.val2, b.val3, b.buf);

b = a;
printf("After: %u %u %u %s \n\r", b.val1, b.val2, b.val3, b.buf);

while(1);
}
thomasj50



Joined: 23 Aug 2006
Posts: 19

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

PostPosted: Sun Nov 12, 2006 2:43 am     Reply with quote

Hi,

Yes, it works all right with version 4.014 too. This is a much smaller example but it should make no difference. I will have to separate out the code to test it separate from the application.

Thomas J.
thomasj50



Joined: 23 Aug 2006
Posts: 19

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

PostPosted: Sun Nov 12, 2006 3:07 am     Reply with quote

Try this change. It uses a pointer to the struct in ram, and fails as long as
the keyword const is in place, but works otherwise. My printout looks like this:

Before: 0 0 0 .
After: 0 22 3 ........,[email protected]... .


typedef struct
{
int8 val1;
int8 val2;
int8 val3;
int8 buf[20];
}S;

const S a = {1,2,3, "Hello World"};

S b;
S* bp;

//====================================
void main()
{
b = 0;
printf("Before: %u %u %u %s \n\r", b.val1, b.val2, b.val3, b.buf);

bp = &b;
*bp = a;
printf("After: %u %u %u %s \n\r", b.val1, b.val2, b.val3, b.buf);

while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 12, 2006 3:13 pm     Reply with quote

I can confirm that it doesn't work. I looked at the .LST file for both
your recent post and my post. In the non-pointer version, the compiler
generates code to do Table Reads (which reads from the Flash memory).
In the pointer version, it doesn't do that. It's attempting to use the FSR
register to copy from RAM to RAM. It's a bug. I can't immediately
think of a work-around for it. This was with PCH vs. 3.249.
thomasj50



Joined: 23 Aug 2006
Posts: 19

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

PostPosted: Mon Nov 13, 2006 11:35 am     Reply with quote

Ok, thanks for the help with debugging this! I can work around it in my code, the ram struct is static so I can use it directly instead of going trough a pointer (the copy was in a subroutine, hence the pointer). Should I tell CCS about this or do they watch this list continously, do you think ?

Best Regards,
Thomas Johansson
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 13, 2006 11:40 am     Reply with quote

No, they don't watch this board. Send an email to CCS support.
Give them the compiler version number and a short (but complete)
test program that shows the problem. Also give them your user
reference number.
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