Page 1 of 1

Priority task..

PostPosted: Mon Jul 17, 2006 3:32 am
by ubbe
Hi,
I am newbie to Salvo <<Lite>>.
When I change my priority , my application doesn't work.I don't use OS_Yield.
Can you help me..?
thank

Salvo Lite
MCC18 3.02
MPLAB 7.40

SALVOCFG.H
#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_GLOBALS OSF
#define OSLIBRARY_CONFIG OSA
#define OSLIBRARY_VARIANT OSNONE

#include "SALVOCFG.h"
#include "salvo.h"

/* Task con priorità */

/*
_OSLabel(Saldatura1)
_OSLabel(Encoder1)
_OSLabel(PWM1)
*/

/* Task pointer */
#define Tsk_Saldatura OSTCBP(1)
#define Tsk_Encoder OSTCBP(2)
#define Tsk_PWM OSTCBP(3)


void Saldatura( void )
{

PORTBbits.RB0=1;
}

void Encoder( void )
{


PORTBbits.RB1=1;


}

void PWM( void )
{
PORTBbits.RB2=1;


}

void main( void )
{

TRISB=0;
PORTB=0;


/* RUN Sistema operativo */
OSInit();

/* Crea Task */
OSCreateTask(Saldatura,Tsk_Saldatura, 1);
OSCreateTask(Encoder, Tsk_Encoder, 2);
OSCreateTask(PWM, Tsk_PWM, 3);

/* Task RUN */

OSStartTask(Tsk_Saldatura);
OSStartTask(Tsk_PWM);
OSStartTask(Tsk_Encoder);

for (;
OSSched();
}


void OSIdleTaskHook (void)
{
while(1);
}


Re: Priority task..

PostPosted: Mon Jul 17, 2006 3:39 am
by aek
1) Each Salvo task must have a context switch (OS_Xyz()). Your tasks have no context switch, and so your application is stuck in Tsk_Saldatura(). Add an OS_Yield() to the infinite loop in each task and it will start working.

2) The idle task hook is a function that must exit. Yours will be stuck in an infinite loop. Make it do something simple (like toggle a port bit) and exit ...

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


Re: Priority task..

PostPosted: Tue Jul 18, 2006 12:11 am
by ubbe
Hi,

This my example works without priority levels(?!).
The semaphore works and tasks switch.
OSLIBRARY_CONFIG is OSF .
The priority are disabled and salvolib.h is read only


/*
#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_GLOBALS OSF
#define OSLIBRARY_CONFIG OSA
#define OSLIBRARY_VARIANT OSNONE

*/

#include "SALVOCFG.h"
#include "salvo.h"
unsigned int counter;

/* Task con priorità */

_OSLabel(led1)
_OSLabel(led2)
_OSLabel(led3)

/* Task pointer */
#define Tsk_led0 OSTCBP(1)
#define Tsk_led1 OSTCBP(2)
#define Tsk_led2 OSTCBP(3)
#define BINSEM_COUNTER OSECBP(1)

void InterruptHandlerHigh (void);
//----------------------------------------------------------------------------
// High priority interrupt vector

#pragma code InterruptVectorHigh = 0x08
void
InterruptVectorHigh (void)
{
_asm
goto InterruptHandlerHigh //jump to interrupt routine
_endasm
}

//----------------------------------------------------------------------------
// High priority interrupt routine

#pragma code
#pragma interrupt InterruptHandlerHigh

void
InterruptHandlerHigh ()
{

}

//----------------------------------------------------------------------------
void led0( void )
{
for (;
{
PORTBbits.RB0=1;

if (counter++>100)
{
counter =0;
OSSignalBinSem(BINSEM_COUNTER);
}
OS_Yield(Tsk_led0);

}

}

void led1( void )
{
for (;
{
PORTBbits.RB1=1;
OS_WaitBinSem(BINSEM_COUNTER,OSNO_TIMEOUT,led1);
PORTBbits.RB0=0;

}


}

void led2( void )
{
for (;
{
PORTBbits.RB2=1;
// OS_Delay(100,Tsk_led0);

OS_Yield(Tsk_led2);

}


}

void main( void )
{

TRISB=0;
PORTB=0;


/* RUN Sistema operativo */
OSInit();

/* Crea Task */
OSCreateTask(led0,Tsk_led0, 1);
OSCreateTask(led1, Tsk_led1, 2);
OSCreateTask(led2, Tsk_led2, 3);

OSCreateBinSem(BINSEM_COUNTER,0);

counter =0;
for (;
OSSched();
}

void OSIdleTaskHook (void)
{
// PORTB=0; if uncommented , RB1 is always 1
}


Re: Priority task..

PostPosted: Tue Jul 18, 2006 7:33 am
by aek
quote:
The priority are disabled and salvolib.h is read only
I think you may be misunderstanding some things ...

1) You do not control whether priorities are disabled or not. Priorities are enabled in all Salvo libraries except the -m configuration library. You are using a -a configuration library, so priorities are enabled.

2) Salvo tasks can have the same priorities.

3) There is no reason for a user to modify salvolib.h. If you modify it, your application will not run properly. Hence the warning in the file, and the fact that it is read-only. In fact, there is no reason to modify any of Salvo's header or source files.

4) In your application, only Tsk_led0 will run. Why? Because it has the highest priority, and it only yields (it does not delay or wait). When it yields to the scheduler, it is still the highest-priority task, and so the scheduler only runs it and not the others. Change all of your task priorities to the same (e.g. 2) and all three tasks will start running.

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