View previous topic :: View next topic |
Author |
Message |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
Struct of structs |
Posted: Tue Mar 09, 2004 9:42 am |
|
|
Hi All
Does a struct that contains structs all have to fit into a single bank of memory?
I seem to run out to memory with an aray of structs or struct of structs, but if I instantiate them seperatly they compile.
I am using pcm 3.184/mplab6.40 and a PIC 16F877A
Code: |
struct packet{ // Header(first 5 bytes), data(up to 26 bytes), chksum
BYTE rx_DA; // Desgination address recieved
BYTE data_size; // Number of bytes. NOT counting header and chksum
BYTE function; // Function code of packet
BYTE sequence; // This is the n packet of the total
BYTE packet_total;// Total number of packets in message
BYTE data[MAXDATA];// Data, size is the number of bytes
BYTE rx_chksum; // A checksum over the entire pkt.
BYTE calc_chksum; // This checksum is calculated as data is recieved
//////////////////////////////////////////////////////////////////
BOOLEAN done; // FLAG, 1=all data has been recieved.
BOOLEAN good; // FLAG, 1=chksum is corect AND dest==my_address, fctn code is a valid function
//////////////////////////////////////////////////////////////////
}; // Define 4 packets of buffer space. pkt[0]->pkt[3]
struct packet pkt0;
struct packet pkt1;
struct packet pkt2;
|
Has anyone done something simulare to this?
I want to define a buffer with 3 packets. |
|
|
SteveP
Joined: 26 Mar 2004 Posts: 1 Location: Dartford, UK.
|
Structs in Structs |
Posted: Fri Mar 26, 2004 11:07 am |
|
|
I have a similar programmin requirement at the moment and have found that the limit is caused by the RAM block size limit. Nothing can be done but define each struct individually as you have done.
Not very elegant, but gets the job done.
Steve. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Fri Mar 26, 2004 5:34 pm |
|
|
By looking at the first line of your code your struct size is 31 bytes (although the actual struct appears to be bigger). The biggest memory bank is 96 bytes, so as long as you keep your struct size under 32 you should be able to place an array of 3 in one bank. Try this:
struct packet pkt[3];
#locate pkt=0x190 //Put the array at the very beginning of bank 2 |
|
|
|