Page 2 of 2

Re: Inline services possible bug

PostPosted: Tue Jan 07, 2003 10:09 am
by aek
Hi Luben.

Here's why I made the comment about OSLOC_ALL:

code:
#define OS_Delay(delay, label) do { 
OSDelay(delay);
OS_Yield(label);
} while (0)

does not involve any of Salvo's global (banked) objects -- OSDelay() takes a bank 0 parameter (because all PICC parameters are in bank 0), and OS_Yield(), which looks like this:
code:
#define OS_Yield(label)
do { OSSaveRtnAddr(label);
asm(" return");
asm("_" _OSMkstr(label) ":");
} while (0)

also doesn't involve any banked variables. So no matter what OSLOC_ALL is, it doesn't directly impact the code that the compiler generates.

So my guess is that if it truly is a PICC bug, it's an optimization bug that is provoked by the do { } while ( 0 ) construct.

------------------


Re: Inline services possible bug

PostPosted: Wed Jan 08, 2003 3:53 am
by luben
Hello,

I think that the problem could not be easy solved... at least for me the seed of the problem is that there are 2 different view points - when looking to the program from TASK point and when looking to the program from SALVO kernel view point.

In fact after the return (OS_Yield) other program (RTOS kernel) begins execution. Then it uses call to the place nextdoor to OS_Yield it brings the control to the task, but it believes that it's another program... not the previous. It's not normal flow of operation of one single program return .... call.. return.. call..
I mean, it's not normal inside of one program to have many return/call places (the normall flow should be call/return).
Seems that the problem is very deep and heavy.

The compiler view point is not from the task place, but from the kernel place.

I think that this needs some special macros to froce the compiler banking calculation.

Why this guy will not make some new pragma
#pragma force_banking
that will just force banking.

I'll try to make one example without SALVO and will see if the bug exists there.

For sure with SALVO OS_Delays this exists right now....

Best regards
Luben


Re: Inline services possible bug

PostPosted: Wed Jan 08, 2003 4:59 am
by luben
Hello,

I think that I made example, where the bug is nacked and could be detaily examined

code:

/*
I think I succeeded to locate the bug into simple example.
make a project, compile it with target 16F876 and Simulator mode.
Luben

PROGRAM that shows BUG with banking when using SALVO OS_Delay()

Target processor is 16F876
Simulator mode

*/


#include "pic.h" // include main file with PIC description


__CONFIG(XT & WDTDIS & PWRTEN & BORDIS); // configure processor
__IDLOC(0002); // write the version in location

bank2 static unsigned char var; // vaiable that resides in BANK2 - different from the bank of main loop variable

/***************************************************************/
void Task(void) // syncronize EEPROM with user variables in background mode
/***************************************************************/
{

var = 20;

while(1)
{

if (var)
{
var--; // !!!!!!! HERE YOU CAN SEE THE BUG - put here one BREAKPOINT
// when stepping you'll see that the program will not decrement the VAR
// for sure it decrements some other variable on the same address but
// in other bank
// to get this easier - open File Register Window and you can watch how
// variable in bank2 is changed "correctly" instead of var in bank1
// just run (F9) several times when you're in File register Window...

}
else
{
var = 20; // makes simple counter to 20
}

asm("return"); // this 2 operators imitate OS_Delay() service in SALVO
asm("_LABEL1:");

//==================================================

} // end of the main loop
}

/***************************************************************/
void main() // main program
/***************************************************************/
{
// ----------- TMR0 control -----------------------------

bank1 static unsigned char var1; // variable in BANK1 (imitate SALVO TCB )
OPTION = 0b01000001;

INTCON = 0; // GIE disable

/*--------- originally this is a SALVO kernel calling loop, where the tasks are called
with call _Addr. When returning the control to the kernel the task uses
asm "return".

The example is remade to be more convenient to get where the problem is
(originally it is 4 tasks and 1 event project for SALVO MONITOR)

*/
Task(); // imitate the initial start of the task

while(1) // non stopping loop of the main program
{
var1 = var1/2 + 71; // makes some calculations to show to the compiler that bank1 is
// the current bank (forcing compiler to think that bank1 is current bank)


asm("call _LABEL1"); // the RTOS kernel brings back the control to the task

}

}


The target is 16F876, Simulator mode

regards
Luben


Re: Inline services possible bug

PostPosted: Thu Jan 09, 2003 2:21 am
by aek
For anyone else watching this thread ... the problem is not a bug per se in Salvo or PICC. It occurs because of the way the Salvo context switcher is written.

HI-TECH and Pumpkin are working on a fix for this right now, and it will likely appear in PICC and Salvo updates in the near future.

------------------