Pumpkin, Inc.

Pumpkin User Forums

multitasking

For issues specific to Microchip's PICmicro® MCUs, including compilers (e.g. HI-TECH PICC & PICC-18, Microchip MPLAB®-C18) and IDEs (e.g. Microchip MPLAB®).

multitasking

Postby larsbn » Fri May 02, 2008 12:37 am

I use Salvo 3.2.2 Lite version, HI-TECH PICC-18-compiler and a PIC18F458.
I have made a small design where I have defined three tasks and no events. I have given them all the same priority (8) and I expected all three of them to be executed in a round-robin way. The code compiles fine (no error) but when I run the program in the controller, it only executes the first two tasks. The third one is never executed even though it has the same priority as the first two! I did try to give it a higher priority (1) but that doesn't help. Still only the first two are executed. This is also clearly confirmed in MPSIM. As far as I understand, the Salvo Lite version should be able to handle three events (and I do not get any compiling errors). If I rearrange the orer in which they are declared in the code (and renumber the tcb-blocks) then the one on the last row will not run.
I don't understand this. Do you have any clues?
Regards
Lars B

------------------
/L

/L
larsbn
 
Posts: 18
Joined: Mon Mar 10, 2008 11:00 pm
Location: Gothenburg, Sweden

Re: multitasking

Postby aek » Fri May 02, 2008 10:53 am

#define OSTASKS 3 ?

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

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

Re: multitasking

Postby aek » Sat May 03, 2008 1:44 am

Check return code from your calls to OSCreateTask().

Make sure you're using OSTCBP(1), OSTCB(2) & OSTCBP(3).

Make sure that's really the salvocfg.h the compiler is seeing (use #error).

List the code here.

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

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

Re: multitasking

Postby larsbn » Sat May 03, 2008 9:40 am

Yes, I do have that line i the salvocfg.h-file. (Besides, wouldn't the compiler complain if I didn't?)
/larsbn


quote:
Originally posted by aek:
#define OSTASKS 3 ?


/L
larsbn
 
Posts: 18
Joined: Mon Mar 10, 2008 11:00 pm
Location: Gothenburg, Sweden

Re: multitasking

Postby larsbn » Sun May 04, 2008 10:45 am

This is how I checked the return codes: I defined a new variable, test (int) and set test=OSCreateTask() for each of the three OSCreateTask()-Lines in my code and then I read the value of the variable "test" in MPSIM (please let me know if there is a better way to do it).
Anyway, the return code of the first two ones are 0x0000 but the return code of the third one is 0x0002. I guess that tells me that there is something wrong with the last one, but I can't figure out what...

I do use OSTCBP(1), OSTCB(2) & OSTCBP(3).

I also use the right salvocfg-file. I did the #error-trick and that works.

Here is my code (at the end I also list the salvocfg-file I'm using:


code:
#include <pic18.h>
#include <salvo.h>

unsigned char ad8bit(unsigned char kanal);
void Display(unsigned char siffra);
unsigned char data,number,dp;
int test1,test2,test3;

_OSLabel(TaskAD1);
_OSLabel(TaskDecimal1);
_OSLabel(TaskDisplay1);

void TaskAD(void) {
ADCON0=0xC1;
while(1) {
data=ad8bit(0);
OS_Yield(TaskAD1);
}
}

void TaskDisplay(void) {
TRISC=0x00;
while(1) {
if (data<=25)
number=0;
else if (data<=50)
number=1;
else if (data<=75)
number=2;
else if (data<=100)
number=3;
else if (data<=125)
number=4;
else if (data<=150)
number=5;
else if (data<=175)
number=6;
else if (data<=200)
number=7;
else if (data<=225)
number=8;
else
number=9;
Display(number);
OS_Yield(TaskDisplay1);
}
}

void TaskDecimal(void){
TRISB=0xFF;
while(1) {
if (RB0)
dp=0x80;
else
dp=0x00;
OS_Yield(TaskDecimal1);
}
}

int main() {
OSInit();
OSCreateTask(TaskAD,OSTCBP(1),8);
OSCreateTask(TaskDisplay,OSTCBP(2),8);
OSCreateTask(TaskDecimal,OSTCBP(3),8);

while(1){
OSSched();
}
}

void Display(unsigned char siffra) {
switch (siffra) {
case 0:
PORTC=0x3F | dp;
break;
case 1:
PORTC=0x06 | dp;
break;
case 2:
PORTC=0x5B | dp;
break;
case 3:
PORTC=0x4F | dp;
break;
case 4:
PORTC=0x66 | dp;
break;
case 5:
PORTC=0x6D | dp;
break;
case 6:
PORTC=0x7D | dp;
break;
case 7:
PORTC=0x07 | dp;
break;
case 8:
PORTC=0x7F | dp;
break;
case 9:
PORTC=0x6F | dp;
break;
}
}

unsigned char ad8bit(unsigned char kanal){
kanal<<=3;
ADCON0=0xC1 | kanal;
GODONE=1;
while(GODONE);
return ADRESH;
}



My Salvocfg-file:

code:
#define	OSUSE_LIBRARY		TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_CONFIG OSM
#define OSLIBRARY_VARIANT OSB
#define OSTASKS 3

Library-file I use: sfp87smb.lib

regards
larsbn

[This message has been edited by aek (edited May 05, 2008).]

/L
larsbn
 
Posts: 18
Joined: Mon Mar 10, 2008 11:00 pm
Location: Gothenburg, Sweden

Re: multitasking

Postby aek » Mon May 05, 2008 9:46 am

That does look fine ... before I try your app here, could you please update to v3.2.3, with all the patches?
http://www.pumpkininc.com/salvo/lite/pic/3.2/

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

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

Re: multitasking

Postby larsbn » Mon May 05, 2008 9:57 am

I downloaded the updates as you recommended. Didn't help, though. Problem remains....

I also tried to reduce my program, but even if I only run the small program below, it only executes the first two tasks. The return value of the third OSCreateTask() (=test3) is still 0x02, which I think means that "an invalid pointer was passed to the service". That doesn't make sense to me, since I use OSTCBP(3) to pass a correct pointer.

#include <pic18.h>
#include <salvo.h>
unsigned char test1,test2,test3;
_OSLabel(TaskAD1);
_OSLabel(TaskDecimal1);
_OSLabel(TaskDisp1);

void TaskAD(void) {
while(1) {
OS_Yield(TaskAD1);
}
}

void TaskDisp(void) {
while(1) {
OS_Yield(TaskDisp1);
}
}

void TaskDecimal(void){
while(1) {
OS_Yield(TaskDecimal1);
}
}

int main() {
OSInit();
test1=OSCreateTask(TaskAD,OSTCBP(1),8);
test2=OSCreateTask(TaskDisp,OSTCBP(2),8);
test3=OSCreateTask(TaskDecimal,OSTCBP(3),8);

while(1){
OSSched();
}
}

/L
larsbn
 
Posts: 18
Joined: Mon Mar 10, 2008 11:00 pm
Location: Gothenburg, Sweden

Re: multitasking

Postby aek » Wed May 07, 2008 12:42 am

Odd .. please do one more thing before I try this here -- since you're using an 'F458, there's no need to use such a small library. Please use a -ab or -tb library and update your salvocfg.h accordingly ...

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

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

Re: multitasking

Postby larsbn » Wed May 07, 2008 10:42 am

When I try an -ab library there is no change. It still only runs the first two tasks.
When I change to a -tb library I get two compiler errrors:
Error[491] : can't find 0x61 words for psect "nvrram" in segment "COMRAM" Error[491] : can't find 0x3 words for psect "rbss" in segment "COMRAM"

I also tried changing from "small memory modell" to "large memory modell" (with an -ab library) but that still only runs the first two tasks. I always get return code 0x02 from the last OSCreateTask(). It just doesn't like the OSTCBP(3)-pointer, as far as I understand.

/L
larsbn
 
Posts: 18
Joined: Mon Mar 10, 2008 11:00 pm
Location: Gothenburg, Sweden

Re: multitasking

Postby aek » Fri May 09, 2008 8:31 am

OK, this took a while to figure out, so it is no wonder you had difficulty with this ... and I'm sorry that you had these problems.

It appears that our documentation is incorrect, and this may be due to changes in Microchip's or HI-TECH's products since Salvo Lite v3.2.3 was released ...

I built your application with source code and it worked fine ... but I had all sorts of problems running it when built from sfp87smb.lib ...

To make a long story short, it works fine if you use slp80lmb.lib (built with the default / large memory model). This is the "safest" library to use, as it does not use the LFSR instruction (and therefore is compatible with all PIC18 devices).

If you look at the .map file, however, you'll see that PICC18 is using the pic86l-c.lib library ... so you can also use sfp86lmb.lib. Which means that you can also use sfp86smb.lib, if you set Project -> Build Options -> Project -> Global -> Memory Model: Small ...

So the problem was simply that you were using the wrong library, due to bad documentation on our part. What is odd is that at the time the RM-PICC18.PDF was written, this would have been the right library, or so we were told ...

Here's the build:

code:
Clean: Deleting intermediary and output files.
Clean: Deleted file "D:PumpkinCustomerLarsbnPIC18main.obj".
Clean: Deleted file "D:PumpkinCustomerLarsbnPIC18main.cce".
Clean: Deleted file "C:salvosrcmem.obj".
Clean: Deleted file "C:salvosrcmem.cce".
Clean: Deleted file "PIC18F458_Probs.cof".
Clean: Done.
Executing: "C:Program FilesHI-TECH SoftwarePICC-189.50inpicc18.exe" -C -E"main.cce" "main.c" -O"main.obj"
-I"D:PumpkinCustomerLarsbnPIC18" -I"C:SalvoInc" -Zg9 -O -ASMLIST -Bs -Q -MPLAB -18F458
Executing: "C:Program FilesHI-TECH SoftwarePICC-189.50inpicc18.exe" -C -E"mem.cce" "mem.c" -O"mem.obj"
-I"D:PumpkinCustomerLarsbnPIC18" -I"C:SalvoInc" -Zg9 -O -ASMLIST -Bs -Q -MPLAB -18F458
Executing: "C:Program FilesHI-TECH SoftwarePICC-189.50inpicc18.exe" -E"PIC18F458_Probs.lde"
"D:PumpkinCustomerLarsbnPIC18main.obj" "C:salvosrcmem.obj" "C:salvolibhtpicc18sfp86smb.lib"
-M"PIC18F458_Probs.map" -O"PIC18F458_Probs.cof" -O"PIC18F458_Probs.hex" -Bs -Q -MPLAB -18F458

Memory Usage Map:

Program space:
CODE used 2E8h ( 744) of 8000h bytes ( 2.3%)
LOWCODE used 0h ( 0) of 8000h bytes ( 0.0%)

Data space:
RAM used 9h ( 9) of 600h bytes ( 0.6%)
BIGRAM used 0h ( 0) of 600h bytes ( 0.0%)
COMRAM used 1Dh ( 29) of 60h bytes ( 30.2%)
NVRAM used 0h ( 0) of 100h bytes ( 0.0%)

EEPROM space:
EEDATA used 0h ( 0) of 100h bytes ( 0.0%)

External data memory:
None available

ID Location space:
IDLOC used 0h ( 0) of 8h nibbles ( 0.0%)

Configuration bits:
CONFIG used 0h ( 0) of 7h words ( 0.0%)

Summary:
Program space used 2E8h ( 744) of 8000h bytes ( 2.3%)
Data space used 26h ( 38) of 600h bytes ( 2.5%)
EEPROM space used 0h ( 0) of 100h bytes ( 0.0%)
External data memory None available
ID Location space used 0h ( 0) of 8h nibbles ( 0.0%)
Configuration bits used 0h ( 0) of 7h words ( 0.0%)

Loaded D:PumpkinCustomerLarsbnPIC18PIC18F458_Probs.cof.
BUILD SUCCEEDED: Fri May 09 14:27:26 2008


Here's the program I ran:
code:
#include <pic18.h>
#include <salvo.h>
unsigned char test1,test2,test3, test4;
_OSLabel(TaskAD1);
_OSLabel(TaskDecimal1);
_OSLabel(TaskDisp1);

void TaskAD(void) {
while(1) {
OS_Yield(TaskAD1);
}
}

void TaskDisp(void) {
while(1) {
OS_Yield(TaskDisp1);
}
}

void TaskDecimal(void){
while(1) {
OS_Yield(TaskDecimal1);
}
}

int main() {
OSInit();
test1=OSCreateTask(TaskAD,OSTCBP(1),8);
test2=OSCreateTask(TaskDisp,OSTCBP(2),8);
test3=OSCreateTask(TaskDecimal,OSTCBP(3),8);
test4=OSCreateTask(TaskDecimal,OSTCBP(4),8);

while(1){
OSSched();
}
}


I used your salvocfg.h. test1, test2 and test3 are all 0 prior to entering OSSched, and test4 is 2 (correct).

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

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

Next

Return to PICmicro MCUs

Who is online

Users browsing this forum: No registered users and 2 guests

cron