Pumpkin, Inc.

Pumpkin User Forums

BANK problems maybe still exists

If you think you've found a bug or other mistake in your Salvo distribution, post it here.

BANK problems maybe still exists

Postby luben » Fri Jan 17, 2003 11:27 am

Hello,

The bank problems were 2:
- the tasks doesn't returrn the control to the kernel with bank set to 0
- the kernel doesn't return the right bank to the task - fixed with new assembler aspic.exe

The first problem looked not so dangerous, because all kernel functionality is written in that way , that overrides the problem.

Today I realized that it could be a problem that tasks doesn't return the bank to 0.....

Usually the kernel looks like:

code:

while(1)
{
OSSched();
}


But what about

code:

while(1)
{
var1 = .......; // some calculations
var2 = .......;
if (......) // for projects without ISR Timer is called from this level
OSTimer();
// some calculations operations could be done before calling the kernel
OSSched();
var2 = .......;
}

if var1 and var2 are defined in "bad" banks, they could yield wrong results (if the bank set in the last task, is not the bank of the var1 or var2)..... I'll try to make an example and to check if this is true.
But I smell, that some small part of the bank bug is still staying.....

Regards
Luben

[This message has been edited by luben (edited January 18, 2003).]

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

Re: BANK problems maybe still exists

Postby luben » Sat Jan 18, 2003 7:55 am

Hello,

NEW BUG!!!

Some good and some bad news - aspic.exe seems that works fine and no old problems exists.

In fact, my example - when using return/call , doesn't work , as I felt. And it's what I told you - it's impossible for one compiler without artifical intelect to keep track of the right bank into assembler section. One experienced and good assembler programmer could write so crazy codes,to set/reset banks, that it's hard to to understand from first and second view what's up.

Because you use C instructions for calling the tasks, the compiler could set the right banks.

In short:
- my approach return/call (the example I published in teh forum) doesn't work correct
- your approach

code:

typedef void (* typeFnP) (void); // for writing a function pointer
typeFnP TaskP; // ""
void LABEL1 ( void ); // ""


/***************************************************************/
void SaveFnP ( typeFnP fnP)
{
TaskP = fnP; // set the function pointer
}


/***************************************************************/
void Task(void)

{
var = 20; // initialization

while(1) {
if (var) // check STATUS[6,5] here (bank bits)
var--; // they're wrong from #2 execution onwards

SaveFnP(LABEL1); // update function pointer to alternate entry point
asm("return"); // alternate exit point
asm("_LABEL1:"); // placeholder only

}
}


works fine.

I mean----- this sounded like to be the end of BANK BUG problem.

I made SALVO project - it works fine too..... BUT, I got other BUG!
If you put some code after OSSched() and ... BANG! It's maybe because of the OSSched() macro....

The example below doesn't work.
Remove the row after OSSched - and it works!

code:

#include "pic.h" // include main library of HiTech
#include "stdio.h" // include procedures for I/O sprintf()
#include "salvokrn.h" // include SALVO functionality
static unsigned char var;
bank3 static unsigned char var1;

_OSLabel(_TASK01) // define labels
/*****************************************/
void TASK01(void) // task 1
/*****************************************/
{
while (1)
{
var++;

OS_Yield(_TASK01);
}
}

_OSLabel(_TASK02) // define labels
_OSLabel(_TASK02a) // define labels
/*****************************************/
void TASK02(void) // task 1
/*****************************************/
{
while (1)
{
var++;
OS_Yield(_TASK02a);
}
}


void main(void) // main loop
{
OPTION = 0b11000110; //prescaller 1:128 Every 20 ms synchronize (with compensation)
INTCON = 0;
OSInit(); // init SALVO
OSCreateTask(TASK01, OSTCBP(1), 5); // create task
OSCreateTask(TASK02, OSTCBP(2), 5); // create task

while (1)
{
var1++;
OSSched(); // kernel of SALVO
var1 += 2; // !!!!!!!!!!!!
// if this row is removed - the project works fine like it have to be
// with this row it works unpredictable.... BANG!

}


}

/*
================ SALVOCFG.H
I just copied it from my project
====================
*/

#define OSBYTES_OF_DELAYS 1
#define OSCOMPILER OSHT_PICC // compiler
#define OSTARGET OSPIC16 // processor type
#define OSEVENTS 0 // number of events(binSem,messages) 1 QUEUEU
#define OSTASKS 10 // number of running tasks
// defined more tasks, then used, just to provoke mistakes to leave their "holes"

//---------- MESSAGE QUEUES SUPPORT ---------------------
#define OSENABLE_MESSAGE_QUEUES FALSE // disable message queues
#define OSENABLE_MESSAGES FALSE // enable messages
#define OSBIG_MESSAGE_POINTERS FALSE // enable big messages pointing both RAM and ROM

#define OSENABLE_TIMEOUTS FALSE // enable timeout when waiting
#define OSENABLE_BINARY_SEMAPHORES FALSE // enable binary semaphores
#define OSENABLE_EVENT_TRYING FALSE
//#define OSCALL_OSSIGNALEVENT OSFROM_ANYWHERE // to call it from ISR

#define OSCLEAR_WATCHDOG_TIMER() asm("clrwdt") // clear watchdog timer command

//----------- RAM destination of the SALVO resources -----
#define OSLOC_TCB bank1 // all SALVO located in bank2
#define OSLOC_ECB bank1
#define OSLOC_CTCB bank1




BTW, will be great is HiTech keeps the new resetbanks() function - sometimes it could be useful.

This shows again why we NEVER have to touch the damn assembler (despite that I programmed more time on assembler in my life, then on C). What's wrong with the pure C?

Regards
Luben

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

Re: BANK problems maybe still exists

Postby aek » Mon Jan 20, 2003 12:02 pm

Hi Luben.

I'll take a look at it, but the bug you describe should definitely not be happening ... one of the "golden ruls" of PICC and PICC-18 is that every function must exit with bank 0 selected. OSSched() is a function, and so it will always exit with bank 0 selected, and then the compiler needs to set the banks in order to operate on var1.

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

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: BANK problems maybe still exists

Postby luben » Mon Jan 20, 2003 12:10 pm

Hello,

Maybe I didn't explained correctly - it's not wrong operation of VAR1.... the program stops working and responding at all! I mean, something is worng with the compilation of the loop. The right word is "unpredictable" behaviour - I saw that the control of the program just jumped away from the loop.

Luben

[This message has been edited by luben (edited January 20, 2003).]

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


Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 2 guests

cron