|
|
View previous topic :: View next topic |
Author |
Message |
thomasj50
Joined: 23 Aug 2006 Posts: 19
|
Copying structs from rom |
Posted: Sun Nov 12, 2006 1:03 am |
|
|
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
|
|
Posted: Sun Nov 12, 2006 1:33 am |
|
|
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
|
|
Posted: Sun Nov 12, 2006 2:43 am |
|
|
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
|
|
Posted: Sun Nov 12, 2006 3:07 am |
|
|
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
|
|
Posted: Sun Nov 12, 2006 3:13 pm |
|
|
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
|
|
Posted: Mon Nov 13, 2006 11:35 am |
|
|
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
|
|
Posted: Mon Nov 13, 2006 11:40 am |
|
|
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. |
|
|
|
|
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
|