Pumpkin, Inc.

Pumpkin User Forums

Passing const variables

If you can't make Salvo do what you want it to do, post it here.

Passing const variables

Postby Salvo Tech Support » Wed Feb 14, 2001 3:28 am

Hi ChrisV.

What you describe is correct. Setting OSBIG_MESSAGE_POINTERS to TRUE allows a pointer to point to both RAM and ROM. If you force al_zone to static, then it works.

What you want is to pass const's instead of static vars. What you must do is dereference the message pointer properly, like this:

code:
alarm_zone = *(const char *) al_zoneP;

This tells the compiler to treat al_zoneP as a pointer to a char constant, which is what you want. Without the const in the cast, it treats al_zoneP as a pointer to a char, which is in RAM (not ROM), and so the dereferencing in your example didn't work.

The best thing to do is to define a type like this:

code:
typedef const char type_al_zone;

and then you can do:

code:
type_al_zone al_zone = 1;
...
alarm_zone = * (type_al_zone *) al_zoneP;

Please see AN-3 Salvo, Banked Objects and the HI-TECH PIC C Compiler for more info on correctly dereferencing pointers. The idea is that you have to explicitly cast the pointer to the appropriate type before dereferencing it.

[This message has been edited by Salvo Tech Support (edited February 14, 2001).]

--------
Salvo Technical Support
Please request all tech support through the Forums.
Salvo Tech Support
 
Posts: 173
Joined: Sun Nov 19, 2000 12:00 am

Re: Passing const variables

Postby ChrisV » Wed Feb 14, 2001 11:13 am

Hello,
Still havng a problem with passing const variables via messages. I have set OSBIG_MESSAGE_POINTERS TRUE
Im not sure what i missing.... if I change al_zone to static within task_convert, the message is passed.

code:
const char al_zone = 1;


void task_convert (void)
{
for (;;) {
...
OSSignalMsg(ALARM,(OStypeMsgP) &al_zone);
}
}


void task_alarm (void)
{
char al_temp;
char alarm_zone;
OStypeMsgP al_zoneP;


for(;;) {
OS_WaitMsg(ALARM, &al_zoneP, task_alarm_on1);
alarm_zone = *(char*) al_zoneP;
}
}


thanks

(ChrisV: I've taken the liberty of making your example complete and more readbale using the UBB code tag. You'll find more info in this forums FAQ (upper right corner of screen).

Salvo Tech Support.)

[This message has been edited by Salvo Tech Support (edited February 14, 2001).]

ChrisV
 
Posts: 10
Joined: Wed Jan 24, 2001 12:00 am
Location: Chandler, AZ


Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron