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

How to use CONDITIONAL COMPILE for TABLES in eeprom & co

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



Joined: 10 Sep 2003
Posts: 7

View user's profile Send private message

How to use CONDITIONAL COMPILE for TABLES in eeprom & co
PostPosted: Wed Aug 03, 2005 5:46 am     Reply with quote

Hi,

I have found that if I attempt to embed EEP or code space tables in my code that are subject to conditional compile statements, the code compiles ok but when I try to use the Simulator in MPLAB, executed code is completely out of sync with compiled code, many statements appear to be missing and it is impossible to set breakpoints or debug the code.

I am writing code for a project whilst the hardware is being developed in parallel and I have not yet decided if I will require tables that are 5-entry or 9-entry, so I declared both tables and used conditional compile statements to enable the 5-entry tables but disabled the 9-entry tables until/unless they are needed.

However I would still expect this to be a valid thing to do, so this may be a bug...

Here is one of the EEprom dual-table declarations (I have knocked-out all but the first and last entries to save space in this thread):

#if 5_SUB_BANDS
#rom EEP_DP0_TBL = {
//Hex Addr (Dec) No. Min Max Sub
//val Offset Val Taps Val Val Band
0x32, // 0 ( 50) 100 0 0x64 + 0MHz
0x32} // 4 ( 50) 100 0 0x64 + 20MHz
#endif

#if 9_SUB_BANDS
#rom EEP_DP0_TBL = {
//Hex Addr (Dec) No. Min Max Sub
//val Offset Val Taps Val Val Band
0x32, // 0 ( 50) 100 0 0x64 + 0MHz
0x32} // 8 ( 50) 100 0 0x64 + 20MHz
#endif

Here are the conditional compile declarations:

#define 5_SUB_BANDS true; //default length of calibration tables
//#define 5_SUB_BANDS false;

//#define 9_SUB_BANDS true; //alt. length of calibration tables
#define 9_SUB_BANDS false;

BTW - I have noticed that whilst conditional compile statements are defined as accepting 'an expresson with constants & standard operators', this is not the case. You cannot, as I have found, logically combine these conditional compile names e.g. '#if 9_SUB_BANDS || WIDE_BAND'. It seems you can only use a single boolean.

Anyway, if the above table declarations are present I get the problems I've already mentioned.

In addition to the above, I also have similar default tables in code space:

#if 5_SUB_BANDS
int8 const ROM5_DP0_TBL[5] = {
//Hex Addr (Dec) No. Min Max Sub
//val Offset Val Taps Val Val Band
0x32, // 0 ( 50) 100 0 0x64 + 0MHz
0x32};// 4 ( 50) 100 0 0x64 + 20MHz
#endif

#if 9_SUB_BANDS
int8 const ROM9_DP0_TBL[9] = {
//Hex Addr (Dec) No. Min Max Sub
//val Offset Val Taps Val Val Band
0x32, // 0 ( 50) 100 0 0x64 + 0MHz
0x32};// 8 ( 50) 100 0 0x64 + 20MHz
#endif

...and it doesn't like these either.

Furthermore, although for the EEP tables I use the same name 'EEP_DP0_TBL ' for 5 and 9-entry tables and it compiles ok, the compiler complains if you try to do this in the code space tables, which is why I had to give them unique names: 'ROM5_DP0_TBL' and 'ROM9_DP0_TBL' which is another pain.

...however even though this also compiles ok, it too causes the problems I've described. Only if I remove ALL sets of these particular tables does MPLAB return to normal operation (I have several other tables in EEP and code space that are not conditional compile enabled and are problem-free).

I DO need to have these tables embedded, is there a way of using conditional compilation on TABLES that will work?

Adrian
kypec



Joined: 20 Sep 2003
Posts: 54

View user's profile Send private message

Some thoughts on CONDITIONAL COMPILE
PostPosted: Thu Aug 04, 2005 2:52 am     Reply with quote

Hi Adrian,

I'm probably not going to give you a complete solution to your problem
but here are few ideas of mine, which I succesfully use when doing conditional compilation.
My PCM and PCH are both version 3.190

1. complex expression evaluation like these work for me
Code:
#ifndef MACHINE_NAME_X
 #define MACHINE_NAME_X 'P'  //first ASCII char
 #define MACHINE_NAME_Y 'D'  //second ASCII char
#endif

#if (MACHINE_NAME_X=='P' || MACHINE_NAME_X=='G' || MACHINE_NAME_X=='X') && MACHINE_NAME_Y=='D'
 #define MEMBER_NUMBER 0x00 //PD/GD/XD module alias Power Source Unit = MODBUS MASTER
#elif MACHINE_NAME_X=='M' && MACHINE_NAME_Y=='D'
 #define MEMBER_NUMBER MD_BUS0 //MD module alias Wire Feeder Unit = MODBUS SLAVE
#elif MACHINE_NAME_X=='R' && MACHINE_NAME_Y=='C'
 #define MEMBER_NUMBER RC_BUS0 //RC module alias Remote Control Unit = MODBUS SLAVE
#elif MACHINE_NAME_X=='I' && MACHINE_NAME_Y=='D'
 #define MEMBER_NUMBER ID_BUS0 //ID module alias Robot Interface Unit = MODBUS SLAVE
#else #error Unknown or unsupported hardware unit's name defined
#endif


2. When I need to work with a size of variable like an array or structure which depends on conditional compilation I refer to it using the sizeof(var) statement:
Code:
for (mb.index=0;mb.index<sizeof(mb_buffer);mb.index++) mb_buffer[mb.index]=0;


3. I would try to code your program in a more readable way:
Code:
#define SUB_BANDS 5 //allowed values are either 5 or 9

#if SUB_BANDS==5
#rom EEP_DP0_TBL = {
//Hex Addr (Dec) No. Min Max Sub
//val Offset Val Taps Val Val Band
0x32, // 0. ( 50) 100 0 0x64 + 0MHz
0x32, // 1. ( 50) 100 0 0x64 + 0MHz
0x32, // 2. ( 50) 100 0 0x64 + 0MHz
0x32, // 3. ( 50) 100 0 0x64 + 0MHz
0x32} // 4. ( 50) 100 0 0x64 + 20MHz
#elif SUB_BANDS==9
#rom EEP_DP0_TBL = {
//Hex Addr (Dec) No. Min Max Sub
//val Offset Val Taps Val Val Band
0x32, // 0. ( 50) 100 0 0x64 + 0MHz
0x32, // 1. ( 50) 100 0 0x64 + 0MHz
0x32, // 2. ( 50) 100 0 0x64 + 0MHz
0x32, // 3. ( 50) 100 0 0x64 + 0MHz
0x32, // 4. ( 50) 100 0 0x64 + 0MHz
0x32, // 5. ( 50) 100 0 0x64 + 0MHz
0x32, // 6. ( 50) 100 0 0x64 + 0MHz
0x32, // 7. ( 50) 100 0 0x64 + 0MHz
0x32} // 8. ( 50) 100 0 0x64 + 20MHz
#else #error Please specify SUB_BANDS as 5 or 9
#endif

and then apply the similar approach to tables in code space Wink

Good luck,
kypec
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