AnsweredAssumed Answered

CW08 V5.0 Problem with global variable over-writing a global structure

Question asked by bigmac on Jul 12, 2007
Latest reply on Jul 13, 2007 by CompilerGuru
I have been attempting to use the ROM based routines ERARNGE (page erase) and PRGRNGE from within my code, to implement non-volatile storage of parameter data within a 908QYx device.  The use of these routines requires a data structure to reside at a specific location in RAM.
The following is an excerpt from the associated header file -
#define DATASIZE 2        /* Data bytes to be stored (up to 32) */
#define RAMStart 0x0080
typedef struct {
   byte CTRLBYT;
   byte CPUSPD;
   word LADDR;
   byte databuf[DATASIZE];
}  BlockStruct;
extern BlockStruct RAMBlock @ RAMStart+8;
It is useful to determine the number of bytes to be stored from within the header file, by defining the value of DATASIZE.  The code compiles correctly, and the RAMBlock structure commences at address 0x0088.
However, if I declare further global variables, as well as the structure, (within main.c) such as -
/* Globals */
BlockStruct RAMBlock;
byte var[16];
the situation occurs where the var array will commence at address 0x0080, and will consequently over-write RAMBlock.
Is there some way to solve this problem, perhaps using pragmas.  I do not necessarily want to create a new section specifically for RAMBlock, within the PRM file, for the following reasons -
  1. The size of a new section would need to match DATASIZE, that may differ for each application.  It would not generally be feasible to always allow for a worst case of 36 bytes, not with a total of 128 bytes of RAM available.
  2. It is likely that the 8 bytes of RAM starting at 0x0080 would never be assigned to anything.
Presumably, if I did not need to specify the exact location for RAMBlock, there would not be a problem.
Any suggestions would be welcomed.

Message Edited by bigmac on 2007-07-12 10:17 PM