Page 1 of 1

Possible bug with banking

PostPosted: Fri Dec 22, 2000 8:48 am
by luben
Hello,

After I succeded to make a simple project and compiled it (with the kind help of the people of Salvo) and ran it on my ICD module into 16F873 processor. And I found a strange behavior.

I have 2 tasks, declared in main. When I use before the task name the key word "bank1" the task never starts.
Like
bank1 void Task1(void);

And after I removed the word "bank1" everything is correct - with the ICD I can trace the program flow comming into the task.

Some suggestions? Am I wrong somewhere.

I use bank1 because my code growed very much and I have open space for Salvo. But talking about pure C - there should be no problems to declare my function in any page, right?

Regards
Luben


Re: Possible bug with banking

PostPosted: Fri Dec 22, 2000 9:10 am
by NoMore
bankX are specifiers for variables (RAM page), not for code (ROM page). I never care about ROM pages. It's the compiler's headache.

Re: Possible bug with banking

PostPosted: Fri Dec 22, 2000 11:55 am
by luben
Hello,

That's true - bankx is usually used for selecting where to put the variables. But in HiTech C it's possible to declare one function to be forced into some bank (it's even possible to force the compiler to use only call...return sceme in small PIC with faskcall prefix, instead of lookup tables). So, it's not an error to add bank1 before the function. Maybe my question should be modified like - if I use declaration before my functions like "bankx" will Salvo interpret it correctly, is it possible some problems to appear?

Regards
Luben


Re: Possible bug with banking

PostPosted: Sat Dec 23, 2000 1:22 am
by aek
Hi Luben.

Re: "it's possible to make mistake and the compiler will not generate an error (this is real potential problem)."

That's both the power and the danger of C. We try to remove the danger portion by standardization, and in this case, lots of typedefs.


Re: Possible bug with banking

PostPosted: Sat Dec 23, 2000 10:06 am
by aek
PICC's type qualifier bankn is only "used for selecting where to put the variables." See section 5.17 Special Type Qualifiers of the PIC C manual for more info.

Declaring

code:
bank1 void Task1(void);

is to declare Task1 as a function that returns a bank1 void parameter -- doesn't make much sense, though I don't know why it would cause problems in Salvo. This may be an oversight in PICC -- you should refer this question (i.e. what it means to declare bankn void, and what affect it has) to support@htsoft.com .

Furthermore, PICC functions can return objects in banks other than bank0. That's probably why the declaration doesn't generate an error.

To locate a function in another ROM page (sometimes also called a bank), my understanding of PICC is that you'd have to create your own psect to drive picc.exe accordingly.

We have not investigated placing tasks in anything but the standard, automatically-generated psects.

You may also find Pumpkin's AN-3 useful w/regard to banking objects.

[This message has been edited by aek (edited December 23, 2000).]


Re: Possible bug with banking

PostPosted: Sat Dec 23, 2000 10:31 am
by aek
On further reflection, I think I know why it didn't work for you ...

Salvo's task pointers are declared (see salvoincludeportpicc.h) as:

code:
typedef void (* OStypeTP) (void);

meaning that tasks are functions that take no parameters and return nothing. By declaring a task as:

code:
bank1 void Task1(void);

you're breaking the code because the precompiled scheduler OSSched() in the freeware libraries -- which uses pointers to dispatch the tasks -- is expecting tasks of type OStypeTP, but you've created a task of a different type.

This sort of type mismatch is a common source of problems that crop up when using the bank qualifiers, especially when pointers are involved. It is not an easy subject to master. AN-3 describes in depth how to avoid this sort of problem, with some tips.


Re: Possible bug with banking

PostPosted: Sat Dec 23, 2000 11:54 am
by luben
Hello,

I see that I just misunderstood the HiTech C directive bankx before the function. But this shows something other - it's possible to make mistake and the compiler will not generate an error (this is real potential problem). I know that this is the heaviest part of one program creation - to find some small "holls" from where an error can appear. In my case I just wronged something, but I didn't receive any error message, just was very surprised that from 2 tasks only one received the control and other was out of the task scheduler activity. Well, after changed the prefix and everything began to work again.

Imagine that I make such mistake in one giant project, it's doubtful that I can locate it for day or two.

Regards
Luben