Pumpkin, Inc.

Pumpkin User Forums

SALVO and memory pages in PIC

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

SALVO and memory pages in PIC

Postby Salvo Tech Support » Tue Feb 13, 2001 6:32 am

Hi Luben.

You shouldn't have any problems. Salvo's variables can be placed anywhere, as you point out. You also (correctly) point out that PIC C pointers can only point to banks 0&1 or 2&3, respectively.

How does this affect Salvo? Simple -- you (as the programmer) must ensure that each time you dereference a pointer (i.e. when you extract a message's contents from a message or message queue), you must correctly cast the result with the bank specifier that's appropriate to your data.

In your second example, there's absolutely no problem if all of Salvo's variables are located in banks 2&3 via OSLOC_XYZ and your project has its variables in banks 0&1. It just means that whenever you dereference the pointer in a message or message queue, you must specify the bank (see AN-3 Salvo, Banked Objects and the HI-TECH PIC C Compiler for this code snippet:

cmd = * (bank1 char *) msgP;

and for more info.) This says "treat msgP as a pointer to a char in bank1, and assign the value pointed to by msgP to cmd." You can look at the source code for salvodemod1 and see that Salvo's variables are all in bank3, yet other variables are in banks 0, 1 and 2.

In your first example, let's say that all of Salvo's vars are in bank3, and you have vars in bank0, bank1 and bank2. Furthermore you have two message queues, msgQ1 points to data in bank1 and msgQ2 points to data in bank2. To extract an (integer) message from msgQ1, you would do this:

num = * (bank1 int *) msgP;

and for the (char) message in msgQ2, you do this:

char= * (bank2 char *) msgP;

This means that a given message or message queue should always point to elements in the same bank.

However, there are some subtleties you should be aware of: 1) a pointer can actually access data in a bank pair, e.g. a pointer can access data in banks 0&1 or in banks 2&3. So you could put all of Salvo's vars in bank1, and then be able to access data in bank2 and bank3 using the same pointer. Note that this is true for PIC16 PICmicros, but not for PIC17 PICmicros. 2) On the PIC17 you can use far pointers, which get around the banking problem altogether. 3) Since the bank specifier is only really necessary when dereferencing the pointer, you could actually do something really crazy, like alternate data banks in a message queue, e.g. the even elements are in bank1, and the odd elements are in bank2, and whenever you successfully OS_WaitMsgQ(), you take that into account when dereferencing the element. But that's a pretty advanced topic ... :-)

Once you understanding banking and the PIC C compiler, it becomes pretty easy -- but until you do, it can be very confusing. Please see AN-3, salvo.h and portpicc.h for more info.

In summary, all you need to do is place Salvo's vars via OSLOC_XYZ, correctly declare your variables with bank specifiers, and then correctly dereference them when you extract the contents of a message. As mentioned in AN-3, typedefs for your variables with the bank specifier in them are highly recommended.

[This message has been edited by Salvo Tech Support (edited February 13, 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: SALVO and memory pages in PIC

Postby luben » Tue Feb 13, 2001 11:39 am


I wonder what will happen if whole project resides in pages 0 & 1 and SALVO in pages 2 or 3. For variables this is not a problem, but what about pointers to variables - they could point only one of the areas page 1&0 and page 2&3.

Now I'm working over one very big project and I suspect that SALVO can crash in some situations. Because I dont'r have the sources I don't know how will behave.

So my question is - how is SALVO protected from such situations - when pointers have to point variables in both page areas (0&1 and 2&3). Or what will happen if the whole project resides in pages 0&1 but SALVO is located with OSLOC_XXXX to page 2 or 3?


Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests